CpSc 423, Language Processor Techniques

Assignment 3

due May 20

Intermediate Code Generation

For the final project of the semester, add semantic actions to your parser to generate Three-Address Code.

Like previous assignments, your program should take the name of a file containing a program on the command line and write 3AC to standard output. The parser should continue to function as before (i.e., write an error message and quit if the input contains syntax errors). You do not need to dump the symbol table; simply generate 3AC.

Details

Use the syntax shown here for 3AC. Assume an unlimited number of available memory locations and that location 0 always contains 0.

Example

Assuming that n has been assigned memory location 1, i has been assigned location 2, and sum has been assigned location 3, your program should produce 3AC for the factorial example program similar to the following:
	0:  (addi, 9, 0, 1)
	1:  (addi, 1, 0, 3)
	2:  (addi, 1, 0, 2)
	3:  (addi, 9, 0, 4)
	4:  (lt, 2, 4, 5)
	5:  (eq, 2, 4, 6)
	6:  (or, 5, 6, 7)
	7:  (beq, 7, 0, 13)
	8:  (mul, 3, 1, 3)
	9:  (addi, 1, 0, 8)
	10: (sub, 1, 8, 1)
	11: (addi, 2, 8, 2)
	12: (j, 0, 0, 4)
	13: (wrt, 3, 0, 0)
	14: (hlt, 0, 0, 0)
Note the word similar -- this code was generated by hand. The code your program produces may differ, as long as it produces the correct answer.