⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 头文件.h

📁 八、 设计SAMPLE语言的语法、语义分析器
💻 H
字号:

#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
#define max 61
#define max2 200
#define max3 40
#define max4 40
#define max0 10
class item{
public:
	int x,y;
	item();
	item(int x1,int x2);
};

class jieguolist{
public:
	int w;
	int hang[max2];
	item jieguo[max2];
	jieguolist();
	void add(int hao,int id,int);
};
class changbiaolist{
public :
	int idend;
	char *list[max2];
	changbiaolist();
	void add(char hao[max3]);
};
class biaomalist{
public:
	char*list[max];
	biaomalist();
};
class bianYi{
	private:
	ifstream inf;
	int i;//行号
	
	public:
		biaomalist list1;
	    jieguolist list3;
	    changbiaolist list2;
		void createbianYi(char*fileName);
		bianYi();
		bianYi(char*fileName);
		int looklist1(int begin,int end,char fuhao[10]);
		int looklist2(char fuhao[10]);
        int looklist22(char fuhao[max3]);
		char getCh();
		~bianYi();
		void ciFa();
};

////////////////////////////////////////////////////////////////////////////state
#define numchain 10
class state{
public:
      int chain[numchain];
      int codebegin;
      state&merge(int cs[],int cd[]);
	  state&operator=(state &);
	  state(const state&temp);
	  state();
};

////////////////////////////////////////////////////////////////////////////tfl
#define numTFL 10
class TFL{
public:
	TFL(){};
    int headt[numTFL];
    int headf[numTFL];
    int codebegin;
    TFL&operator=(TFL &temp);
	TFL( const TFL & temp); 

} ; 

//算符
#define suanfu_or    1
#define suanfu_and   2
#define suanfu_not   3
#define suanfu_above     4
#define suanfu_low     5
#define suanfu_leftkuohao   6
#define suanfu_rightkuohao     7
#define suanfu_bctf  0
#define suanfu_jing     8
#define suanfu_equ 9
#define suanfu_lowequ 10
#define suanfu_aboveequ 11
#define suanfu_end   100
#define numsuanfu 11
#define volumnstack 40
#define nummaxstack 10
#define volumntruelist 10
#define volumnfalselist 10
#define _available 1
#define _unavailable 0

class suanfu_stack{
public:
     int suanfutop;
     int optop;/////运算符顶
     item sfs[volumnstack];
     int truelist[nummaxstack][volumntruelist];
     int falselist[nummaxstack][volumnfalselist];
     suanfu_stack();
	 void suanfu_clear();
     int applyfortruelist();
     int applyforfalselist();
     void suanfu_push(item temp);
     void suanfu_pop(item &temp);
     void truelist_merge(int first,int second,int end);
     void falselist_merge(int first,int second,int end);
};
int findfuhaobiao(int k);
void superpop(int i);
TFL boolean_E(); //这一模块的入口


//控制
/*
while_W->while
while_C->while_W boolean_E do
while_T->while_C S
*/
state while_W();
state while_C();
state while_T();//while控制语句的入口
/*
if_C->if boolean_E then
if_T->if_C S else
if_E->if_T S
*/
state if_T();
state if_C();
state if_E();//while控制语句的入口
/*
repeat_E->repeat_T E
repeat_T->repeat_B S until
repeat_B->repeat
*/
state repeat_B();
state repeat_E();//repeat控制语句的入口
state repeat_T();
//赋值
#define numfuzhi 8
#define fuzhi_add 1
#define fuzhi_sub 2
#define fuzhi_mul 3
#define fuzhi_div 4
#define fuzhi_equ 5
#define fuzhi_bc 0
#define fuzhi_jing   6
#define fuzhi_leftkuohao 7
#define fuzhi_rightkuohao 8
#define volumnstack 40
#define fuzhi_end   100
class fuzhi_stack{
public:
     int fuzhitop;
     int optop;/////运算符顶
     item fzs[volumnstack];
     fuzhi_stack();
     int applyforitem(char []);
     void fuzhi_push(item temp);
     void fuzhi_pop(item &temp);
	 void fuzhi_clear();
};
int findfuzhibiao(int k);
void fuzhi_superpop(int i);
state fuzhi_E();//这一模块的入口

#define numtv 20
class valuetype{
public:
	int type;
	int location;
	valuetype(int,int );
	valuetype(const valuetype&);
	valuetype();
};
class valuetable{
public:
	valuetype vt[numtv];
	int vttop;
	valuetable();
	void add(valuetype);
	int vt_findlocation(int l);
	void print();
};
state sentence();//入口
state St();
state K();
valuetype valueDefine();
valuetype L();
valuetype T();
//语句构造
/*
mulsentence->begin sentencelist end   复合语句的chain取语句表的chain
sentencelist->sentence sentencetemp   用临时句的codebegin回填语句的chain,用sentencetemp的chain作为语句表的chain
sentencetemp->;sentencelist|#         语句表的chain作为临时句的chain,若为空则返回长度为0的chain
*/
state mulsentence();
state sentencelist();
state sentencetemp();
//四元式
#define numyuan 40
class fouryuan{
public:
	fouryuan();
	item payyuan[numyuan][4];
	int jumplist[numyuan][2];
	void load(int ,item t1,item t2,item t3,item t4);
	void load(int ,item t1,item t2,item t3,int t4);
	void writeback(int l[],int address);
	void load(int address1,int t4);
	int yuantop;
	int address[numyuan];
	void printfouryuan();
	void helpprint(int,int);

};

#define baseaddress 0    //基地址
#define templength 8



void error();              //出错处理
void getnextsign();   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -