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

Due Tuesday February 19th (by 11:59pm)

Introduction

PA2 is the first programming assignment for CS453 where you can work in a team. Your team will extend a JLex based scanner to include all of the tokens in the MeggyJava language. Additionally you will be writing a parser that can generate AVR assembly code for the PA2 grammar, which is basically just setPixel() statements.

For the scanner part of the assignment, an incomplete regression testing system is provided. This testing system iterates through all input files fname.in in a TestCases directory and compares output with corresponding fname.in.OK files. You are provided with a MJPA2Driver.java program that calls the scanner repeatedly and outputs each symbols that is read in.

Example: The file plus.in contains:

+
+ + +
    + 
  +   + 
+       + 
 +     +
and scanning it should produce the following result (NOTE that the given driver doesn't quite do this. You have to edit it.):
symbol: #2  symbolValue:  [+  at: (1,1)  value: -1]
symbol: #2  symbolValue:  [+  at: (2,1)  value: -1]
symbol: #2  symbolValue:  [+  at: (2,3)  value: -1]
symbol: #2  symbolValue:  [+  at: (2,5)  value: -1]
symbol: #2  symbolValue:  [+  at: (3,5)  value: -1]
symbol: #2  symbolValue:  [+  at: (4,3)  value: -1]
symbol: #2  symbolValue:  [+  at: (4,7)  value: -1]
symbol: #2  symbolValue:  [+  at: (5,1)  value: -1]
symbol: #2  symbolValue:  [+  at: (5,9)  value: -1]
symbol: #2  symbolValue:  [+  at: (6,2)  value: -1]
symbol: #2  symbolValue:  [+  at: (6,8)  value: -1]
The symbol number "#2" corresponds to a constant for the PLUS token (see sym.java generated by the JavaCup tool). A Symbol object contains a token and a SymbolValue objects. SymbolValue objects contain a lexeme, line, position, and integer value. The default integer value is -1. This default value is used to indicate that no extra value is associated with a PLUS token, but a ColorLiteral, a ToneLiteral, or a number will have useful associated values. See the Meggy Java Tokens description in the Resources section of the website for a description of Symbols and their associated values.

For the second part of this assignment, you will be creating the Meggy Java 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 as parameters to the Meggy.setPixel() function calls. You will

The Assignment

To complete this assignment you must:

For the second part of the assignment, you should create a jar file, MJPA2.jar, that can be executed as follows:

   java -jar MJ.jar InputFile.java
   

The input files can be any PA2 MeggyJava program. The PA2Test.java example you wrote for PA1 is a possible test case for MJ.jar. 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. See the Meggy Sim instructions for usage notes.

Assembly (.s) programs have a prolog and epilog. Files for these are provided in avrH.rtl.s and avrF.rtl.s.

The set of instructions you will need include those in the avrH.rtl.s and avrF.rtl.s files and 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

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

Notice that avrF.rtl.s already has an infinite loop at the end of main so that the program will always remain running on the Meggy Jr device even if there is no while loop in the MeggyJava program.

For this assignment, no error handling is necessary. In other words, you can assume the input is correct.

You will start off by downloading ~cs453/public/PA2Start.tar.gz.

Provided Test Cases for Part I

You are provided with various test cases. This set is incomplete. For each token type: (Specials, Reserved Words, Reserved Phrases, Int-Literal, Id, Comments) create files fnm.in and fnm.in.OK, thoroughly testing that type, and provide files errfnm.in and errfnm,in.OK thoroughly testing incorrect tokens of that type, e.g. an errspec.in could contain ">@$" and more.

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.