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

Adam B cruxic at gmail.com
Fri Apr 13 16:58:26 PDT 2012


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.


More information about the antlr-interest mailing list