[antlr-interest] ambiguities in antlr3 grammar

Benjamin S Wolf jokeserver at gmail.com
Fri Nov 9 11:14:14 PST 2012


It looks like your ambiguity is between lhs and phrase but not quite as you
say. The problem is that lhs can be multiple phrases and phrase can be
multiple words, thus WORD WORD can either be parsed as one phrase of two
words or two phrases of one word (the error is pointing at the second WORD
there).

You can get rid of the error by forcing one or the other options: change
lhs to prevent two phrases from neighboring each other, or change phrase to
only take one word at a time. That is,

lhs : phrase | ( value | phrase value )+ phrase? ;

or

phrase : WORD;


On Fri, Nov 9, 2012 at 12:51 PM, Arun Ramakrishnan <
sinchronized.arun at gmail.com> wrote:

>   Take this grammar snippet ( antlr 3.4 )
>
> *********************************
> lhs : (phrase | value)+;
> phrase : WORD+;
> value : '{}';
>
> WORD  :   ('a'..'z')+ ;
> **********************************
>
> I get the following warning in antlrworks.
> ***********************************
> Decision can match input such as "WORD" using multiple alternatives: 1, 2
>
> As a result, alternative(s) 2 were disabled for that input
> ***********************************
>
> I understand that rules phrase and lhs might match the same piece of
> string. But, then I know I am always going to try to parse the text by
> calling the specific top level rule when invoke it right. So, is there a
> way to make the warnings go away.
>
> thanks
> Arun
>
> 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