?? pl0.h
字號:
/*
* PL/0 complier program for win32 platform (implemented in C)
*
* The program has been test on Visual C++ 6.0, Visual C++.NET and
* Visual C++.NET 2003, on Win98, WinNT, Win2000, WinXP and Win2003
*
*/
typedef enum {
false,
true
} bool;
#define norw 13 /* 關鍵字個數 */
#define txmax 100 /* 名字表容量 */
#define nmax 14 /* number的最大位數 */
#define al 10 /* 符號的最大長度 */
#define amax 2047 /* 地址上界*/
#define levmax 3 /* 最大允許過程嵌套聲明層數 [0, levmax]*/
#define cxmax 500 /* 最多的虛擬機代碼數 */
/* 符號 */
enum 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,
writesym, readsym, dosym, callsym, constsym,
varsym, procsym};
#define symnum 32
/* 名字表中的類型 */
enum object {
constant,
variable,
procedur,
array //add
};
/* 虛擬機代碼 */
enum fct {
lit, opr, lod,
sto, cal, inte,
jmp, jpc
};
#define fctnum 8
/* 虛擬機代碼結構 */
struct instruction
{
enum fct f; /* 虛擬機代碼指令 */
int l; /* 引用層與聲明層的層次差 */
int a; /* 根據f的不同而不同 */
};
FILE* fas; /* 輸出名字表 */
FILE* fa; /* 輸出虛擬機代碼 */
FILE* fa1; /* 輸出源文件及其各行對應的首地址 */
FILE* fa2; /* 輸出結果 */
bool listswitch; /* 顯示虛擬機代碼與否 */
bool tableswitch; /* 顯示名字表與否 */
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]; /* 保留字的類別碼 */
enum symbol ssym[256]; /* 單字符的類別碼 */
char mnemonic[fctnum][5]; /* 虛擬機代碼指令名稱 */
bool declbegsys[symnum]; /* 表示聲明開始的符號集合 */
bool statbegsys[symnum]; /* 表示語句開始的符號集合 */
bool facbegsys[symnum]; /* 表示因子開始的符號集合 */
/* 名字表結構 */
struct tablestruct
{
char name[al]; /* 名字 */
enum object kind; /* 類型:constant, variable, procedur, array */
int val; /* 數值,僅const使用 */
int level; /* 所處層,僅const不使用 */
int adr; /* 地址,僅const不使用 */
int size; /* 需要分配的數據區空間, 僅procedure使用 */
};
struct tablestruct table[txmax]; /* 名字表 */
FILE* fin;
FILE* fout;
char fname[al];
int err; /* 錯誤計數器 */
/* 當函數中會發生fatal error時,返回-1告知調用它的函數,最終退出程序 */
#define getsymdo if(-1 == getsym()) return -1
#define getchdo if(-1 == getch()) return -1
#define testdo(a, b, c) if(-1 == test(a, b, c)) return -1
#define gendo(a, b, c) if(-1 == gen(a, b, c)) return -1
#define expressiondo(a, b, c) if(-1 == expression(a, b, c)) return -1
#define factordo(a, b, c) if(-1 == factor(a, b, c)) return -1
#define termdo(a, b, c) if(-1 == term(a, b, c)) return -1
#define conditiondo(a, b, c) if(-1 == condition(a, b, c)) return -1
#define statementdo(a, b, c) if(-1 == statement(a, b, c)) return -1
#define constdeclarationdo(a, b, c) if(-1 == constdeclaration(a, b, c)) return -1
#define vardeclarationdo(a, b, c) if(-1 == vardeclaration(a, b, c)) return -1
void error(int n);
int getsym();
int getch();
void init();
int gen(enum fct x, int y, int z);
int test(bool* s1, bool* s2, int n);
int inset(int e, bool* s);
int addset(bool* sr, bool* s1, bool* s2, int n);
int subset(bool* sr, bool* s1, bool* s2, int n);
int mulset(bool* sr, bool* s1, bool* s2, int n);
int block(int lev, int tx, bool* fsys);
void interpret();
int factor(bool* fsys, int* ptx, int lev);
int term(bool* fsys, int* ptx, int lev);
int condition(bool* fsys, int* ptx, int lev);
int expression(bool* fsys, int* ptx, int lev);
int statement(bool* fsys, int* ptx, int lev);
void listcode(int cx0);
int vardeclaration(int* ptx, int lev, int* pdx);
int constdeclaration(int* ptx, int lev, int* pdx);
int position(char* idt, int tx);
void enter(enum object k, int* ptx, int lev, int* pdx);
int base(int l, int* s, int b);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -