




版權(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ù)類(lèi)型常量表文件:c40.txt*/if (floading=fop
5、en(c41.txt,w)=NULL)printf(Error! Cant create file : c41.txt);return;fclose (floading);/*建立浮點(diǎn)類(lèi)型常量表文件:c41.txt*/if (floading=fopen(c42.txt,w)=NULL)printf(Error! Cant create file : c42.txt);return;fclose (floading);/*建立字符類(lèi)型常量表文件:c42.txt*/if (floading=fopen(c43.txt,w)=NULL)printf(Error! Cant create file
6、: c43.txt);return;fclose (floading);/*建立字符串類(lèi)型常量表文件: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ù)類(lèi)型常量臨時(shí)文件:temp_c40*/if (floading=fopen(temp_c41,w)=NULL)printf(Error! Cant create file : temp_c41);return;fclose (floading);/*建立浮點(diǎn)類(lèi)型常量臨時(shí)文件:temp_c41*/if (floading=fopen(temp_c42,w)=NULL)printf(Error! C
9、ant create file : temp_c42);return;fclose (floading);/*建立字符類(lèi)型常量臨時(shí)文件:temp_c42*/if (floading=fopen(temp_c43,w)=NULL)printf(Error! Cant create file : temp_c43);return;fclose (floading);/*建立字符串類(lèi)型常量臨時(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ì)回車(chē)符進(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ù)類(lèi)型常量表 *n);printf(* 5 - 查看浮點(diǎn)類(lèi)型常量表 *n);printf(* 6 - 查看字符類(lèi)型常量表 *n);printf(* 7 - 查看字符串類(lèi)型常量表 *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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 60 選擇性必修3 第九單元 第51講 胚胎工程
- 采石場(chǎng)承包與礦產(chǎn)資源開(kāi)發(fā)管理合同
- 文化創(chuàng)意產(chǎn)業(yè)采購(gòu)合同版權(quán)保護(hù)保密協(xié)議
- 物態(tài)變化溫度教學(xué)課件
- 消防救援知識(shí)考試試卷含黨召喚救援裝備等多方面內(nèi)容
- 工程交接驗(yàn)收移交表
- 服務(wù)規(guī)范執(zhí)行效果評(píng)估考核試卷
- 智能物流配送路徑規(guī)劃算法考核試卷
- 實(shí)踐項(xiàng)目設(shè)計(jì)與實(shí)施考核試卷
- 機(jī)電科長(zhǎng)面試題及答案
- 2025至2030高純氯化鉀行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- ××中學(xué)實(shí)驗(yàn)室危化品管理細(xì)則
- 家政服務(wù)培訓(xùn) 課件
- 2025年婚姻家庭咨詢師職業(yè)資格考試試題及答案
- 2025年人教版小學(xué)五年級(jí)下冊(cè)數(shù)學(xué)期末重難點(diǎn)測(cè)評(píng)試題(含答案和解析)
- 2024年天津市應(yīng)急管理局招聘行政執(zhí)法專(zhuān)職技術(shù)檢查員筆試真題
- 變電站創(chuàng)優(yōu)工程匯報(bào)
- 廣西壯族自治區(qū)欽州市2024-2025學(xué)年高二上學(xué)期期末檢測(cè)歷史試題(含答案)
- 項(xiàng)目部主要管理制度
- 音樂(lè)杜鵑圓舞曲教案
- T/CACE 0129-2024竹編安全帽
評(píng)論
0/150
提交評(píng)論