LL(*) 解析器如何工作?

发布于 2024-09-03 18:59:09 字数 114 浏览 3 评论 0原文

我在互联网上找不到关于 LL(*) 解析器(例如 ANTLR)的任何完整描述。

我想知道 LL(k) 解析器和 LL(*) 解析器之间有什么区别,以及为什么它们不支持左递归语法,尽管它们具有灵活性。

I cannot find any complete description about LL(*) parser, such as ANTLR, on Internet.

I'm wondering what is the difference between an LL(k) parser and an LL(*) one and why they can't support left-recusrive grammars despite their flexibility.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽蝶幻影 2024-09-10 18:59:09

这是一篇关于 LL(*)< 的文章(由 antlr 的作者 Terence Parr 撰写) /code> 语法分析:文章有一个很好的例子,说明对于任何 k 来说,什么是 LL(*) 而不是 LL(k)

另一个很好的参考(而且更完整)是 "Definitive ANTLR Reference" ,同样由 Terence Parr 撰写,原始期刊文章描述antlr如何工作[pdf]

Here is an article (by Terence Parr, the author of antlr) about LL(*) grammar analysis: article with a nice example of what is LL(*) but not LL(k), for any k.

Another good reference (and much more complete) is the "Definitive ANTLR Reference", again by Terence Parr, and the original journal article describing how antlr works [pdf].

场罚期间 2024-09-10 18:59:09

当您看到这一点时,通常是为了解析语言而向前查看的令牌数量。

这对于 LR 解析器来说也是一样的。

所以 k 是解析器在做出决定之前将获取的最大令牌量。
请注意,k 越高,解析器就越难,除非您使用生成器(ANTLR、yacc、bison,...)。

LL 解析器使用自上而下的方法,这意味着它将寻找最深的树。
因此,左递归将生成无限深的树,并会破坏解析器。

AFAIK 大多数语言都使用 LR 解析器。

When ever you see this it generally the amount of token look ahead in order to parse the language.

This is the same thing for LR parser.

So k is the maximum mount of token that the parer will fetch before taking a decision.
Be aware that the more k is hight the harder the parser will be unless you use a generator (ANTLR, yacc, bison, ...).

LL parser use a top down approach which mean that it will look for the deepest tree.
Because of that left recursion will make an infinitively deep tree and will break the parser.

AFAIK Most of the language use LR parser.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文