2、am>usingnamespacestd;constintMaxStateNum=12;constintMaxVtNum=6;constintMaxVnNum=4;constintMaxNodeNum=50;constintMaxStackDepth=50;constintMaxRuleNum=7;enumisAccept{YES,NO,ERROR};structGrammar{intnode;intRightLength;};structStackNode{intstate;intnode;};classLasa{private:charVn[MaxVnNum];char
3、Vt[MaxVtNum];intActionfMaxStateNumlfMaxVtNum];intGoto[MaxStateNum][MaxVnNum];Grammargrammar[MaxRuleNum];StackNodeStack[MaxStackDepth];inttops;public:Lasa();~Lasa(){}isAcceptaccept(charstr[]);};Lasa::Lasa(){charvn[MaxVnNum]={'ZVEVTVF};charvt[MaxVtNum]={intac[MaxStateNuml[MaxVtNum]={{0,0,0,4
4、,0,5},{999,6,0,0,0,0},{・2,・2,7,0,・2,0},{-4,-4,-4,0,-4,0},{0,0,0,4,0,5},{・6,・6,・6,0,・6,0},{0,0,0,4,0,5},{0,0,0,4,0,5},{0,6,0,0,11,0},{-11,7,0,-1,0},{-3,-3,-3,0,-3,0},{-5,-5,-5,0,-5,0}};intgo[MaxStateNum][MaxVnNum]={{0,1,2,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,8,2,3},{0,0,0,0},{0,0,9,3},{0,0,0
5、,10},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};Grammargra[MaxRuleNum]={{100,2},{101,3},{101,l},{102,3},{102,1},{103,3)4103,1}};inti=0,j=0;tops=0;Stack[tops].state=0;while(i6、n[iJU]=ac[i]UJ;}for(i=0;i7、j]=go[i]U];}i=0;while(i8、串”;act=O;while(str[i]!=, ,llact<999){if(str[i]==O*)tag=l;j=0;cout«"t"«k++«"t";while(j<=tops){if(j!=O){if(Stack[j].node>99&&Stack[j].node<110)cout«Vn[Stack[j].node-100);elsecout«Vt[Stack[j].node];}cout«Stack[j++].state;}cout«"tttn;••J=l;while(strfj]!=