For the second part of the 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 using the lexer you wrote in PA2b to provide a list of tokens to your predictive parser. Your predictive parser will use recursive descent parsing and syntax-directed code generation to translate the input MeggyJava program to AVR assembly. We will be compiling and using your compiler as follows:
ghc --make MainPA2b.hs -o mjc mjc TestCase.java java -jar MJSIM.jar -b -f TestCase.java.s > t1 javac TestCase.java java TestCase > t2 diff t1 t2
The input files can be any PA2 MeggyJava program. 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, MJSIM.jar. See the Meggy Sim instructions for usage notes.
We highly recommend you use the regression script (regress.sh) that was covered in the third week's recitation. 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 prolog and epilog. Files for these are provided in ~cs453/public/ (avrH.rtl.s and avrF.rtl.s). Recall the IncludeFile.hs code from the regression testing recitation. 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
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. However, we recommend generating errors for cases you are not handling by using an error call like in the 15 minute compiler recitation example.
You will need to submit a picture of your MeggyJr with a picture that you have programmed with the PA2 grammar. The picture should be in png format and the filename should be demoPA2.png.
svn log svn infoThe output should be from subversion or similar output from any other revision control tool.
tar cvf PA2.tar README revision-control.txt demoPA2.png Lexer.hs MainPA2b.hs