请帮助我理解 中Left Most Derivation
的第二个L
是什么意思LL Parser
。
用一个最简单的例子来解释。
我看到下图解释了最左推导,但我不明白:
请帮助我理解 中Left Most Derivation
的第二个L
是什么意思LL Parser
。
用一个最简单的例子来解释。
我看到下图解释了最左推导,但我不明白:
语法规则以非终结符号和终结符号显示在左侧。非终结符号应该是大写字母,其他一切通常都是终结符号。在示例中,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.