[antlr-interest] Noob needs help with: warning "Decision can match input such as X... using multiple alternatives"

Kyle Ferrio kferrio at gmail.com
Mon Apr 16 16:18:03 PDT 2012


In addition to the examples swirling around the antlr website, have a look
at the screencasts posted by Scott Stanchfield on vimeo.

And if you really want to see how easy calculator-like parsing can be and
you're not afraid of working without a net, try the early access builds of
antlr v4, aka Honey Badger.  Besides making a lot of things dead simple, v4
has specific features for making algebraic expression parsing a snap.  Oh,
and it can handle direct left recursion.  Thanks be to Ter, Benevolent
ANTLR Dictator for Life!

Kyle
On Apr 13, 2012 4:58 PM, "Adam B" <cruxic at gmail.com> wrote:

> Hello all,
>
> I'm learning antlr in hopes of creating a DSL.  To this end I need to
> define a rule for nested "expressions" like:
>
>       (1+2)*((3-4)/5)+7
>
> After working around the left-recursion limitation I came up with something
> like this (simplified for clarity):
>
> -------help.g------
>    grammar help;
>
>    options
>    {
>        output=AST;
>    }
>
>    prog: expr EOF;
>
>    expr
>        : INT (binary_op^ expr)*
>        | '('! expr ')'! (binary_op^ expr)*
>        ;
>
>    binary_op
>        : '+'
>        | '-'
>        | '*'
>        | '/'
>        ;
>
>
>    INT:    '0'..'9'+;
> ----------------
>
> This creates a beautiful AST with one problem.  ANTLRWorks spits out this
> warning:
>
>    [16:47:14] warning(200): help.g:11:24:
>    Decision can match input such as "'*'..'/'" using multiple
> alternatives: 1, 2
>
>    As a result, alternative(s) 2 were disabled for that input
>
> What am I doing wrong?
>
> Any help you could offer would be greatly appreciated!
> - Adam B.
>
> 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