8

請幫我理解Left Most Derivation第二個LLL Parser是什麼意思。什麼是最左派生?

用一個最簡單的例子來解釋它。

我看到下面的圖片解釋最左推導,但我不明白:

enter image description here

+0

我覺得最左邊的派生意味着你總是將規則#應用到你可以應用它的最左邊的地方。所以我可以說'規則N - > N D',你知道你可以在最左邊的位置應用它。如果是RR分析器,它會將它應用於最右邊的位置。 – Patashu 2013-03-04 03:34:40

回答

10

語法規則被顯示在左邊與非終結符和終結符。非終結符號應該是大寫字母,其他所有符號通常都是終端符號。在例子中,N和D是非終結符,0-9是終結符。最左派生總是讓最左邊的非終結符通過語法規則。試着格式化下面的例子。

N 
=> N D --Replaces the first/left most/only (which is "N") with the N => N D rule 
=> N D D --Replaces the first/left most nonterminal (which is "N") with the N => N D rule 
=> D D D --Replaces the first nonterminal (which is "N") with the N => D rule 
=> 1 D D --Replaces the first nonterminal ("D") with the D => 1 rule(our first terminal character!) 
=> 1 2 D --Replaces the first nonterminal ("D") with the D => 2 rule 
=> 1 2 3 --Replaces the first nonterminal ("D") with the D => 3 rule 
-- Only terminal characters remain, derivation/reduction is complete. 
相關問題