Inspect Manual
Inspect Concepts
Inspect Manual—429164-006
2-12
Scope of Identifiers
Scope of Identifiers
The concept of scope is central to several programming languages. The scope of an
identifier determines the portion of the program in which that identifier is defined (also
referred to as the domain of an identifier). All the languages that use the concept of
scope provide some construct by which the programmer can define the boundaries of
a specific scope domain. Each language has its own name for these constructs (for
example, C calls them functions and COBOL85 calls them program units), but Inspect
groups them all under the term scope unit.
Some languages even allow one scope unit to contain other scope units (COBOL85
and Pascal, for example). In this case, the domain of an interior scope unit is defined
by the boundaries of its containing, or parent, scope unit.
Compilers for scope-dependent languages use the scope of an identifier to distinguish
it from similarly named identifiers in other scope units. Inspect uses the scope of an
identifier for exactly the same purpose.
Scope Paths
In Inspect, you define the scope of an identifier by specifying the scope path to that
identifier. The scope path is the list of scope units containing the identifier, starting with
the outermost and working down to innermost (the one containing the identifier). In
some cases, the scope path consists of a single scope unit, while in other cases it
might consist of ten or more scope units.
The general syntax you use to specify a scope path to Inspect is common to all
languages:
As an example, examine this code fragment (written in a simple pseudolanguage):
scope-unit main begin
...
scope-unit deep begin
identifiers: a,b,c
...
scope-unit deeper begin
...
scope-unit deepest begin
identifiers: x,y,z
...
end; {end of deepest}
...
end; {end of deeper}
...
end; {end of deep}
...
end; {end of main}
#scope-unit [ .scope-unit ]...