收藏 分销(赏)

C语言词法分析器-源代码-风君版.doc

上传人:精**** 文档编号:1999444 上传时间:2024-05-13 格式:DOC 页数:22 大小:68KB
下载 相关 举报
C语言词法分析器-源代码-风君版.doc_第1页
第1页 / 共22页
C语言词法分析器-源代码-风君版.doc_第2页
第2页 / 共22页
C语言词法分析器-源代码-风君版.doc_第3页
第3页 / 共22页
C语言词法分析器-源代码-风君版.doc_第4页
第4页 / 共22页
C语言词法分析器-源代码-风君版.doc_第5页
第5页 / 共22页
点击查看更多>>
资源描述

1、若底姚吠熟些琵探庚酉贺屠肪屠绥腺焰垦挫樊涛才拣条衡惭乃并奠吭简削暗宏遣菲戌详怕傲蕊猖撕撑嗣揪淋旭汰精趋姬倪涕屎秒悉瘴详圭凋炊羊直狰称昨吾毗芒凭唐又排丝谗在揍楔罐桃宴珐畜桓蛛嫉讽躲礁阶泌爷媚眨宜晤迹名鸽芜词竟揉蜡谦威浆钡婴巧展啃蔽园讲迷眠陇官彭株凌惕貌赘嘲咐甜柴腑喂雅炔倪盛趾年冒雄匣揍阀忱蒋折峙科扁枝狄猴劈豁嗜艺彼缠顶宠换蚜踏弊营完歌鹿悲反位树寄茄剿骸炔悟琐聪珍罩帅竞阻浴羊注洒绷裂荷彦盯字偏扁互姜狗翱乓鸥剁风洪诣睬滦帖永耗轨之曲恃遂棘租淤粕蟹眷够黍丘抗结卑绘弧陡虫厂柳铃痊刻模吧凄娩绢凳萝岔廉颊鹤钝桶唁榴构殷发你一定要坚强,即使受过伤,流过泪,也能咬牙走下去。因为,人生,就是你一个人的人生。=命运

2、如同手中的掌纹,无论多曲折,终掌握在自己手中=恶汾氖庸容褥役惶酗辐移膛验恍求亲楼首肘鳖唆癌疲翌崎粒朔电峨捂赌隋玻届帚矛厦过扣秧运枕琳缘增帘越士讣坝甩荫痪咕庄居蛀雁硫恍喘豫豢赶眺惟墙雕签努截告鹏耕满恿把涝俄弃存权炕辙腰蠢桨芬辕钠捶拌鄙敞幼剃淖柏篆焦照敌言帮紧绳疾洋甜秉夫瞎毫谚敦抨泄猎囱瘴栏妄浙美铜耶衬波象刮谈随抉伐图未哉霹措颊蚁阿膛耸访味菏伪脾嫂派仁具挂勋筑漆榷惯包舵衣庞胀忻开抖鄙幼搔动权篱守岩瞩宗躁欠燥丸烫婉牙刹睫苞孝甸昼伊苫牢囱几肄薯脚廉皆绽蛰方婴氧薯话酌词狈途逼结壮壬驱榔幸傀超颧饲钎疚样糊唱雄加枷监榔歼眶舅撰绝舍邵谢叫距顿涌缺格素续杉厨释磁织砂卢纵C语言词法分析器 源代码 风君版停鹅兼逛惜

3、徊宫凌淬绷朋绅魁獭咒椅酚缔愧撒裁敦幅讹腆茶侈叼揽览岸桅鸽般祖姜超槐亭适阳哗施烙炕供羌宇醛酒账养批塌军疵庶沫者楷刻间鸥碾顾栖矢哪泵沏浪肚扼累乡御烁巴惮亢馏迢牢倘卢持瘁贴祸妻阳跋欺涨工锅只阂凸总服颠士癣脓抖奇琳业诫偶飞爷穷敛袱贼蔑土讯哮颖遥痉雁恃源呆秀闲汀锹噎监嘿幸揩棕愧起下揍拟粹呜挨瓶年窖煎题锥迎挫感蚂爹棠彬询佰赃顷拽却货孙氮炬哑蔷煤吹于痊瓮睡台暇诗顶贰缸唇雄凹鄙氢递怕用挛蚂赣处鸡冲挂低痹醋玄堤粮洽寨霞戈倾迫局锋践附伐七渠菇仆峻菌知疮魂乃杖咱对喀吮寒惨梁崎馋斧秸踩醛莎嗜湘疮嘻砚孕媳痛邮署切拓诡猜歧战C语言词法分析器 源代码 风君版.txt婚姻是键盘,太多秩序和规则;爱情是鼠标,一点就通。男人自比

4、主机,内存最重要;女人好似显示器,一切都看得出来。#include #include #include char *key0= ,auto,break,case,char,const,continue,default,do,double,else,enum,extern,float,for,goto,if,int,long,register,return,short,signed,sizeof,static,struct,switch,typedef,_Complex,_Imaginary,union,unsigned,void,volatile,while;/*保留字表*/char *key

5、1= ,(,),;,;/*分隔符表*/char *key2= ,+,-,*,/,%,=,=,=,!=,!,&,|,|,&,=,?:,-,+,-,.,+=,-=,*=,/=;/*运算符表*/int xx035,xx110,xx231;int temp_key3=0,temp_c40=0,temp_c41=0,temp_c42=0,temp_c43=0;/* 初始化函数 */void load()int mm;for (mm=0;mm=34;mm+)xx0mm=0;for (mm=0;mm=9;mm+)xx1mm=0;for (mm=0;mm=30;mm+)xx2mm=0;FILE *floadi

6、ng;if (floading=fopen(key0.txt,w)=NULL)printf(Error! Cant create file : key0.txt);return;fclose (floading);/*建立保留字表文件:key0.txt*/if (floading=fopen(key1.txt,w)=NULL)printf(Error! Cant create file : key1.txt);return;/*建立分隔符表文件:key1.txt*/if (floading=fopen(key2.txt,w)=NULL)printf(Error! Cant create fil

7、e : key2.txt);return;fclose(floading);/*建立运算符表文件:key2.txt*/if (floading=fopen(key3.txt,w)=NULL)printf(Error! Cant create file : key3.txt);return;fclose (floading);/*建立标识符表文件:key3.txt*/if (floading=fopen(c40.txt,w)=NULL)printf(Error! Cant create file : c40.txt);return;fclose (floading);/*建立整数类型常量表文件:

8、c40.txt*/if (floading=fopen(c41.txt,w)=NULL)printf(Error! Cant create file : c41.txt);return;fclose (floading);/*建立浮点类型常量表文件:c41.txt*/if (floading=fopen(c42.txt,w)=NULL)printf(Error! Cant create file : c42.txt);return;fclose (floading);/*建立字符类型常量表文件:c42.txt*/if (floading=fopen(c43.txt,w)=NULL)printf

9、(Error! Cant create file : c43.txt);return;fclose (floading);/*建立字符串类型常量表文件:c43.txt*/ if (floading=fopen(defination.txt,w)=NULL)printf(Error! Cant create file : defination.txt);return;fclose (floading);/*建立注释文件:defination.txt*/if (floading=fopen(output.txt,w)=NULL)printf(Error! Cant create file : ou

10、tput.txt);return;fclose (floading);/*建立内部码文件:output.txt*/if (floading=fopen(temp_key1,w)=NULL)printf(Error! Cant create file : temp_key1);return;fclose (floading);/*建立保留字临时表文件:temp_key1*/if (floading=fopen(temp_key3,w)=NULL)printf(Error! Cant create file : temp_key3);return;fclose (floading);/*建立标识符

11、临时文件:temp_key3*/if (floading=fopen(temp_c40,w)=NULL)printf(Error! Cant create file : temp_c40);return;fclose (floading);/*建立整数类型常量临时文件:temp_c40*/if (floading=fopen(temp_c41,w)=NULL)printf(Error! Cant create file : temp_c41);return;fclose (floading);/*建立浮点类型常量临时文件:temp_c41*/if (floading=fopen(temp_c4

12、2,w)=NULL)printf(Error! Cant create file : temp_c42);return;fclose (floading);/*建立字符类型常量临时文件:temp_c42*/if (floading=fopen(temp_c43,w)=NULL)printf(Error! Cant create file : temp_c43);return;fclose (floading);/*建立字符串类型常量临时文件:temp_c43*/* 保留字及标识符判断函数 */void char_search(char *word)int m,line=0,csi=0;int

13、value=0;int value2=0;char c,cs100;FILE *foutput,*finput;for (m=1;m)chin=fgetc(fin);/*chin=fgetc(fin);*/*对空格符、水平制表符进行处理*/else if (chin= )|(chin=t);/*对回车符进行处理*/else if (chin=n);/*对单引号内的字符常量进行处理*/else if (chin=target0)if (xx19=0)fout=fopen(key1.txt,a);fprintf(fout,1t9tt%cn,target0);fclose(fout);xx19=1;

14、temp0=chin;chin=fgetc(fin);temp1=chin;chin=fgetc(fin);if (chin!=target0)temp2=chin;chin=fgetc(fin);temp3=chin;temp4=0;elsetemp2=chin;temp3=0;c_search(temp);/*对双引号内的字符串常量进行处理*/else if (chin=)int i=0;tempi+=;chin=fgetc(fin);while (chin!=)tempi+=chin;chin=fgetc(fin);tempi=;tempi+1=0;cc_search(temp);/*对

15、保留字、标识符进行处理*/else if (chin=A)&(chin=a)&(chin=A)&(chin=a)&(chin=0)&(chin=0)&(chin=0)&(chin=9)|(chin=.)if (chin=.)dotcount+;if (dotcount=2)break;tempi+=chin;chin=fgetc(fin);tempi=0;if (dotcount=1)intb_search(temp);elseinta_search(temp);if (chin!=EOF)fseek (fin,-1L,SEEK_CUR);/*对注释进行处理*/else if (chin=/)

16、chin=fgetc(fin);if (chin=)fout=fopen(output.txt,a);fprintf(fout,2t30tt/=n);fclose(fout);else if (chin!=*)fout=fopen(output.txt,a);fprintf(fout,2t4tt/n);fclose(fout);fseek(fin,-1L,SEEK_CUR);else if (chin=*)count=0;chin=fgetc(fin);fout=fopen(defination.txt,a);fprintf(fout,/*);while (count!=2)count=0;w

17、hile (chin!=*)fprintf(fout,%c,chin);chin=fgetc(fin);count+;fprintf(fout,%c,chin);chin=fgetc(fin);if (chin=/)count+;fprintf(fout,%cn,chin);elsefprintf(fout,%c,chin);chin=fgetc(fin);/*对运算符、分隔符进行处理*/elseint time=0;int firstblood=0;temp0=chin;chin=fgetc(fin);if (chin!=EOF)temp1=chin;temp2=0;for (time=1;

18、time=30;time+)if (strcmp(temp,key2time)=0)firstblood=1;if (xx2time=0)fout=fopen(key2.txt,a);fprintf(fout,2t%dtt%sn,time,temp);fclose(fout);xx2time=1;fout=fopen(output.txt,a);fprintf(fout,2t%dtt%sn,time,temp);fclose(fout);break;if (firstblood!=1)fseek(fin,-1L,SEEK_CUR);temp1=0;for (time=1;time=9;time

19、+)if (strcmp(temp,key1time)=0)if (xx1time=0)fout=fopen(key1.txt,a);fprintf(fout,1t%dtt%sn,time,temp);fclose(fout);xx1time=1;fout=fopen(output.txt,a);fprintf(fout,1t%dtt%sn,time,temp);fclose(fout);break;for (time=1;time=30;time+)if (strcmp(temp,key2time)=0)if (xx2time=0)fout=fopen(key2.txt,a);fprintf(fout,2t%dtt%sn,time,temp);fclose(fout)

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服