General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Association of properties to definitionsAssociate Sets of Kinds to ObjectsObjects in an input text are often classified to belong to one or more of several kinds, e.g. variables, procedures or labels in programming languages. They may occur in different contexts which determine their kind, require that they belong to a certain kind, or select different computations depending on their kind. Such a classification is often the part of the type analysis task. This module can be used for any classification of objects which is encoded by non negative integral values. The module is instantiated by $/Prop/KindSet.gnrc+instance=NAME +referto=KEY :inst
The module uses sets of kinds implemented by values of type
This module associates a property named
In a context
Similarly in a context
In a context
The roles
This module also provides three operations that modify
We demonstrate the use of this module in our running example.
It shall be analysed if each variable occurs at least once on the
lefthand side of an assignment and on the righthand side.
Hence, we introduce the kinds
#define VarAssigned 1 #define VarUsed 2
In our tree grammar the two occurrences of variables can be distinguished
for the symbol
SYMBOL Variable: Key: DefTableKey; RULE: Variable ::= UseIdent COMPUTE Variable.Key = UseIdent.Key; END; RULE: Statement::= Variable '=' Expression ';' COMPUTE Variable.Kind = VarAssigned; END; RULE: Expression ::= Variable COMPUTE Variable.Kind = VarUsed END; SYMBOL Variable INHERITS AddKind END;
In the context of a variable declaration the set of kinds is checked
using functions of the
SYMBOL DefIdent INHERITS GetKindSet END; RULE: ObjDecl ::= TypeDenoter DefIdent COMPUTE IF (NOT (InIS (VarAssigned, DefIdent.HasKindSet)), printf ("variable %s declared in line %d is never assigned\n", StringTable (DefIdent.Sym), LINE)); IF (NOT (InIS (VarUsed, DefIdent.HasKindSet)), printf ("variable %s declared in line %d is never assigned\n", StringTable (DefIdent.Sym), LINE)); END; |