[antlr-interest] Change operator precedence in a AST
Joan Pujol
joanpujol at gmail.com
Sun Sep 26 14:37:12 PDT 2004
On Sun, 26 Sep 2004 16:38:02 -0400, Bryan Ewbank <ewbank at synopsys.com> wrote:
> Joan Jesús said:
> > How can I change the precedence of operator of my AST
> > to reflect the operator precedence in Java.
> > Someone has some example?
>
> I'm puzzled. In an AST there isn't really precedence - you just evaluate
> bottom-up. Are you looking for guidance in rewriting/rotate the trees to
> reflect a change in precedence? E.g, something like this?
>
> Given:
> (+ A (* C D))
> Produce:
> (* (+ A C) D)
Yes, exactly.
The problem is that I generate the AST using the operator's precedence
of my language. But then when I want to use the AST to translate to
the target language I can't use my AST directly to output code because
the priority of operators change. And I don't know how to manage this
easily.
Cheers,
--
Joan Jesús Pujol Espinar
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