CS 453 Programming Assignment #4 — MeggyJava for Buttons
Due: Thursday, March 29 (by 11:59 PM)
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
PA4
subset of the MeggyJava language that includes the detection of
button presses (Meggy.checkButton), the use of the delay function
(Meggy.delay), the function for reading the screen pixel values
(Meggy.getPixel), the while statement, the if statement, binary
operators, byte casts, plus, minus, and times, and boolean expressions.
See the PA4 Meggy java grammar.
Notice the dangling else syntax, and the unary minus syntax.
Java, and therefore Meggy Java allows int, byte mixed type expressions
for addition, subtraction, comparison, and negation. This is
relevant for type checking as well as code generation.
You will
- add the PA4 grammar rules to the parser,
- perform syntax-directed construction of an Abstract Syntax Tree (AST),
- perform type checking in a checkType visitor, and
- perform code generation to AVR assembly code for all PA4 statements using AVRgen visitor.
Check out DotVisitor.java, an example visitor, as discussed in recit.
Example ASTs of the provided test programs in TestCasesMeggy are
here:
The Assignment
You start with downloading the PA4Empty.tar, and
incorporate your PA3 lexer. You will then
modify your PA3 .cup file so that instead of performing expression evaluation
and code generation it generates an AST. Then, you will extend the provide visitors performing
type checking and code generation.
The input files for your compiler can be any PA4 MeggyJava program. The PA4Cylon.java example
you wrote for PA1 and PA4buttondot.java are possible test cases for MJPA4_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 MJSIM simulator.
See the Meggy Sim instructions for usage notes.
As in PA3, you need to include prolog and epilog into the .s file
# 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:
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. The parser is no longer allowed to generated code or evaluate expressions.
- Unlike in PA3, all expression evaluation needs to be done with AVR code since
the return value from
Meggy.checkButton() is not known until runtime.
- The two concrete visitors provided, CheckTypes and AVRgenVisitor, need to be extended.
For this assignment, type checking will be performed with a visitor.
You will probably want a separate visitor using the ReverseDepthFirstVisitor
to associate nodes in the AST to line and position numbers. This information
will need to be stored in some data structure that is passed to later visitors.
Your goal is to match the type error messages that are printed by the
provided MJ_PA3.jar parser and type checker.
Submitting the Assignment
-
Make sure you test your implementation thoroughly.
-
Only turnin one assignment per group.
- Extend your Test Cases directory with a complete set of meggy jave codes covering all syntactic constructs in the PA4 language.
- Explain your file structure and compiler functionality in a README file
- Create the MJPA4_groupname.tar file that contains all the source code, the .class files, your .cup
and .lex files, README file,
TestCases, and a subversion.txt file. We should be able to use the jar file to run your PA4 MeggyJava compiler.
-
The subversion.txt file should include output from the following:
svn log
svn info
-
Submit assignment using checkin utility.
~cs453/bin/checkin PA4 MJPA4_groupname.tar
-
Sanity Check (procedure TA will use to grade your assignment):
tar -xf MJPA4_groupname.tar
cd PA4
// We will also run the test cases with different arg_opts files.
java -jar MJPA4.jar TestCase.java
java -jar MJSIM.jar TestCase.java.s > t1
javac TestCase.java
java TestCase > t2
diff t1 t2
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.