• 第二版龙书习题答案

    龙书”。龙书是Alfred V. Aho等人于1986年出版的,由于出版年代较早,其中包含部分过时的技术并且没有反映一些新的编译技术。新编的《编译原理》抛弃诸如算符优先分析等过时技术,增加面向对象编译、类型检查等新技术

    0
    1361
    3.34MB
    2018-11-11
    50
  • 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*) (*Author: Niklaus Wirth*) label 99; (*定义标号*) const (*定义常量*) norw = 11; (*保留字最大长度*) txmax = 100; (*符号表最大记录数*) nmax = 14; (*数值型数据所含字符的最大长度*) al = 10; (*标识符最大长度*) amax = 2047; (*最大地址*) levmax = 3; (*分程序最大递归深度*) cxmax = 200; (*目标代码数组大小*) 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 = (constant,variable,procedure); (*类型标识符*) symset = set of symbol; (*式后字集合类型*) fct = (lit,opr,lod,sto,cal,int,jmp,jpc); (*目标代码中的操作码类型*) instruction = packed record f: fct; (*操作码*) l: 0..levmax; (*层差*) a: 0..amax; (*相对地址*) end; (* lit 0,a: 取常量a opr 0,a: 执行a 运算 lod l,a: 取变量(相对地址为a ,层差为l) sto l,a: 存变量 (相对地址为a ,层差为l) cal l,a: 调用过程(入口地址为a ,层差为l) int 0,a: 运行栈S 的指针值增加 a jmp 0,a: 转移到指令地址a 处 jpc 0,a: 条件转移到指令地址a 处*) var ch: char; (*当前字符*) sym: symbol; (*当前单词符号*) id: alfa; (*当前标识符*) num: integer;(*当前数*) cc: integer; (*行字符计数*) ll: integer; (*行长*) kk,err: integer; cx: integer; (*目标代码存放数组下标*) line: array[1..81] of char; (*行缓冲区*) a: alfa; code: array[0..cxmax] of instruction; (*目标代码区*) word: array[1..norw] of alfa; (*保留字表*) wsym: array[1..norw] of symbol; (*保留字机内表示表*) ssym: array[char] of symbol; (*运算符、界限符机内表示表*) mnemonic: array[fct] of packed array[1..5] of char; declbegsys,statbegsys,facbegsys: symset; table: array[0..txmax] of record name: alfa; case kind: object of constant: (val: integer); variable,procedure: (level,adr: integer) end; (*符号表*) procedure error(n: integer); (*报错程序*) begin writeln('****',' ':cc-1,'^',n:2); err:= err+1 end; (*error*)

    0
    420
    64KB
    2018-11-11
    50
上传资源赚积分or赚钱