The Expression module implements type analysis in expressions
containing operators applied to operands:
$/Type/Expression.fw
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. Here are some rules defining expression nodes of a Mystery program:
RULE: Expr ::= Number END;
RULE: Expr ::= ExpIdUse END;
RULE: Expr ::= Expr Operator Expr END;
RULE: Expr ::= Expr '[' Subscript ']' END;
Each expression node is characterized by two attributes: the type of the value delivered when the expression is executed and the type required by the context in which the expression node is embedded. Type analysis must determine the values of those attributes and report an error if they are not compatible. For example, consider the following Mystery expression:
1 + (2 > 3)
The second operand of the addition is an expression delivering a Boolean value, but the addition operator cannot accept a Boolean value as an operand. Type analysis therefore reports an error in this example.
The Expression module provides both
computational roles to be inherited by symbols and
context-dependent computations to be inserted into rules:
ExpressionSymbolOperatorSymbolPrimaryContextTransferContextBalanceContextMonadicContextDyadicContextTriadicContextCastContextIndicationOperNameChkRator