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


Count Occurrences of Objects

The computations of this module enumerate certain occurrences of objects represented by symbols that have a Key attribute. That are usually certain occurrences of identifiers.

The information computed by the module may be used for different purposes, e.g. for statistics about the input text, checks for unique occurrences, computations at the first or the last occurrence, etc.

The module is instantiated by

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

The module provides two computational roles, NAMECount and NAMETotalCnt. The roles may be associated to one or several grammar symbols.

The role NAMERangeCnt is automatically associated to the grammar root. It usually need not be used. It is not intended to provide separate counting in different parts of the tree (see Common Aspects of Property Modules).

Let k be a key, then all occurrences of k in a NAMECount context are enumerated in left-to-right depth-first order. The attribute NAMECount.NAMECnt is the number of k's occurrence with respect to this order. The total number of occurrences of k is associated as the property NAMECnt to k. The role NAMETotalCnt makes it available as an attribute NAMETotalCnt.NAMETotalCnt. If the NAMECnt property is accessed directly in user's computations, those have to state NAMERangeCnt.GotNAMECnt as precondition.

In (see Common Aspects of Property Modules), we explained how to associate these rule to grammar symbols in order to check for multiply definitions:

   SYMBOL MultDefChk    INHERITS Count, TotalCnt END;

   SYMBOL DefIdent      INHERITS MultDefChk END;
   SYMBOL ClassDefIdent INHERITS MultDefChk END;
   SYMBOL ModDefIdent   INHERITS MultDefChk END;

The check is completed by using the results of this module in computations associated to MultDefChk:

   SYMBOL MultDefChk COMPUTE
      IF (GT (THIS.TotalCnt, 1),
      message (ERROR, 
               CatStrInd ("identifier is multiply defined: ",
                          THIS.Sym),
               0, COORDREF));
   END;

The following example demonstrates a different application of this module. Assume we want to print how often each object in a program is referenced in some context. Hence, any identifier occurrence has to be counted. To avoid that this module application collides with the previous, we have to use a different instance of the OccCnt module:

   $/Prop/OccCnt.gnrc +instance=Prnt:inst

That is easily achieved by associating the Count and the TotalCnt roles to the role IdentOcc previously introduced in our running example:

   SYMBOL IdentOcc  INHERITS PrntCount, PrntTotalCnt COMPUTE
      IF (EQ (THIS.PrntCnt, 1),
      printf ("identifier %s occurs %d times\n",
              StringTable (THIS.Sym), THIS.PrntTotalCnt));
   END;


Previous Chapter Next Chapter Table of Contents