⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scan-skel.c

📁 GNU的词法/语法分析器bison源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	if ( ! b )		return;	if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */		YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;	if ( b->yy_is_our_buffer )		skel_free((void *) b->yy_ch_buf  );	skel_free((void *) b  );}/* %if-c-only *//* %endif *//* %if-c++-only *//* %endif *//* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a skel_restart() or at EOF. *//* %if-c-only */    static void skel__init_buffer  (YY_BUFFER_STATE  b, FILE * file )/* %endif *//* %if-c++-only *//* %endif */{	int oerrno = errno;    	skel__flush_buffer(b );	b->yy_input_file = file;	b->yy_fill_buffer = 1;    /* If b is the current buffer, then skel__init_buffer was _probably_     * called from skel_restart() or through yy_get_next_buffer.     * In that case, we don't want to reset the lineno or column.     */    if (b != YY_CURRENT_BUFFER){        b->yy_bs_lineno = 1;        b->yy_bs_column = 0;    }/* %if-c-only */        b->yy_is_interactive = 0;    /* %endif *//* %if-c++-only *//* %endif */	errno = oerrno;}/** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. *  *//* %if-c-only */    void skel__flush_buffer (YY_BUFFER_STATE  b )/* %endif *//* %if-c++-only *//* %endif */{    	if ( ! b )		return;	b->yy_n_chars = 0;	/* 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.	 */	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;	b->yy_buf_pos = &b->yy_ch_buf[0];	b->yy_at_bol = 1;	b->yy_buffer_status = YY_BUFFER_NEW;	if ( b == YY_CURRENT_BUFFER )		skel__load_buffer_state( );}/* %if-c-or-c++ *//** Pushes the new state onto the stack. The new state becomes *  the current state. This function will allocate the stack *  if necessary. *  @param new_buffer The new state. *   *//* %if-c-only */void skel_push_buffer_state (YY_BUFFER_STATE new_buffer )/* %endif *//* %if-c++-only *//* %endif */{    	if (new_buffer == NULL)		return;	skel_ensure_buffer_stack();	/* This block is copied from skel__switch_to_buffer. */	if ( YY_CURRENT_BUFFER )		{		/* Flush out information for old buffer. */		*(yy_c_buf_p) = (yy_hold_char);		YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);		YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);		}	/* Only push if top exists. Otherwise, replace top. */	if (YY_CURRENT_BUFFER)		(yy_buffer_stack_top)++;	YY_CURRENT_BUFFER_LVALUE = new_buffer;	/* copied from skel__switch_to_buffer. */	skel__load_buffer_state( );	(yy_did_buffer_switch_on_eof) = 1;}/* %endif *//* %if-c-or-c++ *//** Removes and deletes the top of the stack, if present. *  The next element becomes the new top. *   *//* %if-c-only */void skel_pop_buffer_state (void)/* %endif *//* %if-c++-only *//* %endif */{    	if (!YY_CURRENT_BUFFER)		return;	skel__delete_buffer(YY_CURRENT_BUFFER );	YY_CURRENT_BUFFER_LVALUE = NULL;	if ((yy_buffer_stack_top) > 0)		--(yy_buffer_stack_top);	if (YY_CURRENT_BUFFER) {		skel__load_buffer_state( );		(yy_did_buffer_switch_on_eof) = 1;	}}/* %endif *//* %if-c-or-c++ *//* Allocates the stack if it does not exist. *  Guarantees space for at least one push. *//* %if-c-only */static void skel_ensure_buffer_stack (void)/* %endif *//* %if-c++-only *//* %endif */{	int num_to_alloc;    	if (!(yy_buffer_stack)) {		/* First allocation is just for 2 elements, since we don't know if this		 * scanner will even need a stack. We use 2 instead of 1 to avoid an		 * immediate realloc on the next call.         */		num_to_alloc = 1;		(yy_buffer_stack) = (struct yy_buffer_state**)skel_alloc								(num_to_alloc * sizeof(struct yy_buffer_state*)								);				memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));						(yy_buffer_stack_max) = num_to_alloc;		(yy_buffer_stack_top) = 0;		return;	}	if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){		/* Increase the buffer to prepare for a possible push. */		int grow_size = 8 /* arbitrary grow size */;		num_to_alloc = (yy_buffer_stack_max) + grow_size;		(yy_buffer_stack) = (struct yy_buffer_state**)skel_realloc								((yy_buffer_stack),								num_to_alloc * sizeof(struct yy_buffer_state*)								);		/* zero only the new slots.*/		memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));		(yy_buffer_stack_max) = num_to_alloc;	}}/* %endif *//* %if-c-only *//** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer *  * @return the newly allocated buffer state object.  */YY_BUFFER_STATE skel__scan_buffer  (char * base, yy_size_t  size ){	YY_BUFFER_STATE b;    	if ( size < 2 ||	     base[size-2] != YY_END_OF_BUFFER_CHAR ||	     base[size-1] != YY_END_OF_BUFFER_CHAR )		/* They forgot to leave room for the EOB's. */		return 0;	b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state )  );	if ( ! b )		YY_FATAL_ERROR( "out of dynamic memory in skel__scan_buffer()" );	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */	b->yy_buf_pos = b->yy_ch_buf = base;	b->yy_is_our_buffer = 0;	b->yy_input_file = 0;	b->yy_n_chars = b->yy_buf_size;	b->yy_is_interactive = 0;	b->yy_at_bol = 1;	b->yy_fill_buffer = 0;	b->yy_buffer_status = YY_BUFFER_NEW;	skel__switch_to_buffer(b  );	return b;}/* %endif *//* %if-c-only *//** Setup the input buffer state to scan a string. The next call to skel_lex() will * scan from a @e copy of @a str. * @param str a NUL-terminated string to scan *  * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use *       skel__scan_bytes() instead. */YY_BUFFER_STATE skel__scan_string (yyconst char * yy_str ){    	return skel__scan_bytes(yy_str,strlen(yy_str) );}/* %endif *//* %if-c-only *//** Setup the input buffer state to scan the given bytes. The next call to skel_lex() will * scan from a @e copy of @a bytes. * @param bytes the byte buffer to scan * @param len the number of bytes in the buffer pointed to by @a bytes. *  * @return the newly allocated buffer state object. */YY_BUFFER_STATE skel__scan_bytes  (yyconst char * bytes, int  len ){	YY_BUFFER_STATE b;	char *buf;	yy_size_t n;	int i;    	/* Get memory for full buffer, including space for trailing EOB's. */	n = len + 2;	buf = (char *) skel_alloc(n  );	if ( ! buf )		YY_FATAL_ERROR( "out of dynamic memory in skel__scan_bytes()" );	for ( i = 0; i < len; ++i )		buf[i] = bytes[i];	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;	b = skel__scan_buffer(buf,n );	if ( ! b )		YY_FATAL_ERROR( "bad buffer in skel__scan_bytes()" );	/* It's okay to grow etc. this buffer, and we should throw it	 * away when we're done.	 */	b->yy_is_our_buffer = 1;	return b;}/* %endif */#ifndef YY_EXIT_FAILURE#define YY_EXIT_FAILURE 2#endif/* %if-c-only */static void yy_fatal_error (yyconst char* msg ){    	(void) fprintf( stderr, "%s\n", msg );	exit( YY_EXIT_FAILURE );}/* %endif *//* %if-c++-only *//* %endif *//* Redefine yyless() so it works in section 3 code. */#undef yyless#define yyless(n) \	do \		{ \		/* Undo effects of setting up skel_text. */ \        int yyless_macro_arg = (n); \        YY_LESS_LINENO(yyless_macro_arg);\		skel_text[skel_leng] = (yy_hold_char); \		(yy_c_buf_p) = skel_text + yyless_macro_arg; \		(yy_hold_char) = *(yy_c_buf_p); \		*(yy_c_buf_p) = '\0'; \		skel_leng = yyless_macro_arg; \		} \	while ( 0 )/* Accessor  methods (get/set functions) to struct members. *//* %if-c-only *//* %if-reentrant *//* %endif *//** Get the current line number. *  */int skel_get_lineno  (void){            return skel_lineno;}/** Get the input stream. *  */FILE *skel_get_in  (void){        return skel_in;}/** Get the output stream. *  */FILE *skel_get_out  (void){        return skel_out;}/** Get the length of the current token. *  */int skel_get_leng  (void){        return skel_leng;}/** Get the current token. *  */char *skel_get_text  (void){        return skel_text;}/* %if-reentrant *//* %endif *//** Set the current line number. * @param line_number *  */void skel_set_lineno (int  line_number ){        skel_lineno = line_number;}/** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. *  * @see skel__switch_to_buffer */void skel_set_in (FILE *  in_str ){        skel_in = in_str ;}void skel_set_out (FILE *  out_str ){        skel_out = out_str ;}int skel_get_debug  (void){        return skel__flex_debug;}void skel_set_debug (int  bdebug ){        skel__flex_debug = bdebug ;}/* %endif *//* %if-reentrant *//* %if-bison-bridge *//* %endif *//* %endif *//* %if-c-only SNIP! this currently causes conflicts with the c++ scanner *//* skel_lex_destroy is for both reentrant and non-reentrant scanners. */int skel_lex_destroy  (void){        /* Pop the buffer stack, destroying each element. */	while(YY_CURRENT_BUFFER){		skel__delete_buffer(YY_CURRENT_BUFFER  );		YY_CURRENT_BUFFER_LVALUE = NULL;		skel_pop_buffer_state();	}	/* Destroy the stack itself. */	skel_free((yy_buffer_stack) );	(yy_buffer_stack) = NULL;/* %if-reentrant *//* %endif */    return 0;}/* %endif *//* * Internal utility routines. */#ifndef yytext_ptrstatic void yy_flex_strncpy (char* s1, yyconst char * s2, int n ){	register int i;    	for ( i = 0; i < n; ++i )		s1[i] = s2[i];}#endif#ifdef YY_NEED_STRLENstatic int yy_flex_strlen (yyconst char * s ){	register int n;    	for ( n = 0; s[n]; ++n )		;	return n;}#endifvoid *skel_alloc (yy_size_t  size ){	return (void *) malloc( size );}void *skel_realloc  (void * ptr, yy_size_t  size ){	/* The cast to (char *) in the following accommodates both	 * implementations that use char* generic pointers, and those	 * that use void* generic pointers.  It works with the latter	 * because both ANSI C and C++ allow castless assignment from	 * any pointer type to void*, and deal with argument conversions	 * as though doing an assignment.	 */	return (void *) realloc( (char *) ptr, size );}void skel_free (void * ptr ){	free( (char *) ptr );	/* see skel_realloc() for (char *) cast */}/* %if-tables-serialization definitions *//* %define-yytables   The name for this specific scanner's tables. */#define YYTABLES_NAME "yytables"/* %endif *//* %ok-for-header */#undef YY_NEW_FILE#undef YY_FLUSH_BUFFER#undef yy_set_bol#undef yy_new_buffer#undef yy_set_interactive#undef yytext_ptr#undef YY_DO_BEFORE_ACTION#ifdef YY_DECL_IS_OURS#undef YY_DECL_IS_OURS#undef YY_DECL#endif#line 93 "scan-skel.l"/*------------------------.| Scan a Bison skeleton.  |`------------------------*/voidscan_skel (FILE *in){  skel_in = in;  skel__flex_debug = trace_flag & trace_skeleton;  skel_lex ();  /* Reclaim Flex's buffers.  */  skel__delete_buffer (YY_CURRENT_BUFFER);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -