In this assignment you will implement a syntactic analyzer for the Decaf language.
To assist the parser in recognizing syntax errors, Yacc provides error tokens. The dragon book suggests that error recovery be associated with "major" nonterminals that generate expressions, methods, statements, and classes. Using error tokens with finer-grained nonterminals allows you to report as many errors as possible but may hopelessly confuse the parser. Error productions on coarser-grained nonterminals allows the parser to continue longer but may miss reporting a large number of errors. You should experiment with error tokens and their placement to see what works best for you.
Any errors detected by the lexical analyser should be reported, and error tokens should not be passed to the parser. Deleting these tokens may cause parse errors, but passing them would not be helpful either.
Your syntactic analyzer should produce two outputs:
< ClassDeclaration > -> class identifier < ClassBody >
The nodes should be printed in preorder. Hence, the productions that are output will form a leftmost derivation. Leaf nodes should not be printed, since they will occur on the righthand side of the appropriate productions.
The two sections of the output should be distinct. The error output should appear first, and then the parse tree output should follow. The output from the lexical analysis assignment, with the exception of the error messages, should be eliminated. Thus, you should print no messages about tokens recognized.
You should do all your developement within a single directory. When you are ready to submit the assignment, create a directory in your home directory called submit_parser and copy all your files into this submission directory. Be sure to provide a make file so I need only unpack your files, run make, and then execute your program.
Your syntactic analyzer will be tested against a variety of test files.
You source code should use comment blocks to explain any non-obvious operations (for example, how you handle errors).
The possible number of points for this assignment is 10. Points are weighted as follows:
Correct and complete parse tree built and displayed for correct Decaf programs |
6 |
Error messages are informative | 2 |
Program builds flawlessly | 1 |
Source code is readable and well commented |
1 |