




已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(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語言的基礎(chǔ)和簡(jiǎn)單的程序編寫;通過本實(shí)驗(yàn)?zāi)軌虺醪降牧私夂驼莆粘绦蛟~法分析的整個(gè)過程;提高自己上機(jī)和編程過程中處理具體問題的能力。二、實(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語言的編譯程序,是用高級(jí)語言PASCAL語言書寫的。整個(gè)編譯過程是由一些嵌套及并列的過程或函數(shù)完成。詞法分析程序是獨(dú)立的過程GETSYM完成,供語法分析讀單詞時(shí)使用。四、實(shí)驗(yàn)步驟閱讀所給出的詞法分析程序(pl0_lexical.c),搞懂程序中每一個(gè)變量的含義,以及每一個(gè)過程的作用,并在該過程中進(jìn)行中文注釋;閱讀完程序后,畫出各過程的流程圖;給出的程序包含兩處輸入錯(cuò)誤,利用所給的pl/0源程序(test.pl0)對(duì)程序進(jìn)行調(diào)試,使其能正確對(duì)所給文件進(jìn)行分析并能夠解釋運(yùn)行;在閱讀懂所給出的詞法分析程序后,將你對(duì)詞法分析的理解寫在實(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 教育培訓(xùn)廣告宣傳與招生服務(wù)協(xié)議
- 智能家居產(chǎn)品俄羅斯市場(chǎng)代理銷售與推廣協(xié)議
- 網(wǎng)紅甜品店區(qū)域代理合作協(xié)議及品牌授權(quán)經(jīng)營(yíng)合同
- 直播平臺(tái)特色食品供應(yīng)鏈管理與選品協(xié)議
- 數(shù)據(jù)治理項(xiàng)目實(shí)施與效果評(píng)估合同
- 登記離婚后公積金財(cái)產(chǎn)分割及利益調(diào)整合同
- 新能源汽車試駕體驗(yàn)及車輛保險(xiǎn)服務(wù)協(xié)議
- 高效智能立體停車庫使用權(quán)轉(zhuǎn)讓協(xié)議
- 網(wǎng)絡(luò)游戲虛擬貨幣發(fā)行與知識(shí)產(chǎn)權(quán)保護(hù)合同
- 綿陽下跳棋協(xié)議書
- 檢驗(yàn)科菌(毒)種及其樣品安全管理制度
- 水域救援課件教學(xué)課件
- (初級(jí))航空油料特設(shè)維修員(五級(jí))理論考試題庫-上(單選題)
- 尾礦庫安全規(guī)程
- 互聯(lián)網(wǎng)+時(shí)代電商助農(nóng)模式的優(yōu)化策略:以S縣為例9000字(論文)
- 《醫(yī)療器械監(jiān)督管理?xiàng)l例》知識(shí)競(jìng)賽考試題庫300題(含答案)
- DL-T5024-2020電力工程地基處理技術(shù)規(guī)程
- 2024年上海市普通高中學(xué)業(yè)水平等級(jí)性考試化學(xué)試卷(含答案)
- 樹立正確就業(yè)觀課件
- 《在馬克思墓前的講話》課件+2023-2024學(xué)年統(tǒng)編版高中語文必修下冊(cè)
- 第24屆世界奧林匹克數(shù)學(xué)競(jìng)賽WMO省級(jí)測(cè)評(píng)五年級(jí)試卷【含答案】
評(píng)論
0/150
提交評(píng)論