1. Arithmetic Expressions
2. Arithmetic Expressions with Strings
3. Arithmetic Expressions with
bool variables
4. Relational Expressions
5. Logical Expressions
Rules for assignment to bool
6. Array Expressions
Sequences with only Addops are evaluated left to right since all Addops
have the same precedence.
Sequences with only Mulops are also evaluated left to right since all
Mulops have the same precedence.
For A op B: A and B can be either real or
int for any operator.
| A | op | B | Result |
| real | +, -, * | real | real |
| real | +, -, * | int | real |
| int | +, -, * | real | real |
| int | +, -, * | int | int |
| real | / | real | real |
| real | / | int | real |
| int | / | real | real |
| int | / | int | int |
| real | % | real | int |
| real | % | int | int |
| int | % | real | int |
| int | % | int | int |
If either argument to the % (mod) operation is real, it
is truncated to an int before applying the mod operation.
| A | op | B | Result | Comment |
| string | + | string | string | Meaning: concatenate:
"abc" + "de" -> "abcde" |
| string | * | int | string | Meaning: concatenate repeat:
"abc" * 3 -> "abcabcabc" |
| string | - | int | string | Meaning: drop from back:
"abcde" - 2 -> "abc" "abcde" - 10 -> "" The int must not be negative |
| string | / | int | string | Meaning: drop from front:
"abcde" / 3 -> "de" "abcde" / 9 -> "" The int must not be negative |
| X | op | Y | Result | Comment |
| real
or int |
relop | real
or int |
bool,
value T or F |
Meaning as usual. Value is type bool.
Both must be cast to real unless both are int. |
| String
Expr |
relop | string
Expr |
bool,
value T or F |
Meaning: Ex: A < B iff A comes before B
in Dictionary listing. ** |
** I.e. the strings are compared, and if
{the ascii value of the leading character in A not
common to both}
< {the ascii value of the leading character not
common to both in B }
then A < B.
A = B means the strings are identical.
Expressions such as A < B < C are not allowed.
Or '!' X where X is an Expression.
The Expressions permitted for X and Y are coerced to bool
values T or F: i. e. Relational
Expressions, Logical Expressions, base types. The result is always
of type bool.
| LogOp | Result | Comments |
| && | bool
T or F |
X && Y is T iff
both are T. |
| || | bool
T or F |
X || Y is F
iff both are F. |
| ! | bool
T or F |
! X is T
iff X is F. |
Note that the bool type, can have only the values T or F, so assignment of a bool to an int, real, or string variable is illegal. However assignment of an int, real, or string to a variable of type bool is legal. Example:
C := X < Y is illegal unless C is of type bool.
Subroutines can return a bool value; they can take
a bool valued expression as an argument;
a return <Expression> statement can return
a bool value;
a bool can be the argument
of a write statement, which writes the character T
or F
but no bool value may be used by arithmetic operators.
Expressions of any base type can be used in the "condition" part of
"if" or "while" statements.
Before use as a condition, int, real, or string
values are converted to bool, following the rules for assignment
to bool as described below.
In an "if", if the condition value is T the "then"
statement list is executed;
if F the "else" statement list, if any, is executed.
Thus the statement:
if a < b then stringV := "T"; numV := 1;
else stringV := "F"; numV := 0; end if;
is legal. The statement:
if a < b then write "T";
else write "F"; end if;
is legal. The statement:
write a < b;
is legal, and prints the character T
or F.
NOTE: These are NOT the same as the strings "T" or "F" despite
similar appearance.
In a "while", if the condition value is T the "do" statement list is executed;
Multiplication and division of numeric arrays by numeric arrays are
not supported;
if used, these operations must be defined
in SRC3 using subs.
| ArrA | op | ArrB | ArrResult | Example | |||||||||||||||||
| int | +,- | int | int |
|
|||||||||||||||||
| real | +,- | int | error | ||||||||||||||||||
| int | +,- | real | error | ||||||||||||||||||
| real | +,- | real | real |
|
are supported, with operations done element by element.
| ArrA | op | ArrB | ArrResult | Examples | |||||||||||||||||
| string | + | string | string | Meaning: concatenate elements
|
|||||||||||||||||
| string | * | int | string | Meaning: repeat concatenate:
|
|||||||||||||||||
| string | - | int | string | Meaning: drop elements from back
|
|||||||||||||||||
| string | / | int | string | Meaning: drop elements from front
|
| ArrA | op | ScalarB | ArrResult | Comment | |||||||||||||
| array of
string |
+ | string | array of
string |
Meaning: concatenate elements
|
|||||||||||||
| array of
string |
* | int | array of
string |
Meaning: repeat concatenate:
|
|||||||||||||
| array of
string |
- | int | array of
string |
Meaning: drop elements from back
|
|||||||||||||
| array of
string |
/ | int | array of
string |
Meaning: drop elements from front
|
For C := A || B, element C[i,j] is A[i,j] || B[i,j]
.
For C := A && B, element C[i,j] is A[i,j]
&& B[i,j].
The results are shown in the table below.
| ArrA | op | ArrB | ArrResult | Examples | |||||||||||||||||
| bool | || | bool | bool |
|
|||||||||||||||||
| bool | && | bool | bool |
|
Assignment of a Logical Expression or a Relational Expression to a variable is only legal if the variable is type bool. No conversion or coercion method from bool to other types is available.
Assignment of arithmetic expressions, constants, or returns
from arithmetic functions to a real or int variable is legal
and the result is converted to the type of that variable. Assignment to
a bool variable is also legal; if the value is 0 then the
bool
has
value F,otherwise T.
Remember that reals rarely achieve the precise value 0 after
a calculation.
If the RHS is real and the LHS is int, truncation occurs.
Assignment of string expressions, constants, or string function
returns, to a variable of type string is legal. Assignment
to a bool variable is also legal;
if the string is empty then the bool has value F
, otherwise T.
Arrays may be assigned to array variables with the same size and shape.
Arrays of real or of int may be assigned to an array of
real,
or
of int, or of bool .
The output type is coerced to the declared type of the LHS Array, produced
by truncation if needed.
Arrays of string may only be assigned to arrays of string, or
of
bool.
| Formal type / Return type | Argument type / Expression type | Comment |
| int | real | truncate, then coerce to int |
| real | int | |
| bool | int, real, string | 0, 0.0, and "" are F; all other values are T. |
Expressions in the return statement may be coerced to the declared function
return type in the same fashion as argument types above.
A read statement reads in a single variable or array element.
A write statement writes an expression list, which may be empty.
A new line is emitted at the end of a write.