[antlr-interest] Problem using string literals

S West antlr at smabber.com
Mon Oct 22 11:30:34 PDT 2007


>  Clifford Heath wrote:
> 
> 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.

Thanks for your clarification and insight, Clifford.
I shall concentrate my efforts on getting the lexing right.

Cheers
Simon


More information about the antlr-interest mailing list