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

📄 gen.c

📁 flex 词法分析工具 类似于lex 此版本为较早前的版本
💻 C
📖 第 1 页 / 共 3 页
字号:
		if ( num_backing_up > 0 )			indent_puts( "{" );	/* } for vi */		indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );		if ( num_backing_up > 0 )			{			outc( '\n' );			gen_backing_up();	/* { for vi */			indent_puts( "}" );			}		indent_down();	/* { for vi */		indent_puts( "}" );		}	else		{ /* compressed */		indent_puts( "do" );		indent_up();		indent_puts( "{" );	/* } for vi */		gen_next_state( false );		indent_puts( "++yy_cp;" );		/* { for vi */		indent_puts( "}" );		indent_down();		do_indent();		if ( interactive )			out_dec( "while ( yy_base[yy_current_state] != %d );\n",				jambase );		else			out_dec( "while ( yy_current_state != %d );\n",				jamstate );		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;" );			}		}	}/* Generate the code to find the next state. */void gen_next_state( worry_about_NULs )int worry_about_NULs;	{ /* NOTE - changes in here should be reflected in gen_next_match() */	char char_map[256];	if ( worry_about_NULs && ! nultrans )		{		if ( useecs )			(void) sprintf( char_map,				"(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",					NUL_ec );		else			(void) sprintf( char_map,				"(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );		}	else		strcpy( char_map, useecs ?			"yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)" );	if ( worry_about_NULs && nultrans )		{		if ( ! fulltbl && ! fullspd )			/* Compressed tables back up *before* they match. */			gen_backing_up();		indent_puts( "if ( *yy_cp )" );		indent_up();		indent_puts( "{" );	/* } for vi */		}	if ( fulltbl )		indent_put2s(			"yy_current_state = yy_nxt[yy_current_state][%s];", 				char_map );	else if ( fullspd )		indent_put2s(			"yy_current_state += yy_current_state[%s].yy_nxt;",				char_map );	else		gen_next_compressed_state( char_map );	if ( worry_about_NULs && nultrans )		{		/* { for vi */		indent_puts( "}" );		indent_down();		indent_puts( "else" );		indent_up();		indent_puts(			"yy_current_state = yy_NUL_trans[yy_current_state];" );		indent_down();		}	if ( fullspd || fulltbl )		gen_backing_up();	if ( reject )		indent_puts( "*yy_state_ptr++ = yy_current_state;" );	}/* Generate the code to make a NUL transition. */void gen_NUL_trans()	{ /* NOTE - changes in here should be reflected in gen_next_match() */	/* Only generate a definition for "yy_cp" if we'll generate code	 * that uses it.  Otherwise lint and the like complain.	 */	int need_backing_up = (num_backing_up > 0 && ! reject);	if ( need_backing_up && (! nultrans || fullspd || fulltbl) )		/* We're going to need yy_cp lying around for the call		 * below to gen_backing_up().		 */		indent_puts( "register char *yy_cp = yy_c_buf_p;" );	outc( '\n' );	if ( nultrans )		{		indent_puts(			"yy_current_state = yy_NUL_trans[yy_current_state];" );		indent_puts( "yy_is_jam = (yy_current_state == 0);" );		}	else if ( fulltbl )		{		do_indent();		out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n",			NUL_ec );		indent_puts( "yy_is_jam = (yy_current_state <= 0);" );		}	else if ( fullspd )		{		do_indent();		out_dec( "register int yy_c = %d;\n", NUL_ec );		indent_puts(		"register yyconst struct yy_trans_info *yy_trans_info;\n" );		indent_puts(		"yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );		indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );		indent_puts(			"yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );		}	else		{		char NUL_ec_str[20];		(void) sprintf( NUL_ec_str, "%d", NUL_ec );		gen_next_compressed_state( NUL_ec_str );		do_indent();		out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate );		if ( reject )			{			/* Only stack this state if it's a transition we			 * actually make.  If we stack it on a jam, then			 * the state stack and yy_c_buf_p get out of sync.			 */			indent_puts( "if ( ! yy_is_jam )" );			indent_up();			indent_puts( "*yy_state_ptr++ = yy_current_state;" );			indent_down();			}		}	/* If we've entered an accepting state, back up; note that	 * compressed tables have *already* done such backing up, so	 * we needn't bother with it again.	 */	if ( need_backing_up && (fullspd || fulltbl) )		{		outc( '\n' );		indent_puts( "if ( ! yy_is_jam )" );		indent_up();		indent_puts( "{" );		gen_backing_up();		indent_puts( "}" );		indent_down();		}	}/* Generate the code to find the start state. */void gen_start_state()	{	if ( fullspd )		{		if ( bol_needed )			{			indent_puts(	"yy_current_state = yy_start_state_list[yy_start + YY_AT_BOL()];" );			}		else			indent_puts(			"yy_current_state = yy_start_state_list[yy_start];" );		}	else		{		indent_puts( "yy_current_state = yy_start;" );		if ( bol_needed )			indent_puts( "yy_current_state += YY_AT_BOL();" );		if ( reject )			{			/* Set up for storing up states. */			indent_puts( "yy_state_ptr = yy_state_buf;" );			indent_puts( "*yy_state_ptr++ = yy_current_state;" );			}		}	}/* gentabs - generate data statements for the transition tables */void gentabs()	{	int i, j, k, *accset, nacc, *acc_array, total_states;	int end_of_buffer_action = num_rules + 1;	acc_array = allocate_integer_array( current_max_dfas );	nummt = 0;	/* The compressed table format jams by entering the "jam state",	 * losing information about the previous state in the process.	 * In order to recover the previous state, we effectively need	 * to keep backing-up information.	 */	++num_backing_up;	if ( reject )		{		/* Write out accepting list and pointer list.		 *		 * First we generate the "yy_acclist" array.  In the process,		 * we compute the indices that will go into the "yy_accept"		 * array, and save the indices in the dfaacc array.		 */		int EOB_accepting_list[2];		/* Set up accepting structures for the End Of Buffer state. */		EOB_accepting_list[0] = 0;		EOB_accepting_list[1] = end_of_buffer_action;		accsiz[end_of_buffer_state] = 1;		dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;		out_str_dec( long_align ? C_long_decl : C_short_decl,			"yy_acclist", MAX( numas, 1 ) + 1 );		j = 1;	/* index into "yy_acclist" array */		for ( i = 1; i <= lastdfa; ++i )			{			acc_array[i] = j;			if ( accsiz[i] != 0 )				{				accset = dfaacc[i].dfaacc_set;				nacc = accsiz[i];				if ( trace )					fprintf( stderr,						_( "state # %d accepts: " ),						i );				for ( k = 1; k <= nacc; ++k )					{					int accnum = accset[k];					++j;					if ( variable_trailing_context_rules &&					  ! (accnum & YY_TRAILING_HEAD_MASK) &&					   accnum > 0 && accnum <= num_rules &&					  rule_type[accnum] == RULE_VARIABLE )						{						/* Special hack to flag						 * accepting number as part						 * of trailing context rule.						 */						accnum |= YY_TRAILING_MASK;						}					mkdata( accnum );					if ( trace )						{						fprintf( stderr, "[%d]",							accset[k] );						if ( k < nacc )							fputs( ", ", stderr );						else							putc( '\n', stderr );						}					}				}			}		/* add accepting number for the "jam" state */		acc_array[i] = j;		dataend();		}	else		{		dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;		for ( i = 1; i <= lastdfa; ++i )			acc_array[i] = dfaacc[i].dfaacc_state;		/* add accepting number for jam state */		acc_array[i] = 0;		}	/* Spit out "yy_accept" array.  If we're doing "reject", it'll be	 * pointers into the "yy_acclist" array.  Otherwise it's actual	 * accepting numbers.  In either case, we just dump the numbers.	 */	/* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays	 * beginning at 0 and for "jam" state.	 */	k = lastdfa + 2;	if ( reject )		/* We put a "cap" on the table associating lists of accepting		 * numbers with state numbers.  This is needed because we tell		 * where the end of an accepting list is by looking at where		 * the list for the next state starts.		 */		++k;	out_str_dec( long_align ? C_long_decl : C_short_decl, "yy_accept", k );	for ( i = 1; i <= lastdfa; ++i )		{		mkdata( acc_array[i] );		if ( ! reject && trace && acc_array[i] )			fprintf( stderr, _( "state # %d accepts: [%d]\n" ),				i, acc_array[i] );		}	/* Add entry for "jam" state. */	mkdata( acc_array[i] );	if ( reject )		/* Add "cap" for the list. */		mkdata( acc_array[i] );	dataend();	if ( useecs )		genecs();	if ( usemecs )		{		/* Write out meta-equivalence classes (used to index		 * templates with).		 */		if ( trace )			fputs( _( "\n\nMeta-Equivalence Classes:\n" ),			      stderr );		out_str_dec( C_int_decl, "yy_meta", numecs + 1 );		for ( i = 1; i <= numecs; ++i )			{			if ( trace )				fprintf( stderr, "%d = %d\n",					i, ABS( tecbck[i] ) );			mkdata( ABS( tecbck[i] ) );			}		dataend();		}	total_states = lastdfa + numtemps;	out_str_dec( (tblend >= MAX_SHORT || long_align) ?			C_long_decl : C_short_decl,		"yy_base", total_states + 1 );	for ( i = 1; i <= lastdfa; ++i )		{		register int d = def[i];		if ( base[i] == JAMSTATE )			base[i] = jambase;		if ( d == JAMSTATE )			def[i] = jamstate;		else if ( d < 0 )			{			/* Template reference. */			++tmpuses;			def[i] = lastdfa - d + 1;			}		mkdata( base[i] );		}	/* Generate jam state's base index. */	mkdata( base[i] );	for ( ++i /* skip jam state */; i <= total_states; ++i )		{		mkdata( base[i] );		def[i] = jamstate;		}	dataend();	out_str_dec( (total_states >= MAX_SHORT || long_align) ?			C_long_decl : C_short_decl,		"yy_def", total_states + 1 );	for ( i = 1; i <= total_states; ++i )		mkdata( def[i] );	dataend();	out_str_dec( (total_states >= MAX_SHORT || long_align) ?			C_long_decl : C_short_decl,		"yy_nxt", tblend + 1 );	for ( i = 1; i <= tblend; ++i )		{		/* Note, the order of the following test is important.		 * If chk[i] is 0, then nxt[i] is undefined.		 */		if ( chk[i] == 0 || nxt[i] == 0 )			nxt[i] = jamstate;	/* new state is the JAM state */		mkdata( nxt[i] );		}	dataend();	out_str_dec( (total_states >= MAX_SHORT || long_align) ?			C_long_decl : C_short_decl,		"yy_chk", tblend + 1 );	for ( i = 1; i <= tblend; ++i )		{		if ( chk[i] == 0 )			++nummt;		mkdata( chk[i] );		}	dataend();	}/* Write out a formatted string (with a secondary string argument) at the * current indentation level, adding a final newline. */void indent_put2s( fmt, arg )char fmt[], arg[];	{	do_indent();	out_str( fmt, arg );	outn( "" );	}/* Write out a string at the current indentation level, adding a final * newline. */void indent_puts( str )char str[];	{	do_indent();	outn( str );	}/* make_tables - generate transition tables and finishes generating output file */void make_tables()	{	register int i;	int did_eof_rule = false;	skelout();	/* First, take care of YY_DO_BEFORE_ACTION depending on yymore	 * being used.	 */	set_indent( 1 );	if ( yymore_used && ! yytext_is_array )		{		indent_puts( "yytext_ptr -= yy_more_len; \\" );		indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" );		}	else		indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" );	/* Now also deal with copying yytext_ptr to yytext if needed. */	skelout();	if ( yytext_is_array )		{		if ( yymore_used )			indent_puts(				"if ( yyleng + yy_more_offset >= YYLMAX ) \\" );

⌨️ 快捷键说明

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