Assignment 6

CS 550 Programming Languages
Instructor: Jeremy Johnson 
Due date: Sat. May 30 at 11:59pm

Mini Language Compiler (version 1) (100 points)

In this assignment you will implement a compiler for version 1 of the mini language (i.e. the version without procedures). The target langauge for your compiler will be the RAL instruction set, and you will be able to run your compiled programs on the RAM simulator from lecture 5. Note that you must first extend the RAM simulator to provide MUL and JMN instructions as outlined in the exercises from lecture 5. You should follow the approach outlined in lecture 5. You may reuse the parser and data structure constructed for the mini language interpreter from lecture 2b. You can simply replace the eval method by a translate method, which should construct a list (or vector) of symbolic RAL instructions. Each of the different classes that define the program data structure (e.g. Expr, StmtList, AssignStmtn, IfStmt, WhileStmt) will need a translate method. These methods are implemented using the approach outlined in lecture 5. In addition to the translate method you should provide an optimize method, which applies peephole optimization as outlined in lecture 5. Other optimizations may be applied but they are not necessary.

You will also need to modify the symbol table to store information such as the address in memory that a variable or constant is stored, the type of entry in the symbol table (e.g. constant, variable, temporary). Note that the address field may be "unknown".

You will also need to implement a link method which converts the symbolic RAL instructions to absolute RAL instructions (i.e. hard coded addresses). This may be done after the program is translated and all necessary information is in the symbol table (i.e. the number of constants and their values, the number of program variables, the number of temporary variables, and the number of instructions along with the instruction addresses where labels occur. The link method can be applied to unoptimized or optimized code.

Finally, a compile method simply calls the translate and link methods. The compile method should take an option the indicated whether optimization ir performed or not. After compiling you can dump the RAL program to a file (or standard out) and then you may execute it on the RAM simulator.

Background Information

Background information is available in lectures 5 and 2.

What to do

Modify the mini language interpreter from Lecture 2b (the one without procedures) to provide
  1. a translate method that produces symbolic RAL instructions to exectute the program on the RAM simulator
  2. an optimize method that performs peephole optimization
  3. a link method that produces absolute (i.e. hard coded addresses) code, corresponding to the translated symbolic RAL code, that can be simulated on the RAM simulator
  4. a compile method which calls translate, optionally calls optimize, and then calls link.
  5. an output method that dumps the compiled RAL program.
You must test your compiler and optimizer on several mini language programs.

How to submit

Students should submit their solution electronically using webct. Only one submission is required per group. The group leader for the assignment should submit the assignment. Submit a gzipped tar file, called A5.tar.gz (the tar file should contain a directory called A5 which contains the files). The tar file should contain source code, instructions how to run your programs, sample input and output files, and a README file. You should provide your modified RAM simulator that you used to execute your compiled programs. The README file should describe all files that are included, contain instructions how to build and use the code, and outline how the code works. The README file should also contain a list of all group members and the group leader for the submitted assignment. You should also indicate how you tested your code. If your program is not working, you should clearly state this in the README file. Code should be documented (clear specifications and comments for any tricky parts of the code).