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 for byte type operands to be used by the multiplication operator.

The Assignment

You will

We will cover shift-reduce parsing and parser generators for shift-reduce parsers starting March 3rd. We recommend that you start by extending your lexer, developing and AST data structure, and developing functions that generate code for your AST and perform type checking. A significant portion of the assignment can be completed before including the parser generated by Happy and your grammar specification with actions that create the AST. START NOW!! This assignment will take time.

Example ASTs

Example ASTs of some test cases are here:

Grading Details

We will be compiling and using your compiler as follows:
    happy MJParserPA3.y -i
    ghc --make MainPA3.hs -o mjc
    mjc TestCase.java
    java -jar MJSIM.jar -b -f TestCase.java.s > t1

    javac TestCase.java
    java TestCase > t2
    diff t1 t2

The input files can be any PA3 MeggyJava program. The output file named InputFile.java.s should be an AVR assembly program that using the provided build process could 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. See the Meggy Sim instructions for usage notes.

We highly recommend you use the regression script (regress.sh) that was covered in the third week's recitation. Create multiple test cases, put them in the WorkingTestCases/ subdirectory and test your mjc compiler against the Java-only output.

Assembly (.s) programs have a prolog and epilog. For PA3 and later assignments, we will let you provide your own input files for these to avoid any grading issues. Make sure to include any files you need in your tar ball.

Execute MJSIM.jar for a list of available instructions. For more details about the instructions see the 06-AVR.txt notes.

For this assignment, there will be no lexer errors, but there will be examples with type errors. Your compiler should catch type errors and print out a reasonable message. We will be manually comparing your messages to those generated by by the Java compiler, javac.

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


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, 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 multiplacation operator