Chapter 4: Syntax Analysis

Example

. Consider following grammar and its SLR parse table:

S ' S
S L = R
S R
L *R
L id
R L
I0 : S' .S
S .L=R
S .R
L .*R
L .id
R .L
I1 : goto(I0 , S)
S' S.
I2 : goto(I0 , L)
S L.=R
R L.

Construct rest of the items and the parse table.

Given grammar:

S L = R

S R

L *R

L id

R L

Augmented grammar:

S ' S

S L = R

S R

L *R

L id

R L

Constructing the set of LR(0) items:

Using the rules for forming the LR(0) items, we can find parser states as follows:

I0 : closure(S ' .S)

S ' .S

S .L = R

S .R

L .*R

L .id

R .L

I 1: goto(I0 , S)

S ' S.

I2 : goto(I0 , L)

S L.=R

R L.

I3 : goto(I 0 , R)

S R.

I4 : goto(I0 , *)

L *.R

R .L

L .*R

L .id

I5 : goto(I0 , id)

L id.

I 6 : goto(I2 , =)

S L=.R

R .L

L .*R

L .id

I 7 : goto(I 4 , R)

L *R.

I 8 : goto(I4 , L)

R L.

goto(I 4 , *) = I 4

goto(I4 , id) = I5

I 9 : goto(I6 , R) S L=R.

I10 : goto(I 6 , L) R L.

goto(I 6, *) = I 4

goto(I6 , id) = I 5

So, the set is C = { I0, I1, I2, ... I10 }