The goal of this assignment is to give you experience generating intermediate representation from code. You will work in teams of two or three students for this.
A starting point for this assignment is in the IntelliJ
project, as4irgen.zip
. The
solution should unpack and build with no errors, at least when using JDK
8. (It will likely build and run with other versions as well, but esubmit
uses JDK 8.) To run, ensure the Project Structure includes the appropriate
version of JDK and then add a start configuration:
0.mj
is good because everything
in it is already implemented except code to evaluate a constant value
expression. Once this is working, you will want to move on to the other
tests. fact.mj exercises a lot of the mini-java language.
-ea
to enable
assertion checks that are in the code. This will help you debug your
solution.
ToTree.java
. See
the TODO statements in this file. You can change other files in the
top directory as well
(Frame.java
, MIPSFrame.java
, ToTreeList.java
, X86Frame.java
),
but it is unlikely you will need to make modifications to these files. Note
that sablecc.jar
has already been run on the grammar file and
that your main is already set up to build the symbol table and typecheck
the program.
Some additional notes on the files you have been given:
ToTree
: the intent is that this will generate an
intermediate representation from the given .mj
source file.
sysprint
, to print integers. We will not support
printing other types of data.
this
, essentially implying all methods are
static
at the moment. We may fix this in a future
assignment.
new
CONST(0)
for uniformity with the tests.
Code
instructions to add documentation in the
output. This helps tremendously when trying to review and debug
compiler output. You will need to match these in your solutions. More
specifically, while
loops are documented by
;;while text of testbefore the loop and
;;end whileat the end. Assignments are documented by
;; id = expression(before the code computing the assignment), and the
new
expression is documented with
;;new classname()where the italicized words are replaced by the appropriate text. Each
;;
comment is preceded by two tab characters.
Not all tests will have sample output because the primary goal of the
assignment is to determine what output to produce. It is also not clear
that every correct solution will produce the same output. The instructor's
solution
produces factorial-output.txt
for the input fact.mj
.
Groups of 3 will have additional requirements. These requirements will not be tested by esubmit, so we may use demos to confirm them.
.length
operation on arrays.
This will include restoring the related productions, storing the
array length in memory at runtime (probably at the start of the array's
location, revising indexing to skip that location), and providing support
for a .length
factor in expressions.
this
and extended classes.
Make sure all group members are documented at the top
of ToTree.java
. Submit your solution to esubmit
as as4ir
. At a minimum, submit ToTree.java
as
the main and ToTreeList.java
as an additional
file. Include any other files you write or modify, but most solutions will
not need additional files. Do not
submit mjava.grammar
; talk to your instructor if you needed to
modify the grammar file for your solution.
Since this is a group assignment, your instructor needs to know which esubmit solution to grade. After your final submission, take a screen shot showing the top part of the submission (with the assignment name, the name of the user doing the submitting, the date, and the number of differences) and submit that screen shot to Canvas.