Re: code generation

torbenm@diku.dk (Torben Ęgidius Mogensen)
17 Nov 2004 11:38:23 -0500

          From comp.compilers

Related articles
code generation malal884@student.liu.se (2002-01-24)
Re: code generation idbaxter@semdesigns.com (Ira D. Baxter) (2002-01-28)
Re: code generation boesler@ipd.info.uni-karlsruhe.de (Boris Boesler) (2002-01-28)
Re: code generation abate@students.cs.unibo.it (Pietro) (2002-01-28)
Re: code generation casse@netcourrier.com (=?ISO-8859-15?q?=22Cass=E9=.Hugues@free.fr) (2002-02-06)
code generation vri@navigator.lv (Viesturs Rikards) (2004-11-14)
Re: code generation torbenm@diku.dk (2004-11-17)
Code generation mcvax!ruuinf!piet@uunet.uu.net (1989-02-14)
| List of all articles for this month |

From: torbenm@diku.dk (Torben Ęgidius Mogensen)
Newsgroups: comp.compilers
Date: 17 Nov 2004 11:38:23 -0500
Organization: Department of Computer Science, University of Copenhagen
References: 04-11-038
Keywords: code, design
Posted-Date: 17 Nov 2004 11:38:22 EST

Viesturs Rikards <vri@navigator.lv> writes:


> What datatype (data structure) would you suggest to use for
> nonterminals like 'conditional_expr', 'expr', 'identifier_expr' etc
> in yacc file for a C like language.


This depends on whether you want to produce an abstract syntax tree
for further processing or if you want to produce code directly (i.e.,
make a "one-pass compiler").


For very simple languages, a one-pass compiler may be the easiest, but
it requires such things as declaration before use of variables and
functions (or back-patching, which may make things ugly). So for
anything nontrivial, I would suggest you make abstract sntax during
parsing and then work on this.


Abstract syntax is in C described most naturally by a tagged union of
structs, i.e., a struct with a tag field (which is an enumerated
type), and a union such that the element of the union is determined by
the tag. Each union element is a struct type with fields for pointers
to subtrees and attributes.


See Andrew Appel's "Modern Compiler Implementation in C" for a
(slightly nonstandard) treatment on how to build and work with
abstract syntax in C.


If you produce code directly, you may only need a symbol table as a
data structure, as code is printed as it is generated.


Aho, Sethi & Ullman's "Compilers - Principles, Techniques and Tools"
is a good source for how to write one-pass compilers.


Torben


Post a followup to this message

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