I4
S→aS·Sb
S→aS·SS
S→·aSSb
S→·aSSS
S→·c S c a I5 I2 I3 I5
S→aSS·b
S→aSS·S
S→·aSSb
S→·aSSS
S→·c S a b c I7 I3 I6
I2 I6
S→aSSb· I7
S→aSSS·
(4) 状态 项目集 经过的符号 到达的状态 I0
S’ →·S
S→·A
A→·Ab
A→·a S A a I1 I2 I3 I1
S’ →S· I2
S→A·
S→A·b b
I4 I3
A→a· I4
S→Ab·
解:
(1)是LR(0)文法,其SLR(1)分析表如下:FOLLOW(S)={#,b,c}
ACTION GOTO a b c # S 0 S2 1 1
ACC 2 S2 S4 3 3 S5 S6 4 R3 R3 R3 5 R1
R1 R1 6 R2 R2 R2
(2)是LR(0)文法,其SLR(1)分析表如下:
FOLLOW(S)=FOLLOW(A)=FOLLOW(B)={#}
ACTION GOTO a b c # S A B 0
S2 1 1
ACC 2 S5 S4 3 3
R1 4 S5 S8 S7 3
6 5
R4 6
R2 7 S5 S9 10 8
R6 9 S5 S8 S7 10 11 10
R3 11
R5
(3)是LR(0)文法,其SLR(1)分析表如下:FOLLOW(S)={#,a,b,c}
ACTION GOTO a b c # S 0 S3 S2