• 407.88 KB
  • 2022-04-22 11:32:36 发布

《编译原理》陈火旺国防工业出版社课后答案

  • 0页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
'课后答案网www.khdaw.com课后答案网http://www.khdaw.com第二章P36-6(1)LG()1是0~9组成的数字串(2)最左推导:N⇒⇒⇒NDNDDNDDD⇒DDDD⇒0DDD⇒⇒⇒01DD012D0127NN⇒⇒⇒⇒DDDD334N⇒⇒⇒⇒⇒⇒NDNDDDDD5DD56D568最右推导:N⇒⇒⇒⇒⇒NDN7ND7N27ND27⇒⇒⇒N127D1270127NN⇒⇒⇒⇒DND4434N⇒⇒⇒⇒⇒⇒NDN8ND8N68D68568P36-7G(S)O→13579||||NO→2468||||DN→0|SO→|AOAA→D|NP36-8文法:ET→+−||ETETTF→|*|/TFTFFE→()|i最左推导:E⇒+⇒+⇒+⇒ETTTFTi+T⇒i+T****FiFFiiFiii⇒+⇒+⇒+ETTFFFiFiEiETiTTiFT⇒⇒*⇒*⇒*⇒*()⇒*(+⇒)*(+⇒)*(+)⇒+⇒+⇒+iiTiiFiii*()*()*()最右推导:E⇒+⇒+ETET******F⇒+⇒ETiE+Fi⇒E+ii⇒T+ii⇒+⇒+Fiiiii*ETFTFFFEFETFEFFEi⇒⇒⇒⇒⇒+***()*()⇒+*()⇒+*()⇒+FTiFFiFiiiii*()⇒+*()⇒+*()⇒+*()语法树:/********************************课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comEEEE+TE-TE+TEF+TEF-TTT*FTFiTFiFFiFiFiiiiii+i+ii-i-ii+i*i*****************/P36-9句子iiiei有两个语法树:S⇒⇒⇒⇒iSeSiSeiiiSeiiiieiS⇒⇒iSiiSeS⇒iiSei⇒iiieiP36-10/**************S→TS|TT→(S)(|)***************/P36-11/***************L1:S→ACA→aAb|abC→cC|εL2:S→ABA→aA|εB→bBc|bcL3:课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comS→ABA→aAb|εB→aBb|εL4:S→A|BA→0A|1εB→1B|0A***************/第三章习题参考答案P64–7(1)*10(|)1101XY01εε101X12345Y1确定化:01{X}φ{1,2,3}φφφ{1,2,3}{2,3}{2,3,4}{2,3}{2,3}{2,3,4}{2,3,4}{2,3,5}{2,3,4}{2,3,5}{2,3}{2,3,4,Y}{2,3,4,Y}{2,3,5}{2,3,4,}010023001100114560111最小化:课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com{,,,,,},{}0123456{,,,,,}012345=={,,}{,,,,,}135012345{,,,}124601{,,,,},{},{}0123456{,,,,}01234={,,}1350{,,,},{},{},{}0123456{,,,}0123={,130}{,,,}{,,}1231=2401{,},{,}{},{},{}0123456{,}01=={}{,}101{,}1201{,}23=={}{,}323{}401{},{},{,},{},{},{}0123456010200100113450111P64–8(1)*)0|1(01(2)*9|8|7|6|5|4|3|2|1()()9|8|7|6|5|4|3|2|1|0)5|0(|)5|0((3)******0|0(110)11||0(010)1P64–12(a)aa,b01a确定化:ab{0}{0,1}{1}{0,1}{0,1}{1}{1}{0}φ课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comφφφ给状态编号:ab012112203333aa01abbbb23a最小化:{,},{,}0123{,}01=={}{,}101{}2ab{,}23=={,}{,}0323{}3ab{,},{},{}0123aabb012ab(b)bba023abaabba145aa已经确定化了,进行最小化课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com最小化:{{,},{,,,}}012345{,}01=={}1{,}{,}0124ab{,,,}{,,,}2345==1305{,,,}{,,,}23452345ab{,}{,}24==10{,}{,}2435ab{,}35=={,}35{,}{,}3524ab{{,},{,},{,}}012435{,}01=={}1{,}{,}0124ab{,}24=={,}10{,}24{,}35ab{,}35=={,}35{,}{,}3524abbba012abaP64–14(1)01010(2):*X(|)010Y201εεX1Y0确定化:01{X,1,Y}{1,Y}{2}课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com{1,Y}{1,Y}{2}{2}{1,Y}φφφφ给状态编号:01012112213333001010111230最小化:{,},{,}0123{,}{}01==1{,}{}01201{,}{,}23==13{,}{}23301{,},{},{}0123011101300第四章P81–1(1)按照T,S的顺序消除左递归G′(S)S→a(||^T)T→ST′T′→,ST′|ε递归子程序:procedureS;beginifsym="a"orsym="^"thenabvanceelseifsym="("课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comthenbeginadvance;T;ifsym=")"thenadvance;elseerror;endelseerrorend;procedureT;beginS;T′end;procedureT′;beginifsym=","thenbeginadvance;S;T′endend;其中:sym:是输入串指针IP所指的符号advance:是把IP调至下一个输入符号error:是出错诊察程序(2)FIRST(S)={a,^,(}FIRST(T)={a,^,(}FIRST(T′)={,,ε}FOLLOW(S)={),,,#}FOLLOW(T)={)}FOLLOW(T′)={)}预测分析表a^(),#SS→aS→^ST→()TT→ST′T→ST′T→ST′T′T′→εTS′→,T′是LL(1)文法P81–2文法:课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comE→TE′E′→+E|εT→FT′T′→T|εF→PF′F′→*F′|εP→(E|)a|b|^(1)FIRST(E)={(,a,b,^}FIRST(E")={+,ε}FIRST(T)={(,a,b,^}FIRST(T")={(,a,b,^,ε}FIRST(F)={(,a,b,^}FIRST(F")={*,ε}FIRST(P)={(,a,b,^}FOLLOW(E)={#,)}FOLLOW(E")={#,)}FOLLOW(T)={+,),#}FOLLOW(T")={+,),#}FOLLOW(F)={(,a,b,^,+,),#}FOLLOW(F")={(,a,b,^,+,),#}FOLLOW(P)={*,(,a,b,^,+,),#}(2)考虑下列产生式:E′→+E|εTT′→|εFF′→*|′εPEa→()|^||bFIRST(+E)∩FIRST(ε)={+}∩{ε}=φFIRST(+E)∩FOLLOW(E")={+}∩{#,)}=φFIRST(T)∩FIRST(ε)={(,a,b,^}∩{ε}=φFIRST(T)∩FOLLOW(T")={(,a,b,^}∩{+,),#}=φFIRST(*F")∩FIRST(ε)={*}∩{ε}=φFIRST(*F")∩FOLLOW(F")={*}∩{(,a,b,^,+,),#}=φFIRST((E))∩FIRST(a)∩FIRST(b)∩FIRST(^)=φ所以,该文法式LL(1)文法.(3)+*()ab^#EET→E"ET→E"ET→E"ET→E"E"EE′→+E′→εE′→εTT→FT′T→FT′T→FT′T→FT′课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comT"T′→εT′→TT′→εT′→TT′→TT′→TT′→εFF→PF′F→PF′F→PF′F→PF′F"F′→εFF′→*′F′→εF′→εF′→εF′→εF′→εF′→εPP→()EP→aP→bP→^(4)procedureE;beginifsym="("orsym="a"orsym="b"orsym="^"thenbeginT;E"endelseerrorendprocedureE";beginifsym="+"thenbeginadvance;Eendelseifsym<>")"andsym<>"#"thenerrorendprocedureT;beginifsym="("orsym="a"orsym="b"orsym="^"thenbeginF;T"endelseerrorendprocedureT";beginifsym="("orsym="a"orsym="b"orsym="^"thenTelseifsym="*"thenerrorendprocedureF;beginifsym="("orsym="a"orsym="b"orsym="^"thenbeginP;F"endelseerrorendprocedureF";beginifsym="*"thenbeginadvance;F"endendprocedureP;课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.combeginifsym="a"orsym="b"orsym="^"thenadvanceelseifsym="("thenbeginadvance;E;ifsym=")"thenadvanceelseerrorendelseerrorend;P81–3/***************(1)是,满足三个条件。(2)不是,对于A不满足条件3。(3)不是,A、B均不满足条件3。(4)是,满足三个条件。***************/第五章P133–1E⇒+⇒+ETET*F短语:E+T*F,T*F,直接短语:T*F句柄:T*FP133–2文法:S→a|^|()TTT→,|SS(1)最左推导:S⇒⇒()(,)(,)(,)(,())(,(,))(,(,))(,(,))(,(,))TTSS⇒⇒⇒SaSaT⇒aTSa⇒SSa⇒aSa⇒aaST⇒⇒⇒⇒(,)(,)((),)((,),)((,,),)((,,),)(((),,),)SSSTSTSST⇒SSSS⇒SSST⇒SSS⇒⇒⇒(((,),,)),)(((,),,),)(((,),,),)(((,),,),)TSSSSSSSSSaSSSS⇒aaSSS⇒⇒⇒⇒(((,),^,),)aaSS(((,),^,()),)aaTS(((,),^,()),)aaSS(((,),^,()),)aaaS⇒(((,),^,()),)aaaa最右推导:课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comS⇒⇒()(,)(,())(,(,))(,(,))(,(,))(,(,))TTS⇒TT⇒TTS⇒TTa⇒TSa⇒Taa⇒⇒(,(,))(,(,))SaaaaaST⇒⇒⇒⇒⇒(,)ST(,)aS(,)aT((),)aT((,),)SaT⇒((,()),)TaT⇒((,()),)Sa⇒⇒((,()),)Taa((,,()),)TSaa⇒((,^,()),)Taa⇒((,^,()),)Saa⇒(((),^,()),)Taa⇒⇒⇒⇒(((,),^,()),)TSaa(((,),^,()),)Taaa(((,),^,()),)Saaa(((,),^,()),)aaaa(2)(((a,a),^,(a)),a)(((S,a),^,(a)),a)(((T,a),^,(a)),a)(((T,S),^,(a)),a)(((T),^,(a)),a)((S,^,(a)),a)((T,^,(a)),a)((T,S,(a)),a)((T,(a)),a)((T,(S)),a)((T,(T)),a)((T,S),a)((T),a)(S,a)(T,S)(T)S“移进-归约”过程:步骤栈输入串动作0#(((a,a),^,(a)),a)#预备1#(((a,a),^,(a)),a)#进2#(((a,a),^,(a)),a)#进3#(((a,a),^,(a)),a)#进4#(((a,a),^,(a)),a)#进5#(((S,a),^,(a)),a)#归6#(((T,a),^,(a)),a)#归7#(((T,a),^,(a)),a)#进8#(((T,a),^,(a)),a)#进9#(((T,S),^,(a)),a)#归10#(((T),^,(a)),a)#归11#(((T),^,(a)),a)#进12#((S,^,(a)),a)#归13#((T,^,(a)),a)#归14#((T,^,(a)),a)#进15#((T,^,(a)),a)#进16#((T,S,(a)),a)#归17#((T,(a)),a)#归课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com18#((T,(a)),a)#进19#((T,(a)),a)#进20#((T,(a)),a)#进21#((T,(S)),a)#归22#((T,(T)),a)#归23#((T,(T)),a)#进24#((T,S),a)#归25#((T),a)#归26#((T),a)#进27#(S,a)#归28#(T,a)#归29#(T,a)#进30#(T,a)#进31#(T,S)#归32#(T)#归33#(T)#进34#S#归P133–3(1)FIRSTVT(S)={a,^,(}FIRSTVT(T)={,,a,^,(}LASTVT(S)={a,^,)}LASTVT(T)={,,a,^,)}(2)a^(),a>>^>>(<<<=<)>>,<<<>>G是算符文法,并且是算符优先文法6(3)优先函数a^(),f44244g55523fffffa^(),课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comggggga^(),(4)栈输入字符串动作#(a,(a,a))#预备#(a,(a,a))#进#(a,(a,a))#进#(t,(a,a))#归#(t,(a,a))#进#(t,(a,a))#进#(t,(a,a))#进#(t,(t,a))#归#(t,(t,a))#进#(t,(t,a))#进#(t,(t,s))#归#(t,(t))#归#(t,(t))#进#(t,s)#归#(t)#归#(t)#进#s#归successP134–5(1)0.S′→⋅S1.SS′→⋅2.S→⋅AS3.S→A⋅S4.S→⋅AS5.S→⋅b6.S→b⋅7.A→⋅SA8.A→⋅SA9.A→SA⋅10.A→⋅a11.A→a⋅(2)1SAε789Sεεεεa01011εεεAS234εεd56课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com确定化:SAab{0,2,5,7,10}{1,2,5,7,8,10{2,3,5,7,10}{11}{6}}{1,2,5,7,8,10{2,5,7,8,10}{2,3,5,7,9,10{11}{6}}}{2,3,5,7,10}{2,4,5,7,8,10{2,3,5,7,10}{11}{6}}{2,5,7,8,10}{2,5,7,8,10}{2,3,5,7,9,10{11}{6}}{2,3,5,7,9,10{2,4,5,7,8,10{2,3,5,7,10}{11}{6}}}{2,4,5,7,8,10{2,5,7,8,10}{2,3,5,7,9,10{11}{6}}}{11}φφφφ{6}φφφφAS5:A→S⋅A6:A→⋅SA3:SS′→⋅S→⋅ASS→⋅ASSAaA→S⋅ASb→⋅S→⋅ASAS→⋅AAS→⋅ASb→⋅bAa→⋅A→⋅aAS→⋅AS→⋅ASA→⋅aS→bSaASbSAbaA0:SS′→⋅4:S→A⋅S7:S→⋅ASS→⋅ASS→⋅ASA→⋅SAASSb→⋅Sb→⋅S→⋅ASAS→⋅AAS→⋅ASb→⋅bA→⋅aA→⋅aAS→⋅AA→⋅aaabba1:A→a⋅2:Sb→⋅课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comDFA构造LR(0)项目集规范族也可以用GO函数来计算得到。所得到的项目集规范族与上图中的项目集一样:I={SS′→⋅,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}0GO(I,a)={A→⋅a}=I01GO(I,b)={Sb→⋅}=I02GO(I,S)={SS′→⋅,A→S⋅A,A→⋅SA,A→⋅a,S→⋅AS,Sb→⋅}=I03GO(I,A)={S→⋅AS,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I04GO(I,a)={A→⋅a}=I31GO(I,b)={Sb→⋅}=I32GO(I,S)={A→⋅SA,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I35GO(I,A)={A→⋅SA,S→A⋅S,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I36GO(I,a)={A→⋅a}=I41GO(I,b)={Sb→⋅}=I42GO(I4,S)={S→⋅AS,A→S⋅A,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I7GO(I,A)={S→⋅AS,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I44GO(I,a)={A→⋅a}=I51GO(I,b)={Sb→⋅}=I52GO(I5,S)={A→⋅SA,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I5GO(I5,A)={A→⋅SA,S→A⋅S,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I6GO(I6,a)={A→⋅a}=I1GO(I6,b)={Sb→⋅}=I2GO(I6,S)={S→⋅AS,A→S⋅A,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I7GO(I6,A)={S→⋅AS,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I4GO(I7,a)={A→⋅a}=I1GO(I7,b)={Sb→⋅}=I2GO(I7,S)={A→⋅SA,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I5GO(I,A)={A→⋅SA,S→A⋅S,S→⋅AS,Sb→⋅,A→⋅SA,A→⋅a}=I76项目集规范族为C={I1,I2,I3,I4,I5,I6,I7}(3)不是SLR文法状态3,6,7有移进归约冲突状态3:FOLLOW(S’)={#}不包含a,b状态6:FOLLOW(S)={#,a,b}包含a,b,;移进归约冲突无法消解状态7:FOLLOW(A)={a,b}包含a,b;移进归约冲突消解所以不是SLR文法。(4)构造例如LR(1)项目集规范族见下图:对于状态5,因为包含项目[A→AS⋅a/b],所以遇到搜索符号a或b时,应该用A→AS归约。又因为状态5包含项目[A→⋅aa/b],所以遇到搜索符号a时,应该移进。因此存在“移进-归约”矛盾,所以这个文法不是LR(1)文法。课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.combbb1:5:8:S′→S⋅#A→SA⋅a/bS→A⋅Sa/bAA→S⋅Aa/bS→A⋅Sa/bS→⋅ASa/bAAA→⋅SAa/bS→⋅ASa/bS→⋅ba/bA→⋅aa/bS→⋅ba/bA→⋅SAa/bS→⋅ASa/bA→⋅SAa/bA→⋅aa/bSS→⋅ba/bA→⋅aa/baaSSaS3:aaAa0:3:S′→⋅S#A→a⋅a/bAS→⋅AS#/a/b9:6:S→⋅b#/a/bA→S⋅Aa/bS→AS⋅a/bSbA→⋅SAa/b4:A→⋅SAa/bA→S⋅Aa/bA→⋅aa/bS→b⋅/#a/bA→⋅aa/bA→⋅SAa/bA→⋅aa/bS→⋅ASa/bSS→⋅ASa/bS→⋅ba/bAbS→⋅ba/baaSbb2:7:S→A⋅S#/a/bS→AS⋅/#a/bS→⋅AS#/a/bA→S⋅Aa/bSbS→⋅b#/a/bA→⋅SAa/b10:A→⋅SAa/bA→⋅aa/bS→b⋅a/bA→⋅aa/bS→⋅ASa/bS→⋅ba/bAA5:课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com第六章/********************第六章会有点难P164–5(1)E→E1+T{if(E1.type=int)and(T.type=int)thenE.type:=intelseE.type:=real}E→T{E.type:=T.type}T→num.num{T.type:=real}T→num{T.type:=int}(2)P164–7L.2lengthS→L1|L2{S.val:=L1.val+(L2.val/2)}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–1a*(-b+c)ab@c+*a+b*(c+d/e)abcde/+*+-a+b*(-c+d)a@bc@d+*+¬A∨¬(C∨¬D)A¬CD¬∨¬∨(A∧B)∨(¬C∨D)AB∧C@D∨∨(A∨B)∧(C∨¬D∧E)AB∨CD@E∧∨∧if(x+y)*z=0then(a+b)↑celsea↑b↑cxy+z*0=ab+c↑abc↑↑¥或xy+z*0=P1jezab+c↑P2jumpabc↑↑P1P2课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comP217–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)+,a,b,T1(2)@,T,-,T12(3)+,c,d,T3(4)*,T,T,T234(5)+,a,b,T5(6)+,T,c,T56(7)-,T,T,T467P218–4自下而上分析过程中把赋值句翻译成四元式的步骤:A:=B*(-C+D)步骤输入串栈PLACE四元式(1)A:=B*(-C+D)(2):=B*(-C+D)iA(3)B*(-C+D)i:=A-(4)*(-C+D)i:=iA-B(5)*(-C+D)i:=EA-B课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com(6)*(-C+D)i:=EA-B(7)(-C+D)i:=E*A-B-(8)-C+D)i:=E*(A-B--(9)C+D)i:=E*(-A-B---(10)+D)i:=E*(-iA-B---C(11)+D)i:=E*(-EA-B---C(@,C,-,T)1(12)+D)i:=E*(EA-B--T1(13)D)i:=E*(E+A-B--T-1(14))i:=E*(E+iA-B--T-D1(15))i:=E*(E+EA-B--T-D(+,T,D,T)112(16))i:=E(EA-B--T2(17)i:=E*(E)A-B--T-2(18)i:=E+EA-B-T(*,B,T,T)223(19)i:=EA-T(:=,T,-,A)33(20)A产生的四元式:(@,C,-,T)1(+,T,D,T)12(*,B,T,T)23(:=,T,-,A)3P218–5/****************设A:10*20,B、C、D:20,宽度为w=4则T1:=i*20T1:=T1+jT2:=A–84T3:=4*T1Tn:=T2[T3]//这一步是多余的T4:=i+jT5:=B–4T6:=4*T4T7:=T5[T6]T8:=i*20T8:=T8+jT9:=A–84T10:=4*T8T11:=T9[T10]T12:=i+jT13:=D–4T14:=4*T12T15:=T13[T14]T16:=T11+T15T17:=C–4课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comT18:=4*T16T19:=T17[T18]T20:=T7+T19Tn:=T20******************/P218–6100.(jnz,A,-,0)101.(j,-,-,102)102.(jnz,B,-,104)103.(j,-,-,0)104.(jnz,C,-,103)105.(j,-,-,106)106.(jnz,D,-,104)--假链链首107.(j,-,-,100)--真链链首假链:{106,104,103}真链:{107,100}P218–7100.(j<,A,C,102)101.(j,-,-,0)102.(j<,B,D,104)103.(j,-,-,101)104.(j=,A,‘1’,106)105.(j,-,-,109)106.(+,C,‘1’,T1)107.(:=,T1,-,C)108.(j,-,-,100)109.(j≤,A,D,111)110.(j,-,-,100)111.(+,A,‘2’,T2)112.(:=,T2,-,A)113.(j,-,-,109)114.(j,-,-100)P219–12/********************(1)MAXINT–5MAXINT–4MAXINT–3MAXINT–2MAXINT–1MAXINT课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com(2)翻译模式方法1:forE1:=E2toE3doSS→FdoMS1F→ForI:=EtoE12I→idM→εS→FdoMS{backpatch(S1.nextlist,nextquad);1backpatch(F.truelist,M.quad);emit(F.place‘:=’F.place‘+’1);emit(‘j≤,’F.place‘,’F.end‘,’M.quad);S.nextlist:=F.falselist;}F→ForI:=EtoE{F.falselist:=makelist(nextquad);12emit(‘j>,’E1.place‘,’E2.place‘,0’);emit(I.Place‘:=’E1.place);F.truelist:=makelist(nextquad);emit(‘j,-,-,-’);F.place:=I.place;F.end:=E2.place;}I→id{p:=lookup(id.name);ifp<>nilthenI.place:=pelseerror}M→ε{M.quad:=nextquad}****************/方法2:S→forid:=E1toE2doS1S→FS1F→forid:=E1toE2doF→forid:=E1toE2do{INITIAL=NEWTEMP;emit(‘:=,’E1.PLACE’,-,’INITIAL);FINAL=NEWTEMP;emit(‘:=,’E2.PLACE’,-,’FINAL);p:=nextquad+2;emit(‘j ,’INITIAL‘,’FINAL’,’p);F.nextlist:=makelist(nextquad);课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comemit(‘j,-,-,-’);F.place:=lookup(id.name);ifF.place nilthenemit(F.place‘:=’INITIAL)F.quad:=nextquad;F.final:=FINAL;}S→FS1{backpatch(S1.nextlist,nextquad)p:=nextquad+2;emit(‘j ,’F.place‘,’F.final’,’p);S.nextlist:=merge(F.nextlist,makelist(nextquad));emit(‘j,-,-,-’);emit(‘succ,’F.place’,-,’F.place);emit(‘j,-,-,’F.quad);}第九章P270–9(1)传名即当过程调用时,其作用相当于把被调用段的过程体抄到调用出现处,但必须将其中出现的任一形式参数都代之以相应的实在参数。A:=2;B:=3;A:=A+1;A:=A+(A+B);printA;∴A=9(2)传地址即当程序控制转入被调用段后,被调用段首先把实在参数抄进相应的形式参数的形式单元中,过程体对形参的任何引用或赋值都被处理成对形式单元的间接访问。当被调用段工作完毕返回时,形式单元(都是指示器)所指的实参单元就持有所希望的值。①A:=2;B:=3;T:=A+B②把T,A,A的地址抄进已知单元J1,J2,J3③x:=J1;y:=J2;z:=J3//把实参地址抄进形式单元,且J2=J3④Y↑:=y↑+1Z↑:=z↑+x↑//Y↑:对y的间接访问Z↑:对z的间接访问⑤printAA=8(3)得结果每个形参均对应两个单元,第一个存放实参地址,第二个存放实参值,在过程体中对形参的课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com任何引用或赋值都看成是对它的第二个单元的直接访问,但在过程工作完毕返回前必须把第二个单元的内容放到第一个单元所指的那个实参单元中①A:=2;B:=3;T:=A+B②把T,A,A的地址抄进已知单元J1,J2,J3③x1:=J1;x2:=T;y1:=J2;y2:=A;z1:=J3;z2:=A;//将实参的地址和值分别放进两个形式单元中④y2:=y2+1;z2:=z2+x2;//对形参第二个单元的直接访问⑤x1↑:=x2;y1↑:=y2;z1↑:=z2//返回前把第二个单元的内容存放到第一个单元所指的实参地址中⑥printAA=7(4)传值即被调用段开始工作时,首先把实参的值写进相应的形参单元中,然后就好像使用局部变量一样使用这些形式单元A:=2;B:=3;x:=A+By:=Az:=Ay:=y+1z:=z+xprintAA=2过程调用不改变A的值第十章P306-1课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.comP306-2readA,BF:=1BC:=A*AB1D:=B*BifC100gotoL2课后答案网http://www.khdaw.com 课后答案网www.khdaw.com课后答案网http://www.khdaw.com---------------------------haltB4---------------------------L:F:=F-12gotoLB15---------------------------基本块为B、B、B、B、B12345P307-4I:=1readJ,KA:=K*IB:=J*IT:=K*100L:C:=A*BwriteCA:=A+KB:=B+JifA