3 ms·
You should definitely make your states hierarchical: https://www.sciencedirect.com/science/article/pii/0167642387900359 https://www.sciencedirect.com/science/ar
by rwmj 4y ago
You should definitely make your states hierarchical: https://www.sciencedirect.com/science/article/pii/0167642387900359 https://www.sciencedirect.com/science/article/pii/0167642387... https://statecharts.dev/what-is-a-statechart.html https://statecharts.dev/what-is-a-statechart.html That's a much better way to manage the complexity of large state machines.
But I think the problem you're going to find with trying to make a "pure data" representation is how can you express a next state for a state machine if that next state depends on some decision made by running some code? You'll end up just expressing the code in an alternate language. (Maybe there's a way of doing it but I'm not seeing it ...)
Here's a custom state machine representation we came up with a while back to express the state transitions of quite a complex protocol. It looks like code (in fact, the file is *.c) but it's not normal C. It works more like yacc in that the code fragments are disentangled from the state machine and output to another C file where there is a huge, generated switch statement, but no one has to write or maintain the switch statement.
https://gitlab.com/nbdkit/libnbd/-/blob/424420a55bab1a8ec9acffe684e0bbd0dc4ec45d/generator/state_machine.ml#L262 https://gitlab.com/nbdkit/libnbd/-/blob/424420a55bab1a8ec9ac...
https://gitlab.com/nbdkit/libnbd/-/blob/424420a55bab1a8ec9acffe684e0bbd0dc4ec45d/generator/states-newstyle.c#L113 https://gitlab.com/nbdkit/libnbd/-/blob/424420a55bab1a8ec9ac...