etter[i+1]='\0'; if (search(letter,1))//判断是否为关键字(保留字) printf("<%s,%s>\n",letter,letter); else printf("
\n",letter); nword++; u: return(ch); } /////////////////////////////////////////////////////////////////////////////////////////// char numberprocess(char ch)//数字处理程序 { int i=-1; char num[20]; while (isdigit(ch)!=0) { num[++i]=ch; ch=fgetc(fp); cnum++; if(ch=='\n') line++; } if(ch=='.')
{ num[++i]=ch; ch=fgetc(fp); while (isdigit(ch)!=0) { num[++i]=ch; ch=fgetc(fp); cnum++; if(ch=='\n') line++; } } if(isalpha(ch)!=0)//处理错误的数字符号串(数字后不能紧跟字母) { while(isspace(ch)==0&;&;ch!=EOF)//非空格 { num[++i]=ch; ch=fgetc(fp); cnum++; if(ch=='\n') line++; } num[++i]='\0'; fnum++; cout<<"错误"<\n",num); nword++; u: return(ch); } ////////////////////////////////////////////////////////////////////////////////////////////// char otherprocess(char ch) { int i=-1,k=0; int flag=1; char other[20],temp[10]; if (isspace(ch)!=0) {
ch=fgetc(fp); cnum++; if(ch=='\n') line++; goto u; } while((isspace(ch)==0)&;&;(isalnum(ch)==0)&;&;ch!=EOF)//读入空格字母数字以外的符 号 { if(ch=='/')//跳过注释代码 { ch1=ch;//回退保留 ch=fgetc(fp); cnum++; if(ch=='\n') line++; if(ch=='*')//注释以/*开头*/结尾 { printf("注释: "); ch=fgetc(fp); cnum++; if(ch=='\n') line++; while(flag&;&;ch!=EOF) { if(ch=='*') { ch=fgetc(fp); cnum++; if(ch=='\n') line++; if(ch=='/')//注释结束 flag=0; else printf("%c",ch); } printf("%c",ch); ch=fgetc(fp); cnum++; if(ch=='\n') line++; } if(flag!=0&;&;ch==EOF)
{ fnum++; cout<<"错误"< { temp[0]=other[k]; temp[1]='\0'; if (search(temp,2))//+ - * / = { nword++; if(temp==interpunction[2])//表示赋值符号= printf("\n",compro[pro],temp); else printf("<%s,->\n",temp); } else if (search(temp,3))//标点符号不算做单
词 { // printf("<%c,->\n",temp[0]); } else if (search(temp,4))//比较操作符 { temp[1]=other[k+1]; temp[2]='\0'; if (search(temp,4)) k++; cout<<""<\n",temp[0]); nword++; } else if(isspace(other[0])==0)//不是空格 printf("错误!非法字符:%s\n",other); }
u:return (ch); }