![c語言詞法分析器-c語言版-源代碼(Clanguagelexicalanalyzer-clanguageversion-sourcecode)_第1頁](http://file4.renrendoc.com/view/92ed4d72815a09da73f536f49163659e/92ed4d72815a09da73f536f49163659e1.gif)
![c語言詞法分析器-c語言版-源代碼(Clanguagelexicalanalyzer-clanguageversion-sourcecode)_第2頁](http://file4.renrendoc.com/view/92ed4d72815a09da73f536f49163659e/92ed4d72815a09da73f536f49163659e2.gif)
![c語言詞法分析器-c語言版-源代碼(Clanguagelexicalanalyzer-clanguageversion-sourcecode)_第3頁](http://file4.renrendoc.com/view/92ed4d72815a09da73f536f49163659e/92ed4d72815a09da73f536f49163659e3.gif)
![c語言詞法分析器-c語言版-源代碼(Clanguagelexicalanalyzer-clanguageversion-sourcecode)_第4頁](http://file4.renrendoc.com/view/92ed4d72815a09da73f536f49163659e/92ed4d72815a09da73f536f49163659e4.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
c語言詞法分析器ーc語言版一源代碼(Clanguagelexicalanalyzer
clanguageversion_sourcecode)包括くstdio.h>包括〈字符串?!卑à绦颉!眂har*KEY0[]={"、“自動”、“破”ヽ“案例”、“炭”ヽ“常量”、“繼續(xù)”、“默認(rèn)”、“做”、“雙”、“人”、“枚舉”、“外部”、“浮”、“”、“去”、“如果”、“國際”、“長”、“登記”、“回歸”、“短”、“簽署”、“大小”、“靜”、“結(jié)構(gòu)”、“開關(guān)”、“類型”、“一complex”、“.imaginary”、“聯(lián)盟”、“無”、“虛”、“不穩(wěn)定”,“而”};保留字表/**/char*keyl[]={“”、“(”、つ”、“[”ヽ“]”、“{”、分隔符表/**char?鍵口={“”運算符表/**intXX0[35][10],XXI,XX2[31]國際temp_key3=0,tempc40=0,temp_c41=0,temp_c42=0,temp_c43=0;/*******初始化函數(shù)*******/無效()Iint毫米;對于(mm=0;mm=34;采購經(jīng)理+)IXX0[毫米]=0;)對于(mm=0;毫米=〈9:毫米+++)IXXI[毫米]=0;對于(mm=0;mm=30;采購經(jīng)理+)XX2[毫米]=0;?文件載;如果((載=fopen(“KEYO.txt"、"W"))==null){printf("錯誤!無法創(chuàng)建文件:KEY0.txt");返回;)關(guān)閉文件(載);/**/建立保留字表文件:KEY0.txt如果((載=fopen("keyl.txt"、"W"))==null)iprintf(“錯誤!無法創(chuàng)建文件:KEY1.txt");返回;/**/建立分隔符表文件:KEY1.txt如果((載=fopen("key2.txt"、'如"))==null)(printf("錯誤!無法創(chuàng)建文件:KEY2.txt");返回;}關(guān)閉文件(載);/**/建立運算符表文件:KEY2.txt如果((載=fopen(“KEY3.txt"、"W"))==null)(printf(“錯誤!無法創(chuàng)建文件:KEY3.txt");返回;)關(guān)閉文件(載);/**/建立標(biāo)識符表文件:KEY3.txt如果((載=fopen("C40.txt"、"W"))==null)printf("錯誤!無法創(chuàng)建文件:C40.txt");返回;)關(guān)閉文件(載);/**/建立整數(shù)類型常量表文件:C40.txt如果((載=fopen("C41.txt"、"W"))==null){printf("錯誤!無法創(chuàng)建文件:C41.txt");返回;)關(guān)閉文件(載);/**/建立浮點類型常量表文件:C41.txt如果((載=fopen(“C42.txt"、"W"))==null)printf("錯誤!無法創(chuàng)建文件:C42.txt”);返回;}關(guān)閉文件(載);/**/txt建立字符類型常量表文件:C42。如果((載二fopen(“C43.txt"、“W"))==null)(printf("錯誤!無法創(chuàng)建文件:C43.txtv);返回;)關(guān)閉文件(載);/**/建立字符串類型常量表文件:C43.txt如果((載=fopen("定義.txt”、"W"))==null)(printf("錯誤!無法創(chuàng)建文件:定義.txt”);返回;)關(guān)閉文件(載);/**/txt建立注釋文件:定義。如果((載=fopen(“輸出文件”、“W"))==null){printf("錯誤!無法創(chuàng)建文件:輸出"txt");返回;)關(guān)閉文件(載);/**/txt建立內(nèi)部碼文件:輸出。如果((載;fopen("temp_keyl">"W"))==null)(printf("錯誤!無法創(chuàng)建文件:temp-keyl");返回;關(guān)閉文件(載);建立保留字臨時表文件:temp_keyl*//*如果((載=fopen("temp_key3"、"W"))==null)(printf("錯誤!無法創(chuàng)建文件:temp_key3");返回;)關(guān)閉文件(載);建立標(biāo)識符臨時文件:temp_key3*//*如果((載=fopen("temp_c40"、"W"))==null)]printf("錯誤!無法創(chuàng)建文件:temp_c40w);返冋;)關(guān)閉文件(載);建立整數(shù)類型常量臨時文件:temp_c40*//*如果((載=fopen("temp_c41"ヽ"W"))==null)printf("錯誤!無法創(chuàng)建文件:temp_c41");返回;)關(guān)閉文件(載);建立浮點類型常量臨時文件:temp_c41*//*如果((載;fopen("temp_c42"、"W"))==null){printf("錯誤!無法創(chuàng)建文件:temp_c42,r);返回;)關(guān)閉文件(載);建立字符類型常量臨時文件:temp_c42*//*如果((載;fopen("temp_c43"、“W"))==null)printf("錯誤!無法創(chuàng)建文件:temp_c43>>);返回;)關(guān)閉文件(載);建立字符串類型常量臨時文件:temp_c43*//*)/*******保留字及標(biāo)識符判斷函數(shù)?******//*******浮點類型判斷函數(shù)*******/無效intbsearch(char?的話)(foutput文件?,*finput;字符c;字符cs[100];int=0;int行=0;intvalue2=0;如果(temp一Ml==0)(foutput=fopen("temp_c41","");fprintf(foutput,"%s",字);關(guān)閉文件(foutput);temp_c41++;foutput=fopen("C41.txt","");fprintf(foutput,"4T1\T1T%s\n",字);關(guān)閉文件(foutput);)finput=fopen(<ftemp_c41"ヽ"R");C=指針(finput);而(c)!=EOF)而(c)!=”ncs;C=指針(finput);}cs="0”;CSI=0;行+;如果(strcmp(CS?字)==0)(value2=1;打破;}C=指針(finput);關(guān)閉文件(finput);如果(value2==1)foutput=fopen("輸出。txt",グ’);fprintf(foutput,“4T1TT%s%d\n",行,字);關(guān)閉文件(foutput);)其他的{foutput=fopen("temp_c41","");fprintf(foutput,"%s",字);關(guān)閉文件(foutput);temp_c41++;foutput=fopen("輸出。txt","");fprintf(foutput,“4T1TT%s%d\n",tempc41,字);關(guān)閉文件(foutput);foutput=fopen("C40。txt","");fprintf(foutput,“4T1TT%s%d\n",tempc41?字);關(guān)閉文件(foutput);))/*******字符串常量判斷函數(shù)?******/無效cc_search(char?的話)!file*foutput,*finput;charc;charcs[100];intcsi=0;intline=0;intvalue2=0;if(temp_c==0)foutput=fopen("temp_c","a");fprintf(foutput,"%s"n",word);fclose(foutput);temp_c++;foutput=fopen("c43.txt","a");fprintf(foutput,"4it3andtlandt%s\n",word);fclose(foutput);finput-fopen("temp_c","r");c=fgetc(finput);while(c!=eof)while(c!='\n')cs[csi++]=c;c=fgetc(finput);cs[csi]=‘、0';csi=0;line++;if(strcmp(cs,word)==0)(value2=1;break;)c=fgetc(finput);)fclose(finput);if(value2==1)foutput=fopen("output.txt","a");fprintf(foutput,z,4it3t"t%d%s\n”,line,word);fclose(foutput);elsefoutput=fopen("temp_c","a");fprintf(foutput,"%s"n",word);fclose(foutput);temp_c++;foutput=fopen("output,txt","a");fprintf(foutput,"4it3tt%d%s\n",thetemp_c,word);fclose(foutput);foutput=fopen("c43.txt","a");fprintf(foutput,"4it3tt%d%s\n",thetemp_c,word);fclose(foutput);/*******字符常量判斷函數(shù)?******/voidc_search(char*word)(file*foutput,*finput;charc;charcs[100];intcsi=0;intline=0;intvalue2=0;if(temp_c42==0)Ifoutput=fopen("temp_c42","a");fprintf(foutput,"%s"n",word);fclose(foutput);temp_c42++;foutput=fopen("c42.txt,a);fprintf(foutput,“4it2andtlandt%s\n”,word);fclose(foutput);finput=fopen("temp_c42","r");c=fgetc(finput);while(c!=eof)while(c!='\n')cs[csi++]=c;c=fgetc(finput);cs[csi]='、0';csi=0;line++;if(strcmp(cs,word)==0)(value2=1;break;}c=fgetc(finput);)fclose(finput);if(value2==1)Ifoutput=fopen("output.txt","a");fprintf(foutput,"4it2*t%d%t%s\n”,line,word);fclose(foutput);elsefoutput=fopen("temp_c42","a");fprintf(foutput,"%s"n",word);fclose(foutput);temp_c42++;foutput=fopen("output,txt","a");fprintf(foutput,"4it2*t%d%t%s\n",thetemp_c42,word);fclose(foutput);foutput=fopen("c42.txt","a");fprintf(foutput,"4it2*t%d%t%s\n",thetemp_c42,word);fclose(foutput);/*******主掃描函數(shù)*******/scan(void){intcount;charchin;file*fin;file*agriculturaldevelopment;charfilename[50];chartemp[100];chartarget[3]= ;printf(“請輸入文件名:“);scanf("%s",filename);if((fin=fopen(filename,"r"))==null)[printf("error!can,topenfile:%s"n"文件名);返回;下巴=指針(鰭);當(dāng)(下巴)!=EOF){對文件包含、宏定義進(jìn)行處理/**/如果(下巴=="中’){當(dāng)(下巴)!=下巴=指針(鰭);/?下巴=指針(鰭);*/)對空格符、水平制表符進(jìn)行處理/**/elseif((下巴==")||(下巴=='\t'))對回車符進(jìn)行處理/**/否則如果(下巴=“n”)對單引號內(nèi)的字符常量進(jìn)行處理/**/否則如果(目標(biāo)=[0])(如果(XXI[9]==0)!四=fopen("keyl.txt","");fprintf(4,“1T9\T/T%c\n"?目標(biāo)[0]);關(guān)閉文件(四);XXI[9]=1;臨時溫度[0]=下巴;下巴=指針(鰭);臨時溫度[1]=下巴;下巴二指針(鰭);如果(下巴)!二目標(biāo)[0]I臨時溫度[2]:下巴;下巴二指針(鰭);臨時溫度[3]=下巴;臨時值[4]=“0”;)其他的臨時值[3]=“0”;c_search(臨時);)對雙引號內(nèi)的字符串常量進(jìn)行處理/**/否則,如果(須="")!int=iO;臨時文件“i”;下巴=指針(鰭);當(dāng)(下巴)!=""體溫[下巴];下巴=指針(鰭);臨時[i]="";溫度[i+1]=\0;cc_search(臨時);)對保留字、標(biāo)識符進(jìn)行處理/**/elseif(((下巴>=““)&(下巴く=Z))||((下巴>="“)&(下巴く=Z))||(下巴=='_'))!int=i0;而(((下巴〉:“”)&(下巴く=Z))||((下巴〉="")&(下巴く=Z))丨|(下巴==)丨丨((下巴〉=’0')&(下巴く=9)))(體溫[下巴];下巴=指針(鰭);)溫度溫:”〇;charsearch(臨時);如果(下巴)!=EOF)fseek(鰭,11,seekcur);)對整型、浮點型數(shù)據(jù)進(jìn)行處理/**/elseif((下巴>='〇')&(下巴く=9))國際dotcount=0;int=i0;而(((下巴>='〇')&(下巴く=9))||(下巴==""))(如果(下巴=)dotcount++;如果(dotcount==2)打破;體溫[下巴];下巴=指針(鰭);溫度“i=”〇;如果(dotcount==1)intbsearch(臨時);其他的inta_search(臨時);如果(下巴)!=EOF)fseek(鰭,11,seek一cur);)對注釋進(jìn)行處理/**/否則,如果(下巴=“/”)[下巴=指針(鰭);如果(下巴="二")四=fopen("輸出。txt”,“”);fprintf(4,“2T30\T/T/=\n");關(guān)閉文件(四);}如果(下巴)!="*"{四=fopen("輸出。txt”,“”);fprintf(4,“2T4\TT/\n”);關(guān)閉文件(四);fseek(鰭,11,seekcur);)否則如果(下巴:“*”)計數(shù)=0;下巴二指針(鰭);四=fopen(“定義。txtw,"");fprintf(4,“*”);(計數(shù))!=2){計數(shù)=0;當(dāng)(下巴)!=fprintf(upeverybody'slife,,%c,chin).chin=fgetc()(fin);)count++;fprintf(upeverybody'slife,"%c,chin).chin=fgetc()(fin);if(chin=='/')count++;fprintf(upeverybody'slife,"%c\n",chin).}else(fprintf(upeverybody'slife,飛c”,chin).chin=fgetc()(fin);)/?對運算符、分隔符進(jìn)行處理?/else(inttime=0;intfirstblood=0;temp[0]=chin;chin=fgetc()(fin);if(chin.=eof){temp[1]=chin;temp[2]=‘、〇';for(time=1;timeく=30;time++)Iif(strcmp(temp,key2[time])==0){firstblood=1;if(xx2[time]==0)iupeverybody's1ife=fopen('key2.txt","a");fprintf(upeverybody'slife,“2\t%d\t\t%s\n”,time,temp.fclose(upeverybody'slife.xx2[time]=1;upeverybody,slife=fopen("output.txt",a);fprintf(upeverybody's1ife,“2\t%d\t\t%s\n”,time,temp.fclose(upeverybody'slife.break;))if(firstblood!=1)(fseek()(fin,-11,seek_cur).temp[1]=>\0';for(time=1;time<=9;time++)if(strcmp(temp,keyl[time])==0)if(xxl[time]==0)upeverybody'slife=fopen("keyl.txt","a");fprintf(upeverybody'slife,"1\t%d\t\t%s\n",time,temp.fclose(upeverybody'slife.xxl[time]=1;upeverybody'slife=fopen("output.txt","a");fprintf(upeverybody'slife,"1\t%d\t\t%s\n",time,temp.fclose(upeverybody'slife.break;for(time=1;time<=30;time++)if(strcmp(temp,key2[time])==0)if(xx2[time]==0)upeverybody,slife=fopen("key2.txt","a");fprintf(upeverybody'slife,“2\t%d\t\t%s\n”,time,temp.fclose(upeverybody'slife.xx2[time]=1;upeverybody'slife=fopen("output.txt,a);fprintf(upeverybody'slife,“2\t%d\t\t%s\n”,time,temp.fclose(upeverybody'slife.break;chin=fgetc()(fin);upeverybody'slife=fopen("output.txt",a);fprintf(upeverybody'slife,“1\t6\t\t}\n");fclose(upeverybody'slife./*******main函數(shù)*******/voidmain()file*updates;charcharin;charcommand='q'.printf("ヽn");printf("********************c語言詞法分析工具********************、n");printf("**\n");printf('**\n");printf("?命令如下:*\n");printf("*0->查看保留字表文件?\n");Printf(*1/viewdelimitertablefile*\n");Printf('*2->Viewoperatortablefile*\n");Printf('*3/viewidentifiertablefile*\n");Printf('*4->viewtypeintegerconstanttable*\n");Printf(*5/viewfloating-pointtypeconstanttable*\n");Printf('*6->viewcharactertypeconstanttable*\n");Printf('*7->Viewstringtypeconstanttable*\n");Printf('*8—>Viewcommentfile*\n");Printf(*9->viewinternalcodefile*\n");Printf('*\n* ");Printf('*\n*Q/exit");Printfrxl**1*xl*xl* xlx*1* *1*?Jx <*1**Jxxlx?Jxxlxxl*xlx>>!*xL*xlxxlxxlxxl*xl*xlxxl*xlxxlxxL?xL*xlxxl*xlxxl*xl>xL*xlxxlxxlxxl*xlxxl*xl*******\n");Printf("\n");Load();Scan();Printf("\n");Printf(analysiscompleted)!\n");Getchar();Printf("\n");Printf(entercommand:);Command=getchar();While((command!='Q')&&(command!='q'))Switch(command)Case'0):{Printf("*************************\n");Printf("\n");Fread=fopen("keyO.txt","R");Charin=fgetc(FREAD);While(CHARIN,=EOF)Putchar(CHARIN);Charin=fgetc(FREAD);Printf("\n");Printf("*************************\n");Printf("\n");Printf(entercommand:);Break;)Case'1':!Printf("*************************\n");Printf("\n");Fread=fopen("keyl.txt/z,"R");Charin=fgetc(FREAD);While(CHARIN,=EOF)IPutchar(CHARIN);Charin=fgetc(FREAD);PrintfPrintf("*************************\n");Printf("\n");Printf(entercommand:);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(entercommand:);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;}(printf("*************************n");printf("\n");fread=fopen("c40.txJ,"r");charin=fgetc(fread);while(charin!=eof)putchar(charin);charin=fgetc(fread);)printf("ヽn");printf("*************************n");printf("ヽn");printf("請輸入命令:");break;)(printf("*************************n");printf("ヽn");fread=f
溫馨提示
- 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)出讓合同主體變更及土地征收補償協(xié)議
- 鄉(xiāng)村旅游攪拌車運輸合同
- 二零二五年度磚廠安全生產(chǎn)責(zé)任管理合同模板
- 二零二五年度企業(yè)應(yīng)急資金借款合同規(guī)范
- 開關(guān)插座采購合同標(biāo)準(zhǔn)版
- 《分論點的擬定》課件
- 《現(xiàn)代建筑文化》課件
- 《電路及分析方法》課件
- 銅產(chǎn)業(yè)供應(yīng)鏈管理與優(yōu)化
- 2025年酒店總經(jīng)理崗位職責(zé)與薪酬協(xié)議
- 綠色能源項目融資計劃書范文
- 大樹扶正施工方案
- 2024年全國職業(yè)院校技能大賽中職組(母嬰照護(hù)賽項)考試題庫(含答案)
- 課題申報參考:全齡友好視角下的社區(qū)語言景觀評估及空間優(yōu)化研究
- 五年級下冊語文四大名著??贾R點
- 2024年上海普陀區(qū)司法局招聘人民調(diào)解員考試真題
- 光伏發(fā)電項目施工組織設(shè)計方案及技術(shù)措施
- 2025年1月日歷表(含農(nóng)歷-周數(shù)-方便記事備忘)
- 專題06 現(xiàn)代文閱讀(解析版)2015-2024單招考試語文(四川真題)
- 《固體食品罐用冷軋電鍍錫鋼板及鋼帶》編制說明
評論
0/150
提交評論