3 Operations on Basic Patterns and References

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.

3.1 Assignment

The following table shows the legal combinations of the left and right side of an assignment for basic patterns and references:
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:

3.2 Relational Operators

3.2.1 Restrictions on Relational Expressions

The relational operators:
=, <>, <, <=, >, >=
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
#)

3.2.2 Type Rules for Relational Expressions

The following table shows the legal combinations of types for expressions of the form:
E1 = E2
and
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

3.3 Arithmetic Operators.

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.

3.4 Boolean Operators

3.4.1 Xor Primitive

An xor primitive is supported as a basic operation on booleans. If E1 and E2 are boolean expressions then the expression

E1 xor E2
is an exclusive or between E1 and E2.

3.4.2 Short-circuit Boolean Expressions

Boolean expressions are implemented as short-circuit boolean expressions.

That is, in:

B1 or B2
B2 is not evaluated if B1 is true.

Similarly in:

B1 and B2
B2 is not evaluated if B1 is false.

3.4.3 Type rules for boolean expressions

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

3.4.4 Unary Operators:

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]