How To Pretty Print AGrammar

XT -- A Bundle of Program Transformation Tools
Task

How to pretty-print a grammar.

Description

A grammar can be pretty-printed (to plain text, html, or latex) using the GPP package in the following way:

  1. Parse the grammar.
  2. Feed the resulting parse tree to the pretty-print front-end asfix2boxGPP.
  3. Feed the resulting BOX expression to one of the pretty-print back-ends: box2textGPP, box2htmlGPP, or box2latexGPP.

Alternatively, a grammar can be pretty-printed using the ast2box tool:

  1. Parse the grammar.
  2. Implode the resulting parse tree to an AST.
  3. Feed the AST to the pretty-print front-end ast2abox.
  4. Feed the resulting BOX expression to one of the pretty-print back-ends: abox2text, abox2html, or abox2latex.

Examples

Assuming sdf.cons.sdf is the grammar of Sdf and Sdf.cons.pp is a pretty-print table for Sdf, a grammar L.sdf can be pretty-printed to text, html and latex in the following way:

  # sdf2table -i sdf.cons.def -o sdf.cons.tbl
  # sglr -p sdf.cons.tbl -i L.sdf -o L.af
  # implode-asfix -i L.af -o L.asdf
  # ast2abox -p sdf.cons.pp -i L.asdf -o L.sdf.abox
  # abox2text -i L.sdf.abox -o L.sdf.text
  # abox2html -i L.sdf.abox -o L.sdf.html
  # abox2latex -i L.sdf.abox -o L.sdf.tex

Tip: use locate to find sdf.cons.tbl and sdf.cons.pp in your XT installation.

[Note: when trying this with XT 0.7 abox2html and abox2latex don't seem to work -- EelcoVisser - 26 Jun 2001]

The file L.sdf.tex can be included in a latex document, which has the following package statement in its preamble:

  \usepackage{boxenv}
In the file L.sdf.tex you can read where to find the file boxenv.sty (See HowToUseGPPWithLaTeX).

See also

GPP, HowToUseGPPWithLaTeX