DECLARE I ARRAY(3) INTEGER, M MATRIX(2,2),
6.0 DATA MANIPULATION AND EXPRESSIONS
An expression is an algorithm used for computing a value. In HAL/S, expressions are formed by combining together operators with operands in a well-defined manner.
Operands generally are variables, literals, other expressions, and functions. The type of an expression is the type of its result, which is not necessarily the same as the types of its operands.
In HAL/S, expressions are divided into three major classes according to their usage: • regular expressions appear in a very large number of contexts throughout the
language; e.g., in assignment statements, as arguments to procedures and functions, and in I/O statements. Typical regular expressions are arithmetic, bit, and character. They are collectively denoted by <expression>.
• conditional expressions are used to express combinations of relationships between quantities, and are found in IF statements, and in WHILE and UNTIL phrases. They are denoted by <condition>.
• event expressions are used exclusively in real time programming statements. 6.1 Regular Expressions.
Regular expressions comprise arithmetic expressions, bit expressions, and character expressions, together with a limited form of structure expression. As a generic form, <expression> appears in the assignment statement as the input arguments of procedure and function blocks, and in the WRITE statement.
SYNTAX:
Figure 6-1 expression - #23
Descriptions of <arith exp, <bit exp>, <char exp>, and <structure exp> are given in the following subsections.
6.1.1 Arithmetic Expressions.
Arithmetic expressions include integer, scalar, vector, and matrix expressions. Collectively they are known by the syntactical term <arith exp>.
expression 23
arith exp
structure exp char exp bit exp
SYNTAX:
Figure 6-2 arithmetic expression - #24 SEMANTIC RULES:
1. An <arith exp> is a sequence of <arith operand>s separated by infix arithmetic operators, and possibly preceded by a unary plus or minus.
2. The form < > is used to show that the two <arith operand>s are separated by one or more spaces. It signifies a product between the <arith operand>s.
3. The syntax diagram for <arith exp> produces a sequence extensible on the right. Any sequence produced is not necessarily to be considered as evaluated from left to right. The order of evaluation of each operation in the sequence is dictated by operator precedence.
4. Not all types of <arith operand>s are legal in every infix operation. The following table summarizes all possible forms by indicating the result of each legal operation.
arith exp 24 examples: I + J -(K + 2)3 M.(M*N) * * / + _ + _ * < > . arith operand 25
Table 6-1 Infix Operators Notes:
In operations with vector and matrix operands, the sizes of the operands must be com- patible with the operation involved, in the usual mathematical sense.
outer product.
cross product - valid for 3-vectors only. dot product.
every element of the vector or matrix is multiplied by the integer or scalar. every element of the vector or matrix is divided by the integer or scalar.
if the right operand is literally “T” the transpose is indicated. If the right operand is literally “0” the result is an identity matrix. If the right operand is a positive inte- ger number, a repeated product is implied. If the right operand is a negative inte- ger number, repeated product of the inverse is implied. These are the only legal forms.
the operands are converted to scalar before division.
the operation is undefined if the value of the left operand is negative, and the value of the right operand is nonintegral.
the result is a scalar except if the right operand is a non-negative integral com- pile time constant in which case the result is an integer.
If both operands are variables, then the integer is not converted to a scalar and the base’s precision determines the precision of the calculation.
5. Except as noted in Rule 4(+), if one operand in an operation is of INTEGER type and the other operand is of SCALAR, VECTOR, or MATRIX type, the INTEGER is converted to a SCALAR before performing the operation. The precision of the INTEGER is maintained (i.e. INTEGER SINGLE is converted to SCALAR SINGLE, INTEGER DOUBLE is converted to SCALAR DOUBLE).
OPERANDS INFIX OPERATOR
LEFT RIGHT + - < > * • / * *
VECTOR VECTOR VECTOR VECTOR MATRIX1 VECTOR2 SCALAR3
VECTOR MATRIX VECTOR
MATRIX VECTOR VECTOR
VECTOR INTEGER VECTOR4 VECTOR5 VECTOR10
VECTOR SCALAR VECTOR4 VECTOR5
INTEGER SCALAR
VECTOR VECTOR4
MATRIX MATRIX MATRIX MATRIX MATRIX
MATRIX INTEGER MATRIX4 MATRIX5 MATRIX6 & 10
MATRIX SCALAR MATRIX4 MATRIX5 MATRIX6
INTEGER SCALAR
MATRIX MATRIX4
SCALAR SCALAR SCALAR SCALAR SCALAR SCALAR SCALAR8
SCALAR INTEGER SCALAR SCALAR SCALAR SCALAR SCALAR10
INTEGER SCALAR SCALAR SCALAR SCALAR SCALAR SCALAR8
INTEGER INTEGER INTEGER INTEGER INTEGER SCALAR7 INTEGER9 SCALAR 1 2 3 4 5 6 7 8 9 10
6. If the two operands of an operation are of differing precision, the result is double precision; otherwise, the precision of the result is the precision of the operands. However, when only one operand is a literal (which includes non-aggregate CONSTANTS), the precision of the result is the same as the precision of the non- literal operand. An aggregate is defined in this case as an ARRAY, STRUCTURE, VECTOR, or MATRIX.