Java Reference
In-Depth Information
function C
losure
( state ) returns Set
ans state
repeat
prev ans
14
foreach A
→α•
B
γ∈ ans do
15
foreach p
P
roductions
F
or
( B ) do
ans ans ∪{
B
→•
RHS( p )
}
16
until ans = prev
return ( ans )
end
procedure C
ompute
G
oto
( States , s )
closed
C
losure
( s )
17
foreach
X∈
( N ∪Σ
) do
18
RelevantItems
A
dvance
D
ot
( closed ,X
)
19
if RelevantItems
then
Table [ s ][
X
]
shift A
dd
S
tate
( States , RelevantItems )
20
end
Figure 6.10: LR(0) closure and transitions.
State 0
Goto
State 3
Goto
State 4
Goto
$
E
Start
→•
E $
3
Start
E
$
4
Start
E $
E
→•
plus E E
1
E
→•
num
2
num
plus
num
State 1
Goto
State 2
Goto
E
plus
EE
5
E
num
plus
E→• plus E E
1
E→• num
2
num
plus
E
E
State 5
Goto
State 6
Goto
E→plus E • E
6
E→plus E E •
E
→•
plus E E
1
E
→•
num
2
Figure 6.11: LR(0) computation for Figure 6.2, shown as a
characteristic finite-state machine. State 0 is the initial state,
and the double-boxed states are accept states.
 
Search WWH ::




Custom Search