Step 2: Parser -- Due: Friday, September 19, 11:59pm

Introduction

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:

Parser structure

Parser Generation Tools and Their Tutorials

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:

The Task

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:

  1. Write the parser using one of the tools suggested above;
  2. Modify your lexer in the first step to feed tokens to parser instead of printing them;
  3. Your parser should print "Accepted" to the standard output if the input file is accepted by the language's grammar or "Not accepted" otherwise.
  4. Make sure your parser doesn't produce any shift-reduce errors. You may loose points if you have such errors.
See the Piazza page for some tips on working on step2.

Testcases

Testcases can be downloaded here. Note that only ECE 573 students need to handle testcase 22

How to handle "Not accepted"

Sample Solution

To help you better test your compiler, you can try running inputs through our sample solution (a JAR file, which can be run with java -jar).

Submission

You will lose 10% of total credit if you failed to follow the following rules.

Expected Directory Structure of Your Project

See this page for instructions regarding the directory structure of your project.

Expected Behavior of Your Compiler

Assuming the above directory structure is used

References