#include #include #include #include #include using namespace std;#define MAX 22char ch =' ';string key[15]={"switch","break","if","then","else","while","write","read","do", "int","const","char","float","double","for"};int Iskey(string c) //关键字判断{ int i; for(i=0;i ='a'))||((c<='Z')&&(c>='A'))) return 1; else return 0;}int IsDigit(char c) //判断是否为数字{ if(c>='0'&&c<='9') return 1; else return 0;}void analyse(FILE *fpin) //词法分析程序{ string arr=""; while((ch=fgetc(fpin))!=EOF) { arr=""; if(ch==' '||ch=='\t'||ch=='\n') { } else if(IsLetter(ch)) { while(IsLetter(ch)||IsDigit(ch)) { if((ch<='Z')&&(ch>='A')) ch=ch+32; arr=arr+ch; ch=fgetc(fpin); } fseek(fpin,-1L,SEEK_CUR); if (Iskey(arr)) { cout< <<"\t$关键字"< ' :{ch=fgetc(fpin); if(ch=='=') cout<<">="<<"\t$运算符"< ')cout<<">>"<<"\t$输入控制符"< "<<"\t$运算符"< ') cout<<"<>"<<"\t$运算符"< >in_fn; if((fpin=fopen(in_fn,"r"))!=NULL) break; else cout<<"文件路径错误!请输入源文件名(包括路径和后缀名):"; } cout<<"\n********************分析如下*********************"<