code generation

Viesturs Rikards <>
14 Nov 2004 22:42:43 -0500

          From comp.compilers

Related articles
code generation (2002-01-24)
Re: code generation (Ira D. Baxter) (2002-01-28)
Re: code generation (Boris Boesler) (2002-01-28)
Re: code generation (Pietro) (2002-01-28)
Re: code generation (=?ISO-8859-15?q? (2002-02-06)
code generation (Viesturs Rikards) (2004-11-14)
Re: code generation (2004-11-17)
Code generation mcvax!ruuinf! (1989-02-14)
| List of all articles for this month |

From: Viesturs Rikards <>
Newsgroups: comp.compilers
Date: 14 Nov 2004 22:42:43 -0500
Organization: Compilers Central
Keywords: code, question
Posted-Date: 14 Nov 2004 22:42:43 EST


I'd like to ask some questions about compilers.

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.

For example, if one of rules looks like this:
: some_expr
| identifier_expr '=' expr { code("=",$1,$3); }

Assuming that 'some_expr' and 'expr' can be expanded further (and
contain many other expression that have operators, parentheses etc)
how would you suggest to generate quadruples or triples (intermediate
code)? For instance 'expr' can be a single number like "99" or it can
be a string "x+1", for instance.

I guess 'expr' must be some type of union but how then intermediate
code (triples/quads) can be generated in this instance?

If "code" is some function that generates code then passing argument
doesnt give the correct value because it can be both number or string.

However, if terminals are used as here:
expr: VAR '=' NUMBER { code('=',$1,$3) }

Then variables $1 and $3 give the correct values i.e. the variable
name and some number.

Thank you.

Post a followup to this message

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