16 // Initialize the machine. Invokes any init statement blocks. Returns 0
17 // if the machine begins in a non-accepting state and 1 if the machine
18 // begins in an accepting state.
21 // Execute the machine on a block of data. Returns -1 if after processing
22 // the data, the machine is in the error state and can never accept, 0 if
23 // the machine is in a non-accepting state and 1 if the machine is in an
25 int execute( char *data, int len );
27 // Indicate that there is no more data. Returns -1 if the machine finishes
28 // in the error state and does not accept, 0 if the machine finishes
29 // in any other non-accepting state and 1 if the machine finishes in an
43 cout << " ts = " << ( ts == 0 ? -1 : ts-buf ) << endl;
46 cout << "from: fc = ";
51 cout << " ts = " << ( ts == 0 ? -1 : ts-buf ) << endl;
54 c_comm := ( any* $0 '*/' @1 @{ fgoto main; } ) $~to_act $*from_act;
55 cxx_comm := ( any* $0 '\n' @1 @{ fgoto main; } ) $~to_act $*from_act;
59 # Single and double literals.
60 ( 'L'? "'" ( [^'\\\n] | /\\./ )* "'" ) $~ to_act $* from_act;
61 ( 'L'? '"' ( [^"\\\n] | /\\./ )* '"' ) $~ to_act $* from_act;
64 ( [a-zA-Z_] [a-zA-Z0-9_]* ) $~ to_act $* from_act;
67 fract_const = digit* '.' digit+ | digit+ '.';
68 exponent = [eE] [+\-]? digit+;
69 float_suffix = [flFL];
71 ( fract_const exponent? float_suffix? |
72 digit+ exponent float_suffix? ) $~ to_act $* from_act;
74 # Integer decimal. Leading part buffered by float.
75 ( ( '0' | [1-9] [0-9]* ) [ulUL]{0,3} ) $~ to_act $* from_act;
77 # Integer octal. Leading part buffered by float.
78 ( '0' [0-9]+ [ulUL]{0,2} ) $~ to_act $* from_act;
80 # Integer hex. Leading 0 buffered by float.
81 ( '0x' [0-9a-fA-F]+ [ulUL]{0,2} ) $~ to_act $* from_act;
83 # Three char compounds, first item already buffered. */
84 ( '...' ) $~ to_act $* from_act;
86 # Single char symbols.
87 ( punct - [_"'] ) $~ to_act $* from_act;
89 # Comments and whitespace.
90 ( '/*' ) $~ to_act $* from_act { fgoto c_comm; };
91 ( '//' ) $~ to_act $* from_act { fgoto cxx_comm; };
93 ( any - 33..126 )+ $~ to_act $* from_act;
100 void Scanner::init( )
105 int Scanner::execute( char *data, int len )
108 char *pe = data + len;
116 int Scanner::finish( )
118 if ( cs == Scanner_error )
120 if ( cs >= Scanner_first_final )
127 int len = strlen( buf );
131 scanner.execute( buf, len );
132 if ( scanner.cs == Scanner_error ) {
133 /* Machine failed before finding a token. */
134 cout << "PARSE ERROR" << endl;
152 #ifdef _____OUTPUT_____
199 from: fc = 39 ts = 16
203 from: fc = 39 ts = 16
205 from: fc = 39 ts = 16