[antlr-interest] Understanding priorities in lexing (newbie) [Suggestion]
Terence Parr
parrt at cs.usfca.edu
Fri Jul 13 10:28:34 PDT 2007
On Jul 13, 2007, at 10:18 AM, Susan Jolly wrote:
> I really appreciate people who take the time to write the simplest
> possible
> grammar that illustrates the problem they are having rather than
> embedding
> huge grammars in their posts.
Hi Susan! Agreed.
> Here is one way to get v3 to generate the code so the lexer looks
> ahead for
> the original example. Is there any reason not to do this?
>
> fragment KEYWORD : 'a' 'b' 'c' ;
> fragment OTHER : 'a' | 'b' | 'c';
> DUMMY : ( (KEYWORD) => KEYWORD {$type = KEYWORD;}
> | OTHER {$type = OTHER;}
> );
That is a correct grammar. Note that the following is not really
going to work:
DUMMY
options {backtrack=true;}
: (KEYWORD {$type = KEYWORD;} | OTHER{$type = OTHER;})
;
it will not execute the backtracking in this case as it thinks it
knows what it's doing. :(
Ter
More information about the antlr-interest
mailing list