Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 850
Jakob Avatar asked Feb 01 '11 22:02

Jakob


People also ask

What is ANTLR tool?

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.

Is ANTLR a compiler?

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.

What is Backus Naur Form BNF rules illustrate with an example?

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.

What is Backus Naur form used for?

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.


2 Answers

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

like image 189
Frank Hileman Avatar answered Nov 03 '22 10:11

Frank Hileman


# 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`
like image 20
Travis Avatar answered Nov 03 '22 10:11

Travis