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 . N2
2]
closure(
)
and N2
3
P
then
[N2
.
3]
closure(
)
)
' equal to
.
1 . M
2 ]

'
such that M
3
P and
[ M
.
3 ] 
' add
[M
.
3 ] to
'.
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
.
.
3 ] that the iteration will
add must also be a member of closure(
) by the
definition of closure.
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
'.
) 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
'.
and is therefore valid for
by assumption.
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'with![]()
N
![]()
![]()
1 M
2
= 
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'The existence of this derivation implies that the item [ M![]()
N
![]()
![]()
1 M
'
![]()
![]()
1
3
'
.
3 ] is valid for
.
. The basis step is so simple that we will look
at the induction step first:
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'with![]()
N
![]()
![]()
1 x
2

1 =
. This, however implies that
[ N
1 x .
2 ] is indeed valid for
x.
(
0, eps) is
[ S'
. S]. The derivation
S'
S'
S
shows that this item is valid for eps.