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

📄 head.h

📁 一个很一般的编译程序 有词法分析
💻 H
字号:
#include "stdio.h"
#include "string.h"
#include "iostream.h"
#include "process.h"
#include "ctype.h"
#include "math.h"


#define WORDSIZE 0 
#define BUFLINE 256 //源代码每行长度
#define STACKSIZE 256 //堆栈长度
//----------------------------------
#define	IF	0
#define	THEN	1
#define	ELSE	2
#define	WHILE	3
#define	DO	4
#define	BEGIN	5
#define	END	6
#define	I	7
#define	EVALUATE	8
#define	SEMICOLON	9
#define	AND	10
#define	OR	11
#define	GREAT	12
#define	LOW	13
#define	EQUAL	14
#define	TRUE	15
#define	FALSE	16
#define	PLUS	17
#define	MULTIPLY	18
#define	LEFT	19
#define	RIGHT	20
#define	CONST	21
#define	ACC	22
#define	Vn_S	23
#define	Vn_L	24
#define	Vn_B	25
#define	Vn_E	26

#define WRD_ERR -99

class fourexp{//的类
public:
	char * op ;
	char * sym11 ;
	int sym12;
	char * sym21 ;
	int sym22 ;
	int temp ;
	char * ch4;
	bool isadd;
	fourexp * next;
	fourexp * chain;
	int address ;
	fourexp(){next = NULL;}
public:
	void Display(){//展示四元式
	cout<<address;
	cout<<"( ";
	cout<<op<<",";
	if(sym11=='\0')
		cout<<"t"<<sym12<<",";
	if( sym12 == -1)
		cout<<sym11<<",";
	if(sym21=='\0')//问题项目,在跳转项目上有问题( j=,t6, ,t-842150451 )
		if( isadd ==true )
			cout<<sym22<<",";
		else
			cout<<"t"<<sym22<<",";
	if( sym22 == -1)
		cout<<sym21<<",";/**/
	if( ch4=='\0'){
		if( isadd == true )
			cout<<temp<<" " ;
		else
			cout<<"t"<<temp<<" ";
	}
	if( temp== -1)
		cout<<ch4<<" ";
	cout<<")"<<endl;

}

void  join( char * ch1 ,char* ch2 ,char * ch3 ,int ch4, bool isadd){//方法一
	op = ch1 ;
	sym11 = ch2;
	sym12 = -1 ;
	sym21 = ch3 ;
	sym22 = -1 ;
	temp = ch4 ;
	this->ch4 = '\0';
	this->isadd = isadd ;
}
void  join( char * ch1 , int ch2    , int ch3     , int ch4, bool isadd){//方法二
	op = ch1 ;
	sym11 = '\0';
	sym12 = ch2 ;
	sym21 = '\0' ;
	sym22 = ch3;
	temp = ch4 ;
	this->ch4 = '\0';
	this->isadd = isadd ;
}
void join( char * ch1 , char* ch2  , int ch3     , int ch4, bool isadd){//方法三
	op = ch1 ;
	sym11 = ch2;
	sym12 = -1 ;
	sym21 = '\0' ;
	sym22 = ch3;
	temp = ch4 ;
	this->ch4 = '\0';
	this->isadd = isadd ;
}
void join( char * ch1 , int ch2    , char * ch3  , int ch4, bool isadd){//方法四
	op = ch1 ;
	sym11 = '\0';
	sym12 = ch2 ;
	sym21 = ch3 ;
	sym22 = -1 ;
	temp = ch4 ;
	this->ch4 = '\0';
	this->isadd = isadd ;
}
void join( char * ch1 , int ch2    , char * ch3  , char* ch4, bool isadd){//方法五
	op = ch1 ;
	sym11 = '\0';
	sym12 = ch2 ;
	sym21 = ch3 ;
	sym22 = -1 ;
	temp = -1 ;
	this->ch4 = ch4;
	this->isadd = isadd ;
}
void join( char * ch1 , char* ch2    , char * ch3  , char* ch4, bool isadd){//方法六
	op = ch1 ;
	sym11 = ch2;
	sym12 = -1;
	sym21 = ch3 ;
	sym22 = -1 ;
	temp = -1 ;
	this->ch4 = ch4;
	this->isadd = isadd ;
}

};//class fourexp

typedef struct Vn{
	int t_val;
	char *ch;
	bool isTmp;
	fourexp *head;
	fourexp *tail;
}Vn;



typedef struct WORD{
	int id;//编号
    char name[10];	//单词属性值
	int value;//单词的值,语义分析用
}WORD;



//typedef struct stateNode{
//	int state;
//	int id;
//}stateNode;
typedef struct stateStack{
	int top;
	int stack[STACKSIZE];//语法分析栈
}stateStack;


FILE* sourceFile;



//link insert(link linkList,int n);
//link del(link linkList,int &value);
void error();
void error1();
int  lex(char * buf);
void R(){
	cout<<"this is test!"<<endl;
}

⌨️ 快捷键说明

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