[antlr-interest] resolving ambiguity
Terence Parr
parrt at cs.usfca.edu
Mon May 21 15:14:00 PDT 2012
hi Steve, it will match greedily so that b_chain will match all B's in a row.
Ter
On May 21, 2012, at 8:50 AM, Stephen Siegel wrote:
> 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
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list