
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

CIS 400 Spring 2008
The second part of the programming project is to implement the parser for the source language Decaf. For this part of the project, we will write a recursive descent parser. For the recursive descent parser, you can use the modified Decaf grammar as developed in class that is essentially LL(1). The template programs are partially based on the Linz programs, but were extended to construct and Abstract Syntax Tree. The class TestParser.java reads the source file as input and calls the main Parser function parse. The class Parser.java has all the definitions of token variables from the Scanner class and also has token names for printing error messages. The main method, parse, keeps track of the last token processed and the next token processed. It initializes the Scanner and the error function, and calls the method ParseProgram. ParseProgram is the first of the recursive descent methods that should parse according to the Decaf grammar rules. You should complete this method and write the other methods to make up the parser. Each parsing method should return an AbstractSyntaxTree node (using class ASTnode) to represent what it parsed. The error message method is set up to have error synchronization points at the beginning and end of every Statement and Expression and also at the end of blocks. In addition, it doesn’t print extra error messages in a row. The class ASTnode represents the abstract syntax trees. It will use an integer to encode what type of syntax node it represents, with 0 representing terminal symbols in the grammar. If it is a terminal symbol, then the ASTnode has a Token and otherwise it has a list of child nodes. The one initial test case of the gcd program should also work for the parser. You may wish to design simpler cases to get started with a minimal number of parse methods. Due Dates: By Thursday, March 19, midnight, submit files to blackboard, zipped or not, as convenient. (Right after spring break.) What to hand in: Design and test document, can be named README, or some other obvious name, describing design decisions and test results. Program files, including code documentation.