CS 453 Programming Assignment #5 — MeggyJava for maze solver
Due Wednesday March 30th (by 11:59pm)
Introduction
This assignment is to be done with your CS 453 programming partner.
In this assignment you will be writing a program that parses the
PA5 subset of the MeggyJava language
that includes the playing tones method (Meggy.toneStart),
the less than operator, and user-defined functions and function calls.
You will
- add the tokens for the PA5 MeggyJava to the PA4 lexer,
- add the PA5 grammar rules to the parser,
- and update the code generation visitor to handle the new language
features.
Note that even though the grammar enables the declaration of classes,
you will not be implementing objects until PA6. You need the syntax
of class definitions and calling methods on a receiver like "new Foo()"
or "this" to keep Java happy and for PA6 and PA7. The code you
will be generating will treat all functions as if they are in the same
scope.
For this assignment, the focus is on code generation for function calls
and therefore all of the input programs will be syntactically
and semantically correct.
The Assignment
You should create a jar file, MJPA5_groupname.jar, that can be executed as follows:
java -jar MJPA5_groupname.jar InputFile.java
The input files can be any PA5 MeggyJava program. The
PA5Cylon.java example
you wrote for PA2 and
PA5MazeSolver.java are possible test cases for MJPA5_groupname.jar.
The output file named InputFile.java.s
should be an AVR assembly program that using
the provided build process will run on the MeggyJr device.
Additionally, the InputFile.java.s file must be such that we can run
it through the AVR simulator MJSIM.jar (NOTE: this is
a new version of MJSIM.jar updated for PA5).
See the Meggy Sim instructions for usage notes.
The set of instructions you will need include a file declaration at the top
of the assembly file (.file "main.java"
), instructions provided in the
avrH.rtl.s and avrF.rtl.s
files and the following:
# Examples of each statement type are provided.
# Register numbers, constant values, and labels can change.
ldi r24,lo8(1)
ldi r25,hi8(0)
ldi r24,73
lds r24, Button_A
push r24
pop r24
call functionName
tst r24
cp r24, r25
breq MJ_L6
brne MJ_L7
jmp MJ_L6
LabelWithAnyName:
# top of a function declaration
.text
.global Cloudrain
.type Cloudrain, @function
Cloudrain:
# indirect stores and loads
std Y+1, r24
ldd r24, Y + 3
Also see PA5bluedot.java.s for the assembly code
that the reference compiler generates for PA5bluedot.java. NOTE that you do NOT have to generate
the same assembly code, you just need to generate assembly code that results
in MJSIM.jar spitting out the same text messages as the text only version.
For more details about the instructions see
the 08-MeggyJrSimple-n-AVR.txt notes.
Notice that avrF.rtl.s already has an infinite
loop at the end of main so that the program will always remain
running on the Meggy Jr device even if there is no while loop in
the MeggyJava program.
This assignment requires the following implementation strategies be used:
- An AST must be built by the parser.
- You should keep the check visitor class from PA4.
- The AVR code must be generated by a concrete visitor.
Other than the above, you have complete freedom as long as the result
is a working compiler.
Getting Started
The following is a suggested progression for starting this assignment:
- Start with your working PA4 compiler.
- Write some functions and function calls in AVR by hand. The AVR code
you write should be something you could generate with the AVR code
generator visitor. Make sure the assembly code you are using works
for recursive functions. For example, you could implement the PA5raindrop.java
example from PA2 by hand in AVR. It is ok to look at the avr-gcc generated
assembly file while doing this, but you need to make sure you can generate
the code and that the code goes through MJSIM.jar. In class we will
be talking about how you need to allocate a space on the run-time stack
for each of your parameters and load that value as needed.
- Extend your .lex and .cup files for the new grammar features.
- Modify your code generator visitor so that it can handle a function
definition and a function call where main just passes x, y, and color
to a method in another class and that method does a Meggy.setPixel().
- Use additional features in your test inputs such as using parameters
in complex expressions and Meggy.toneStart(). Modify the
code generator visitor to handle these new features.
Submitting the Assignment
-
Make sure you test your implementation thoroughly.
-
Only turnin one assignment per group.
- Create the MJPA5_groupname.jar file that contains all the source code, the .class files, your .cup and .lex files, a README file, and a subversion.txt file. We should be able to use the jar file to run your PA5 MeggyJava compiler.
You do NOT have to include MJSIM.jar or the meggy package into your jar file.
You will probably have to add filenames to the provided Makefile in the command that creates the jar file.
-
Submit assignment using checkin utility.
~cs453/bin/checkin PA5 MJPA5_groupname.jar
-
Sanity Check (procedure TA will use to grade your assignment):
// We will also run the test cases with different arg_opts files.
java -jar MJPA5_groupname.jar TestCase.java
java -jar MJSIM.jar -b -f TestCase.java.s > t1
javac TestCase.java
java TestCase > t2
diff t1 t2
// to get the README, subversion.txt, look at source files,
// and view any other required files
jar xf MJPA5_groupname.jar
Late Policy
Late assignments will be accepted up to 48 hours past the due date for a 10%
deduction. The assignment will not be accepted past this period.
Late means anything after 11:59pm
on the day the assignment is due, including 12 midnight.
mstrout@cs.colostate.edu
.... March 23, 2011