To use the standard solution for this problem, the user must request that two generic libraries be instantiated:
The AlgScope module provides the concept of nested regions containing entities distinguished by integer Sym attributes, while the Unique module provides the concept of an error for entities that appear more than once in a region.
An attribute grammar fragment is used to connect the concepts provided by these two modules to the nodes of Figure 4:
A SetName must be unique over the region lying outside of all sets, while a SetElement must be unique over the set in which it appears. Instead of duplicating the computations necessary for checking uniqueness at each of these symbols, we can define a new symbol (Entity) and associate the computations with it. Then we specify that the symbols SetName and SetElement inherit Entity's computations.
The computations needed for a definition within a region are associated with the symbol IdDefScope exported by the AlgScope module, while the computations verifying that such a definition is unique are associated with the symbol Unique, exported by the Unique module. Entity inherits those computations from these two symbols.
Each Entity (either a SetName or a SetElement) consists of a single terminal symbol, Word, whose value was computed by mkidn when that Word was recognized. TERM can be used in a symbol computation to access that value. SYNT.Sym=TERM thus states that the Sym attribute of an Entity should be the same as the value computed for Word by mkidn. (SYNT defines the computed attribute as a synthesized attribute [WG84] of the symbol with which the computation is associated - Entity in this case.)
Computations needed at the node representing the outermost region are provided automatically by the AlgScope module. Those needed at nodes representing inner regions are associated with the symbol RangeScope, exported by the AlgScope module. In this example, a SetBody represents an inner region, and therefore SetBody inherits the RangeScope computations.