Garbage CollectionTop The Correctness of LR(0) parsing About this closure stuff...

About this closure stuff...

  1. When we build an LR(0) machine we use the following algorithm to compute closures:
  2. We can prove that each item in closure() is valid for using an argument based on showing that the claim that execution of the loop body preserves the "invariant" that all items in ' are valid for .
    basis?
    All items in are assumed valid for , so the invariant will be true when the loop begins to execute..
    induction?
    Assume that all item in ' are valid for and let [ M . 3 ] be the item added during an execution of the loop body. The addition of this item implies that some item of the form [ N 1 . M 2 ] must have already been in '. By the assumption that the invariant holds at the beginning of each execution of the loop body, this item 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 . Therefore, adding this item to ' preserves the invariant.
  3. 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

Garbage CollectionTop The Correctness of LR(0) parsing About this closure stuff...