[antlr-interest] Tokens and literals: how to avoid conflics?

Gioele Barabucci barabucc at cs.unibo.it
Fri Jul 11 10:57:49 PDT 2008


This simple grammar

> grammar Tok1;
> 
> stmt:     'id' S id_name S ('#IMP'|'#FIX') EOF; 
> id_name:  '#' NAME;
> 
> NAME: ('A'..'Z')+;
> S: (' '|'\n')+;

parses "id #AAA #FIX" correctly but fails on "id #III #FIX" with a
MismatchedTokenException(5!=9).

I think the exception is raised because as soon as the lexer sees "#I"
(in "#III") it expects the token to be equal to the literal "#IMP".

Is there a way to work around this problem?

-- 
Gioele Barabucci <barabucc at cs.unibo.it>



More information about the antlr-interest mailing list