Milestone 4

Objectives

The objective of this week's assignment is to ensure that you have functional parser stubs for your parser.

To Do

Using this context free grammar for μPascal, construct nonterminal stubs for your parser. You can find a description of how to do these stub here near the bottom of the page. Essentially, there will be a method for each non terminal in the grammar. That method is responsible for expanding itself when it is called. That is, the method for a nonterminal (e.g., ) will be called only when it is the leftmost nonterminal at the current phase of the parse. This nonterminal will expand itself based on the lookahead symbol. How this happens is not important right now. Just note the following. More will be presented in class.
  • There should be a case statement that switches on a global lookahead variable.
  • The case statement should have case clauses for each rule in the grammar that has the nonterminal of this method on the left, plus one (the "others" clause) for the error condition.
  • Each method should have pre- and post-conditions.
  • Each case clause should be commented with the rule number and actual rule it expands.
  • In each case clause, the right hand side of the appropriate rule should be expanded:
  • Wherever a token appears, a call to a new method, Match, must be made with the token as an argument;
  • wherever a nonterminal appears, a call to that nonterminal's method must be inserted.
  • In the "others" clause, a call to a new method, Error, must be made.
  • You will need to provide stubs for Match and Error as well.
  • The case selectors must, of course, be of your proper Token_Type, and you will need to insert dummy tokens for now in order to make it possible to compile the stubs.
  • In some cases you may know the proper tokens to make the correct selection. You may insert them at this point. You can change them later if you are wrong.
  • Without knowing the proper tokens to insert, your nonterminal methods will not actually be able to call other nonterminal methods, so make sure your stubs to not try to execute such calls. One way to do this is to ensure that the dummy value you insert for the lookahead always takes the "others" route, where you can print your message from last time, as in "Expression has not yet been implemented." You will be removing these messages one at a time as you later completely implement these stubs.
  • Finally, you will need to insert temporarily a series of calls in your parser that calls each of the nonterminal methods and the Match and Error methods, just to see that the program works to the extent that each method can be called. Remember that each team member is to get a subset of the nonterminals to implement as stubs.

To Turn In

You will not be required to turn anything in for this milestone. Just have your source and executable files ready for examination in the lab if called on.