[antlr-interest] Choosing token

Terence Parr parrt at cs.usfca.edu
Fri May 11 09:34:53 PDT 2007


On May 11, 2007, at 9:19 AM, Johannes Luber wrote:

> Stefan Chrobot wrote:
>> Hello!
>>
>> Is there a way other than reordering the rules to tell ANTLRv3 to  
>> prefer
>> token BOOLEAN instead of IDENTIFIER?
>>
>> grammar Test;
>>
>> start    :    BOOLEAN
>>     |    IDENTIFIER;
>>
>> IDENTIFIER
>>     :    ('a'..'z'|'A'..'Z'|'0'..'9')+;
>>
>> BOOLEAN    :    'true' | 'false';
>
> Yes. Look at
> <http://www.antlr.org/wiki/display/ANTLR3/Quick+Starter+on+Parser 
> +Grammars+-+No+Past+Experience+Required>
> in the "How to define tokens" section for more information.

I'm not sure Johannes (excellent) tutorial says it explicitly: the  
order in which you define lexical rules gives the priority.  Put  
BOOLEAN before IDENTIFIER. :)

Ter



More information about the antlr-interest mailing list