CS 453 Programming Assignment #2 — MeggyJava Scanner and setPixel Compiler

Introduction

For PA2, you will be creating the MeggyJava to AVR compiler for the PA2 subset of the MeggyJava language that enables any number of pixels to be set with Meggy.setPixel() and will include byte casts of constant integers as parameters to the Meggy.setPixel() function calls. You will The github repositories for this assignment can be created by going to https://classroom.github.com/group-assignment-invitations/31150ef71e0fd6eb2f66fa1c7e87da18.

The Assignment

For this assignment, you need to create a compiler that translates the PA2 grammar for MeggyJava into AVR assembly code that is executable by MJSIM.jar. You will be writing the lexer using strategies that were discussed in class the week of September 6th. For your parser, many of you will probably implement a recursive descent parser as was discussed in class the week of September 12th. Other approaches are also acceptable including using the Happy parser generator or parser combinators. Your group is responsible for encoding the grammars to these tools if you use them. Do NOT use anyone else's encoding. Your parser will use syntax-directed code generation to translate the input MeggyJava program to AVR assembly. We will be placing all of your Haskell source files into the src/ directory of a stack project called mjcPA2. Compiling and using your compiler will proceed as follows:

    stack build MJCPA2
    stack exec MJCPA2 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 PA2 MeggyJava program. 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. 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.

Assembly (.s) programs have a prologue and epilogue. Use this provided Util.hs directly or something like it to generate the necessary prologue and epilogue.

Your first test case should just test whether the prolog and epilog are generated correctly. Then you need to parse and generate code for Meggy.setPixel() statements.

For setPixel code you need assembly code instructions a little like the following:

        # Examples of each statement type are provided.
        # Register numbers, constant values, and function names can change.
        ldi    r24,lo8(1)
        ldi    r24,73
        call   functionName

For this assignment, no error handling is necessary. In other words, you can assume the input is correct. However, we recommend generating errors for cases you are not handling by using an error call like in the 15-minute compiler recitation example.

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.arizona.edu, 9/6/16
9/26/16, took out reference to demoPA2.png