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

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

问题描述

是否有工具可以将ANTLR语法语法与其他BNF语法相互转换?有几种形式的Backus-Naur形式(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?

推荐答案

Jakob写道:

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-parser生成器(如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语法转换成类似B​​NF的形式会更容易,尽管只有最琐碎的语法.一旦将各种谓词放入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天全站免登陆