编译原理 龙书答案
4. 对所有形如B→C 的产生式,将C压栈 5. 返回2
(Aho)4.44 为练习4.4文法构造SLR分析表,解决冲突 解:拓广文法 R'→R
R→R ‘|’ R | RR | R* | (R) | a | b
I0={ R'→ R, R→ R ‘|’ R, R→ RR, R→ R*, R→ (R), R→ a, R→ b }
goto(I0, R) = { R'→R , R→R ‘|’ R, R→R R, R→R *, R→ R ‘|’ R, R→ RR, R→ R*, R→ (R), R→ a, R→ b } = I1
goto(I0, () = { R→( R), R→ R ‘|’ R, R→ RR, R→ R*, R→ (R), R→ a, R→ b } = I2 goto(I0, a) = { R→a } = I3 goto(I0, b) = { R→b } = I4
goto(I1, R) = { R→RR , R→R ‘|’ R, R→R R, R→R *, R→ R ‘|’ R, R→ RR, R→ R*, R→ (R), R→ a, R→ b } = I5
goto(I1, |) = { R→R ‘|’ R, R→ R ‘|’ R, R→ RR, R→ R*, R→ (R), R→ a, R→ b } = I6 goto(I1, *) = { R→R * } = I7 goto(I1, () = I2 goto(I1, a) = I3 goto(I1, b) = I4
goto(I2, R) = { R→(R ), R→R ‘|’ R, R→R R, R→R *, R→ R ‘|’ R, R→ RR, R→ R*, R→ (R), R→ a, R→ b } = I8 goto(I2, () = I2 goto(I2, a) = I3 goto(I2, b) = I4 goto(I5, R) = I5 goto(I5, |) = I6 goto(I5, *) = I7 goto(I5, () = I2 goto(I5, a) = I3 goto(I5, b) = I4
goto(I6, R) = { R→R ‘|’ R , R→R ‘|’ R, R→R R, R→R *, R→ R ‘|’ R, R→ RR, R→ R*, R→ (R), R→ a, R→ b } = I9 goto(I6, () = I2 goto(I6, a) = I3 goto(I6, b) = I4 goto(I8, R) = I5 goto(I8, |) = I6 goto(I8, *) = I7 goto(I8, () = I2
goto(I8, )) = { R→(R) } = I10 goto(I8, a) = I3 goto(I8, b) = I4 goto(I9, R) = I5