[antlr-interest] Right-to-left binding (was RE: Problem with AST)

Bryan Ewbank ewbank at synopsys.com
Thu Oct 21 05:56:41 PDT 2004


Hi Marcin,

I struggled with how to do right-to-left operator evaluations as well, and
the examples sidestep it by stopping the calculator example
at multiplication (exponentiation is right-to-left).  What I figured out
was:

For a left-to-right operator, you use the standard production:

	left_to_right:	operand ( OP^ operand )*

For a right-to-left operator, you use recursion on the rightmost element;
also notice that the production
uses a "?" instead of a "*" - A "*" is ambiguous because ANTLR can't know
whether to recurse, or return:

	right_to_left:	operand ( OP^ right_to_left )?

> From: Marcin Rzeźnicki [mailto:marcin-rzeznicki at wp.pl]
> Just one more question. I started to think about that idea and I have
> become aware of fact that transformation like these destroys operator
> connectiveness. It seems to me that all operators bind to the left. Is
> there any way to achieve right binding? For example: a OP b OP c ( OP
> stands for binary operator) will become #(OP #(OP a b) c), I would like
> to be able to implement in some cases #(OP a #(OP b c)).



 
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