LinuxCommandLibrary

dcg

Compile and load Datalog programs

TLDR

Start a wizard to choose what kind of code (e.g. module, service, form, etc.) to generate

$ dcg
copy

Directly specify the kind of code to generate
$ dcg [service|plugin|theme|module|form]
copy

Generate the code in a specific directory
$ dcg --directory [path/to/directory]
copy

SYNOPSIS

dcg [OPTION]... [inputfile]

PARAMETERS

-h, --help
    Display usage information and exit

-V, --version
    Output version information and exit

-o FILE, --output=FILE
    Set output PostScript file (default: grammar.ps)

-s NUM, --scale=NUM
    Set diagram scaling factor (default: 1.0)

-p SIZE, --page=SIZE
    Set page size: a4 or letter (default: a4)

-l, --landscape
    Use landscape page orientation

--no-title
    Omit grammar title from diagram

DESCRIPTION

dcg is a utility for generating visual syntax diagrams (also known as railroad diagrams) from context-free grammars specified in a BNF-like notation.

It reads grammar rules from an input file or standard input and produces a PostScript output file depicting the grammar's structure graphically. This is particularly useful for documentation, teaching parsers, or compiler development where visualizing recursive and alternative productions aids understanding.

The tool supports non-terminals, terminals, repetitions (e.g., <list> ::= <item> *), options, and grouping. Diagrams are drawn horizontally or vertically as needed, with automatic layout. Output can be scaled, paged (A4/letter), and oriented landscape/portrait.

dcg is lightweight, dependency-free for basic use, but requires a PostScript viewer like gv(1) or converter like ps2pdf(1) for PDF. It's ideal for LaTeX integration via epsfig.

CAVEATS

Input must use strict BNF syntax; ambiguities or cycles may produce suboptimal layouts.
Generates PostScript only—no direct SVG/PDF/HTML output.
Large grammars can result in wide or multi-page diagrams requiring manual adjustment.

INPUT FORMAT EXAMPLE

<grammar> ::= <rule> *
<rule> ::= <nonterminal> ::= production ;
Example:
prog ::= stmt * ;
stmt ::= if expr then stmt | expr ;

OUTPUT USAGE

View with gv dcg.ps or convert: ps2pdf grammar.ps grammar.pdf for PDF.

HISTORY

dcg was developed by Andreas Scherer in the late 1990s for TeX users. First released around 1998, it's maintained in Debian since 2001 (dcg 0.8.1). Focuses on simplicity for BNF visualization, predating web-based tools like Railroad Diagram Generator.

SEE ALSO

dot(1), gv(1), ps2pdf(1), graphviz(1)

Copied to clipboard