Assignment 3: Introduction to LR(0) Parsing
Due: 11/10/03

  1. (This question is stolen from Fisher and LeBlanc) Construct the LR(0) machines for each of the following grammars. Which grammars are not LR(0)? Explain why.
    1. S L $
      L L ; E
      L E
      E x

    2. S L $
      L E ; L
      L E
      E x

    3. S L $
      L L ; L
      L E
      E x

    4. S L $
      L x T
      T
      T ; L

    (Note: The in grammar (d) is meant to represent the empty string. )

  2. If you think about it for a while, there is something annoying about our definition of a viable prefix. Basically, the problem is that it would be nice if the formal definition corresponded to the intuitive interpretation of the term "viable prefix" -- namely a prefix that has a chance of being completed to form a valid string in the language.

    Taking into account the fact that we are only interested in right-most derivations, an apparently obvious alternate definition intended to capture what we have in mind might be:

    Def.
    We say that a string (Vn U Vt)* is a feasible prefix for G if is different from S and there exists a rightmost derivation
    S
    for some string Vt*.

    The definition used in class, by contrast is:

    Def.
    We say that a string (Vn U Vt)* is a viable prefix for G if there exists a rightmost derivation
    S N 1 2
    for some N Vn, 1, 2 (Vn U Vt)* and Vt* such that = 1.
    How do these two definitions relate to one another? Are they equivalent? In particular:
    1. Does being a feasible prefix imply that a string must be a viable prefix?
    2. Does being a viable prefix imply that a string must be a feasible prefix? For each of these questions, justify your answer giving proofs or counter examples as approriate.

    In your answer, you should assume that the grammars involved contain no useless non-terminals. That is, assume that every non-terminal derives some string of terminal symbols.


Computer Science 434
Department of Computer Science
Williams College