h1. YAKINDU SCT 2 Reference h2. State chart elements In the following the state chart elements of the YAKINDU SCT 2 editor are described. The meta model of the YAKINDU SCT 2 is the model of finite state machines. It is based on the view of a system that is defined by a finite number of states. The behavior of that system is based on the active states. These states are determined by the history of the state machine. Very important are the theoretical models for state machines by Mealy and Moore. Mealy state machines associate actions with transitions. Moore machines associate actions with states (entry, exit). In the YAKINDU SCT 2 both is possible. The YAKINDU SCT 2 meta model is designed similar to the UML state chart meta model with the following differences * they are self contained with interfaces defined by events and variables * core execution semantics are cycle driven, not event driven ** this allows to process concurrent events ** event driven behavior can be defined on top * time is an abstract concept for state charts * time control is delegated to the environment The model interpreter and different flavors of generated code follow these same core semantics. Please refer to the description of the "UML Statecharts":http://en.wikipedia.org/wiki/UML_state_machine for more details. h3. Regions As already mentioned the YAKINDU state charts are self contained. They are organized in regions. Due to this it is possible to organize multiple state machines in different regions and to run them concurrently. !images/parallelRegions.jpg! h3. States States are the central elements of a state machine. A state has to be placed inside a region and needs a unique name inside this region. During simulation each state can be active or passive. An active state has actions that are accomplished. Either an action is carried out on entering a state, during active state or on exit. h3. Transitions A transition is the transfer of one state to another. Transitions are diagrammed as arrows and can carry events and actions but must not. The syntax of events and actions is defined by the language "SText":#SText. Please refer to the documentation section "Events":#Events for more details. For more details on Actions refer to the chapter "Actions":#Actions. If a state has more than one outgoing transition without event that transition is carried out first that was modeled first. h3. Initial state and final state Initial and final states are pseudo states, because the state chart does not rest on them. Pseudo states express characteristics that are impossible to express by simple states. The initial state is always the first state that is active during interpretation or simulation of the state machine. An initial state can only have one outgoing transition and no incoming. This transition has no events or actions. Inside a region only one initial state is allowed, but every region can have an initial state. h3. Choice Choice is also a pseudo state. It can be used to model a conditional path. Choice nodes divide a transition into multiple parts. Usually the first transition points towards the choice node. One of the choice outgoing transitions can carry a condition. h3. Junction A junction is a pseudo state do combine transitions. This is very comfortable if a state machine has many similar transitions. Junctions add clear arrangement to the state machine. h3. Composite State A composite state is a state that is composed of other state machines. These are also organized in regions. Besides the simple composite state YAKINDU knows two kinds of composite states: orthogonal state and submachine states. Composite states contain other state machine branches. h4. Orthogonal states In the context of state machines orthogonal states are states that are independent from each other. The most famous example is the keyboard example: !images/orthogonalState_example.jpg! h4. Submachine states Submachine states may contain complete state machines. Here the user can chose another state machine to be included or create a new sub statemachine. During simulation only the top level statemachine is interpreted. It is not possible to jump to the sub level state machines and back. !images/substatemachine_example.jpg! h3. Shallow History The shallow history state is a pseudo state that is placed inside regions of composite states. It is used to 'remember' the last active state inside a composite state. So it is possible to jump to this state instead of starting at the inner entry state again. The following example of a questionaire answering will explain this: !images/shallowHistory01.jpg! The interesting parts in this state chart are the events _checkProgress_ and _goon_. CheckProgress jumps back to the init state while assigning the current progress count to the variable _temp_. _goon_ jumps to the shallow history state that was placed inside the composite state. !images/shallowHistory02.jpg! !images/shallowHistory03.jpg! On triggering the _goon_ event the last active state is activated again. h3. Deep History Deep history is similar to shallow history but more complex. With a deep history the latest state of multiple nested states is remembered. h2. SText SText is the textual modeling language for the YAKINDU statecharts. It is case sensitive. h3. Typesystem SText has an integrated small typesystem with the following simple types: * integer * real * boolean * string * void So events and variables can be declared with types: bc.. var intVar : integer var realVar : real var boolVar : boolean var stringVar : string var voidVar : void event addInt : integer event checkValidity : boolean h3. Expressions Expressions can be defined similar to other programming languages. SText offers operators to define logical expressions, bitwise arithmetic, and arithmetic expressions and bit shifting. Logical expressions in SText are similar to other programming languages. The return type is *boolean*. In the following there are some examples of these: h4. Logical AND bc.. var1 && var2 h4. Logical OR bc.. var1 || var2 h4. Logical NOT bc.. !var1 h4. Conditional expression bc.. var1 ? var2 : 23 h4. Bitwise XOR bc.. var1 ^ var2 h4. Bitwise OR bc.. var1 | var2 h4. Bitwise AND bc.. var1 & var2 h4. Logical Relations and Shift Operators |less than | < | |equal or less than | <= | |greater than | > | |equal or greater than | >= | |equal | == | |not equal | != | |shift left | << | |shift right | >> | h4. Binary arithmetic operators |plus | + | |minus | - | |multiply | * | |divide | / | |modulo | % | h4. Unary arithmetic operators |positive | + | |negative | - | |circa | ~ | h3. Statements A statements can be either an assignment, raising an event or call an operation. SText has the following assignment operators: * simple assignment: = * multiply and assign: *= * divide and assign: /= * calculate modulo and assign: %= * add and assign: += * subtract and assign: -= * bitshift left and assign: <<= * bitshift right and assign: >>= * bitwise AND and assign: &= * bitwise XOR and assign: ^= * bitwise OR and assign: @|=@ An event is raised by the keyword _raise_ followed by the event name and if it is an interface event the name of the interface. An operation is called similar to other programming languages with the operation name and passing concrete parameters. The parameters can be expressions. h3. Scopes h4. Namespace SText allows to define unique namespaces, which can be used to qualify references to the statechart. bc.. namespace trafficlights h4. interface scope Declarations in the interface scope are externally visible. They can be shared within the environment. bc.. interface NamedInterface: in event event1 out event event3 var variable1 : real entrypoint entry1 exitpoint exit1 h4. internal scope Declarations made in an internal scope are only visible for contained states. bc.. internal: var localVariable1: integer event localEvent: integer local event localEvent2: NamedInterface.event1 || localEvent local event localEvent3: localEvent || localEvent2 : 25 operation localOperation (integer, integer): integer localEvent3 / raise NamedInterface.event3 : localOperation(valueOf(localEvent),NamedInterface.variable1); h3. Declarations Within scopes there can be declarations of Events, Variables, Operations, LocalReactions, EntryPoints and ExitPoints. h3. Events Within interface scope events have an direction. They can either be ingoing or outgoing: bc.. interface NamedInterface: in event event1 out event event2 p. Within local scope events can carry variables: bc.. internal: event localEvent1 : integer p. Local events can be derived from interface events or other local events and can have a value assignment: bc.. internal: event localEvent1: integer local event localEvent2 = NamedInterface.event1 || localEvent1 local event localEvent3 = localEvent2 || 25 h3. Variables Variables can have different visibilities. They can be visible for the environment: bc.. var variable1: real p. Variables can be *readonly* (constants): bc.. var readonly pi: real = 3.1415 p. Variables can be referenced by the environment. bc.. var external variable3: integer = 34 h3. Actions Actions are key constructs in state machines to model behavior. The YAKINDU SCT 2 knows the following kinds of actions. h4. after With the keyword _after_ you can model a transition after a certain period of time: bc.. after 1s after 345mics after 4050ns after 1234ms h4. always The keyword always is used only for local reactions that are executed always. h4. default The keyword default marks transitions that are always accomplished. h4. else The keyword _else_ marks transitions that are carried out in case of a condition. ??? h4. entry The keyword entry marks actions that are carried out on entering a state. h4. every _Every_ marks a periodic transition. h4. exit _Exit_ marks actions on leaving a state. h4. onCycle _OnCycle_ marks actions that are carried out. h3. Operations Operations can have none, one or multiple parameters. The parameters are only declarated by their type. An operation can have one return type similar to Java. bc.. operation localOperation (integer, integer):integer localEvent3/ raise NamedInterface3.event1 h3. LocalReactions Local reactions describe the internal behavior of a state. So they have internal scope. A local reaction is declared as follows: bc.. LocalReaction: ReactionTrigger '/' ReactionEffect ('#' ReactionProperties)? ReactionTrigger: (Event ("," Event )* (=> '[' Expression ']')?) | '[' Expression ']' ReactionEffect: Statement (';' Statement )* (';')? Statement: Assignment | EventRaising | OperationCall ReactionProperties: (EntryPoint | ExitPoint)* p. Within a local reaction an interface event can be raised: bc.. internal: localEvent1 / raise NamedInterface.event3 : localOperation (valueOf(localEvent), NamedInterface.variable1); p. Local reactions can have priority values. These are defined by a following # and the integer number of priority: bc.. localEvent2 / NamedInterface.variable2 += 3; #1 localEvent3 / NamedInterface.variable4 += 2.0; #2 h3. EntryPoints Every state chart has an entry point. An entry point can be declared like the following: bc.. entrypoint entry1 h3. ExitPoints Every state chart has an exit point. This exit point can be declared like the following. bc.. exitpoint exit1 h2. SGraph SGraph is the metamodel for the graphical part of the statechart editor. It owns all core elements of a state machine like states, pseudostates, transitons etc. but it describes how these elements shall be shown by the editor. h2. SExec SExec is the name of an intermediate execution model. This intermediate model is used behind the scenes as a foundation for the code generators and the simulation engine. This guarantees that the simulation behaves in the same way as the generated Statechart implementations. It captures the execution behavior and may also serve as the basis of custom code generators. h2. SGen All generators can be customized with a generator model. This is a textual model file where generator features, like i.e. the outlet path, can be specified. The following screenshot shows an example configuration for the java code generator. In future releases, we will add generator features for the execution type (event or cycle based), interface styles (static or generic) and much more. !images/sGenEditor.png! To get started with the generator model, we included a new Eclipse wizard that creates a basic configuration file with default values. !images/sGenEditor.png! To execute the Generator Model, select “Generate Model” from the context menu of the resource in the “Project Explorer”.