[antlr-interest] Right-to-left binding (was RE: Problem with
AST)
Marcin Rzeźnicki
marcin-rzeznicki at wp.pl
Thu Oct 21 12:13:14 PDT 2004
Bryan Ewbank wrote:
> 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 )?
Hello Bryan,
You are right, second pattern does the right thing. Thank you very much
for your help
--
Greetings
Marcin Rzeźnicki
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