在 Python 中解析上下文无关语法

发布于 2024-09-04 12:20:35 字数 84 浏览 1 评论 0原文

Python 中有哪些工具可以帮助解析上下文无关语法?

当然,我可以自己开发,但我正在寻找一个通用工具,可以为给定的 CFG 生成解析器。

What tools are available in Python to assist in parsing a context-free grammar?

Of course it is possible to roll my own, but I am looking for a generic tool that can generate a parser for a given CFG.

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

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

发布评论

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

评论(1

苦行僧 2024-09-11 12:20:35

我强烈推荐 PLY - 它是 Python 中的 Lex/Yacc 克隆,以复杂的方式使用该语言的自省功能方式允许非常自然的语法规范。如果您还记得的话,Yacc 正是 C​​FG 在可理解的 DSL 中的体现,它定义了人们如何解析它们。

我用它来实现我的ANSI C 解析器,并且与 PLY 的交互几乎毫不费力。

I warmly recommend PLY - it's a Lex/Yacc clone in Python that uses the language's introspection facilities in a sophisticated manner to allow for a very natural specification of the grammar. Yacc, if you recall, is the very embodiment of CFGs in an understandable DSL that defines how one parses them.

I used it to implement my parser for ANSI C and the interaction with PLY was almost effortless.

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