【问题标题】:what is meant by left most derivation?最左推导是什么意思?
【发布时间】:2023-03-27 05:21:01
【问题描述】:

请帮我理解Left Most Derivation第二个LLL Parser中的含义。

用一个最简单的例子解释一下。

我看到下图解释了最左边的推导但是我没看懂:

【问题讨论】:

  • 我认为最左边的推导意味着你总是将规则应用到你可以应用它的最左边的地方。所以我可以说'Rule N -> N D'并且你知道在最左边的地方应用它。如果它是一个 RR 解析器,它会将它应用到它可以应用到的最右边的位置。

标签: parsing language-agnostic compiler-construction


【解决方案1】:

语法规则以非终结符号和终结符号显示在左侧。非终结符号应该是大写字母,其他一切通常都是终结符号。在示例中,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.

【讨论】:

    猜你喜欢
    • 2018-07-17
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 2011-08-12
    相关资源
    最近更新 更多