CSE5317/4305 Project #2 (Parsing)

Due Friday March 6 before midnight

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 you are free to update your pcat.lex file too. You should cover all the syntactic constructs described in the PCAT manual.
Note: Please remove the following line from pcat.cup:

    static { System.out.println("*** Downloading the PcatParser solution classes."); }

Your grammar productions in your final submitted pcat.cup file should not contain any semantic action, but before you submit your project, you may put some print actions in some grammar productions to trace your parsing. For example, you may write the rule:

expr := expr PLUS expr {: System.out.println("reduce by E<-E+E"); :}
Note: Before you submit your file, remove all your actions.

You need to test your parser against all the test files *.pcat in the directory tests. For example, to test hello.pcat, you execute:

run 2 tests/hello.pcat
where 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:
solution 2 tests/hello.pcat
You need to test your scanner against all the test files *.pcat in the directory tests. You can do this using: run 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.

After ensuring that your program compiles and executes correctly, remove all your actions from your grammar productions and cleanup your pcat directory using

Then, if you are using Linux/MacOS, archive your pcat directory using tar cfz pcat.tgz pcat. If you are using Windows, zip the pcat directory into the file pcat.zip. Then submit your file (pcat.tgz or pcat.zip) here:

Submit Project #2:

Last modified: 02/19/15 by Leonidas Fegaras