|Position of an Intermediate Code Generator firstname.lastname@example.org (Chris Rowland) (2002-07-15)|
|Re: Position of an Intermediate Code Generator email@example.com (Torben Ęgidius Mogensen) (2002-07-21)|
|Re: Position of an Intermediate Code Generator firstname.lastname@example.org (Hannah Schroeter) (2002-07-21)|
|Re: Position of an Intermediate Code Generator email@example.com (Marco van de Voort) (2002-07-31)|
|Re: Position of an Intermediate Code Generator firstname.lastname@example.org (Peter H. Froehlich) (2002-08-04)|
|From:||"Hannah Schroeter" <email@example.com>|
|Date:||21 Jul 2002 02:06:06 -0400|
|Organization:||Schlund + Partner AG|
|Summary:||Basic compiler structure, answering a question about how to integrate intermediate code generation into a compiler|
|Posted-Date:||21 Jul 2002 02:06:05 EDT|
Chris Rowland <firstname.lastname@example.org> 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.
Return to the
Search the comp.compilers archives again.