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

Adam B cruxic at gmail.com
Mon Apr 16 16:21:50 PDT 2012


Thanks for the reply, Norm.  I tried your suggested tweak to the calculator
example and it complains that

   "rule term has non-LL(*) decision due to recursive rule invocations..."


On Mon, Apr 16, 2012 at 12:59 PM, Norman Dunbar <Norman at dunbar-it.co.uk>wrote:

> Evening Adam,
>
> as one noob to another then, here's what I think. I noticed you haven't
> had any replies yet, so idf I put something obviously incorrect, I'm
> sure we'll get jumped on by those who know better than I do! Let's hope
> so anyway!
>
>
> > 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
> >
>
> Does this help? It's not mine, it's one of the ANTLR examples:
>
> grammar SimpleCalc;
>
> tokens {
>        PLUS    = '+' ;
>        MINUS   = '-' ;
>        MULT    = '*' ;
>        DIV     = '/' ;
> }
>
>
> /*------------------------------------------------------------------
>  * PARSER RULES
>  *------------------------------------------------------------------*/
>
> expr    : term ( ( PLUS | MINUS )  term )* ;
>
> term    : factor ( ( MULT | DIV ) factor )* ;
>
> factor  : NUMBER ;
>
>
> /*------------------------------------------------------------------
>  * LEXER RULES
>  *------------------------------------------------------------------*/
>
> NUMBER  : (DIGIT)+ ;
>
> WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+    { $channel =
> HIDDEN; } ;
>
> fragment DIGIT  : '0'..'9' ;
>
>
> Now, I'm not convinced that the above is complete, yet, but as a simple
> grammar it's fine. I'd be thinking about a FACTOR being also able to be
> a '(' followed by an expr followed by a ')'. Something like:
>
>
> factor  : NUMBER |
>        LPAREN expr RPAREN;
>
> Where LPAREN and RPAREN are defined in the tokens table.
>
>
> HTH
>
>
> Cheers,
> Norm.
>
>
> --
> Norman Dunbar
> Dunbar IT Consultants Ltd
>
> Registered address:
> Thorpe House
> 61 Richardshaw Lane
> Pudsey
> West Yorkshire
> United Kingdom
> LS28 7EL
>
> Company Number: 05132767
>
> 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