|Trying to find an example of producing intermediate Code in YACC firstname.lastname@example.org (Dave) (2002-11-06)|
|Re: Trying to find an example of producing intermediate Code in YACC email@example.com (Duong Thanh An) (2002-11-12)|
|From:||"Duong Thanh An" <firstname.lastname@example.org>|
|Date:||12 Nov 2002 14:13:22 -0500|
|Posted-Date:||12 Nov 2002 14:13:22 EST|
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
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 email@example.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
Return to the
Search the comp.compilers archives again.