CIS 606. Translator Design I

Programming Project 2

The second programming assignment is to construct a predictive parser for PSub, based on the LL(1) grammar derived in Homework 2.

This assignment will be due at the start of class on Wednesday, June 12. To be fair to the other students, I will not grant extensions; if your code is not working by the deadline, submit what you have and I will try to assign partial credit. You may work in pairs (but not in larger groups); in fact, I would encourage this method if you are comfortable working with someone else, as it means less work for the grader!

As with all programming assignments, it will not be sufficient to simply produce code that works---it must also be adequately structured and documented. If any changes are required to your lexer from Project 1, you should submit that revised code as well.

The interface to the parser should be a function ParseProgram() which attempts to recognize an entire PSub program on the standard input. It should not return anything; instead, as the program is parsed the following should be printed:

The effect of this will be to print out a preorder traversal of the parse tree. If an error is found, you should print out a message giving the current line number, what was expected (which token or variable), and what token was actually found, and then quit.

The main program will just perform any needed initialization and then call ParseProgram(). When it returns, you should check that there is no remaining unparsed input, then exit. Note that nothing more needs to be done with the symbol table for this phase.

You should submit a printout containing all the source code for your parser and main program, plus the result of running the main program on the same example program from Project 1 (which is still in the file /pub/CIS606/pp1input on the cis machines). As mentioned above, you should also submit Homework 2 at this time, as well as any changes that were required to the code from Project 1 (hopefully none).

Original Grammar for PSub

Brian Howard (bhoward@cis.ksu.edu)