付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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,_Imaginar y,un
2、ion,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
3、=0;mm=9;mm+)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
4、(floading=fopen(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! Can
5、t create file : 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
6、);/* 建立字符类型常量表文件:c42.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 (f
7、loading=fopen(output.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
8、(Error! Cant create file : 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);retu
9、rn;fclose (floading);/* 建立浮点类型常量临时文件: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);/* 建立字符串类型常量临时文件:te
10、mp_c43*/*保留字及标识符判断函数*/void 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=
11、0)fout=fopen(key1.txt,a);fprintf(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);w
12、hile (chin!=)tempi+=chin;chin=fgetc(fin);tempi=;tempi+1=0;cc_search(temp);/* 对保留字、标识符进行处理*/elseif(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)in
13、tb_search(temp);elseinta_search(temp);if (chin!=EOF)fseek (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 i
14、f (chin=*)count=0;chin=fgetc(fin);fout=fopen(defination.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);/* 对运算符、分隔符进行处理
15、*/elseint time=0;int firstblood=0;temp0=chin;chin=fgetc(fin);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%
16、sn,time,temp);fclose(fout);break;if (firstblood!=1)fseek(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
17、);break;for (time=1;time查看保留字表文件*n);printf(*1 -查看分隔符表文件*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
18、();scan();printf(n);printf(分析完成! 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);pr
19、intf(请输入命令: );break;case 1:printf(*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(c
20、harin);charin=fgetc(fread);printf(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(
21、c40.txt,r);charin=fgetc(fread);while (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年新型结构不锈钢丝绳合作协议书
- 译林版英语三年级下册Unit1-Unit2(基础知识过关含答案)
- 2025 八年级道德与法治上册合理利用网络课件
- 旅游景区导览系统操作与维护指南(标准版)
- 建筑行业施工与管理规范
- 环保设施操作与污染控制指南
- 新能源技术发展与应用手册(标准版)
- 旅游酒店业服务与管理指南(标准版)
- 网络设备故障诊断与处理指南(标准版)
- 燃气锅炉燃烧过程智能控制系统设计
- 2025年新疆中考化学试卷真题(含答案解析)
- 2025年物流运输安全考试试题及答案
- 住房公积金银行服务网点建设及服务管理指南-地方标准编制说明
- 2025年西宁市城区中考英语试卷真题(含答案)
- 2021-2025年高考化学真题知识点分类汇编之有机合成(推断大题)(一)
- 柴油发动机维护与故障排查手册
- 安桥AV功放接收机TX-SR600使用说明书
- 探究“教学评”一体化在小学数学教学中的应用与策略
- 诊断学基础重点【完全版】
- 2025年电力机车司机职业技能竞赛理论考试题库(含答案)
评论
0/150
提交评论