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

Tasks related to generating output

Previous Chapter Next Chapter Table of Contents


Commonly used Output patterns for PTG

The module PtgCommon provides definitions for frequently used PTG patterns. These patterns fall into two categories: The first one supports different types of output leaves; the second contains frequently used patterns for building sequences.

The module does not have generic parameters. It is used by including

   $/Output/PtgCommon.fw
in a .specs file.

The module introduces PTG specifications for patterns named Id, AsIs, CString, PString, CChar, Numb, Seq, CommaSeq. When using PtgCommon.fw these names must not be specified in any other PTG specification.

The functions provided by this module may be used in `.lido' specifications or in `.c' files. To introduce prototypes for the defined functions, use the header file PtgCommon.h.

Frequently Used Patterns

The module PtgCommon provides useful and commonly used PTG patterns, especially for the output of non-literal terminal symbols. They are documented both by showing their PTG pattern definitions and the signature of the resulting pattern functions:

Pattern: Id: [PtgOutId $ int]
Resulting Function: PTGNode PTGId(int id)
The argument id must refer to an identifier or a string stored in the character storage module of Eli, see Character Storage Module of Library Reference Manual. The PTG pattern produces the same identifier or character string in the output.

Pattern: AsIs: $ string
Resulting Function: PTGNode PTGAsIs(char *string)
The PTG pattern produces the specified argument string in the output. The character string is not copied, only the pointer is.

Pattern: Numb: $ int
Resulting Function: PTGNode PTGNumb(int numb)
The PTG pattern produces the given integral number.

Pattern: CString: [CPtgOutstr $ string]
Resulting Function: PTGNode PTGCString(char *string)
and PTGNode PTGCStringId(int id)
The argument is a string. The PTG pattern function produces the same character string quoted according to the rules of the C language. PTGCStringId is macro based on PTGCString. It takes an index into the character storage module of Eli, see Character Storage Module of Library Reference Manual. It produces the string stored there quoted according to the rules of the C language..

Pattern: PString: [PPtgOutstr $ string]
Resulting Function: PTGNode PTGPString(char *string)
and PTGNode PTGPStringId(int id)
The argument is a string. The PTG pattern function produces the same character string quoted according to the rules of the Pascal language. PTGPStringId is macro based on PTGPString. It takes an index into the character storage module of Eli, see Character Storage Module of Library Reference Manual. It produces the string stored there quoted according to the rules of the Pascal language..

Pattern: CChar: [CPtgOutchar $ int]
Resulting Function: PTGNode PTGCChar(int c)
The PTG pattern produces the specified value as C character literal.

Pattern: Seq: $ $
Resulting Function: PTGNode PTGPSeq(PTGNode, PTGNode)
Takes two arguments and yields a new node that prints the concatenation of the given patterns.

Pattern: CommaSeq: $ { ", " } $
Resulting Function: PTGNode PTGPCommaSeq(PTGNode, PTGNode)
Takes two arguments and yields their concatenation separated by a comma. By enclosing the separator with braces, it is assured that a comma will be printed, only if none of the arguments refers to the predefined value PTGNULL that yields an empty output. This makes the pattern well suited to be used in conjunction with the CONSTITUENTS construct. See Optional Parts in Patterns of Pattern-based text generator, for details.

Pattern: Eol: $ "\n"
Resulting Function: PTGNode PTGEol(PTGNode)
This pattern attaches a newline at the end of the given text. Note that the PTG output functions do not automatically put a newline at the end of the output.

Useful Embedded Functions

The functions embedded in the PTG patterns defined in PTGCommon.fw (See Commonly used Output patterns for PTG) might also be useful in user defined patterns. These functions are:

void PtgOutId (PTG_OUTPUT_FILE fs, int c);
takes an index into the character storage module of Eli, see Character Storage Module of Library Reference Manual. It outputs the string stored there.

void CPtgOutstr (PTG_OUTPUT_FILE fs, char *s);
takes a string argument and outputs the same string quoted according to the rules of the C language.

void CPtgOutchar (PTG_OUTPUT_FILE fs, int c);
takes an integer character code and outputs the character.

void PPtgOutstr (PTG_OUTPUT_FILE fs, int c);
takes a string argument and outputs the same string quoted according to the rules of the Pascal language.

Examples

The first example will use a PTG pattern that prints an identifier or a floating point number. This is done by defining the symbol role PtgLeaf that computes a ptg attribute. It generates the source text of the identifier when processed through a ptg processing function. This role can be inherited by a tree symbol that appears directly above a terminal, that was processed through the mkidn gla processor.

   CLASS SYMBOL PtgLeaf: ptg: PTGNode;

   CLASS SYMBOL PtgLeaf COMPUTE
      THIS.ptg = PTGId(TERM);
   END;

In this example, the class symbol PtgLeaf can be used later to denote all the different grammar symbols that compute ptg leaf patterns. This is done for example in the second example, that computes a PTG pattern that prints all occurrences of PtgLeaf in a comma separated list.

   CLASS SYMBOL LeafCommaList: ptg: PTGNode;
   CLASS SYMBOL LeafCommaList COMPUTE
      THIS.ptg =
        CONSTITUENTS PtgLeaf.ptg
        WITH (PTGNode, PTGCommaSeq, IDENTICAL, PTGNull);
   END;

Please refer to Symbol Specifications of Lido Reference Manual, for an explanation of symbol computations, see CONSTITUENT(S) of Lido Reference Manual, for an explanation of the CONSTITUENT(S)-construct and read Predefined Entities of Lido Reference Manual, for an explanation of the predefined IDENTICAL-function.

Special Situation when Using C String Literals

A special situation occurs, if C string literals are input tokens and are to be reproduced identically. Two different token processors can be used to store the string: If the c_mkstr processor is specified in a `.gla' file,

   CStringLit: $\" (auxCString) [c_mkstr]
the string is interpreted and the result is stored. Such a string can be processed with the pattern functions PTGCStringId() and PTGPStringId() to yield C or Pascal string literals on output. However, as strings are null terminated in Eli, the first occurrence of an embedded zero-character terminates the string, and the result is truncated. A solution for this would be to not interpret the control sequences and to store the string verbatim as it is provided on input. That is achieved by the token processor mkstr:
   CStringLit: $\" (auxCString) [mkstr]
As control sequences are not interpreted by mkstr, PTGPString and PTGCString can not be used to produce an identical output string. Instead, the pattern function PTGAsIs is to be used. Since the latter token processor can handle embedded zero characters, it is used in the canned description C_STRING_LIT for C string literals. See Canned Descriptions of Lexical Analysis.


Previous Chapter Next Chapter Table of Contents