reference.textile 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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 a textual description language (#Statechartdescriptionlanguage). Please refer to the documentation section "Events":#Events for more details. For more details on Actions refer to the chapter "Actions":#ReactionTriggers.
  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. Statechart description language
  50. The textual description language is used to declare and describe behaviors in the state machine. It is case sensitive.
  51. h3. Typesystem
  52. The language 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. The language offers operators to define logical expressions, bitwise arithmetic, and arithmetic expressions and bit shifting.
  69. Logical expressions 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. The language 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. ==<!-- Start stext_keyword_namespace -->==
  127. h4. Namespace
  128. The language allows to define unique namespaces, which can be used to qualify references to the statechart.
  129. bc..
  130. namespace trafficlights
  131. p. ==<!-- End stext_keyword_namespace -->==
  132. ==<!-- Start stext_keyword_interface -->==
  133. h4. interface scope
  134. Declarations in the interface scope are externally visible. They can be shared within the environment.
  135. bc..
  136. interface NamedInterface:
  137. in event event1
  138. out event event3
  139. var variable1 : real
  140. entrypoint entry1
  141. exitpoint exit1
  142. p. ==<!-- End stext_keyword_interface -->==
  143. ==<!-- Start stext_keyword_internal -->==
  144. h4. internal scope
  145. Declarations made in an internal scope are only visible for contained states.
  146. bc..
  147. internal:
  148. var localVariable1: integer
  149. event localEvent: integer
  150. local event localEvent2: NamedInterface.event1 || localEvent
  151. local event localEvent3: localEvent || localEvent2 : 25
  152. operation localOperation (integer, integer): integer
  153. localEvent3 / raise NamedInterface.event3 :
  154. localOperation(valueOf(localEvent),NamedInterface.variable1);
  155. p. ==<!-- End stext_keyword_internal -->==
  156. h3. Declarations
  157. Within scopes there can be declarations of Events, Variables, Operations, LocalReactions, EntryPoints and ExitPoints.
  158. ==<!-- Start stext_keyword_event -->==
  159. h3. Events
  160. Within interface scope events have an direction. They can either be ingoing or outgoing:
  161. bc..
  162. interface NamedInterface:
  163. in event event1
  164. out event event2
  165. p. Within local scope events can carry variables:
  166. bc..
  167. internal:
  168. event localEvent1 : integer
  169. p. Local events can be derived from interface events or other local events and can have a value assignment:
  170. bc..
  171. internal:
  172. event localEvent1: integer
  173. local event localEvent2 = NamedInterface.event1 || localEvent1
  174. local event localEvent3 = localEvent2 || 25
  175. p. ==<!-- End stext_keyword_event -->==
  176. ==<!-- Start stext_keyword_var -->==
  177. h3. Variables
  178. Variables can have different visibilities. They can be visible for the environment:
  179. bc..
  180. var variable1: real
  181. p. Variables can be *readonly* (constants):
  182. bc..
  183. var readonly pi: real = 3.1415
  184. p. Variables can be referenced by the environment.
  185. bc..
  186. var external variable3: integer = 34
  187. p. ==<!-- End stext_keyword_var -->==
  188. h3. Reaction Triggers
  189. Actions are key constructs in state machines to model behavior. The YAKINDU SCT 2 knows the following kinds of actions.
  190. ==<!-- Start stext_keyword_after -->==
  191. h4. after
  192. The _after_ trigger specifies one-shot time events.
  193. After the specified time the reaction is triggered. An _after_ trigger can be used in transitions of states as well in local reactions of states and statecharts. The specified time starts when the state or statechart is entered.
  194. bc. after 20 s
  195. Structure:
  196. @after@ _@time@_ (_@unit@_)?
  197. The time unit can be:
  198. * ==<!-- Start stext_keyword_s -->== s - seconds ==<!-- End stext_keyword_s -->==
  199. * ==<!-- Start stext_keyword_ms -->== ms - milliseconds ==<!-- End stext_keyword_ms -->==
  200. * ==<!-- Start stext_keyword_us -->== us - microseconds ==<!-- End stext_keyword_us -->==
  201. * ==<!-- Start stext_keyword_ns -->== ns - nanoseconds ==<!-- End stext_keyword_ns -->==
  202. * empty - implies seconds
  203. p. ==<!-- End stext_keyword_after -->==
  204. ==<!-- Start stext_keyword_every -->==
  205. h4. every
  206. The _every_ trigger specifies periodic time events.
  207. The reaction is triggered periodically after the specified time. An _every_ trigger can be used in transitions of states as well in local reactions of states and statecharts. The specified time starts when the state or statechart is entered and repeats periodically.
  208. bc. every 200 ms
  209. Structure:
  210. @every@ _@time@_ (_@unit@_)?
  211. The time unit can be:
  212. * s - seconds
  213. * ms - milliseconds
  214. * us - microseconds
  215. * ns - nanoseconds
  216. * empty - implies seconds
  217. ==<!-- End stext_keyword_every -->==
  218. ==<!-- Start stext_keyword_always -->==
  219. h4. always
  220. This trigger is always true and enables a reaction to be executed in every run to completion step (RTS). It is equivalent to _oncycle_.
  221. ==<!-- End stext_keyword_always -->==
  222. ==<!-- Start stext_keyword_default -->==
  223. ==<!-- Start stext_keyword_else -->==
  224. h4. default, else
  225. The _default_ trigger is equivalent to the _else_ trigger. It is intended for use for the outgoing transitions of _choice_ pseudo states, to make sure that always an outgoing transition can be taken. It can only be be used in transitions and implies the lowest evaluation priority for that transition.
  226. ==<!-- End stext_keyword_else -->==
  227. ==<!-- End stext_keyword_default -->==
  228. ==<!-- Start stext_keyword_entry -->==
  229. h4. entry
  230. An _entry_ trigger marks actions that are carried out on entering a state or state machine.
  231. ==<!-- End stext_keyword_entry -->==
  232. ==<!-- Start stext_keyword_exit -->==
  233. h4. exit
  234. An _exit_ trigger marks actions that are carried out on exiting a state or state machine.
  235. ==<!-- End stext_keyword_exit -->==
  236. ==<!-- Start stext_keyword_oncycle -->==
  237. h4. oncycle
  238. The _oncycle_ trigger is always true and enables a reaction to be executed in every run to completion step (RTS). It is equivalent to _always_.
  239. ==<!-- End stext_keyword_oncycle -->==
  240. ==<!-- Start stext_keyword_operation -->==
  241. h3. Operations
  242. 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.
  243. bc..
  244. operation localOperation (integer, integer):integer
  245. localEvent3/ raise NamedInterface3.event1
  246. p. ==<!-- End stext_keyword_operation -->==
  247. h3. LocalReactions
  248. Local reactions describe the internal behavior of a state. So they have internal scope. A local reaction is declared as follows:
  249. bc..
  250. LocalReaction: ReactionTrigger '/' ReactionEffect ('#' ReactionProperties)?
  251. ReactionTrigger: (Event ("," Event )* (=> '[' Expression ']')?) | '[' Expression ']'
  252. ReactionEffect: Statement (';' Statement )* (';')?
  253. Statement: Assignment | EventRaising | OperationCall
  254. ReactionProperties: (EntryPoint | ExitPoint)*
  255. p. Within a local reaction an interface event can be raised:
  256. bc..
  257. internal:
  258. localEvent1 / raise NamedInterface.event3 : localOperation (valueOf(localEvent), NamedInterface.variable1);
  259. p. Local reactions can have priority values. These are defined by a following # and the integer number of priority:
  260. bc..
  261. localEvent2 / NamedInterface.variable2 += 3; #1
  262. localEvent3 / NamedInterface.variable4 += 2.0; #2
  263. p. ==<!-- Start stext_keyword_entrypoint -->==
  264. h3. EntryPoints
  265. Every state chart has an entry point. An entry point can be declared like the following:
  266. bc..
  267. entrypoint entry1
  268. p. ==<!-- End stext_keyword_entrypoint -->==
  269. ==<!-- Start stext_keyword_exitpoint -->==
  270. h3. ExitPoints
  271. Every state chart has an exit point. This exit point can be declared like the following.
  272. bc..
  273. exitpoint exit1
  274. p. ==<!-- End stext_keyword_exitpoint -->==
  275. h2. SGraph
  276. 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.
  277. h2. SExec
  278. 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.
  279. h2. SGen
  280. 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.
  281. To get started with the generator model, we included a new Eclipse wizard that creates a basic configuration file with default values.
  282. !images/sGenEditor.png!
  283. The generator model is associated with the builder. If *Project* > *Build Automatically* is checked the files are generated. In the following the specific customizing features of the generator models are explained.
  284. h3. Generator model for Java
  285. The generator model for Java is used to customize the generation of Java code from the state chart model.
  286. h4. Feature Outlet
  287. With the feature *Outlet* you define the folder the source files will be generated in:
  288. bc..
  289. feature Outlet {
  290. targetProject = "org.terra.coffee.machine"
  291. targetFolder = "src-gen"
  292. }
  293. h4. Feature LicenseHeader
  294. With the feature Licence header you can set a licence text that is added to the headers of all generated files:
  295. bc..
  296. feature licenseHeader {
  297. licenseText = "Copyright (c) 2012 itemis AG.
  298. All rights reserved."
  299. }
  300. h4. Feature Debug
  301. The feature debug controls the output of debug information. An important information source is the intermediate model sExec.
  302. bc..
  303. feature Debug {
  304. dumpSexec = false
  305. }
  306. h4. Feature FunctionInlining
  307. bc..
  308. feature FunctionInlining {
  309. inlineChoices=true
  310. inlineEnterRegion=true
  311. inlineEnterSequences=true
  312. inlineEntries=true
  313. inlineEntryActions=true
  314. inlineExitActions=true
  315. inlineExitRegion=true
  316. inlineExitSequences=true
  317. inlineReactions=true
  318. }
  319. h4. Feature GeneralFeatures
  320. bc..
  321. feature GeneralFeatures {
  322. EventBasedStatemachine=true
  323. GenericInterfaceSupport=true
  324. InterfaceObserverSupport=true
  325. RuntimeService=false
  326. StatemachineFactorySupport=true
  327. TimerService=true
  328. }
  329. h4. Feature Naming
  330. bc..
  331. feature Naming {
  332. basePackage="org.java"
  333. implementationSuffix="ipl"
  334. }
  335. h3. Generator model for C
  336. h4. Feature Outlet
  337. The feature is similar to the target language Java.
  338. h4. Feature LicenseHeader
  339. The feature is similar to the target language Java.
  340. h4. Feature Debug
  341. The feature is similar to the target language Java.
  342. h4. Feature CCodeFeature
  343. bc..
  344. feature CCodeFeature {
  345. DebugType="DEBUG"
  346. InterfaceEventListener=false
  347. Singleton=true
  348. }
  349. h4. Feature FunctionInlining
  350. h3. Generator model for C++
  351. h4. Feature Outlet
  352. The feature is similar to the target language Java.
  353. h4. Feature LicenseHeader
  354. The feature is similar to the target language Java.
  355. h4. Feature Debug
  356. The feature is similar to the target language Java.
  357. h4. Feature FunctionInlining