|code generation firstname.lastname@example.org (2002-01-24)|
|Re: code generation email@example.com (Ira D. Baxter) (2002-01-28)|
|Re: code generation firstname.lastname@example.org (Boris Boesler) (2002-01-28)|
|Re: code generation email@example.com (Pietro) (2002-01-28)|
|Re: code generation firstname.lastname@example.org (=?ISO-8859-15?q?=22Cass=E9=.Hugues@free.fr) (2002-02-06)|
|code generation email@example.com (Viesturs Rikards) (2004-11-14)|
|Re: code generation firstname.lastname@example.org (2004-11-17)|
|Code generation email@example.com (1989-02-14)|
|From:||firstname.lastname@example.org (Torben Ęgidius Mogensen)|
|Date:||17 Nov 2004 11:38:23 -0500|
|Organization:||Department of Computer Science, University of Copenhagen|
|Posted-Date:||17 Nov 2004 11:38:22 EST|
Viesturs Rikards <email@example.com> 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.
Return to the
Search the comp.compilers archives again.