[antlr-interest] Token class in lexer - lexical
nondeterminismerror
Jiho Han
jhan at InfinityInfo.com
Tue Jul 25 10:36:37 PDT 2006
I see. Then I guess I better make sure the parser won't need to use any
of the OP_* tokens.
Thanks!
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Scott Amort
Sent: Tuesday, July 25, 2006 12:30 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Token class in lexer - lexical
nondeterminismerror
Hi,
Jiho Han wrote:
> I am new to ANTLR.
> I have the following defined in my lexer.
>
> OP_EQ : '=' ;
> OP_NEQ : "<>" ;
> OP_GT : '>' ;
> OP_LT : '<' ;
> OP_GE : ">=" ;
> OP_LE : "<=" ;
> LPAREN : '(' ;
> RPAREN : ')' ;
You need to preface these rules with 'protected', for example:
protected OP_EQ: '=';
> OPERATOR : (OP_EQ | OP_NEQ | OP_GT | OP_LT | OP_GE | OP_LE) ;
>
> When I run it through antlr I get:
>
> FilterExpression.g: warning:lexical nondeterminism between rules OP_EQ
> and OPERATOR upon
> FilterExpression.g: k==1:'='
> FilterExpression.g: k==2:<end-of-token>
>
> And bunch of others like it.
This is due to non-determinism between any of these expressions (i.e.
are you matching OP_EQ or OPERATOR?) Using the 'protected' keyword
tells ANTLR that your OP_* rules are helpers, and are not to be passed
on to the parser.
Best,
Scott
More information about the antlr-interest
mailing list