code generation

Viesturs Rikards <vri@navigator.lv>
14 Nov 2004 22:42:43 -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: Viesturs Rikards <vri@navigator.lv>
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

Hello,


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:
expr
: 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
$3
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.