![]() |
![]() |
![]() |
General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
![]() |
![]() |
Tutorial on Type AnalysisDifferent Kinds of Objects
After having introduced variables to our language in the last section,
we need to indicate which kinds of program objects
exist in the language, and how are they distinguished.
So far we have types, variables, and the two predefined boolean
constants being program objects. The contexts where a type is
required are distinguished from other contexts by using the roles
of the
Furthermore we have to ensure that on the left-hand side of an
assignment there is really a variable, rather than a boolean constant.
(An erroneous use of a type is captured by the above mentioned
distinction.) That distinction can not be made using the IsVariable.pdl[24]== IsVariable: int; This macro is attached to a product file.
As
The IsVariable.lido[25]== SYMBOL ObjDecls, DefIdent: IsVariable: int; SYMBOL ObjDecls COMPUTE INH.IsVariable = 0; END; SYMBOL DefIdent COMPUTE INH.IsVariable = 0; END; RULE: Declaration ::= 'var' ObjDecls ';' COMPUTE ObjDecls.IsVariable = 1; END; RULE: ObjDecl ::= TypeDenoter DefIdent COMPUTE DefIdent.IsVariable = INCLUDING ObjDecls.IsVariable; END; SYMBOL DefIdent COMPUTE INH.GotProp = ResetIsVariable (THIS.Key, THIS.IsVariable); END; This macro is attached to a product file.
We now need to mark those contexts of the ChkVariable.lido[26]== SYMBOL Variable: VariableNeeded: int; SYMBOL Variable COMPUTE INH.VariableNeeded = 0; END; RULE: Statement ::= Variable '=' Expression ';' COMPUTE Variable.VariableNeeded = 1; END; RULE: Variable ::= UseIdent COMPUTE IF (AND (Variable.VariableNeeded, NOT (GetIsVariable (UseIdent.Key, 0))), message (ERROR, "variable required", 0, COORDREF)) <- Variable.Type; END; This macro is attached to a product file.
The dependency
(For our simple language, where only the predefined boolean
constants can violate the above condition, we could have specified
the check for variables even simpler: Just state that
|