CS 453 Programming Assignment #5 — MeggyJava for maze solver

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


This assignment is to be done with your CS 453 programming partner. In this assignment you will be writing a program that parses the PA5 subset of the MeggyJava language that includes the playing tones method (Meggy.toneStart), the less than operator, and user-defined functions and function calls. You will Note that even though the grammar enables the declaration of classes, you will not be implementing objects until PA6. You need the syntax of class definitions and calling methods on a receiver like "new Foo()" or "this" to keep Java happy and for PA6 and PA7. The code you will be generating will treat all functions as if they are in the same scope.

For this assignment, the focus is on code generation for function calls and therefore all of the input programs will be syntactically and semantically correct.

The Assignment

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

The input files can be any PA5 MeggyJava program. The PA5Cylon.java example you wrote for PA2 and PA5MazeSolver.java are possible test cases for MJPA5_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 updated for PA5). 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
    # top of a function declaration
    .global Cloudrain
    .type Cloudrain, @function

    # indirect stores and loads
    std    Y+1, r24
    ldd    r24, Y + 3

Also see PA5bluedot.java.s for the assembly code that the reference compiler generates for PA5bluedot.java. NOTE that you do NOT have to generate the same assembly code, you just need to generate assembly code that results in MJSIM.jar spitting out the same text messages as the text only version.

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:

Other than the above, you have complete freedom as long as the result is a working compiler.

Getting Started

The following is a suggested progression for starting this assignment:
  1. Start with your working PA4 compiler.

  2. 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. For example, you could implement the PA5raindrop.java example from PA2 by hand in AVR. It is ok to look at the avr-gcc generated assembly file while doing this, but you need to make sure you can generate the code and that the code goes through MJSIM.jar. In class we will be talking about how you need to allocate a space on the run-time stack for each of your parameters and load that value as needed.

  3. Extend your .lex and .cup files for the new grammar features.

  4. Modify your code generator visitor so that it can handle a function definition and a function call where main just passes x, y, and color to a method in another class and that method does a Meggy.setPixel().

  5. Use additional features in your test inputs such as using parameters in complex expressions and Meggy.toneStart(). Modify the code generator visitor to handle these new features.

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 23, 2011