You will be implementing the Generate_Code operation as an extension to the Program component (see the Program section in the class notes for the specs). Your implementation will translate a Program object into the corresponding code for the BugsWorld virtual machine (discussed in class). This is the last phase in the BL translator.
In addition, your implementation will also check for the few possible remaining syntax errors, which were not checked by the parser. These include undefined instructions and direct and/or indirect use of recursion. Use the assert statement to notify users of these errors, just as you did in the previous lab assignment.
The set up instructions will provide you with a user catalog containing the following components and auxiliary items:
The test driver for this lab is the BL translator that reads in a BL program and, if no syntax errors are found, outputs the corresponding code for the BugsWorld virtual machine. To use a demonstration version of the translator, just execute the command 321_Translator < program.bl. If you want to save the output to a file you can use the command 321_Translator < program.bl > program.bo.
cp -r /class/sce/now/321/labs/catalogs/lab4 /project/c321axnn
cd /project/c321axnn/lab4 chmod -R g-l,g+rwX . set-group-ID .
Translator (instead
of 321_Translator).
Since for every syntactically valid BL program, there is a unique object
program for the BugsWorld virtual machine (according to the specs of
Generate_Code), you can check whether your implementation is correct
by comparing the output produced by your translator with the output produced
by the demo version of the translator. (The diff Unix command
can be used to quickly compare two files. Use the man diff
command to find more information about this command.)
In addition, another useful utility is available. It is called
321_Disassembler and can be used to display a BL object file
(a file generated by the translator) using the mnemonic names for the
BugsWorld virtual machine instructions. Invoke it with the command
321_Disassembler < program.bo.
Give it a try, and you will see how it can help you debugging your lab.
rcpp-submit c321?? lab4If you get an error message rather than a confirmation of success, please read the message; it contains useful information! Do not just run the same command again. Save the e-mail you get as a receipt of submission, just in case.