




版權(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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 船舶行業(yè)競(jìng)爭(zhēng)格局考核試卷
- 肉類產(chǎn)品加工過(guò)程中的食品安全檢測(cè)技術(shù)考核試卷
- 生態(tài)保護(hù)工程生態(tài)保護(hù)宣傳教育考核試卷
- 葡萄酒釀造過(guò)程中的產(chǎn)區(qū)特色產(chǎn)品開發(fā)與品牌推廣考核試卷
- 輪胎行業(yè)市場(chǎng)細(xì)分與競(jìng)爭(zhēng)策略考核試卷
- 通信設(shè)備在高鐵通信系統(tǒng)的穩(wěn)定性考核試卷
- 茶館客戶體驗(yàn)設(shè)計(jì)與反饋機(jī)制考核試卷
- 賦能創(chuàng)新生態(tài)引領(lǐng)企業(yè)可持續(xù)發(fā)展考核試卷
- 初中物理回聲測(cè)距離
- 抖音平臺(tái)短視頻內(nèi)容制作技術(shù)保密及推廣合作協(xié)議
- 神經(jīng)鞘瘤MRI診斷要點(diǎn)及鑒別診斷課件
- 120個(gè)常見文言實(shí)詞例釋-高考語(yǔ)文考前復(fù)習(xí)速記清單
- T-CEPPEA 5002-2019 電力建設(shè)項(xiàng)目工程總承包管理規(guī)范
- GA 1812.2-2024銀行系統(tǒng)反恐怖防范要求第2部分:數(shù)據(jù)中心
- 2025年端午節(jié)撞上兒童節(jié)活動(dòng)方案
- 法治護(hù)航成長(zhǎng)路-四年級(jí)法制教育專題
- 電工技能培訓(xùn)課件下載
- 衛(wèi)生管理醫(yī)療戰(zhàn)略考題及答案
- 冷鏈物流突發(fā)事件應(yīng)急處理措施
- 25春國(guó)家開放大學(xué)《中國(guó)古代文學(xué)(下)》形考任務(wù)1-4參考答案
- 2025年荊州監(jiān)利市暢惠交通投資有限公司招聘筆試參考題庫(kù)含答案解析
評(píng)論
0/150
提交評(píng)論