您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 廖力编译原理课件第7章
1xobjects@seu.edu.cn37932352•••––––31•1)2)3)——41•3——•4)•5)52–•1)•2)•3)•4)6•2––•1•2LR71•–•82•X→α{1}•E→E(1)+E(2)3•94•–•3––101)2)11••(0)S`→E{PRINTE•VAL}•(1)E→E(1)+E(2){E•VAL=E(1)•VAL+E(2)•VAL}•(2)E→E(1)*E(2){E•VAL=E(1)•VAL*E(2)•VAL}•(3)E→(E(1)){E•VAL=E(1)•VAL}•(4)E→i{E•VAL=LEXVAL}•LEXVAL12#S0………………E(1)•VALE(1)+Sm-1E(2)•VALE(2)SmTOPVAL13•TOP•(0)S`→E{PRINTVAL[TOP]}(1)E→E(1)+E(2){VAL[TOP]=VAL[TOP]+VAL[TOP+2]}(2)E→E(1)*E(2){VAL[TOP]=VAL[TOP]*VAL[TOP+2]}(3)E→(E(1)){VAL[TOP]=VAL[TOP+1]}(4)E→i{VAL[TOP]=LEXVAL}14•79*5#,•P1196.615r3r2r1S9r4S2S2S2S2r3r3r39r2r2(S5)r2(S4)8r1S5(r1)r1(S4)7S5S468S357S34r4r4r436S32accS5S411S30S#*iGOTOACTION165#-16-#E*0,1,511r3*5#-16#E0,110*5#--16-#(E)0,2,6,99r1*5#--16#(E0,2,68r4*5#--7-9#(E+E0,2,6,4,77*5#--7--#(E+90,2,6,4,369*5#--7-#(E+0,2,6,45r4+9*5#--7#(E0,2,64+9*5#---#(70,2,337+9*5#--#(0,227+9*5#-#01ACTIONINPUTVALSYM171:(Operator,Operand1,Operand2,Result)1Operand1,Operand2,ResultOperator•2•3182(Operator,Operand1,Operand2)1)2)193()Operand1Operand2Operator4OperatorOperand1Operand220–1•A→i=E•E→E+E|E*E|-E|(E)|i2•NEWTEMPT1T2•ENTRY(i)i•GENOP,ARG1,ARG2,RESULT)213•E•PLACEE––22••(1)A→i=E{GEN(=,E•PLACE,_,ENTRY(i)}•(2)E→-E(1){T=NEWTEMP;–GEN(@,E(1)•PLACE,_,T);–E•PLACE=T}•(3)E→E(1)*E(2){T=NEWTEMP;–GEN(*,E(1)•PLACE,E(2)•PLACE,T);–E•PLACE=T}•(4)E→E(1)+E(2){T=NEWTEMP;–GEN(+,E(1)•PLACE,E(2)•PLACE,T);–E•PLACE=T}•(5)E→(E(1)){E•PLACE=E(1)•PLACE}•(6)E→i{E•PLACE=ENTRY(i)}23T1Ci=E*(E+D)#T1Ci=E*(i+D)#T1i=E*(C+D)#T1i=E*(C+D)#(@,B,,T1)T1i=E*(C+D)#Bi=-E*(C+D)#i=-i*(C+D)#i=-B*(C+D)#i=-B*(C+D)#i=-B*(C+D)#A=-B*(C+D)#PLACESYM24•:1•2•325•i•E•MODEE1•E→E(1)opE(2)E•MODE–{IFE(1)•MODE=intANDE(2)•MODE=int–THENE•MODE=intELSEE•MODE=r}262•X=Y+I*J,XYIJ–(*i,I,J,T1)–(itr,T1,_,T2)–(+r,Y,T2,T3)–(=,T3,_,X)27•1•2EE•PLACEE•MODE•328–––––:E(1)ropE(2)rop(,=,=,,=,)E(1)E(2)29–G(B):E→EE|EE|E|(E)|i|EaropEa–iEa•1•2301•31(1)E→Ea(1)ropEa(2){T=NEWTEMP;GEN(rop,Ea(1)•PLACE,Ea(2)•PLACE,T);E•PLACE=T}(2)E→E(1)bopE(2){T=NEWTEMP;GEN(bop,Ea(1)•PLACE,Ea(2)•PLACE,T);E•PLACE=T}(3)E→E(1){T=NEWTEMP;GEN(,E(1)•PLACE,_,T);E•PLACE=T}(4)E→(E(1)){E•PLACE=E(1)•PLACE}(5)E→i{E•PLACE=ENTRY(i)}322X+YZA(BC):•G(B)LRLR•(+,X,Y,T1);E+E•(,T1,Z,T2);EE•(,B,_,T3);E•(,T3,C,T4);EE•(,A,T4,T5);EE•(,T2,T5,T6);EE33••–ABA1BAB1;•IFATHENTRUEELSEB.–ABA0BAB0;•IFATHENBELSEFALSE–A;•IFATHENFALSEELSETRUE.341•ifEthenS1elseS2ES1S2352E•(jnz,A1,_,P)–IfA1thengotoP•(jθ,A1,A2,P)–IfA1θA2thengotoP•(j,_,_P)–GotoP•PE“”“”36•ifABDthenS1elseS2•:(1)(jnz,A,_,(5));AS1•(2)(j,__,(3));A•(3)(j,B,D,(5));;•(4)(j,_,_,(P+1));;•(5)S1•……•(P)(j,_,_,(q));S1S2•(p+1)S2•……•(q)37•114“ABD”•2•3•4383–G(B):E→EE|EE|E|(E)|i|EaropEa•E→E(1)E(2)E(1)→i“”“”“”“”“”,•E→E(1)E(2)E→E0E(2)E0→E(1)•E→E(1)E(2)E→EAE(2)EA→E(1)393G`(B):–E→EAE|E0E|E|(E)|i|EaropEa–EA→E–E0→E404–E•TCE•FC–E•TCE•FCE“”“”414•E•TCE•FC———S0…E(1)SSYMPLACETCFC425G(B)–E→EAE|E0E|E|(E)|i|EaropEa–EA→E–E0→E•–(1)E→i{E•TC=NXQ;E•FC=NXQ+1;–GEN(jnz,ENTRY(i),_,0);–GEN(j,_,_,0)}–043•ABD••:(1)(jnz,A,_,0);•(2)(j,_,_,0);A•TC:1;•FC:2;445G(B)(7)E0→E(1)–{BACKPATCH(E(1)•FC,NXQ);–E0•TC=E(1)•TC;}•E(1)0E(1)0455G(B)PROCEDUREBACKPATCH(p,t)•{Q=p;•WHILE(Q0)•{q=Q4;•tQ•Q=q;}}•:46•ABD•:(1)(jnz,A,_,0);•(2)(j,_,_,(3));A•E0•TC:1;•FC475G(B)(2)E→EaropEa–{E•TC=NXQ;E•FC=NXQ+1;–GEN(jrop,Ea(1)•PLACE,Ea(2)•PLACE,0);–GEN(j,_,_,0)}48•ABD•:(1)(jnz,A,_,0);•(2)(j,_,_,(3));A•(3)(j,B,D,0);;•(4)(j,_,_,0);;•E•TC:3;•E•FC:4;495G(B)(8)E→E0E(2)–{E•FC=E(2)•FC;–E•TC=MERG(E0•TC,E(2)•TC}•EE(2)E(2)E(1)E(2)E50•ABD•:(1)(jnz,A,_,0);•(2)(j,_,_,(3));A•(3)(j,B,D,1);;•(4)(j,_,_,0);;•E•TC:31;•E•FC:4;51•FUNCTIONMERG(p1,p2);•{IFp2=0•MERG=p1•ELSE•{p=p2;•WHILEp40•p=p4;•p1p•MERG=p2;}}•p2p1p252•(3)E→(E(1))–{E•TC=E(1)•TC;E•FC=E(1)•FC}•(4)E→E(1)–{E•TC=E(1)•FC;E•FC=E(1)•TC}•(5)EA→E(1)–{BACKPATCH(E(1)•TC,NXQ);–EA•FC=E(1)•FC;}•(6)E→EAE(2)–{E•TC=E(2)•TC;–E•FC=MERG(EA•FC,E(2)•FC}53•ABC2#EAiC#2#EABC#2.(j,,0)(5)21#EBC#1.(jnz,a,,0)(3)21#EBC##iBC##ABC#FCTCSYMINPUT54FCTCSYMINPUT3.(jnz,B,,0)243#EAEC6.(j,,,3)56#E#6.(j,,,0)536#E0E#5.(jnz,C,,0)635#E#0E3#E0i3#E0C3#E0C43#EC4.(j,,,2)(5)43#EC55•••••56(GOTO)1•1–GOTO–L:S•L•2–L:S…GOTOL–GOTOL…L:S572•(1)L:S–……–GOTOL–……•(2)–S→gotoL–Label→i:•(3)–LLabelL58…S.QUADL………CATINFORMATIONNAMES.QUAD:SGOTOL(j,,,p)p=S.QUAD592(1)GOTOL`–……–GOTOL`–……–GOTOL`–……–L`:S•(2)–L`60…pL`………CATINFORMATIONNAME(2)(a)“”pCAT“”(b)(p)(j,,,0)61…qL`………CATINFORMATIONNAME(c)2L`L’q(d)(q)(j,,,p)p(c)(d)62…rL`………CATINFORMATIONNAME(r)(j,,,q)(q)(j,,,p)(p)(j,,,0)63(GOTO)•2•(2)–e)L`:SSBACKPATCH–•(3)––S→gotoL1–Label→i:264–{:–LLCAT‘’NXQGEN(j,,,0);–Lp=L.;L.NXQGEN(j,,,p);–Lp=L.;GEN(j,,,p);–}65–{:–LLCAT‘’NXQ–L‘’CAT;–{‘’–q=L.;–BACKPATCH(q,NXQ);–L.=NXQ;}–}66IF1IF–S→ifEthenS(1)–S→ifEthenS(1)elseS(2)2IF•(1)EE•TC,E•FC•(2)thenEBACKPATCH(E•TC,NXQ)•(3)S(1)67IF2IF•(4)elseS(1)GOTO(j,,,0)S(2)IFS(2)elseE•–ifE1thenifE2thenS1elseS2elseS3–SS•CHAIN68IF2IF•(4`)elseS(1)IF•(5)S(2)IFS(1)S•CHAIN•E,S(1),S(2)S•CHAIN69IF3•S→ifEthenS(1)elseS(2)–C→ifEthen–T→CS(1)else–S→TS(2)•S→ifEthenS(1)–C→ifEthen–S→CS(1)70IF4•C→ifEthen{BACKPATCH(E•TC,NXQ);–C•CHAIN=E•FC;}•T→CS(1)else{q=NXQ;GEN(j,,0);–BACKPATCH(C•CHAIN,NXQ);–T•CHAIN=MERG(S(1)•CHAIN,q)}•S→TS(2){S•CHAIN=MERG(T•CHAIN,S(2)•CHAIN)}•S
本文标题:廖力编译原理课件第7章
链接地址:https://www.777doc.com/doc-1776863 .html