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

📄 gen.c

📁 flex 词法分析工具 类似于lex 此版本为较早前的版本
💻 C
📖 第 1 页 / 共 3 页
字号:
		else			indent_puts( "if ( yyleng >= YYLMAX ) \\" );		indent_up();		indent_puts(		"YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );		indent_down();		if ( yymore_used )			{			indent_puts("yy_flex_strncpy( &yytext[yy_more_offset], yytext_ptr, yyleng + 1 ); \\" );			indent_puts( "yyleng += yy_more_offset; \\" );			indent_puts(				"yy_prev_more_offset = yy_more_offset; \\" );			indent_puts( "yy_more_offset = 0; \\" );			}		else			{			indent_puts(		"yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" );			}		}	set_indent( 0 );	skelout();	out_dec( "#define YY_NUM_RULES %d\n", num_rules );	out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );	if ( fullspd )		{		/* Need to define the transet type as a size large		 * enough to hold the biggest offset.		 */		int total_table_size = tblend + numecs + 1;		char *trans_offset_type =			(total_table_size >= MAX_SHORT || long_align) ?				"long" : "short";		set_indent( 0 );		indent_puts( "struct yy_trans_info" );		indent_up();		indent_puts( "{" ); 	/* } for vi */		if ( long_align )			indent_puts( "long yy_verify;" );		else			indent_puts( "short yy_verify;" );		/* In cases where its sister yy_verify *is* a "yes, there is		 * a transition", yy_nxt is the offset (in records) to the		 * next state.  In most cases where there is no transition,		 * the value of yy_nxt is irrelevant.  If yy_nxt is the -1th		 * record of a state, though, then yy_nxt is the action number		 * for that state.		 */		indent_put2s( "%s yy_nxt;", trans_offset_type );		indent_puts( "};" );		indent_down();		}	if ( fullspd )		genctbl();	else if ( fulltbl )		genftbl();	else		gentabs();	/* Definitions for backing up.  We don't need them if REJECT	 * is being used because then we use an alternative backin-up	 * technique instead.	 */	if ( num_backing_up > 0 && ! reject )		{		if ( ! C_plus_plus )			{			indent_puts(			"static yy_state_type yy_last_accepting_state;" );			indent_puts(				"static char *yy_last_accepting_cpos;\n" );			}		}	if ( nultrans )		{		out_str_dec( C_state_decl, "yy_NUL_trans", lastdfa + 1 );		for ( i = 1; i <= lastdfa; ++i )			{			if ( fullspd )				out_dec( "    &yy_transition[%d],\n", base[i] );			else				mkdata( nultrans[i] );			}		dataend();		}	if ( ddebug )		{ /* Spit out table mapping rules to line numbers. */		if ( ! C_plus_plus )			{			indent_puts( "extern int yy_flex_debug;" );			indent_puts( "int yy_flex_debug = 1;\n" );			}		out_str_dec( long_align ? C_long_decl : C_short_decl,			"yy_rule_linenum", num_rules );		for ( i = 1; i < num_rules; ++i )			mkdata( rule_linenum[i] );		dataend();		}	if ( reject )		{		/* Declare state buffer variables. */		if ( ! C_plus_plus )			{			outn(	"static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );			outn( "static char *yy_full_match;" );			outn( "static int yy_lp;" );			}		if ( variable_trailing_context_rules )			{			if ( ! C_plus_plus )				{				outn(				"static int yy_looking_for_trail_begin = 0;" );				outn( "static int yy_full_lp;" );				outn( "static int *yy_full_state;" );				}			out_hex( "#define YY_TRAILING_MASK 0x%x\n",				(unsigned int) YY_TRAILING_MASK );			out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n",				(unsigned int) YY_TRAILING_HEAD_MASK );			}		outn( "#define REJECT \\" );		outn( "{ \\" );		/* } for vi */		outn(	"*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );		outn(	"yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );		if ( variable_trailing_context_rules )			{			outn(		"yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );			outn(		"yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );			outn(	"yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );			}		outn( "++yy_lp; \\" );		outn( "goto find_rule; \\" );		/* { for vi */		outn( "}" );		}	else		{		outn(		"/* The intent behind this definition is that it'll catch" );		outn( " * any uses of REJECT which flex missed." );		outn( " */" );		outn( "#define REJECT reject_used_but_not_detected" );		}	if ( yymore_used )		{		if ( ! C_plus_plus )			{			if ( yytext_is_array )				{				indent_puts( "static int yy_more_offset = 0;" );				indent_puts(					"static int yy_prev_more_offset = 0;" );				}			else				{				indent_puts( "static int yy_more_flag = 0;" );				indent_puts( "static int yy_more_len = 0;" );				}			}		if ( yytext_is_array )			{			indent_puts(	"#define yymore() (yy_more_offset = yy_flex_strlen( yytext ))" );			indent_puts( "#define YY_NEED_STRLEN" );			indent_puts( "#define YY_MORE_ADJ 0" );			indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" );			indent_up();			indent_puts( "{ \\" );			indent_puts( "yy_more_offset = yy_prev_more_offset; \\" );			indent_puts( "yyleng -= yy_more_offset; \\" );			indent_puts( "}" );			indent_down();			}		else			{			indent_puts( "#define yymore() (yy_more_flag = 1)" );			indent_puts( "#define YY_MORE_ADJ yy_more_len" );			indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );			}		}	else		{		indent_puts( "#define yymore() yymore_used_but_not_detected" );		indent_puts( "#define YY_MORE_ADJ 0" );		indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );		}	if ( ! C_plus_plus )		{		if ( yytext_is_array )			{			outn( "#ifndef YYLMAX" );			outn( "#define YYLMAX 8192" );			outn( "#endif\n" );			outn( "char yytext[YYLMAX];" );			outn( "char *yytext_ptr;" );			}		else			outn( "char *yytext;" );		}	out( &action_array[defs1_offset] );	line_directive_out( stdout, 0 );	skelout();	if ( ! C_plus_plus )		{		if ( use_read )			{			outn("\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" );			outn(		"\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );			}		else			{			outn(			"\tif ( yy_current_buffer->yy_is_interactive ) \\" );			outn( "\t\t{ \\" );			outn( "\t\tint c = '*', n; \\" );			outn( "\t\tfor ( n = 0; n < max_size && \\" );	outn( "\t\t\t     (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );			outn( "\t\t\tbuf[n] = (char) c; \\" );			outn( "\t\tif ( c == '\\n' ) \\" );			outn( "\t\t\tbuf[n++] = (char) c; \\" );			outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" );			outn(	"\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );			outn( "\t\tresult = n; \\" );			outn( "\t\t} \\" );			outn(	"\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\" );			outn( "\t\t  && ferror( yyin ) ) \\" );			outn(		"\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );			}		}	skelout();	indent_puts( "#define YY_RULE_SETUP \\" );	indent_up();	if ( bol_needed )		{		indent_puts( "if ( yyleng > 0 ) \\" );		indent_up();		indent_puts( "yy_current_buffer->yy_at_bol = \\" );		indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" );		indent_down();		}	indent_puts( "YY_USER_ACTION" );	indent_down();	skelout();	/* Copy prolog to output file. */	out( &action_array[prolog_offset] );	line_directive_out( stdout, 0 );	skelout();	set_indent( 2 );	if ( yymore_used && ! yytext_is_array )		{		indent_puts( "yy_more_len = 0;" );		indent_puts( "if ( yy_more_flag )" );		indent_up();		indent_puts( "{" );		indent_puts( "yy_more_len = yy_c_buf_p - yytext_ptr;" );		indent_puts( "yy_more_flag = 0;" );		indent_puts( "}" );		indent_down();		}	skelout();	gen_start_state();	/* Note, don't use any indentation. */	outn( "yy_match:" );	gen_next_match();	skelout();	set_indent( 2 );	gen_find_action();	skelout();	if ( do_yylineno )		{		indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );		indent_up();		indent_puts( "{" );		indent_puts( "int yyl;" );		indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );		indent_up();		indent_puts( "if ( yytext[yyl] == '\\n' )" );		indent_up();		indent_puts( "++yylineno;" );		indent_down();		indent_down();		indent_puts( "}" );		indent_down();		}	skelout();	if ( ddebug )		{		indent_puts( "if ( yy_flex_debug )" );		indent_up();		indent_puts( "{" );		indent_puts( "if ( yy_act == 0 )" );		indent_up();		indent_puts( C_plus_plus ?			"cerr << \"--scanner backing up\\n\";" :			"fprintf( stderr, \"--scanner backing up\\n\" );" );		indent_down();		do_indent();		out_dec( "else if ( yy_act < %d )\n", num_rules );		indent_up();		if ( C_plus_plus )			{			indent_puts(	"cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" );			indent_puts(			"         \"(\\\"\" << yytext << \"\\\")\\n\";" );			}		else			{			indent_puts(	"fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );			indent_puts(				"         yy_rule_linenum[yy_act], yytext );" );			}		indent_down();		do_indent();		out_dec( "else if ( yy_act == %d )\n", num_rules );		indent_up();		if ( C_plus_plus )			{			indent_puts("cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";" );			}		else			{			indent_puts(	"fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );			indent_puts( "         yytext );" );			}		indent_down();		do_indent();		out_dec( "else if ( yy_act == %d )\n", num_rules + 1 );		indent_up();		indent_puts( C_plus_plus ?			"cerr << \"--(end of buffer or a NUL)\\n\";" :		"fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );		indent_down();		do_indent();		outn( "else" );		indent_up();		if ( C_plus_plus )			{			indent_puts(	"cerr << \"--EOF (start condition \" << YY_START << \")\\n\";" );			}		else			{			indent_puts(	"fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );			}		indent_down();		indent_puts( "}" );		indent_down();		}	/* Copy actions to output file. */	skelout();	indent_up();	gen_bu_action();	out( &action_array[action_offset] );	line_directive_out( stdout, 0 );	/* generate cases for any missing EOF rules */	for ( i = 1; i <= lastsc; ++i )		if ( ! sceof[i] )			{			do_indent();			out_str( "case YY_STATE_EOF(%s):\n", scname[i] );			did_eof_rule = true;			}	if ( did_eof_rule )		{		indent_up();		indent_puts( "yyterminate();" );		indent_down();		}	/* Generate code for handling NUL's, if needed. */	/* First, deal with backing up and setting up yy_cp if the scanner	 * finds that it should JAM on the NUL.	 */	skelout();	set_indent( 4 );	if ( fullspd || fulltbl )		indent_puts( "yy_cp = yy_c_buf_p;" );	else		{ /* compressed table */		if ( ! reject && ! interactive )			{			/* Do the guaranteed-needed backing up to figure			 * out the match.			 */			indent_puts( "yy_cp = yy_last_accepting_cpos;" );			indent_puts(				"yy_current_state = yy_last_accepting_state;" );			}		else			/* Still need to initialize yy_cp, though			 * yy_current_state was set up by			 * yy_get_previous_state().			 */			indent_puts( "yy_cp = yy_c_buf_p;" );		}	/* Generate code for yy_get_previous_state(). */	set_indent( 1 );	skelout();	gen_start_state();	set_indent( 2 );	skelout();	gen_next_state( true );	set_indent( 1 );	skelout();	gen_NUL_trans();	skelout();	if ( do_yylineno )		{ /* update yylineno inside of unput() */		indent_puts( "if ( c == '\\n' )" );		indent_up();		indent_puts( "--yylineno;" );		indent_down();		}	skelout();	/* Update BOL and yylineno inside of input(). */	if ( bol_needed )		{		indent_puts( "yy_current_buffer->yy_at_bol = (c == '\\n');" );		if ( do_yylineno )			{			indent_puts( "if ( yy_current_buffer->yy_at_bol )" );			indent_up();			indent_puts( "++yylineno;" );			indent_down();			}		}	else if ( do_yylineno )		{		indent_puts( "if ( c == '\\n' )" );		indent_up();		indent_puts( "++yylineno;" );		indent_down();		}	skelout();	/* Copy remainder of input to output. */	line_directive_out( stdout, 1 );	if ( sectnum == 3 )		(void) flexscan(); /* copy remainder of input to output */	}

⌨️ 快捷键说明

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