next up previous contents
Next: 2.5.5 An example of Up: 2.5 More Examples Previous: 2.5.3 An example of   Contents

2.5.4 An example of enter/exit actions

Enter actions of a state are written under the ENTER descriptor. Exit actions are written under the EXIT descriptor. There may be multiple ENTER or EXIT descriptors.

The N (new state) property of an ENTER descriptor specifies the state that is entered. The S (source state) property of an EXIT descriptor specifies the state that is exited.

The following example (enterexit1.des) demonstrates the use of enter actions and exit actions.

STATECHART:
    A [DS]
    B [FS]

ENTER:
    N: A
    O: [DUMP("enter A")]

EXIT:
    S: A
    O: [DUMP("exit A")]

ENTER:
    N: B
    O: [DUMP("enter B")]

TRANSITION:
    S: A
    N: B
    E: e
    O: [DUMP("transition from A to B")]

The result of the simulation is:

enter A
['A'] > e
transition from A to B
exit A
enter B
['B'] > exit

In this example, enter actions are defined for states A and B to print out simple messages. An exit action is also defined for state A. A transition changes the model from state A to state B. In its output (O property), a message is also printed.

From the output, one may notice that output of the transition that causes the state change is executed before exit actions, and exit actions are before enter actions. This semantics of DCharts conforms to the original statecharts semantics proposed by David Harel. In addition to this fact, in one single transition, exit actions of a state are always executed before the exit actions of superstates of that state. Conversely, enter actions of a state are always executed after the enter actions of superstates of that state.

A global option ``Harel'' specifies whether the semantics of a model strictly conforms to the David Harel's semantics. By default it is set to true. A designer may override this option to false to use the alternative semantics. (This option is discussed later.)


next up previous contents
Next: 2.5.5 An example of Up: 2.5 More Examples Previous: 2.5.3 An example of   Contents
Thomas Huining Feng
2004-04-05