Previous: ExpressionSymbol, Up: Expressions


2.2 Operations

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')
is used in the context of an expression whose operator has a single operand (e.g. negation).
DyadicContext(`e1',`rator',`e2',`e3')
is used in the context of an expression whose operator has two operands (e.g. addition).
TriadicContext(`e1',`rator',`e2',`e3',`e4')
is used in the context of an expression whose operator has three operands

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')
Used to supply the operator indication that would normally come from the `rator' symbol. Argument `ind' is the definition table key of the desired operator indication.
BadIndication
Yields 1 if the operator indication supplied by Indication is invalid, 0 otherwise.
OperName
Yields the operator that would normally be the value of `rator'.Oper.
BadOperator
Yields 1 if the operator that would normally be the value of `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).