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

📄 lexyy.c

📁 这个是我在编译原理做的课程设计,一个编译器,包括词法语法分析,结果生成四元式序列,可执行文件也在里面:)
💻 C
📖 第 1 页 / 共 2 页
字号:
#define FLEX_COMPRESSED
/* A lexical scanner generated by flex */

/* scanner skeleton version:
 * $Header: flex.skel,v 2.0 89/06/20 15:49:46 vern Locked $
 */

#include <stdio.h>

#define FLEX_SCANNER

/* amount of stuff to slurp up with each read */
#ifndef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif

#ifndef YY_BUF_SIZE
#define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of input buffer */
#endif

/* returned upon end-of-file */
#define YY_END_TOK 0

/* copy whatever the last rule matched to the standard output */

#define ECHO fputs( yytext, yyout )

/* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
 * is returned in "result".
 */
#define YY_INPUT(buf,result,max_size) \
	if ( (result = read( fileno(yyin), buf, max_size )) < 0 ) \
	    YY_FATAL_ERROR( "read() in flex scanner failed" );
#define YY_NULL 0
#define yyterminate() return ( YY_NULL )

/* report a fatal error */
#define YY_FATAL_ERROR(msg) \
	{ \
	fputs( msg, stderr ); \
	putc( '\n', stderr ); \
	exit( 1 ); \
	}

/* default yywrap function - always treat EOF as an EOF */
#define yywrap() 1

/* enter a start condition.  This macro really ought to take a parameter,
 * but we do it the disgusting crufty way forced on us by the ()-less
 * definition of BEGIN
 */
#define BEGIN yy_start = 1 + 2 *

/* action number for EOF rule of a given start state */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)

/* special action meaning "start processing a new file" */
#define YY_NEW_FILE goto new_file

/* default declaration of generated scanner - a define so the user can
 * easily add parameters
 */
#define YY_DECL int yylex( void )

/* code executed at the end of each rule */
#define YY_BREAK break;

#define YY_END_OF_BUFFER_CHAR 0

/* done after the current pattern has been matched and before the
 * corresponding action - sets up yytext
 */
#define YY_DO_BEFORE_ACTION \
	yytext = yy_bp; \
	yy_hold_char = *yy_cp; \
	*yy_cp = '\0'; \
	yy_c_buf_p = yy_cp;

/* returns the length of the matched text */
#define yyleng (yy_cp - yy_bp)

#define EOB_ACT_RESTART_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2

/* return all but the first 'n' matched characters back to the input stream */
#define yyless(n) \
	{ \
	*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \
	yy_c_buf_p = yy_cp = yy_bp + n; \
	YY_DO_BEFORE_ACTION; /* set up yytext again */ \
	}

#define unput(c) yyunput( c, yy_bp )

#define YY_USER_ACTION

FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
unsigned char  *yytext;

# line 1 "p1.l"
#define INITIAL 0
# line 2 "p1.l"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define    		Iden    	300
#define    		IntNo		301
#define	  	RealNo  	302
/*Define keywords here:*/
#define	  	Program 	400
#define	  	Begin		401
#define	  	End		402
#define	  	Var		403
#define	  	Integer 	404
#define	  	Real		405
#define	  	While		406
#define	  	Do		407
#define		If		408
#define		Then		409
#define		Else		410
#define		Or		411
#define		And		412
#define		Not		413
/*Define double_character terminates:   */
#define		LE		500
#define		GE		501
#define		NE		502
#define		ERRORCHAR	600

#define MAXSTR 20
char str1[20]; 
#define COMMENT 1
# line 37 "p1.l"
#define YY_END_OF_BUFFER 41
typedef int yy_state_type;
static const short int yy_accept[183] =
    {   0,
        0,    0,    0,    0,   41,   39,   38,   38,   13,   17,
        7,    8,   11,    9,   20,   10,   19,   12,    5,    5,
       21,   22,   15,   14,   16,   37,   37,   37,   37,   37,
       37,   37,   37,   37,   37,   37,   37,   37,    1,   18,
        4,    4,    3,    4,    4,    4,    4,    4,    4,    4,
        4,    4,    4,    4,    4,    4,    4,    4,    4,    4,
        4,    4,    4,    4,    4,    4,    4,    4,    4,    4,
        4,    4,    4,    1,    4,    2,   38,    6,    6,    0,
        6,    5,   37,   37,   37,   30,   37,   37,   31,   37,
       37,   34,   37,   37,   37,   37,   37,    4,    4,    4,

        4,    4,    4,    4,    4,    4,    4,    4,    4,    4,
        4,    4,    4,    4,    4,    4,    4,    4,    4,    0,
        6,    6,   35,   37,   37,   25,   37,   36,   37,   37,
       37,   26,   37,    4,    4,    4,    4,    4,    4,    4,
        4,    4,    4,    4,    4,    4,    4,    0,    6,   37,
       33,   37,   37,   28,   32,   37,    4,    4,    4,    4,
        4,    4,    4,    4,    4,   24,   37,   37,   29,    4,
        4,    4,    4,   37,   37,    4,    4,   27,   23,    4,
        4,    0
    } ;

static const unsigned char   yy_ec[256] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    2,    1,    1,    1,    1,    4,    5,    1,    6,
        7,    8,    9,   10,   11,   12,   13,   14,   15,   15,
       15,   15,   15,   15,   15,   15,   15,   16,   17,   18,
       19,   20,    1,    1,   21,   22,   23,   24,   25,   26,
       27,   28,   29,   23,   23,   30,   31,   32,   33,   34,
       23,   35,   36,   37,   23,   38,   39,   23,   23,   23,
        1,    1,    1,    1,    1,    1,   21,   22,   23,   24,

       25,   26,   27,   28,   29,   23,   23,   30,   31,   32,
       33,   34,   23,   35,   36,   37,   23,   38,   39,   23,
       23,   23,   40,   41,   42,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,

        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1
    } ;

static const char yy_meta[43] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    2,    2,    1,    1,    1,    1,    1,
        2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
        2,    2,    2,    2,    2,    2,    2,    2,    2,    1,
        1,    3
    } ;

static const short int yy_base[185] =
    {   0,
        0,    0,   42,    0,  353,  354,   83,   85,  354,  354,
      354,  354,  354,  354,  354,  354,   75,  354,   79,   83,
      354,  354,  354,  354,  354,  320,  326,    0,  317,   69,
       70,  316,  313,  312,  321,  317,  323,  315,  354,  354,
        0,  101,  103,    0,    0,    0,    0,    0,    0,    0,
        0,   93,    0,   97,  101,    0,    0,    0,    0,    0,
      116,  133,  310,  127,  131,  136,  134,  137,  138,  139,
       82,  153,  147,    0,    0,  354,  174,  166,  168,  172,
      183,  187,    0,  317,  313,    0,  303,  314,    0,  300,
      299,    0,  302,  313,  308,  297,  302,    0,  186,  189,

      191,  206,  210,  214,  298,   68,  200,  297,  164,  187,
      296,  201,  205,  295,  198,  202,  216,  175,  214,  236,
      354,  238,    0,  297,  300,    0,  299,    0,  296,  292,
      289,    0,  290,  245,    0,  243,  287,  233,  241,  286,
      242,  285,  217,  240,  284,  283,  245,  264,  266,  282,
        0,  286,  277,    0,    0,  286,  268,  270,  278,  277,
      244,  254,  276,  275,  262,    0,  281,  284,    0,  272,
      263,  269,  261,  256,  230,  265,  267,    0,    0,  223,
      158,  354,  176,  301
    } ;

static const short int yy_def[185] =
    {   0,
      182,    1,  182,    3,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  183,  183,  183,  183,  183,
      183,  183,  183,  183,  183,  183,  183,  183,  182,  182,
      184,  184,  184,  184,  184,  184,  184,  184,  184,  184,
      184,  184,  184,  184,  184,  184,  184,  184,  184,  184,
      182,   61,   61,   61,   61,   61,   61,   61,   61,   61,
       61,   61,   61,  184,  184,  182,  182,  182,  182,  182,
      182,  182,  183,  183,  183,  183,  183,  183,  183,  183,
      183,  183,  183,  183,  183,  183,  183,  184,  184,  184,

      184,  184,  184,  184,   61,   61,   61,   61,   61,   61,
       61,   61,   61,   61,   61,   61,   61,   61,   61,  182,
      182,  182,  183,  183,  183,  183,  183,  183,  183,  183,
      183,  183,  183,  184,  184,  184,   61,   61,   61,   61,
       61,   61,   61,   61,   61,   61,   61,  182,  182,  183,
      183,  183,  183,  183,  183,  183,  184,  184,   61,   61,
       61,   61,   61,   61,   61,  183,  183,  183,  183,   61,
       61,   61,   61,  183,  183,   61,   61,  183,  183,   61,
       61,    0,  182,  182
    } ;

static const short int yy_nxt[397] =
    {   0,
        6,    7,    8,    9,   10,   11,   12,   13,   14,   15,
       16,   17,   18,   19,   20,   21,   22,   23,   24,   25,
       26,   27,   28,   29,   30,   28,   28,   28,   31,   28,
       28,   32,   33,   34,   35,   28,   36,   37,   38,   39,
       40,    6,   41,   42,   43,   44,   45,   46,   47,   48,
       49,   50,   51,   52,   53,   54,   55,   56,   57,   58,
       59,   60,   61,   62,   63,   64,   65,   63,   63,   63,
       66,   63,   63,   67,   68,   69,   70,   63,   71,   72,
       73,   74,   75,   76,   77,   77,   77,   77,   78,   78,
       79,  137,   80,   80,   79,   89,   81,   82,   87,  105,

       88,   90,   99,   99,   99,   99,  100,  100,  101,  117,
      102,  102,  101,  105,  103,  104,   98,   98,   98,   98,
       98,   98,   98,   98,   98,   98,   98,   98,   98,  105,
      105,   98,   98,   98,   98,   98,  105,  105,  105,  105,
      105,  105,  105,  105,  105,  105,  105,  106,  105,  105,
      105,  105,  105,  105,  105,   98,   98,  107,  105,  108,
      109,  111,  110,  116,  105,  105,  113,  112,  105,  105,
      105,  114,  115,  118,  119,   77,   77,   83,  105,   78,
       78,  122,  122,   79,  105,   80,   80,   99,   99,  105,
      120,  121,  120,  121,   79,  105,   81,   81,   79,  139,

       81,   82,  100,  100,  136,  136,  105,  120,  121,  146,
      140,  120,  121,  134,  135,  134,  135,  101,  105,  102,
      102,  101,  144,  103,  103,  101,  138,  103,  104,  105,
      143,  105,  105,  105,  134,  135,  105,  141,  134,  135,
      145,  142,  147,  162,  148,  105,  148,  105,  105,  149,
      149,  122,  122,  157,  105,  157,  136,  136,  158,  158,
      179,  159,  120,  121,  105,  160,  161,  134,  135,  163,
      171,  105,  105,  105,  165,  105,  105,  149,  149,  149,
      149,  158,  158,  158,  158,  105,  173,  176,  172,  177,
      178,  121,  105,  105,  105,  135,  105,  181,  105,  180,

      105,   98,   98,  105,  175,  174,  105,  105,  105,  170,
      169,  168,  167,  166,  105,  164,  105,  105,  105,  156,
      155,  154,  153,  152,  151,  150,  105,  105,  105,  105,
      133,  132,  131,  130,  129,  128,  127,  126,  125,  124,
      123,  105,   97,   96,   95,   94,   93,   92,   91,   86,
       85,   84,  182,    5,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182

    } ;

static const short int yy_chk[397] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    3,    3,    3,    3,    3,    3,    3,    3,
        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
        3,    3,    3,    3,    7,    7,    8,    8,   17,   17,
       19,  106,   19,   19,   20,   31,   20,   20,   30,  106,

       30,   31,   42,   42,   43,   43,   52,   52,   54,   71,
       54,   54,   55,   71,   55,   55,   61,   61,   61,   61,
       61,   61,   61,   61,   61,   61,   61,   61,   61,   61,
       61,   61,   61,   61,   61,   61,   61,   61,   61,   61,
       61,   61,   61,   61,   61,   61,   61,   61,   61,   61,
       61,   61,   61,   61,   61,   61,   61,   62,   64,   64,
       65,   66,   65,   70,   62,   67,   67,   66,   68,   69,
       70,   68,   69,   72,   73,   77,   77,  183,   73,   78,
       78,   79,   79,   80,   72,   80,   80,   99,   99,  181,
       78,   78,   79,   79,   81,  109,   81,   81,   82,  109,

       82,   82,  100,  100,  101,  101,  118,   81,   81,  118,
      110,   82,   82,  100,  100,  101,  101,  102,  110,  102,
      102,  103,  116,  103,  103,  104,  107,  104,  104,  115,
      115,  107,  112,  116,  103,  103,  113,  112,  104,  104,
      117,  113,  119,  143,  120,  119,  120,  117,  143,  120,
      120,  122,  122,  134,  180,  134,  136,  136,  134,  134,
      175,  138,  122,  122,  138,  139,  141,  136,  136,  144,
      161,  144,  139,  141,  147,  161,  147,  148,  148,  149,
      149,  157,  157,  158,  158,  162,  165,  171,  162,  172,
      174,  149,  173,  165,  171,  158,  176,  177,  177,  176,

      172,  184,  184,  170,  168,  167,  164,  163,  160,  159,
      156,  153,  152,  150,  146,  145,  142,  140,  137,  133,
      131,  130,  129,  127,  125,  124,  114,  111,  108,  105,
       97,   96,   95,   94,   93,   91,   90,   88,   87,   85,
       84,   63,   38,   37,   36,   35,   34,   33,   32,   29,
       27,   26,    5,  182,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182,  182,  182,  182,  182,
      182,  182,  182,  182,  182,  182

    } ;

/* the intent behind this definition is that it'll catch
 * any uses of REJECT which flex missed
 */
#define REJECT reject_used_but_not_detected
#define yymore() yymore_used_but_not_detected

/* these variables are all declared out here so that section 3 code can
 * manipulate them
 */
static unsigned char  *yy_c_buf_p;	/* points to current character in buffer */
static int yy_init = 1;		/* whether we need to initialize */
static int yy_start = 0;	/* start state number */

/* true when we've seen an EOF for the current input file */
static int yy_eof_has_been_seen;

static int yy_n_chars;		/* number of characters read into yy_ch_buf */

/* yy_ch_buf has to be 2 characters longer than YY_BUF_SIZE because we need
 * to put in 2 end-of-buffer characters (this is explained where it is
 * done) at the end of yy_ch_buf
 */
static unsigned char  yy_ch_buf[YY_BUF_SIZE + 2];

/* yy_hold_char holds the character lost when yytext is formed */
static unsigned char  yy_hold_char;

static yy_state_type yy_last_accepting_state;
static unsigned char  *yy_last_accepting_cpos;

static yy_state_type yy_get_previous_state( void );
static int yy_get_next_buffer( void );
static void yyunput( int c, unsigned char  *buf_ptr );
static int input( void );
static void yyrestart( FILE *input_file );

YY_DECL
    {
    register yy_state_type yy_current_state;
	register unsigned char  *yy_cp, *yy_bp;
    register int yy_act;



    if ( yy_init )
	{
	if ( ! yy_start )
	    yy_start = 1;	/* first start state */

	if ( ! yyin )
	    yyin = stdin;

	if ( ! yyout )
	    yyout = stdout;

new_file:
	/* this is where we enter upon encountering an end-of-file and
	 * yywrap() indicating that we should continue processing
	 */

	/* we put in the '\n' and start reading from [1] so that an
	 * initial match-at-newline will be true.
	 */

	yy_ch_buf[0] = '\n';
	yy_n_chars = 1;

	/* 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.
	 */
	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;
	yy_init = 0;
	}

    while ( 1 )		/* loops until end-of-file is reached */
	{
	yy_cp = yy_c_buf_p;

	/* support of yytext */
	*yy_cp = yy_hold_char;

	/* yy_bp points to the position in yy_ch_buf of the start of the
	 * current run.
	 */
	yy_bp = yy_cp;

	yy_current_state = yy_start;
	do
	    {
	    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];
	    ++yy_cp;
	    }
	while ( yy_current_state != 182 );
	yy_cp = yy_last_accepting_cpos;
	yy_current_state = yy_last_accepting_state;

	/* bogus while loop to let YY_BACK_TRACK, EOB_ACT_LAST_MATCH,
	 * and EOF actions branch here without introducing an optimizer-
	 * daunting goto
	 */
	while ( 1 )

⌨️ 快捷键说明

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