1、/将标识符插入符号表void insertNumList();/将数字插入常数表void fillBuffer(int a);/ 填充buff的半区函数2程序源代码#includestdlib.hstring.hmath.hint pointer=0;/int i=0,j=0,c=0,appear,d=0,num_location;int row_num=0,letter_num=0,word_num=0;int z=1;char C= ;char token30;char buff4095;char token_list20030;char number20010;char next_cha
2、rac,charac,file_name20;char keywords3210=auto,breakcasecharconstcontinuedefaultdodoubleelseenumexternfloatforgotoifintlongregisterreturnshortsignedsizeofstaticstructswitchtypedefunionunsignedvoidvolatilewhile;double num;FILE *file_pointer;void fillBuffer(int a)/ / i=0; while(!feof(file_pointer) & i=
3、97 & C=65 &=90) return true; return false;bool digit()/ if(C=48 &=57)int searchForKeywords()/ for(int x=0;x32;x+) if(strcmp(token,keywordsx)=0) return 0; return 1;int searchForToken()/ int i=0; while(i=c-1) if(strcmp(token,token_listi)=0) appear=i; / word_num+;int searchForNum()/=d-1) if(strcmp(toke
4、n,numberi)=0) num_location=i; void insertTokenList()/ strcpy(token_listc+,token);void insertNumList()/ strcpy(numberd+,token);main() printf(输入源文件的路径:n); scanf(%s,file_name); file_pointer=fopen(file_name,r if(file_pointer=NULL) printf(无法查找到文件,发生错误! while(C! readChar(); switch(C) case 65: case 66: cas
5、e 67: case 68: case 69: case 70: case 71: case 72: case 73: case 74: case 75: case 76: case 77: case 78: case 79: case 80: case 81: case 82: case 83: case 84: case 85: case 86: case 87: case 88: case 89: case 90: case 97: case 98: case 99: case 100: case 101: case 102: case 103: case 104: case 105:
6、case 106: case 107: case 108: case 109: case 110: case 111: case 112: case 113: case 114: case 115: case 116: case 117: case 118: case 119: case 120: case 121: case 122: case _:/ while(alphabet()|digit()|C= link(); tokenj= j=0; pointer-; if(searchForKeywords()=1)/ if(searchForToken()=1)/ in
7、sertTokenList();,c-1);,appear); %s, ,token); break; case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: num=(C-48); while(digit() num=num*10+(C-48);. num=num+(C-48)*pow(0.1,z+); if(searchForNum()=1)/ insertNumList(); %f, %d ,num,d-1);,num,num_location);+ +=, 赋值运
8、算符 else if(C= +, 自加 +, 加号 - -, 自减 -= , 赋值运算符 -, 减号 * *, 乘号 break;/ next_charac=buffpointer; & next_charac! /*, 多行注释 /, 单行注释 /, 除号 % %, 取模 ( (, 左小括号 ) ), 右小括号 , 左中括号 , 右中括号 , -左大括号 , 右大括号 :, 冒号 ;, 分号 , , 逗号 ., 句号 ? ?, 问号 , 引号 # #, 井号 =, 大于等于 , 大于 , 小于 =, 判等 =, 赋值等 , 且 , 取地址符 | |, 或 |, 运算符 ! !=, 不等 , 非 该源文件的行数为:%d,单词数为%d,字符数为%d.n,row_num,word_num,letter_num); system(pause3程序的执行结果测试程序为:运行结果为:四、有待改进的地方
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1