




已閱讀5頁(yè),還剩2頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
編譯原理(實(shí)驗(yàn)部分)實(shí)驗(yàn)2_PL0詞法分析一、實(shí)驗(yàn)?zāi)康募由詈挽柟虒?duì)于詞法分析的了解和掌握;初步認(rèn)識(shí)PL/0語(yǔ)言的基礎(chǔ)和簡(jiǎn)單的程序編寫(xiě);通過(guò)本實(shí)驗(yàn)?zāi)軌虺醪降牧私夂驼莆粘绦蛟~法分析的整個(gè)過(guò)程;提高自己上機(jī)和編程過(guò)程中處理具體問(wèn)題的能力。二、實(shí)驗(yàn)設(shè)備1、PC 兼容機(jī)一臺(tái);操作系統(tǒng)為WindowsWindowsXP。2、Visual C+ 6.0 或以上版本, Windows 2000 或以上版本,匯編工具(在Software 子目錄下)。三、實(shí)驗(yàn)原理PL/O語(yǔ)言的編譯程序,是用高級(jí)語(yǔ)言PASCAL語(yǔ)言書(shū)寫(xiě)的。整個(gè)編譯過(guò)程是由一些嵌套及并列的過(guò)程或函數(shù)完成。詞法分析程序是獨(dú)立的過(guò)程GETSYM完成,供語(yǔ)法分析讀單詞時(shí)使用。四、實(shí)驗(yàn)步驟閱讀所給出的詞法分析程序(pl0_lexical.c),搞懂程序中每一個(gè)變量的含義,以及每一個(gè)過(guò)程的作用,并在該過(guò)程中進(jìn)行中文注釋;閱讀完程序后,畫(huà)出各過(guò)程的流程圖;給出的程序包含兩處輸入錯(cuò)誤,利用所給的pl/0源程序(test.pl0)對(duì)程序進(jìn)行調(diào)試,使其能正確對(duì)所給文件進(jìn)行分析并能夠解釋運(yùn)行;在閱讀懂所給出的詞法分析程序后,將你對(duì)詞法分析的理解寫(xiě)在實(shí)驗(yàn)報(bào)告上。實(shí)驗(yàn)代碼#includemain() printf (my name is 08061118 yuchaofeng );主程序:#include #include #include #include #include #define NULL 0FILE *fp;char cbuffer;char *key8=DO,BEGIN,ELSE,END,IF,THEN,VAR,WHILE;char *border6=,;,:=,.,(,);char *arithmetic4=+,-,*,/;char *relation6=,=,;char *consts20;char *label20;int constnum=0,labelnum=0;int search(char searchchar,int wordtype) int i=0; switch (wordtype) case 1:for (i=0;i=7;i+) if (strcmp(keyi,searchchar)=0) return(i+1); ; case 2:for (i=0;i=5;i+) if (strcmp(borderi,searchchar)=0) return(i+1); ; return(0); case 3:for (i=0;i=3;i+) if (strcmp(arithmetici,searchchar)=0) return(i+1); ; ; return(0); ; case 4:for (i=0;i=5;i+) if (strcmp(relationi,searchchar)=0) return(i+1); ; ; return(0); ; case 5:for (i=0;i=constnum;i+) if (strcmp(constsi,searchchar)=0) return(i+1); ; constsi-1=(char *)malloc(sizeof(searchchar); strcpy(constsi-1,searchchar); constnum+; return(i); ; case 6:for (i=0;i=labelnum;i+) if (strcmp(labeli,searchchar)=0) return(i+1); ; labeli-1=(char *)malloc(sizeof(searchchar); strcpy(labeli-1,searchchar); labelnum+; return(i); ; char alphaprocess(char buffer) int atype; int i=-1; char alphatp20; while (isalpha(buffer)|(isdigit(buffer) alphatp+i=buffer; buffer=fgetc(fp); ; alphatpi+1=0; if (atype=search(alphatp,1) printf(%s (1,%d)n,alphatp,atype-1); else atype=search(alphatp,6); printf(%s (6,%d)n,alphatp,atype-1); ; return(buffer); char digitprocess(char buffer) int i=-1; char digittp20; int dtype; while (isdigit(buffer) digittp+i=buffer; buffer=fgetc(fp); digittpi+1=0; dtype=search(digittp,5); printf(%s (5,%d)n,digittp,dtype-1); return(buffer); char otherprocess(char buffer) int i=-1; char othertp20; int otype,otypetp; othertp0=buffer; othertp1=0; if (otype=search(othertp,3) printf(%s (3,%d)n,othertp,otype-1); buffer=fgetc(fp); goto out; ; if (otype=search(othertp,4) buffer=fgetc(fp); othertp1=buffer; othertp2=0; if (otypetp=search(othertp,4) printf(%s (4,%d)n,othertp,otypetp-1); goto out; else othertp1=0; printf(%s (4,%d)n,othertp,otype-1); goto out; ; if (buffer=:) buffer=fgetc(fp); if (buffer=) printf(:= (2,2)n); buffer=fgetc(fp); goto out; else if (otype=search(othertp,2) printf(%s (2,%d)n,othertp,otype-1); buffer=fgetc(fp); goto out; ; if (buffer!=n)&(buffer!= ) printf(%c error,not a wordn,buffer); buffer=fgetc(fp);out: return(buffer); void main() int i; for (i=0;i=20;i+) labeli=NULL; constsi=NULL; ; if (fp=fopen(skh.c,r)=NULL) printf(error); else cbuffer = fgetc(fp); while (cbuffer!=EOF) if (isa
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 市政污水管網(wǎng)改造項(xiàng)目安全管理方案(參考模板)
- 2025年混凝土攪拌運(yùn)輸車(chē)合作協(xié)議書(shū)
- 城鎮(zhèn)污水管網(wǎng)建設(shè)工程數(shù)字化方案(參考模板)
- 油田開(kāi)發(fā)項(xiàng)目規(guī)劃設(shè)計(jì)方案(參考)
- 汽車(chē)配套產(chǎn)業(yè)基地項(xiàng)目初步設(shè)計(jì)(參考)
- 城鎮(zhèn)污水管網(wǎng)建設(shè)項(xiàng)目初步設(shè)計(jì)(范文模板)
- 鄉(xiāng)村金融創(chuàng)新與城鄉(xiāng)資金流通
- 2025年門(mén)系統(tǒng)配件項(xiàng)目發(fā)展計(jì)劃
- 西藏銀行招聘考試會(huì)計(jì)基礎(chǔ):會(huì)計(jì)檔案考試試題
- 2025年光刻膠專用化學(xué)品項(xiàng)目合作計(jì)劃書(shū)
- 企業(yè)崗位職級(jí)管理制度
- 兒童沙門(mén)菌感染診療要點(diǎn)
- 2025-2030年中國(guó)少兒藝術(shù)培訓(xùn)行業(yè)市場(chǎng)深度調(diào)研及競(jìng)爭(zhēng)格局與投資研究報(bào)告
- 2025泰山護(hù)理職業(yè)學(xué)院教師招聘考試試題
- 省供銷(xiāo)社招聘試題及答案
- 養(yǎng)殖場(chǎng)防疫員聘請(qǐng)協(xié)議書(shū)
- 護(hù)士考編制試題及答案
- 提升教師評(píng)價(jià)素養(yǎng)的策略及實(shí)施路徑
- 消防安全管理制度與操作流程匯編
- 女性導(dǎo)尿術(shù)方法步驟
評(píng)論
0/150
提交評(píng)論