| Building an LR(1) Machine |
goto(, x ) = { [ N
![]()
1 x .
2 , a ] | [ N
![]()
1 . x
2 , a]
}
of LR(1) items for a grammar G with
productions P, we define closure(
) to be the smallest
set of LR(1) items such that:
) 
1 . N2
2,a]
closure(
)
and N2
3
P
then, for each b
First(
2 a ),
[N2
.
3, b]
closure(
)
(
, x) = closure ( goto (
, x ) )
. S $,
] ) as its
initial state.
E
( L , E )
E
S
L
L , E
L
E
S
ident
S
( S )
1 . , x ] and
either another reduce item of the form [ M
2 . , x ] or
a shift item of the form [ M
alpha. x
2 , y ].
with input x if state
contains a shift item of the form
[ N
alpha. x
, a], reduces using production
N
if state
contains a reduce item of
the form [ N
. , x ] and reports error otherwise.
| Building an LR(1) Machine |