[antlr-interest] Re: Building trees with the correct associativity

Paul J. Lucas pauljlucas at mac.com
Wed Dec 1 19:00:40 PST 2004


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
	token.  But this is orthoganal to the problem at hand.

	- 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