Skip to content
/ kgt Public
forked from katef/kgt

BNF wrangling and railroad diagrams

License

Notifications You must be signed in to change notification settings

kimusan/kgt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KGT: Kate's Grammar Tool

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

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

expr.svg

Clone with submodules (contains required .mk files):

; git clone --recursive https://github.com/katef/kgt.git

To build and install:

; pmake -r install

You can override a few things:

; CC=clang PREFIX=$HOME pmake -r install

Building depends on:

  • Any BSD make. This includes OpenBSD, FreeBSD and NetBSD make(1) and sjg's portable bmake (also packaged as pmake).

  • A C compiler. Any should do, but GCC and clang are best supported.

  • ar, ld, and a bunch of other stuff you probably already have.

Ideas, comments or bugs: kate@elide.org

About

BNF wrangling and railroad diagrams

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 97.1%
  • Makefile 2.3%
  • Other 0.6%