[antlr-interest] Re: Change operator precedence in a AST

lgcraymer lgc at mail1.jpl.nasa.gov
Mon Sep 27 01:04:07 PDT 2004


You still can use the AST to generate code--just insert parentheses in
the appropriate spots.

--Loring

--- In antlr-interest at yahoogroups.com, Joan Pujol <joanpujol at g...> wrote:
> On Sun, 26 Sep 2004 16:38:02 -0400, Bryan Ewbank <ewbank at s...> 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