首页 > 代码库 > 词语分析

词语分析

 

#include <stdio.h>#include<string.h>#define MAX 50 char *arrayjudge[MAX][1]={" ","begin","if","then","for","do","+","-","*","/",":",":=","<","<>",">",";","(",")","!","#"}; void UI() {       printf("\t\t\t欢迎使用词法分析程序!!\n");       printf("    单词符号    种别码       单词符号     种别码\n");       printf("       begin     1            :            10 \n");       printf("       if        2            :=           11 \n");       printf("       then      3            <            12\n");       printf("       for       4            <>           13\n");       printf("       do        5            >            14\n");       printf("       dd*       11           ;            15\n");       printf("       +         6            (            16\n");       printf("       -         7            )            17\n");       printf("       *         8            !            18\n");       printf("       /         9            #            19\n"); } int numberjudge(char arry[],int i,int a) {     int j;     for(i=0;i<strlen(arry);i++)     {         if(arry[i]>47&&arry[i]<58)            return 1;     }        return 0; }int arrayjudges(char arry[])  {       int i;       for(i=0;i<19;i++)       {           if(strcmp(arry,arrayjudge[i][1])==0)            return i;       }       return -1;  }main(){    int i,replace;    char arry[MAX];    UI();    printf("\n请输入字符串(直到##退出):\n");    do{            scanf("%s",arry);            if(strcmp(arry,"##")==0)            break;            replace=numberjudge(arry,i,strlen(arry));            if(replace==1)            {                printf("种别码11\t数字%s\n",arry);            }            else if  (replace==0);            {                i=arrayjudges(arry);                if(i>=0&&i<=5)            {                printf("种别码%d\t\t关键字%s\n",i+1,arry);            }            else if(i>5&&i<=9)            {                  printf("种别码%d\t\t运算符%s\n",i+1,arry);            }           else if(i>9&&i<=18)            {                printf("种别码%d\t界符%s\n",i+1,arry);            }            }     getchar();    }while(1);}技术分享

 

词语分析