CS 453 Programming Assignment #4 — MeggyJava for Buttons

Due Wednesday March 23th (by 11:59pm)

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, and all of the boolean expressions except for the less than operator. You will

The Assignment

You should create a jar file, MJPA4_groupname.jar, that can be executed as follows:
   java -jar MJPA4_groupname.jar InputFile.java
   

The input files can be any PA4 MeggyJava program. The PA4Cylon.java example you wrote for PA2 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 AVR simulator MJSIM.jar (NOTE: this is a new version of MJSIM.jar. We will probably have a new version for each programming assignment). See the Meggy Sim instructions for usage notes. The set of instructions you will need include a file declaration at the top of the assembly file (.file "main.java" ), instructions provided 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 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.

Getting Started

Start with your working PA3 compiler.

Download and untar the ast.tar tarball, which is in ~cs453/public/. Place the ast/ subdirectory within your src/ subdirectory. The ast/ subdirectory should include the node/ and visitor/ subdirectories with all of the ast node subclasses and the visitor framework for programming assignments PA4 through PA7.

Modify your PA3 .cup file so that instead of performing expression evaluation and code generation it generates an AST. See the 3/1/2011 notes about how to generate AST nodes, how to store the AST from the parse, and how to apply the dot visitor to the AST so as to visualize the AST.

Create a concrete visitor (we recommend in a subdirectory under src/ called ast_visitors/) for code generation and byte and integer expression evaluation. Port all of the logic from your PA3 syntax-directed versions of this functionality into the visitor and then make sure that all of your PA3 regression tests still work.

Start adding PA4 features one feature at a time to your lexer, parser, and code generation visitor.

We will cover type checking after break, so the type checking visitor should probably be saved for last.

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 .... March 2, 2011