[antlr-interest] [SPAM] Syntax ambiguity?
Olivier Lefevre
lefevrol at yahoo.com
Fri Mar 4 00:02:47 PST 2011
Sorry, the subject is not very informational but I cannot
get the hang of the problem, so I cannot devise a better
subject. I have this small grammar:
grammar Gr3;
options { output=AST; }
stat : fun1 | fun2 ;
fun1 : 'fun1(' ID1 ')' ;
fun2 : 'fun2(' ID2 ')' ;
fragment DIGIT : '0'..'9' ;
fragment LETTER : ('a'..'z' | 'A'..'Z') ;
ID1 : (DIGIT | LETTER)+ ;
ID2 : (DIGIT | LETTER | '_' | '-' | '.')+ ;
WS : (' '|'\t')+ { skip(); } ;
It can recognize, say, fun1(AB) and fun2(AB_CD) as expected
but not fun2(AB), which should also be valid since AB matches
both ID1 or ID2. Rewriting fun2 as
fun2 : 'fun2(' (ID1 | ID2) ')' ;
works but is not satisfactory because I want an ID2 as fun2
argument, not an ID1. So, how can I force ANTLR to "consider"
ID1 in this position?
Thanks,
-- O.L.
More information about the antlr-interest
mailing list