Assignment 2: Introduction to Parsing
Due: 10/23/03

  1. Consider the grammar

    < S > a | ( < T > )
    < T > < T > , < S > | < S >

    Produce an S-grammar that describes the same languages. (Hints: 1) Look over §5.6 in the F+L or §4.3 in AS+U. 2) Please don't just give me a grammar. Instead, give me an explanation of how you got from the grammar above to your final grammar. 3) If you can't get all the way to an S-grammar, at least give me something which is an S-grammar except that it contains some rules of the form N .
  2. In class, I showed you that a grammar containing the productions

    < stmt > if < expr > then < stmt > end
    | if < expr > then < stmt > else < stmt > end

    could not be deterministically parsed top-down. Please show an example of a non-ambiguous grammar that can not be deterministically parsed bottom-up. (Hint: Remember that "deterministically parsed" means that the parser can decide what action to take next without looking ahead more than some bounded number of characters in the input stream.)


(Global hint: If the grammar you produce for either of these exercises has more that 10 productions you are working much harder than you need to.)


Computer Science 434
Department of Computer Science
Williams College