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:
- Parse the grammar.
- Feed the resulting parse tree to the pretty-print front-end asfix2abox.
- 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:
- Parse the grammar.
- Implode the resulting parse tree to an AST.
- Feed the AST to the pretty-print front-end ast2abox?
- Feed the resulting BOX expression to one of the pretty-print back-ends: abox2text?, abox2html, or abox2latex.
Examples
Assuming sdf.cons.def 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 -2 -p sdf.cons.tbl -i L.sdf -o L.asfix
# implode-asfix -i L.asfix -o L.af
# ast2abox -p sdf.cons.pp -i L.af -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
The files sdf.cons.tbl and sdf.cons.pp are installed in share/sdf-tools/ under your XT installation.
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
GenericPrettyPrinter,
HowToUseGPPWithLaTeX