Revisión | 8d69b3e5dc86c8f05087f85798bd6aad87e4d097 (tree) |
---|---|
Tiempo | 2022-06-10 23:56:18 |
Autor | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
BUSY: FSM eval: Dezyne part added
@@ -19,4 +19,19 @@ | ||
19 | 19 | |
20 | 20 | .. seealso:: :ref:`G2C-actions` |
21 | 21 | |
22 | +.. _Declarative-programming: | |
22 | 23 | |
24 | +Declarative programming (todo) | |
25 | +============================== | |
26 | + | |
27 | +.. todo:: | |
28 | + | |
29 | + * I like a declarative style | |
30 | + | |
31 | + - describe what you need; not how to implement (the details) | |
32 | + | |
33 | + * Makefiles are a good example | |
34 | + | |
35 | + * Argparse (vs loop over argv) is a second example | |
36 | + | |
37 | + .. note:: CCastle: blog: “(1) declare what you need”. Declarative style programing. Eg loop over Argv vs argparse, makefiles |
@@ -92,16 +92,15 @@ | ||
92 | 92 | and other *modern* features however. |
93 | 93 | |
94 | 94 | |
95 | -SMC (State Machine Compiler) & friend | |
96 | -===================================== | |
95 | +SMC (State Machine Compiler) & friends | |
96 | +====================================== | |
97 | 97 | |
98 | 98 | .. include:: sidebar-SMC.irst |
99 | 99 | |
100 | 100 | There are many versions of the “State Machine Compiler”. Most use a text-input-file to specify a FSM_ and *’compile’* |
101 | -that first into source-code, that can then will be compiled “asis”. We do not discuss the tools itself, but will examine | |
102 | -the input-file. Even have defined a formal grammar; like Uncle Bob’s version, which we take as a reference. | |
101 | +that into programm-code first. Then the normal compiler is used to compile it “asis”. | |
103 | 102 | |BR| |
104 | -Some “friends” use a XML-input file, which are characterised below. | |
103 | +We do not discuss the tools itself, but will examine the input-file. And (when given) the formal grammar. | |
105 | 104 | |
106 | 105 | Uncle Bobs’s version |
107 | 106 | --------------------- |
@@ -123,8 +122,8 @@ | ||
123 | 122 | ``:``\-modifier postfixing a state, and putting the abstract-state-name between |
124 | 123 | parenthesis. |
125 | 124 | |BR| |
126 | -It is also possible to specify entry/leave(exit) action, again by postfixing state with :samp:`‘<’ {entry-action}` or | |
127 | -:samp:`‘>’ {exit-action}`. | |
125 | +It is also possible to specify entry/leave(exit) action, again by postfixing a state with :samp:`‘<’ {entry-action}` | |
126 | +or/and :samp:`‘>’ {exit-action}`. | |
128 | 127 | |
129 | 128 | The basic syntax is quite simple and readable; although whitespace as separator is not ideally --also as it make it a bit |
130 | 129 | unclear (hard to remember) what the order is. This readability issues becomes bigger when factoring-out (and the number |
@@ -205,7 +204,19 @@ | ||
205 | 204 | |BR| |
206 | 205 | Additionally, those concurren “substates” do not *exist*, whe the upper state is passive ... |
207 | 206 | |
208 | -.. centered:: Have to give it a tought ... | |
207 | +.. tip:: Have to give this a tought ... | |
208 | + | |
209 | + When ``state`` can act a small FSM_ internally, we can possible define a “concurrent state class” too. That class | |
210 | + act as state, and can have “two” (or more) FSM’s inside ... | |
211 | + | |
212 | + The inheritance-order/tree becomes complex however; `Liskov | |
213 | + <https://en.wikipedia.org/wiki/Liskov_substitution_principle>`__ should not be violated. | |
214 | + | |
215 | + * ``FSM`` is s subtype of ``state``. (as a state, is only active or not). | |
216 | + * The “concurrent one`` is also a subtype of ``state``, not containing some ``FSM``\s | |
217 | + | |
218 | + *Or, should we not inherited, but always aggregate? Sometimes 1, sometimes more...* | |
219 | + | |
209 | 220 | |
210 | 221 | No Referring |
211 | 222 | ------------ |
@@ -218,11 +229,68 @@ | ||
218 | 229 | Some other relevant languages |
219 | 230 | ***************************** |
220 | 231 | |
232 | +There are more tools (and there input languages) that can inspire us. They do not directly define a FSM_, but can be | |
233 | +used to visualize it, or use FSMs as part of the languages. | |
234 | + | |
221 | 235 | DOT/graphviz |
222 | 236 | ============ |
223 | 237 | |
224 | -- https://en.wikipedia.org/wiki/DOT_(graph_description_language) | |
225 | -- https://www.graphviz.org | |
238 | +.. sidebar:: Links | |
239 | + | |
240 | + * `https://en.wikipedia.org/wiki/DOT_(graph_description_language) | |
241 | + <https://en.wikipedia.org/wiki/DOT_(graph_description_language)>`__ | |
242 | + * https://en.wikipedia.org/wiki/Graphviz | |
243 | + * https://www.graphviz.org | |
244 | + | |
245 | +DOT is language --introduced & used by tool Graphviz-- to describe (mathematical) graphs. It’s a very flexible language: | |
246 | +both undirected and directed “edges” between “nodes” are possible; one can describe trees “woods” and more, which can | |
247 | +be cyclic (or not). When introduced (together with the autorouters graphviz), over 30 years ago, it hit the marked ... | |
248 | +|BR| | |
249 | +Suddenly we could describe & show anything ... Including state-diagrams. | |
250 | + | |
251 | +DOT, as a language, can’t define a FSM -even we can show the state-transitions. And nowadays one would prefer plantUML | |
252 | +(which used graphviz) to that. | |
253 | +|BR| | |
254 | +But it has learned us that state-transition (arrows, or edges in a graph) can be described in text as simple as | |
255 | +:samp:`{current} --> {next}`. A syntax we will reuse in Castle. | |
256 | + | |
257 | +Verum’s Dezyne | |
258 | +============== | |
259 | + | |
260 | +.. sidebar:: Links | |
261 | + | |
262 | + - https://dezyne.org | |
263 | + - https://gitlab.com/dezyne | |
264 | + - https://verum.com/discover-dezyne/ | |
265 | + - https://dezyne.org/dezyne/manual/dezyne/html_node/A-Simple-State-Machine.html | |
266 | + | |
267 | +Dezyne (now open-source) is a programming language (with a set of tools) to implement (embedded) controll software. One | |
268 | +can also create state-machines with it. So that part of the language can inspire Castle. We use `this Tutorial | |
269 | +<https://dezyne.org/dezyne/manual/dezyne/html_node/A-Simple-State-Machine.html>`__ example as reference. | |
270 | + | |
271 | +In this example the `behavior` is described in an (mostly) `“Imperative” | |
272 | +<https://en.wikipedia.org/wiki/Imperative_programming>`__ (normal) style of programming [#dezyne-semantics]_, mixed with | |
273 | +events (``on`` keywords) and guards (:samp:`[{bool-expr}]`, like above). Therefore this simple FSM is implemented in a | |
274 | +phraseology that is very close to the nested-switch one. The outer switch is replaced by pillar of guards (The lines starting | |
275 | +with ``[]`` can we top-levels cases); the inner switch by ``on`` “event-handler”. | |
276 | + | |
277 | +|BR| | |
278 | +Not shown in this example, but one use the reverted style (as far as I know). | |
279 | + | |
280 | +In away, it also resembles the “factor the state out” style as described above in the “tables” -- although de developer | |
281 | +has to use an assign-statement to change state; unlike above where naming the new state will do [#dezyne-state]_. | |
282 | +|BR| | |
283 | +Assuming one can use the “reverted” (nested-switch) style too, it is in Dezyne possible to (“in a way”) factor-out the | |
284 | +inputs (instead of the state). None of the examples above where able to this. | |
285 | + | |
286 | +For Castle, if (and only if) we enable this factor-out option (even when we do not endorse it), I would prefer to have | |
287 | +this symmetry (as in Dezyne): one can factor-out both state and/or inputs! As shown in the example, the syntax for both | |
288 | +switches is a differs a bit. By such a contrast in syntax, its become cleare wich “ID” is state an which one it de | |
289 | +“input”. And thus we can allow to swap the order, and so, it becomes possible to factor-out both. #Nice | |
290 | + | |
291 | +BTW, Dezyne uses both “declarative” and “imperative” statements. As we describe in :ref:`Declarative-programming` Castle | |
292 | +will promote this declarative style; it’s great to declare a FSM (over implement it in an imperative style). And I have | |
293 | +no glue why Dezyne made another choice... | |
226 | 294 | |
227 | 295 | |
228 | 296 | XXXXXX |
@@ -238,8 +306,6 @@ | ||
238 | 306 | - http://www.colm.net/open-source/ragel/ |
239 | 307 | |
240 | 308 | Dezyne (of Verum) |
241 | - - https://verum.com/discover-dezyne/ | |
242 | - - https://dezyne.org/dezyne/manual/dezyne/html_node/A-Simple-State-Machine.html | |
243 | 309 | |
244 | 310 | Frame |
245 | 311 | - https://modeling-languages.com/designing-hierarchical-state-machines-using-frame-notation/ |
@@ -326,15 +392,24 @@ | ||
326 | 392 | |
327 | 393 | .. [#google] |
328 | 394 | When `googling for scxml + xinclude <https://www.google.com/search?q=scxml+xinclude>`__ one find a few hits. Like |
329 | - asking it is an omission (as it was descriped in a draft), or is it removed from the spec (and forgotten to update | |
330 | - the example)? | |
395 | + the comment/question “is it an omission” (as it was descriped in a draft), or “is it removed” from the spec (and | |
396 | + *forgotten* to update the example)? | |
331 | 397 | |BR| |
332 | - There is no clear answer, but is appears that XINclude is kind of a general XML-facility; that have to be applied | |
398 | + There is no clear answer, but is appears that `XInclude` is kind of a general XML-facility; that have to be applied | |
333 | 399 | first (before using scxml). Which resembles the preprocessor. So I give up [#xml-more]_ |
334 | 400 | |
335 | 401 | .. [#xml-more] |
336 | 402 | I was kind of hoping that one coud refer to a part in another file. Like we have a common “library” scxml-file and |
337 | - use (the definitions of) a few “states” in that file. Apparently not | |
403 | + use (the definitions of) a few “states” in that file. Apparently not ... | |
404 | + | |
405 | +.. [#dezyne-semantics] | |
406 | + Notice that the style of Dezyne resembles (or “feels as”) imperative programming, but the semantics do differ! | |
407 | + | |
408 | +.. [#dezyne-state] | |
409 | + Dezyne has no “states” (at tupe/words) -- at least not in the found FSMs. Is create state by assigning value to | |
410 | + variable; that act as stare (like in C). Probably one can use the Enum type to define (simulate) state; but still one | |
411 | + has to assign that value to a variable. | |
412 | + | |
338 | 413 | |
339 | 414 | .. _FSM: https://en.wikipedia.org/wiki/Finite-state_machine |
340 | 415 | .. _State pattern: https://en.wikipedia.org/wiki/State_pattern |