[antlr-interest] Alternative(s) 2 were disabled for that input
Markus
grey_earl at web.de
Fri Sep 19 04:49:22 PDT 2008
----------------------- CUT -------------------
>
> //=== Parser ===//
> expr: orexpression*;
> orexpression
>
> : andexpression (OR orexpression)*
> ;
>
> andexpression
> : notexpression (AND andexpression)*
> ;
>
> notexpression
> : (NOT)? atom
> ;
>
> atom
> : WORD+
> | LEFT_PAREN! expr RIGHT_PAREN!
> ;
>
> --- On Thu, 9/18/08, jack zhang <jackgzhang2 at yahoo.com> wrote:
> From: jack zhang <jackgzhang2 at yahoo.com>
> Subject: Alternative(s) 2 were disabled for that input
> To: antlr-interest at antlr.org
> Date: Thursday, September 18, 2008, 4:46 PM
>
> Hi,
> I keep getting following errors:
>
> warning(138): Query.g:0:0: grammar Query: no start rule (no rule can
> obviously be followed by EOF) warning(200): Query.g:27:40: Decision can
> match input such as "OR" using multiple alternatives: 1, 2 As a result,
> alternative(s) 2 were disabled for that input
> warning(200): Query.g:31:39: Decision can match input such as "AND" using
> multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for
> that input
> warning(200): Query.g:39:7: Decision can match input such as "WORD" using
> multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for
> that input
>
------------------------- CUT --------------------
The parser complains because it can match a OR b OR c in two ways, one by
using the kleene star * in or_expression twice and so matching two ORs with
their corresponding expressions reduced to atoms, and the other one by using
the kleene star * in or_expression once, and matching b OR c with another
or_expression. You want to change or_expression (and similar and_expression)
to
or_expression
: and_expression (OR and_expression)*
;
so it always has to match the kleene star * twice and the parser won't
complain about this anymore. I know the error messages can be sometimes quite
confusing, and the best way to deal with this is to make a copy of your
grammar and remove one rule at a time to see which one really causes the
error. Then at least you know which rule to fix.
Markus
More information about the antlr-interest
mailing list