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. 
相关问题