www.pudn.com > compile2.rar > compile2.cpp
#include#include #define MAXLONG 100 char temp[10];//临时存放pretll_table的CHARS static int line_n=1; void GET_SENTENCE(char B,char e);//得到对应的M[X,a]的句子函数声明 struct TABLE{ char begin; char tail; char CHARS[5]; }; TABLE pretell_table[30]={{'E','i',"TM"},{'E','+',"\0"},{'E','*',"\0"},{'E','(',"TM"},{'E',')',"\0"},{'E','#',"\0"} ,{'M','i',"\0"},{'M','+',"+TM"},{'M','*',"\0"},{'M','(',"\0"},{'M',')',"ε"},{'M','#',"ε"} ,{'T','i',"FN"},{'T','+',"\0"},{'T','*',"\0"},{'T','(',"FN"},{'T',')',"\0"},{'T','#',"\0"} ,{'N','i',"\0"},{'N','+',"ε"},{'N','*',"*FN"},{'N','(',"\0"},{'N',')',"ε"},{'N','#',"ε"} ,{'F','i',"i"},{'F','+',"\0"},{'F','*',"\0"},{'F','(',"(E)"},{'F',')',"\0"},{'F','#',"\0"} };//预测分析表 class STACK{//定义一个栈类 private: int top;//栈顶指针 int bottom;//栈底指针 char stack[MAXLONG];//栈长 public: STACK()//栈初始化,构造函数 {top=0;bottom=0;} ~STACK(){}//析构函数 void PUSH_STACK(char const character)//进栈操作 { if((top-bottom)>=MAXLONG-1)//判断是否栈空 cout<<"The STACK if full!"< =0;i--)//字符串反向进栈 { char temp=chars[i]; PUSH_STACK(temp); } } void POP_STACK()//出栈顶元素 { if((top-bottom)==0)//判断栈空 cout<<"The STACK is empty!"< =0;j--) cout< ='A'&&X<='Z'))//X属于终结符 { if(X==a)//X和a匹配 { if(X=='#')//为#和#号匹配接受 { cout<