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.
20 int execute( const char *data, int len );
37 val = val * 10 + (fc - '0');
47 '-' @see_neg ->om_num |
49 [0-9] @add_digit ->more_nums
54 [0-9] @add_digit ->more_nums
59 [0-9] @add_digit ->more_nums |
64 main := ( atoi '\n' @{ cout << val << endl; } )*;
69 int StateChart::init( )
75 int StateChart::execute( const char *data, int len )
78 const char *pe = data + len;
82 if ( cs == StateChart_error )
84 if ( cs >= StateChart_first_final )
89 int StateChart::finish( )
92 if ( cs == StateChart_error )
94 if ( cs >= StateChart_first_final )
108 while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
109 atoi.execute( buf, strlen(buf) );
111 if ( atoi.finish() <= 0 )
112 cerr << "statechart: error: parsing input" << endl;