#include #include using namespace std; extern char buf[]; struct Scanner { int cs, act; char *ts, *te; // Initialize the machine. Invokes any init statement blocks. Returns 0 // if the machine begins in a non-accepting state and 1 if the machine // begins in an accepting state. void init( ); // Execute the machine on a block of data. Returns -1 if after processing // the data, the machine is in the error state and can never accept, 0 if // the machine is in a non-accepting state and 1 if the machine is in an // accepting state. int execute( char *data, int len ); // Indicate that there is no more data. Returns -1 if the machine finishes // in the error state and does not accept, 0 if the machine finishes // in any other non-accepting state and 1 if the machine finishes in an // accepting state. int finish( ); }; static const char _Scanner_actions [] = { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 7, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 20, 1, 21, 1, 22, 1, 23, 1, 24, 1, 25, 1, 26, 1, 27, 1, 28, 1, 29, 1, 30, 1, 31, 2, 4, 0, 2, 6, 1, 2, 7, 8, 2, 7, 9, 2, 7, 10, 2, 7, 11, 3, 4, 5, 0, 0 , }; static const char _Scanner_trans_keys [] = { 1, 0, 0, 17, 1, 0, 0, 17, 1, 0, 7, 7, 6, 10, 9, 10, 9, 13, 5, 5, 5, 8, 0, 0, 2, 19, 2, 19, 7, 10, 9, 18, 9, 18, 5, 8, 7, 19, 7, 18, 15, 18, 15, 18, 15, 18, 9, 18, 15, 18, 7, 18, 9, 19, 3, 19, 1, 0, 1, 0, 0 , }; static const char _Scanner_char_class [] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 2, 2, 2, 4, 2, 2, 5, 6, 2, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 2, 2, 2, 2, 2, 2, 2, 11, 11, 11, 11, 12, 13, 14, 14, 14, 14, 14, 15, 14, 14, 14, 14, 14, 14, 14, 14, 16, 14, 14, 14, 14, 14, 2, 17, 2, 2, 14, 2, 11, 11, 11, 11, 12, 13, 14, 14, 14, 14, 14, 18, 14, 14, 14, 14, 14, 14, 14, 14, 16, 14, 14, 19, 14, 14, 2, 2, 2, 2, 0 , }; static const short _Scanner_index_offsets [] = { 0, 0, 18, 18, 36, 36, 37, 42, 44, 49, 50, 54, 55, 73, 91, 95, 105, 115, 119, 132, 144, 148, 152, 156, 166, 170, 182, 193, 210, 210, 0 , }; static const char _Scanner_indices [] = { 0, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 0, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 8, 9, 0, 0, 10, 10, 10, 10, 12, 12, 12, 12, 12, 14, 14, 13, 13, 15, 17, 19, 1, 4, 19, 19, 20, 21, 22, 23, 24, 24, 24, 24, 25, 24, 19, 24, 24, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 28, 27, 29, 29, 29, 29, 30, 31, 32, 30, 32, 30, 30, 32, 10, 10, 30, 30, 32, 30, 32, 30, 30, 32, 33, 27, 27, 34, 29, 35, 36, 36, 35, 31, 35, 35, 37, 37, 35, 37, 38, 29, 39, 36, 36, 39, 31, 39, 39, 40, 40, 39, 40, 41, 41, 39, 41, 42, 42, 35, 42, 43, 43, 35, 43, 12, 12, 12, 12, 12, 44, 45, 45, 44, 45, 46, 46, 44, 46, 29, 35, 23, 23, 35, 31, 35, 35, 37, 37, 35, 37, 24, 24, 24, 24, 24, 24, 24, 24, 47, 24, 24, 1, 4, 47, 47, 47, 47, 24, 24, 24, 24, 24, 24, 24, 24, 47, 24, 24, 0 , }; static const char _Scanner_index_defaults [] = { 0, 1, 1, 4, 4, 7, 0, 0, 11, 13, 13, 16, 18, 18, 27, 30, 30, 27, 35, 39, 39, 35, 35, 44, 44, 35, 47, 47, 48, 48, 0 , }; static const char _Scanner_trans_cond_spaces [] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 , }; static const char _Scanner_cond_targs [] = { 12, 1, 12, 2, 3, 12, 4, 12, 12, 7, 16, 12, 23, 9, 10, 28, 11, 29, 13, 12, 14, 17, 18, 25, 26, 27, 12, 12, 5, 15, 12, 6, 12, 12, 12, 12, 19, 21, 8, 12, 20, 12, 22, 12, 12, 24, 12, 12, 0, 0 , }; static const char _Scanner_cond_actions [] = { 49, 0, 13, 0, 0, 11, 0, 47, 23, 0, 0, 45, 0, 0, 0, 5, 0, 7, 0, 25, 9, 0, 63, 63, 0, 57, 43, 41, 0, 60, 33, 0, 15, 27, 29, 35, 66, 0, 0, 37, 0, 19, 0, 17, 39, 0, 21, 31, 0, 0 , }; static const char _Scanner_to_state_actions [] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 51, 1, 51, 69, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 , }; static const char _Scanner_from_state_actions [] = { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 54, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 , }; static const char _Scanner_eof_trans [] = { 0, 1, 1, 1, 1, 8, 1, 1, 12, 0, 0, 0, 0, 27, 28, 31, 31, 28, 36, 40, 40, 36, 36, 45, 45, 36, 48, 48, 0, 0, 0 , }; static const char _Scanner_nfa_targs [] = { 0, 0 , }; static const char _Scanner_nfa_offsets [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , }; static const char _Scanner_nfa_push_actions [] = { 0, 0 , }; static const char _Scanner_nfa_pop_trans [] = { 0, 0 , }; static const int Scanner_start = 12; static const int Scanner_first_final = 12; static const int Scanner_error = 0; static const int Scanner_en_c_comm = 9; static const int Scanner_en_cxx_comm = 11; static const int Scanner_en_main = 12; void Scanner::init( ) { { cs = ( int ) Scanner_start; ts = 0; te = 0; act = 0; } } int Scanner::execute( char *data, int len ) { char *p = data; char *pe = data + len; char *eof = pe; { int _trans = 0; const char *_acts; unsigned int _nacts; const char *_keys; const char *_inds; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume : _acts = _Scanner_actions + _Scanner_from_state_actions[cs]; _nacts = ( unsigned int ) (*( _acts )) ; _acts += 1; while ( _nacts > 0 ) { switch ( (*( _acts )) ) { case 1 : { cout << "from: fc = "; if ( (((*( p )) )) == '\'' ) cout << (int)(((*( p )) )); else cout << (((*( p )) )); cout << " ts = " << ( ts == 0 ? -1 : ts-buf ) << endl; } break; case 6 : { { ts = p; } } break; } _nacts -= 1; _acts += 1; } _keys = _Scanner_trans_keys + (cs<<1); _inds = _Scanner_indices + _Scanner_index_offsets[cs]; if ( ((*( p )) )<= 126 && ((*( p )) )>= 10 ) { int _ic = ( int ) _Scanner_char_class[( int ) ((*( p )) )- 10]; if ( _ic <= ( int ) (*( _keys+1 )) && _ic >= ( int ) (*( _keys )) ) _trans = ( int ) (*( _inds + ( int ) (_ic - ( int ) (*( _keys )) ) )) ; else _trans = ( int ) _Scanner_index_defaults[cs]; } else { _trans = ( int ) _Scanner_index_defaults[cs]; } goto _match_cond; _match_cond : cs = ( int ) _Scanner_cond_targs[_trans]; if ( _Scanner_cond_actions[_trans]== 0 ) goto _again; _acts = _Scanner_actions + _Scanner_cond_actions[_trans]; _nacts = ( unsigned int ) (*( _acts )) ; _acts += 1; while ( _nacts > 0 ) { switch ( (*( _acts )) ) { case 2 : { { cs = 12; goto _again; } } break; case 3 : { { cs = 12; goto _again; } } break; case 7 : { { te = p+1; } } break; case 8 : { { act = 3; } } break; case 9 : { { act = 4; } } break; case 10 : { { act = 5; } } break; case 11 : { { act = 6; } } break; case 12 : { { te = p+1; } } break; case 13 : { { te = p+1; } } break; case 14 : { { te = p+1; } } break; case 15 : { { te = p+1; } } break; case 16 : { { te = p+1; } } break; case 17 : { { te = p+1; } } break; case 18 : { { te = p+1; } } break; case 19 : { { te = p+1; } } break; case 20 : { { te = p+1; { { cs = 9; goto _again; } } } } break; case 21 : { { te = p+1; { { cs = 11; goto _again; } } } } break; case 22 : { { te = p; p = p - 1; } } break; case 23 : { { te = p; p = p - 1; } } break; case 24 : { { te = p; p = p - 1; } } break; case 25 : { { te = p; p = p - 1; } } break; case 26 : { { te = p; p = p - 1; } } break; case 27 : { { te = p; p = p - 1; } } break; case 28 : { { te = p; p = p - 1; } } break; case 29 : { { p = ((te))-1; } } break; case 30 : { { p = ((te))-1; } } break; case 31 : { { switch ( act ) { case 0 : { { cs = 0; goto _again; } } break; default: p = ((te))-1; break; } } } break; } _nacts -= 1; _acts += 1; } _again : _acts = _Scanner_actions + _Scanner_to_state_actions[cs]; _nacts = ( unsigned int ) (*( _acts )) ; _acts += 1; while ( _nacts > 0 ) { switch ( (*( _acts )) ) { case 0 : { cout << "to: fc = "; if ( (((*( p )) )) == '\'' ) cout << (int)(((*( p )) )); else cout << (((*( p )) )); cout << " ts = " << ( ts == 0 ? -1 : ts-buf ) << endl; } break; case 4 : { { ts = 0; } } break; case 5 : { { act = 0; } } break; } _nacts -= 1; _acts += 1; } if ( cs == 0 ) goto _out; p += 1; if ( p != pe ) goto _resume; _test_eof : {} if ( p == eof ) { if ( _Scanner_eof_trans[cs]> 0 ) { _trans = ( int ) _Scanner_eof_trans[cs]- 1; goto _match_cond; } } _out : {} } return 0; } int Scanner::finish( ) { if ( cs == Scanner_error ) return -1; if ( cs >= Scanner_first_final ) return 1; return 0; } void test( ) { int len = strlen( buf ); Scanner scanner; scanner.init(); scanner.execute( buf, len ); if ( scanner.cs == Scanner_error ) { /* Machine failed before finding a token. */ cout << "PARSE ERROR" << endl; } scanner.finish(); } char buf[4096]; int main() { strcpy( buf, "a b 0.98 /*\n" "9 */'\\''//hi\n" "there\n" ); test(); return 0; }