} VN[count]=singleChar; vnNum=count+1; } }else{ count=0; while(VT[count]!=singleChar&&VT[count]!='\\0') { count++; } if(VT[count]=='\\0') { VT[count]=singleChar; vtNum=count+1; } } j++; }
printf(\输入的文法:\\n\for(k=0;k<=i;k++){ j=0; while(Grammar[k][j]!='\\0') { if(j==1) { printf(\ } printf(\ j++; } printf(\}
count=0; printf(\
while(VT[count]!='\\0') {
printf(\ count++; }
VT[count]='#'; vtNum=count+1;
printf(\printf(\count=0;
while(VN[count]!='\\0') {
printf(\ count++; }
printf(\
//?printf(\ fclose(fp);
grammarNum=i+1; return i; }
int vNumCount() { int i,j;
for(i=0;i j=1; while(Grammar[i][j]!='\\0') { j++; } VNum[i]=j; //??printf(\ } printf(\ return 0; } void InitStack(){ state.base=(int *)malloc(100*sizeof(int)); if(!state.base) exit(1); state.top=state.base; *state.top=0; symbol.base=(char *)malloc(100*sizeof(char)); if(!symbol.base) exit(1); symbol.top=symbol.base; *symbol.top='#'; } int Judge(int stateTop,char inputChar){ int i,j; for(i=0;i if(stateTop==i) break; } for(j=0;j if(inputChar==AVT[j]) break; } return Action[i][j]; } int GetGoto(int stateTop,char inputChar){ int i,j; for(i=0;i for(j=0;j if(inputChar==GVN[j]) break; } return Goto[i][j]; } int print(int count,int i,char Input[],int action,int gt,int sign) { int *p=state.base,stateNum; int j,jj; char *q=symbol.base,symbolNum; printf(\ while(p!=state.top+1) { stateNum=*p; printf(\ p++; } printf(\ while(q!=symbol.top+1) { symbolNum=*q; printf(\ q++; } printf(\ j=i; jj=0; while(jj printf(\ jj++; } while(Input[j]!='\\0') { printf(\ j++; } printf(\ if(sign==1) { printf(\ } if(sign==2) { printf(\ } if(sign==3) { printf(\ } if(sign==0) printf(\ return 0; } int Pop(int action) { int *p,stateNum,ssValue,i; state.top--; p=state.top; stateNum=*p; i=VNum[action]-1; while(i!=0) { symbol.top--; i--; } symbol.top++; *symbol.top=Grammar[action][0]; ssValue=GetGoto(stateNum,Grammar[action][0]); if(ssValue==0) return ssValue; state.top++; *state.top=ssValue; return ssValue; } int Reduction() { char Input[20]; int i=0,count=1; int ssValue,action; int stateTop,gt; int sign=-1;//移进1,规约2,接受3 scanf(\ while(Input[i]!='\\0') { if(Input[i]>='A'&&Input[i]<='Z') { printf(\输入的不是有效的表达式!\ return 0; } i++; } i=0; printf(\步骤\\t状态栈\\t符号栈\\t输入串\\t\\tACTION\\tGOTO\\n\ while(Input[i]!='\\0') { if(count==1) { print(count,i,Input,0,0,0); count++; } stateTop=*state.top; ssValue=Judge(stateTop,Input[i]); if(ssValue==0) { state.top--; if(*symbol.top=='#') { printf(\规约出错!\ return 0; } continue; } if(ssValue==-1) {