Example #1
0
#! /usr/bin/python

import fsm

m = fsm.Machine("hos")

m.header("""
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;

char * now() {
  time_t rawtime;
  time(&rawtime);
  return ctime (&rawtime);
}
""")

m.state('OFF_DUTY',
        '// code for OFF_DUTY_STATE\n',
        [m.edge('END', 'END', """
cout << "th-th-that's all, folks." << endl;
exit(EXIT_SUCCESS);
"""),
         m.edge('ON_DUTY', 'ON_DUTY_STATIONARY', """
cout << "driver coming on duty " << now();
""")])
Example #2
0
#! /usr/bin/python

import fsm

m = fsm.Machine("float_check")

m.header("""
#include <cctype>
#include <cstdlib>
#include <iostream>
using namespace std;
""")

m.state('S0', '', m.edges(('DIGIT', 'S3'), ('SIGN', 'S1'), ('DECIMAL', 'S2')))

m.state('S1', '', m.edges(('DECIMAL', 'S2'), ('DIGIT', 'S3')))

m.state('S2', '', [m.edge('DIGIT', 'S4')])

m.state('S3', '',
        m.edges(('DIGIT', 'S3'), ('DECIMAL', 'S4'), ('EXPONENT', 'S5')))

m.state(
    'S4', '',
    m.edges(('DIGIT', 'S4'), ('EXPONENT', 'S5'), ('END_OF_INPUT', 'ACCEPT')))

m.state('S5', '', m.edges(('DIGIT', 'S6'), ('SIGN', 'S7')))

m.state('S6', '', m.edges(('DIGIT', 'S6'), ('END_OF_INPUT', 'ACCEPT')))

m.state('S7', '', [m.edge('DIGIT', 'S6')])