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

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()
  2. When we build an LR(0) machine we use the following algorithm to compute closures:
  3. 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 '.


Computer Science 434
Department of Computer Science
Williams College

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