[ragel-users] Nested machines to make a HSM?
B. Estrade
estr... at gmail.com
Fri Jul 11 18:08:40 UTC 2008
On Fri, Jul 11, 2008 at 12:16:26PM -0500, Chuck Remes wrote:
>
> I'm currently reading "Practical Statecharts in C/C++" by Miro Samek
> which was suggested on this list some months ago. It is blowing my mind.
>
> I'm curious to know if it is possible to use ragel to nest multiple
> machines so that behavior is inherited as described in that book.
>
> If you haven't read the book, I'll give a quickie explanation. Imagine
> an oven that has 4 states:
>
> Heating
> Baking
> Toasting
> Door Open
>
> The Baking and Toasting states are substates of the Heating superstate
> because they exhibit different behavior though both require the
> heating element to be on. If the machine is in the Toasting state and
> it receives a door opened event, it transitions to Door Open. Toasting
> has no exit action of its own; it inherits an exit action
> (TurnOffHeatingElement) from its superstate, Heating.
>
> So, much like we have encapsulation and inheritance in OOP, a
> hierarchical state machine allows substates to inherit behavior from
> superstates. Here endeth the quickie overview. I hope it made some
> sense.
>
> Is this kind of inheritance (or chain of responsibility-ish) behavior
> possible in ragel? If so, how would one achieve it?
I admittedly don't know how to do this in Ragel (it's been a while since I played with it), but you can set up the heirarchy from a symbol/transition view using a regular expression.
So, if you look at it as a regex, it is something like:
H(B+T)D + D
This accepts:
HBD
HTD
D
Of course, you have to define what the valid order of things might be, otherwise you could get something super general like:
((H(B+T))*D)*
Brett
>
> cr
>
> >
More information about the ragel-users
mailing list