欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    《中间代码生成》PPT课件.ppt

    • 资源ID:5456899       资源大小:1.04MB        全文页数:155页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    《中间代码生成》PPT课件.ppt

    中间代码生成,第八章 中间代码生成,中间代码说明语句的翻译赋值语句的翻译控制语句的翻译(if、循环)属性文法的实现过程调用的翻译,8.1 中间代码,作用过渡:经过语义分析被译成中间代码序列形式中间语言的语句优点便于编译系统的实现、移植、代码优化,常用的中间代码(语言),三地址代码(四元式)语法(结构)树(三元式)(5.2节)后缀式逆波兰表示(2.3节)特点形式简单、语义明确、便于翻译独立于目标语言,例 8-1 表达式(A-12)*B+6 的中间代码,+,*,6,-,A,12,B,三地址码T1=A-12T2=T1*BT3=T2+6,四元组(-,A,12,T1)(*,T1,B,T2)(+,T2,6,T3),三元组(-,A,12)(*,B)(+,6),波兰表示+*-A12B6逆波兰表示A12-B*6+,如何生成语言结构的三地址码,类似于构建语法树生成后缀表示,以S:=(A-12)*B+6为例将赋值语句变换为语法结构树,属性设置E.p 是语法结构树指针id.entry 是名字的符号表入口num.val 是数值基本函数结点构造mknode 建中间结点mkleaf 建叶结点,6,A,12,-,+,B,*,S,:=,生成赋值语句语法树的语法制导定义,例 8-2:a:=b*(-c)+b*(-34)的语法结构树直观描述,:=,*,-,0,+,*,-,0,id,b,num,34,id,b,id,c,id,a,root,语法结构树数组存储形式,地址 算符 操作数 操作数012345678910,a:=b*(-c)+b*(-34),以语法分析为中心,后缀式(逆波兰表示),操作数 1,操作数 2,运算符操作数,运算符例 8-7:a:=b*(-c)+b*(-34)的后缀式a b c-*b 34-*+:=,生成后缀式的属性文法,三地址代码,一般形式 x:=y op z其中 x,y,z 为变量名、常数或编译产生的临时变量四元式(op,y,z,x),种类:x:=y op z 双目运算 x:=op y 单目运算 x:=y 赋值语句 if x relop y goto l 条件转移语句(relop,x,y,l),其它语句的三地址代码,goto l 无条件转移 param x 实在参数 call p,n 过程调用 return x 过程返回 x:=yi数组运算 xi:=y x:=&y指针运算 x:=*y*x=y,生成三地址码的属性文法,8.2 说明语句的翻译,作用说明语句(Declarations)用于对程序中规定范围内使用的各类变量、常数、过程进行说明编译要完成的工作在符号表中记录被说明对象的属性,为执行做准备,要关心的问题,类型基本类型/内部类型(built-in):整型、实型、双精度型、逻辑型、字符型用户定义类型结构描述作用域有效范围一般:说明所在的分程序、过程,要关心的问题,类型的作用引入数据抽象、隐蔽数据的基本表示用户无需注明字节数规定可用的运算类型检查数据精度控制规定存储单元的字节数,优化空间管理,变量说明的翻译,在符号表中填写变量的属性种别、类型、相对地址、作用域等相对地址全局变量表示为静态数据区的偏移值(offset)局部变量表示为局部数据区(活动记录部分)的偏移值两种数据区,例 8-3:相对地址举例,名字 相对地址x 0i64j68,08566468,beginreal x8;integer i,j;end,文法描述,P DD D;DD id:TT integer T realT arraynum of T1 T T1,例如:a:integer;b:real;c:array10of real,属性、过程、与全局量,文法变量T(类型)的属性type 类型width 占用的字节数基本子程序enter:设置变量的类型和地址array:数组类型处理全局量offset:已分配空间字节数,说明语句的翻译模式,P offset:=0 DDD;DDid:T enter(id.name,T.type,offset);offset:=offset+T.widthTinteger T.type:=integer;T.width:=4Treal T.type:=real;T.width:=8Tarray num of T1 T.type:=array(num.val,T1.type);T.width:=num.val*T1.widthTT1 T.type:=pointer(T1.type);T.width:=4,PMDM offset:=0,例 8-4 x:real;i:integer 的翻译,enter(x,real,0),offset=0,offset=8,T.type=realT.width=8,offset=12,T.type=integerT.width=4,enter(i,integer,8),Did:T enter(id.name,T.type,offset);offset:=offset+T.width,例 8-4 x:real;i:integer 的翻译,Poffset:=0Doffset:=0D;Doffset:=0 x:Tenter(x,T.type,offset);offset:=offset+T.width;Doffset:=0 x:realT.type:=real;T.width:=8 enter(x,T.type,offset);offset:=offset+T.width;Dx:real(x,real,0);offset:=8;Dx:real(x,real,0);offset:=8;i:Tenter(id.name,T.type,offset);offset:=offset+T.widthx:real(x,real,0);offset:=8;i:integerT.type:=integer;T.width:=4enter(i,T.type,offset);offset:=offset+T.widthx:real(x,real,0);i:integer(i,integer,8);offset:=12,作用域信息的保存,所讨论语言的文法P D SD D;D|id:T|proc id;D;S 语义动作用到的函数mktable(previous):创建一个新的符号表;enter(table,name,type,offset)addwidth(table,width):符号表的大小;enterproc(table,name,newtable)在table指向的符号表中为name建立一个新表项;,P M D S addwidth(top(tblptr),top(offset);pop(tblptr);pop(offset)M t:=mktable(nil);push(t,tblptr);push(0,offset)D D1;D2D proc id;N D1;S t:=top(tblptr);addwidth(t,top(offset);pop(tblptr);pop(offset);enterproc(top(tblptr),id.name,t)Did:T enter(top(tblptr),id.name,T.type,top(offset);top(offset):=top(offset)+T.widthN t:=mktable(top(tblptr);push(t,tblptr);push(0,offset),处理嵌套过程中的说明语句,program sort(input,output);var a:array0.10 of integer;x:integer;procedure readarray;var i:integer;begin aend;procedure exchange(i,j:integer);begin x:=ai;ai:=aj;aj:=x;end;procedure quicksort(m,n:integer);var k,v:integer;function partition(y,z:integer):integer;var i,j:integer;begin a v exchange(i,j)end;begin end;begin end;,例:一个带有嵌套的pascal程序(图7-22),表 头,空,sort,offset,tblptr,top,top,0,表 头,空,sort,offset,tblptr,top,top,40,a array 0,x integer 40,a array 0,表 头,空,sort,offset,tblptr,top,top,44,表 头,空,sort,readarrary,表 头,offset,tblptr,top,top,44,0,a array 0,x integer 40,表 头,空,sort,readarrary,表 头,offset,tblptr,top,top,44,4,a array 0,x integer 40,i integer 0,表 头,空,sort,readarrary,表 头 4,offset,tblptr,top,top,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头,top,top,0,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头,quicksort,0,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头,quicksort,4,k integer 0,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头,quicksort,8,k integer 0,v integer 4,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头,quicksort,8,k integer 0,v integer 4,表 头,partition,0,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头,quicksort,8,k integer 0,v integer 4,表 头,partition,4,i integer 0,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头,quicksort,8,k integer 0,v integer 4,表 头,partition,8,i integer 0,j integer 4,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头,quicksort,8,k integer 0,v integer 4,表 头 8,partition,i integer 0,j integer 4,partition,表 头,空,sort,readarrary,表 头 4,offset,tblptr,44,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头 8,quicksort,k integer 0,v integer 4,表 头 8,partition,i integer 0,j integer 4,partition,quicksort,表 头 44,空,sort,readarrary,表 头 4,offset,tblptr,a array 0,x integer 40,i integer 0,readarray,指向readarray,exchange,表 头 0,top,top,exchange,指向exchange,表 头 8,quicksort,k integer 0,v integer 4,表 头 8,partition,i integer 0,j integer 4,partition,quicksort,记录说明的翻译,空间分配设置首地址和各元素的相对地址大于所需的空间(对齐)例:struct Node float x,y;struct node*next;node;,0,4,8,记录说明的翻译,符号表及有关表格处理为每个记录类型单独构造一张符号表将域名id的信息(名字、类型、字节数)填入到该记录的符号表中所有域都处理完后,offset将保存记录中所有数据对象的宽度T.type通过将类型构造器record应用于指向该记录符号表的指针获得,记录的域名,T record D endT record L D endT.type:=record(top(tblptr);T.width:=top(offset);pop(tblptr);pop(offset)L t:=mktable(nil);push(t,tblprt);push(0,offset),数组说明的翻译,符号表及有关表格(内情向量)处理维数、下标上界、下标下界、类型等空间分配首地址、需用空间计算存放方式按行存放、按列存放影响具体元素地址的计算,数组的引用与分配策略,操作元素的引用、修改:数组:Ai,j,k 记录、结构、联合:结构的引用、修改:A,B,A.c分配策略静态:直接完成相应的分配工作动态:构造代码,以在运行时调用分配过程,静态数组分配要完成的工作,数组存放在一个连续的存储区中知道起始地址要计算该数组的大小按照与简单变量类似的方式进行分配,?哪些要处理的问题准备上下界的计算体积的计算动态分配子程序将计算的结果告诉动态分配子程序进行分配,动态数组分配要完成的工作,动态分配方案下数组说明的代码结构,D id:array low1:up1,lown:upn of T,low1.code送工作单元W1up1.code送工作单元W2lown.code送工作单元W2n-1upn.code送工作单元W2n,动态分配子程序其它参数(n,type)转动态分配子程序入口,?D id:array num of T,8.4 赋值语句的翻译,翻译的需求充分了解各种语言现象的语义包括:控制结构、数据结构、单词充分了解它们的实现方法目标语言的语义了解中间代码的语义了解运行环境,实现赋值语句的翻译,基本子程序gen(code),emit(code):产生一条中间代码newtemp:产生新的临时变量lookup:检查符号表中是否出现某名字属性设置中间代码序列 code存储位置 place,为赋值语句产生三地址码的翻译模式,S id:=E p:=lookup(id.name);if p nil thenemit(p,:=,E.place)else error E E1+E2E.place:=newtemp;emit(E.place,:=,E1.place,+,E2.place)E E1 E.place:=newtemp;emit(E.place,:=,uminus,E1.place)E(E1)E.place:=E1.place E id p:=lookup(id.name);if p nil then E.place:=p else error,临时名字的重用,大量临时变量的使用对优化有利大量临时变量会增加符号表管理的负担也会增加运行时临时数据占的空间E E1+E2的动作产生的代码的一般形式为计算E1到t1计算E2到t2t3:=t1+t2()()()()临时变量的生存期像配对括号那样嵌套或并列,基于临时变量生存期特征的三地址代码,x:=a b+c d e f,引入一个计数器c,它的初值为0。每当临时变量作为运算对象使用时,c减去1;每当要求产生新的临时名字时,使用$c并把c增加1。,数组元素的引用,数组元素的翻译完成上下界检查生成完成相对地址的计算代码目标x:=yi 和 yi:=xy为数组地址的固定部分相当于第1个元素的地址,i是相对地址,不是数组下标,数组元素地址计算-行优先,一维数组Alow1:up1(nk=upk-lowk+1)Addr(Ai)=base+(i-low1)*w=(base-low1*w)+i*w=c+i*w二维数组Alow1:up1,low2:up2;Ai1,i2Addr(Ai1,i2)=base+(i1-low1)*n2+(i2-low2)*w=base+(i1-low1)*n2*w+(i2-low2)*w=base-low1*n2*w-low2*w+i1*n1*w+i2*w=base-(low1*n2-low2)*w+(i1*n1+i2)*w=c+(i1*n2+i2)*w,A1,1,A1,2,A1,3 A2,1,A2,2,A2,3,数组元素地址计算的翻译方案,下标变量访问的产生式L idElist|idElist Elist,E|E为了使数组各维的长度n在我们将下标表达式合并到Elist时是可用的,需将产生式改写为:L Elist|idElist Elist,E|idE,数组元素地址计算的翻译方案,L Elist|id Elist Elist,E|idE目的使我们在整个下标表达式列表Elist的翻译过程中随时都能知道符号表中相应于数组名id的表项,从而能够了解登记在符号表中的有关数组id的全部信息。于是我们就可以为非终结符Elist引进一个综合属性array,用来记录指向符号表中相应数组名字表项的指针。,数组元素地址计算的翻译方案,属性Elist.array,用来记录指向符号表中相应数组名字表项的指针。Elist.ndim,用来记录Elist中下标表达式的个数,即数组的维数。Elist.place,用来临时存放Elist的下标表达式计算出来的值。函数limit(array,j),返回nj,赋值语句完整的产生式,S L:=EE E+EE(E)E LL ElistL idElist Elist,EElist idE,赋值语句的翻译模式,Lid L.place:=id.place;L.offset:=null ElistidE Elist.place:=E.place;Elist.ndim:=1;Elist.array:=id.place ElistElist1,E t:=newtemp;m:=Elist1.ndim+1;emit(t,:=,Elist1.place,limit(Elist1.array,m);emit(t,:=,t,+,E.place);Elist.array:=Elist1.array;Elist.place:=t;Elist.ndim:=mL Elist L.place:=newtemp;emit(L.place,:=,base(Elist.array),invariant(Elist.array);L.offset:=newtemp;emit(L.offset,:=,Elist.place,w),赋值语句的翻译模式,E Lif L.offset=null then/L是简单变量/E.place:=L.place else begin E.place:=newtemp;emit(E.place,:=,L.place,L.offset,)endE E1+E2E.place:=newtemp;emit(E.place,:=,E1.place,+,E2.place)E(E1)E.place:=E1.place S L:=Eif L.offset=null then/L是简单变量/emit(L.place,:=,E.place)else emit(L.place,L.offset,:=,E.place),例:设A是一个1020的整型数组,w=4,例,t1:=y 20 t1:=t1+z,例,t1:=y 20 t1:=t1+z,t2:=A 84 t3:=4 t1,例,t1:=y 20 t1:=t1+z,t2:=A 84 t3:=4 t1,t4:=t2 t3,例,t1:=y 20 t1:=t1+z,t2:=A 84 t3:=4 t1,t4:=t2 t3,x:=t4,表达式翻译中的其它问题,临时变量空间的统计了解需求、及时释放运算合法性检查利用符号表保存的名字类型类型自动转换填加专用指令,类型转换,x:=y+i j(x和y的类型是real,i和j的类型是integer)中间代码t1:=i int jt2:=inttoreal t1 t3:=y real+t2 x:=t3,类型转换,E E1+E2的语义子程序E.place:=newtempif E1.type=integer and E2.type=integer then begin emit(E.place,:=,E1.place,int+,E2.place);E.type=integerendelse if E1.type=integer and E2.type=real then beginu:=newtemp;emit(u,:=,inttoreal,E1.place);emit(E.place,:=,u,real+,E2.place);E.type:=realend.,8.5 控制语句的翻译,高级语言的控制结构顺序 begin 语句;;语句end条件 if_then_else、if_thenswitch、case循环 while_do、do_while for、repeat_until三地址码goto n(j,_,_,n)if x relop y goto n(jrelop,x,y,n),布尔表达式的翻译,基本文法EE1 or E2|E1 and E2|not E1|(E1)|id1 relop id2|id处理方式数值表示法(与算术表达式的处理类似)真:E.place=1假:E.place=0真假出口表示法(作为条件控制)真出口:E.true假出口:E.false,数值表示法,a or b and not ct1:=not ct2:=b and t1t3:=a or t2ab100:if ab goto 103101:t:=0102:goto 104103:t:=1104,数值表示法,E E1 or E2 E.place:=newtemp;gen(E.place:=E1.placeorE2.place)E E1 and E2 E.place:=newtemp;gen(E.place:=E1.placeandE2.place)E not E1 E.place:=newtemp;gen(E.place:=notE1.place),数值表示法,E(E1)E.place:=E1.place E id1 relop id2 E.place:=newtemp;gen(ifid1.place relop.op id2.placegotonextstat+3);gen(E.place:=0);gen(gotonextstat+2);gen(E.place:=1)E id E.place:=id.place;,真假出口表示法,属性E.true,E为真时控制到达的位置;E.false,E为假时控制到达的位置。abif ab goto E.truegoto E.falseEE1 or E2如果E1为真,则立即可知E为真,即E1.true与E.true相同;如果E1为假,则必须计算E2的值,令E1.false为E2的开始E2的真假出口分别与E的真假出口相同,简单布尔表达式的翻译示例 例如:ab or cd and ef,if ab goto Ltrue goto L1L1:if cd goto L2 goto LfalseL2:if ef goto Ltrue goto Lfalse,真假出口表示法,E E1 or E2 E1.true:=E.true;E1.false:=newlab;E2.true=E.true;E2.false:=E.false;E.code:=E1.code;gen(E1.false:);E2.code E E1 and E2 E1.true:=newlab;E1.false:=E.false;E2.true=E.true;E2.false:=E.false;E.code:=E1.code;gen(E1.true:);E2.code E not E1 E1.true:=E.false;E1.false:=E.true;E.code:=E1.code,真假出口表示法,E(E1)E1.true:=E.true;E1.false:=E.false;E.code:=E1.codeE id1 relop id2 E.code:=gen(ifid1.place relop id2.placegotoE.true);gen(goto E.false)E id E.code:=gen(if id1.place goto E.true);gen(goto E.false),混合模式布尔表达式的翻译,E E1 relop E2 E1+E2 E.code:=E1.code;E2.code;gen(ifE1.place relop E2.place gotoE.true);gen(gotoE.false),混合模式布尔表达式的翻译示例 例如:4+ab-c and d,t1=4+a t2=b-c if t1t2 goto L1 goto LfalseL1:if d goto Ltrue goto Lfalse,回填,两遍扫描:从给定的输入构造出一棵语法树;对语法树按深度优先遍历,来进行定义中给出的翻译。一遍扫描:先产生暂时没有填写目标标号的转移指令。对于每一条这样的指令作适当的记录,一旦目标标号被确定下来,再将它“回填”到相应的指令中。E.truelistE.falselist,回填,翻译模式用到如下三个函数:1makelist(i):创建一个仅包含i的新表,i 是四元式数组的一个索引(下标),或说 i是四元式代码序列的一个标号。2merge(p1,p2):连接由指针p1和p2指向 的两个表并且返回一个指向连接后的表的 指针。3backpatch(p,i):把i作为目标标号回 填到p所指向的表中的每一个转移指令中 去。此处的“表”都是为“回填”所拉的链,布尔表达式的自底向上语法制导翻译模式,E E1 or M E2backpatch(E1.falselist,M.quad);E.truelist:=merge(E1.truelist,E2.truelist);E.falselist:=E2.falselistM M.quad:=nextquad,布尔表达式的自底向上语法制导翻译模式,E E1 and M E2backpatch(E1.truelist,M.quad);E.truelist:=E2.truelistE.falselist:=merge(E1.falselist,E2.falselist);,布尔表达式的自底向上语法制导翻译模式,E not E1E.truelist:=E1.falselist;E.falselist:=E1.truelist;,布尔表达式的自底向上语法制导翻译模式,E(E1)E.truelist:=E1.truelist;E.falselist:=E1.falselist;,布尔表达式的自底向上语法制导翻译模式,E id1 relop id2E.truelist:=makelist(nextquad);E.falselist:=makelist(nextquad+1);emit(ifid1.place relop id2.place goto-)Emit(goto-),布尔表达式的自底向上语法制导翻译模式,E trueE.truelist:=makelist(nextquad)emit(goto-)E falseE.falselist:=makelist(nextquad)emit(goto-),例,E.t=100,104E.f=103,105,M.q:=102,E.t:=100E.f:=101,E.t=104E.f=103,105,E.t=102E.f=103,E.t=104E.f=105,图 8-29 ab or cd and ef的注释分析树,a,b,or,M.q:=104,and,c,d,e,f,100:if ab goto 101:goto-102:if cd goto 104103:goto 104:if ef goto 105:goto-,100:if ab goto 101:goto-,102:if cd goto 103:goto-,104:if ef goto 105:goto-,100:if ab goto 101:goto 102102:if cd goto 104103:goto 104:if ef goto 105:goto-,控制流语句的翻译,S if E then S1|if E then S1 else S2|while E do S1|S1;S2|A/*赋值语句*/S.nextlist:=nil,控制流语句的翻译,控制流语句的翻译,S if E then S1E.true:=newlabel;E.false:=S.next;S1.next:=S.next;S.code:=E.code|gen(E.true,:)|S1.code,控制流语句的翻译,S if E then S1 else S2E.true:=newlabel;E.false:=newlabel;S1.next:=S.next;S2.next:=S.next;S.code:=E.code|gen(E.true,:)|S1.code|gen(goto,S.next)|gen(E.false,:)|S2.code,控制流语句的翻译,S while E do S1 S.begin:=newlabel;E.true:=newlabel;E.false:=S.next;S1.next:=S.begin;S.code:=gen(S.begin,:)|E.code|gen(E.true,:)|S1.code|gen(goto,S.begin),控制流语句的翻译,S S1;S2S1.next:=newlabel;S2.next:=S.next;S.code:=S1.code|gen(S1.next,:)|S2.code,例 8-4:翻译下列语句,while a y do z:=x+1;else S2 x:=y,S3,生成的三地址代码序列,L1:if a y goto L5 goto L1L5:t1:=x+1z:=t1 goto L3L4:x:=y goto L1Lnext:,E1.code,E2.code,S1.code,S2.code,S3.code,while ay do z:=x+1 else x:=y,控制流语句的自底向上翻译_利用回填技术,S if E then M S1|if E then M1 S1 N else M2 S2|while M1 E do M2 S1|S1;M S2 M M.quad:=nextquadN N.nextlist:=makelist(nextquad);emit(goto-),if-then语句的自底向上翻译,S if E then M S1backpatch(E.truelist,M.quad)S.nextlist:=merge(E.falselist,S1.nextlist),if-then-else语句的自底向上翻译,S if E then M1 S1 N else M2 S2backpatch(E.truelist,M1.quad);backpatch(E.falselist,M2.quad);S.nextlist:=merge(S2.nextlist,merge(N.nextlist,S1.nextlist),while语句的自底向上翻译,S while M1 E do M2 S1backpatch(S1.nextlist,M1.quad);backpatch(E.truelist,M2.quad);S.nextlist:=E.falselist;emit(gotoM1.quad),语句列表的翻译,S S1;M S2backpatch(S1.nextlist,M.quad);S.nextlist:=S2.nextlist,例 8-4:翻译下列语句,while a y do z:=x+1;else S2 x:=y,S3,例,while ay do z:=x+1 else x:=y的注释分析树,S.n:=101,while,M1.q:=100,E.t:=100E.f:=101,a,b,do,M2.q:=102,S1.n:=105,109,if,E.t:=102E.f:=103,c,5,then,M1.q:=104,S1.n:=105,N.n:=109,else,M2.q:=110,S2.n:=nil,:=,x,y,while,M1.q:=104,E.t:=104E.f:=105,x,y,do,M2.q:=106,:=,z,E.place=t1,M1.q:=100,E.t:=100E.f:=101,M2.q:=102,E.t:=102E.f:=103,M1.q:=104,M1.q:=104,E.t:=104E.f:=105,M2.q:=106,+,x,1,E.place=t1,S1.n:=105,S,S.n:=nil,N.n:=109,M2.q:=110,S2.n:=nil,S1.n:=105,109,S.n:=101,生成的四元式序列,100:(j

    注意事项

    本文(《中间代码生成》PPT课件.ppt)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开