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

Association of properties to definitions

Previous Chapter Next Chapter Table of Contents


Associate Sets of Kinds to Objects

Objects in an input text are often classified to belong to one or more of several kinds, e.g. variables, procedures or labels in programming languages. They may occur in different contexts which determine their kind, require that they belong to a certain kind, or select different computations depending on their kind. Such a classification is often the part of the type analysis task.

This module can be used for any classification of objects which is encoded by non negative integral values.

The module is instantiated by

   $/Prop/KindSet.gnrc+instance=NAME +referto=KEY :inst

The module uses sets of kinds implemented by values of type unsigned int provided by the IntSet module (see Bit Sets of Integer Size of Bit Sets of Integer Size). (That module is instantiated automatically with referto parameter int, and the instance parameter omitted.) Hence the largest code chosen for a kind value must be less than the number of bits of an unsigned int (16 or 32 implementation dependent).

This module associates a property named NAMEKindSet of type IntSet to objects. Three computational roles NAMEAddKind, NAMEAddKindSet, and NAMEGetKindSet are provided.

In a context NAMEAddKind the kind value of the attribute NAMEAddKind.NAMEKind is added to the set of kinds of the object. The attribute has to be provided by a user's computation.

Similarly in a context NAMEAddKindSet the IntSet value of the attribute NAMEAddKindSet.NAMEKindSet is united to the set of kinds of the object. The attribute has to be provided by a user's computation.

In a context NAMEGetKindSet the property is accessed and supplied by the attribute NAMEGetKindSet.HasNAMEKindSet. It can be used to compare the set of required kinds to the set of associated kinds using functions of the IntSet module.

The roles AddKind and AddKindSet must not be associated to the same grammar symbol. GetKindSet may be combined with one of them. That is necessary if kinds are determined by applications of objects rather than by definitions, or if a language does not distinguish between defining and applied occurrences.

NAMERangeKindSet is automatically associated to the grammar root (see Common Aspects of Property Modules). If the NAMEKindSet property is accessed in other user's computations, those have to state NAMERangeKindSet.GotNAMEKind as precondition.

This module also provides three operations that modify NAMEKindSet properties stored in the definition module:

InsertNAMEKindSet(k,i) inserts element i into the set stored for key k, and yields the new set as result.

UnionNAMEKindSet(k,s) adds the set s to the set stored for key k, stores the result and returns it.

IntersectNAMEKindSet(k,s) intersects the set s with set stored for key k, stores the result and returns it.

We demonstrate the use of this module in our running example. It shall be analysed if each variable occurs at least once on the lefthand side of an assignment and on the righthand side. Hence, we introduce the kinds VarAssigned and VarUsed. A variable can have any set of the values depending on its occurrences. The values are named by a .head specification:

   #define   VarAssigned    1
   #define   VarUsed        2

In our tree grammar the two occurrences of variables can be distinguished for the symbol Variable rather than for the symbol UseIdent. Hence we propagate the Key attribute of UseIdent upto Variable and apply the module roles there:

   SYMBOL Variable: Key: DefTableKey;
   RULE: Variable ::= UseIdent COMPUTE
     Variable.Key = UseIdent.Key;
   END;

   RULE: Statement::= Variable '=' Expression ';' COMPUTE
     Variable.Kind = VarAssigned;
   END;

   RULE: Expression ::= Variable COMPUTE
     Variable.Kind = VarUsed
   END;

   SYMBOL Variable INHERITS AddKind END;

In the context of a variable declaration the set of kinds is checked using functions of the IntSet module:

   SYMBOL DefIdent INHERITS GetKindSet END;
   RULE: ObjDecl ::= TypeDenoter DefIdent COMPUTE
     IF (NOT (InIS (VarAssigned, DefIdent.HasKindSet)),
     printf ("variable %s declared in line %d is never assigned\n", 
              StringTable (DefIdent.Sym), LINE));

     IF (NOT (InIS (VarUsed, DefIdent.HasKindSet)),
     printf ("variable %s declared in line %d is never assigned\n",
              StringTable (DefIdent.Sym), LINE));
   END;


Previous Chapter Next Chapter Table of Contents