CSE 321 Lab 4


Lab 4 Table of Contents


Objective

The objective for this assignment is to implement the Program_Generate_Code component, which is an extension to the Program component.


Overview

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.


Materials Provided

The set up instructions will provide you with a user catalog containing the following components and auxiliary items:

You will need to:

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.


Set Up

  1. Copy the lab4 course catalog to your group project directory (/project/c321axnn, where "x" is your section letter and "nn" is your team number):
    cp -r /class/sce/now/321/labs/catalogs/lab4 /project/c321axnn
    
  2. Make sure that the new catalog will be accessible to your partner. Perform this action now and as your last act whenever you finish a working session. Note that 'l' in the chmod command is the letter 'l' ("el"), as in "lock":
    cd /project/c321axnn/lab4
    
    chmod -R g-l,g+rwX .
    
    set-group-ID .
    
  3. Look around the new user catalog to familiarize yourself with its contents.

Using the Test Driver

The test driver for this lab is the BL translator that uses your implementation of Generate_Code for Program. You can execute it just like the demo version (as explained in the Materials Provided section) but calling it 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.


What To Submit

Once you and your partner are convinced that all implementations are working correctly, get into your group's lab4 directory /project/c321axnn/lab4 in an xterm window and use the rcpp-submit command to submit your solution as follows (noting that you will need to use the appropriate suffix in place of ?? in this command, as posted next to your instructor's name on the CSE 321 Home Page):
rcpp-submit c321?? lab4
If 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.