Eli   Documents Get Eli: Translator Construction Made Easy at SourceForge.net.
    Fast, secure and Free Open Source software downloads

General Information

 o Eli: Translator Construction Made Easy
 o Global Index
 o Frequently Asked Questions
 o Typical Eli Usage Errors

Tutorials

 o Quick Reference Card
 o Guide For new Eli Users
 o Release Notes of Eli
 o Tutorial on Name Analysis
 o Tutorial on Type Analysis
 o Typical Eli Usage Errors

Reference Manuals

 o User Interface
 o Eli products and parameters
 o LIDO Reference Manual
 o Typical Eli Usage Errors

Libraries

 o Eli library routines
 o Specification Module Library

Translation Tasks

 o Lexical analysis specification
 o Syntactic Analysis Manual
 o Computation in Trees

Tools

 o LIGA Control Language
 o Debugging Information for LIDO
 o Graphical ORder TOol

 o FunnelWeb User's Manual

 o Pattern-based Text Generator
 o Property Definition Language
 o Operator Identification Language
 o Tree Grammar Specification Language
 o Command Line Processing
 o COLA Options Reference Manual

 o Generating Unparsing Code

 o Monitoring a Processor's Execution

Administration

 o System Administration Guide

Mail Home

Pattern-based Text Generator

Next Chapter Table of Contents


Introduction 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 .ptg. PTG generates a C module ptg_gen.[ch] that has one function for each pattern specified. Calls of these functions apply the patterns in order to compose an instance of the target text, which can be output by a call of PTG's output functions. Those functions may be used in LIDO specifications or in C modules which import the interface file of the generated module ptg_gen.h.

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 functions directly. For the above example a C program would contain statements like

   printf ("( %s. %s)", a, b);
where a and b are pointers to the strings to be inserted.

Such a statement implements what text to be generated by the format string and the arguments, when it is to be output by the placement of the statement within the program, and how the text is produced by format strings and output functions.

PTG separates the issues what and when by the pattern specifications (what) and the function calls (when). The calls produce an internal structure with all information necessary to output the text, rather than immediately outputting it. PTG automatically and efficiently implements the how.


Next Chapter Table of Contents