www.pudn.com > syntax_analysis.rar > functions.cpp


#include 
#include"functions.hpp" 
//打印字符串str到屏幕,参数采用字符指针. 
bool PRINT_func(char* str) 
{ 
	cout<='a' && *F_current<='z') 
	{  
		++F_current; 
        return true; 
	} 
	else 
		if(*F_current!='(') 
		{ 
			PRINT_func("ERROR"); 
			F_flag=1; 
			return true; 
		} 
		else 
		{ 
			++F_current; 
			E_func(F_current,F_flag); 
			if(*F_current!=')') 
			{ 
				PRINT_func("ERROR"); 
				F_flag=1; 
				return true; 
			} 
			else 
			{ 
				++F_current; 
				return true; 
			} 
		} 
} 
//描述T过程,具体内容参考实验指导书 
//参数功能同上 
bool T_func(string::const_iterator& T_current,int& T_flag) 
{ 
	F_func(T_current,T_flag); 
	while(*T_current=='*' || *T_current=='/') 
	{ 
		++T_current; 
		F_func(T_current,T_flag);	 
	} 
	return true; 
} 
//描述E过程,具体内容参考实验指导书 
//参数功能同上 
bool E_func(string::const_iterator& E_current,int& E_flag) 
{ 
	T_func(E_current,E_flag); 
	while(*E_current=='+' || *E_current=='-') 
	{ 
		++E_current; 
		T_func(E_current,E_flag); 
	} 
	return true; 
} 
//描述ZC过程,具体内容参考实验指导书 
//第一参数为当前位置,刚开始时即obj.begin() 
//第二参数为结束位置即obj.end() 
bool ZC_func(string::const_iterator& ZC_current,const string::const_iterator& ZC_end) 
{ 
	int ZC_flag=int(); 
	while(ZC_current!=ZC_end) 
	{ 
		E_func(ZC_current,ZC_flag); 
		if(*ZC_current!=';' || ZC_flag==1) 
		{ 
			PRINT_func("ERROR,AGAIN"); 
			ZC_flag=0; 
			++ZC_current; 
		} 
		else 
		{ 
			PRINT_func("RIGHT,AGAIN"); 
			++ZC_current; 
		} 
	} 
	return true; 
} 
//从文件中读出所有字符到对象object中,同时去掉所有的空格和换行 
//参数采用引用,以便将结果带回主调函数. 
bool GetTextFromFile(string& object) 
{ 
	//定义字符数组并初始化为'\0',用作临时存储空间 
	char ch[50]={'\0'}; 
	//定义整形变量并初始化为0,用作字符数组下标 
	int i=int(); 
	//定义ifstream类型对象readfile,用以只读方式打开文件 
	ifstream readfile("test.txt",ios::in); 
	//测试能否成功打开文件 
	if(!readfile) 
	{ 
		cerr<<"can't open test.txt!"<