BNF wrangling and railroad diagrams
Do you want to convert various kinds of BNF to other kinds of BNF? No?
Well imagine if you did! This would be the tool for you.
Input: Various BNF-like syntaxes
Output: Various BNF-like syntaxes, AST dumps, and Railroad Syntax Diagrams
Compilation phases:
Gallery:
Getting started:
See the /examples directory for grammars in various BNF dialects. These have been collated from various sources and are of various quality. BNF dialects tend to be poorly specified, and these examples are an attempt to keep a corpus of known-good examples for each dialect. kgt can't parse them all yet.
kgt reads from stdin in dialect -l ...
and writes to stdout
in format -e ...
:
; kgt -l bnf -e rrutf8 < examples/expr.bnf
expr:
โโโโโฎโโ term โโ "+" โโ expr โโโญโโโคโ
โ โ
โฐโโโโโโโโโ term โโโโโโโโโโโฏ
term:
โโโโโฎโโ factor โโ "*" โโ term โโโญโโโคโ
โ โ
โฐโโโโโโโโโ factor โโโโโโโโโโโฏ
factor:
โโโโโฎโโ "(" โโ expr โโ ")" โโโญโโโคโ
โ โ
โฐโโโโโโโโ const โโโโโโโโโโฏ
const:
โโโโ integer โโโคโ
and the same grammar output as SVG instead:
; kgt -l bnf -e svg < examples/expr.bnf > /tmp/expr.svg
Clone with submodules (contains required .mk files):
; git clone --recursive https://github.com/katef/kgt.git
To build and install:
; bmake -r install
You can override a few things:
; CC=clang bmake -r
; PREFIX=$HOME bmake -r install
You need bmake for building. In order of preference:
When you see "bmake" in the build instructions above, it means any of these.
Building depends on:
Ideas, comments or bugs: [email protected]