[antlr-interest] Help on gated semantic predicate

Andrew Mains andrew.mains at oracle.com
Fri Aug 10 11:23:56 PDT 2012


Francis,

The problem here is that both MASK and ID are lexer rules, not parser 
rules. As you probably know, even though you are using a combined 
grammar, the lexer and parser still compile down to separate Java 
classes.  Since the lexer provides tokens for the parser, it necessarily 
executes its rules before the parser
sees a single token. Furthermore, rules defined first in the lexer have 
precedence over those defined later, so the lexer will match MASK 
instead of ID.

Therefore, the lexer matches MASK before start is even called, giving 
the behavior you observed.

If mask were a parser rule instead of a lexer rule, it would act as you 
expected.

Hope this helps!

Andrew

On 08/09/2012 12:00 PM, antlr-interest-request at antlr.org wrote:
> start           : ID;
> MASK        :    {false}?=>( 'A' | 'B');
> VARIABLE   : 'A'..'Z';
> ID               :   ('a'..'z'|'A'..'Z'|'_')
> ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
> WS             :   ( ' '   | '\t' | '\r' | '\n' )+        {
> $channel=HIDDEN; }    ;
>



More information about the antlr-interest mailing list