如何处理Treetop左递归
我有一个用于新的通用编程的 语法文件我正在尝试构建的语言。我试图使该语言变得健壮且易于使用(它很大程度上受到 Ruby 等的启发),为此我引入了一些左递归规则。
我看到一些例子似乎表明了以下左递归规则:
rule l_recurse
l_recurse / 'something else'
end
可以通过将其更改为非左递归规则:
rule r_recurse
'something else' / r_recurse
end
对我来说,这看起来会遇到不同的问题并且仍然会失败。我是对的,还是这“有效”?
我试图(查找和)消除的特定左递归可以在 语法文件。我不确定哪些规则受到影响,但至少一些规则被指出已经离开-递归。 (顺便说一句,我试图通过收紧范围规则来消除他提到的特定范围问题。)
I have a grammar file for a new general-purpose programming language I'm trying to build. I'm trying to make the language robust and natural to use (it is heavily inspired by Ruby, among others), and in doing so I have introduced some left-recursive rules.
I've seen some examples that seem to indicate the following left-recursive rule:
rule l_recurse
l_recurse / 'something else'
end
can be made non-left-recursive by changing it to:
rule r_recurse
'something else' / r_recurse
end
To me this looks like it would have the a different problem and would still fail. Am I right, or will this "just work"?
The specific left-recursions I'm trying to (find and) eliminate are found in this grammar file. I'm not sure which rules are affected, but at least some were pointed out to have left-recursion. (By the way I have tried to eliminate the specific range issue he mentioned by tightening up range's rule.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
特定情况
简化为
(正确的递归规则也是如此),所以我需要查看您的具体示例以找出您想知道的内容。 这个问题的答案给出了左递归消除的一般规则。
典型的易于消除的左递归情况之一是列表:
并且可以将其更改为右递归
(这是一般递归消除的特殊情况)。
The particular case
simplifies to
(and so does the right recursion rule) so I need to see your specific example to find out what you want to know. The answer to this question gives the general rule for left recursion elimination.
One of the typical easy-to-remove left recursion cases is lists:
and that can be changed to right recursion
(which is a special case of the general recursion elimination).