北邮-编译原理与技术-课后答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

111.11.31.41.5233.2(1)0(0|1)*00001(4)0*10*10*10*1013.4(1)numnum2|0num1|1num1||9num1num1num2|0num1|1num1||9num1num22|4|6|8|0(2)numnum2|1num1|2num1||9num1num1num2|0num1|1num1||9num1num22|4|6|8|03.8DFA3.9(3)!=(5)=(1)=(2)for(4)+==+=++for_loopC03125{}(**)other*other4other}}ootthhtterer4)+2*ootthhtterer344.1bexprbtermEEorbtermE|btermbfactorTTandbfactorT|bfactornotbfactor|(bexpr)|true|falsebexprvoidproce_xpr(void){proc_term();if(char==or){forwardpointer;proc_expr;}}btermvoidproc_term(void){036orbtermbexpr:7813andbfactorbterm:14151618bexprtrue/false17notbfactorbfactor:88notnotfafcctoor131315174proc_factor();if(char==and){forwardpointer;proc_term();}}bfactorvoidproc_factor(void){if(char==not){forwardpointer;proc_factor();}elseif(char==(){forwardpointer;proc_expr();if(char==))forwardpointer;elseerror();};elseif(char==true)||(char==false)forwardpointer;elseerror();}4.3(1)FIRST(A)={(,},FOLLOW(A)={$,}(2)FIRST((A)A)FIRST()=FIRST((A)A)FOLLOW(A)=LL(1)4.5(1)EA|BAnum|idB(L)LELLEL|(2)FIRSTFOLLOW,FIRSTFOLLOWE(,num,id$,(,),num,idAnum,id$,(,),num,idB($,(,),num,idL(,num,id)L(,num,id,)||(c||(chhaar==r==ffaflsepooinntteerr;;r();;))={)={$,}})=F5(3)LL(1)EA|BFIRST(A)FIRST(B)=Anum|idFIRST(num)FIRST(id)=B(L)LELLEL|FIRST(EL)FOLLOW(L)=LL(1)),numid$EEBEAEAAAnumAidBB(L)LLELLELLELLLELLLELLEL(4)(a(b(2))(c))(1)$E(a(b(2))(c))$EB(2)$B(a(b(2))(c))$B(L)(3)$)L((a(b(2))(c))$(4)$)La(b(2))(c))$LEL(5)$)LEa(b(2))(c))$EA(6)$)LAa(b(2))(c))$(7)$)Lida(b(2))(c))$(8)$)L(b(2))(c))$LEL(9)$)LE(b(2))(c))$EB(10)$)LB(b(2))(c))$B(L)(11)$)L)L((b(2))(c))$(12)$)L)Lb(2))(c))$LEL(13)$)L)LEb(2))(c))$EA(14)$)L)LAb(2))(c))$Aid(15)$)L)Lidb(2))(c))$(16)$)L)L(2))(c))$LEL(17)$)L)LE(2))(c))$EB(18)$)L)LB(2))(c))$B(L)(19)$)L)L)L((2))(c))$(20)$)L)L)L2))(c))$LEL(21)$)L)L)LE2))(c))$(22)$)L)L)LA2))(c))$Anum(23)$)L)L)Lnum2))(c))$(24)$)L)L)L))(c))$L(25)$)L)L)))(c))$(26)$)L)L)(c))$L(27)$)L))(c))$((2))(((aa((bb((22))())(c))a((bb((22))(aa((bb(iidd((b((22))))((BB((LL))c))$LLEL))(c)))(c))$$EEc))c))$$a(b(22)))(c)))(c))((bb((2))()LE)L)LAA6(28)$)L(c))$LEL(29)$)LE(c))$EB(30)$)LB(c))$B(L)(31)$)L)L((c))$(32)$)L)Lc))$LEL(33)$)L)LEc))$EA(34)$)L)LAc))$Aid(35)$)L)Lidc))$(36)$)L)L))$L(37)$)L)))$(38)$)L)$L(39)$))$(40)$$4.9(1)(0)SS(1)SAS(2)Sb(3)ASA(4)AaLR(0)DFAI0SSSASSbASAAaI1SSASAASAAaSASSbI2SASSASSbASAAaI3AaI4SbI5ASASASSASSbASAAaI6ASASASSbASAAaI7SASASAASAAaSASSbI3aI4bI3aI4bI3aI4bI3aI4bSabAAASASASASI3aI4bSI6AA4)AAaASASASSAASSSSASSAASSASASSSAaa7(2)SLR(1)I5SLRASAFOLLOW(A)={a,b}M[5,b]=reduceASASbM[5,b]=shift4SLR(1)(3)LR(1)DFAI5[ASA,a/b][Aa,a/b]-LR(1)4.14LL(1)FIRSTFOLLOWFIRSTFOLLOWSa,b$Aa,bBa,bSAaAb|BbBaFIRST(AaAb)FOLLOW(BbBa)=I0SS,$SAS,$/a/bSb,$/a/bASA,a/bAa,a/bI1SS,$ASA,a/bASA,a/bAa,a/bSAS,a/bSb,a/bI2SAS,$/a/bSAS,$/a/bSb,$/a/bASA,a/bAa,a/bI3Aa,a/bI4Sb,$/a/bI5ASA,a/bSAS,a/bSAS,a/bSb,a/bASA,a/bAa,a/bI6ASA,a/bSAS,a/bSb,a/bASA,a/bAa,a/bI7SAS,$/a/bASA,a/bASA,a/bAa,a/bSAS,a/bSb,a/bI3aI8bI3aI8bI3aI8bI3aSabAAASASASASI3aI8bSI8Sb,a/bba//abb//,aa//aabb//SSAA,aa//aabb//Aaa,,aa//aabb//AASAASS,$$/SSASSAASb8LL(1)ab$SSAaAbSBbBaAAABBBLL(1)LL(1)SLR(1)(0)SS(1)SAaAb(2)SBbBa(3)A(4)BLR(0)I0SSSAaAbSBbBaABFOLLOW(A)=FOLLOW(B)={a,b}AB-SLR(1)4.16LR(0)DFALR(0)LR(0)SLR(1)LR(1)LALR(1)(0)0)LRR((1)1)LLRR(1)1)1)LALALRR((1)1)955.1(4*7+1)*25.2E.valT.valF.valETFE.iT.iETnum.lexvalnumETEE.i=T.valE.val=E.valE+TE1E1.i=E.i+T.valE.val=E1.valE-TE1E1.i=E.i-T.valE.val=E1.valEE.val=E.iLE.val=58nT.val=58T.val=29*F.val=2(E.val=29)E.val=28+T.val=1T.val=28+F.val=1T.val=4*F.val=7F.val=4digit.lexval=7digit.lexval=4digit.lexval=1digit.lexval=2F.F.vvaall==11=77vvalalal=77diggiitt.lleexxvval=l=210TFTT.i=F.valT.val=T.valT*FT1T1.i=T.i*F.valT.val=T1.valTT.val=T.iF(E)T.val=E.valFnumT.val=num.lexval5.3((a)+(b))5.4(1)abcE.nptrE.nptrT.nptr(E.nptr)T.nptr(E.nptr)T.nptridT.nptrid+aentryabentryb+SABCabc.uS.v.uA.v.uB.vC.vabcennttrrtttyyraa11(2)C.v=2B.u=S.uB.v=B.uA.u=B.v+C.vA.v=3*A.uS.v=A.v(3)abcS.u5S.v21(4)abcB.u=S.uB.v=B.uC.u=B.vC.v=C.u-2A.u=B.v+C.vA.v=3*A.uS.v=A.vS.u5S.v245.6(1)E.typeT.typeEE1+TIf(E1.type==integer)&&(T.type==integer)E.type=integer;ElseE.type=realETE.type=T.typeTnum.numT.type=realTnumT.type=integer.uS.v.uA.v.uB.v.uC.vabccS.uS.u12(2)E.typeT.typeE.codeT.codeLEPrint(E.code)EE1+TIf(E1.type==integer)&&(T.type==integer){E.type=integer;E.code=+||E1.code||T.code;}Else{E.type=real;if(E1.type==integer)E1.code=inttoreal(E1.code);elseif(T.type==integer)T.code=inttoreal(T.code);E.code=+||E1.code||T.code;}ETE.type=T.typeE.code=T.codeTnum.numT.type=realT.code=num.num.lexvalTnumT.type=integerT.code=num.lexval5.9(1)T.typeL.inaddtypeid.entry,typetypeid.entryDLTL.in=T.typeTintegerT.type=integerTrealT.type=realLL1,idL1.in=L.inaddtype(id.entry,L.in)Lidaddtype(id.entry,L.in)(2)LDLTL.inTL5.11(1)B.htB.psB.psBLLL11.in=L=L..iinnddddttypypttnteggeerpe=rereale(e(i13(2)S{B.ps=10}B{S.ht=B.ht}B{B1.ps=B.ps}B1{B2.ps=B.ps}B2{B.ht=max(B1.ht,B2.ht)}B{B1.ps=B.ps}B1sub{B2.ps=shrink(B.ps)}B2{B.ht=disp(B1.ht,B2.ht)}Btext{B.ht=text.hB.ps}(3)LRLMNLMNLMNBisSLBB.ps=L.sS.ht=B.htLL.s=10BB1MB2B1.ps=B.psM.i=B.psB2.ps=M.sB.ht=max(B1.ht,B2.ht)BB1subNB2B1.ps=B.psN.i=B.psB2.ps=N.sB.ht=disp(B1.ht,B2.ht)B

1 / 34
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功