A very simple DSL for state-machines,

47 views
Skip to first unread message

Ron AARON

unread,
Sep 20, 2021, 6:48:33 AMSep 20
to
and a SM manager, in 8th:

https://8th-dev.com/forum/index.php/topic,2379.0.html


A SM is defined as simply as:


with: sm

sm:
:: init init-action
-> a foo
-> b bar
:: foo foo-action
etc...
sm;


The states are defined after '::', as the name of the state and the word
to invoke when "sm:act" is invoked on the state-machine (in that state).

The transitions are defined with '->' and the name of the 'verb' causing
the transition, and the new state after the transition.

In this implementation, the last defined state is assumed as the target
of any transitions, until the next state is defined.

An advantage of this particular approach is that the actions don't need
to be defined before the state-machine is, as they are "found" at
runtime. A possible refinement would be to 'compile' the machine by
doing the action look-up once, prior to using the machine.

Transitions are effected with the word 'sm:next', and actions are
performed with 'sm:act'.
Reply all
Reply to author
Forward
0 new messages