?? pl0.h
字號(hào):
/**************************************************************************
* PL/0 語言編譯程序,由江漢石油學(xué)院計(jì)算機(jī)科學(xué)系周云才根據(jù)清華大學(xué)出版社出版,
* 呂映芝,張素琴,蔣維杜編寫的教材《編譯原理》中第二章(PL/0編譯程序的實(shí)現(xiàn))
* 以及附錄A中的代碼改編而成。
* 代碼版權(quán)由周云才擁有,使用者必須遵循以下約定:
* 可以免費(fèi)使用此文件,但必須包含此聲明。
* 可以修改、傳播、打印、出版這里的源代碼。
* 可以在任何軟件工程中使用這里的源代碼。
* 周云才對(duì)于由此源代碼的使用而引起的任何問題沒有任何責(zé)任。
* 周云才地址:湖北省荊州市江漢石油學(xué)院計(jì)算機(jī)科學(xué)系
* 郵編:434023
* 信箱:zyc262@163.net
* 電話: 0716-8431262
**********************************************************************************************/
#include <stdio.h>
#include <set>
#include <string>
#include <iostream>
#include <iostream>
#include <vector>
#ifndef WIRTH_ZYC_
#define WIRTH_ZYC_
using namespace std;
const int norw=13;//no. of reserved words
const int txmax=100;//length of identifier table
const int al=10;//length of identifiers
const int nmax=14;// max. no. of digits in numbers
const int amax=2047;//maximum address
const int levmax=3;// maximum depth of block nesting
const int cxmax=200;// size of code array
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;//functions
typedef set<symbol> symset;
struct instruction{
fct f;//function code
int l;//level,cann't big than levmax
int a;//displacement address,cann't big than amax
};
/*******************************************
* 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 *
*******************************************/
typedef struct{
alfa name;
obj0 kind;
union {
struct{int level,adr,size;}inOther;
int val;
}other;
} Table;
class PL0
{
protected:
bool listswitch,sourceEnd;
char ch;// last character read
symbol sym; //last symbol read
alfa id; // last identifier read
int num;//last number read
int cc; //character count
int ll; //line length
int kk,err;
int cx; //code allocation index
int codeNo;//code line no.
static string errStr[];//error string
char line[lineLength];//code line
vector<string> errorString;//error array
alfa a;
instruction code[cxmax+1];//destination code array
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 interpret();
};
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -