[antlr-interest] Syntactic predicates question

Artem Dmytrenko admytren at engin.umich.edu
Mon Jan 30 11:14:00 PST 2006


Another newbie question here :)

I'm running into some problems while using syntactic predicates to 
resolve between ambiguous grammar rules. Here's a snippet from my lexer:

protected ActionToken: ("Action" | 'A');
protected ID: ALPHA (ALPHA | DIGIT)+;

SyntacticPredicate:
   (ActionToken) => (ActionToken { $setType (ActionToken); } ) |
   (ID) => (ID { $setType (ID); } );

The expectation is that this rule will match either "Action" or "A" and 
tag it as ActionToken or it will match alphanumeric string that starts 
with a letter and mark it as ID. However when parsing a string like 
"A12345" the rule returns neither to the parser. Here's an example 
misparsing message that my parser emits:

line 1:94: expecting ID, found 'A'

It appears that the match is stuck in the middle - e.g. ActionToken rule 
rejected the string but ID did not match it. Is that the expected 
behavior for syntactic predicates? Are there any workarounds for this 
problem?

Thank you in advance for any help and/or pointers.

Sincerely,
Artem Dmytrenko


More information about the antlr-interest mailing list