reference.textile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. h1. YAKINDU SCT 2 Reference
  2. h2. State chart elements
  3. 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.
  4. The YAKINDU SCT 2 meta model is designed similar to the UML state chart meta model with the following differences
  5. * they are self contained with interfaces defined by events and variables
  6. * core execution semantics are cycle driven, not event driven
  7. ** this allows to process concurrent events
  8. ** event driven behavior can be defined on top
  9. * time is an abstract concept for state charts
  10. * time control is delegated to the environment
  11. The model interpreter and different flavors of generated code follow these same core semantics.
  12. Please refer to the description of the "UML Statecharts":http://en.wikipedia.org/wiki/UML_state_machine for more details.
  13. h3. Regions
  14. 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.
  15. !images/parallelRegions.jpg!
  16. h3. States
  17. 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.
  18. h3. Transitions
  19. A transition is the transfer of one state to another. Transitions are diagrammed as arrows and can carry events and actions but must not.
  20. 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.
  21. If a state has more than one outgoing transition without event that transition is carried out first that was modeled first.
  22. h3. Initial state and final state
  23. 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.
  24. 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.
  25. Inside a region only one initial state is allowed, but every region can have an initial state.
  26. h3. Choice
  27. Choice is also a pseudo state. It can be used to model a conditional path. Choice nodes divide a transition into multiple parts.
  28. Usually the first transition points towards the choice node. One of the choice outgoing transitions can carry a condition.
  29. h3. Junction
  30. 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.
  31. h3. Composite State
  32. 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.
  33. Composite states contain other state machine branches.
  34. h4. Orthogonal states
  35. In the context of state machines orthogonal states are states that are independent from each other. The most famous example is the keyboard example:
  36. !images/orthogonalState_example.jpg!
  37. h4. Submachine states
  38. 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.
  39. !images/substatemachine_example.jpg!
  40. h3. Shallow History
  41. 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:
  42. !images/shallowHistory01.jpg!
  43. 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.
  44. !images/shallowHistory02.jpg!
  45. !images/shallowHistory03.jpg!
  46. On triggering the _goon_ event the last active state is activated again.
  47. h3. Deep History
  48. Deep history is similar to shallow history but more complex. With a deep history the latest state of multiple nested states is remembered.
  49. h2. SText
  50. SText is the textual modeling language for the YAKINDU statecharts. It is case sensitive.
  51. h3. Typesystem
  52. SText has an integrated small typesystem with the following simple types:
  53. * integer
  54. * real
  55. * boolean
  56. * string
  57. * void
  58. So events and variables can be declared with types:
  59. bc..
  60. var intVar : integer
  61. var realVar : real
  62. var boolVar : boolean
  63. var stringVar : string
  64. var voidVar : void
  65. event addInt : integer
  66. event checkValidity : boolean
  67. h3. Expressions
  68. Expressions can be defined similar to other programming languages. SText offers operators to define logical expressions, bitwise arithmetic, and arithmetic expressions and bit shifting.
  69. Logical expressions in SText are similar to other programming languages. The return type is *boolean*. In the following there are some examples of these:
  70. h4. Logical AND
  71. bc..
  72. var1 && var2
  73. h4. Logical OR
  74. bc..
  75. var1 || var2
  76. h4. Logical NOT
  77. bc..
  78. !var1
  79. h4. Conditional expression
  80. bc..
  81. var1 ? var2 : 23
  82. h4. Bitwise XOR
  83. bc..
  84. var1 ^ var2
  85. h4. Bitwise OR
  86. bc..
  87. var1 | var2
  88. h4. Bitwise AND
  89. bc..
  90. var1 & var2
  91. h4. Logical Relations and Shift Operators
  92. |less than | < |
  93. |equal or less than | <= |
  94. |greater than | > |
  95. |equal or greater than | >= |
  96. |equal | == |
  97. |not equal | != |
  98. |shift left | << |
  99. |shift right | >> |
  100. h4. Binary arithmetic operators
  101. |plus | + |
  102. |minus | - |
  103. |multiply | * |
  104. |divide | / |
  105. |modulo | % |
  106. h4. Unary arithmetic operators
  107. |positive | + |
  108. |negative | - |
  109. |circa | ~ |
  110. h3. Statements
  111. A statements can be either an assignment, raising an event or call an operation. SText has the following assignment operators:
  112. * simple assignment: =
  113. * multiply and assign: *=
  114. * divide and assign: /=
  115. * calculate modulo and assign: %=
  116. * add and assign: +=
  117. * subtract and assign: -=
  118. * bitshift left and assign: <<=
  119. * bitshift right and assign: >>=
  120. * bitwise AND and assign: &=
  121. * bitwise XOR and assign: ^=
  122. * bitwise OR and assign: @|=@
  123. 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.
  124. An operation is called similar to other programming languages with the operation name and passing concrete parameters. The parameters can be expressions.
  125. h3. Scopes
  126. h4. Namespace
  127. SText allows to define unique namespaces, which can be used to qualify references to the statechart.
  128. bc..
  129. namespace trafficlights
  130. h4. interface scope
  131. Declarations in the interface scope are externally visible. They can be shared within the environment.
  132. bc..
  133. interface NamedInterface:
  134. in event event1
  135. out event event3
  136. var variable1 : real
  137. entrypoint entry1
  138. exitpoint exit1
  139. h4. internal scope
  140. Declarations made in an internal scope are only visible for contained states.
  141. bc..
  142. internal:
  143. var localVariable1: integer
  144. event localEvent: integer
  145. local event localEvent2: NamedInterface.event1 || localEvent
  146. local event localEvent3: localEvent || localEvent2 : 25
  147. operation localOperation (integer, integer): integer
  148. localEvent3 / raise NamedInterface.event3 :
  149. localOperation(valueOf(localEvent),NamedInterface.variable1);
  150. h3. Declarations
  151. Within scopes there can be declarations of Events, Variables, Operations, LocalReactions, EntryPoints and ExitPoints.
  152. h3. Events
  153. Within interface scope events have an direction. They can either be ingoing or outgoing:
  154. bc..
  155. interface NamedInterface:
  156. in event event1
  157. out event event2
  158. p. Within local scope events can carry variables:
  159. bc..
  160. internal:
  161. event localEvent1 : integer
  162. p. Local events can be derived from interface events or other local events and can have a value assignment:
  163. bc..
  164. internal:
  165. event localEvent1: integer
  166. local event localEvent2 = NamedInterface.event1 || localEvent1
  167. local event localEvent3 = localEvent2 || 25
  168. h3. Variables
  169. Variables can have different visibilities. They can be visible for the environment:
  170. bc..
  171. var variable1: real
  172. p. Variables can be *readonly* (constants):
  173. bc..
  174. var readonly pi: real = 3.1415
  175. p. Variables can be referenced by the environment.
  176. bc..
  177. var external variable3: integer = 34
  178. h3. Actions
  179. Actions are key constructs in state machines to model behavior. The YAKINDU SCT 2 knows the following kinds of actions.
  180. h4. after
  181. With the keyword _after_ you can model a transition after a certain period of time:
  182. bc..
  183. after 1s
  184. after 345mics
  185. after 4050ns
  186. after 1234ms
  187. h4. always
  188. The keyword always is used only for local reactions that are executed always.
  189. h4. default
  190. The keyword default marks transitions that are always accomplished.
  191. h4. else
  192. The keyword _else_ marks transitions that are carried out in case of a condition. ???
  193. h4. entry
  194. The keyword entry marks actions that are carried out on entering a state.
  195. h4. every
  196. _Every_ marks a periodic transition.
  197. h4. exit
  198. _Exit_ marks actions on leaving a state.
  199. h4. onCycle
  200. _OnCycle_ marks actions that are carried out.
  201. h3. Operations
  202. 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.
  203. bc..
  204. operation localOperation (integer, integer):integer
  205. localEvent3/ raise NamedInterface3.event1
  206. h3. LocalReactions
  207. Local reactions describe the internal behavior of a state. So they have internal scope. A local reaction is declared as follows:
  208. bc..
  209. LocalReaction: ReactionTrigger '/' ReactionEffect ('#' ReactionProperties)?
  210. ReactionTrigger: (Event ("," Event )* (=> '[' Expression ']')?) | '[' Expression ']'
  211. ReactionEffect: Statement (';' Statement )* (';')?
  212. Statement: Assignment | EventRaising | OperationCall
  213. ReactionProperties: (EntryPoint | ExitPoint)*
  214. p. Within a local reaction an interface event can be raised:
  215. bc..
  216. internal:
  217. localEvent1 / raise NamedInterface.event3 : localOperation (valueOf(localEvent), NamedInterface.variable1);
  218. p. Local reactions can have priority values. These are defined by a following # and the integer number of priority:
  219. bc..
  220. localEvent2 / NamedInterface.variable2 += 3; #1
  221. localEvent3 / NamedInterface.variable4 += 2.0; #2
  222. h3. EntryPoints
  223. Every state chart has an entry point. An entry point can be declared like the following:
  224. bc..
  225. entrypoint entry1
  226. h3. ExitPoints
  227. Every state chart has an exit point. This exit point can be declared like the following.
  228. bc..
  229. exitpoint exit1
  230. h2. SGraph
  231. 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.
  232. h2. SExec
  233. 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.
  234. h2. SGen
  235. 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.
  236. !images/sGenEditor.png!
  237. To get started with the generator model, we included a new Eclipse wizard that creates a basic configuration file with default values.
  238. !images/sGenEditor.png!
  239. To execute the Generator Model, select “Generate Model” from the context menu of the resource in the “Project Explorer”.