General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Name analysis according to scope rulesPredefined Identifiers
In most languages some identifiers are predefined, e.g. names for
basic types or for constants like
Both modules The implementation of the modules use two functions which introduce a source identifier into the identifier table and establish a binding for it in some environment. These functions can be used directly for example in cases where predefinitions are to be established for other environments than the outermost one. Those functions are described below.
The $/Name/PreDefine.gnrc +instance=NAME +referto=IDENT :instThe optional instance parameter characterizes the name space in which
identifiers are to be predefined. The instance parameter
has to be the same as that of the basic scope rule module instance
used for that name space. Several instances of this module may address
different name spaces.
The If a grammar has several identifier terminal symbols predefinitions can be made using several instances of this module, if they belong to different name spaces.
The module provides two functions
The predefined identifiers are to be described in a file as explained below.
The name of that file has to be given as
$/Name/PreDefId.gnrc +instance=NAME +referto=(FILENAME) :instThe instance parameter has to be the same as that of the
PreDefine instance.
If this instantiation is contained in a .specs file and
if the description file, say Predef.d is contained in the
same directory, it may read
$/Name/PreDefId.gnrc +referto=(Predef.d) :instThis can also be used if the .specs file and Predef.d
are contained in a .fw specification.
The description file contains a sequence of macro calls, one for each predefined identifier, e.g. PreDefKey ("int", intKey) PreDefKey ("real", realKey) PreDefSym ("external", externSym) PreDefSymKey ("fail", failSym, failKey) PreDefSymKeyBind ("write", writeSym, writeKey, writeBind)The sequence should not contain anything else, because it is expanded in several contexts where different definitions of those macros are valid. Each call of one of the macros establishes a predefinition for one identifier, and makes the result accessible via the supplied variable names. Usually not all of those variables are needed. Hence, the available macros differ in the combinations of those variables. We first explain the most general macro. The meanings of the other macros are deduced from it.
Note: The string need not obey the
rules specified for the notation of
The variables According to the above description the following macro call PreDefSymKeyBind ("write", writeSym, writeKey, writeBind)creates the following variables to be defined and initialized as described: int writeSym; DefTableKey writeKey; Binding writeBind;
The other macros that are provided cause a subset of the effects
described for
The thus introduced variables and known keys may be used in
The described modules are based on a C module which provides the
following two functions. They may be used directly to establish
bindings in other environments than the outermost one, for example.
In that case it is sufficient to use the module The two functions are:
In our running example we introduce predefined names for some basic types and for Boolean constants by the module instantiations $/Name/PreDefine.gnrc +referto=Ident :inst $/Name/PreDefId.gnrc +referto=(Predef.d):instThe file Predef.d contains
PreDefKey ("int", intKey) PreDefKey ("real", realKey) PreDefKey ("bool", boolKey) PreDefKey ("true", trueKey) PreDefKey ("false", falseKey)Then key names like intKey can be used e.g. in computations
for type checking (see Type Analysis of Type analysis tasks).
In that case it is necessary to state that true and false
are of type bool in a .pdl specification:
trueKey -> TypeOf = {boolType}; falseKey -> TypeOf = {boolType};It associates the TypeOf property to the predefined objects.
|