14 char *tokstart, *tokend;
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 << " tokstart = " << ( tokstart == 0 ? -1 : tokstart-buf ) << endl;
46 cout << "from: fc = ";
51 cout << " tokstart = " << ( tokstart == 0 ? -1 : tokstart-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;
113 if ( tokstart != 0 ) {
114 have = pe - tokstart;
115 memmove( data, tokstart, have );
120 int Scanner::finish( )
122 if ( cs == Scanner_error )
124 if ( cs >= Scanner_first_final )
131 int len = strlen( buf );
135 scanner.execute( buf, len );
136 if ( scanner.cs == Scanner_error ) {
137 /* Machine failed before finding a token. */
138 cout << "PARSE ERROR" << endl;
156 #ifdef _____OUTPUT_____
157 from: fc = a tokstart = 0
158 to: fc = a tokstart = 0
159 from: fc = tokstart = 0
160 to: fc = a tokstart = -1
161 from: fc = tokstart = 1
162 to: fc = tokstart = 1
163 from: fc = b tokstart = 1
164 to: fc = tokstart = -1
165 from: fc = b tokstart = 2
166 to: fc = b tokstart = 2
167 from: fc = tokstart = 2
168 to: fc = b tokstart = -1
169 from: fc = tokstart = 3
170 to: fc = tokstart = 3
171 from: fc = 0 tokstart = 3
172 to: fc = tokstart = -1
173 from: fc = 0 tokstart = 4
174 to: fc = 0 tokstart = 4
175 from: fc = . tokstart = 4
176 to: fc = . tokstart = 4
177 from: fc = 9 tokstart = 4
178 to: fc = 9 tokstart = 4
179 from: fc = 8 tokstart = 4
180 to: fc = 8 tokstart = 4
181 from: fc = tokstart = 4
182 to: fc = 8 tokstart = -1
183 from: fc = tokstart = 8
184 to: fc = tokstart = 8
185 from: fc = / tokstart = 8
186 to: fc = tokstart = -1
187 from: fc = / tokstart = 9
188 to: fc = / tokstart = 9
189 from: fc = * tokstart = 9
190 to: fc = * tokstart = -1
195 from: fc = 9 tokstart = -1
196 to: fc = 9 tokstart = -1
197 from: fc = tokstart = -1
198 to: fc = tokstart = -1
199 from: fc = * tokstart = -1
200 to: fc = * tokstart = -1
201 from: fc = / tokstart = -1
202 to: fc = / tokstart = -1
203 from: fc = 39 tokstart = 16
204 to: fc = 39 tokstart = 16
205 from: fc = \ tokstart = 16
206 to: fc = \ tokstart = 16
207 from: fc = 39 tokstart = 16
208 to: fc = 39 tokstart = 16
209 from: fc = 39 tokstart = 16
210 to: fc = 39 tokstart = -1
211 from: fc = / tokstart = 20
212 to: fc = / tokstart = 20
213 from: fc = / tokstart = 20
214 to: fc = / tokstart = -1
215 from: fc = h tokstart = -1
216 to: fc = h tokstart = -1
217 from: fc = i tokstart = -1
218 to: fc = i tokstart = -1
223 from: fc = t tokstart = 25
224 to: fc = t tokstart = 25
225 from: fc = h tokstart = 25
226 to: fc = h tokstart = 25
227 from: fc = e tokstart = 25
228 to: fc = e tokstart = 25
229 from: fc = r tokstart = 25
230 to: fc = r tokstart = 25
231 from: fc = e tokstart = 25
232 to: fc = e tokstart = 25
235 to: fc = e tokstart = -1