CS 370
Homework Assignment 3
Using Parsing to Produce a Syntax Checker
Due: Friday March 3, 5pm
Take the C grammar YACC file from the class web page, and
combine it with your lexical analyzer to construct a "syntax checker" for
the 370-C language. A "syntax checker" checks whether there were any
lexical or syntax errors. If no errors were found, your program should
print "No errors". If errors were found, your program should print an
appropriate error message and exit.
- Add rules to your makefile to compile the .y file to a .c file,
compile .c to .o, and link into your executable.
- Change your executable name to: cck ("C checker")
- Change your main() to call yyparse() instead of its loop that
called yylex().
- Check yyparse()'s return value to see if it saw a syntax error.
- Add missing tokens to the scanner, if any are in the C grammar
that you don't have already from homework #2.
- Write a function yyerror(s) that prints
the message "syntax error at or before: %s" before printing
the current token's lexeme. Add to this message the line number
and filename at which the error was discovered.