Finite State Machine Generator for C

For quite a long time I’m thinking about simple code generating tools. I don’t want to use a special XML syntax or descriptive language but a simple Excel or OpenOffice sheet instead.

The aim is to generated C source code for small microcontroller applications or retrocomputing systems.

For the start I made a simple generator for finite state machines (Wikipedia entry)

It is also my first script written in Python and thus not really as tidy and neat as I prefer. But it is working for now.

It takes the sheet from an OpenOffice .ods table like this:

@brief autofire button statemachine
@see    
     
State Event Next State
INIT KeyPressed PULSE_ON
INIT KeyNotPressed AUTOFIRE_OFF
AUTOFIRE_OFF KeyPressed PULSE_ON
PULSE_ON KeyNotPressed AUTOFIRE_OFF
PULSE_ON PulseTimeElapsed PULSE_OFF
PULSE_OFF KeyNotPressed AUTOFIRE_OFF
PULSE_OFF PulseTimeElapsed PULSE_ON

and generates a switch-case style state machine in C with callback functions for state and event handling.

A version with support for object oriented programming with pointers to statemachine objects is planned aswell. Check the github for functional updates.

The actual code can be found on Github: https://github.com/simonsunnyboy/gen-fsm