summaryrefslogtreecommitdiff
path: root/flex.skl
blob: 1ccbdff4355beaae73ca13d8d7d770be8baf0cfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
/* A lexical scanner generated by flex */

/* scanner skeleton version:
 * $Header$
 */

#include <stdio.h>

#define FLEX_SCANNER

/* returned upon end-of-file */
#define YY_END_TOK 0

/* amount of stuff to slurp up with each read */
#define YY_READ_BUF_SIZE 8192

#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of input buffer */

/* number of characters one rule can match.  One less than YY_BUF_SIZE to make
 * sure we never access beyond the end of an array
 */
#define YY_BUF_MAX (YY_BUF_SIZE - 1)

/* copy whatever the last rule matched to the standard output */

#define ECHO fputs( yytext, yyout )

/* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
 * is returned in "result".
 */
#define YY_INPUT(buf,result,max_size) \
	if ( (result = read( fileno(yyin), buf, max_size )) < 0 ) \
	    YY_FATAL_ERROR( "read() in flex scanner failed" );
#define YY_NULL 0

/* report a fatal error */
#define YY_FATAL_ERROR(msg) \
	{ \
	fputs( msg, stderr ); \
	putc( '\n', stderr ); \
	exit( 1 ); \
	}

/* default yywrap function - always treat EOF as an EOF */
#define yywrap() 1

/* enter a start condition.  This macro really ought to take a parameter,
 * but we do it the disgusting crufty way that old Unix-lex does it
 */
#define BEGIN yy_start = 1 +

/* default declaration of generated scanner - a define so the user can
 * easily add parameters
 */
#define YY_DECL int yylex()

/* code executed at the end of each rule */
#define YY_BREAK break;

#define YY_END_OF_BUFFER_CHAR 0

/* done after the current pattern has been matched and before the
 * corresponding action - sets up yytext
 */
#define YY_DO_BEFORE_ACTION \
	yytext = yy_bp; \
	yy_hold_char = *yy_cp; \
	*yy_cp = '\0'; \
	yy_c_buf_p = yy_cp;

/* returns the length of the matched text */
#define yyleng (yy_cp - yy_bp)

#define EOB_ACT_RESTART_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2

/* return all but the first 'n' matched characters back to the input stream */
#define yyless(n) \
	{ \
	*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \
	yy_c_buf_p = yy_cp = yy_bp + n; \
	YY_DO_BEFORE_ACTION; /* set up yytext again */ \
	}

#define unput(c) yyunput( c, yy_bp )

#define YY_USER_ACTION

%% section 1 code and the data tables for the DFA go here

FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;

/* these variables are all declared out here so that section 3 code can
 * manipulate them
 */
static char *yy_c_buf_p;	/* points to current character in buffer */
static int yy_init = 1;		/* whether we need to initialize */
static int yy_start = 0;	/* start state number */

/* true when we've seen an EOF for the current input file */
static int yy_eof_has_been_seen;

static int yy_n_chars;		/* number of characters read into yy_ch_buf */

/* yy_ch_buf has to be 2 characters longer than YY_BUF_SIZE because we need
 * to put in 2 end-of-buffer characters (this is explained where it is
 * done) at the end of yy_ch_buf
 */
static char yy_ch_buf[YY_BUF_SIZE + 2];

/* yy_hold_char holds the character lost when yytext is formed */
static char yy_hold_char;
char *yytext;

static yy_state_type yy_last_accepting_state;
static char *yy_last_accepting_cpos;

static yy_state_type yy_get_previous_state();
static int yy_get_next_buffer();

static void yyunput();
static int input();

YY_DECL
    {
    register yy_state_type yy_current_state;
    register char *yy_cp, *yy_bp;
    register int yy_act;

%% user's declarations go here

    if ( yy_init )
	{
	if ( ! yy_start )
	    yy_start = 1;	/* first start state */

	if ( ! yyin )
	    yyin = stdin;

	if ( ! yyout )
	    yyout = stdout;

new_file:
	/* this is where we enter upon encountering an end-of-file and
	 * yywrap() indicating that we should continue processing
	 */

	/* we put in the '\n' and start reading from [1] so that an
	 * initial match-at-newline will be true.
	 */

	yy_ch_buf[0] = '\n';
	yy_n_chars = 1;

	/* we always need two end-of-buffer characters.  The first causes
	 * a transition to the end-of-buffer state.  The second causes
	 * a jam in that state.
	 */
	yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
	yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;

	yy_eof_has_been_seen = 0;

	yytext = yy_c_buf_p = &yy_ch_buf[1];
	yy_hold_char = *yy_c_buf_p;
	yy_init = 0;
	}

    while ( 1 )		/* loops until end-of-file is reached */
	{
	yy_cp = yy_c_buf_p;

	/* support of yytext */
	*yy_cp = yy_hold_char;

	/* yy_bp points to the position in yy_ch_buf of the start of the
	 * current run.
	 */
	yy_bp = yy_cp;

%% code to set up and find next match goes here

	/* bogus while loop to let YY_BACK_TRACK and EOB_ACT_LAST_MATCH
	 * actions branch here without introducing an optimizer-daunting
	 * goto
	 */
	while ( 1 )
	    {
%% code to find the action number goes here

	    YY_DO_BEFORE_ACTION;
	    YY_USER_ACTION;

#ifdef FLEX_DEBUG
	    fprintf( stderr, "--accepting rule #%d (\"%s\")\n",
		     yy_act, yytext );
#endif
	    switch ( yy_act )
		{
%% actions go here

		case YY_END_OF_BUFFER:
		    /* undo the effects of YY_DO_BEFORE_ACTION */
		    *yy_cp = yy_hold_char;

		    yytext = yy_bp;

		    switch ( yy_get_next_buffer() )
			{
			case EOB_ACT_END_OF_FILE:
			    {
			    if ( yywrap() )
				{
				/* note: because we've taken care in
				 * yy_get_next_buffer() to have set up yytext,
				 * we can now set up yy_c_buf_p so that if some
				 * total hoser (like flex itself) wants
				 * to call the scanner after we return the
				 * YY_NULL, it'll still work - another YY_NULL
				 * will get returned.
				 */
				yy_c_buf_p = yytext;
				return ( YY_NULL );
				}

			    else
				goto new_file;
			    }
			    break;

			case EOB_ACT_RESTART_SCAN:
			    yy_c_buf_p = yytext;
			    yy_hold_char = *yy_c_buf_p;
			    break;

			case EOB_ACT_LAST_MATCH:
			    yy_c_buf_p = &yy_ch_buf[yy_n_chars];

			    yy_current_state = yy_get_previous_state();

			    yy_cp = yy_c_buf_p;
			    yy_bp = yytext;
			    continue; /* go to "YY_DO_BEFORE_ACTION" */
			}
		    break;

		default:
		    printf( "action # %d\n", yy_act );
		    YY_FATAL_ERROR( "fatal flex scanner internal error" );
		}

	    break; /* exit bogus while loop */
	    }
	}
    }


/* yy_get_next_buffer - try to read in new buffer
 *
 * synopsis
 *     int yy_get_next_buffer();
 *     
 * returns a code representing an action
 *     EOB_ACT_LAST_MATCH - 
 *     EOB_ACT_RESTART_SCAN - restart the scanner
 *     EOB_ACT_END_OF_FILE - end of file
 */

static int yy_get_next_buffer()

    {
    if ( yy_c_buf_p != &yy_ch_buf[yy_n_chars + 1] )
	{
	YY_FATAL_ERROR( "NULL in input" );
	/*NOTREACHED*/
	}

    else
	{ /* try to read more data */
	register char *dest = yy_ch_buf;
	register char *source = yytext - 1; /* copy prev. char, too */
	register int number_to_move, i;
	int ret_val;
	
	/* first move last chars to start of buffer */
	number_to_move = yy_c_buf_p - yytext;

	for ( i = 0; i < number_to_move; ++i )
	    *(dest++) = *(source++);

	if ( yy_eof_has_been_seen )
	    /* don't do the read, it's not guaranteed to return an EOF,
	     * just force an EOF
	     */
	    yy_n_chars = 0;

	else
	    /* read in more data */
	    YY_INPUT( (&yy_ch_buf[number_to_move]), yy_n_chars,
		      YY_BUF_SIZE - number_to_move - 1 );

	if ( yy_n_chars == 0 )
	    {
	    if ( number_to_move == 1 )
		ret_val = EOB_ACT_END_OF_FILE;
	    else
		ret_val = EOB_ACT_LAST_MATCH;

	    yy_eof_has_been_seen = 1;
	    }

	else
	    ret_val = EOB_ACT_RESTART_SCAN;

	yy_n_chars += number_to_move;
	yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
	yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;

	/* yytext begins at the second character in
	 * yy_ch_buf; the first character is the one which
	 * preceded it before reading in the latest buffer;
	 * it needs to be kept around in case it's a
	 * newline, so yy_get_previous_state() will have
	 * with '^' rules active
	 */

	yytext = &yy_ch_buf[1];

	return ( ret_val );
	}
    }


/* yy_get_previous_state - get the state just before the EOB char was reached
 *
 * synopsis
 *     yy_state_type yy_get_previous_state();
 */

static yy_state_type yy_get_previous_state()

    {
    register yy_state_type yy_current_state;
    register char *yy_cp;

%% code to get the start state into yy_current_state goes here

    for ( yy_cp = yytext; yy_cp < yy_c_buf_p; ++yy_cp )
	{
%% code to find the next state goes here
	}

    return ( yy_current_state );
    }


static void yyunput( c, yy_bp )
int c;
register char *yy_bp;

    {
    register char *yy_cp = yy_c_buf_p;

    *yy_cp = yy_hold_char; /* undo effects of setting up yytext */

    if ( yy_cp < yy_ch_buf + 2 )
	{ /* need to shift things up to make room */
	register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
	register char *dest = &yy_ch_buf[YY_BUF_SIZE + 2];
	register char *source = &yy_ch_buf[number_to_move];

	while ( source > yy_ch_buf )
	    *--dest = *--source;

	yy_cp += dest - source;
	yy_bp += dest - source;

	if ( yy_cp < yy_ch_buf + 2 )
	    YY_FATAL_ERROR( "flex scanner push-back overflow" );
	}

    if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
	yy_cp[-2] = '\n';

    *--yy_cp = c;

    YY_DO_BEFORE_ACTION; /* set up yytext again */
    }


static int input()

    {
    int c;
    char *yy_cp = yy_c_buf_p;

    *yy_cp = yy_hold_char;

    if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
	{ /* need more input */
	yytext = yy_c_buf_p;
	++yy_c_buf_p;

	switch ( yy_get_next_buffer() )
	    {
	    /* this code, unfortunately, is somewhat redundant with
	     * that above
	     */
	    case EOB_ACT_END_OF_FILE:
		{
		if ( yywrap() )
		    {
		    yy_c_buf_p = yytext;
		    return ( EOF );
		    }

		yy_ch_buf[0] = '\n';
		yy_n_chars = 1;
		yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
		yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
		yy_eof_has_been_seen = 0;
		yytext = yy_c_buf_p = &yy_ch_buf[1];
		yy_hold_char = *yy_c_buf_p;

		return ( input() );
		}
		break;

	    case EOB_ACT_RESTART_SCAN:
		yy_c_buf_p = yytext;
		break;

	    case EOB_ACT_LAST_MATCH:
		YY_FATAL_ERROR( "unexpected last match in input()" );
	    }
	}

    c = *yy_c_buf_p;
    yy_hold_char = *++yy_c_buf_p;

    return ( c );
    }