CS 453 Programming Assignment #4 — Adding tones, less than, and methods

In this assignment you will extend MeggyJava and hence the compiler to the PA4 subset that includes the playing tones method (Meggy.toneStart), the less than operator, user-defined methods, and method calls.

For PA4 and PA5 joint and separate group reports are required if you are working with a partner or group (see below for details). The joint report should be put in the README file and the separate reports should be emailed to cs453@cs.colostate.edu. Both are due with the assignment itself. The group joint and separate reports will be worth 10% of the programming assignment grade for those of you working in a group.

Here are some example programs: PA4noDef.java, PA4doubleDef.java, and PA4bluedot.java, its symbol table, and its PA4bluedot.java.s file.

Notice that PA4doubleDef is legal Java but illegal MeggyJava (no overloading is allowed in MeggyJava).

The above .s file is from the reference compiler and includes code for passing the pointer to object instances for each method call.

The Assignment

You will Note that even though the grammar enables the declaration of classes, you will not be implementing objects until PA5. You need the syntax of class definitions and calling methods on receivers like "new Foo()" and "this". For this assignment, the focus is on code generation for methods and method calls. Your compiler needs to check for undefined, doubly defined, and incorrectly typed symbols.

NOTE that MeggyJava does not allow passing buttons as parameters to user-defined functions or assigning button values to variables. This is a pedagogical simplification. For PA3 we discussed an approach for generating the checkButton method that relies on the button values to be passed as constants to the checkButton method. If we enabled button values to be assigned to parameters (or later other variables), then we would have to generate more complex code to determine the button value at runtime and therefore check the correct run-time library variable name OR use the GetButtons() method in the provided MeggyJrSimple interface and do some bit vector manipulation.

Tricky Bits

The challenging part of this assignment will be designing and in the code creating a symbol table and generating correct AVR assembly code for functions and function calls, especially recursive functions. We recommend that you design and test your symbol table separately. Additionally, 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. Of course the reference compiler output will help as well.

Common Errors in PA3

Grading Details

We will be compiling and using your compiler as follows:
    happy MJParserPA4.y -i
    ghc --make MainPA4.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 PA4 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 PA4 grammar. The video 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/29/15
kushagra.tiwary@colostate.edu, 4/3/15, added "common errors in PA3"
kushagra.tiwary@colostate.edu, 4/11/15, updated filename requirements for PA4.tar