[antlr-interest] Re: Syntactic predicate for additive Expression

Mark markl at glyphic.com
Fri Apr 16 09:05:57 PDT 2004


--- In antlr-interest at yahoogroups.com, "e_mani9" <e_mani9 at y...> wrote:
>   I had conflict between additive expression and unary expression, 
> so i used syntactic predicate to fix it. 
You should not need any syntatic predicates for this kind of grammar.  Try:

AddExpr: MulExpr ((ADD | SUB) MulExpr)* ;
MulExpr: PowExpr ((MUL | DIV) PowExpr)* ;
PowExpr: UnaryExpr (POW UnaryExpr)* ;
UnaryExpr: (ADD | SUB) UnaryExpr | Value ;

This should have all the proper associativity and precedence you want. And none of the 
ambiguity.

Depending on the whole grammar, you may need to add options{greedy=true;} here or 
there, but it is impossible to say without seeing the rest of the grammar.

- Mark




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list