




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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= ,+,-,*,/,%,=,=,=,!=,!,&,|,|,&,=,?:,-,+,-,.,+=,-=,*=,/=;/*運(yùn)算符表*/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);/*建立運(yùn)算符表文件:key2.txt*/if (floading=fopen(key3.txt,w)=NULL)printf(Error! Cant create file : key3.txt);return;fclose (floading);/*建立標(biāo)識(shí)符表文件: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);/*建立浮點(diǎn)類型常量表文件: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);/*建立保留字臨時(shí)表文件:temp_key1*/if (floading=fopen(temp_key3,w)=NULL)printf(Error! Cant create file : temp_key3);return;fclose (floading);/*建立標(biāo)識(shí)符臨時(shí)文件:temp_key3*/if (fload
8、ing=fopen(temp_c40,w)=NULL)printf(Error! Cant create file : temp_c40);return;fclose (floading);/*建立整數(shù)類型常量臨時(shí)文件:temp_c40*/if (floading=fopen(temp_c41,w)=NULL)printf(Error! Cant create file : temp_c41);return;fclose (floading);/*建立浮點(diǎn)類型常量臨時(shí)文件:temp_c41*/if (floading=fopen(temp_c42,w)=NULL)printf(Error! C
9、ant create file : temp_c42);return;fclose (floading);/*建立字符類型常量臨時(shí)文件:temp_c42*/if (floading=fopen(temp_c43,w)=NULL)printf(Error! Cant create file : temp_c43);return;fclose (floading);/*建立字符串類型常量臨時(shí)文件:temp_c43*/* 保留字及標(biāo)識(shí)符判斷函數(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);*/*對(duì)空格符、水平制表符進(jìn)行處理*/else if (chin= )|(chin=t);/*對(duì)回車符進(jìn)行處理*/else if (chin=n);/*對(duì)單引號(hào)內(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);/*對(duì)雙引號(hào)內(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);/*對(duì)保留字、標(biāo)識(shí)符進(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);/*對(duì)注釋進(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);/*對(duì)運(yùn)算符、分隔符進(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 - 查看運(yùn)算符表文件 *n);printf(* 3 - 查看標(biāo)識(shí)符表文件 *n);printf(* 4 - 查看
17、整數(shù)類型常量表 *n);printf(* 5 - 查看浮點(diǎn)類型常量表 *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(請(qǐng)輸入命令:);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(請(qǐng)輸入命令:);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(請(qǐng)輸入命令:);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(請(qǐng)輸入命令:);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(請(qǐng)輸入命令:);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(請(qǐng)輸入命令:);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(請(qǐng)輸入命令:);break;case 6:printf(*n);printf(n);fread=fopen(c42.t
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 大班健康的蔬菜公開(kāi)課
- 河南中考答案 數(shù)學(xué)試卷
- 廣東省職高一數(shù)學(xué)試卷
- 醫(yī)院課件宣傳海報(bào)制作
- 肝炎病毒微生物與免疫基礎(chǔ)99課件
- 2025年中國(guó)生物傳感器行業(yè)市場(chǎng)運(yùn)營(yíng)現(xiàn)狀及投資戰(zhàn)略咨詢報(bào)告
- 2025年中國(guó)河北省房地產(chǎn)行業(yè)未來(lái)前景預(yù)測(cè)研究報(bào)告
- 青海省項(xiàng)目-藏區(qū)區(qū)域醫(yī)療中心項(xiàng)目可行性研究報(bào)告-智博睿編制
- 2025-2030年中國(guó)防水防油針刺呢行業(yè)深度研究分析報(bào)告
- 健康的人快樂(lè)多課件
- 租地延期合同協(xié)議書
- 2025-2030中國(guó)電力金具市場(chǎng)調(diào)研及重點(diǎn)企業(yè)投資評(píng)估規(guī)劃分析研究報(bào)告
- 數(shù)字技術(shù)考試題及答案
- 國(guó)考消防證試題及答案
- 教師遴選筆試試題及答案
- 船廠安全用電培訓(xùn)課件
- 高中學(xué)生管理
- 2025年西班牙語(yǔ)DELE考試真題模擬試卷(C1)
- 中國(guó)智能駕駛商業(yè)化發(fā)展白皮書
- 《2025年CSCO腎癌診療指南》解讀
- 人教版九年級(jí)化學(xué)上冊(cè)暑假銜接講義(初二升初三)
評(píng)論
0/150
提交評(píng)論