[antlr-interest] resolving ambiguity
Stephen Siegel
siegel at udel.edu
Mon May 21 08:50:20 PDT 2012
In the following grammar:
-----------------------------------------------
grammar g1;
options { output=AST; }
tokens { B_CHAIN; }
r : (A | b_chain)*;
b_chain : B+ -> ^(B_CHAIN B+);
A : 'A';
B : 'B';
// BB should yield ^(BCHAIN B B)
-----------------------------------------------
there is an ambiguity since input "BB" could be parsed as (1) two "b_chain"s (each with one "B") or as (2) one b_chain (with two "B"s). I want to tell ANTLR to choose option (2).
Right now, I get this warning:
-------------------------------------
[11:45:02] Checking Grammar g1.g...
[11:45:02] warning(200): g1.g:5:11:
Decision can match input such as "B" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
-------------------------------------
Does anyone know how to resolve the ambiguity?
Thanks,
Steve
More information about the antlr-interest
mailing list