Re: Trying to find an example of producing intermediate Code in YACC

"Duong Thanh An" <dgthanhan@yahoo.com>
12 Nov 2002 14:13:22 -0500

          From comp.compilers

Related articles
Trying to find an example of producing intermediate Code in YACC dchou1108@hotmail.com (Dave) (2002-11-06)
Re: Trying to find an example of producing intermediate Code in YACC dgthanhan@yahoo.com (Duong Thanh An) (2002-11-12)
| List of all articles for this month |

From: "Duong Thanh An" <dgthanhan@yahoo.com>
Newsgroups: comp.compilers
Date: 12 Nov 2002 14:13:22 -0500
Organization: http://groups.google.com/
References: 02-11-023
Keywords: code,
Posted-Date: 12 Nov 2002 14:13:22 EST

Hi dave,


Generating im. code and byte code is not simple. it depends on what
kind of code you want to generate and how complex you language is.


I do not have experience with Yacc. I used Bison instead. With Bison,
when parsing the souce code, it builds an internal stack that helps
keeping nonterminal symbols'properties. You can make use of this stack
to produce the code recursively.
For example, you have an if statement likes the following:
if ::= if bool-exp then block endif
so, you can attach the action code for this if like this:
{
$$.code.add($2.code); //code if excuting boolean expression
$$.code.add(JUMP_IF_FALSE, $4.code.getSize()); //jump over the block
code if the result of the boolean expression is false
$$.code.add($4.code); //code for executing the body of the if
statement
}


That just a simple case for generating code. For a complete system,
you must have a detailed design for target im. code, instruction set,
...


I've ever had some experience on generating byte code. if you are
interested in this field please mail me at dgthanhan@yahoo.com or
visit our site at


http://www11.brinkster.com/animalsgroup/ to download our thesis about
constructing a scripting simulation system at this site in the
document store (Unfortunately, it is in Vietnamese :().


Duong Thanh An
Animalsgroup online
http://www11.brinkster.com/animalsgroup/


Post a followup to this message

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