We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
The community reviewed whether to reopen this question 9 months ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
我为此目的写了一个翻译器。 Universal-transpiler 能够转换 ANTLR 语法进入 PEG.js, 近,ABNF,XBNF 以及其他一些语法符号。目前还无法将 ANTLR 转换为 W3C-BNF,但我会尝试在未来版本中添加此功能。
该翻译器仅与 ANTLR 语言的一小部分兼容,但我希望它仍然有用。
I wrote a translator for this purpose. Universal-transpiler is able to convert ANTLR grammars into PEG.js, nearley, ABNF, XBNF, and several other grammar notations. It is not yet able to translate ANTLR into W3C-BNF, but I will try to add this feature in a future version.
This translator is only compatible with a small subset of the ANTLR language, but I hope it will still be useful.
ANTLR (v3) 是用以下语法“用自己的话”编写的(正如特伦斯·帕尔本人所说):
http://www.antlr.org/grammar/ANTLR/ANTLRv3.g
据我所知没有。如果它确实存在,我也从未在我定期阅读的 ANTLR 邮件列表上看到过讨论这个工具。
另请注意,许多 BNF 变体允许 左递归 规则,这是 LL 解析器生成器像ANTLR无法应对。左递归规则当然可以由该工具重新分解,但这可能相当棘手,并且可能会导致比手动执行此操作所得到的语法“可读”得多。
至于将 ANTLR 语法转换为类似 BNF 的形式,我想会更容易,尽管只是使用最简单的语法。一旦将各种类型的谓词放入 ANTLR 语法中,转换可能会再次变得棘手。
ANTLR (v3) is written "in its own words" (as Terence Parr himself put it) in this grammar:
http://www.antlr.org/grammar/ANTLR/ANTLRv3.g
Not that I know of. And if it does exist, I've never seen this tool being discussed on the ANTLR mailing list that I read on a regular basis.
Also note that many BNF-variants allow for left-recursive rules, something that an LL-parser generator like ANTLR cannot cope with. The left recursive rules can of course be re-factored out by the tool, but that could be rather tricky, and will probably result in a far less "readable" grammar than one would get than doing this manually.
As to converting ANTLR grammars into BNF-like form would be easier I guess, although only with the most trivial grammars. As soon as various types of predicates are put into an ANTLR grammar, the conversion might again become tricky.
有一个网站提供了大量的语法和工具来在其格式之间进行转换:
http:// slebok.github.io/zoo/index.html
There's a site that host a huge variety of grammars and tools to convert between their formats:
http://slebok.github.io/zoo/index.html
Antlr4 确实允许左递归,具有显着的灵活性。我找到了一个现代工具,可以在 Antlr 语法与其他类型的语法之间进行转换。目前这得到了很好的支持:
trconvert
Antlr4 does allow left recursion, with remarkable flexibility. I found a modern tool to convert to and from Antlr grammars to other types of grammars. This is well supported at this time:
trconvert