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 asfix2abox.
  3. Feed the resulting Box expression to one of the pretty-print back-ends: abox2text?, abox2html, or abox2latex.

Alternatively, a grammar can be pretty-printed using the ast2abox? 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 G.tbl is the parse table for a grammar of language L and G.pp is the corresponding pretty-print table. A term T.sdf over langauge L can be pretty-printed to text, html and latex in the following way:

  # sglr -2 -p G.tbl -i T.sdf -o T.asfix
  # implode-asfix -i T.asfix -o T.af
  # ast2abox -p G.pp -i T.af -o T.sdf.abox
  # abox2text -i T.sdf.abox -o T.sdf.text
  # abox2html -i T.sdf.abox -o T.sdf.html
  # abox2latex -i T.sdf.abox -o T.sdf.tex

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

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

See also

GenericPrettyPrinter, HowToUseGPPWithLaTeX

Revision: r1.6 - 18 May 2005 - 06:44 - MerijnDeJonge
Tools > HowToPrettyPrintAGrammar
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback