Data TypesPrimitive Datatypes
Occam supports five primitive types (Burns, 1988, p. 53):
- INT. An integer of length best directly supported by the hardware.
- BYTE. A single 8-bit byte for values 0 - 255.
- BOOL. Boolean type for values TRUE and FALSE.
- CHAN. Communications channel between processes.
- TIMER. A special communications channel which produces events after a specified elapsed time.
In occam, variables are declared by listing variable names after a data type. The type declaration list ends with a colon, and must precede the construction (PAR, SEQ, etc.) where the variables are used.
INT I, J: REAL32 X, Y: CHAN OF INT Out: I := 4 J := 2 X := .1E+3 Y := 97123.45
Occam assignments may be listed on a single line, as in the statement:
X, Y := Y, X
The assignments are executed in parallel, equivalent to the sequence
PAR X = Y Y = Xwhich has the behavior of swapping the values of X and Y. The parallel code is equivalent to the traditional sequential swap operation:
SEQ T = X X = Y Y = T
Occam supports the general mathematical and boolean operators, with some unique symbol representations that seem unusual today.
|Addition||I + J|
|Subtraction||I - J|
|Multiplication||I * J|
|Division||I / J|
|Remainder||I \ J|
|Equal||I = J|
|Greater Than||I > J I >= J|
|Less Than||I < J I <= J|
|Not Equal||I <> J|
|Boolean Operators||AND, OR, NOT|
|Bitwise AND||I /\ J (that's / \ )|
|Bitwise OR||I \/ J (that's \ / )|
|Bitwise XOR||I >< J|
Occam only supports binary and unary expressions! Addition, for example, may only take two operands. To perform addition between three operands, the statement must explicitly include grouping parentheses.
Arrays in occam are specified by preceding the type declaration with a size in brackets. Index values start at zero. To enumerate through arrays one element at a time, the SEQ constructor contains a named iterator, which resembles a FOR statement from other languages. An array's size may be determined using the SIZE operator.
The following code first declares a byte array (string) of 7 characters and sends its contents to the output channel. The second segment performs the same action but uses a named constant, Maxlength, to contain the size and the SIZE operator to control the iteration.
BYTE string: SEQ string := "Matthew" SEQ I = 0 FOR 7 output ! string[I] VAL INT Maxlength IS 7: [Maxlength]BYTE string: SEQ string := "Matthew" SEQ I = 0 FOR SIZE string output ! string[I]
Occam also supports record types, which are basically variables containing concatenated primitive types. However, occam's records do not allow elements to be updated individually. That is, notations such as C's
record.variable = 0;
are not possible. Occam requires the record data to be retrieved using its integer ordinal position, making the use of records unnecessarily complex.
Return to Index