




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、#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 *key1= ,(,),;,;/*分隔符表*/char *
2、key2= ,+,-,*,/,%,=,=,=,!=,!,&,|,|,&,=,?:,-,+,-,.,+=,-=,*=,/=;/*運算符表*/int xx035,xx110,xx231;int temp_key3=0,temp_c40=0,temp_c41=0,temp_c42=0,temp_c43=0;/* 初始化函數(shù) */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 *floading;if (floading=fopen(key
3、0.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 file : key2.txt);return;fclo
4、se(floading);/*建立運算符表文件:key2.txt*/if (floading=fopen(key3.txt,w)=NULL)printf(Error! Cant create file : key3.txt);return;fclose (floading);/*建立標(biāo)識符表文件:key3.txt*/if (floading=fopen(c40.txt,w)=NULL)printf(Error! Cant create file : c40.txt);return;fclose (floading);/*建立整數(shù)類型常量表文件:c40.txt*/if (floading=fop
5、en(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(Error! Cant create file
6、: 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 : output.txt);return;fclose (
7、floading);/*建立內(nèi)部碼文件: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);/*建立標(biāo)識符臨時文件:temp_key3*/if (fload
8、ing=fopen(temp_c40,w)=NULL)printf(Error! Cant create file : temp_c40);return;fclose (floading);/*建立整數(shù)類型常量臨時文件: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_c42,w)=NULL)printf(Error! C
9、ant 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*/* 保留字及標(biāo)識符判斷函數(shù) */void char_search(char *word)int m,line=0,csi=0;int value=0;int value2=0;char
10、 c,cs100;FILE *foutput,*finput;for (m=1;m)chin=fgetc(fin);/*chin=fgetc(fin);*/*對空格符、水平制表符進(jìn)行處理*/else if (chin= )|(chin=t);/*對回車符進(jìn)行處理*/else if (chin=n);/*對單引號內(nèi)的字符常量進(jìn)行處理*/else if (chin=target0)if (xx19=0)fout=fopen(key1.txt,a);fprintf(fout,1t9tt%cn,target0);fclose(fout);xx19=1;temp0=chin;chin=fgetc(fin
11、);temp1=chin;chin=fgetc(fin);if (chin!=target0)temp2=chin;chin=fgetc(fin);temp3=chin;temp4=0;elsetemp2=chin;temp3=0;c_search(temp);/*對雙引號內(nèi)的字符串常量進(jìn)行處理*/else if (chin=)int i=0;tempi+=;chin=fgetc(fin);while (chin!=)tempi+=chin;chin=fgetc(fin);tempi=;tempi+1=0;cc_search(temp);/*對保留字、標(biāo)識符進(jìn)行處理*/else if (chi
12、n=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);/*對注釋進(jìn)行處理*/else if (chin=/)chin=fgetc(fin);if (chin=
13、)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;while (chin!=*)fprintf(fou
14、t,%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);/*對運算符、分隔符進(jìn)行處理*/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(
15、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+)if (strcmp(temp,key1tim
16、e)=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 - 查看分隔符表文件 *n);printf(* 2 - 查看運算符表文件 *n);printf(* 3 - 查看標(biāo)識符表文件 *n);printf(* 4 - 查看
17、整數(shù)類型常量表 *n);printf(* 5 - 查看浮點類型常量表 *n);printf(* 6 - 查看字符類型常量表 *n);printf(* 7 - 查看字符串類型常量表 *n);printf(* 8 - 查看注釋文件 *n);printf(* 9 - 查看內(nèi)部碼文件 *n);printf(* - *n);printf(* Q - 退出 *n);printf(*n);printf(n);load();scan();printf(n);printf(分析完成!n);getchar();printf(n);printf(請輸入命令:);command=getchar();while (co
18、mmand!=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:printf(*n);printf(n);fread=fopen(key1.txt,r);charin=fgetc(fread);while (char
19、in!=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);printf(n);printf(*n);printf(n);printf(請輸入命令:);break;case 3:printf(*n);printf(
20、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);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=fopen(c42.t
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 IEC 62290-2:2025 EN-FR Railway applications - Urban guided transport management and command/control systems - Part 2: Functional requirements specification
- 【正版授權(quán)】 IEC 60512-99-002:2022/AMD1:2025 EN-FR Amendment 1 - Connectors for electrical and electronic equipment - Tests and measurements - Part 99-002: Endurance test schedules - Tes
- 【正版授權(quán)】 IEC 60947-7-1:2025 EN-FR Low-voltage switchgear and controlgear - Part 7-1: Ancillary equipment - Terminal blocks for copper conductors
- 2025年影視制作過程與技術(shù)考試試卷及答案
- 2025年心理學(xué)專業(yè)考試試題及答案
- 2025年數(shù)據(jù)挖掘與機(jī)器學(xué)習(xí)技術(shù)考試試題及答案
- 2025年海洋科學(xué)專業(yè)考試試卷及答案
- 2025年電子商務(wù)實務(wù)及案例分析考試試題及答案
- 配送貨車合同協(xié)議書
- 2025年母嬰護(hù)理專項考核試題
- 10SMS202-2 埋地矩形雨水管道及其附屬構(gòu)筑物(磚、石砌體)
- 河道景觀設(shè)計合同范本
- 翻譯員工作合同
- NB-T31052-2014風(fēng)力發(fā)電場高處作業(yè)安全規(guī)程
- 2024年湖南高考?xì)v史真題
- 海外倉合同范本
- 體育行業(yè)投標(biāo)書
- 慢性淋巴增殖性疾病的診斷課件
- 2024年高校教師資格證資格考試題庫含答案(滿分必刷)
- 2024-2029全球及中國電氣電子中的CFD行業(yè)市場發(fā)展分析及前景趨勢與投資發(fā)展研究報告
- 中國法律史-第三次平時作業(yè)-國開-參考資料
評論
0/150
提交評論