cs152 Lab #3: Code Generation with Mil Interpreter

This week we will hand out the third phase of the class project, which deals with using our Bison and Flex code to output Mil Code. Mil Code is an IR (Immediate Representation), or a pseudo-assembly language that our compiler will generate. We will also complete an exercise that will help you understand the basics of code generation.

Outline for today's lab:

  1. Go over the third phase of the class project
  2. Complete an exercise to help you become familar with the Mil Interpreter
  3. Begin working on the third phase of the class project


Practice with the Mil Interpreter

In this exercise, we will write a code generation specification for simplified version of the Min language. We will take a bison and flex file, and translate that into Mil code. This language will deal with simple addition, multiplication, subtraction, division, mod, and copy statements.

Task 1: Running the Mil Interpreter
1. Download the Mil Interpreter.
2. Execute the command: "scp ~/Downloads/mil_run username@bolt.cs.ucr.edu:~/" to upload mil_run to the server. Please pay special attention to the colon ":" before the ".edu" and "~/". For example, if your email is dtan004, do: scp ~/Downloads/mil_run dtan004@bolt.cs.ucr.edu:~/
3. ssh into the bolt server (e.g. ssh dtan004@bolt.cs.ucr.edu)
4. While on the bolt server, do chmod 777 mil_run to allow the bolt server to execute mil_run
5. Download basic.mil.
6. Execute mil_run basic.mil. Does the program print out 150?


If you are having a difficulty doing this, you may try:
wget https://www.cs.ucr.edu/~dtan004/proj3/mil_run

Task 2: Code Generation
1. Download the starter code here.
2. For each grammar statement, translate that piece of the grammar into Mil Code. You can look up the Mil Specification here. Print the Mil Code to the console.
3. Run your compiler on basic.min. Can your program generate the correct code?
4. Try a more complicated example: math.min. Here is the Mil Code: math.mil.

Task 3: Generating the Symbol Table
1. Study the symbol table. Understand how the symbol table is being built.
2. Use the symbol table to catch an unidentified variable. Try catching the unidentified variable in error.min