1.1 Assignment
occam programs are built from processes. The simplest process in an occam program is an action. An action is either an assignment, an input or an output. Consider the following example:
x := y + 2
This simple example is an assignment, which assigns the value of the expression y + 2 to the variable x. The syntax of an assignment is:
assignment variable := expression
The variable on the left of the assignment symbol (:=) is assigned the value of the expression on the right of the symbol. The value of the expression must be of the same data type as the variable to which it is to be assigned, otherwise the assignment is not valid.
A multiple assignment assigns values to several variables, as illustrated in the following example:
a, b, c := x, y + 1, z + 2
This assignment assigns the values of x, y + 1 and z + 2 to the variables a, b and c respectively. The expressions on the right of the assignment are evaluated, and the assignments are then performed in parallel. Consider the following example:
x, y := y, x
The effect of this multiple assignment is to swap the values of the variables x and y.
The syntax of multiple assignment extends the syntax for assignment:
assignment variable.list := expression.list
variable.list 1 , variable
expression.list 1 , expression
A list of expressions appearing to the right of the assignment symbol (:=) is evaluated in parallel, and then each value is assigned (in parallel) to the corresponding variable of the list to the left of the symbol. The rules which govern the names used in a multiple assignment therefore follow from those for names used in parallel constructions (see page 16). Practically, this means that no name may appear twice on the left side of a multiple assignment, as the name of a variable or as the name of a variable and the name of a subscript expression which selects a component from an array .The expression on the right of the assignment symbol (:=) may be a function. A multiple result function can be an expression list in a multiple assignment..
1.2 Communication
Communication is an essential part of occam programming. Values are passed between concurrent processes by communication on channels. Each channel provides unbuffered, unidirectional point-to-point communication between two concurrent processes. The format and type of communication on a channel is .Two actions exist in occam which perform communication on a channel. They are: input and output.
1.2.1 Input
An input receives a value from a channel and assigns the received value to a variable. Consider the following
example:
keyboard ? char
This simple example receives a value from the channel named keyboard and assigns the value to the variable char. The input waits until a value is received.
The syntax of an input is:
input channel ? variable
An input receives a value from the channel on the left of the input symbol (?), and assigns that value to the variable on the right of the symbol. The value input must be of the same data type as the variable to which it is assigned, otherwise the input is not valid.
1.2.2 Output
An output transmits the value of an expression to a channel. Consider the following example:
screen ! char
This simple example transmits the value of the variable char to the channel named screen. The output waits until the value has been received by a corresponding input.The syntax of an output is:
output channel ! expression
An output transmits the value of the expression on the right of the output symbol (!) to the channel named on the left of the symbol.
1.3 SKIP and STOP
The primitive process SKIP starts, performs no action and terminates.The primitive process STOP starts, performs no action and never terminates.To explain how SKIP behaves, consider the following sequence:
SEQ
keyboard ? char
SKIP
screen ! char
This sequence executes the input keyboard ? char, then executes SKIP, which performs no action. The sequence continues, and the output screen ! char is executed. The behaviour of STOP is illustrated by the following sequence:
SEQ
keyboard ? char
STOP
screen ! char
This sequence performs the input keyboard ? char before, then executes STOP, which starts but does not terminate and so does not allow the sequence to continue. The output screen ! char is never executed.
1.4 Summary
The primitive occam processes are assignments, inputs, outputs, SKIP and STOP:
Process = assignment
| input
| output
| SKIP
| STOP