Eli   Documents

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 Scope Graphs
 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

Previous Chapter Next Chapter Table of Contents


Some Useful Techniques

This chapter describes some techniques that solve common tasks in PTG applications.

Output of Data Items

Usually data items like numbers, identifiers, or strings which are computed by the translation process or taken from the input are to be inserted into the output text at certain positions. This is best achieved by using typed insertion points as described in See Typed Insertion Points.

It is often necessary to convert single data items into a PTGNode pointer to be used in pattern applications. This can be achieved by defining patterns for single data items:

   Number:    $ int
   String:    $ string
   StringLit: "\"" $ string "\""
Such patterns are applied by calls like PTGNumber(5), PTGString("+"), PTGStringLit("Hello!") producing the text items 5, +, and "Hello!" respectively.

Predefined patterns for the conversion of single data items to PTGNode pointers can also be found in a module of the specification library, see also see Commonly used Output patterns for PTG of Tasks related to generating output.

This module also solves the problem of generating a PTGNode that generates a data item of the input text, e.g. identifiers or floating point numbers, on output.

Generating Identifiers

Common techniques for producing identifiers are recommended especially for translation into programming languages. In the simplest case identifiers are just reproduced from the input as shown above. The following set of patterns allow to add prefixes or postfixes to the original identifiers (see See Typed Insertion Points):

   PointerId: "PTR_" $ string
   ValueId:   "VAL_" $ string
   UniqueId:  $ string $ int
Patterns like the first two may be used to generate different output identifiers from one input identifier. The last pattern allows to attach a number to an identifier, e.g. to guarantee uniqueness in the output in cases where the source and the target language have different scope rules.

Note: PTG does not add any white space between pattern items. Hence, patterns where identifiers or numbers may be inserted have to ensure that the component tokens are separated, e.g.

   Decl: $ /* Type */ " " $ /* Ident */

Output of Sequences

The construction of output text often requires to compose arbitrary long sequences of items, e.g tokens, statements, or procedures. Some simple techniques for those tasks are described here. The examples can easily be generalized for similar applications.

A generally applicable pattern for constructing sequences is

   Seq: $ $
An application

   PTGSeq (PTGString("."), PTGSeq (PTGString("."), PTGString(".")))
produces a sequence of 3 dots, assuming pattern String is suitably defined.

The following C loop computes a sequence of n dots:

   PTGNode dots = PTGNULL; int i;
   for (i=0; i<n; i++) dots = PTGSeq (dots, PTGString("."));

Sequences where the items are separated by a certain string, e.g. a comma or a space character can be specified by

   CommaSeq: $ {", "} $
An application

   PTGCommaSeq (PTGNumber (1), PTGNumber (2))
produces 1, 2, assuming pattern Number be suitably defined.

The following C loop computes a comma separated sequence of the numbers 1 to n:

   PTGNode numseq = PTGNULL; int i;
   for (i=1; i<=n; i++)
     numseq = PTGCommaSeq (numseq, PTGNumber (i));


Previous Chapter Next Chapter Table of Contents