Write a predictive, recursive descent (RD) parser for the C- language defined in Appendix A, section 2 of the text.
In a comment above every parsing method that represents a non-terminal, show the rewritten grammar rule that it parses. Use DESCRIPTIVE non-terminal and function names. Use the STANDARD techniques we studied to remove LEFT RECURSION and perform LEFT FACTORING. Aim to avoid ad-hoc techniques, and when you use them, write DETAILED comments explaining your logic. Ensure your entire parser is well-commented.
Use your Lexer class from a previous assignment to obtain tokens.
Take the name of a C- program as a command-line argument. If no argument is specified read from standard input. Use ".cm" as the extension for C- source files.
Output the following in the case of a valid program.
Valid!
Output an appropriate error if the program is invalid. Start line and column numbers with 1. Use the exact format below.
Error while parsing 'construct' Encountered: lexeme (line x, column y) Expected : token(s)
Here's a concrete error message.
Error while parsing 'declaration' Encountered: 'hi' (line 1, column 2) Expected : INT or VOID
You are NOT required to do error recovery.
You may work with a partner. Only ONE team member should submit. Ensure each team member's name is listed in all submitted files.
Submit your driver file "CMinus.cc", "Lexer.cc", "Parser.cc", header file(s), and Makefile. ENSURE your Makefile is named "Makefile" and that it properly builds your program, and that "make clean" removes the executable and all generated files.
You will need to use an ad-hoc technique to handle expression and params. This MIGHT include maintaining a vector of tokens for lookahead flexibility or passing booleans values around.
See the CMinusPrograms directory for numerous test cases.