[antlr-interest] Help on gated semantic predicate

Jim Idle jimi at temporal-wave.com
Wed Aug 8 21:46:08 PDT 2012


Why would you expect that? Your gate  is always false and you have ambiguous rules. The trace reflects that. 

As general advice to everyone, look at the generated code, it helps to understand what is going on. 

Good luck,

Jim

On Aug 8, 2012, at 9:04 PM, Francis ANDRE <francis.andre.kampbell at orange.fr> wrote:

> Hi
> 
> With such reduced grammar
> 
> 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; }    ;
> 
> 
> With an input such as a single character:    A
> 
> the lexer/parser produces
> enter MASK A line=1:0
> exit MASK A line=1:0
> line 1:0 rule MASK failed predicate: {false}?
> tokens=
> enter start [@0,1:1='<EOF>',<-1>,1:1]
> exit start [@0,1:1='<EOF>',<-1>,1:1]
> 
> 
> while I would expect to get this
> enter VARIABLE A line=1:0
> exit VARIABLE ? line=1:1
> tokens=A
> enter start [@0,0:0='A',<6>,1:0]
> exit start [@0,0:0='A',<6>,1:0]
> line 1:0 missing ID at 'A'
> 
> 
> Why the rule MASK with the gated predicate {false}?==> is executed??
> 
> TIA for your help.
> 
> FA
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list