3 ms·
In my experience SMC ("state machine compiler", tres original no?) is better-suited than ragel for working with state machines that're easily specified as "stat
by frig 17y ago
In my experience SMC ("state machine compiler", tres original no?) is better-suited than ragel for working with state machines that're easily specified as "state charts".
The difference is that ragel is oriented around consuming a stream-of-chars: the generated state machine expects to be consuming chars as input.
You can pick up on this in the writeup even though Zed's not pointing it out: he first has to define his messages as chars (eg: 'done' == 'D'), then he specifies his states + transitions in terms of those definitions.
SMC instead generates methods for each 'message' and it's the enveloping program's responsibility to call the correct method to update the state.
This is cleaner for simpler state machines.
None of this is intended as a knock on ragel, btw: it's a very solid piece of software, and for more-complicated state machines should be the go-to choice.
- Afton 17y agoMake blog post. Post entry to HN. :)
- pcc 17y agoHonestly the smc programmers manual http://smc.sourceforge.net/SmcManual.htm http://smc.sourceforge.net/SmcManual.htm is probably good enough. Its quite light; even with a blog post one would still have to extrapolate from the author's application to how one would apply the tool to one's own problem domain. But +1 for SMC; used it quite a few times already, in many cases in new product versions replacing legacy code where the original insisted to implement a partially-identified state machine "by hand" (and invariably ended up tripping over all sorts of unforeseen and edge cases). I've also found that merely the exercise of thinking in terms of FSM definition, often helps to simplify the problem (for example by identifying that there may actually be multiple independent/"orthogonal" FSMs present, instead of one monolithic one).
- mgreenbe 17y agoSMC also seems more robust. If you look in the examples section of the manual, they describe an "FSM" that can identify palindromes on the alphabet { '0', '1', 'c' }, where 'c' indicates the center. This is not a regular language -- SMC has a stack. <http://www.cs.brown.edu/~sk/Publications/Talks/SwineBeforePerl/> http://www.cs.brown.edu/~sk/Publications/Talks/SwineBeforePe...; is a fun talk that describes an implementation of state machines in Scheme macros. With a good compiler, those tail calls will be translated to local branches!
- thurston 17y agoCorrection: ragel is not bound to chars. It can consume integral numbers of any size up to long. The numbers do not need to be in arrays. They can be embedded in structures.
- frig 17y agoThat's useful, thanks. Also thanks for this: http://news.ycombinator.com/item?id=134834 http://news.ycombinator.com/item?id=134834 It's a wonderfully useful statement, and gets at what I was trying to get at much better than I could. I stand by SMC being a better fit for simple finite state machines (eg: the kind best specified using state charts); typical uses I've put SMC towards are for ensuring consistency of internal state in complicated UI elements and similar tasks...for which there's no real 'regular language' that needs parsing (or, at least: no real gain to be had in setting up a regular language of input-events when state charts will do). I'm guessing you're the thurston behind ragel: thank you for making ragel, for making it available, and for making it so well; it is an extremely high-quality piece of work.