Previous: ExpressionSymbol, Up: Expressions
An operator indication is a symbol used to represent an operation in
source program text.
For example, in Mystery the + symbol represents addition and the
AND symbol represents logical conjunction.
The operation is actually carried out by an operator, which specifies
the types of its operand and the result that it delivers.
Each Mystery operator indication identifies a single operator, but more
complex relationships are possible
(see Overloaded Indications and Procedures).
A unique definition table key is used to represent each distinct operator
indication and each distinct operator.
The type analysis computations for expressions use these keys as data,
and for that reason it is common to have rules defining operator
indications as instances of a common nonterminal that inherits the
OperatorSymbol role
(see Language-Defined Operators).
For example, the operator indications in Mystery are all defined as
instances of the nonterminal Operator:
SYMBOL Operator INHERITS OperatorSymbol END;
OperatorSymbol.Oper is set to the definition table key
of the operator identified by context-dependent computations
(see Overload resolution):
MonadicContext(`e1',`rator',`e2')DyadicContext(`e1',`rator',`e2',`e3')TriadicContext(`e1',`rator',`e2',`e3',`e4')The arguments are all grammar symbols.
Arguments `e1', `e2', `e3', and `e4' all play the
ExpressionSymbol role, with `e1' being the result;
`rator' plays the OperatorSymbol role.
Expression contexts with arbitrary numbers of operands are handled as procedure calls (see Calling a procedure).
All three Mystery operator indications are dyadic:
RULE: Expr ::= Expr Operator Expr
COMPUTE DyadicContext(Expr[1],Operator,Expr[2],Expr[3]);
END;
A particular context may fit one of these patterns,
but not include a symbol playing the OperatorSymbol role.
In that case, the `rator' argument would be omitted and the effect
of the OperatorSymbol role provided by three additional
context-dependent computations:
Indication(`ind')BadIndicationIndication is invalid,
0 otherwise.
OperName`rator'.Oper.
BadOperator`rator'.Oper is invalid, 0 otherwise.
The Mystery array reference is a monadic context that has no grammar
symbol playing the OperatorSymbol role; the appropriate operator
indication is determined by the array type
(see User-Defined Types):
RULE: Expr ::= Expr '[' Subscript ']'
COMPUTE
MonadicContext(Expr[1],,Subscript);
Indication(Expr[2].Type);
IF(OR(BadIndication,BadOperator),
message(ERROR,"Not an array",0,COORDREF));
END;
Indication and BadOperator
are also commonly used in cast constructs
(see Changing the Type of a Value).