Creating a parser
CSCI 4627
Spring 2002

Due: Feb. 19.

Write a parser for the C- language described in the appendix of the text. Use the following guidelines. Please do not ignore these guidelines; they define the assignment.

  1. The parser should only check whether the program is syntactically correct. It should print "good" if the program is syntactically correct and "syntax error at line ***" otherwise, where *** is replaced by the line number where the first syntax error occurs.

    Errors such as using an undeclared variable, or type errors, are not considered syntax errors. They are semantic errors, and will be checked for in a different part of the compiler.

  2. Use your lexer for lexical analysis. Provide any support functions that you find convenient.

  3. Write the parser using recursive descent. It should be easy to determine, from the name of a function, to which nonterminal it corresponds. Do not attempt to write the parser by ad-hoc means. It is simplest to put all of the functions in one file. If you feel it is necessary to break the program up into more than one file, keep the number of files small.

  4. You might need to make some changes to the grammar to make it top-down parsable (LL(1)). Include, near the top of your parser, a complete grammar, as it is after you have modified it.

    For each nonterminal in the grammar, list the First and Follow set. Include them as comments in the parser.

    Ensure that your recursive descent parser follows your grammar closely. If you find yourself making a change to the grammar while writing the parser, be sure to change the comment that describes the grammar as well.