📄 pl0.h
字号:
#include <stdio.h>
#include <set>
#include <string>
#include <iostream>
#include <iostream>
#include <vector>
const int norw=13;//保留字的个数
const int txmax=100;//分析表的长度限制
const int al=10;//标识符的长度限制
const int nmax=14;// 数字的长度
const int amax=2047;//地址的最大值
const int levmax=3;//语法分析的最大层深
const int cxmax=200;//目标代码数组的长度。
const int lineLength=82;
typedef enum {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,WRITESYM,READSYM,DOSYM,CALLSYM,CONSTSYM,VARSYM,PROCSYM} symbol;
typedef char alfa[al+1];
typedef enum{CONSTANT,VARIABLE,PROCEDURE}obj0;
typedef enum {LIT,OPR,LOD,STO,CAL,INT,JMP,JPC} fct;//目标代码的功能码
typedef set<symbol> symset;
struct instruction{
fct f;//功能码
int l;//层深,不能比levmax大
int a;//地址,不能比amax大
};
typedef struct{
alfa name;
obj0 kind;
union {
struct{int level,adr,size;}inOther;
int val;
}other;
} Table;
class PL0//定义PL0类
{
protected:
bool listswitch,sourceEnd;
char ch;//最后读到的字符
symbol sym; //最后读到的关键字
alfa id; //最后读到的标识符
int num;//最后读到的数字
int cc; //字符计数
int ll; //行的长度
int kk,err;
int cx; //code数组的索引
int codeNo;//code数组的号
static string errStr[];//错误字符串
char line[lineLength];
vector<string> errorString;//error的数组,vector的功能实际上是栈。
alfa a;
instruction code[cxmax+1];//中间代码数组
alfa word[norw+1];
symbol wsym[norw+1];
symbol ssym[100];
char mnemonic[8][6];//中间代码指令名称
symset declbegsys,statbegsys,facbegsys;
Table table[txmax+1];
FILE *fin,*fout;
public:
void SaveCode();
PL0(char* source,char*destination);
~PL0(){fclose(fin),fclose(fout);}
void listcode(int cx0);
void error(int n);
void getsym();
void getch();
void gen(fct x,int y,int z);
void test(symset s1,symset s2,int n);
void block(int lev,int tx,symset fsys);
void enter(obj0 k,int &tx,int &dx,int lev);
int position(alfa id,int tx);
void constdeclaration(int&tx,int&dx,int lev);
void vardeclaration(int&tx,int&dx,int lev);
void factor(symset fsys,int tx,int lev);
void term(symset fsys,int tx,int lev);
void expression(symset fsys,int tx,int lev);
void condition(symset fsys,int tx,int lev);
void statement(symset fsys,int tx,int lev);
int base(int l,int b,int s[]);
void errout();
void interpret();
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -