1 
2 #line 1 "clang.rl"
3 /*
4  * A mini C-like language scanner.
5  */
6 
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdlib.h>
10 
11 
12 #line 91 "clang.rl"
13 
14 
15 
16 #line 17 "clang.c"
17 static const int clang_start = 10;
18 static const int clang_error = 0;
19 
20 static const int clang_en_c_comment = 8;
21 static const int clang_en_main = 10;
22 
23 
24 #line 94 "clang.rl"
25 
26 #define BUFSIZE 128
27 
scanner()28 void scanner()
29 {
30 	static char buf[BUFSIZE];
31 	int cs, act, have = 0, curline = 1;
32 	char *ts, *te = 0;
33 	int done = 0;
34 
35 
36 #line 37 "clang.c"
37 	{
38 	cs = clang_start;
39 	ts = 0;
40 	te = 0;
41 	act = 0;
42 	}
43 
44 #line 105 "clang.rl"
45 
46 	while ( !done ) {
47 		char *p = buf + have, *pe, *eof = 0;
48 		int len, space = BUFSIZE - have;
49 
50 		if ( space == 0 ) {
51 			/* We've used up the entire buffer storing an already-parsed token
52 			 * prefix that must be preserved. */
53 			fprintf(stderr, "OUT OF BUFFER SPACE\n" );
54 			exit(1);
55 		}
56 
57 		len = fread( p, 1, space, stdin );
58 		pe = p + len;
59 
60 		/* Check if this is the end of file. */
61 		if ( len < space ) {
62 			eof = pe;
63 			done = 1;
64 		}
65 
66 
67 #line 68 "clang.c"
68 	{
69 	if ( p == pe )
70 		goto _test_eof;
71 	switch ( cs )
72 	{
73 tr2:
74 #line 50 "clang.rl"
75 	{te = p+1;{
76 		printf( "double_lit(%i): ", curline );
77 		fwrite( ts, 1, te-ts, stdout );
78 		printf("\n");
79 	}}
80 	goto st10;
81 tr6:
82 #line 42 "clang.rl"
83 	{te = p+1;{
84 		printf( "single_lit(%i): ", curline );
85 		fwrite( ts, 1, te-ts, stdout );
86 		printf("\n");
87 	}}
88 	goto st10;
89 tr8:
90 #line 28 "clang.rl"
91 	{{p = ((te))-1;}{
92 		printf( "symbol(%i): %c\n", curline, ts[0] );
93 	}}
94 	goto st10;
95 tr10:
96 #line 12 "clang.rl"
97 	{curline += 1;}
98 #line 62 "clang.rl"
99 	{te = p+1;}
100 	goto st10;
101 tr11:
102 #line 68 "clang.rl"
103 	{{p = ((te))-1;}{
104 		printf( "int(%i): ", curline );
105 		fwrite( ts, 1, te-ts, stdout );
106 		printf("\n");
107 	}}
108 	goto st10;
109 tr18:
110 #line 57 "clang.rl"
111 	{te = p+1;}
112 	goto st10;
113 tr19:
114 #line 12 "clang.rl"
115 	{curline += 1;}
116 #line 57 "clang.rl"
117 	{te = p+1;}
118 	goto st10;
119 tr20:
120 #line 28 "clang.rl"
121 	{te = p+1;{
122 		printf( "symbol(%i): %c\n", curline, ts[0] );
123 	}}
124 	goto st10;
125 tr25:
126 #line 28 "clang.rl"
127 	{te = p;p--;{
128 		printf( "symbol(%i): %c\n", curline, ts[0] );
129 	}}
130 	goto st10;
131 tr26:
132 #line 64 "clang.rl"
133 	{te = p+1;{ {goto st8;} }}
134 	goto st10;
135 tr27:
136 #line 68 "clang.rl"
137 	{te = p;p--;{
138 		printf( "int(%i): ", curline );
139 		fwrite( ts, 1, te-ts, stdout );
140 		printf("\n");
141 	}}
142 	goto st10;
143 tr30:
144 #line 76 "clang.rl"
145 	{te = p;p--;{
146 		printf( "float(%i): ", curline );
147 		fwrite( ts, 1, te-ts, stdout );
148 		printf("\n");
149 	}}
150 	goto st10;
151 tr31:
152 #line 84 "clang.rl"
153 	{te = p;p--;{
154 		printf( "hex(%i): ", curline );
155 		fwrite( ts, 1, te-ts, stdout );
156 		printf("\n");
157 	}}
158 	goto st10;
159 tr32:
160 #line 34 "clang.rl"
161 	{te = p;p--;{
162 		printf( "ident(%i): ", curline );
163 		fwrite( ts, 1, te-ts, stdout );
164 		printf("\n");
165 	}}
166 	goto st10;
167 st10:
168 #line 1 "NONE"
169 	{ts = 0;}
170 	if ( ++p == pe )
171 		goto _test_eof10;
172 case 10:
173 #line 1 "NONE"
174 	{ts = p;}
175 #line 176 "clang.c"
176 	switch( (*p) ) {
177 		case 10: goto tr19;
178 		case 34: goto st1;
179 		case 39: goto st3;
180 		case 47: goto tr21;
181 		case 48: goto tr22;
182 		case 95: goto st16;
183 	}
184 	if ( (*p) < 65 ) {
185 		if ( (*p) < 49 ) {
186 			if ( 33 <= (*p) && (*p) <= 46 )
187 				goto tr20;
188 		} else if ( (*p) > 57 ) {
189 			if ( 58 <= (*p) && (*p) <= 64 )
190 				goto tr20;
191 		} else
192 			goto tr23;
193 	} else if ( (*p) > 90 ) {
194 		if ( (*p) < 97 ) {
195 			if ( 91 <= (*p) && (*p) <= 96 )
196 				goto tr20;
197 		} else if ( (*p) > 122 ) {
198 			if ( 123 <= (*p) && (*p) <= 126 )
199 				goto tr20;
200 		} else
201 			goto st16;
202 	} else
203 		goto st16;
204 	goto tr18;
205 tr1:
206 #line 12 "clang.rl"
207 	{curline += 1;}
208 	goto st1;
209 st1:
210 	if ( ++p == pe )
211 		goto _test_eof1;
212 case 1:
213 #line 214 "clang.c"
214 	switch( (*p) ) {
215 		case 10: goto tr1;
216 		case 34: goto tr2;
217 		case 92: goto st2;
218 	}
219 	goto st1;
220 st2:
221 	if ( ++p == pe )
222 		goto _test_eof2;
223 case 2:
224 	if ( (*p) == 10 )
225 		goto tr1;
226 	goto st1;
227 tr5:
228 #line 12 "clang.rl"
229 	{curline += 1;}
230 	goto st3;
231 st3:
232 	if ( ++p == pe )
233 		goto _test_eof3;
234 case 3:
235 #line 236 "clang.c"
236 	switch( (*p) ) {
237 		case 10: goto tr5;
238 		case 39: goto tr6;
239 		case 92: goto st4;
240 	}
241 	goto st3;
242 st4:
243 	if ( ++p == pe )
244 		goto _test_eof4;
245 case 4:
246 	if ( (*p) == 10 )
247 		goto tr5;
248 	goto st3;
249 tr21:
250 #line 1 "NONE"
251 	{te = p+1;}
252 	goto st11;
253 st11:
254 	if ( ++p == pe )
255 		goto _test_eof11;
256 case 11:
257 #line 258 "clang.c"
258 	switch( (*p) ) {
259 		case 42: goto tr26;
260 		case 47: goto st5;
261 	}
262 	goto tr25;
263 st5:
264 	if ( ++p == pe )
265 		goto _test_eof5;
266 case 5:
267 	if ( (*p) == 10 )
268 		goto tr10;
269 	goto st5;
270 tr22:
271 #line 1 "NONE"
272 	{te = p+1;}
273 	goto st12;
274 st12:
275 	if ( ++p == pe )
276 		goto _test_eof12;
277 case 12:
278 #line 279 "clang.c"
279 	switch( (*p) ) {
280 		case 46: goto st6;
281 		case 120: goto st7;
282 	}
283 	if ( 48 <= (*p) && (*p) <= 57 )
284 		goto tr23;
285 	goto tr27;
286 st6:
287 	if ( ++p == pe )
288 		goto _test_eof6;
289 case 6:
290 	if ( 48 <= (*p) && (*p) <= 57 )
291 		goto st13;
292 	goto tr11;
293 st13:
294 	if ( ++p == pe )
295 		goto _test_eof13;
296 case 13:
297 	if ( 48 <= (*p) && (*p) <= 57 )
298 		goto st13;
299 	goto tr30;
300 tr23:
301 #line 1 "NONE"
302 	{te = p+1;}
303 	goto st14;
304 st14:
305 	if ( ++p == pe )
306 		goto _test_eof14;
307 case 14:
308 #line 309 "clang.c"
309 	if ( (*p) == 46 )
310 		goto st6;
311 	if ( 48 <= (*p) && (*p) <= 57 )
312 		goto tr23;
313 	goto tr27;
314 st7:
315 	if ( ++p == pe )
316 		goto _test_eof7;
317 case 7:
318 	if ( (*p) < 65 ) {
319 		if ( 48 <= (*p) && (*p) <= 57 )
320 			goto st15;
321 	} else if ( (*p) > 70 ) {
322 		if ( 97 <= (*p) && (*p) <= 102 )
323 			goto st15;
324 	} else
325 		goto st15;
326 	goto tr11;
327 st15:
328 	if ( ++p == pe )
329 		goto _test_eof15;
330 case 15:
331 	if ( (*p) < 65 ) {
332 		if ( 48 <= (*p) && (*p) <= 57 )
333 			goto st15;
334 	} else if ( (*p) > 70 ) {
335 		if ( 97 <= (*p) && (*p) <= 102 )
336 			goto st15;
337 	} else
338 		goto st15;
339 	goto tr31;
340 st16:
341 	if ( ++p == pe )
342 		goto _test_eof16;
343 case 16:
344 	if ( (*p) == 95 )
345 		goto st16;
346 	if ( (*p) < 65 ) {
347 		if ( 48 <= (*p) && (*p) <= 57 )
348 			goto st16;
349 	} else if ( (*p) > 90 ) {
350 		if ( 97 <= (*p) && (*p) <= 122 )
351 			goto st16;
352 	} else
353 		goto st16;
354 	goto tr32;
355 tr15:
356 #line 12 "clang.rl"
357 	{curline += 1;}
358 	goto st8;
359 st8:
360 #line 1 "NONE"
361 	{ts = 0;}
362 	if ( ++p == pe )
363 		goto _test_eof8;
364 case 8:
365 #line 366 "clang.c"
366 	switch( (*p) ) {
367 		case 10: goto tr15;
368 		case 42: goto st9;
369 	}
370 	goto st8;
371 st9:
372 	if ( ++p == pe )
373 		goto _test_eof9;
374 case 9:
375 	switch( (*p) ) {
376 		case 10: goto tr15;
377 		case 42: goto st9;
378 		case 47: goto tr17;
379 	}
380 	goto st8;
381 tr17:
382 #line 16 "clang.rl"
383 	{{goto st10;}}
384 	goto st17;
385 st17:
386 	if ( ++p == pe )
387 		goto _test_eof17;
388 case 17:
389 #line 390 "clang.c"
390 	goto st0;
391 st0:
392 cs = 0;
393 	goto _out;
394 	}
395 	_test_eof10: cs = 10; goto _test_eof;
396 	_test_eof1: cs = 1; goto _test_eof;
397 	_test_eof2: cs = 2; goto _test_eof;
398 	_test_eof3: cs = 3; goto _test_eof;
399 	_test_eof4: cs = 4; goto _test_eof;
400 	_test_eof11: cs = 11; goto _test_eof;
401 	_test_eof5: cs = 5; goto _test_eof;
402 	_test_eof12: cs = 12; goto _test_eof;
403 	_test_eof6: cs = 6; goto _test_eof;
404 	_test_eof13: cs = 13; goto _test_eof;
405 	_test_eof14: cs = 14; goto _test_eof;
406 	_test_eof7: cs = 7; goto _test_eof;
407 	_test_eof15: cs = 15; goto _test_eof;
408 	_test_eof16: cs = 16; goto _test_eof;
409 	_test_eof8: cs = 8; goto _test_eof;
410 	_test_eof9: cs = 9; goto _test_eof;
411 	_test_eof17: cs = 17; goto _test_eof;
412 
413 	_test_eof: {}
414 	if ( p == eof )
415 	{
416 	switch ( cs ) {
417 	case 11: goto tr25;
418 	case 5: goto tr8;
419 	case 12: goto tr27;
420 	case 6: goto tr11;
421 	case 13: goto tr30;
422 	case 14: goto tr27;
423 	case 7: goto tr11;
424 	case 15: goto tr31;
425 	case 16: goto tr32;
426 	}
427 	}
428 
429 	_out: {}
430 	}
431 
432 #line 127 "clang.rl"
433 
434 		if ( cs == clang_error ) {
435 			fprintf(stderr, "PARSE ERROR\n" );
436 			break;
437 		}
438 
439 		if ( ts == 0 )
440 			have = 0;
441 		else {
442 			/* There is a prefix to preserve, shift it over. */
443 			have = pe - ts;
444 			memmove( buf, ts, have );
445 			te = buf + (te-ts);
446 			ts = buf;
447 		}
448 	}
449 }
450 
main()451 int main()
452 {
453 	scanner();
454 	return 0;
455 }
456 
457