CS 453 Programming Assignment #3 — MeggyJava CheckButton Compiler (Control Flow, Parser Generators, and ASTs)
In this assignment you will be writing a program that parses, type checkes,
and generates code for the
PA3
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,
byte casts, plus, minus, and times, and boolean expressions.
Notice the dangling else syntax, and the unary minus syntax.
Java, and therefore MeggyJava allows int, byte mixed type expressions
for addition, subtraction, comparison, and negation.
This is relevant for type checking as well as code generation.
Note that the MeggyJava grammer allows only byte type operands
to be used by the multiplication operator.
The Assignment
You will
- modify your PA2 lexer to handle one-line and multi-line comments in Java,
- modify your PA2 parser
so that it does syntax-directed construction of
an Abstract Syntax Tree (AST) instead
of doing code generation,
- perform type checking for the PA2 grammar in a function that accepts
an AST as input and calls error with a reasonable message
if there is a type error,
- perform code generation to AVR assembly code for the PA2 AST nodes
with another function, and
- incrementally add the PA3 features to the lexer, parser,
AST creation, type checking, and code generation.
- This time a demo that illustrates the PA3 MeggyJava features
will be required! The demo should be videotaped.
Example ASTs
The reference compiler creates an AST and has a function that
converts the AST to a dot file.
Example ASTs of some test cases are here:
The reference compiler AST design is no great shakes. It can definitely
be improved upon, and I look forward to seeing better designs coming from
the class.
Groups for PA3
Groups can be of size 1 to 5 for PA3.
You can create a github repository for PA3
by going to the PA3 assignment in the
github classroom for cs453.
Grading Details
Compiling and using your compiler will proceed
as follows:
stack build MJCPA3
stack exec MJCPA3 TestCase.java
java -jar MJSIM.jar -b -f TestCase.java.s > t1
// Executing the Java-only version with the meggy/ package.
javac TestCase.java
java TestCase > t2
diff t1 t2
The input files can be any PA3 MeggyJava program.
The InputFile.java.s file must be such that we can run
it through the AVR simulator, MJSIM.jar.
If you need additional Haskell libraries, you need to post a message on
Piazza indicating you would like to use the external library.
We will reply with a .cabal file that will be used to grade ALL projects.
This means everyone will then be able to use that same external library.
We highly recommend you use the regression script regress.sh. Read the comments in the file header
to see how it works.
Create multiple test cases,
put them in the WorkingTestCases/ subdirectory and test your mjc
compiler against the Java-only output.
For this assignment, there will be no lexer errors, but there
will be examples with type errors. Your compiler should catch
the first type error and print out a reasonable message. We will be manually
comparing your messages to those generated by by the Java compiler, javac.
They do not need to be identical, but you do need to catch the errors.
The MeggyJava compiler requires the additional error that integer multiplication
is not allowed.
You will need to submit a video of your MeggyJr with a MeggyJava program
that only demonstrates the features in the PA2 and PA3 grammars.
The picture should be named demoPA3.something, where something is
.mov or whatever video format you used for PA1. You can
talk during the demo.
Submitting the Assignment
Grading
- 5% README file
- 5% revision-control.txt file
- 5% demo file
- 15% Compiler detects first type error for all PA3 grammar productions
- 70% Compiler generates AVR executable by MJSIM.jar for the
PA3 MeggyJava grammar.
PA3 Peer Review Criteria
The following will be the recommended peer evaluation criteria:
- "Readable source code. Using line breaks to separate logically similar sections of code (for example in the Lexer Token data type)."
- "Would a student in a different University's compiler class find this easy to reason about?"
- Remove all unneeded code from PA2.
- Clean separation of concepts into modules and consistency of the code formating across
the different modules.
- How well is the error handling separated out?
Additionally the PA3 peer review will include rating the group's PA3 demo.
Late Policy
Late assignments will be accepted up
to 24 hours past the due date for a 20%
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 and 11:59pm and one second.
If your assignment is late, it will not be included in the peer review process.
mstrout@cs.colostate.edu, 3/2/15
mstrout@cs.colostate.edu, 3/23/15, updated Grading percentages to include type errors
kushagra.tiwary@colostate.edu, 4/3/15, added note about multiplication operator
mstrout@cs.arizona.edu, 9/26/16, modified for turnin procedure at UA
mstrout@cs.arizona.edu, 10/8/16, included the peer evaluation criteria