CS 453 Programming Assignment #4 — MeggyJava for Buttons

Due: Thursday, March 29 (by 11:59 PM)

Introduction

This assignment is to be done with your CS 453 programming partner. In this assignment you will be writing a program that parses the PA4 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, binary operators, byte casts, plus, minus, and times, and boolean expressions. See the PA4 Meggy java grammar. Notice the dangling else syntax, and the unary minus syntax.

Java, and therefore Meggy Java allows int, byte mixed type expressions for addition, subtraction, comparison, and negation. This is relevant for type checking as well as code generation.

You will

Check out DotVisitor.java, an example visitor, as discussed in recit. Example ASTs of the provided test programs in TestCasesMeggy are here:

The Assignment

You start with downloading the PA4Empty.tar, and incorporate your PA3 lexer. You will then modify your PA3 .cup file so that instead of performing expression evaluation and code generation it generates an AST. Then, you will extend the provide visitors performing type checking and code generation.

The input files for your compiler can be any PA4 MeggyJava program. The PA4Cylon.java example you wrote for PA1 and PA4buttondot.java are possible test cases for MJPA4_groupname.jar. The output file named InputFile.java.s should be an AVR assembly program that using the provided build process will run on the MeggyJr device. Additionally, the InputFile.java.s file must be such that we can run it through the MJSIM simulator. See the Meggy Sim instructions for usage notes. As in PA3, you need to include prolog and epilog into the .s file

    # Examples of each statement type are provided.
    # Register numbers, constant values, and labels can change.
    ldi    r24,lo8(1)
    ldi    r25,hi8(0)
    ldi    r24,73
    lds    r24, Button_A

    push   r24
    pop    r24

    call   functionName

    tst    r24    
    cp     r24, r25
    breq   MJ_L6
    brne   MJ_L7
    jmp    MJ_L6
    
    LabelWithAnyName:

For more details about the instructions see the 08-MeggyJrSimple-n-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.

This assignment requires the following implementation strategies be used:

For this assignment, type checking will be performed with a visitor. You will probably want a separate visitor using the ReverseDepthFirstVisitor to associate nodes in the AST to line and position numbers. This information will need to be stored in some data structure that is passed to later visitors. Your goal is to match the type error messages that are printed by the provided MJ_PA3.jar parser and type checker.

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.