Example
Construct sets of LR(1) items for the grammar on previous slide
| I0 : |
S ' .S, |
$
|
| |
S .CC, |
$
|
| |
C .cC, |
c
/d
|
| |
C .d, |
c
/d
|
| I1 : |
goto(I0 ,S)
|
|
| |
S ' S., |
$
|
| I2 : |
goto(I 0 ,C)
|
|
| |
S C.C, |
$
|
| |
C .cC, |
$
|
| |
C .d, |
$
|
| I3 : |
goto(I 0 ,c) |
|
| |
C c.C, |
c/d
|
| |
C .cC, |
c/d
|
| |
C .d, |
c/d
|
| I 4 : |
goto(I 0 ,d)
|
|
| |
C d., |
c/d
|
| I5 : |
goto(I 2 ,C)
|
|
| |
S CC., |
$ |
| I6 : |
goto(I 2 ,c)
|
|
| |
C c.C, |
$ |
| |
C .cC, |
$ |
| |
C .d, |
$ |
| I 7 : |
goto(I 2 ,d)
|
|
| |
C d., |
$
|
| I 8 : |
goto(I 3 ,C)
|
|
| |
C cC., |
c/d
|
| I9 : |
goto(I 6 ,C) |
|
| |
C cC., |
$
|
To construct sets of LR(1) items for the grammar given in previous slide we will begin by computing closure of {[S ´ .S, $]}.
To compute closure we use the function given previously.
In this case α = ε , B = S, ß =ε and a=$.
So add item [S .CC, $].
Now first(C$) contains c and d so we add following items
we have A=S, α = ε , B = C, ß=C and a=$
Now first(C$) = first(C) contains c and d
so we add the items [C .cC, c], [C .cC, d], [C .dC, c], [C .dC, d].
Similarly we use this function and construct all sets of LR(1) items.
|
| |
|
|
|