1 /* A lexical scanner generated by flex */
3 /* scanner skeleton version:
4 * $Id: flex.skel,v 1.3 1994/06/24 10:56:48 ceriel Exp $
14 /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
27 /* use prototypes in function declarations */
30 /* the "const" storage-class-modifier is valid */
33 #else /* ! __cplusplus */
39 void *malloc( size_t );
49 #endif /* ! __cplusplus */
63 #define YY_PROTO(proto) proto
65 #define YY_PROTO(proto) ()
66 /* we can't get here if it's an ANSI C compiler, or a C++ compiler,
67 * so it's got to be a K&R compiler, and therefore there's no standard
68 * place from which to include these definitions
76 /* amount of stuff to slurp up with each read */
77 #ifndef YY_READ_BUF_SIZE
78 #define YY_READ_BUF_SIZE 8192
81 /* returned upon end-of-file */
84 /* copy whatever the last rule matched to the standard output */
86 /* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
87 /* this used to be an fputs(), but since the string might contain NUL's,
90 #define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
92 /* gets input and stuffs it into "buf". number of characters read, or YY_NULL,
93 * is returned in "result".
95 #define YY_INPUT(buf,result,max_size) \
96 if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
97 YY_FATAL_ERROR( "read() in flex scanner failed" );
100 /* no semi-colon after return; correct usage is to write "yyterminate();" -
101 * we don't want an extra ';' after the "return" because that will cause
102 * some compilers to complain about unreachable statements.
104 #define yyterminate() return ( YY_NULL )
106 /* report a fatal error */
108 /* The funky do-while is used to turn this macro definition into
109 * a single C statement (which needs a semi-colon terminator).
110 * This avoids problems with code like:
112 * if ( something_happens )
113 * YY_FATAL_ERROR( "oops, the something happened" );
117 * Prior to using the do-while the compiler would get upset at the
118 * "else" because it interpreted the "if" statement as being all
119 * done when it reached the ';' after the YY_FATAL_ERROR() call.
122 #define YY_FATAL_ERROR(msg) \
125 (void) fputs( msg, stderr ); \
126 (void) putc( '\n', stderr ); \
131 /* default yywrap function - always treat EOF as an EOF */
134 /* enter a start condition. This macro really ought to take a parameter,
135 * but we do it the disgusting crufty way forced on us by the ()-less
136 * definition of BEGIN
138 #define BEGIN yy_start = 1 + 2 *
140 /* action number for EOF rule of a given start state */
141 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
143 /* special action meaning "start processing a new file" */
144 #define YY_NEW_FILE \
147 yy_init_buffer( yy_current_buffer, yyin ); \
148 yy_load_buffer_state(); \
152 /* default declaration of generated scanner - a define so the user can
153 * easily add parameters
155 #define YY_DECL int yylex YY_PROTO(( void ))
157 /* code executed at the end of each rule */
158 #define YY_BREAK break;
160 #define YY_END_OF_BUFFER_CHAR 0
163 #define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
166 typedef struct yy_buffer_state *YY_BUFFER_STATE;
168 %% section 1 definitions go here
170 /* done after the current pattern has been matched and before the
171 * corresponding action - sets up yytext
173 #define YY_DO_BEFORE_ACTION \
175 %% code to fiddle yytext and yyleng for yymore() goes here
176 yy_hold_char = *yy_cp; \
180 #define EOB_ACT_CONTINUE_SCAN 0
181 #define EOB_ACT_END_OF_FILE 1
182 #define EOB_ACT_LAST_MATCH 2
184 /* return all but the first 'n' matched characters back to the input stream */
188 /* undo effects of setting up yytext */ \
189 *yy_cp = yy_hold_char; \
190 yy_c_buf_p = yy_cp = yy_bp + n; \
191 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
195 #define unput(c) yyunput( c, yytext )
198 struct yy_buffer_state
202 YY_CHAR *yy_ch_buf; /* input buffer */
203 YY_CHAR *yy_buf_pos; /* current position in input buffer */
205 /* size of input buffer in bytes, not including room for EOB characters*/
208 /* number of characters read into yy_ch_buf, not including EOB characters */
211 int yy_eof_status; /* whether we've seen an EOF on this buffer */
212 #define EOF_NOT_SEEN 0
213 /* "pending" happens when the EOF has been seen but there's still
216 #define EOF_PENDING 1
220 static YY_BUFFER_STATE yy_current_buffer;
222 /* we provide macros for accessing buffer states in case in the
223 * future we want to put the buffer states in a more general
226 #define YY_CURRENT_BUFFER yy_current_buffer
229 /* yy_hold_char holds the character lost when yytext is formed */
230 static YY_CHAR yy_hold_char;
232 static int yy_n_chars; /* number of characters read into yy_ch_buf */
236 #ifndef YY_USER_ACTION
237 #define YY_USER_ACTION
244 extern YY_CHAR *yytext;
246 extern FILE *yyin, *yyout;
251 FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
253 %% data tables for the DFA go here
255 /* these variables are all declared out here so that section 3 code can
258 /* points to current character in buffer */
259 static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0;
260 static int yy_init = 1; /* whether we need to initialize */
261 static int yy_start = 0; /* start state number */
263 /* flag which is used to allow yywrap()'s to do buffer switches
264 * instead of setting up a fresh yyin. A bit of a hack ...
266 static int yy_did_buffer_switch_on_eof;
268 static yy_state_type yy_get_previous_state YY_PROTO(( void ));
269 static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
270 static int yy_get_next_buffer YY_PROTO(( void ));
271 static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr ));
272 void yyrestart YY_PROTO(( FILE *input_file ));
273 void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
274 void yy_load_buffer_state YY_PROTO(( void ));
275 YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
276 void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
277 void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
279 #define yy_new_buffer yy_create_buffer
282 static int yyinput YY_PROTO(( void ));
284 static int input YY_PROTO(( void ));
289 register yy_state_type yy_current_state;
290 register YY_CHAR *yy_cp, *yy_bp;
293 %% user's declarations go here
300 yy_start = 1; /* first start state */
308 if ( yy_current_buffer )
309 yy_init_buffer( yy_current_buffer, yyin );
311 yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
313 yy_load_buffer_state();
318 while ( 1 ) /* loops until end-of-file is reached */
320 %% yymore()-related code goes here
323 /* support of yytext */
324 *yy_cp = yy_hold_char;
326 /* yy_bp points to the position in yy_ch_buf of the start of the
331 %% code to set up and find next match goes here
334 %% code to find the action number goes here
339 do_action: /* this label is used only to access EOF actions */
341 %% debug code goes here
347 case YY_END_OF_BUFFER:
349 /* amount of text matched not including the EOB char */
350 int yy_amount_of_matched_text = yy_cp - yytext - 1;
352 /* undo the effects of YY_DO_BEFORE_ACTION */
353 *yy_cp = yy_hold_char;
355 /* note that here we test for yy_c_buf_p "<=" to the position
356 * of the first EOB in the buffer, since yy_c_buf_p will
357 * already have been incremented past the NUL character
358 * (since all states make transitions on EOB to the end-
359 * of-buffer state). Contrast this with the test in yyinput().
361 if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
362 /* this was really a NUL */
364 yy_state_type yy_next_state;
366 yy_c_buf_p = yytext + yy_amount_of_matched_text;
368 yy_current_state = yy_get_previous_state();
370 /* okay, we're now positioned to make the
371 * NUL transition. We couldn't have
372 * yy_get_previous_state() go ahead and do it
373 * for us because it doesn't know how to deal
374 * with the possibility of jamming (and we
375 * don't want to build jamming into it because
376 * then it will run more slowly)
379 yy_next_state = yy_try_NUL_trans( yy_current_state );
381 yy_bp = yytext + YY_MORE_ADJ;
385 /* consume the NUL */
386 yy_cp = ++yy_c_buf_p;
387 yy_current_state = yy_next_state;
393 %% code to do backtracking for compressed tables and set up yy_cp goes here
398 else switch ( yy_get_next_buffer() )
400 case EOB_ACT_END_OF_FILE:
402 yy_did_buffer_switch_on_eof = 0;
406 /* note: because we've taken care in
407 * yy_get_next_buffer() to have set up yytext,
408 * we can now set up yy_c_buf_p so that if some
409 * total hoser (like flex itself) wants
410 * to call the scanner after we return the
411 * YY_NULL, it'll still work - another YY_NULL
414 yy_c_buf_p = yytext + YY_MORE_ADJ;
416 yy_act = YY_STATE_EOF((yy_start - 1) / 2);
422 if ( ! yy_did_buffer_switch_on_eof )
428 case EOB_ACT_CONTINUE_SCAN:
429 yy_c_buf_p = yytext + yy_amount_of_matched_text;
431 yy_current_state = yy_get_previous_state();
434 yy_bp = yytext + YY_MORE_ADJ;
437 case EOB_ACT_LAST_MATCH:
439 &yy_current_buffer->yy_ch_buf[yy_n_chars];
441 yy_current_state = yy_get_previous_state();
444 yy_bp = yytext + YY_MORE_ADJ;
452 printf( "action # %d\n", yy_act );
455 "fatal flex scanner internal error--no action found" );
461 /* yy_get_next_buffer - try to read in a new buffer
464 * int yy_get_next_buffer();
466 * returns a code representing an action
467 * EOB_ACT_LAST_MATCH -
468 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
469 * EOB_ACT_END_OF_FILE - end of file
472 static int yy_get_next_buffer()
475 register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
476 register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
477 register int number_to_move, i;
480 if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
482 "fatal flex scanner internal error--end of buffer missed" );
484 /* try to read more data */
486 /* first move last chars to start of buffer */
487 number_to_move = yy_c_buf_p - yytext;
489 for ( i = 0; i < number_to_move; ++i )
490 *(dest++) = *(source++);
492 if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
493 /* don't do the read, it's not guaranteed to return an EOF,
500 int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
502 if ( num_to_read > YY_READ_BUF_SIZE )
503 num_to_read = YY_READ_BUF_SIZE;
505 else if ( num_to_read <= 0 )
506 YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
508 /* read in more data */
509 YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
510 yy_n_chars, num_to_read );
513 if ( yy_n_chars == 0 )
515 if ( number_to_move == 1 )
517 ret_val = EOB_ACT_END_OF_FILE;
518 yy_current_buffer->yy_eof_status = EOF_DONE;
523 ret_val = EOB_ACT_LAST_MATCH;
524 yy_current_buffer->yy_eof_status = EOF_PENDING;
529 ret_val = EOB_ACT_CONTINUE_SCAN;
531 yy_n_chars += number_to_move;
532 yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
533 yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
535 /* yytext begins at the second character in yy_ch_buf; the first
536 * character is the one which preceded it before reading in the latest
537 * buffer; it needs to be kept around in case it's a newline, so
538 * yy_get_previous_state() will have with '^' rules active
541 yytext = &yy_current_buffer->yy_ch_buf[1];
547 /* yy_get_previous_state - get the state just before the EOB char was reached
550 * yy_state_type yy_get_previous_state();
553 static yy_state_type yy_get_previous_state()
556 register yy_state_type yy_current_state;
557 register YY_CHAR *yy_cp;
559 %% code to get the start state into yy_current_state goes here
561 for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
563 %% code to find the next state goes here
566 return ( yy_current_state );
570 /* yy_try_NUL_trans - try to make a transition on the NUL character
573 * next_state = yy_try_NUL_trans( current_state );
577 static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )
579 static yy_state_type yy_try_NUL_trans( yy_current_state )
580 register yy_state_type yy_current_state;
584 register int yy_is_jam;
585 %% code to find the next state, and perhaps do backtracking, goes here
587 return ( yy_is_jam ? 0 : yy_current_state );
592 static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
594 static void yyunput( c, yy_bp )
596 register YY_CHAR *yy_bp;
600 register YY_CHAR *yy_cp = yy_c_buf_p;
602 /* undo effects of setting up yytext */
603 *yy_cp = yy_hold_char;
605 if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
606 { /* need to shift things up to make room */
607 register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
608 register YY_CHAR *dest =
609 &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
610 register YY_CHAR *source =
611 &yy_current_buffer->yy_ch_buf[number_to_move];
613 while ( source > yy_current_buffer->yy_ch_buf )
616 yy_cp += dest - source;
617 yy_bp += dest - source;
618 yy_n_chars = yy_current_buffer->yy_buf_size;
620 if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
621 YY_FATAL_ERROR( "flex scanner push-back overflow" );
624 if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
629 /* note: the formal parameter *must* be called "yy_bp" for this
630 * macro to now work correctly
632 YY_DO_BEFORE_ACTION; /* set up yytext again */
644 YY_CHAR *yy_cp = yy_c_buf_p;
646 *yy_cp = yy_hold_char;
648 if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
650 /* yy_c_buf_p now points to the character we want to return.
651 * If this occurs *before* the EOB characters, then it's a
652 * valid NUL; if not, then we've hit the end of the buffer.
654 if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
655 /* this was really a NUL */
659 { /* need more input */
663 switch ( yy_get_next_buffer() )
665 case EOB_ACT_END_OF_FILE:
669 yy_c_buf_p = yytext + YY_MORE_ADJ;
676 return ( yyinput() );
683 case EOB_ACT_CONTINUE_SCAN:
684 yy_c_buf_p = yytext + YY_MORE_ADJ;
687 case EOB_ACT_LAST_MATCH:
689 YY_FATAL_ERROR( "unexpected last match in yyinput()" );
691 YY_FATAL_ERROR( "unexpected last match in input()" );
698 yy_hold_char = *++yy_c_buf_p;
705 void yyrestart( FILE *input_file )
707 void yyrestart( input_file )
712 yy_init_buffer( yy_current_buffer, input_file );
713 yy_load_buffer_state();
718 void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
720 void yy_switch_to_buffer( new_buffer )
721 YY_BUFFER_STATE new_buffer;
725 if ( yy_current_buffer == new_buffer )
728 if ( yy_current_buffer )
730 /* flush out information for old buffer */
731 *yy_c_buf_p = yy_hold_char;
732 yy_current_buffer->yy_buf_pos = yy_c_buf_p;
733 yy_current_buffer->yy_n_chars = yy_n_chars;
736 yy_current_buffer = new_buffer;
737 yy_load_buffer_state();
739 /* we don't actually know whether we did this switch during
740 * EOF (yywrap()) processing, but the only time this flag
741 * is looked at is after yywrap() is called, so it's safe
742 * to go ahead and always set it.
744 yy_did_buffer_switch_on_eof = 1;
749 void yy_load_buffer_state( void )
751 void yy_load_buffer_state()
755 yy_n_chars = yy_current_buffer->yy_n_chars;
756 yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
757 yyin = yy_current_buffer->yy_input_file;
758 yy_hold_char = *yy_c_buf_p;
763 YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
765 YY_BUFFER_STATE yy_create_buffer( file, size )
773 b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
776 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
778 b->yy_buf_size = size;
780 /* yy_ch_buf has to be 2 characters longer than the size given because
781 * we need to put in 2 end-of-buffer characters.
783 b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
785 if ( ! b->yy_ch_buf )
786 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
788 yy_init_buffer( b, file );
795 void yy_delete_buffer( YY_BUFFER_STATE b )
797 void yy_delete_buffer( b )
802 if ( b == yy_current_buffer )
803 yy_current_buffer = (YY_BUFFER_STATE) 0;
805 free( (char *) b->yy_ch_buf );
811 void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
813 void yy_init_buffer( b, file )
819 b->yy_input_file = file;
821 /* we put in the '\n' and start reading from [1] so that an
822 * initial match-at-newline will be true.
825 b->yy_ch_buf[0] = '\n';
828 /* we always need two end-of-buffer characters. The first causes
829 * a transition to the end-of-buffer state. The second causes
830 * a jam in that state.
832 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
833 b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
835 b->yy_buf_pos = &b->yy_ch_buf[1];
837 b->yy_eof_status = EOF_NOT_SEEN;
841 /* redefine yyless() so that it does not access local variables of YYDECL */
845 /* return all but the first 'n' matched characters back to the input stream */
849 /* undo effects of setting up yytext */ \
850 yytext[yyleng] = yy_hold_char; \
851 yy_c_buf_p = yytext + n; \
852 yy_hold_char = *yy_c_buf_p; \
853 *yy_c_buf_p = '\0'; \