EBNF语法解析器模块
你知道一个语法解析器模块(用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过更多搜索后,我决定采用典型的 lex/yacc 方法,使用 Jison 表示 node.js。
After some more searching I've decided to take the typical lex/yacc approach using Jison for node.js.
如果您熟悉 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).