kgt

BNF wrangling and railroad diagrams

Github星跟蹤圖

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

Compilation phases:

phases.svg

  • Bold indicates the input BNF dialects with the most features
  • ✨ indicates presentational formats (these are the good ones!)
  • 🧪 indicates debugging formats.
    You don't want these unless you're looking at kgt's internals.
  • Other formats provide various subsets of features

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

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

主要指標

概覽
名稱與所有者katef/kgt
主編程語言C
編程語言Makefile (語言數: 4)
平台
許可證BSD 2-Clause "Simplified" License
所有者活动
創建於2017-02-01 05:13:03
推送於2025-04-11 03:13:56
最后一次提交2020-05-19 21:36:00
發布數0
用户参与
星數607
關注者數19
派生數31
提交數505
已啟用問題?
問題數38
打開的問題數19
拉請求數31
打開的拉請求數0
關閉的拉請求數3
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?