[antlr-interest] Problem using string literals
Clifford Heath
clifford.heath at gmail.com
Sat Oct 20 22:06:35 PDT 2007
S West wrote:
> grammar Test;
> test : (LETTER | '-')+;
> unrelated_rule : 'BONGO: ' LETTER;
> LETTER : ('A'..'Z');
LETTER and 'BONGO: ' are both lexical rules.
When Antlr sees a 'B', it says "this could be BONGO",
and looks further until it finds out. If not, it returns
LETTER instead.
That process produces a token stream, which is fed to the
non-lexical rules (test). It sees a BONGO token and barfs
because it was unexpected.
> I do not understand why this is happening, the literal 'BONGO: ' is in a
> totally separate and unreferred-to parser rule.
No, it's a lexer rule, which is called from an unrelated parser rule.
All lexer rules get applied before any parser rule sees the results.
Cifford.
More information about the antlr-interest
mailing list