[antlr-interest] Re: Building trees with the correct associativity
    lgcraymer 
    lgc at mail1.jpl.nasa.gov
       
    Wed Dec  1 19:53:46 PST 2004
    
    
  
--- In antlr-interest at yahoogroups.com, "Paul J. Lucas"
<pauljlucas at m...> wrote:
> On Thu, 2 Dec 2004, lgcraymer wrote:
> 
> > I miswrote the second case which should have been
> > 
> > addExpr
> >     :
> >     mulExpr  (addOp addExpr)?
> >     ;
> > 
> > and you can do the rewrite within the ()?.
> 
> 	That still doesn't work: the tree is still right-associative,
> 	i.e., 5 - 2 + 3 equals 0 instead of 6.
> 
> > Out of curiosity, why are you avoiding the more compact
> > 
> > addExpr
> >     :
> >     mulExpr (addOp^ mulExpr)*
> >     ;
> > 
> > The binary trees avoid inserting the extra node.
> 
> 	Because that's illegal syntax in ANTLR 2.7.x.  addOp is not a
Well, yeah, which is why (PLUS | MINUS) and (MUL | DIV) get sprinkled
through expression grammars.
> 	token.  But this is orthoganal to the problem at hand.
I'm not at all sure of that.  I think that the observation that the
normal tree construction here (via ^ annotation) is left associative.
 That's not an obvious point.
--Loring
> 	- Paul
 
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