Description#
This first assessed project builds on the familiarity you gained with JavaCC in building the scanner for the MoJo language. The parser consumes the tokens recognised by the scanner from the input file. Initially, your parser will simply take an input and decide if it is a syntactically correct MoJo program. Once you have this working you will use your parser to construct an abstract syntax tree (AST) for the input program.
This project is worth 7% of total course mark.
Getting Started
You should fork the Project 2 repository on gitlab. Begin first by grafting your token definitions from Lab 1 into this new template. If your scanner still needs more work, you can keep at it, or you can ask for help from the us to get it working.
Your first step is to write JavaCC grammar rules so that your parser recognizes whether an input is a syntactically correct MoJo program. Once you have this working you will then use semantic actions in your parser to construct an abstract syntax tree (AST) for the input program.
- The framework for building the AST and printing out the results is
available in
src/mojo/Absyn.java. - You do not need to edit this file
- However, in order for it to work correctly you will need to complete
the token definitions in your
src/mojo/Parser.jjfile with the proper names.
You can run the parser and print out the AST it builds using the command:
java -cp bin mojo.Absyn <input_file.mj>
Before starting this project familiarise yourself with Chapters 3 and 4 of the textbook, and with the lecture notes. In addition to the lectures these will give you a solid foundation for starting your parser.
Expected Output#
The class mojo.Absyn contains a main method that loads files,
invokes the parser, and prints the result. The grading script and test
cases expect the format output by this method, which is essentially a
“pretty printed” AST. Make sure your program does not add any
extraneous output to standard output and make sure to run against the
provided tests. Our grading script ignores the standard error output.
Testing#
Test go into the tests subdirectory, along with their expected
outputs. You can run the tests using the grade.sh script. Feel free
to devise new tests, and share your tests with your classmates (we
don’t prommise that what we have given you is comprehensive). We will
also curate any tests you contribute and add them to the repository.
Turn in and grading#
- You should do all of your work in your own gitlab fork of the project. Make sure to commit and push your work to gitlab frequently so you maintain a record of your work, and to keep track of your changes.
- You do not need to turn anything in: we can see your forked repository and will be grading fromn their directly. Just make sure to commit and push your work to gitlab by the deadline.
- We will rebuild your submissionn from source with your Makefile.
- We will run the grading script on your code with additional test inputs that are not included in the repo.
- We will provide the additional test inputs along with your score after the deadline.
- Make sure your program doesn’t print anything extra to the standard output!
Deadline#
Your work should be committed and pushed to your forked gitlab repo by 11:59pm on 13 March 2023.