lch22PL0编译程序的实现张素琴.ppt
文本预览下载声明
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 下标指针cx,tx和变量dx的作用 code [cx] table[tx] s [t] (运行栈) cx tx t(运行时栈指针) (0) jmp 0 0 (1) int 0 7 . . (cx ) . (0) name …adr... (1) b (dx) ... ( tx) q p m b Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. Table表的下标指针tx补充说明: 主程序 BLOCK 第1次调用block BLOCK(0,0,…) 0 0 ... BLOCK BLOCK(LEV+1,TX,…) (递归进入分程序) LEV tx LEV tx (6) 6 (9) 1 tx是BLOCK的 实际值参 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. PL/0编译程序的实现 procedure gen(x:fct; y, z:integer); begin if cxcxmax then(*指针越界*) begin write(‘program too long’); close(fin);(*关闭文件*) writeln; exit end; Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. PL/0编译程序的实现 with code[cx] do begin f:=x;(* 表示code[cx].f:=x; *) l:=y;(* 表示code[cx].l:=y; *) a:=z;(* 表示code[cx].a:=z; *) end; cx:=cx+1end (*gen*); Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. PL/0编译程序的实现 对分程序的定义(见教材417,437页) procedure block(lev,tx:integer;fsys:symset); var dx:integer; (*data allocationindex*) tx0:integer; (*initial table index*) cx0:integer; (*initial code index*) ( tx0,cx0是tx,cx的初值) Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. PL/0编译程序的实现 对分程序体人口的处理(见程序文本block 的过程体) begin (*block*) dx:=3; tx0:=tx; (保留当前table表指针值) table[tx].adr:=cx;(保留当前code指针值到过程名 的adr域 ) gen(jmp,0,0);(生成转向过程体入口的指令,该指令的地址 为cx 已保留在过程名的adr域,等生成 过程
显示全部