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. You will also be adding error handling to your lexer and parser. The error messages should include line and column information that the lexer provides with Tokens.

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. Your compiler does not have to generate a pointer to object instances yet for PA4.

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.

For lexical analysis, your compiler needs to handle lexer errors by printing out an error message for the first lexer error seen. If you print more error messages that is fine. For syntactic analysis (parser), your compiler needs to handle parsing errors by printing out an error message for the first parser error seen. If you print more error messages that is fine. For semantic analysis (type checking) your compiler needs to check for undefined, doubly defined, and incorrectly typed symbols (parameters and method names). Just catching the first type error is sufficient.

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.

Another difficult piece will be adding line and column information to the tokens provided by lexical analysis. This line and column information will make error messages much more useful.

Break things into small testable pieces.

Groups for PA4

Groups can be of size 1 to 5 for PA4.

You can create a github repository for PA4 by going to the PA4 assignment in the github classroom for cs453.

Grading Details

Compiling and using your compiler will proceed as follows:
    stack build MJCPA4
    stack exec MJCPA4 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 PA4 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.

You will need to submit a video of your MeggyJr with a MeggyJava program that only demonstrates the features in the PA4 grammar. The picture should be named PA4demo.something, where something is .mov or whatever video format you used for PA1.

Submitting the Assignment

Grading

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/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
mstrout@cs.arizona.edu, 10/24/16, updated for Fall 2016