編譯原理課程設(shè)計--LR(0)分析器自動構(gòu)造程序的實現(xiàn)_第1頁
編譯原理課程設(shè)計--LR(0)分析器自動構(gòu)造程序的實現(xiàn)_第2頁
編譯原理課程設(shè)計--LR(0)分析器自動構(gòu)造程序的實現(xiàn)_第3頁
編譯原理課程設(shè)計--LR(0)分析器自動構(gòu)造程序的實現(xiàn)_第4頁
編譯原理課程設(shè)計--LR(0)分析器自動構(gòu)造程序的實現(xiàn)_第5頁
已閱讀5頁,還剩29頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、 衡陽師范學(xué)院工科課程設(shè)計 -編譯原理課程設(shè)計報告 題 目: LR(0)分析器自動構(gòu)造程序的實現(xiàn) 學(xué) 號: 13190207 姓 名: 譚金星 班 級: 1302 指導(dǎo)教師: 陳瓊老師 日 期: 2016年 6月20日 目 錄第一章 概 述4第二章 設(shè)計的基本原理52.1 識別文法的LR(0)項目集規(guī)范族的構(gòu)造52.2 LR(0)分析表的構(gòu)造52.3 LR(0)分析器總控程序構(gòu)造6第三章 程序設(shè)計73.1 程序總體構(gòu)架73.2 程序存儲結(jié)構(gòu)83.2.1 符號表存儲結(jié)構(gòu)83.2.2 產(chǎn)生式表存儲結(jié)構(gòu)83.2.3 項目集規(guī)范族表存儲結(jié)構(gòu)93.2.4 LR(0)分析表存儲結(jié)構(gòu)93.3 程序

2、算法103.3.1 項目集規(guī)范族的構(gòu)造103.3.2 LR(0)分析表構(gòu)造11第四章 程序測試124.1 符號表測試124.2 產(chǎn)生式表測試134.3 項目集規(guī)范族表測試134.4 LR(0)分析表測試144.5 LR(0)分析器測試14第五章 總結(jié)和展望15附錄16參考文獻17一 概 述本課程設(shè)計完成了以下內(nèi)容:1. 實現(xiàn)了對任意給定的文法,識別文法活前綴的、的狀態(tài)轉(zhuǎn)化矩陣及項目集規(guī)范族的構(gòu)造;2. 判斷該文法是否為文法,實現(xiàn)了分析表的構(gòu)造,并輸出到指定文件中;3. 實現(xiàn)了分析器總控程序,對輸入的表達式進行文法分析。4.在VC+6.0程序上運行二 設(shè)計的基本原理本課程設(shè)計的核心算法Error

3、! Reference source not found.主要有三點:1. 識別文法活前綴的、的狀態(tài)轉(zhuǎn)化矩陣及項目集規(guī)范族的構(gòu)造;2. 分析表的構(gòu)造;3. 分析器總控程序的構(gòu)造。2.1 識別文法的LR(0)項目集規(guī)范族的構(gòu)造采用(閉包)的構(gòu)造一個文法的項目規(guī)范簇。假定是文法的任一項目集,定義和構(gòu)造的閉包的算法:(1)的任何項目都屬于;(2)若屬于,那么,對任何關(guān)于的產(chǎn)生式,項目也屬于;(3)重復(fù)執(zhí)行上述兩個步驟直至不再增大。其中初始 ,為對文法進行拓廣構(gòu)造而引進的不出現(xiàn)在中的非終結(jié)符。定義狀態(tài)轉(zhuǎn)換函數(shù),的第一個變元是一個項目集,第二個變元是一個文法符號。函數(shù)值定義為。其中 = 任何形如的項目|

4、 屬于2.2 LR(0)分析表的構(gòu)造 假定。令每個項目集的下標作為分析器的狀態(tài)。特別是,令那個包含項目的集合的下標為分析器的初態(tài)。分析表的子表和子表可按如下方法構(gòu)造: (1)若項目屬于且,為終結(jié)符,則置為“把移近?!?,簡記為“”。 (2)若項目屬于,那么對于任何終結(jié)符(或結(jié)束符#),置為“用產(chǎn)生式進行規(guī)約”,簡記為“”(假定產(chǎn)生式是文法的第j個產(chǎn)生式) (3)若項目屬于,則置為“接受”,簡記為“acc”。 (4)若,則置。 (5)分析表中凡不能用規(guī)則14填入信息的空白處均置上“報錯標志”。如果分析表中任何一項被重復(fù)填入,則說明分析表的入口不是唯一的,項目集中存在沖突項目,該文法不是文法。2.3

5、 LR(0)分析器總控程序構(gòu)造分析表包括量部分,“動作”表和“狀態(tài)轉(zhuǎn)換”表。規(guī)定了當狀態(tài)面臨輸入符號時應(yīng)采取什么動作。規(guī)定了狀態(tài)面對文法符號時下一狀態(tài)是什么。每一項所規(guī)定的動作不外乎是下述四種可能之一。(1)移進 把的下一狀態(tài)和輸入符號推進棧,下一輸入符號變成現(xiàn)行輸入符號。(2)歸約 指用某一產(chǎn)生式進行規(guī)約。假若的長度為,規(guī)約的動作是,去除棧頂?shù)膫€項,使狀態(tài)變成棧頂狀態(tài),然后把的下一狀態(tài)推進棧。規(guī)約動作不改變現(xiàn)行輸入符號。規(guī)約動作不改變現(xiàn)行輸入符號。(3)接受 宣布分析成功,停止分析器工作(4)報錯 發(fā)現(xiàn)源程序含有錯誤,調(diào)用出錯處理程序。三 程序設(shè)計3.1 程序總體構(gòu)架 本課程設(shè)計開發(fā)的程序主

6、要由4張表組成,分別為:符號表、產(chǎn)生式表、表和項目集規(guī)范簇表。同時,項目集規(guī)范簇表包含一個分析棧作為分析器總控程序。產(chǎn)生式表包含符號表作為子表,項目集規(guī)范簇表包含產(chǎn)生式表、表作為子表。 程序工作流程:1. 讀取含有文法規(guī)則的文件,為該文法中的每一個不同的文法符號(終結(jié)符和非終結(jié)符分配一個編號),記錄文法符號的屬性(終結(jié)符/非終結(jié)符),存儲于一張符號表中;2. 再次讀取文件,將產(chǎn)生式存儲于產(chǎn)生式表中;3. 根據(jù)產(chǎn)生式構(gòu)建項目集規(guī)范族,存儲于表中;4. 根據(jù)構(gòu)建的項目集規(guī)范族構(gòu)建分析表,填寫分析表同時檢查該文法是否為文法;5. 對于輸入的表達式,分析器根據(jù)構(gòu)建的分析表進行文法分析,給出分析結(jié)果。3

7、.2 程序存儲結(jié)構(gòu)3.2.1 符號表存儲結(jié)構(gòu)動態(tài)數(shù)組下標,同時作為符號的編號標識符是否為非終結(jié)符3.2.2 產(chǎn)生式表存儲結(jié)構(gòu)產(chǎn)生式標號非終結(jié)符標號 (與中的一致)指示當前非終結(jié)符的產(chǎn)生式當前非終結(jié)符產(chǎn)生式的長度,用于幫助區(qū)分一個產(chǎn)生式的不同項目,即項目個數(shù)等于指示下一個非終結(jié)符一個產(chǎn)生式中的標識符名(與中的一致)一個產(chǎn)生式中的下一個標識符3.2.3 項目集規(guī)范族表存儲結(jié)構(gòu) 1)定義二元組 : :產(chǎn)生式標號,與 中的一致 :一個產(chǎn)生式的第個項目,可由 中的幫助確定 如:產(chǎn)生式 : , 2)結(jié)構(gòu):當前狀態(tài)編號 指示下一狀態(tài) 指示閉包中的項目 閉包中的項目名當前項目的產(chǎn)生的新狀態(tài)的編號,即狀態(tài)轉(zhuǎn)移的

8、目的地狀態(tài)編號閉包中的下一個項目待構(gòu)造的項目的閉包的待構(gòu)造的項目的閉包待構(gòu)造狀態(tài)的待構(gòu)造狀態(tài)的項目3.2.4 LR(0)分析表存儲結(jié)構(gòu)指示表頭的孩子結(jié)點指示表頭的后繼結(jié)點指示該表項的操作指示該表項的操作數(shù)指示該表項是否被填寫過,用于判斷文法是否為文法3.3 程序算法3.3.1 項目集規(guī)范族的構(gòu)造1. (初始化)將初始條件作為該狀態(tài)頭結(jié)點的第一個孩子結(jié)點,并構(gòu)造該孩子結(jié)點的閉包,連接其后,指向第一個狀態(tài)頭結(jié)點,指向第一個狀態(tài)頭結(jié)點的第一個孩子結(jié)點;2. 查看,若為空,停止;若不為空,轉(zhuǎn)3;3. 查看,若為空,轉(zhuǎn)4;若不為空,構(gòu)造的,檢查該狀態(tài)與之前構(gòu)造的狀態(tài)有無重復(fù),若重復(fù),則停止構(gòu)造,的填寫重

9、復(fù)的已存在的狀態(tài)的編號;若不重復(fù),則作為一個新狀態(tài),連接于,并構(gòu)造其閉包連接其后,指向。轉(zhuǎn)2;4. 指向下一狀態(tài),若下一狀態(tài)為空,則結(jié)束,否則,指向下一狀態(tài)頭結(jié)點的第一個孩子結(jié)點,轉(zhuǎn)3。具體細節(jié):設(shè)所指項目為,因為要對其構(gòu)造閉包,該項目一定不是終態(tài),所以區(qū)分項目的圓點符號位于第個標識符的左側(cè)?,F(xiàn)在構(gòu)造的閉包,分兩個步驟實現(xiàn):1. 構(gòu)造的 : 查看中編號為的產(chǎn)生式,取得該產(chǎn)生式的長度屬性1) 若,則停止構(gòu)造當前閉包(已是終態(tài)),此時 的項填;2) 否則,將作為該閉包的第一個項目,此時 的項填該新狀態(tài)的狀態(tài)編號。2. 構(gòu)造該孩子結(jié)點的閉包 :查看中編號為的產(chǎn)生式的第個標識符,取得該標識符的,查看中

10、該標識符的類別屬性3) 若為1(非終結(jié)符),則查看非終結(jié)符的所有產(chǎn)生 式,記這些產(chǎn)生式的編號為,將所有的加入閉包4) 否則,結(jié)束3. 檢查該狀態(tài)與之前構(gòu)造的狀態(tài)有無重復(fù) :斷言:任意兩個狀態(tài),只要不同,則即為不同狀態(tài)。3.3.2 LR(0)分析表構(gòu)造對于編號為的狀態(tài),現(xiàn)依據(jù)其項目填寫分析表:1. 如果該項目形如,查看該項目的屬性,1)若為終結(jié)符,則在表的狀態(tài)對應(yīng)行,對應(yīng)列,填寫,表示將把 移進棧2)若為非終結(jié)符,則在表的狀態(tài)對應(yīng)行,對應(yīng)列,填寫,表示狀態(tài)轉(zhuǎn)移至狀態(tài)2. 如果該項目形如1)若為起始符號,則置在表的狀態(tài)對應(yīng)行,對應(yīng)列,填寫,表示接受。2)否則,對任何終結(jié)符或結(jié)束符,則在表的狀態(tài)對應(yīng)

11、行,對應(yīng)列,填寫,表示用產(chǎn)生式進行規(guī)約。四 程序測試以文法G為例:程序模塊輸入:含上述文法的文件,下面展示個模塊的輸出結(jié)果4.1 符號表測試圖6 符號表測試輸出結(jié)果為 <符號編號,符號,是否為終結(jié)符>與預(yù)期結(jié)果相同圖7 產(chǎn)生式表測試4.2 產(chǎn)生式表測試輸出結(jié)果與讀入的文件中的產(chǎn)生式相同,且產(chǎn)生式中符號的編號正確4.3 項目集規(guī)范族表測試圖8 DFA表測試輸出結(jié)果為 <狀態(tài)編號> :<產(chǎn)生式編號,產(chǎn)生式項目編號,項目轉(zhuǎn)移的目標狀態(tài)>與預(yù)期結(jié)果相同4.4 LR(0)分析表測試圖9 分析表測試輸出結(jié)果為分析表,與預(yù)期結(jié)果相同4.5 LR(0)分析器測試以輸入字符串

12、accd#和acad#為例圖10 分析器測試表達式的分析結(jié)果正確五 總結(jié)和展望完成了編譯原理課程設(shè)計之后,我感到十分的疲憊,但是那一份富有成就感的欣喜卻勝過了那十分的疲憊。由于本次選題匆忙,選了一道比較有難度的題目,在做課程設(shè)計的過程中,我翻閱了很多相關(guān)資料,對課本中點到即止的知識進行了更加深入的學(xué)習(xí),有了更加深入的理解。做課程設(shè)計的過程是痛苦的,我在這一個星期內(nèi)多次熬夜戰(zhàn)斗,有時甚至顧不上吃飯,只為了揪出程序中的錯誤,只為了精益求精的完成這個課程設(shè)計。就在我寫這份總結(jié)的時候,我發(fā)現(xiàn)自己我一點也不累了,反而很興奮,很有成就感。通過本次課程設(shè)計,我發(fā)現(xiàn)實踐是檢驗學(xué)習(xí)深度、學(xué)習(xí)成果的唯一途徑,課本

13、上的知識點都是濃縮的精華,在理論闡述上不可能做到面面俱到,學(xué)到的知識當然也不可能直接運用到實際情況上。在實踐的過程中,我們需要將我們學(xué)習(xí)到的知識進行一定程度的擴充,本次課程設(shè)計涉及到算法,LR分析器自動構(gòu)造程序的機制原理以及C+語言。在用C+語言實現(xiàn)本次課程設(shè)計的過程中,我更加熟悉了C+語言的語法機制,語言規(guī)范;在實現(xiàn)LR分析器自動構(gòu)造程序的過程中,我更加熟悉了其構(gòu)造程序的原理以及與之相關(guān)的算法。由于時間匆忙,我完成的課程設(shè)計還有很多不足之處,很多工作還可以繼續(xù)完善,在提交作業(yè)之后,我不會把它放在那里一看不看的,我會繼續(xù)完善它,讓它更加人性化,具有可操作性,比如做個可視化的界面出來,豐富它的功

14、能,相信以后的工作將更加多彩豐富,更加有成就感! 附錄說明:本附錄中包含了本次課程設(shè)計的所有代碼34 Closure_List.h#ifndef CLOSURE_LIST_H#define CLOSURE_LIST_H#include "Formula_List.h"#include "LR0_Table.h"struct Item_Name_Typeint Formula_Num; int Formula_Item; ;struct Closure_Child_NodeItem_Name_Type Item_Name;int Destination;

15、Closure_Child_Node *Next_Item;struct Closure_Parent_Nodeint Current_State;Closure_Parent_Node *Next_State;Closure_Child_Node *Item;class Closure_Listprivate:Closure_Parent_Node *Closure_List_head;Closure_Parent_Node *GoToSet_Parent;Closure_Parent_Node *Current_Parent;Closure_Child_Node *GoToSet_Chil

16、d;Closure_Child_Node *Current_Child;int AmountOf_State; Formula_List sub_Formula_List;LR0_Table sub_LR0_Table;public:Closure_List():sub_Formula_List(),sub_LR0_Table()Closure_List_head = NULL;GoToSet_Parent = NULL;Current_Parent = NULL;GoToSet_Child = NULL;Current_Child = NULL;AmountOf_State = 0;Crea

17、te_Closure_List();Closure_List();void print_Closure_List();void make_LR0_Table();void print_LR0_Table();void Output_LR0_Table_ToFile();bool Sentence_Analyse(const char Sentence50);private:void Add_Clousure();bool Add_GoToSet();void Set_Initial_State();bool Is_Same_State_Exist(const int Formula_Num,c

18、onst int Formula_Item,int& Same_State_Num);void Create_Closure_List();void Destroy_Closure_List();#endifFormula_List.h#ifndef FORMULA_LIST_H#define FORMULA_LIST_H#include "Sign_List.h"struct Formula_List_ChildItemint Sign_Name;Formula_List_ChildItem* Next_Sign;struct Formula_List_Paren

19、tItemint Formula_Num; int Vn_Name; int Formula_Length; Formula_List_ParentItem* Next_Vn;Formula_List_ChildItem* Formula;class Formula_Listprivate:Formula_List_ParentItem *Formula_List_head;Formula_List_ChildItem *current_Formula_Item;Formula_List_ParentItem *current_VnNode;Sign_List Sub_Sign_List; p

20、ublic:Formula_List():Sub_Sign_List()Formula_List_head = NULL; current_Formula_Item = NULL; current_VnNode = NULL;Create_Formula_List();Formula_List();void print_Formula_List();int int_check_Sign_Name(const char word);char char_check_Sign_Name(const int Sign_Name);int Get_Formula_Length(const int For

21、mula_Num);int Get_Sign_Name(const int Formula_Num, const int Item_Num);int Get_Formula_LeftVn(const int Formula_Num);bool Is_Sign_Name_Vn(const int Sign_Name);int Get_AmountOf_Identity();private:void Destroy_Formula_List();void Create_Formula_List(); ;#endifLR0_Table.h#ifndef LR0_TABLE_H#define LR0_

22、TABLE_H#include <iostream>#include <fstream>using namespace std;#include "ConstValue.h"struct LR0_Table_Childchar Operation;int Oprand;bool Has_Been_Filled;LR0_Table_Child *Next_Table_Child;struct LR0_Table_ParentLR0_Table_Child *Table_Child;LR0_Table_Parent *Next_Table_Parent;

23、class LR0_Tableprivate:LR0_Table_Parent *LR0_Table_head;LR0_Table_Parent *Current_Parent;LR0_Table_Child *Current_Child;public:LR0_Table();LR0_Table();void initial(const int AmountOf_State, const int AmountOf_Identity);bool Fill_In_Table(const int State_Num, const int Identity_Num,const char char_Op

24、ration, const int int_Oprand);void _OutputToFile();void _print_LR0_Table();void Visit_LR0_Table(const int State_Num, const int Identity_Num, char& char_Opration, int& int_Oprand);private:void Destroy_LR0_Table();#endifSign_List.h#ifndef SIGN_LIST_H#define SIGN_LIST_H#include <iostream>

25、#include <fstream>using namespace std;#include "ConstValue.h"struct Sign_List_itemchar Identity; bool Is_Vn;Sign_List_item *next_Identity;struct Identity_List_itemchar Identity; bool Is_Vn;class Sign_Listprivate:Identity_List_item *Identity_List;int AmountOf_Identity; public:Sign_Lis

26、t();Sign_List();void print_Identity_List();int _int_check_Sign_Name(const char word);char _char_check_Sign_Name(const int Sign_Name);bool _Is_Sign_Name_Vn(const int Sign_Name);int _Get_AmountOf_Identity();private:void Destroy_temp_Sign_List();void Create_Identity_List();private:Sign_List_item *curre

27、nt_Identity; Sign_List_item *head; bool Is_sameIdentity_Exist(const char word);#endifStack.h#ifndef STACK_H#define STACK_Hstruct elemint data;elem *next;class Stackprivate:elem *top;int count;public:Stack();Stack();bool pushElem(const int Data);bool getElem(int &Data); bool popElem();int countEl

28、em()const;#endifClosure_List.cpp#include "Closure_List.h"#include "Stack.h"bool Closure_List:Add_GoToSet()int temp_Formula_Length = sub_Formula_List.Get_Formula_Length(GoToSet_Child->Item_Name.Formula_Num);if (GoToSet_Child->Item_Name.Formula_Item <= temp_Formula_Length)

29、int SameDestination = 0;if (Is_Same_State_Exist(GoToSet_Child->Item_Name.Formula_Num,GoToSet_Child->Item_Name.Formula_Item +1,SameDestination)=true)GoToSet_Child->Destination = SameDestination;return false; Closure_Child_Node *tempChild = new Closure_Child_Node;tempChild->Item_Name.Formu

30、la_Num = GoToSet_Child->Item_Name.Formula_Num;tempChild->Item_Name.Formula_Item = GoToSet_Child->Item_Name.Formula_Item +1;tempChild->Next_Item = NULL;Current_Child = tempChild;Closure_Parent_Node *tempParent = new Closure_Parent_Node;tempParent->Item = tempChild;tempParent->Next_S

31、tate = NULL;tempParent->Current_State = Current_Parent->Current_State +1;Current_Parent->Next_State = tempParent;Current_Parent = tempParent;GoToSet_Child->Destination = Current_Parent->Current_State;+AmountOf_State;return true;elseGoToSet_Child->Destination = -1;return false;void

32、Closure_List:Add_Clousure()int temp_Sign_Name = sub_Formula_List.Get_Sign_Name(GoToSet_Child->Item_Name.Formula_Num,GoToSet_Child->Item_Name.Formula_Item +1);if (temp_Sign_Name=-1)return;if (sub_Formula_List.Is_Sign_Name_Vn(temp_Sign_Name)=true)int temp_Formula_Num = 1;int temp_Vn_Name = 0;whi

33、le (temp_Vn_Name = sub_Formula_List.Get_Formula_LeftVn(temp_Formula_Num)!=-1)if (temp_Sign_Name=temp_Vn_Name)Closure_Child_Node *tempChild = new Closure_Child_Node;tempChild ->Item_Name.Formula_Num = temp_Formula_Num;tempChild ->Item_Name.Formula_Item = 1;tempChild->Next_Item = NULL;Current

34、_Child->Next_Item = tempChild;Current_Child = tempChild;+temp_Formula_Num;void Closure_List:Set_Initial_State()Closure_List_head = new Closure_Parent_Node;Closure_List_head->Current_State = 0;Closure_List_head->Item = NULL;Closure_List_head->Next_State = NULL;GoToSet_Parent = Closure_Lis

35、t_head;Current_Parent = Closure_List_head;Closure_Child_Node *tempChild = new Closure_Child_Node;tempChild ->Item_Name.Formula_Num = 1;tempChild ->Item_Name.Formula_Item = 1;tempChild->Next_Item = NULL;Closure_List_head ->Item = tempChild;GoToSet_Child = tempChild;Current_Child = tempChi

36、ld;+AmountOf_State;int temp_Sign_Name = sub_Formula_List.Get_Sign_Name(1,1);int temp_Formula_Num = 1;int temp_Vn_Name = 0;while (temp_Vn_Name = sub_Formula_List.Get_Formula_LeftVn(temp_Formula_Num)!=-1)if (temp_Sign_Name=temp_Vn_Name)Closure_Child_Node *tempChild = new Closure_Child_Node;tempChild -

37、>Item_Name.Formula_Num = temp_Formula_Num;tempChild ->Item_Name.Formula_Item = 1;tempChild->Next_Item = NULL;Current_Child->Next_Item = tempChild;Current_Child = tempChild;+temp_Formula_Num;void Closure_List:Create_Closure_List()Set_Initial_State();while (GoToSet_Parent!=NULL)if (GoToSet

38、_Child!=NULL)if (Add_GoToSet()=true) Add_Clousure(); GoToSet_Child = GoToSet_Child->Next_Item; elseGoToSet_Parent = GoToSet_Parent->Next_State;if (GoToSet_Parent=NULL)break;GoToSet_Child = GoToSet_Parent->Item;void Closure_List:Destroy_Closure_List()Current_Parent = Closure_List_head;if (Cl

39、osure_List_head = NULL)return;elsewhile (Current_Parent != NULL)Closure_Parent_Node *temp_ToDelete = Current_Parent;Current_Child = Current_Parent->Item;while (Current_Child != NULL)Closure_Child_Node *ToDelete = Current_Child;Current_Child = Current_Child->Next_Item;delete ToDelete;Current_Pa

40、rent = Current_Parent->Next_State;delete temp_ToDelete;Closure_List_head = NULL;GoToSet_Parent = NULL;Current_Parent = NULL;GoToSet_Child = NULL;Current_Child = NULL;void Closure_List:print_Closure_List()Closure_Parent_Node *print_Vn_Node = Closure_List_head;if (Closure_List_head = NULL)return;el

41、sewhile (print_Vn_Node != NULL)cout<<print_Vn_Node->Current_State<<" : "Closure_Child_Node *pirnt_Item_Node = print_Vn_Node->Item;while (pirnt_Item_Node != NULL)cout<<'<'<<pirnt_Item_Node->Item_Name.Formula_Num<<','<<pirnt_Ite

42、m_Node->Item_Name.Formula_Item<<','<<pirnt_Item_Node->Destination<<">, "pirnt_Item_Node = pirnt_Item_Node->Next_Item;cout<<endl;print_Vn_Node = print_Vn_Node->Next_State;bool Closure_List:Is_Same_State_Exist(const int Formula_Num,const int For

43、mula_Item ,int& Same_State_Num)Closure_Parent_Node *Check_Parent_Node = Closure_List_head;while (Check_Parent_Node != NULL)if (Check_Parent_Node->Item->Item_Name.Formula_Item = Formula_Item &&Check_Parent_Node->Item->Item_Name.Formula_Num = Formula_Num)Same_State_Num = Check_

44、Parent_Node->Current_State;return true;Check_Parent_Node =Check_Parent_Node->Next_State;Same_State_Num = -1;return false;void Closure_List:make_LR0_Table()sub_LR0_Table.initial(AmountOf_State,sub_Formula_List.Get_AmountOf_Identity();Closure_Parent_Node *Traverse_Parent = Closure_List_head;Clos

45、ure_Child_Node *Traverse_Child = Closure_List_head->Item;bool No_ErrorOccurIn_FillingTable = true;while (Traverse_Parent!=NULL)Item_Name_Type Traverse_Item; Traverse_Item.Formula_Num = Traverse_Child->Item_Name.Formula_Num;Traverse_Item.Formula_Item = Traverse_Child->Item_Name.Formula_Item;

46、int CurrentFormulalength = sub_Formula_List.Get_Formula_Length(Traverse_Item.Formula_Num);if (Traverse_Item.Formula_Item<=CurrentFormulalength) int Traverse_Sign_Name = sub_Formula_List.Get_Sign_Name(Traverse_Item.Formula_Num, Traverse_Item.Formula_Item);int Goal_State_Num = Traverse_Child->De

47、stination;if (sub_Formula_List.Is_Sign_Name_Vn(Traverse_Sign_Name)=false)No_ErrorOccurIn_FillingTable = sub_LR0_Table.Fill_In_Table(Traverse_Parent->Current_State,Traverse_Sign_Name,'s',Goal_State_Num);elseNo_ErrorOccurIn_FillingTable = sub_LR0_Table.Fill_In_Table(Traverse_Parent->Curr

48、ent_State,Traverse_Sign_Name,'g',Goal_State_Num);else int Traverse_Sign_Name = sub_Formula_List.Get_Sign_Name(Traverse_Item.Formula_Num, Traverse_Item.Formula_Item-1);if (Traverse_Sign_Name=1)No_ErrorOccurIn_FillingTable = sub_LR0_Table.Fill_In_Table(Traverse_Parent->Current_State,sub_For

49、mula_List.Get_AmountOf_Identity(),'a',1);elsefor (int i=0; i<sub_Formula_List.Get_AmountOf_Identity(); +i)if (sub_Formula_List.Is_Sign_Name_Vn(i)=false)No_ErrorOccurIn_FillingTable = sub_LR0_Table.Fill_In_Table(Traverse_Parent->Current_State, i,'r',Traverse_Item.Formula_Num);No

50、_ErrorOccurIn_FillingTable = sub_LR0_Table.Fill_In_Table(Traverse_Parent->Current_State, sub_Formula_List.Get_AmountOf_Identity(),'r',Traverse_Item.Formula_Num);if (No_ErrorOccurIn_FillingTable=false)cout<<"This is not LR(0) Grammarn"exit(1);if (Traverse_Child->Next_Item!=NULL)Traverse_Child = Traverse_Child->Next_Item;elseif (Traverse_Parent->Next_State!=NULL)Traverse_Parent = Traverse_Parent->Next_State;Traverse_Child = Traverse_Paren

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論