Assignment 03 - MiniJava to miniIR Translator
| Release Date | 07/09/2026 |
| Deadline | 18/09/2026, 23:59 hours |
This assignment is graded out of 15: 9 for this take-home part and 6 for an extension you implement in the lab session on 22/09/2026. See the assignments page for how the lab component works.
This assignment is the third part of a multi part project to write an optimizing compiler for MiniJava. We start with type checked MiniJava programs and generate programs in miniIR format. Akin to a standard optimizing compiler, in this assignment, we will implement a module that translates programs in a high level language minijava to programs in intermediate form miniIR.
miniIR still permits nested expressions: an operand of an instruction may itself be a computation. Flattening those into one-operation-per-instruction form (microIR) is the subject of assignment 4.
Use JTB and JavaCC and write in Java one or more visitors which translate MiniJava programs to miniIR form. Your main file should be called P2.java, if A.java contains a program to be simplified then
$ javac P2.java
$ java P2 < A.java > A.miniIR
should create A.miniIR in miniIR form and is semantically equivalent to A.java. Note, your program must take input from standard input and write to standard output (so that we can use redirection).
To check that a program is in miniIR form, you could tie the miniIR.jj to build a parser. To ensure that your miniIR program is semantically equivalent to the A.java program, you can use the interpreter of miniIR interp-miniIR.jar to compare the output of A.java with the output of your generated program; say the generated miniIR code is stored in A.miniIR, then to invoke the interpreter use: java -jar interp-miniIR.jar < A.miniIR.
Alternatively, make compiles the assignment, make run FILE=<input> runs it,
and make clean removes the .class files you must delete before submitting.
Note: Please do not alter the directory structure of RollNo_P2.
Only edit GJDepthFirst.java and P2.java
Resources
The source files are on Github.
Get the source by cloning the entire repo:
$ git clone https://github.com/fplaunchpad/cs3300_m26
If you have already cloned the repo, you can get the latest updates by:
$ cd cs3300_m26 # go to the cloned repo
$ git pull
The MiniJava grammar specification is here.
The miniIR grammar specification is BNF-miniIR.
Slides from a previous offering are available as A3_slides. Note that they translate MiniJava straight to microIR, combining this assignment with assignment 4; the material on generating IR from MiniJava still applies.
Submission
Rename the folder RollNo_P2 with your roll number. For example, if your roll
number is cs99b999, then the folder should be named cs99b999_P2. Remove all
the .class files before submission. For example, you can do:
$ cd cs99b999_P2
$ find . -name "*.class" | xargs rm
Then produce the compressed gzip archive as follows:
$ tar cvzf cs99b999_P2.tar.gz cs99b999_P2
Submit the .tar.gz file.
Note: You should thoroughly test your code. Some sample mini java programs are provided for testing. Create positive and negative tests per feature and test your code before submission. Please ensure that there are no compilation errors. If there are compilation errors, that code will yield zero marks.
Checking your work before you submit
Run the same program that marks you over the public testcases:
$ python3 ../selftest/eval.py <YOUR-ROLLNO>_P2.tar.gz
It builds your archive the way the grader does, so a packaging mistake shows
up here instead of costing you marks. Note that assignment 3 submits as
_P2, one behind the assignment number.
There are three sets of testcases: the public set you can run here, a private set behind the online checker that reports only how many passed, and a hidden set used for marking that you never see. You are marked on all three together, every test counting equally, so passing the first two is necessary and not sufficient. A submission that does not build scores zero.
See selftest/README.md.