SlideShare a Scribd company logo
SMC
The State Machine Compiler               (40 ’)




  François Perrad
  francois.perrad@gadz.org




                   fperrad@OSDC.fr2009
The State Machine Compiler
   Introduction
   Basic concepts
   Advanced concepts
   More features
   A case study : a Telephone
   Conclusion



                 fperrad@OSDC.fr2009
FSM are everywhere
   FSM : Finite State Machine
   Not a new technology
   Strong theorical base
   Reactive systems / Transformational
    systems
   Event driven
   Applications :
       Telephones, automobiles, communication
        networks, avionic systems, man-machine
        interface

                  fperrad@OSDC.fr2009
FSM graphical view
   Moore
   Mealy
   Grafcet
   UML = Harel statechart




                  fperrad@OSDC.fr2009
A SourceForge project
   Some facts :
       registered in 2000
       ~500 downloads / month
       ~100 bugs (closed)
       written in Java
       mature codebase
       well documented
       3 developers
       Licence MPL

   See :
    http://www.ohloh.net/projects/7339?p=SMC

                     fperrad@OSDC.fr2009
The State Machine Compiler
   Introduction
   Basic concepts
   Advanced concepts
   More features
   A case study : a Telephone
   Conclusion



                 fperrad@OSDC.fr2009
A Compiler
   A input source .sm (yacc-like syntax)
   A output source (readable) in your language
   Currently 14 target languages :
       C, C++, C#, Groovy, Java, Lua, Objective-C, Perl, PHP,
        Python, Ruby, Scala, Tcl and VB.net
   An Object Oriented design :
       your class has a member which is the FSM generated class
   A small RunTime Library
   Parser & Lexer of SMC are written with SMC
   The root of SMC is ATN (Augmented Transition
    Network)
   Robert C. Martin (uncle bob) is the author of the
    initial SMC implementation
                           fperrad@OSDC.fr2009
A Simple Transition
// State 
Idle {
   // Trans    Next State        Actions 
   Run         Running           {} 
} 




                 fperrad@OSDC.fr2009
A Reflexive Transition
// State 
Idle { 
   // Trans    Next State  Actions 
   Timeout     Idle        {} 
} 




                 fperrad@OSDC.fr2009
A Internal Event
// State
Idle { 
   // Trans    Next State  Actions 
   Timeout     nil         {} 
} 




                 fperrad@OSDC.fr2009
A Transition with Actions
// State 
Idle 
{ 
   // Trans 
   Run 
      // Next State 
      Running 
             // Actions 
             { 
                 StopTimer("Idle"); 
                 DoWork(); 
             } 
} 



                     fperrad@OSDC.fr2009
Transition Guards
// State 
Idle 
{ 
    // Trans 
    Run 
    // Guard condition 
    [ctxt.isValid()] 
       // Next State 
       Running 
              // Actions 
              { 
                  StopTimer("Idle"); 
                  DoWork(); 
              } 

    Run       Idle    { RejectRequest(); } 
} 
                        fperrad@OSDC.fr2009
Transition Arguments
// State 
Idle 
{ 
    // Transition 
    Run(msg: const Message&) 
    // Guard condition 
    [msg.isValid()] 
        // Next State 
        Running 
       // Actions 
       { 
           StopTimer("Idle"); 
           DoWork(msg); 
       } 
    Run(msg: const Message&) 
        // Next State Actions 
        Idle          { RejectRequest(msg); } 
} 
                          fperrad@OSDC.fr2009
Entry and Exit Actions
// State 
Idle 
Entry { StartTimer("Idle", 1); CheckQueue(); } 
Exit { StopTimer("Idle"); } 
{ 
   // Transitions 

} 




                     fperrad@OSDC.fr2009
the State Machine Compiler
   Introduction
   Basic concepts
   Advanced concepts
   More features
   A case study : a Telephone
   Conclusion



                 fperrad@OSDC.fr2009
Advanced Features
   Map : state container
       only one level (multiple with UML)
   Push/Pop
       with stack context
       see UML History
   Default state
        factorisation of common behavior
        in a map
   No concurrency (ie //)
                 fperrad@OSDC.fr2009
The Design Pattern




       fperrad@OSDC.fr2009
the State Machine Compiler
   Introduction
   Basic concepts
   Advanced concepts
   More features
   A case study : a Telephone
   Conclusion



                 fperrad@OSDC.fr2009
More features
   Event management is yours
   Graphviz output generation
   HTML table generation
   Dynamic trace
   Namespace support
   Reflection/Introspection (for MMI)




               fperrad@OSDC.fr2009
Graphviz output




       fperrad@OSDC.fr2009
the State Machine Compiler
   Introduction
   Basic concepts
   Advanced concepts
   More Features
   A case study : a Telephone
   Conclusion



               fperrad@OSDC.fr2009
A Telephone
   Go to the WEB
   Play with the demo (Applet Java)
@   http://smc.sourceforge.net/SmcDemo.htm




                   fperrad@OSDC.fr2009
the State Machine Compiler
   Introduction
   Basic concepts
   Advanced concepts
   More Features
   A case study : a Telephone
   Conclusion



                 fperrad@OSDC.fr2009
all contributions welcomed
   Eclipse plugin
   Debian packaging
   Pluggable language support
   New target language
   Regression test
   …




                fperrad@OSDC.fr2009
Bibliography / Webography
- SMC : http://smc.sourceforge.net/
- Robert C. Martin, "Agile Software Development"
- http://en.wikipedia.org/wiki/Finite_state_machine
- http://en.wikipedia.org/wiki/Statechart
- D. Harel, "Statecharts: A Visual Formalism for Complex
     Systems"
- http://www.uml.org/
- http://fr.wikipedia.org/wiki/Grafcet
- NF C03-190 - Diagramme fonctionnel "GRAFCET"
- http://en.wikipedia.org/wiki/Augmented_transition_network




                         fperrad@OSDC.fr2009

More Related Content

PPT
Learning for semantic parsing using statistical syntactic parsing techniques
PPTX
PDF
Theory of Computation Lecture Notes
PPS
Java rmi example program with code
PDF
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
PPT
M03 2 Behavioral Diagrams
PPTX
1.8. equivalence of finite automaton and regular expressions
PPT
JDBC
Learning for semantic parsing using statistical syntactic parsing techniques
Theory of Computation Lecture Notes
Java rmi example program with code
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
M03 2 Behavioral Diagrams
1.8. equivalence of finite automaton and regular expressions
JDBC

What's hot (20)

PPT
PDF
Internationalization
PPT
Working with frames
PPTX
minimization the number of states of DFA
PPTX
State
PPT
Hibernate
PPTX
Servlet and Servlet Life Cycle
PDF
Servlet and servlet life cycle
PPTX
List manipulation
PPTX
Classes, Objects and Method - Object Oriented Programming with Java
PPTX
Event Handling in Mobile Application Development.pptx
PPTX
The State Design Pattern
PPT
Slides ppt
PPT
Java Basics
PPT
Basic using of Swing in Java
PPT
Log4 J
PPTX
003 - JavaFX Tutorial - Layouts
PPT
Unified Modeling Language
Internationalization
Working with frames
minimization the number of states of DFA
State
Hibernate
Servlet and Servlet Life Cycle
Servlet and servlet life cycle
List manipulation
Classes, Objects and Method - Object Oriented Programming with Java
Event Handling in Mobile Application Development.pptx
The State Design Pattern
Slides ppt
Java Basics
Basic using of Swing in Java
Log4 J
003 - JavaFX Tutorial - Layouts
Unified Modeling Language
Ad

Similar to The State Machine Compiler (20)

PPT
Open Source XMPP for Cloud Services
PPTX
ECI OpenFlow 2.0 the Future of SDN
PDF
Model_Driven_Development_SDR
PDF
Crushing Latency with Vert.x
PPTX
Infrastructure as Code in your CD pipelines - London Microsoft DevOps 0423
PPT
Virtual platform
PPT
Erlang OTP
PDF
Preparing to program Aurora at Exascale - Early experiences and future direct...
PDF
Glomosim adding routing protocol
PPT
DDD Framework for Java: JdonFramework
PPT
First Failure Data Capture for your enterprise application with WebSphere App...
PPTX
Python Streaming Pipelines with Beam on Flink
PPT
20081114 Friday Food iLabt Bart Joris
PPTX
C Programming Language Tutorial for beginners - JavaTpoint
PPTX
Ob1k presentation at Java.IL
PDF
Cloud RPI4 tomcat ARM64
PDF
Flink Forward Berlin 2018: Thomas Weise & Aljoscha Krettek - "Python Streamin...
PPTX
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
PPT
Eclipse RT Day
ODP
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Open Source XMPP for Cloud Services
ECI OpenFlow 2.0 the Future of SDN
Model_Driven_Development_SDR
Crushing Latency with Vert.x
Infrastructure as Code in your CD pipelines - London Microsoft DevOps 0423
Virtual platform
Erlang OTP
Preparing to program Aurora at Exascale - Early experiences and future direct...
Glomosim adding routing protocol
DDD Framework for Java: JdonFramework
First Failure Data Capture for your enterprise application with WebSphere App...
Python Streaming Pipelines with Beam on Flink
20081114 Friday Food iLabt Bart Joris
C Programming Language Tutorial for beginners - JavaTpoint
Ob1k presentation at Java.IL
Cloud RPI4 tomcat ARM64
Flink Forward Berlin 2018: Thomas Weise & Aljoscha Krettek - "Python Streamin...
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
Eclipse RT Day
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Ad

Recently uploaded (20)

PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Approach and Philosophy of On baking technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Getting Started with Data Integration: FME Form 101
PPTX
A Presentation on Touch Screen Technology
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Web App vs Mobile App What Should You Build First.pdf
DP Operators-handbook-extract for the Mautical Institute
A comparative study of natural language inference in Swahili using monolingua...
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
cloud_computing_Infrastucture_as_cloud_p
Univ-Connecticut-ChatGPT-Presentaion.pdf
MIND Revenue Release Quarter 2 2025 Press Release
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
1 - Historical Antecedents, Social Consideration.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hindi spoken digit analysis for native and non-native speakers
Approach and Philosophy of On baking technology
A comparative analysis of optical character recognition models for extracting...
Getting Started with Data Integration: FME Form 101
A Presentation on Touch Screen Technology
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Web App vs Mobile App What Should You Build First.pdf

The State Machine Compiler

  • 1. SMC The State Machine Compiler (40 ’) François Perrad francois.perrad@gadz.org fperrad@OSDC.fr2009
  • 2. The State Machine Compiler  Introduction  Basic concepts  Advanced concepts  More features  A case study : a Telephone  Conclusion fperrad@OSDC.fr2009
  • 3. FSM are everywhere  FSM : Finite State Machine  Not a new technology  Strong theorical base  Reactive systems / Transformational systems  Event driven  Applications :  Telephones, automobiles, communication networks, avionic systems, man-machine interface fperrad@OSDC.fr2009
  • 4. FSM graphical view  Moore  Mealy  Grafcet  UML = Harel statechart fperrad@OSDC.fr2009
  • 5. A SourceForge project  Some facts :  registered in 2000  ~500 downloads / month  ~100 bugs (closed)  written in Java  mature codebase  well documented  3 developers  Licence MPL  See : http://www.ohloh.net/projects/7339?p=SMC fperrad@OSDC.fr2009
  • 6. The State Machine Compiler  Introduction  Basic concepts  Advanced concepts  More features  A case study : a Telephone  Conclusion fperrad@OSDC.fr2009
  • 7. A Compiler  A input source .sm (yacc-like syntax)  A output source (readable) in your language  Currently 14 target languages :  C, C++, C#, Groovy, Java, Lua, Objective-C, Perl, PHP, Python, Ruby, Scala, Tcl and VB.net  An Object Oriented design :  your class has a member which is the FSM generated class  A small RunTime Library  Parser & Lexer of SMC are written with SMC  The root of SMC is ATN (Augmented Transition Network)  Robert C. Martin (uncle bob) is the author of the initial SMC implementation fperrad@OSDC.fr2009
  • 8. A Simple Transition // State  Idle { // Trans  Next State Actions  Run  Running  {}  }  fperrad@OSDC.fr2009
  • 9. A Reflexive Transition // State  Idle {  // Trans  Next State  Actions  Timeout  Idle  {}  }  fperrad@OSDC.fr2009
  • 10. A Internal Event // State Idle {  // Trans  Next State  Actions  Timeout  nil  {}  }  fperrad@OSDC.fr2009
  • 11. A Transition with Actions // State  Idle  {  // Trans  Run  // Next State  Running  // Actions  {      StopTimer("Idle");      DoWork();  }  }  fperrad@OSDC.fr2009
  • 12. Transition Guards // State  Idle  {      // Trans      Run  // Guard condition  [ctxt.isValid()]  // Next State  Running  // Actions  {      StopTimer("Idle");      DoWork();  }      Run  Idle  { RejectRequest(); }  }  fperrad@OSDC.fr2009
  • 13. Transition Arguments // State  Idle  {      // Transition      Run(msg: const Message&)  // Guard condition  [msg.isValid()]      // Next State      Running  // Actions  {      StopTimer("Idle");      DoWork(msg);  }      Run(msg: const Message&)      // Next State Actions      Idle  { RejectRequest(msg); }  }  fperrad@OSDC.fr2009
  • 14. Entry and Exit Actions // State  Idle  Entry { StartTimer("Idle", 1); CheckQueue(); }  Exit { StopTimer("Idle"); }  {  // Transitions  }  fperrad@OSDC.fr2009
  • 15. the State Machine Compiler  Introduction  Basic concepts  Advanced concepts  More features  A case study : a Telephone  Conclusion fperrad@OSDC.fr2009
  • 16. Advanced Features  Map : state container  only one level (multiple with UML)  Push/Pop  with stack context  see UML History  Default state  factorisation of common behavior in a map  No concurrency (ie //) fperrad@OSDC.fr2009
  • 17. The Design Pattern fperrad@OSDC.fr2009
  • 18. the State Machine Compiler  Introduction  Basic concepts  Advanced concepts  More features  A case study : a Telephone  Conclusion fperrad@OSDC.fr2009
  • 19. More features  Event management is yours  Graphviz output generation  HTML table generation  Dynamic trace  Namespace support  Reflection/Introspection (for MMI) fperrad@OSDC.fr2009
  • 20. Graphviz output fperrad@OSDC.fr2009
  • 21. the State Machine Compiler  Introduction  Basic concepts  Advanced concepts  More Features  A case study : a Telephone  Conclusion fperrad@OSDC.fr2009
  • 22. A Telephone  Go to the WEB  Play with the demo (Applet Java) @ http://smc.sourceforge.net/SmcDemo.htm fperrad@OSDC.fr2009
  • 23. the State Machine Compiler  Introduction  Basic concepts  Advanced concepts  More Features  A case study : a Telephone  Conclusion fperrad@OSDC.fr2009
  • 24. all contributions welcomed  Eclipse plugin  Debian packaging  Pluggable language support  New target language  Regression test  … fperrad@OSDC.fr2009
  • 25. Bibliography / Webography - SMC : http://smc.sourceforge.net/ - Robert C. Martin, "Agile Software Development" - http://en.wikipedia.org/wiki/Finite_state_machine - http://en.wikipedia.org/wiki/Statechart - D. Harel, "Statecharts: A Visual Formalism for Complex Systems" - http://www.uml.org/ - http://fr.wikipedia.org/wiki/Grafcet - NF C03-190 - Diagramme fonctionnel "GRAFCET" - http://en.wikipedia.org/wiki/Augmented_transition_network fperrad@OSDC.fr2009