3、dio>#include#include#include#include#includeusingnamespacestd;stringoriginal[9]={//保存原文法"E->E+T","E->E-T","E->T","T->T*F","T->T/F","T->F","F->i","F->(E)","F->n"};stringG[11]={//拓广文法"E->TA","A->+TA","A->-TA","A
4、->e","T->FB","B->*FB","B->/FB","B->e","F->(E)","F->i","F->n"};stringFIRST[5]={//first集"E:(in",//E"A:+-e",//A"T:(in",//T"B:*/e",//B"F:(in"//F};stringFOLLOW[5]={//follow集"E:)$",//E"A:)$",//A"T:+-)$",//T"B:+-)$",//B"F:+-*/)$",//F};charVN[5]={'E','A','T','B
5、','F'};//存储非终结符charVT[9]={'i','n','+','-','*','/','(',')','$'};//存储终结符typedefstructBlock{charvn;//非终结符charvt;//终结符strings;//产生式}block;//存储分析预测表每个位置对应的终结符,非终结符,产生式blocktable[45];//5*9=45charis_vt(chara)//是否为非终结符,不是返回'x'{for(inti=0;i<5;i++){if(a==VN[i])re
6、turn'x';}if(isalpha(a))//是字母return'i';if(isdigit(a))//是数字return'n';for(inti=0+2;i<9;i++){if(a==VT[i])returna;}}intfind_table(charX,chara)//查找是否存在符合的产生式{for(inti=0;i<45;i++){if(table[i].vn==X&&table[i].vt==is_vt(a))if(0!=table[i].s.size())returni;elseret
7、urn999;//error项}return999;}voidLL_one(stringtemp){stackST;//栈ST.push('$');//初始化压入栈ST.push('E');cout<<"栈"<<"输入"<<"输出"<99)cout<<":";elseif(j>9)cout<<":";elsecout<<":";//输出stackt_ST;//栈cha
8、rt_char;inti2=ST.size();for(inti1=0;i19、";for(int