Here is a sample C solution to Assignment 1. Questions and comments are welcome.
All files used in the solution are available in the given tarball.
To access the files, download the tarball (as a binary file) copy it to a
directory on dwarf such as
$HOME/public/pli/exx/, and unpack
the tarball with the command
$ tar xzf jmc.tgzThis will create a directory
jmccontaining all the files.
To use your new copy of the solution, enter the new directory, run
make, then run the parser
./parse with an
optional source file name argument. With no command line argument, the
parser reads from standard input. The parser writes errors to standard
output and the syntax tree to file
The solution is minimal. It lacks adequate comments, and would be
penalised for this (I may yet go back and add comments). Its
distinguishing feature (in my opinion) is its use an intermediate
yylex() function which is called by the parser and which
calls the actual lex-generated scanner. This approach allows some tree
construction in the scanner and keeps the actions in the yacc
specification simpler. The alternative approach of keeping the scanner
simpler and making the parser more complex is equally valid. Note that
we've tried hard to be consistent with naming conventions and presentation.
But please let me know of any functional errors or stylistic weaknesses that you note.