How to understand Example-4.64 of the syntax analysis chapter in Dragon Book?

53 Views Asked by At

everybody!

When I learn dragon book, I encountered some trouble. I can't understand the first step in Eaxmple-4.64, which appears in subsection 4.7.5 and page 273.

Problem

At first, Eaxmple-4.61 gives an augmented non-SLR grammar. The original text is as follows:

Example 4.61 : We shall use as an example of the efficient LALR(1) table construction method the non-SLR grammar from Example 4.48, which we reproduce below in its augmented form:

S' -> S
S  -> L = R | R
L  -> *R | id
R  -> L

Then, Eaxmple-4.64 wants to construct the kernels of LALR(1) items for the above grammer. The original text is as follows:

Eaxmple-4.64 : Let us construct the kernels of the LALR(1) items for the grammar of Example 4.61. The kernels of the LR(0) items were shown in Fig. 4.44. When we apply Algorithm 4.62 to the kernel of set of items I0, we first compute CLOSURE({ [S'->.S , #] }), which is

S' -> .S, #
S  -> .L = R, #
S  -> .R, #
L  -> .*R, #/=  // why is there a "=".
L  -> .id, #/=  // why is there a "=".
R  -> .L, #

And the pseudo code CLOSUER(I) as follows:

enter image description here

But I think the answer is:

S' -> .S, #
S  -> .L = R, #
S  -> .R, #
L  -> .*R, =  // the difference
L  -> .id, =  // the difference
R  -> .L, #

I don't know how the # is derived in L -> .*R, #/= and L -> .id, #/=. Could anybody tell me the reason. Thanks!

1

There are 1 best solutions below

1
rici On

Both of them come from the closure of the item R→.L, #, which maps to A→α.Bβ, a with A=R, α=ε, B=L, β=ε, a=# so that FIRST(βa) is {#}, leading to the addition of both productions for L with lookahead #.