In this section the rules for basic patterns- and references operations such as assignment, arithmetic operations, relational operations, boolean operations, etc. are further specified.
All expressions are evaluated as 32-bit values, either signed or unsigned. If an expression is assigned to a a variable representing 8- or 16-bit values, only the least significant 8- or 16-bits are assigned.
In the following a number of tables showing legal combinations of operands and result type for the operations on basic patterns and references will be given. Entries not shown are illegal. Entries marked with * are illegal. Entries marked with ! will give a compiler warning, and may become illegal in a future version of BETA. The following abbreviations will be used:
Abbreviations:
int represents an evaluation of type integer
bool represents an evaluation of type boolean
iref represents an evaluation of type item reference
cref represents an evaluation of type component reference
sref represents an evaluation of type structure reference
NONE is both an iref, a cref and an sref.
E -> V
The rows of the table shows possible types of of E and the columns of the tables show possible types of of V. The elements of the table shows the result type, which for assignment are the same as the type of V.
Note that E and C stand for arbitrary evaluations including values as in:
a+b*10 -> c
and references as in:
&P[] -> S[]
| int | char | real | bool | iref | cref | sref |
int | int | char | real | ! | * | * | * |
char | int | char | * | * | * | * | * |
real | int | * | real | * | * | * | * |
bool | ! | * | * | bool | * | * | * |
iref | * | * | * | * | iref | * | * |
cref | * | * | * | * | * | cref | * |
sref | * | * | * | * | * | * | sref |
Notes:
can only be used for the basic patterns integer, real, boolean, and char.
=, <>, <, <=, >, >=
The relational operators:
can in addition be used for references.
=, <>
It is not possible to compare a list of values as in:
(# P: (# ... exit(e1,e2,e3) #); A: (# ... exit(f1,f2,f3) #); B: @boolean do P = A -> B; P = (g1,g2,g3) -> b #)
and
E1 = E2
E1 <> E2
| int | char | real | bool | iref | cref | sref |
int | bool | bool | bool | ! | * | * | * |
char | bool | bool | bool | * | * | * | * |
real | bool | bool | bool | * | * | * | * |
bool | ! | * | * | bool | * | * | * |
iref | * | * | * | * | bool | * | * |
cref | * | * | * | * | * | bool | * |
sref | * | * | * | * | * | * | bool |
The following table shows the legal combinations of types for expressions of the form:
E1 < E2
E1 <= E2
E1 > E2
E1 >= E2
| int | char | real | bool | sref |
int | bool | bool | bool | * | * |
char | bool | bool | bool | * | * |
real | bool | bool | bool | * | * |
bool | * | * | * | bool | * |
sref | * | * | * | * | bool |
The following table shows the legal combinations of types for expressions of the form:
E1 + E2
E1 - E2
E1 * E2
| int | char | real |
int | int | int | real |
char | int | int | * |
real | real | * | real |
The following table shows the legal combinations of types for expressions on the form :
E1 div E2
Note that the div operator is integer division.
| int | char |
int | int | int |
char | int | int |
The following table shows the legal combinations of types for expressions of the form:
E1 / E2
Note that the / operator is a a real operator. The result is always a real, even if the operands are integers. If integer division is wanted, use the div operator.
| int | char | real |
int | real | real | real |
char | real | real | * |
real | real | * | real |
char is likely to be eliminated as a legal operand for / in a future version.
An xor primitive is supported as a basic operation on booleans. If E1 and E2 are boolean expressions then the expression
is an exclusive or between E1 and E2.
E1 xor E2
Boolean expressions are implemented as short-circuit boolean expressions.
That is, in:
B2 is not evaluated if B1 is true.
B1 or B2
Similarly in:
B2 is not evaluated if B1 is false.
B1 and B2
The following table shows the legal combinations of types for expressions of the form:
E1 and E2
E1 or E2
E1 xor E2
| bool |
bool | bool |
For unary expressions of the form:
+ E
- E
The legal types for E are: int, char, or real. The result type is the same as operand type
For a unary expression of the form:
not E
The type of E must be bool and the result type is bool
BETA Language Modifications - Reference Manual | © 1999-2002 Mjølner Informatics |
[Modified: Sunday October 22nd 2000 at 0:53]
|