[antlr-interest] Help on gated semantic predicate

Francis ANDRE francis.andre.kampbell at orange.fr
Wed Aug 8 21:04:30 PDT 2012


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


More information about the antlr-interest mailing list