1、第6章 习题6-1 将下列中缀式改写为逆波兰式。(1) -A*(B+C)/(D-E)(2) (a*d+c)/d+e)*f+g(3) a+x4(cd*3)(4) abcab+0a06-3 将下列语句翻译成四元式序列。(1) X:=A*(B+C)+D(2) if A(B(CD) then S1 else S2(3) while A0 do if A=1 then C:=C+1 else A:=A+26-4 设有二维PASCAL数组A110, 120和三维PASCAL数组B110, 120, 130,给出赋值语句 AI,J:=BJ,I+J,I+1+X的四元式序列。第5章 习题答案6-1 解:(1)
2、A-BC+*DE-/(2) ad*c+d/e+f*g+(3) ax+4cd3*(4) abcde*f/0a+b0a06-3 解:(1) (1) (+,B,C,T1) (2) (*,A,T1 ,T2)(3) (+,T2 ,D,T3)(4) (=,T3 ,0,X)(2) 如下所示: (1) (jnz,A,0,3);(2) (j,0,0,p+1);(3) (jnz,B,0,9);(4) (j,0,0,5);(5) (jnz,C,0,9);(6) (j,0,0,7);(7) (jnz,D,0,9);(8) (j,0,0,p+1);(9) 与S1相应的四元式序列(p) (j,0,0,q)(p+1) 与S
3、2相应的四元式序列(q) (3) 假设所产生的四元式序列编号从1开始(1) (j,B,0,5)(4) (j,0,0,13)(5) (j=,A,1,7)(6) (j,0,0,10)(7) (+,C,1,T1)(8) (=,T1 , ,C)(9) (j,0,0,1)(10) (+,A,2,T2)(11) (=,T2 , ,A)(12) (j,0,0,1)(13) 6-4 解:(1) (*,I,20,T1)(2) (+,J,T1,T1) (3) (-,aA,CA ,T2) (4) (+,I,J,T3)(5) (*,J,20,T4) (6) (+,T3 ,T4 ,T4)(7) (+,I,1,T5) (8) (*,T4,30,T6) (9) (+,T5 ,T6 ,T6) (10) (-,aB,CB ,T7) (11) (=,T7T6,0,T8) (12) (+,T8 ,X,T9)(13) (=,T9 ,0,T2T1) (注:(1)(3)是计算下标变量AI,J地址的四元式,T2中存放的是CONSTPART部分,而T1中存放的是VARPART部分,aA表示数组A的首地址;(4)(10) 是计算下标变量BJ,I+J,I+1地址的四元式,T7中存放的是CONSTPART部分,而T6中存放的是VARPART部分,aB表示数组B的首地址。)