Reactive scripts provide a flexible approach, allowing parallelism, distribution, object orientation, and preemption primitives.
The language contains an original combination of event-driven synchronous programming with broadcast communication and object based programming, including dynamic creation of objects.
- await E waits for event E to be generated. (events need not be declared before being used). Event configurations extend this to more general situations where one waits for the simultaneous occurrence of several events, the occurrence of one amongst several events, or for the absence of an event (resp. and, or, and not constructs).
- generate E generates event E. Generation of an event concerns only the current reaction, and is lost for the future (events are not persistent). Events are broadcast that is, execution of generate E fires all the await E commands that are stored in the interpretor. Finally, generation of an already generated event has no effect.
An important point however is that the action controlled by the absence of an event will be delayed to the next reaction, following the absence decision principle which states that reaction to absence is always postponed to the next instant. The end of the reaction is the precise moment one is sure the event is definitely absent and not to delay reactions to event absences would cause trouble (often called ``causality problems''), as in:
await not E;generate E
where E would be generated during the same reaction it is absent. This would violate the basic broadcast hypothesis of reactive scripts, which states that the presence/absence of an event is the same in the whole system.
- External statements like assignments, procedure calls or printing statements are always put between ``{'' and ``}''. In this paper, of course we use Java syntax.
- Commands are grouped in blocks : they are executed in sequence when separated by ``;'' and in parallel when separated by ``||'' ; a parallel block terminates when all its branches do (parentheses are used for precedence purposes).
- The stop command defines the end of instant in a sequence for the current interpretor reaction. It is the new starting point for the next reaction. The stop command is needed to trigger execution of a command by several occurrences of the same event. For example, the following command prints message Two! after two occurrences of E:
await E;stop;await E;{Out.println("Two!"}
- The next command forces the interpretor to execute the next reaction as soon as the current one is over.
- Cyclic behaviors are defined using the loop operator. The loop body is run as soon as the command is entered, and when it terminates it is automatically restarted.
A problem would appear if a loop body would terminate in the same reaction it is started (one speaks of an ``instantaneous loop''), as in:
loop {System.out.println("OK!")} end
Execution would cycle producing infinitely many OK!, and would prevent the interpretor to terminate the current reaction.
Instantaneous loops are detected at run time.
- There are two test commands: if which tests for boolean conditions, and when which tests for events. Tests of events always obey the absence decision principle. For example, consider:
when E then
generate F
else
generate G
end
Event F is generated if E occurs in the current reaction; otherwise, G is generated in the next reaction.
- The until statement is the basic preemption operator of reactive scripts. It executes its body and terminates for two reasons: either because the body terminates, and in this case termination of the until is immediate; or because a given event occurs (the case of actual preemption), and then termination of the until depends on the body, accordingly to the absence decision principle. For example consider the command:
do
await E;{System.out.println("E!")}
||
await F;{System.out.println("F!")}
until G;
{Out.println("Terminated!")}
If G does not occurs before both E and F does, then all works as if the until command was not there: E! is printed as soon as E occurs, F! is printed as soon as F occurs, and Terminated! is printed simultaneously with the last event, as then the body of the until terminates. On the contrary, if G occurs while E or F have not yet occurred, then the until command is exited at the next reaction and Terminated! is printed at that time.
An ``actual'' part can be added to a until command, to be executed only in case of actual preemption.
- Execution of a command can be controlled by the occurrence of an event, using the control operator. Actually, the body of a control command is executed only during reactions where the controlling event occurs. For example, the following command prints a message only when E occurs:
control
loop {System.out.println("OK!")};stop end
by E