編譯原理課設(shè)詞法分析報(bào)告、自下而上語(yǔ)法分析報(bào)告程序、生成中間代碼_第1頁(yè)
編譯原理課設(shè)詞法分析報(bào)告、自下而上語(yǔ)法分析報(bào)告程序、生成中間代碼_第2頁(yè)
編譯原理課設(shè)詞法分析報(bào)告、自下而上語(yǔ)法分析報(bào)告程序、生成中間代碼_第3頁(yè)
編譯原理課設(shè)詞法分析報(bào)告、自下而上語(yǔ)法分析報(bào)告程序、生成中間代碼_第4頁(yè)
編譯原理課設(shè)詞法分析報(bào)告、自下而上語(yǔ)法分析報(bào)告程序、生成中間代碼_第5頁(yè)
已閱讀5頁(yè),還剩41頁(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)介

1、實(shí)用標(biāo)準(zhǔn)文案大全課程設(shè)計(jì)任務(wù)書(shū)課題名稱(chēng)編譯原理課程設(shè)計(jì)完成時(shí)間指導(dǎo)教師職稱(chēng)學(xué)生姓名班級(jí)總體設(shè)計(jì)要求總體設(shè)計(jì)要求:課程設(shè)計(jì)內(nèi)容共給定1 個(gè)題目,每個(gè)學(xué)生按照課程設(shè)計(jì)要求,在規(guī)定的兩周時(shí)間內(nèi)獨(dú)立完成。題目:編譯程序構(gòu)造涉及內(nèi)容:詞法分析、語(yǔ)法分析、語(yǔ)義分析生成中間代碼工作內(nèi)容及時(shí)間進(jìn)度安排第一周、周:設(shè)計(jì)動(dòng)員,布置課程設(shè)計(jì)任務(wù),查閱資料,制定方案,進(jìn)行程序方案設(shè)計(jì)。第一周、周2- 周 5:編寫(xiě)和調(diào)試程序第二周、周1- 周 3:編寫(xiě)和調(diào)試程序第二周、周4:整理,撰寫(xiě)設(shè)計(jì)報(bào)告。第二周、周5:驗(yàn)收,提交設(shè)計(jì)報(bào)告,評(píng)定成績(jī)。畢業(yè)設(shè)計(jì)成果1、課程設(shè)計(jì)報(bào)告書(shū)一份2、源程序清單一份3、成果使用說(shuō)明書(shū)一份實(shí)用標(biāo)準(zhǔn)

2、文案大全內(nèi)容摘要 第 1 章 緒論1.1 、課程設(shè)計(jì)目的1.2 、課程設(shè)計(jì)意義1.3 、課程設(shè)計(jì)要求1.4 、課程設(shè)計(jì)內(nèi)容1.4.1 、題目編譯程序構(gòu)造1.4.2 、內(nèi)容涉及詞法分析、自下而上語(yǔ)法分析程序的實(shí)現(xiàn):slr (1)分析器的實(shí)現(xiàn)以及生成中間代碼。1.4.3 、具體要求根據(jù) lr分析算法構(gòu)造 slr (1)分析程序,并完成語(yǔ)法分析動(dòng)作(當(dāng)需要一個(gè)單詞時(shí),調(diào)用詞法分析程序獲?。?,同時(shí)完成語(yǔ)義分析生成四元式輸出。要求程序具有通用性,改變文法時(shí)只需改變程序的數(shù)據(jù)初值,無(wú)需改變程序主體;要求完成一條說(shuō)明語(yǔ)句、 一條算數(shù)表達(dá)式和賦值語(yǔ)句的翻譯, 生成中間代碼。變量說(shuō)明語(yǔ)句的文法及相應(yīng)的語(yǔ)義子程

3、序:.att表示數(shù)據(jù)類(lèi)型屬性, fill函數(shù)表示將單詞 id 及其類(lèi)別屬性填寫(xiě)符號(hào)表。實(shí)用標(biāo)準(zhǔn)文案大全(0)sd; acc (1)dint id fill(id ,int ) ;d.att=int; (2)dfloat id fill(id,float); d.att=float; (3)dd(1),id fill(id,d(1).att);d.att=d(1).att; 算數(shù)表達(dá)式和賦值語(yǔ)句的文法及相應(yīng)的語(yǔ)義子程序。(1)aid=e; p=lookup(); emit(e.palce, , p ); (2)ee(1)+t e.palce=newtemp(); emit(+ ,e

4、(1).palce,t.palce ,e.palce) (3)et e.palce=t.palce; (4)tt(1)*f t.palce=newtemp(); emit(+ ,t(1).palce,f.palce ,t.palce) (5)tf t.palce=f.palce; (6)f(e) f.palce=e.palce; (7)fid p=lookup(); f.palce=p; (8)fnum p=lookup(num.value) f.palce=p; 構(gòu)造其用于 slr(1)分析的識(shí)別活前綴的dfa以及 action表和 goto 表。然后編程實(shí)現(xiàn)。 (關(guān)于詞法分析

5、部分只需識(shí)別出與此文法相關(guān)的單詞即可(+, *, ( , ) ,id ,=) ) 。1.4.4 、程序設(shè)計(jì)提示(1)分析棧設(shè)計(jì)時(shí)可以用一個(gè)棧完成,也可以設(shè)計(jì)三個(gè)棧:一個(gè)符號(hào)棧,一個(gè)狀態(tài)棧,一個(gè)語(yǔ)義棧,則歸約時(shí),則需要在符號(hào)棧中退掉n 個(gè)符號(hào),在狀態(tài)棧中退掉 n 個(gè)符號(hào)(n 為產(chǎn)生式符號(hào)個(gè)數(shù)),語(yǔ)義棧中退掉 n 個(gè)符號(hào)對(duì)應(yīng)的語(yǔ)義;(2)終結(jié)符表和非終結(jié)符表的組織和預(yù)測(cè)分析程序中相同(將符號(hào)對(duì)應(yīng)到一個(gè)數(shù)字,表示在分析表中對(duì)應(yīng)的下標(biāo)) 。(3)action表中的錯(cuò)誤處理:簡(jiǎn)化的錯(cuò)誤處理:當(dāng)查找action表出現(xiàn)空白時(shí),則當(dāng)前單詞無(wú)法移進(jìn)和規(guī)約,可簡(jiǎn)單的認(rèn)為當(dāng)前單詞為多余的單詞,則拋棄當(dāng)前單詞,讀下一

6、單詞繼續(xù)分析。1.4.5 、測(cè)試數(shù)據(jù)源文件中數(shù)據(jù):int area,r ; r=1;area=r*r+r ;程序要求輸出二元式序列、符號(hào)表、語(yǔ)法分析過(guò)程、四元式序列。實(shí)用標(biāo)準(zhǔn)文案大全1.4.6 、程序擴(kuò)展要求第 2 章程序總體設(shè)計(jì)實(shí)用標(biāo)準(zhǔn)文案大全第 3 章 程序詳細(xì)設(shè)計(jì)與實(shí)現(xiàn)3.1 、詞法分析首先定義結(jié)構(gòu)體typedef struct /狀態(tài)棧 int datamax; int top; seqstack1; typedef struct /符號(hào)棧 string datamax; int top; seqstack2; struct reserveedword/保留字表結(jié)構(gòu) string wo

7、rd; char value; reserveedword1maxsize; struct identifer/標(biāo)識(shí)符表結(jié)構(gòu) char identiname15; char identitype15; int address; identifer1maxsize; struct constant/常量表結(jié)構(gòu) string constantname; string value; 實(shí)用標(biāo)準(zhǔn)文案大全 int constantaddress; constant1maxsize; 詞法分析主要函數(shù)結(jié)構(gòu): void initscanner() /該函數(shù)用于用 c語(yǔ)言當(dāng)中常見(jiàn)的關(guān)鍵字初始化保留表 void

8、isalpha(char s) /用于判斷讀入的字符是不是字母 void isnumber(char s) /用于判斷讀入的字符是不是數(shù)字 void isother(char s) /判斷除數(shù)字與字母之外的其他字符 void lexscan() /用于循環(huán)從程序中讀入字符并判斷應(yīng)調(diào)用那個(gè)判斷函數(shù)字符 void output(int i,int j,char ss15) /輸出二元式本模塊程序的偽代碼如下:打開(kāi)文件infile.open(input.txt,ios:in); if(!infile) cerr讀取的文件打開(kāi)失敗 !=a)&(ch=a)&(ch=0)&(ch=

9、9) isnumber(ch) output ; else isother(ch) output ; 關(guān)閉文件infile.close(); 詞法分析器中從源文件讀出一個(gè)單詞,判斷其類(lèi)型是關(guān)鍵字、標(biāo)識(shí)符還是普通符號(hào),根據(jù)其類(lèi)型為結(jié)構(gòu)體各項(xiàng)賦值,并將其傳給語(yǔ)法分析函數(shù)。實(shí)用標(biāo)準(zhǔn)文案大全3.2 、語(yǔ)法分析由于說(shuō)明語(yǔ)句與算術(shù)表達(dá)式和賦值語(yǔ)句所使用的是不同的文法,所以兩者的action 表和 goto 表也不一樣, 本次課設(shè)采用二維數(shù)組存放action 表和 goto 表信息, 其中移進(jìn)用大于 0的數(shù)表示,歸約用小于 0的數(shù)表示,成功用 100表示(acc),其他處用 0 表示,查表時(shí)遇到相應(yīng)的數(shù)進(jìn)行

10、相應(yīng)的操作。其中,歸約部分需要根據(jù)其產(chǎn)生式的信息進(jìn)行,所以程序中有如下定義:string v18=int,float,;,id,#,d,s; /存放說(shuō)明文法當(dāng)中的字符string v213=#,id,=,num,;,+,*,(,),f,a,e,t;/存放算本文法當(dāng)中的字符根據(jù)狀態(tài)轉(zhuǎn)換圖 (dfa)構(gòu)造 slr(1)分析表:其中說(shuō)明文法和算術(shù)文法分別構(gòu)造, 同時(shí)在每個(gè)表當(dāng)中既有action表 又有g(shù)oto 表int analysis_table1108=3,4,0,0,0,0,2,1, 0,0,0,0,0,100,0,0, 0,0,5,6,0,0,0,0, 0,0,0,0,7,0,0,0, 0,

11、0,0,0,8,0,0,0, 0,0,0,0,0,-1,0,0, 0,0,0,0,9,0,0,0, 0,0,-2,-2,0,0,0,0, 0,0,-3,-3,0,0,0,0, 0,0,-4,-4,0,0,0,0; int analysis_table21713=0,2,0,0,0,0,0,0,0,0,1,0,0, 100,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,3,0,0,0,0,0,0,0,0,0,0, 0,9,0,8,0,0,0,7,0,6,0,4,5, 0,0,0,0,10,11,0,0,0,0,0,0,0, 0,0,0,0,-3,-3,12,0,-3,0,0,0,0,

12、 0,0,0,0,-5,-5,-5,0,-5,0,0,0,0, 0,9,0,8,0,0,0,7,0,6,0,13,5, 0,0,0,0,-8,-8,-8,0,-8,0,0,0,0, 0,0,0,0,-7,-7,-7,0,-7,0,0,0,0, -1,0,0,0,0,0,0,0,0,0,0,0,0, 0,9,0,8,0,0,0,7,0,6,0,0,14, 0,9,0,8,0,0,0,7,0,15,0,0,0, 0,0,0,0,0,11,0,0,16,0,0,0,0, 0,0,0,0,-2,-2,12,0,-2,0,0,0,0, 0,0,0,0,-4,-4,-4,0,-4,0,0,0,0, 0,0

13、,0,0,-6,-6,-6,0,-6,0,0,0,0; 語(yǔ)法分析當(dāng)中各個(gè)函數(shù)說(shuō)明及偽代碼:void action1(int i,string s) /通過(guò)詞法分析傳過(guò)來(lái)的值判斷移實(shí)用標(biāo)準(zhǔn)文案大全進(jìn)動(dòng)作三個(gè)棧 (狀態(tài)棧,符號(hào)棧 , 語(yǔ)義棧 ) 應(yīng)該讀入哪些值。void action2(int i,string s) /同 action1只是表示算術(shù)文法int address(string m,int i,string x) /獲得在分析表中的列下標(biāo)void goto1(int i,string s) /通過(guò)判斷棧中的元素,來(lái)判斷用那個(gè)產(chǎn)生式來(lái)進(jìn)行規(guī)約void goto2(int i,string

14、 s) /同 goto1 void slr1() /對(duì)說(shuō)明文法進(jìn)行語(yǔ)法分析void slr1() /對(duì)算術(shù)文法進(jìn)行語(yǔ)法分析偽代碼如下:先判斷是說(shuō)明文法還是算術(shù)文法 if(說(shuō)明文法 ) slr1() push_seq1(s1,0); push_seq2(s2,#); push_seq2(s3,_); while(1) j=address(v1,8,get1); top_seq1(s1,top); j=analysis_table1topj; if(jd;歸約 else if(j=-2) 用 d-int id歸約 else if(j=-3) 用 d-float id歸約 else if(j=-4)

15、 用 d-d,id 歸約 else if(j0) action1(top,get1); else slr2() push_seq1(s1,0); push_seq2(s2,#); push_seq2(s3,_); 實(shí)用標(biāo)準(zhǔn)文案大全 while(1) j=address(v2,13,get1); j=analysis_table2topj; if(j0) action2(top,get1); else if(jid=e; 歸約 else if(j=-2) 用 e-e+t歸約 else if(j=-3) 用 e-t 歸約 else if(j=-4) 用 t-t*f 歸約); else if(j=-

16、5) 用 t-f 歸約 else if(j=-6) 用 f-(e) 歸約 else if(j=-7) 用 f-id 歸約 else if(j=-8) 用 f-num歸約 3.3 、語(yǔ)義分析一個(gè)程序經(jīng)過(guò)詞法分析,語(yǔ)法分析之后, 表明該院程序在書(shū)寫(xiě)上是正確的,但是未對(duì)程序的內(nèi)部邏輯語(yǔ)義進(jìn)行分析,接下來(lái)是進(jìn)行語(yǔ)義分析。語(yǔ)義分析當(dāng)中各個(gè)函數(shù)說(shuō)明:void print(string s) /打印四元式str1,string str2,string str3,string str4) /產(chǎn)生四元式string newtemp() /產(chǎn)生一個(gè)新的臨時(shí)變量實(shí)用標(biāo)準(zhǔn)文案大全3.4 、程序?qū)崿F(xiàn)結(jié)果圖圖 3-4 語(yǔ)

17、義分析結(jié)果圖實(shí)用標(biāo)準(zhǔn)文案大全圖 3-5 二元式圖 3-6 符號(hào)表圖 3-7 四元式附錄#include #include using namespace std; #define maxsize 50 實(shí)用標(biāo)準(zhǔn)文案大全#define max 30 ifstream infile; char ch; int m,n,kk=0,addr=0,t=1; string get1; string inmaxsize; string insmaxsize; string s4; int count=0; string v18=int,float,;,id,#,d,s; string v213=#,id,=

18、,num,;,+,*,(,),f,a,e,t; string e=,e1=,t=,t1=,f=; int analysis_table1108=3,4,0,0,0,0,2,1, 0,0,0,0,0,100,0,0, 0,0,5,6,0,0,0,0, 0,0,0,0,7,0,0,0, 0,0,0,0,8,0,0,0, 0,0,0,0,0,-1,0,0, 0,0,0,0,9,0,0,0, 0,0,-2,-2,0,0,0,0, 0,0,-3,-3,0,0,0,0, 0,0,-4,-4,0,0,0,0; int analysis_table21713=0,2,0,0,0,0,0,0,0,0,1,0,0

19、, 100,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,3,0,0,0,0,0,0,0,0,0,0, 實(shí)用標(biāo)準(zhǔn)文案大全 0,9,0,8,0,0,0,7,0,6,0,4,5, 0,0,0,0,10,11,0,0,0,0,0,0,0, 0,0,0,0,-3,-3,12,0,-3,0,0,0,0, 0,0,0,0,-5,-5,-5,0,-5,0,0,0,0, 0,9,0,8,0,0,0,7,0,6,0,13,5, 0,0,0,0,-8,-8,-8,0,-8,0,0,0,0, 0,0,0,0,-7,-7,-7,0,-7,0,0,0,0, -1,0,0,0,0,0,0,0,0,0,0,0,

20、0, 0,9,0,8,0,0,0,7,0,6,0,0,14, 0,9,0,8,0,0,0,7,0,15,0,0,0, 0,0,0,0,0,11,0,0,16,0,0,0,0, 0,0,0,0,-2,-2,12,0,-2,0,0,0,0, 0,0,0,0,-4,-4,-4,0,-4,0,0,0,0, 0,0,0,0,-6,-6,-6,0,-6,0,0,0,0; typedef struct /狀態(tài)棧 int datamax; int top; seqstack1; typedef struct /符號(hào)棧 string datamax; int top; seqstack2; struct res

21、erveedword/保留字表結(jié)構(gòu)實(shí)用標(biāo)準(zhǔn)文案大全 string word; char value; reserveedword1maxsize; struct identifer/標(biāo)識(shí)符表結(jié)構(gòu) char identiname15; char identitype15; int address; identifer1maxsize; struct constant/常量表結(jié)構(gòu) string constantname; string value; int constantaddress; constant1maxsize; void initscanner(); void lexscan();

22、void isalpha(char); void isnumber(char); void isother(char); void output(int ,int ,char *); void scanner(); void change(char c,string str) 實(shí)用標(biāo)準(zhǔn)文案大全 int len=str.length(); for(int num=0;numlen;num+) cnum=strnum; clen=0; seqstack1 *init_seqstack1() seqstack1 *s; s=new seqstack1; if(!s) cout 空間不足! top=-

23、1; return s; int empty_seq1(seqstack1 *s) if(s-top=-1) return 1; else 實(shí)用標(biāo)準(zhǔn)文案大全return 0; int push_seq1(seqstack1 *s,int x) if(s-top=max-1) return 0; else s-top+; s-datas-top=x; return 1; int pop_seq1(seqstack1 *s,int *x) if(empty_seq1(s) return 0; else *x=s-datas-top; s-top-; return 1; void top_seq1(

24、seqstack1 *s,int &e) 實(shí)用標(biāo)準(zhǔn)文案大全 if(empty_seq1(s) coutdatas-top; seqstack2 *init_seqstack2() seqstack2 *s; s=new seqstack2; if(!s) cout 空間不足! top=-1; return s; int empty_seq2(seqstack2 *s) if(s-top=-1) return 1; 實(shí)用標(biāo)準(zhǔn)文案大全else return 0; int push_seq2(seqstack2 *s,string x) if(s-top=max-1) return 0; e

25、lse s-top+; s-datas-top=x; return 1; int pop_seq2(seqstack2 *s,string *x) if(empty_seq2(s) return 0; else *x=s-datas-top; s-top-; return 1; 實(shí)用標(biāo)準(zhǔn)文案大全void out_seq1(seqstack1 *s) for(int i=0;itop;i+) printf(%d,s-datai); void out_seq2(seqstack2 *s) char ch15; for(int i=0;itop;i+) change(ch,s-datai); pri

26、ntf(%s,ch); seqstack1 *s1=init_seqstack1(); seqstack2 *s2=init_seqstack2(); seqstack2 *s3=init_seqstack2(); void pop(int n) int m; string s; for(int i=0;in;i+) pop_seq1(s1,&m); pop_seq2(s2,&s); 實(shí)用標(biāo)準(zhǔn)文案大全 pop_seq2(s3,&s); int screamp(char a15,string b) int i=0,j=0; while(ai!=0&bi!=0) i

27、f(ai=bi) i+; j+; else return 0; if(ai=bi) return 1; else return 0; int screamp1(string a,string b) int i=0,j=0; while(ai!=0&bi!=0) 實(shí)用標(biāo)準(zhǔn)文案大全 if(ai=bi) i+; j+; else return 0; if(ai=bi) return 1; else return 0; void clear(seqstack1 *s1,seqstack2 *s2,seqstack2 *s3) int m; string s; while(!empty_seq1

28、(s1) pop_seq1(s1,&m); pop_seq2(s2,&s); pop_seq2(s3,&s); 實(shí)用標(biāo)準(zhǔn)文案大全void char_table() char str115,str215; coutn生成的標(biāo)識(shí)符表為: ; coutntnamettypetvaluetaddress; for(int i=0;im;i+) printf(n%dt%st%s,i,identifer1i.identiname,identifer1i.identitype); coutn生成的常數(shù)表為: ; coutntvaluettypetnametaddress; for(i

29、nt j=0;jn;j+) change(str1,constant1j.constantname); change(str2,constant1j.value); printf(n%dt%st%s,j,str1,str2); int judge(string m,int i,string x) for(int j=0;ji;j+) if(screamp1(x,mj) return 1; return 0; int address(string m,int i,string x) 實(shí)用標(biāo)準(zhǔn)文案大全 for(int j=0;ji;j+) if(screamp1(x,mj) return j; v

30、oid print(string s) coutn產(chǎn)生的四元式為 endl; char chmax; for(int i=0;icount;i+) change(ch,si); printf(%s,ch); coutendl; coutendl; void emit(string str1,string str2,string str3,string str4) scount+=(;scount+=str1;scount+=,; scount+=str2;scount+=,;scount+=str3; scount+=,;scount+=str4;scount+=); count+; stri

31、ng newtemp() 實(shí)用標(biāo)準(zhǔn)文案大全 char s2; s0=t; s1=t; s2=0; t+; return s; void action1(int i,string s) int pos,j; j=address(v1,8,s); pos=analysis_table1ij; char str15; change(str,s); out_seq1(s1); tt); if(pos=100) cout 分析成功! endl; cout*endl; else printf(action%d,%s=s%d狀態(tài)%d入棧n,i,str,pos,pos); 實(shí)用標(biāo)準(zhǔn)文案大全push_seq1(

32、s1,pos); push_seq2(s2,s); push_seq2(s3,_); get1=inaddr; addr+; void goto1(int i,string s) int pos,j; if(judge(v1,8,s) j=address(v1,8,s); pos=analysis_table1ij; char str15; change(str,s); printf(goto%d,%s=%dn,i,str,pos); push_seq1(s1,pos); push_seq2(s2,s); void slr1() clear(s1,s2,s3); char str115; pu

33、sh_seq1(s1,0); push_seq2(s2,#); push_seq2(s3,_); 實(shí)用標(biāo)準(zhǔn)文案大全 get1=inaddr; addr+; int top,j; while(1) j=address(v1,8,get1); top_seq1(s1,top); if(top=100) addr-; return; j=analysis_table1topj; if(jd;歸約); pop(2); top_seq1(s1,top); goto1(top,s); push_seq2(s3,_); else if(j=-2) 實(shí)用標(biāo)準(zhǔn)文案大全 out_seq1(s1);printf(t

34、t);out_seq2(s2);printf(tt);out_seq2(s3);printf(tt用 d-int id歸約); change(str1,int); for(int k=0;kfloat id歸約); change(str1,float); for(int k=0;kd,id 歸約); for(int k=0;k0) action1(top,get1); void action2(int i,string s) int pos,j; if(judge(v2,13,s) j=address(v2,13,s); pos=analysis_table2ij; char str15; c

35、hange(str,s); 實(shí)用標(biāo)準(zhǔn)文案大全out_seq1(s1);printf(tt);out_seq2(s2);printf(tt);out_seq2(s3);printf(tt); if(pos=100) cout 分析成功! endl; cout*0) action2(top,get1); else if(jid=e; 歸約); pop(4); top_seq1(s1,top); goto2(top,a); for(int i=0;ie+t歸約); pop(3); 實(shí)用標(biāo)準(zhǔn)文案大全 top_seq1(s1,top); goto2(top,e); e1=e; e=newtemp();

36、emit(+,e1,t,e); push_seq2(s3,e); else if(j=-3) out_seq1(s1);printf(tt);out_seq2(s2);printf(tt);out_seq2(s3);printf(tt用 e-t歸約); pop(1); top_seq1(s1,top); goto2(top,e); e=t; push_seq2(s3,t); else if(j=-4) out_seq1(s1);printf(tt);out_seq2(s2);printf(tt);out_seq2(s3);printf(tt用 t-t*f 歸約); pop(3); top_se

37、q1(s1,top); goto2(top,t); t1=t; 實(shí)用標(biāo)準(zhǔn)文案大全 t=newtemp(); emit(*,t1,f,t); push_seq2(s3,t); else if(j=-5) out_seq1(s1);printf(tt);out_seq2(s2);printf(tt);out_seq2(s3);printf(tt用 t-f 歸約); pop(1); top_seq1(s1,top); goto2(top,t); t=f; push_seq2(s3,f); else if(j=-6) out_seq1(s1);printf(tt);out_seq2(s2);print

38、f(tt);out_seq2(s3);printf(tt用 f-(e) 歸約); pop(3); top_seq1(s1,top); goto2(top,f); f=e; push_seq2(s3,e); else if(j=-7) 實(shí)用標(biāo)準(zhǔn)文案大全 pnum=insaddr-2;num+; out_seq1(s1);printf(tt);out_seq2(s2);printf(tt);out_seq2(s3);printf(tt用 f-id 歸約); pop(1); top_seq1(s1,top); goto2(top,f); for(int i=0;inum歸約); pop(1); to

39、p_seq1(s1,top); goto2(top,f); for(int i=0;in;i+) 實(shí)用標(biāo)準(zhǔn)文案大全 if(screamp1(constant1i.constantname,pnum-1) f=constant1i.constantname; push_seq2(s3,f); void printslr1() coutn*語(yǔ)法語(yǔ)義分析情況*endl; cout狀態(tài)棧 tt符號(hào)棧 tt語(yǔ)義棧 tt動(dòng)作說(shuō)明 endl; void initscanner() reserveedword11.word=int; reserveedword12.word=char; reserveedwo

40、rd13.word=float; reserveedword14.word=void; reserveedword15.word=const; reserveedword16.word=for; reserveedword17.word=if; reserveedword18.word=else; 實(shí)用標(biāo)準(zhǔn)文案大全 reserveedword19.word=then; reserveedword110.word=while; reserveedword111.word=switch; reserveedword112.word=break; reserveedword113.word=begi

41、n; reserveedword114.word=end; void scanner() cout 生成的二元式為: endl; while(ch!=#) lexscan(); cout=a)&(ch=a)&(ch=0)&(ch=a)&(ch=a)&(ch=0)&(ch=9) infile.get(ch); keepi=ch; i+; keepi-1=0; for(int k=1;k=14;k+) if(screamp(keep,reserveedword1k.word) output(1,i-1,keep); inaddr=keep;insad

42、dr=keep; addr+; return; 實(shí)用標(biāo)準(zhǔn)文案大全 if(m=0) for(k=0;ki;k+) identifer1m.identinamek=keepk; output(2,0,keep); inaddr=id;insaddr=keep; addr+; m+; else for(int j=0;jm;j+) if(screamp(keep,identifer1j.identiname) output(2,j,keep); inaddr=id;insaddr=keep; addr+; infile.seekg(-1,ios:cur); return; for(k=0;k=0)&(ch=9) infile.get(ch); integeri=ch; i+; integeri-1=0; if(n=0) constant1n.constan

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論