There appears to be something fundamental that I am not "getting"
about the way semantic predicates work. In the grammar below, the
input "cat" is recognized using the rule "cat" but in not recognized
by either the rule "expr" or the rule "pexpr". Could someone explain
to me why this is so and what the fix is?
Thanks,
Bob Wentworth
//======================================================
grammar ATest;
options {
backtrack = true;
memoize = true;
output = template;
}
@parser::header { package dummy; }
@lexer::header { package dummy; }
WS : ( ' '
| '\t'
| '\r'
| '\n'
) {$channel=HIDDEN;}
;
WHEN : 'when' ;
WORD : ('a'..'z')+ ;
expr : cat
| cat WHEN dog
| dog
;
pexpr : {input.LT(1).getText().equals("cat")}?=> cat
| {input.LT(1).getText().equals("cat")}?=> cat WHEN dog
| {input.LT(1).getText().equals("dog")}?=> dog
;
cat : {input.LT(1).getText().equals("cat")}?=> WORD ;
dog : {input.LT(1).getText().equals("dog")}?=> WORD ;
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---