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

📄 ytab.c

📁 一个小型的c语言编译器,做的非常好,不过不是我做的.
💻 C
📖 第 1 页 / 共 5 页
字号:
   159,   107,     0,   104,    45,     0,    51,    52,    59,     0,
     0,    57,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,    13,   107,     0,   107,    82,    62,    63,
    64,    65,    66,    67,   168,     0,     0,     0,     0,     0,
    91,    94,     0,     0,     0,     0,   107,     0,   124,   126,
   128,   130,   132,   134,   135,   137,   138,   139,   140,   142,
   143,   145,   146,   148,   149,   150,     0,     0,   165,   172,
   151,     0,   105,   171,    48,    50,     0,    55,     0,   109,
   110,   111,   112,   113,   114,   115,   116,   117,   118,   119,
   107,    80,    78,    83,    68,     0,    72,    74,   107,   107,
     0,   107,   107,     0,   101,   102,     0,     0,   163,   164,
     0,   160,   161,     0,    60,    56,    58,    76,   107,    70,
   107,     0,     0,   107,     0,     0,   100,   103,   121,   173,
   106,    69,   107,    73,    84,    87,     0,     0,    96,    71,
   107,   107,    92,   107,   107,    85,    88,   107,     0,     0,
    90,    93,     0,    97,    86,   107,    95,   107,    89,     0,
    98,   107,    99 };
typedef struct { char *t_name; int t_val; } yytoktype;
#ifndef YYDEBUG
#	define YYDEBUG	0	/* don't allow debugging */
#endif

#if YYDEBUG

yytoktype yytoks[] =
{
	"idTYPEDEF",	257,
	"kFOR",	258,
	"kWHILE",	259,
	"kIF",	260,
	"kELSE",	261,
	"kCASE",	262,
	"kSWITCH",	263,
	"kDEFAULT",	264,
	"kGOTO",	265,
	"kRETURN",	266,
	"kDO",	267,
	"kBREAK",	268,
	"kCONTINUE",	269,
	"kSIZEOF",	270,
	"kAUTO",	271,
	"kREGISTER",	272,
	"kSTATIC",	273,
	"kEXTERN",	274,
	"kTYPEDEF",	275,
	"kINT",	276,
	"kLONG",	277,
	"kSHORT",	278,
	"kCHAR",	279,
	"kVOID",	280,
	"kFLOAT",	281,
	"kDOUBLE",	282,
	"kSIGNED",	283,
	"kUNSIGNED",	284,
	"kCONST",	285,
	"kVOLATILE",	286,
	"cSTRING",	287,
	"cINT",	288,
	"cREAL",	289,
	"cCHAR",	290,
	"oPLUS",	291,
	"oMINUS",	292,
	"oMUL",	293,
	"oDIV",	294,
	"oMOD",	295,
	"oEQUAL",	296,
	"oASSIGN",	297,
	"oUNEQU",	298,
	"oLT",	299,
	"oLE",	300,
	"oGT",	301,
	"oGE",	302,
	"oCOMMA",	303,
	"oSEMI",	304,
	"oCOLON",	305,
	"oQUESTION",	306,
	"oQUOTE",	307,
	"oDOTDOTDOT",	308,
	"oARROW",	309,
	"oLP",	310,
	"oRP",	311,
	"oLB",	312,
	"oRB",	313,
	"oLC",	314,
	"oRC",	315,
	"oBITOR",	316,
	"oBITAND",	317,
	"oBITNOT",	318,
	"oBITXOR",	319,
	"oLFTSHT",	320,
	"oRITSHT",	321,
	"oOR",	322,
	"oAND",	323,
	"oNOT",	324,
	"oADDADD",	325,
	"oSUBSUB",	326,
	"oPLUSASSIGN",	327,
	"oMINUSASSIGN",	328,
	"oMULASSIGN",	329,
	"oDIVASSIGN",	330,
	"oMODASSIGN",	331,
	"oBITORASSIGN",	332,
	"oBITANDASSIGN",	333,
	"oBITNOTASSIGN",	334,
	"oBITXORASSIGN",	335,
	"oLFTSHTASSIGN",	336,
	"oRITSHTASSIGN",	337,
	"yNAME",	338,
	"pINCLUDE",	339,
	"pINCLDNAME",	340,
	"-unknown-",	-1	/* ends search */
};

char * yyreds[] =
{
	"-no such reduction-",
	"translation_unit : external_declaration",
	"translation_unit : translation_unit external_declaration",
	"external_declaration : function_definition",
	"external_declaration : declaration",
	"external_declaration : control_line",
	"function_definition : declaration_specifiers declarator",
	"function_definition : declaration_specifiers declarator compound_statement",
	"function_definition : declarator",
	"function_definition : declarator compound_statement",
	"declaration : declaration_specifiers init_declarator_list oSEMI",
	"declaration : declaration_specifiers oSEMI",
	"declaration_list : declaration",
	"declaration_list : declaration_list declaration",
	"declaration_specifiers : storage_class_specifier declaration_specifiers",
	"declaration_specifiers : storage_class_specifier",
	"declaration_specifiers : type_specifier declaration_specifiers",
	"declaration_specifiers : type_specifier",
	"declaration_specifiers : type_qualifier declaration_specifiers",
	"declaration_specifiers : type_qualifier",
	"storage_class_specifier : kAUTO",
	"storage_class_specifier : kREGISTER",
	"storage_class_specifier : kSTATIC",
	"storage_class_specifier : kTYPEDEF",
	"storage_class_specifier : kEXTERN",
	"type_specifier : kINT",
	"type_specifier : kLONG",
	"type_specifier : kSHORT",
	"type_specifier : kCHAR",
	"type_specifier : kVOID",
	"type_specifier : kFLOAT",
	"type_specifier : kDOUBLE",
	"type_specifier : kSIGNED",
	"type_specifier : kUNSIGNED",
	"type_specifier : idTYPEDEF",
	"type_qualifier : kCONST",
	"type_qualifier : kVOLATILE",
	"init_declarator_list : init_declarator",
	"init_declarator_list : init_declarator_list oCOMMA init_declarator",
	"init_declarator : declarator",
	"init_declarator : declarator oASSIGN initializer",
	"declarator : direct_declarator",
	"direct_declarator : identifier",
	"direct_declarator : direct_declarator oLB constant_expression oRB",
	"direct_declarator : direct_declarator oLB oRB",
	"direct_declarator : direct_declarator oLP parameter_type_list oRP",
	"direct_declarator : direct_declarator oLP oRP",
	"parameter_type_list : parameter_list",
	"parameter_type_list : parameter_list oCOMMA oDOTDOTDOT",
	"parameter_list : parameter_declaration",
	"parameter_list : parameter_list oCOMMA parameter_declaration",
	"parameter_declaration : declaration_specifiers declarator",
	"parameter_declaration : declaration_specifiers abstract_declarator",
	"parameter_declaration : declaration_specifiers",
	"initializer : assignment_expression",
	"initializer : oLC initializer_list oRC",
	"initializer : oLC initializer_list oCOMMA oRC",
	"initializer_list : initializer",
	"initializer_list : initializer_list oCOMMA initializer",
	"abstract_declarator : direct_abstract_declarator",
	"direct_abstract_declarator : oLB constant_expression oRB",
	"identifier : yNAME",
	"statement : labeled_statement",
	"statement : expression_statement",
	"statement : compound_statement",
	"statement : selection_statement",
	"statement : iteration_statement",
	"statement : jump_statement",
	"labeled_statement : identifier oCOLON",
	"labeled_statement : identifier oCOLON statement",
	"labeled_statement : kCASE constant_expression oCOLON",
	"labeled_statement : kCASE constant_expression oCOLON statement",
	"labeled_statement : kDEFAULT oCOLON",
	"labeled_statement : kDEFAULT oCOLON statement",
	"expression_statement : expression oSEMI",
	"compound_statement : oLC declaration_list",
	"compound_statement : oLC declaration_list statement_list oRC",
	"compound_statement : oLC",
	"compound_statement : oLC statement_list oRC",
	"compound_statement : oLC declaration_list",
	"compound_statement : oLC declaration_list oRC",
	"compound_statement : oLC oRC",
	"statement_list : statement",
	"statement_list : statement_list statement",
	"selection_statement : kIF oLP expression oRP",
	"selection_statement : kIF oLP expression oRP statement",
	"selection_statement : kIF oLP expression oRP statement else_clause",
	"selection_statement : kSWITCH oLP expression oRP",
	"selection_statement : kSWITCH oLP expression oRP statement",
	"else_clause : kELSE statement",
	"else_clause : /* empty */",
	"iteration_statement : kWHILE",
	"iteration_statement : kWHILE oLP expression oRP",
	"iteration_statement : kWHILE oLP expression oRP statement",
	"iteration_statement : kDO",
	"iteration_statement : kDO statement kWHILE oLP expression oRP oSEMI",
	"iteration_statement : kFOR oLP expression oSEMI",
	"iteration_statement : kFOR oLP expression oSEMI expression oSEMI",
	"iteration_statement : kFOR oLP expression oSEMI expression oSEMI expression oRP",
	"iteration_statement : kFOR oLP expression oSEMI expression oSEMI expression oRP statement",
	"jump_statement : kGOTO identifier oSEMI",
	"jump_statement : kCONTINUE oSEMI",
	"jump_statement : kBREAK oSEMI",
	"jump_statement : kRETURN expression oSEMI",
	"expression : assignment_expression",
	"expression : expression oCOMMA",
	"expression : expression oCOMMA assignment_expression",
	"expression : /* empty */",
	"assignment_expression : conditional_expression",
	"assignment_expression : unary_expression oASSIGN assignment_expression",
	"assignment_expression : unary_expression oPLUSASSIGN assignment_expression",
	"assignment_expression : unary_expression oMINUSASSIGN assignment_expression",
	"assignment_expression : unary_expression oMULASSIGN assignment_expression",
	"assignment_expression : unary_expression oDIVASSIGN assignment_expression",
	"assignment_expression : unary_expression oMODASSIGN assignment_expression",
	"assignment_expression : unary_expression oBITORASSIGN assignment_expression",
	"assignment_expression : unary_expression oBITANDASSIGN assignment_expression",
	"assignment_expression : unary_expression oBITXORASSIGN assignment_expression",
	"assignment_expression : unary_expression oLFTSHTASSIGN assignment_expression",
	"assignment_expression : unary_expression oRITSHTASSIGN assignment_expression",
	"conditional_expression : logical_OR_expression",
	"conditional_expression : logical_OR_expression oQUESTION expression oCOLON conditional_expression",
	"constant_expression : conditional_expression",
	"logical_OR_expression : logical_AND_expression",
	"logical_OR_expression : logical_OR_expression oOR logical_AND_expression",
	"logical_AND_expression : inclusive_OR_expression",
	"logical_AND_expression : logical_AND_expression oAND inclusive_OR_expression",
	"inclusive_OR_expression : exclusive_OR_expression",
	"inclusive_OR_expression : inclusive_OR_expression oBITOR exclusive_OR_expression",
	"exclusive_OR_expression : AND_expression",
	"exclusive_OR_expression : exclusive_OR_expression oBITXOR AND_expression",
	"AND_expression : equality_expression",
	"AND_expression : AND_expression oBITAND equality_expression",
	"equality_expression : relational_expression",
	"equality_expression : equality_expression oEQUAL relational_expression",
	"equality_expression : equality_expression oUNEQU relational_expression",
	"relational_expression : shift_expression",
	"relational_expression : relational_expression oLT shift_expression",
	"relational_expression : relational_expression oGT shift_expression",
	"relational_expression : relational_expression oLE shift_expression",
	"relational_expression : relational_expression oGE shift_expression",
	"shift_expression : additive_expression",
	"shift_expression : shift_expression oLFTSHT additive_expression",
	"shift_expression : shift_expression oRITSHT additive_expression",
	"additive_expression : multiplicative_expression",
	"additive_expression : additive_expression oPLUS multiplicative_expression",
	"additive_expression : additive_expression oMINUS multiplicative_expression",
	"multiplicative_expression : cast_expression",
	"multiplicative_expression : multiplicative_expression oMUL cast_expression",
	"multiplicative_expression : multiplicative_expression oDIV cast_expression",
	"multiplicative_expression : multiplicative_expression oMOD cast_expression",
	"cast_expression : unary_expression",
	"unary_expression : postfix_expression",
	"unary_expression : oADDADD unary_expression",
	"unary_expression : oSUBSUB unary_expression",
	"unary_expression : oPLUS cast_expression",
	"unary_expression : oMINUS cast_expression",
	"unary_expression : oBITNOT cast_expression",
	"unary_expression : oNOT cast_expression",
	"unary_expression : kSIZEOF unary_expression",
	"unary_expression : kSIZEOF oLP unary_expression oRP",
	"unary_expression : kSIZEOF oLP declaration_specifiers oRP",
	"postfix_expression : primary_expression",
	"postfix_expression : postfix_expression oLB expression oRB",
	"postfix_expression : postfix_expression oLP argument_expression_list oRP",
	"postfix_expression : postfix_expression oLP oRP",
	"postfix_expression : postfix_expression oADDADD",
	"postfix_expression : postfix_expression oSUBSUB",
	"primary_expression : identifier",
	"primary_expression : constant",
	"primary_expression : cSTRING",
	"primary_expression : oLP expression oRP",
	"argument_expression_list : assignment_expression",
	"argument_expression_list : argument_expression_list oCOMMA assignment_expression",
	"constant : cINT",
	"constant : cCHAR",
	"constant : cREAL",
	"control_line : pINCLUDE cSTRING",
	"control_line : pINCLUDE pINCLDNAME",
};
#endif /* YYDEBUG */
/*	@(#)yaccpar	1.9	*/

/*
** Skeleton parser driver for yacc output
*/

/*
** yacc user known macros and defines
*/
#define YYERROR		goto yyerrlab
#define YYACCEPT	return(0)
#define YYABORT		return(1)
#define YYBACKUP( newtoken, newvalue )\
{\
	if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
	{\
		yyerror( "syntax error - cannot backup" );\
		goto yyerrlab;\
	}\
	yychar = newtoken;\
	yystate = *yyps;\
	yylval = newvalue;\
	goto yynewstate;\
}
#define YYRECOVERING()	(!!yyerrflag)
#ifndef YYDEBUG
#	define YYDEBUG	1	/* make debugging available */
#endif

/*
** user known globals
*/
int yydebug;			/* set to 1 to get debugging */

/*
** driver internal defines
*/
#define YYFLAG		(-1000)

/*
** global variables used by the parser
*/
YYSTYPE yyv[ YYMAXDEPTH ];	/* value stack */
int yys[ YYMAXDEPTH ];		/* state stack */

YYSTYPE *yypv;			/* top of value stack */
int *yyps;			/* top of state stack */

int yystate;			/* current state */
int yytmp;			/* extra var (lasts between blocks) */

int yynerrs;			/* number of errors */
int yyerrflag;			/* error recovery flag */
int yychar;			/* current input token number */



/*
** yyparse - return 0 if worked, 1 if syntax error not recovered from
*/
int
yyparse()
{
	register YYSTYPE *yypvt;	/* top of value stack for $vars */

	/*
	** Initialize externals - yyparse may be called more than once
	*/
	yypv = &yyv[-1];
	yyps = &yys[-1];
	yystate = 0;
	yytmp = 0;
	yynerrs = 0;
	yyerrflag = 0;
	yychar = -1;

	goto yystack;
	{
		register YYSTYPE *yy_pv;	/* top of value stack */
		register int *yy_ps;		/* top of state stack */
		register int yy_state;		/* current state */
		register int  yy_n;		/* internal state number info */

		/*
		** get globals into registers.
		** branch to here only if YYBACKUP was called.
		*/
	yynewstate:
		yy_pv = yypv;
		yy_ps = yyps;
		yy_state = yystate;
		goto yy_newstate;

		/*
		** get globals into registers.
		** either we just started, or we just finished a reduction
		*/
	yystack:
		yy_pv = yypv;
		yy_ps = yyps;
		yy_state = yystate;

		/*
		** top of for (;;) loop while no reductions done
		*/
	yy_stack:
		/*
		** put a state and value onto the stacks
		*/
#if YYDEBUG
		/*
		** if debugging, look up token value in list of value vs.
		** name pairs.  0 and negative (-1) are special values.
		** Note: linear search is used since time is not a real
		** consideration while debugging.
		*/
		if ( yydebug )
		{

⌨️ 快捷键说明

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