General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Tutorial on Type AnalysisType Checking in ExpressionsExpressions consist of typed names and literals and of operators that are applied to operands of certain types and yield a result of a certain type. Determining the types of expressions and checking the related type rules of the language is a significant subtask of type analysis. The type rules of languages are usually formulated in terms of concepts like "type of program constructs and entities", "signature of operators", "operator overloading", "type conversion". They have common and well-understood meaning for type analysis in general. Of course, the type rules established for a particular language instantiate these concepts in a specific way, e.g. define a specific set of operators with their signature and state which conversions may be applied to resolve overloading.
Eli's type analysis module Expression module[20]== $/Type/Expression.gnrc:inst This macro is invoked in definition 26.
This module carries out type analysis on expression trees,
which are subtrees made up of connected expression nodes.
An expression node is a node representing a program construct
that yields a value of a certain type.
The module provides the role Expression symbols[21]== SYMBOL Expression INHERITS ExpressionSymbol END; SYMBOL Variable INHERITS ExpressionSymbol END; This macro is invoked in definition 27.
The type of each expression node is characterized by two attributes:
Expression symbols may occur in different contexts with respect to
the structure of the expression trees: root contexts, leaf contexts, and
inner contexts. The module provides different computational roles
for those contexts. In leaf contexts the type of the leaf expression
must be stated using the computational role Leaf nodes[22]== RULE: Expression ::= IntNumber COMPUTE PrimaryContext (Expression, intType); END; RULE: Expression ::= 'true' COMPUTE PrimaryContext (Expression, boolType); END; RULE: Expression ::= 'false' COMPUTE PrimaryContext (Expression, boolType); END; RULE: Variable ::= UseIdent COMPUTE PrimaryContext (Variable, UseIdent.Type); END; This macro is invoked in definition 27.
The computational role Transfer nodes[23]== RULE: Expression ::= Variable COMPUTE TransferContext (Expression, Variable); END; This macro is invoked in definition 27.
The node representing an assignment statement has two children.
Both are considered as roots of expression trees.
For the Assignment[24]== RULE: Statement ::= Variable '=' Expression ';' COMPUTE RootContext (Variable.Type, , Expression); Indication (assignOpr); END; This macro is invoked in definition 27.
The An expression in the role of a statement is another example for a root context. On execution the value of the expression will just be discarded. Hence, there is no requirement on its type to be stated or checked: Expression statement[25]== RULE: Statement ::= Expression ';' END; This macro is invoked in definition 27. Expression.specs[26]== Expression module[20] This macro is attached to a product file. Expression.lido[27]== Expression symbols[21] Leaf nodes[22] Transfer nodes[23] Assignment[24] Expression statement[25] This macro is attached to a product file.
|