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

📄 lexyy.c

📁 这个是我在编译原理做的课程设计,一个编译器,包括词法语法分析,结果生成四元式序列,可执行文件也在里面:)
💻 C
📖 第 1 页 / 共 2 页
字号:
	    {
	    yy_act = yy_accept[yy_current_state];

	    YY_DO_BEFORE_ACTION;
	    YY_USER_ACTION;

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

do_action:	/* this label is used only to access EOF actions */
	    switch ( yy_act )
		{
		case 0: /* must backtrack */
		/* undo the effects of YY_DO_BEFORE_ACTION */
		*yy_cp = yy_hold_char;
		yy_cp = yy_last_accepting_cpos;
		yy_current_state = yy_last_accepting_state;
		continue; /* go to "YY_DO_BEFORE_ACTION" */

case 1:
# line 38 "p1.l"
{BEGIN COMMENT;}
	YY_BREAK
case 2:
# line 39 "p1.l"
{BEGIN 0;}
	YY_BREAK
case 3:
# line 40 "p1.l"
{}
	YY_BREAK
case 4:
# line 41 "p1.l"
{}
	YY_BREAK
case 5:
# line 44 "p1.l"
return IntNo;  
	YY_BREAK
case 6:
# line 45 "p1.l"
return RealNo;
	YY_BREAK
case 7:
# line 47 "p1.l"
return '(';
	YY_BREAK
case 8:
# line 48 "p1.l"
return ')';
	YY_BREAK
case 9:
# line 49 "p1.l"
return '+';
	YY_BREAK
case 10:
# line 50 "p1.l"
return '-';
	YY_BREAK
case 11:
# line 51 "p1.l"
return '*';
	YY_BREAK
case 12:
# line 52 "p1.l"
return '/';
	YY_BREAK
case 13:
# line 53 "p1.l"
return '%';
	YY_BREAK
case 14:
# line 54 "p1.l"
return '=';
	YY_BREAK
case 15:
# line 55 "p1.l"
return '<';
	YY_BREAK
case 16:
# line 56 "p1.l"
return '>';
	YY_BREAK
case 17:
# line 57 "p1.l"
return '&';
	YY_BREAK
case 18:
# line 58 "p1.l"
return '|';
	YY_BREAK
case 19:
# line 59 "p1.l"
return '.';
	YY_BREAK
case 20:
# line 60 "p1.l"
return ',';
	YY_BREAK
case 21:
# line 61 "p1.l"
return ':';
	YY_BREAK
case 22:
# line 62 "p1.l"
return ';';
	YY_BREAK
/*key word*/
case 23:
# line 64 "p1.l"
return Program;
	YY_BREAK
case 24:
# line 65 "p1.l"
return Begin;
	YY_BREAK
case 25:
# line 66 "p1.l"
return End;
	YY_BREAK
case 26:
# line 67 "p1.l"
return Var;
	YY_BREAK
case 27:
# line 68 "p1.l"
return Integer;
	YY_BREAK
case 28:
# line 69 "p1.l"
return Real;
	YY_BREAK
case 29:
# line 70 "p1.l"
return While;
	YY_BREAK
case 30:
# line 71 "p1.l"
return Do;
	YY_BREAK
case 31:
# line 72 "p1.l"
return If;
	YY_BREAK
case 32:
# line 73 "p1.l"
return Then;
	YY_BREAK
case 33:
# line 74 "p1.l"
return Else;
	YY_BREAK
case 34:
# line 75 "p1.l"
return Or;
	YY_BREAK
case 35:
# line 76 "p1.l"
return And;
	YY_BREAK
case 36:
# line 77 "p1.l"
return Not;
	YY_BREAK
/*other symbol*/
case 37:
# line 79 "p1.l"
return Iden;
	YY_BREAK
case 38:
# line 80 "p1.l"
{}	/* Ignore white space */
	YY_BREAK
case 39:
# line 81 "p1.l"
{
   				 printf(" Invalid char %s\n",yytext);
				 return ERRORCHAR;
			}
	YY_BREAK
case 40:
# line 85 "p1.l"
ECHO;
	YY_BREAK
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(COMMENT):
    yyterminate();

		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;

				yy_act = YY_STATE_EOF((yy_start - 1) / 2);
				goto do_action;
				}

			    else
				YY_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()

    {
	register unsigned char  *dest = yy_ch_buf;
	register unsigned char  *source = yytext - 1; /* copy prev. char, too */
    register int number_to_move, i;
    int ret_val;

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

    /* try to read more data */

    /* 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
	{
	int num_to_read = YY_BUF_SIZE - number_to_move - 1;

	if ( num_to_read > YY_READ_BUF_SIZE )
	    num_to_read = YY_READ_BUF_SIZE;

	/* read in more data */
	YY_INPUT( (&yy_ch_buf[number_to_move]), yy_n_chars, num_to_read );
	}

    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 unsigned char  *yy_cp;

    yy_current_state = yy_start;

    for ( yy_cp = yytext; yy_cp < yy_c_buf_p; ++yy_cp )
	{
	register unsigned char   yy_c = yy_ec[*yy_cp];
	if ( yy_accept[yy_current_state] )
	    {
	    yy_last_accepting_state = yy_current_state;
	    yy_last_accepting_cpos = yy_cp;
	    }
	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
	    {
	    yy_current_state = yy_def[yy_current_state];
	    if ( yy_current_state >= 183 )
		yy_c = yy_meta[yy_c];
	    }
	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
	}

    return ( yy_current_state );
    }


static void yyunput( int c, register unsigned char  *yy_bp )
    {
	register unsigned 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 unsigned char  *dest = &yy_ch_buf[YY_BUF_SIZE + 2];
	register unsigned 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;
	unsigned 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 );
    }


static void yyrestart( FILE *input_file )
    {
    if ( yyin != stdin )
	fclose( yyin );

    yyin = input_file;
    yy_init = 1;
    }
# line 85 "p1.l"

#ifndef yywrap
 int yywrap(){return 1;}
#endif


⌨️ 快捷键说明

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