如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
#include<stdio.h>#include<string.h>#include<iostream.h>charprog[80],token[8];charch;intsyn,p,m=0,n,sum=0,kk=0;char*rwtab[6]={"begin","if","then","while","do","end"};voidexpression();voidfactor();voidterm();voidstatement();voidyucu();voidscaner(){for(n=0;n<8;n++)token[n]=NULL;ch=prog[p++];while(ch==''){ch=prog[p];p++;}if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){m=0;while((ch>='0'&&ch<='9')||(ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){token[m++]=ch;ch=prog[p++];}token[m++]='\0';p--;syn=10;for(n=0;n<6;n++)if(strcmp(token,rwtab[n])==0){syn=n+1;break;}}elseif((ch>='0'&&ch<='9')){{sum=0;while((ch>='0'&&ch<='9')){sum=sum*10+ch-'0';ch=prog[p++];}}p--;syn=11;if(sum>32767)syn=-1;}elseswitch(ch){case'<':m=0;token[m++]=ch;ch=prog[p++];if(ch=='>'){syn=21;token[m++]=ch;}elseif(ch=='='){syn=22;token[m++]=ch;}else{syn=23;p--;}break;case'>':m=0;token[m++]=ch;ch=prog[p++];if(ch=='='){syn=24;token[m++]=ch;}else{syn=20;p--;}break;case':':m=0;token[m++]=ch;ch=prog[p++];if(ch=='='){syn=18;token[m++]=ch;}else{syn=17;p--;}break;case'*':syn=15;token[0]=ch;break;case'/':syn=16;token[0]=ch;break;case'+':syn=13;token[0]=ch;break;case'-':syn=14;token[0]=ch;break;case'=':syn=25;token[0]=ch;break;case';':syn=26;token[0]=ch;break;case'(':syn=27;token[0]=ch;break;case')':syn=28;token[0]=ch;break;case'#':syn=0;token[0]=ch;break;case'\n':syn=-2;break;default:syn=-1;break;}}voidexpression(){term();while(syn==13||syn==14){scaner();term();}return;}voidfactor(){if(syn==10)scaner();elseif(syn==11)scaner();elseif(syn==27){scaner();expression();if(syn==28){scaner();}else{cout<<"输出')'错误"<<endl;kk=1;}}else{cout<<"表达式错误"<<endl;kk=1;}return;}