




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、C语言词法分析器 源代码 风君版.txt婚姻是键盘,太多秩序和规则;爱情是鼠标,一点就通。男人自比主机,内存最重要;女人好似显示器,一切都看得出来。#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,uni
2、on,unsigned,void,volatile,while;/*保留字表*/char *key1= ,(,),;,;/*分隔符表*/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+
3、)xx1mm=0;for (mm=0;mm=30;mm+)xx2mm=0;FILE *floading;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=fop
4、en(key2.txt,w)=NULL)printf(Error! Cant create file : 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 :
5、 c40.txt);return;fclose (floading);/*建立整数类型常量表文件: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);/*建立字符类型常量表文件:c
6、42.txt*/if (floading=fopen(c43.txt,w)=NULL)printf(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(outpu
7、t.txt,w)=NULL)printf(Error! Cant create file : output.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 f
8、ile : temp_key3);return;fclose (floading);/*建立标识符临时文件: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);/*
9、建立浮点类型常量临时文件:temp_c41*/if (floading=fopen(temp_c42,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*/* 保留字及标识符判断函数 */vo
10、id char_search(char *word)int m,line=0,csi=0;int 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);fp
11、rintf(fout,1t9tt%cn,target0);fclose(fout);xx19=1;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;chi
12、n=fgetc(fin);tempi=;tempi+1=0;cc_search(temp);/*对保留字、标识符进行处理*/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)fse
13、ek (fin,-1L,SEEK_CUR);/*对注释进行处理*/else if (chin=/)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.
14、txt,a);fprintf(fout,/*);while (count!=2)count=0;while (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(f
15、in);if (chin!=EOF)temp1=chin;temp2=0;for (time=1;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(
16、fin,-1L,SEEK_CUR);temp1=0;for (time=1;time=9;time+)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 查看保留字表文件 *n);printf(* 1 - 查看分隔符表
17、文件 *n);printf(* 2 - 查看运算符表文件 *n);printf(* 3 - 查看标识符表文件 *n);printf(* 4 - 查看整数类型常量表 *n);printf(* 5 - 查看浮点类型常量表 *n);printf(* 6 - 查看字符类型常量表 *n);printf(* 7 - 查看字符串类型常量表 *n);printf(* 8 - 查看注释文件 *n);printf(* 9 - 查看内部码文件 *n);printf(* - *n);printf(* Q - 退出 *n);printf(*n);printf(n);load();scan();printf(n);pri
18、ntf(分析完成!n);getchar();printf(n);printf(请输入命令:);command=getchar();while (command!=Q)&(command!=q)switch (command)case 0:printf(*n);printf(n);fread=fopen(key0.txt,r);charin=fgetc(fread);while (charin!=EOF)putchar(charin);charin=fgetc(fread);printf(n);printf(*n);printf(n);printf(请输入命令:);break;case 1:pr
19、intf(*n);printf(n);fread=fopen(key1.txt,r);charin=fgetc(fread);while (charin!=EOF)putchar(charin);charin=fgetc(fread);printf(n);printf(*n);printf(n);printf(请输入命令:);break;case 2:printf(*n);printf(n);fread=fopen(key2.txt,r);charin=fgetc(fread);while (charin!=EOF)putchar(charin);charin=fgetc(fread);pri
20、ntf(n);printf(*n);printf(n);printf(请输入命令:);break;case 3:printf(*n);printf(n);fread=fopen(key3.txt,r);charin=fgetc(fread);while (charin!=EOF)putchar(charin);charin=fgetc(fread);printf(n);printf(*n);printf(n);printf(请输入命令:);break;case 4:printf(*n);printf(n);fread=fopen(c40.txt,r);charin=fgetc(fread);w
21、hile (charin!=EOF)putchar(charin);charin=fgetc(fread);printf(n);printf(*n);printf(n);printf(请输入命令:);break;case 5:printf(*n);printf(n);fread=fopen(c41.txt,r);charin=fgetc(fread);while (charin!=EOF)putchar(charin);charin=fgetc(fread);printf(n);printf(*n);printf(n);printf(请输入命令:);break;case 6:printf(*n);printf(n);fread=fope
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 畜产品加工市场分析考核试卷
- 放射性矿物选矿的放射性物质在线监测考核试卷
- 2025年注会复习计划的重要性试题及答案
- 广艺艺考模拟试题及答案
- 2023年中国铁塔夏季校园招聘709人笔试参考题库附带答案详解
- 空调施工组织方案范本
- 塑胶场地在使用中的清洁与保养考核试卷
- 证券从业资格证突破点试题及答案
- 疫情防控期间的施工方案
- 2025年证券从业资格证实施计划试题及答案
- 山东省天一大联考·齐鲁名校教研体2024-2025学年(下)高三年级第六次联考(物理试题及答案)
- 房地产市场报告 -2025年第一季度青岛写字楼和零售物业市场概况报告
- 2025年03月人力资源社会保障部所属单位笔试历年典型考题(历年真题考点)解题思路附带答案详解
- 上海市工业技术学校招聘考试真题2024
- 《幼儿园课程图景》阅读分享
- 中海油考试试题及答案
- 2025年第三届天扬杯建筑业财税知识竞赛题库附答案(101-200题)
- 2025年光伏逆变器市场前景分析
- 中国画论知到课后答案智慧树章节测试答案2025年春陕西师范大学
- 易制毒危险化学品管理制度
- GB/T 13511.2-2025配装眼镜第2部分:渐变焦定配眼镜
评论
0/150
提交评论