Re: Expression simplifier.

Rasmus Anthin <e8rasmus@etek.chalmers.se>
30 Apr 2001 00:50:44 -0400

          From comp.compilers

Related articles
Expression simplifier. e8rasmus@etek.chalmers.se (Rasmus Anthin) (2001-04-29)
Re: Expression simplifier. e8rasmus@etek.chalmers.se (Rasmus Anthin) (2001-04-30)
Re: Expression simplifier. Brian.Inglis@SystematicSw.ab.ca (2001-04-30)
Re: Expression simplifier. idbaxter@semdesigns.com (Ira D. Baxter) (2001-04-30)
Re: Expression simplifier. e8rasmus@etek.chalmers.se (Rasmus Anthin) (2001-05-03)
| List of all articles for this month |

From: Rasmus Anthin <e8rasmus@etek.chalmers.se>
Newsgroups: comp.compilers
Date: 30 Apr 2001 00:50:44 -0400
Organization: Chalmers University of Technology
References: 01-04-145
Keywords: optimize, comment
Posted-Date: 30 Apr 2001 00:50:44 EDT

> \ B. Rasmus Anthin
> / e8rasmus@etek.chalmers.se
> / www.etek.chalmers.se/~e8rasmus
> [I'd have a set of tree rewriting patterns, e.g. X+0 -> X -John]


Hmmm... But then I have to transform the tree into a binary tree in order
to accomplish this, right?
If I have: "8+3+y" this would then give me a AST like this:


                                                      expression
                                              / / | \ \
                                        / / | \ \
                                    term addop term addop term
                                      | | | | |
                                  factor '+' factor '+' factor
                                      | | |
                                  primary primary primary
                                      | | |
                                    id id id
                                      | | |
                                    '8' '3' 'y'


And the binary tree would then look like:


                +
            / \
          + y
      / \
    8 3


Elimination would then give


                +
            / \
          11 y


Is this correct? And if this is the case, then how would I implement this?
Will I have to transform the eliminated binary tree into an AST again and
then traverse it in order to receive an eliminated expression?


I have the dragon-book, "Writing Compilers and Interpreters" (R. Mak) ,
"Crafting a Compiler with C" (Fischer,LeBlanc) and "Compiler
Construction" (Niklaus Wirth). Can I find anything about it there? I have
looked for it there at a glance but couldn't find anything of use there.




Sincerely,


//Raz
[Yes, see the next few messages. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.