Name Analysis Reference Manual
Most programming languages use natural-language representations for some
basic entities.
For example, the two Boolean values are often represented as
true and false .
There are two mechanisms for introducing such representations into a
programming language:
- Keyword
- A unique basic symbol of the language.
Keywords have neither defining nor applied occurrences,
and their meanings never change.
- Pre-defined identifier
- A normal identifier, subject to the normal scope rules for identifiers,
with a pre-definition in a particular range.
Pre-defined identifiers have applied occurrences, but there is no defining
occurrence for the pre-definition.
They can be re-defined by defining occurrences in other ranges.
Pre-definitions are established by the SGPreDefId module,
instantiated in a `specs' file with or without an instance argument:
$/Name/SGPreDefId.gnrc +instance=NAME +referto=(FILENAME) :inst
$/Name/SGPreDefId.gnrc +referto=(FILENAME) :inst
The instance parameter must have the same value as that of the
ScopeGraphs module for which the pre-definition is intended.
The referto parameter gives the name of the file containing the
descriptions of the pre-definitions.
If the SGPreDefId module is instantiated,
then the MakeName module must be instantiated to encode identifiers
(see Generating Optional Identifiers of Solutions of Common Problems).
For example, if Ident is the basic symbol denoting an identifier,
then the MakeName module instantiation would be:
$/Tech/MakeName.gnrc +instance=Ident:inst.
A set of pre-definitions is enumerated in the file whose name is the
referto argument of the SGPreDefId instantiation.
Each pre-definition is specified by a macro call.
The macro call may have some or all of the following arguments:
_str
- is the literal string being pre-defined.
_sym
- is the name of an integer-valued variable that will be set to the
unique integer value derived from the
_str argument by the
MakeName module.
If this argument is omitted, no variable is set.
_key
- is the name of the
DefTableKey -valued known key
representing the entity bound to the _str argument by
this pre-definition
(see How to specify the initial state of Definition Table).
If this argument is omitted, no entity is associated with the identifier.
_env
- is a
NodeTuplePtr value specifying the range in which the
pre-definition occurs.
If this argument is omitted, the *Env attribute of
the root symbol of the grammar is assumed.
_ndx
- is an integer value specifying the graph index of the pre-definition
(see Isomorphic Scope Graphs).
If this argument is omitted, 0 is assumed.
The string argument need not obey the
rules specified for the notation of identifier symbols.
(Thus artifacts can be defined that cannot be referred to
by a name in a program.)
There is no need to separately declare variables or known keys.
The appearance of the variable name or known key name as a macro argument
ensures that it is declared.
Variable names and known key names are available for use in
LIDO specifications;
known key names may also be used in any other specification that has
access to the definition table
(see Top of Definition Table).
The pre-definition file must contain a sequence of macro calls,
with each macro call establishing a single pre-definition.
The sequence should not contain any other code or text.
Different pre-definitions may require different sets of arguments,
and unfortunately the macro facility used requires each macro name to be
associated with a specific set of arguments.
Thus we have nine macros, all of which do the same thing.
Choose the macro that fits the set of arguments you need to describe the
specific pre-definition:
PreDefSymKeyEnvNdx(_str,_sym,_key,_env,_ndx)
PreDefSymKeyEnv(_str,_sym,_key,_env)
PreDefSymKeyNdx(_str,_sym,_key,_ndx)
PreDefSymKey(_str,_sym,_key)
PreDefSym(_str,_sym)
PreDefKeyEnvNdx(_str,_key,_env,_ndx)
PreDefKeyEnv(_str,_key,_env)
PreDefKeyNdx(_str,_key,_ndx)
PreDefKey(_str,_key)
In some cases, it may be necessary to pre-define ranges
(for example, the range owned by the pre-defined Object class in Java)
Therefore the module also provides macro calls for this purpose.
Each call may have some or all of the following arguments:
_key
- is the name of a
DefTableKey -valued known key allowing the developer
to associate a pre-defined entity with this range
(see The RangeScope role).
It may have the value NoKey , indicating no association.
_range
- is the name of a
NodeTuplePtr -valued variable that is set by this
pre-definition and will be used as the _env argument for
subsequent macro calls.
_env
- is a
NodeTuplePtr value specifying the parent of the pre-defined range
(see The RangeScope role).
If this argument is omitted, the root symbol of the grammar is assumed.
Again we have the issue of different argument patterns needing different
macro names:
PreDefNodeEnv(_key,_range,_env)
PreDefNode(_key,_range)
Pre-definitions are established before name analysis begins.
|