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


 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


 o Eli library routines
 o Specification Module Library

Translation Tasks

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


 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


 o System Administration Guide

Mail Home

Tasks related to generating output

Previous Chapter Next Chapter Table of Contents

Introducing Separators in PTG Output

The `Separator' module supplies functions to insert separator characters into the generated output in a context dependent fashion.

It provides the function Separator which is meant to be embedded in PTG patterns, e.g.

     loop: "while" [Separator] $1 [Separator] $2 [Separator]

The insertions of Separator mark the positions in the generated output texts, where separator characters might be placed.

The decision whether a separator is needed must be made by the user-supplied function Sep_Print:

     Sep_Print(PtgFilePtr file, const char *last, const char *next)
     /* On entry-
      *   file points to the output file
      *   last points to the last string printed
      *   next points to the string about to be printed
      * On exit-
      *   An appropriate separator has been added to the output file

Based on the textual context Sep_Print should decide whether a separator character is required and, if so, must insert an appropriate separator into the output stream. Note that Sep_Print is not allowed to modify either the last string printed or the string about to be printed.

The `Separator' module provides the following output functions which must be used instead of the corresponding PTG functions (see Output Functions of PTG: Pattern-based Text Generator):

PTGNode Sep_Out(PTGNode root);
PTGNode Sep_OutFile(char *filename, PTGNode root);
PTGNode Sep_OutFPtr(FILE *fptr, PTGNode root);

The `Separator' module is used in conjunction with the Unparser Generator `Idem' (see Abstract Syntax Tree Unparsing of Abstract Syntax Tree Unparsing) to simplify pretty-printing of the output. Idem inserts calls to Separator after every literal and terminal symbol in the templates corresponding to the grammar rules.


To include this module into your specification simply add the following line to one of your `.specs'-files:


An example of a Sep_Print function that works well with a C-like language is provided as `C_Separator.fw': a newline is added after any of ; { }, no separator is added after any of ( [ . ++ --, no separator is added before any of [ ] , . ; ++ --, and a single space added in all other cases.

`C_Separator.fw' can be included in your specifications by putting


into a `.specs'-file. `C_Separator.fw' is also useful as an example how to develop your own Sep_Print functions if none of the available modules is satisfactory. The simplest approach is to modify `C_Separator.fw'. Here is a sequence of Eli requests that will extract `C_Separator.fw' as file `My_Separator.fw', make `My_Separator.fw' writable, and initiate an editor session on it:

       -> $elipkg/Output/C_Separator.fw > My_Separator.fw
       -> My_Separator.fw !chmod +w
       -> My_Separator.fw <

In order to change the decision about what (if any) separator is to be inserted in a given context, you need to change `Sep_Print' function, as described above.


Since the `Separator' module uses its own PTG output functions


as explained above, it cannot be combined with specifications that influence PTG output by redefining the PTG output macros (see Influencing PTG Output of PTG: Pattern-based Text Generation).

The memory for storing the last string printed for the `Sep_Print' function is restricted to 1024 characters. If the last string printed exceeds 1024 characters, only its last 1024 characters are stored and passed to `Sep_Print'.

Previous Chapter Next Chapter Table of Contents