antlrcontext-free-grammarbnf

Are there tools to convert between ANTLR and other forms of BNF?


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?


Solution

  • Jakob wrote:

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

    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


    Jakob wrote:

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

    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.