Prev Up
Go backward to The Correctness of LR(0) parsing
Go up to Top

About this closure stuff...

  1. Recall the definition for the closure of a set of LR(0) items:
    closure
    Given a set of LR(0) items for a grammar G with productions P, we define closure() to be the smallest set of LR(0) items such that:
    1. closure()
    2. if [N1 1 . N2 2] closure() and N2 3 P then [N2 . 3] closure()
    and the algorithm given for computing the closure of a given set of LR(0) items:
  2. How can we prove that the sets described by the definition and produced by the algorithm are the same?

    By identifying the invariant of the loop. Namely:

    At the beginning (and end) of each iteration of step (b), ' is a subset of the closure of .

    These facts establish that ' will always be a subset of closure( ). If the loop terminates, then we know that ' must contain closure( ) and therefore ' = closure( ). Luckily, the loop must terminate since there are only a finite number of LR(0) items that step (b) could add to '.

  3. We can prove that each item in closure() is valid for by induction on the number of iterations of the loop in the algorithm to compute the closure executed before the item was included in '.
    basis
    If an item was added in 0 steps it must be an element of and is therefore valid for by assumption.
    induction
    Assume that any item added in less than n steps is valid for and let [ M . 3 ] be the item added at step n. The addition of this item implies that some item of the form [ N 1 . M 2 ] must have been added at an earlier step. By our inductive assumption this item that was added earlier must be valid for . Accordingly, there must be some derivation:
    S' N 1 M 2
    with = 1. Assuming the grammar has no useless non-terminals, it must be possible to derive some string of terminals, ' from 2. Thus, there is a derivation:
    S' N 1 M ' 1 3 '
    The existence of this derivation implies that the item [ M . 3 ] is valid for .
  4. Now, assuming Lemma 1, we can prove Lemma 2 by induction on the length of . The basis step is so simple that we will look at the induction step first:
    induction
    Assume that we know that the theorem holds for all strings of length n and consider some string x such that is of length n and x is a single symbol.

    Suppose that [ N 1 x . 2 ] is an item in ( 0, x ). The fact that this item is in this set implies that the item [ N 1 . x 2 ] must be in ( 0, ). This, together with our inductive assumption implies that [ N 1 . x 2 ] must be valid for . Therefore, there exists a derivation:

    S' N 1 x 2
    with 1 = . This, however implies that [ N 1 x . 2 ] is indeed valid for x.
    basis
    Similarly, when we consider strings of length 0, the only kernel item in ( 0, eps) is [ S' . S]. The derivation S' S' S shows that this item is valid for eps.

Computer Science 434
Department of Computer Science
Williams College

Prev Up