首页 > 代码库 > 词语分析
词语分析
#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);}
词语分析
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。