编译原理课后答案(陈火旺) 下载本文

课后答案网 http://www.khdaw.com

b b b 1: 5: 8: S??S? #A?SA? a/bS?A?S a/b A A?S?A a/bS?A?S a/bS??AS a/b A A A??SA a/bS??AS a/bS??b a/b A??a a/bS??b a/bA??SA a/b S??AS a/bA??SA a/bA??a a/b S S??b a/bA??a a/b a a S S a S 3: 0: 3: a a A a A?a? a/b A S???S # S??AS #/a/b9: 6: S??b #/a/b S?AS? a/bA?S?A a/b S A??SA a/bA?S?A a/bA??SA a/b b 4: A??SA a/b A??a a/bS?b? #/a/bA??a a/b A??a a/b S??AS a/b S S??AS a/bS??b a/b A b S??b a/b a a S b b 2: 7: S?AS? #/a/bS?A?S #/a/b A?S?A a/bS??AS #/a/b A??SA a/bS??b #/a/b10: S b A??a a/bS?b? a/b A??SA a/b S??AS a/bA??a a/b S??b a/b A A 5: 课后答案网 http://www.khdaw.com

课后答案网 http://www.khdaw.com

第六章

/********************第六章会有点难

P164–5

(1)

E?E1+T {if (E1.type = int) and (T.type = int ) then E.type := int else E.type := real} E?T {E.type := T.type} T?num.num {T.type := real} T?num {T.type := int} (2)

P164–7

S?L1|L2

{S.val:=L1.val+(L2.val/2

L2.length)}

S?L {S.val:=L.val}

L?L1B {L.val:=2*L1.val + B.val; L.length:=L1.length+1} L?B {L.val:=B.c;

L.length :=1} B?0 {B.c:=0} B?1 {B.c:=1} ***********************/

第七章

P217–1

a*(-b+c) a+b*(c+d/e) -a+b*(-c+d)

ab@c+* abcde/+*+ a@bc@d+*+

?A??(C??D) A?CD????

AB?C@D?? AB?CD@E???

(A?B)?(?C?D)

(A?B)?(C??D?E)

if (x+y)*z =0 then (a+b)↑c else a↑b↑c xy+z*0= ab+c↑abc↑↑ ¥ 或 xy+z*0= P1 jez ab+c↑ P2 jump abc↑↑

P1 P2

课后答案网 http://www.khdaw.com

课后答案网 http://www.khdaw.com

P217–3

-(a+b)*(c+d)-(a+b+c)的 三元式序列: (1) +, a, b (2) @, (1), - (3) +, c, d (4) *, (2), (3) (5) +, a, b (6) +, (5), c (7) -, (4), (6) 间接三元式序列: 三元式表: (1) +, a, b (2) @, (1), - (3) +, c, d (4) *, (2), (3) (5) +, (1), c (6) -, (4), (5) 间接码表: (1) (2) (3) (4) (1) (5) (6)

四元式序列: (1) (2) (3) (4) (5) (6) (7)

+, a, b, T1 @, T1, -, T2 +, c, d, T3 *, T2, T3, T4 +, a, b, T5 +, T5, c, T6 -, T4, T6, T7

P218–4

自下而上分析过程中把赋值句翻译成四元式的步骤:A:=B*(-C+D) 步骤 输入串 栈 PLACE 四元式 (1) A:=B*(-C+D)

(2) :=B*(-C+D) i A (3) B*(-C+D) i:= A- (4) *(-C+D) i:=i A-B

(5) *(-C+D) i:=E A-B

课后答案网 http://www.khdaw.com

课后答案网 http://www.khdaw.com

(6) (7) (8) (9) (10) (11) (12) (13) (14) (15) (16) (17) (18) (19)

*(-C+D) i:=E (-C+D) i:=E* -C+D) i:=E*( C+D) i:=E*(- +D) i:=E*(-i +D) +D) D) )

i:=E*(-E i:=E*(E i:=E*(E+

A-B A-B- A-B-- A-B--- A-B---C A-B---C A-B--T A-B--T-

11(@,C,-, T)

1 i:=E*(E+i A-B--T-D

1) i:=E*(E+E A-B--T-D (+,T,D,T)

112) i:=E(E A-B--T

i:=E*(E) i:=E+E i:=E

A-B--T- A-B-T A-T

3(20) A

222(*,B,T,T)

32(:=,T,-,A)

3产生的四元式: (@,C,-, T) (+,T,D,T)

12(*,B,T,T) (:=,T,-,A)

3123P218–5

/****************

设A :10*20,B、C、D:20,宽度为w=4 则 T1:= i * 20 T1:=T1+j T2:=A–84 T3:=4*T1

Tn:=T2[T3] //这一步是多余的 T4:= i + j T5:=B–4 T6:=4*T4 T7:=T5[T6] T8:= i * 20 T8:=T8+j T9:=A–84 T10:=4*T8 T11:=T9[T10] T12:= i + j T13:=D–4 T14:=4*T12 T15:= T13[T14] T16:=T11+T15 T17:=C–4

课后答案网 http://www.khdaw.com