Worth 15% of your project grade
This project must be done individually. No copying is permitted. The purpose of this project is to construct a parser for PCAT using CUP. Study the CUP manual, the parser simple_calc.cup for the simple calculator, and the PCAT manual.
You will work on the same directory pcat from Project #1.
The only file that you need to modify is
the pcat.cup file that contains your
parser, but may also update your pcat.lex file too, if necessary.
If you are using Eclipse, you can debug your parser using
the CUP Eclipse Plugin.
You should cover all the syntactic constructs described in
the PCAT manual.
Your grammar productions in your final submitted pcat.cup file should not contain any semantic actions. You need to test your parser against all the test files *.pcat in the directory tests. To compile the source files in the directory pcat, do:
mvn clean installTo test hello.pcat, you execute:
scala lib/pcat.jar 2 tests/hello.pcatwhere 2 indicates that you are testing the second project. The output will consist of error messages only (if any). To see if you got everything right, you should modify the test files a little bit in various places so they cause syntactic errors (remember to replace them back after you are done). For example, what will happen when you parse (x+)? You also need to compare your output with that of the solution:
scala pcat-solution.jar 2 tests/hello.pcatYou need to test your scanner against all the test files *.pcat in the directory tests. You can do this using: scala pcat-solution.jar 2 tests/*.pcat.
Your pcat.cup file should not have any reduce/reduce errors (-10 points for each reduce/reduce error) and should have as few shift/reduce errors as possible (-2 points for each shift/reduce error). Use proper operator precedence/associativity to avoid these errors. Use option -dump_states in CUP to display the states and find the conflicts. Hint: in addition to operators, think also about the precedence of ELSE, ELSIF, and LPAREN. One common mistake is to put operators separately from their use (eg, operator ::= PLUS | MINUS | .... This will mess up the operator precedence in expressions.
After ensuring that your program compiles and executes correctly, remove all your actions from your grammar productions and cleanup your pcat directory using
mvn cleanThen archive your pcat directory into the file pcat.zip. Then submit your file using the following form:
Last modified: 02/17/2016 by Leonidas Fegaras