Code Monkey home page Code Monkey logo

smc's Introduction

A State Machine Compiler

A long time ago, I came across Robert Martin's "State Machine Compiler" from his old web site objectmentor.com. The original SMC was in C++ and I thought it would be nice to have something like that in Java. Eventually, someone did make a Java port, but didn't upload the source since, he said, the code was not quite in good enough shape to publish. This was the situation for quite a while.

Many years later as I was looking for a coding exercise topic, I remembered this gap and decided that I should make a java port myself. Once I had it done, though, I realized that the SMC that I had written was itself a state machine and that it should be possible to write the SMC using the SMC itself. So that's what I did and that's the code that's in the "attic" directory. It's in the "attic" becuase the code itself is now a bit dated and am planning to update it to modern java coding standards. I had been again looking for a coding exercise topic (java 9+) and again remembered this bit of code.

There is java code from Mr Martin on sourceforge and github but these seem to have come out much later than the original java port mentioned above. Text of the original article, for the most part, is at smc.txt here on github.

... some time later

Well, it turns out there wasn't that much to do. Changed some 'Vector's to 'List's, reworked the internal STATE classes a bit and a few other cosmetic changes. To build the smc jar, just checkout the repo, cd into it and run the ./build script. That will bootstrap an smc.jar, generate new Action, Event and FSM classes and rebuild the smc.jar with the newly generated classes. You can sort of see how to use the fsm from the src/smc.java and smc/smcContext.java files. Basically, 'smc' drives the generated Action/Event/FSM code which in turn call into the 'smcContext' for any needed external user-supplied functionality. The simple smc fsm syntax is: fsm syntax

I'll eventually put up a separate example to make usage clearer, most probably the Turnstile example from the oritinal article.

smc's People

Contributors

benravago avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.