General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Association of properties to definitionsCount Occurrences of Objects
The computations of this module enumerate certain occurrences of
objects represented by symbols that have a 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,
The role
Let 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
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
$/Prop/OccCnt.gnrc +instance=Prnt:inst
That is easily achieved by associating the
SYMBOL IdentOcc INHERITS PrntCount, PrntTotalCnt COMPUTE IF (EQ (THIS.PrntCnt, 1), printf ("identifier %s occurs %d times\n", StringTable (THIS.Sym), THIS.PrntTotalCnt)); END;
|