是否有工具可以在 ANTLR 和其他形式的 BNF 之间进行转换? [英] Are there tools to convert between ANTLR and other forms of BNF?

查看:26
本文介绍了是否有工具可以在 ANTLR 和其他形式的 BNF 之间进行转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何工具可以将 ANTLR 语法语法与其他 BNF 语法相互转换?有几种具有规范的形式 Backus-Naur Form(BNF、EBNF、ABNF、W3C-BNF、XBNF...),例如查看此列表.ANTLR 语法语法似乎只是示例描述.我知道 ANTLR 语法文件包含的不仅仅是上下文无关语法的规范,但您应该至少能够转换公共子集 - 有没有人自动完成过?

Are there any tools to convert ANTLR grammar syntax to and from other BNF syntaxes? There are several forms Backus-Naur Form (BNF, EBNF, ABNF, W3C-BNF, XBNF...) with specification, e.g. see this list. The ANTLR grammar syntax only seems to be described by examples. I know that ANTLR grammar files contain more than the specification of a context-free syntax, but you should be able to convert at least the common subset - has anyone done yet automatically?

推荐答案

雅各布写道:

ANTLR 语法似乎只能用例子来描述.

The ANTLR grammar syntax only seems to be described by examples.

ANTLR (v3) 在这个语法中是用它自己的话"(正如 Terence Parr 自己所说的那样):

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


雅各布写道:

但您至少应该能够转换公共子集 - 有人自动完成了吗?

but you should be able to convert at least the common subset - has anyone done yet automatically?

我不知道.如果它确实存在,我从未在我定期阅读的 ANTLR 邮件列表中看到有人讨论过这个工具.

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.

另请注意,许多 BNF 变体允许 左递归 规则,这是 LL像ANTLR这样的解析器生成器无法应付.左递归规则当然可以由工具重新分解,但这可能相当棘手,并且可能会导致比手动执行此操作更不可读"的语法.

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.

至于将 ANTLR 语法转换为类似 BNF 的形式,我想会更容易,尽管只有最简单的语法.一旦将各种类型的谓词放入 ANTLR 语法中,转换可能会再次变得棘手.

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.

这篇关于是否有工具可以在 ANTLR 和其他形式的 BNF 之间进行转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆