EBNF语法解析器模块

发布于 2024-12-23 06:39:38 字数 675 浏览 4 评论 0原文

你知道一个语法解析器模块(用 Ruby、Python、Javascript 编写),给定一个标记列表和一个 EBNF 式语法(作为简单字符串传递),返回解析树?我发现的最接近的是 SimpleParse,这是一个不错的库,但不幸的是它使用了一个单-步骤解析(无标记化)。如果可能的话,我宁愿不使用实现与语言本身纠缠在一起的库(pyparsing树顶,...)。

我并不担心词法分析/标记化,因为有很多可用的库(甚至编写自己的库也很容易),但实现 ENBF 解析器并不是一项简单的任务。我检查了Python wiki LanguageParsing 并测试了其中一些无济于事(也许我忽略了我正在找一个,有很多...)

Do you know of a syntax parser module (written in Ruby, Python, Javascript...) that, given a list of tokens and a EBNF-like grammar (passed as a simple string), returns the parsed tree? The closest I've found to this is SimpleParse, which is a nice library, but unfortunately it uses a single-step parsing (no tokenization). If possible I'd rather not use libraries in which the implementation is entangled with the language itself (pyparsing, treetop, ...).

I am not worried about the lexing/tokenization because there are a lot of libraries available (and even writing your own is pretty easy), but implementing a ENBF parser is not exactly a trivial task. I've checked the Python wiki LanguageParsing and tested some of them to no avail (maybe I overlooked the one I am looking for, there are so many...)

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

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

发布评论

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

评论(2

遇见了你 2024-12-30 06:39:38

经过更多搜索后,我决定采用典型的 lex/yacc 方法,使用 Jison 表示 node.js

After some more searching I've decided to take the typical lex/yacc approach using Jison for node.js.

飘逸的'云 2024-12-30 06:39:38

如果您熟悉 Clojure,我发现 Instaparse 非常棒。您可以将“vanilla”EBNF 编写为多行字符串(或者在单独的文件中,它甚至将 EBNF 从上下文无关语法扩展到上下文相关语法(尽管我还没有玩过那么多)。

If you're familiar with Clojure at all I've found Instaparse to be great. You can write in "vanilla" EBNF as a multi-line string (or in a separate file and it even extends EBNF beyond context-free grammars into context sensitive grammars (though I haven't played around with that much).

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