2 * Demonstrate the use of labels, the epsilon operator, and the join operator
3 * for creating machines using the named state and transition list paradigm.
4 * This implementes the same machine as the atoi example.
21 int execute( const char *data, int len );
38 val = val * 10 + (fc - '0');
48 '-' @see_neg ->om_num |
50 [0-9] @add_digit ->more_nums
55 [0-9] @add_digit ->more_nums
60 [0-9] @add_digit ->more_nums |
65 main := ( atoi '\n' @{ cout << val << endl; } )*;
70 int StateChart::init( )
78 int StateChart::execute( const char *data, int len )
81 const char *pe = data + len;
85 if ( cs == StateChart_error )
87 if ( cs >= StateChart_first_final )
92 int StateChart::finish( )
94 if ( cs == StateChart_error )
96 if ( cs >= StateChart_first_final )
110 while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
111 atoi.execute( buf, strlen(buf) );
113 if ( atoi.finish() <= 0 )
114 cerr << "statechart: error: parsing input" << endl;