Write a recursive-descent parser that recognizes the C2008 language as defined in the handouts from project 2 and the revised grammar (see the web page for a copy). Use good style (including meaningful variable names and appropriate indentation) in your coding and use Javadoc-style comments. You must use Java on cerebro.
Your parser must be a class called Parser in a package called parser and must read tokens using the scanner you developed for project 2. The parser object will be created in the main program, called MainParser.java. The top-level parser function should be called doParse; this will start the parsing of the source file. The parser must determine whether the source code represents a valid C2008 program. The structure of the parser should be that described in class, where there is a function associated with each non-terminal and a case statement associated with each production. Include panic mode error recovery, where an error message (indicating the specific problem, line, and line number) is printed and the parser attempts to recover by scanning until a symbol in the Follow set of the erroneous non-terminal (or EOF) is encountered.
In addition to any error messages, the parser method doParse should return the number of errors encountered. The main program should then print a message at the end indicating how many total errors were encountered. There should also be a traceparse option that, when turned on, will print a message at the beginning and end of the parse for each non-terminal. Use numbering and/or indentation so that the user can easily see where one non-terminal starts and ends. I'll post an example of the output. This option should be controlled from the command line. Your parser does not need to produce an abstract syntax tree (this will be project 4).
In order to complete this assignment, you must first compute the First and
Follow sets for each symbol and the Lookahead set for
each production. Turn in the grammar with
these sets with your project.
As always, you will also be graded on the quality of your test cases – you should turn in the test cases with your project. The test cases should have comments that indicate what each is testing. Also include a file called readme.txt that describes the status of your parser (does it work correctly on everything? If not, describe when it doesn’t work).