Related articles |
---|
Position of an Intermediate Code Generator dirkduck2@hotmail.com (Chris Rowland) (2002-07-15) |
Re: Position of an Intermediate Code Generator torbenm@diku.dk (Torben Ægidius Mogensen) (2002-07-21) |
Re: Position of an Intermediate Code Generator hannah@schlund.de (Hannah Schroeter) (2002-07-21) |
Re: Position of an Intermediate Code Generator marcov@toad.stack.nl (Marco van de Voort) (2002-07-31) |
Re: Position of an Intermediate Code Generator pfroehli@ics.uci.edu (Peter H. Froehlich) (2002-08-04) |
From: | "Hannah Schroeter" <hannah@schlund.de> |
Newsgroups: | comp.compilers |
Date: | 21 Jul 2002 02:06:06 -0400 |
Organization: | Schlund + Partner AG |
References: | 02-07-060 |
Summary: | Basic compiler structure, answering a question about how to integrate intermediate code generation into a compiler |
Keywords: | code, design |
Posted-Date: | 21 Jul 2002 02:06:05 EDT |
Hello!
Chris Rowland <dirkduck2@hotmail.com> wrote:
>[... question on how to integrate an intermediate code generator
> into a simple compiler ...]
I'd do this:
- Parse the source, building an AST (like) data structure
- here, you can add additional analysis, attaching information to
the AST (semantic analysis). If you don't need that part in the
beginning, leave it empty, but you know where to add it later
- Perhaps to AST level optimizations (leave that empty in the beginning),
modifying the AST.
- Now, in one or more separate passes over the AST, you build the
first intermediate code (which might happen to be the final code,
e.g. if you generate stack based virtual machine code from a not
too complicated source language / AST structure, and use an
interpreter to execute the virtual machine code).
- Maybe, do optimizations on the IR level, maybe translate the IR
further into other IRs, and on each level, maybe optimize more.
- "Unparse" the final IR into your translator's output
(unless you're going to run an interpreter immediately on the
internal IR data structures).
I.e. in short: Build an AST in your parser, make your IR generator
work on that AST afterwards.
Kind regards,
Hannah.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.