【正文】
Case Else FXZ(a) = (i, j, k) a = a + 1 FXZ(a) = Empty End Select k = k + 1 Loop 4 特殊問題 及 解決方法 在程序的開發(fā)過程中,遇到的問題及解決辦法如下: 第 XI 頁 共 22 頁 Select集的求解 問題描述 在 LL( 1)分析方法中, select 集的求解至關(guān)重要,其中又涉及到 first 集和 follow 集的求解。代碼如下: Private Declare Function SendMessage Lib user32 Alias SendMessageA (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const LB_SETHORIZONTALEXTENT = amp。在數(shù)據(jù)的處理上我采用各模塊全數(shù)組操作,并且將最終結(jié)果通過字符串方式保存,通過字符串來向其他模塊傳送數(shù)據(jù),這種新的嘗試也讓我的程序帶有個人的風格,讓我對編程的多樣化有了更 深的了解和認識。 [7] 周峰 .Visual Basic案例開發(fā)集錦 [M].北京:電子工業(yè)出版社, 2020。 ( 4)學校可允許學位論文被查閱或借閱。 關(guān)鍵詞 :編譯;語法分析; LL(1)算法;演示 The Design and Implementation of A Syntax Analyzer based on Compilation Theory Abstract The piler generally is made up of the lexical analyzer program, the syntax analysis program, the semantics analysis program, the interlanguage production procedure, the goal code production procedure, the code optimization procedure, the form executive program and the procedure of disposing mistakes. In the teaching process of piler principle, all algorithm explanation needs to be explain clearly, including algorithm condition judgment, grammar analytical table structure process, grammar analytical table concrete production, in view of grammar sentence analysis process and so on. These processes often take much time to analyze, the scheduling and so on. This program mainly work is to plete the algorithm which take advantage of the procedure to deal with those above mentioned processes , in order to save time. The paper aims at introducing a syntax analytical method named LL(1) algorithm which from the up to down. The syntax analyzer analyzes the character string beginning from the left to right one word each time and educes the most left deduction of the sentence in the analyze course.. Key words: piler。教學主要是對這些過程的講解和分析,沒有必要花這么多的時間來做這些工作。 BNF 表示法 :即巴科斯范式表示法,它引進了符號“ |”,符號“ |”表示“或”。 直接左遞歸規(guī)則 :型如 U:: =Uy 的規(guī)則稱為直接左遞歸規(guī)則。 該解決辦法是把文法中每個非終結(jié)符號 A 的右部稱為 A 的候選式,對候選式的選擇,則根據(jù)當前輸入符號來決定。 Z? bZ? bbZ? bbaV? bbabaZ? bbabaaV?bbabaax (babaax) (abaax) (baax) (ax) (x) 對于文法,有 A::= x1|x2|? |xn,若有 First(xi) ∩ First(xj) ??(i?j),采用試探法:即從首字符中有輸入符號的多個候選式中任選一個來試探,如果不成功,就換另一個接著試。方法是在內(nèi)存中開辟一個保護棧,每次 進入遞歸子程序時,就把當前返回地址送入保護棧,相應(yīng)地,每次退出遞歸子程序時,就取棧頂?shù)姆祷氐刂纷鳛槠浞祷氐刂?。根?jù)輸入串向前的 1個符號來確定推導(dǎo)規(guī)則時,就是 LL( 1)方法。如果分析棧中的元素為 A,輸入元素為 a,則其匹配關(guān)系記為 LL(A,a) LL(1)分析矩陣:一種用來反映這種匹配關(guān)系的矩陣表示,該矩陣 稱為 LL(1)分析矩陣。 (3)若上述兩個字符串均為空,則表示全部匹配,輸入串被識別。 LL( K)分析方法 LL(K)分析方法是一種自頂向下 的分析技術(shù)。 遞歸子程序及其調(diào)用: 常用的子程序的種類有 3 種: 簡單子程序, 嵌套子程序, 遞歸子程序。 例:設(shè)有文法 G[Z],和句子 bbabaax Z::=aV|bZ V::=baZ|x Select(Z ::=aV)={a}。 LL( 1)文法 :對于文法 G( S),其每個非終結(jié)符的不同規(guī)則具有不相交的Select 集,則稱該文法為 LL( 1)文法。 非 終結(jié)符 :文法中出現(xiàn)在規(guī)則左部的符號,它們組成的集合稱為非終結(jié)符集。 文法 :對語言結(jié)構(gòu)的定 義和描述,即在形式上用于描述和規(guī)定語言結(jié)構(gòu)。 編譯程序是現(xiàn)代計算機系統(tǒng)的基本組成部分之一。 在編譯原理的教學過程中,算法的講解都需要對算法進行詳細的分析,包括算法條件的判斷,文法分析表的構(gòu)造過程,文法分析表的具體生成,針對文法的句子的分析過程等,這些過程往往需要占用大量時間來分析 、制表等。除非另有說明,本文的工作是原始性工作。 [3] 賀世娟,陳冀川 .Visual Basic 程序設(shè)計 [M].北京:中國水利水電出版社出版。 通過 open 對話框輸入正確的文 法(圖 8 所示),把自己想輸入的文法通過正確格式書寫在 TXT 文檔中,運行軟件后就可以選中該文件打開運行。 解決結(jié)果 在成功獲得 select 集后,對其進行了輸出,結(jié)果如圖 6 所示: 圖 6 顯示 select 集 為 ListBox 添加水平滾動條 問題描述 在 VB 中,系統(tǒng)提供的 ListBox 只有垂直滾動條,而沒有水平滾動條。存放句子分析過程中的分析棧 Dim FHZ(50) As String 39。查找 WF(i,j+1)對應(yīng)的非終結(jié)符在文法的第幾行 If WF(i, j + 1) = WF(n, 0) Then Call first(n, fo) 分析表構(gòu)造模塊 在已經(jīng)得到文法 select 集的前提下,以次為依據(jù),對文法的三種類型的規(guī)則: A::=aβ 型、 A::=Dβ 型、 A::=ε 型分別構(gòu)造分析表,并用一個三維數(shù)組保存。 For i = 0 To zj If WF(a, 1) = ZJF(i) Then 39。 文法的行數(shù) Public zj As Integer 39。 文件路徑 = True On Error GoTo err = Text(*.txt)|*.txt = 1 39。本模塊包含了 LL( 1)算法中的大部分重要數(shù)據(jù)和信息,其中包括獲取輸入文法的終結(jié)符集和非終結(jié)符集,對文法中每一條規(guī)則求 select集( select 集的求解又包括求 first 集或者 follow 集),以及對 select 集合法性的判斷,即同一非終結(jié)符所對應(yīng)的不同規(guī)則的 select 集中不能有相同的終結(jié)符。如果分析棧中的元素為 A,輸入元素為 a,則其匹配關(guān)系記為 LL(A,a) LL(1)分析矩陣:一種用來 反映這種匹配關(guān)系的矩陣表示,該矩陣稱為 LL(1)分析矩陣。根據(jù)輸入串向前的 1個符號來確定推導(dǎo)規(guī)則時,就是 LL( 1)方法。方法是在內(nèi)存中開辟一個保護棧,每次進入遞歸子程序時,就把當前返回地址送入保護棧,相應(yīng)地,每次退出遞歸子程序時,就取棧頂?shù)姆祷氐刂纷鳛槠浞祷氐刂贰?Z? bZ? bbZ? bbaV? bbabaZ? bbabaaV?bbabaax (babaax) (abaax) (baax) (ax) (x) 對于文法,有 A::= x1|x2|? |xn,若有 First(xi) ∩ First(xj) ??(i?j),采用試探法:即從首字符中有輸入符號的多個候選式中任選一個來試探,如果不成功,就換另一個接著試。 該解決辦法是把文法中每個非終結(jié)符號 A 的右部稱為 A 的候選式,對候選式的選擇,則根據(jù)當前輸入符號來決定。 直接左遞歸規(guī)則 :型如 U:: =Uy 的規(guī)則稱為直接左遞歸規(guī)則。 BNF 表示法 :即巴科斯范式表示法,它引進了符號“ |”,符號“ |”表示“或”。教學主要是對這些過程的講解和分析,沒有必要花這么多的時間來做這些工作。 關(guān)鍵詞 :編譯;語法分析; LL(1)算法;演示 The Design and Implementation of A Syntax Analyzer based on Compilation Theory Abstract The piler generally is made up of the lexical analyzer program, the syntax analysis program, the semantics analysis program, the interlanguage production procedure, the goal code production procedure, the code optimization procedure, the form executive program and the procedure of disposing mistakes. In the teaching process of piler principle, all algorithm explanation needs to be explain clearly, including algorithm condition judgment, grammar analytical table structure process, grammar analytical table concrete production, in view of grammar sentence analysis process and so on. These processes often take much time to analyze, the scheduling and so on. This program mainly work is to plete the algorithm which take advantage of the procedure to deal with those above mentioned processes , in order to save time. The paper aims at introducing a syntax analytical method named LL(1) algorithm which from the up to down. The syntax analyzer analyzes the character string beginning from the left to right one word each time and educes the most left deduction of the sentence in the analyze course.. Key words: piler。本軟件的主要任務(wù)就是利用程序來完成算法的上述相關(guān)過程,以達到高效,直觀的效果。編譯程序一般由詞法分析程序、語法分析程序、語義分析程序 、中間代碼生成程