Home of

SMC

The State Machine Compiler

(Updated August 2, 2015)

Your application lives in a world of asynchronous, unordered events: mouse clicks, timeouts, messages, and OS signals. And you're ready for them. You've carefully designed your objects. You're using robust patterns that facilitate reuse and anticipates future product direction. Your dynamic models allow your objects to recover from all but the most catestrophic events. Your application is ready for anything.

But there's a hitch. Your detailed state diagrams are only pictures. How are you going to translate your drawings into code? A transition matrix is cryptic while switch statements means your state machine logic is scattered all over your code. The state pattern looks like a great solution but that means writing and maintaining a class for each state - too much work.

Enter SMC - The State Machine Compiler. Now you put your state diagram in one file using an easy-to-understand language. SMC generates the state pattern classes for you. No more hand-maintained transition matrices. No more widely scattered switch statements. Instead, the state diagram is in one place, coded directly from the picture to the SMC language and is easily maintained.

SMC uses the state pattern to its fullest extent. In the real world, events don't always happen when they should. Dealing with unexpected events is a must for a robust application. By combining virtual methods with the state pattern, SMC allows you to define "Default" transitions - transitions which allow your objects to handle unexpected events, recover and continue providing service (rather than crashing, burning and getting you into trouble).

SMC is a Java application. That means SMC will work on any platform where Java 1.7.0 or better is supported.


Version 6.6.0: Features and Bug Fixes.

Major Changes:

  • C++
    Added a new "-crtp" (Curiously Recurring Template Pattern) option making FSM integration into an application easier and more efficient. Instead of the user class containing an FSM data member like "AppClassContext _fsm", the user class publicly inherits the context like:
    class AppClass : public AppClassContext<AppClass>
    A transition is issued by calling the transition method directly rather than through the _fsm data member. So the call "_fsm.Open()" becomes "Open()". This removes one layer of indirection from user code.
    All C++ examples had their Makefiles updated to include two macros for the CRTP feature. Uncomment these macros and compile to see how this feature works.
  • C++ Added a new "-stack max-state-stack-depth" option. This option generates a fixed-size state stack with the specified maximumdepth. No dynamic memory is allocated for the state stack.
    Caveat: use this option only if 1) your FSM uses the push transition, and 2) your push transitions can only reach a well-defined maximum limit. Conversely, if your FSM does not use push transitions or your push limit is unbounded, then do not use this option.
    This option can be used in combination with "-noex" to create a C++ FSM which performs no dynamic memory allocation (since C++ exceptions automatically use dynamic memory allocation.)
    C++ example EX3 was updated to demonstrate this feature.

Minor changes:

  • All Added a new directive "%fsmfile" and modified the behavior or "%fsmclass". Previously, directive "%fsmclass" set both the FSM class name *and* file name. Now "%fsmclass" sets only the FSM class name and "%fsmfile" sets the file name in which it is stored.
  • C# Added the attribute [System.CodeDom.Compiler.GeneratedCode("smc", "x.x.x")] to each generated class. This attribute is used by source analyzers such as FxCop.
  • Java Updated -java7 -reflection to emit a public final class for each map. This class contains a public static final State7 field for each of the map's states. The purpose behind this feature is to restore the ability to reference states as "<map name>.<state name>". When using -java7, it is preferable to reference a state using the integer constant named "<map name>_<state name>_STATE_ID".
  • All: The -version command line option returns the wrong version.
    (SMC bug 202 )
  • -java7 generates invalid code for transitions with generic parameters.
    (SMC bug 203 )
  • Using -php and -reflect emits an incorrect name for the Default state. In Php, the Default state is named "Default_" so as not to conflict with a Php reserved word.
    (SMC bug 204 )
  • The previous state is not set in action-less transitions.
    (SMC bug 205 )
  • -java7 does not correctly fall through to the Default transition. This is due to the actual transition having a different method signature than the Default transition (which has not parameters).
    (SMC bug 206 )

Check the SMC project's Latest News to find out the latest, report bugs, ask questions, make suggestions or to learn how you can help improve this great tool.

What's New?
C JavaScript Python
C++ Lua Ruby
C# Objective-C Scala
Groovy Perl TCL
Java* PHP VB.net
See how easy it is to put SMC generated state machines into your code. This page walks you through the steps to using the State Machine Compiler. This page comes in fourteen flavors: C , C++ , C# , Groovy , Java , JavaScript , Lua , Objective-C , Perl , PHP , Python , Ruby , Scala , Tcl and VB.net .

* In Java, the state machine can be implemented using either the State Pattern or a transition table (using java.lang.invoke.MethodHandle).

Step into the picture gallery and check out the finite state machine pictures at all levels of detail, both the raw, SMC-generated version to the human-edited improvements. Graphing SMC
SMC Telephone Applet Step in, close the door and place a call. The SMC Telephone Demo is a Java applet driven by an SMC-generated finite state machine . You can watch the FSM do its thing while placing your call.
SMC Programmer's Manual And when all else fails (and only then), READ THE MANUAL!
Got questions? Then check out the Frequently Asked Questions (FAQ) page. Can't find your question? Then e-mail it to me and I will send you the answer and add it to the FAQ. SMC FAQ
Downloading SMC Alright, you're gonna bite. This page has the download links for SMC.
SMC contributers Stand up and and give them a hand! Who? Why those intrepid folks who have contributed to SMC, that's who! Find out who all make SMC the success that it is.
Is there some feature you would like to see added to SMC? Is there an irritating bug you would like to see fixed? Then make a wish. Or better yet, go here to make submit a feature request and here to submit a bug report. Your wish is my command
SourceForge.net Logo SourceForge.net has many other open source software downloads available. Surf over and check it out!
Support This Project

And in case you were wondering, SourgeForge provides all the servers, networks and software necessary to make SMC possible - without asking for anything in return!

Well I'm asking. You can now donate to the SMC project and 100% of the donation goes to SourceForge.net. If you want SMC to keep going, then we all have to keep SourceForge going.

Contacting Me
If you have any comments or questions, contact me.

Ohloh profile for cwrapp

View Charles Rapp's profile on LinkedIn


Copyright 2000 - 2009, 2011, 2013. Charles W. Rapp.
All rights reserved.