资源描述:
《编译原理第6章 习题与答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第6章习题6-1将下列中缀式改写为逆波兰式。(1)-A*(B+C)/(D-E)(2)((a*d+c)/d+e)*f+g(3)a+x≤4∨(c>d*3)(4)a∨b∧c∧ab+0≠a0<∧∨6-3将下列语句翻译成四元式序列。(1)X:=A*(B+C)+D(2)ifA∧(B∨(C∨D))thenS1elseS2(3)whileA0doifA=1thenC:=C+1elseA:=A+26-4设有二维PASCAL数组A[1··10,1··20]和三维P
2、ASCAL数组B[1··10,1··20,1··30],给出赋值语句A[I,J]:=B[J,I+J,I+1]+X的四元式序列。第5章习题答案6-1解:(1)A-BC+*DE-/(2)ad*c+d/e+f*g+(3)ax+4≤cd3*>∨(4)abcde*f/<∧∨6-2解:(1)a+b*c(2)a*(b-c)-(c+d)/e(3)a≤b+c∧a>0∨a+b≠0∧a<06-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、(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)与S2相应的四元式序列(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)(
4、=,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)(=[],T7[T6],0,T8)(12)(+,T8,X,T9)(13)([]=,T9,0,T2[T1])(注:(1)~(3)是计算下标变量A[I,J]地址的四元式,T2中存放的是CONSTPART部分,而T1中
5、存放的是VARPART部分,aA表示数组A的首地址;(4)~(10)是计算下标变量B[J,I+J,I+1]地址的四元式,T7中存放的是CONSTPART部分,而T6中存放的是VARPART部分,aB表示数组B的首地址。)