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?
What is ANTLR? ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
In computer-based language recognition, ANTLR (pronounced antler), or ANother Tool for Language Recognition, is a parser generator that uses LL(*) for parsing. ANTLR is the successor to the Purdue Compiler Construction Tool Set (PCCTS), first developed in 1989, and is under active development.
In computer science, Backus–Naur form (/ˌbækəs ˈnaʊər/) or Backus normal form (BNF) is a metasyntax notation for context-free grammars, often used to describe the syntax of languages used in computing, such as computer programming languages, document formats, instruction sets and communication protocols.
Backus-Naur Form (BNF) is a syntax for describing syntax. It's used to write a formal representation of a context-free grammar. If that doesn't sound abstract enough for you, a grammar doesn't have to be a programming language or even a human language — it can be any syntax that you want to describe.
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
# Grammar Syntax
| | BNF | ISO EBNF | ABNF | ANTLR |
|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|
| rule definition | `<name> ::= ...` | `name = ... ;` | `name = ...` | `name : ... ;` |
| terminal items | `...` | `'...'` or `"..."` | integer or `"..."` | `'...'` |
| non-terminal items | `<...>` | `...` | `...` or `<...>` | `...` |
| concatenation | (space) | `,` | (space) | (space) |
| choice | `|` | `|` | `/` | `|` |
| optional | requires choice syntax[^1] | `[...]` | `*1...` or `[...]` | `...?` |
| 0 or more repititions | requires choice syntax[^2] | `{...}` | `*...` | `...*` |
| 1 or more repititions | requires choice syntax[^3] | `{...}-` | `1*...` | `...+` |
| n repititions | | `n*...` | `n*n...` | |
| n to m repititions | | | `n*m...` | |
| grouping | | `(...)` | `(...)` | `(...)` |
| comment | | `(*...*)` | `;...` | `// ...` or `/* ... */` |
[^1]: `optionalb ::= a b c d | a c d`
[^2]: `list ::= | listitem list`
[^3]: `list ::= listitem | listitem list`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With