General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Pattern-based Text GeneratorIntroduction to PTG
A PTG specification is a set of named patterns describing the structure
and textual components of an output text. They are contained
in files of type Consider the following simple example: Assume we want to produce parenthesized representations of binary trees like S-expressions in LISP:
((1.nil).(2.(3.nil))We specify three named patterns, one for the parenthesized structure, one for the literal nil , and one for numbers:
Pair: "(" $ "." $ ")" Nil: "nil" Numb: $ int For each of these patterns PTG generates a function which yields an internal representation of a pattern application. The following nested calls produce the above output text:
PTGOut ( PTGPair ( PTGPair(PTGNumb(1), PTGNil()), PTGPair(PTGNumb(2), PTGPair(PTGNumb(3), PTGNil())) ));Of course one may store intermediate results of pattern applications and defer output until the target text is completely composed:
n1 = PTGPair (PTGNumb (1), PTGNil ()); n2 = PTGPair(PTGNumb(2), PTGPair(PTGNumb(3), PTGNil())); PTGOut (PTGPair (n1, n2));
The benefits of using PTG can best be described by a comparison
with using C
printf ("( %s. %s)", a, b);where a and b are pointers to the strings to be inserted.
Such a statement implements
PTG separates the issues
|