【问题标题】:Trace of parse for input string using parse table使用解析表对输入字符串进行解析跟踪
【发布时间】:2016-01-25 09:39:17
【问题描述】:

我们的教授在课堂上从来没有时间教我们这些材料,现在我们有家庭作业。 Google 似乎在引导我朝着正确的方向前进,但我想确保我做对了(当然)。

我们得到以下语法,并要求根据它制作一个解析表:

1.  S -> ABe
2.  A -> dB
3.  A -> aS
4.  A -> c
5.  B -> AS
6.  B -> b

我的解析表:

_| a | b | c | d | e | #
S|ABe|   |ABe|ABe|   |
A|aS |   | c |dB |   |
B|AS | b |AS |AS |   |

现在我们得到指示:

"使用你的解析表,给出输入的解析轨迹 字符串 dbbe。给出未使用的输入字符串、堆栈和输出 (规则编号序列)在每次迭代开始时。”

在我的互联网搜索中,我找到了这个例子:

来源:http://what-when-how.com/compiler-writing/top-down-parsing-compiler-writing-part-1/

看起来好像你遍历了语法中给出的每一种可能性,直到你匹配到字符串。

这是我想出的:

这是怎么回事?我理解对了吗?我只通过引用语法来做到这一点;不是我的解析表..我将如何使用我的解析表进行跟踪?

我仍然不确定这意味着什么:

给出未使用的输入字符串、堆栈和输出(规则序列 numbers) 在每次迭代开始时

【问题讨论】:

    标签: parsing tree grammar parse-tree


    【解决方案1】:

    这是他正在寻找的要点(不包括输出;他不在乎那个):

    Stack:     Input String:
    S#         dbbe#          <- S->ABe
    ABe#       dbbe#          <- A->db
    dbBe#      dbbe#          <- Pop off matching 'd' at beginning of stack and string
    bBe#       bbe#           <- Pop off the matching 'b's...
    Be#        be#            <- B->b
    be#        be#            <- Pop off 'b's...
    e#         e#             <- Pop off 'e's...
    #          #              <- Reaching this point on both the stack and input means the input was valid
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      相关资源
      最近更新 更多