linux c语言实现pl0,PL0源代码(C语言版).doc

/*PL/0 编译系统C版本头文件 pl0.h*/

# define norw 13 //a number of reserved word /*关键字个数*/

# define txmax 100 //length of identifier table /*名字表容量*/

# define nmax 14 //max number of digits in numbers /*number的最大位数*/

# define al 10 //length of identifier /*符号的最大长度*/

# define amax 2047 //maximum address /*地址上界*/

# define levmax 3 //max depth of block nesting /*最大允许过程嵌套声明层数[0,lexmax]*/

# define cxmax 200 //size of code array /*最多的虚拟机代码数*/

/*符号*/

enum symbol{

nul, ident, number, plus, minus,

times, slash, oddsym, eql, neq, //slash斜线

lss, leq, gtr, geq, lparen, //leq :less than or equal to; gtr: great than;lparen:left parenthesis

rparen, comma, semicolon,period, becomes,//comma逗号 semicolon分号 period句号 becomes赋值号

beginsym, endsym, ifsym, thensym, whilesym,

writesym, readsym, dosym, callsym, constsym,

varsym, procsym,

};

#define symnum 32

/*-------------*/

enum object{ //object为三种标识符的类型

constant,

variable,

procedur,

};

/*--------------*/

enum fct{ //fct类型分别标识类PCODE的各条指令

lit, opr, lod, sto, cal, inte, jmp, jpc, //书本P23

};

#define fctnum 8

/*--------------*/

struct instruction //指令

{

enum fct f; //功能码

int l; //层次差

int a; //P23

};

FILE * fas; //输出名字表

FILE * fa; //输出虚拟机代码

FILE * fa1; //输出源文件及其各行对应的首地址

FILE * fa2; //输出结果

bool tableswitch; //显示名字表与否

bool listswitch; //显示虚拟机代码与否

char ch; //获取字符的缓冲区,getch使用

enum symbol sym; //当前符号

char id[al+1]; //当前ident,多出一个字节用于存放0

int num; //当前number

int cc,ll; //getch使用的计数器,cc表示当前字符(ch)的位置

int cx; //虚拟机代码指针,取值范围[0,cxmax-1]

char line[81]; //读取行缓冲区

char a[al+1]; //临时符号,多出的一个字节用于存放0

struct instruction code[cxmax]; //存放虚拟机代码的数组

char word[norw][al]; //保留字

enum symbol wsym[norw]; //保留字对

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值