For this 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 writing the lexer using strategies that were discussed in class the week of September 6th. For your parser, many of you will probably implement a recursive descent parser as was discussed in class the week of September 12th. Other approaches are also acceptable including using the Happy parser generator or parser combinators. Your group is responsible for encoding the grammars to these tools if you use them. Do NOT use anyone else's encoding. Your parser will use syntax-directed code generation to translate the input MeggyJava program to AVR assembly. We will be placing all of your Haskell source files into the src/ directory of a stack project called mjcPA2. Compiling and using your compiler will proceed as follows:
stack build MJCPA2 stack exec MJCPA2 TestCase.java java -jar MJSIM.jar -b -f TestCase.java.s > t1 // Executing the Java-only version with the meggy/ package. javac TestCase.java java TestCase > t2 diff t1 t2
The input files can be any PA2 MeggyJava program. 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. Read the comments in the file header to see how it works. 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 prologue and epilogue. Use this provided Util.hs directly or something like it to generate the necessary prologue and epilogue.
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
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.
tar cvf PA2.tar README revision-control.txt *.hs
turnin cs453PA2 PA2.tarEACH person should submit a tar ball. Of course, we expect that tar balls within a group will be identical. YES this is different than PA1 on purpose.