Your goal in this step is to generate the parser for the project's grammar. By the end of this step your compiler should be able to take a source file as the input and parse the content of that file returning "Accepted" if the file's content is correct according to the grammar or "Not Accepted" if it is not.
Now the scanner created in the first step will be modified to feed the parser. Instead of printing the tokens, the scanner has to return what token is recognized in each step. The following diagram shows the basic structure of a simple compiler and hightlights the steps that will be completed at the end of this step:
Similar to the scanner case, there are tools that automatically generate parsers based on context-free grammar descriptions. More precisely, there are parser generators for two main classes of context-free grammars: LR(1) and LL(k). Please, refer to the textbook or one of the references at the end of this handout for the theory of LL(k) and LR(k) parsing.
For this project we recommend two main parser generation tools:
At this step you have to create the code for the parser of your compiler. We recommend you to do that using one of the tools described above, although the whole parser could be written manually without the help of any tool.
The following basic steps should be followed:
Testcases can be downloaded here. Note that only ECE 573 students need to handle testcase 22
Java and ANTLR
In Antlr, a parse error throws an exception. So you would have to write an exception handler that catch "ANTLRException" which is the base class of all exceptions in antlr.
C/C++ and Flex/Bison
When an error occurs in Bison/YACC, the error handler "yyerror" will be invoked. You should customize this handler to print the message and terminate current program.
You will lose 10% of total credit if you failed to follow the following rules.
See this page for clearer instructions regarding the directory structure of your project.
Assuming the above directory structure is used
If Java and ANTLR are used, the following command will be run from the root of your project directory
$ java -cp lib/antlr.jar:classes/ Micro <path to test cases>/test.micro Accepted $
If C/C++ and Flex/Bison are used,
$ <build directory>./Micro path_to_your_testcases/test.micro Accepted $