编译原理中的PL0编译程序

时间:2013-07-03 04:44:21
【文件属性】:
文件名称:编译原理中的PL0编译程序
文件大小:25KB
文件格式:TXT
更新时间:2013-07-03 04:44:21
PL0编译程序 编译原理 中间代码 PL/0语言是Pascal语言的一个子集,我们这里分析的PL/0的编译程序包括了对PL/0语言源程序进行分析处理、编译生成类PCODE代码,并在虚拟机上解释运行生成的类PCODE代码的功能。   PL/0语言编译程序采用以语法分析为核心、一遍扫描的编译方法。词法分析和代码生成作为独立的子程序供语法分析程序调用。语法分析的同时,提供了出错报告和出错恢复的功能。在源程序没有错误编译通过的情况下,调用类PCODE解释程序解释执行生成的类PCODE代码。 PL0的一部分代码: program PL0 (input,output); (*PL/0 compiler with code generation*) (*Program 5.6 in Algorithms + Data Structures = Programs*) (*Almost identical with the version in Compilerbau *) label 99; const norw = 11; (*no. of reserved words*) txmax = 100; (*length of identifier table*) nmax = 14; (*max. no. of digits in numbers*) al = 10; (*length of identifiers*) amax = 2047; (*maximum address*) levmax = 3; (*maximum depth of block nesting*) cxmax = 200; (*size of code array*) type symbol = (nul,ident,number,plus,minus,times,slash,oddsym, eql,neq,lss,leq,gtr,geq,lparen,rparen,comma,semicolon, period,becomes,beginsym,endsym,ifsym,thensym, whilesym,dosym,callsym,constsym,varsym,procsym); alfa = packed array[1..al] of char; object_1 = (constant,variable,prozedure); symset = set of symbol; fct = (lit,opr,lod,sto,cal,int,jmp,jpc); (*functions*) instruction = packed record f: fct; (*function code*) l: 0..levmax;(*level*) a: 0..amax; (*displacement address*) end; (* lit 0,a: load constant a opr 0,a: execute operation a lod l,a: load variable l,a sto l,a: store variable l,a cal l,a: call procedure a at level l int 0,a: increment t-register by a jmp 0,a: jump to a jpc 0,a: jump conditional to a*) .......

网友评论

  • 还在研究中,感谢分享
  • 这个东西也是参考的清华的那本编译书的, 正好用得上 ,感谢分享