Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thautwarm/gkdbnf

convert bnf files, to LaTex notations, supporting multiple LaTex BNF packages as back ends
https://github.com/thautwarm/gkdbnf

bnf code-generation latex

Last synced: 3 months ago
JSON representation

convert bnf files, to LaTex notations, supporting multiple LaTex BNF packages as back ends

Awesome Lists containing this project

README

        

# GKD-BNF

`pip install gkdbnf`.

Maybe the most simplest way to write pretty BNF in LaTex.

Use this package with `gkdtex`:

## Usage

```tex
\gkd@bnf{
:: Integer
:: Symbol
:: String

:: !Expr[MinDyn]! = \mathbf{func} (\! \!) \{ \} %%% functions
| ( ) %%% applications
| = %%% assignments
| \mathbf{if} ( ) \{ \} \{ \} %%% conditions
| %%% variable read
|
|

::=
| \mathbf{const} =

::=
}
```

![example0.PNG](example0.PNG)

## Syntax

Valid BNF Syntax:
```bnf
atom ::= NONTERMINAL
| TERMINAL
| TERMINAL2
| '|'

rule ::= '%%%' TERMINAL2
description ::= TERMINAL | TERMINAL2
type ::= TERMINAL | TERMINAL2 | NONTERMINAL

prod ::= description? NONTERMINAL '::' type '=' atom+ rule?
| '|' atom+ rule?

start ::= start NEWLINE
| start prod
| NEWLINE
| prod
```

Lexer rule by regex:
```
NEWLINE = [\r\n]+
NONTERMINAL = <.*?>
TERMINAL2 = !.*?!
TERMINAL = \S+
```

Whitespace tokens are ignored.

## Nice Error Report
```tex
1: \gkd@usepackage{gkdbnf}
2: \gkd@bnf{
3: ::= a + 1
4:
5: ::= a a
6: Expressions e ::= e
7: }
```

You get error

```
SyntaxError: filename runtest/a.tex:
line 6, column 13, NonTerm not match
```

Then you know you should change `Expression e` to `Expression `.