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

📄 yacc.c

📁 用C++编写的一个编译器
💻 C
📖 第 1 页 / 共 5 页
字号:

/*  A Bison parser, made from yacc.y with Bison version GNU Bison version 1.24
  */

#define YYBISON 1  /* Identify Bison output.  */

#define	IDENTIFIER	258
#define	USERTYPE	259
#define	CINT	260
#define	CUINT	261
#define	CFLOAT	262
#define	SCHAR	263
#define	STRING	264
#define	CBOOL	265
#define	SHORT	266
#define	LONG	267
#define	SIGNED	268
#define	UNSIGNED	269
#define	BOOL	270
#define	VOID	271
#define	CHAR	272
#define	INT	273
#define	FLOAT	274
#define	DOUBLE	275
#define	STRUCT	276
#define	UNION	277
#define	ENUM	278
#define	TYPEDEF	279
#define	STATIC	280
#define	EXTERN	281
#define	AUTO	282
#define	CONST	283
#define	ELLIPSIS	284
#define	VOLATILE	285
#define	REGISTER	286
#define	IF	287
#define	ELSE	288
#define	FOR	289
#define	WHILE	290
#define	DO	291
#define	SWITCH	292
#define	CASE	293
#define	DEFAULT	294
#define	GOTO	295
#define	RETURN	296
#define	BREAK	297
#define	CONTINUE	298
#define	ASM	299
#define	NTOMEM	300
#define	PTOMEM	301
#define	SIZEOF	302
#define	INCR	303
#define	DECR	304
#define	LSH	305
#define	RSH	306
#define	EQ	307
#define	UEQ	308
#define	GTR	309
#define	GEQ	310
#define	LES	311
#define	LEQ	312
#define	LAND	313
#define	LOR	314
#define	ASSIGN	315
#define	ADDAS	316
#define	SUBAS	317
#define	MULAS	318
#define	DIVAS	319
#define	MODAS	320
#define	LSHAS	321
#define	RSHAS	322
#define	XORAS	323
#define	ORAS	324
#define	ANDAS	325

#line 1 "yacc.y"

/***********************************************************
 Yacc script of DCC
 dusiqi 2007
***********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include "utility.h"
#include "syntax.h"
#include "symbol.h"
#include "genasm.h"

extern bool all_id_flag;
extern int blocklevel;
int yylex();
void yyerror(char *info);
#define alloca malloc

#line 41 "yacc.y"
typedef union{
	StmtNode 	*stmt;
	ExpNode 	*exp;
	Symbol 		*sym;
	Type 		*type;
	enum en_sc	sc;
	enum en_bt	bt;
	SuperType	*st;
	/* for constant */
	ConstValue 	val;
} YYSTYPE;

#ifndef YYLTYPE
typedef
  struct yyltype
    {
      int timestamp;
      int first_line;
      int first_column;
      int last_line;
      int last_column;
      char *text;
   }
  yyltype;

#define YYLTYPE yyltype
#endif

#include <stdio.h>

#ifndef __cplusplus
#ifndef __STDC__
#define const
#endif
#endif



#define	YYFINAL		303
#define	YYFLAG		-32768
#define	YYNTBASE	91

#define YYTRANSLATE(x) ((unsigned)(x) <= 325 ? yytranslate[x] : 151)

static const char yytranslate[] = {     0,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,    85,     2,     2,     2,    87,    81,     2,    76,
    77,    75,    82,    74,    83,     2,    86,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,    80,    71,     2,
     2,     2,    90,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    78,     2,    79,    88,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,    72,    89,    73,    84,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
     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,    31,    32,    33,    34,    35,
    36,    37,    38,    39,    40,    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,
    66,    67,    68,    69,    70
};

#if YYDEBUG != 0
static const short yyprhs[] = {     0,
     0,     2,     5,     7,     9,    10,    15,    17,    20,    24,
    26,    29,    31,    33,    35,    37,    39,    41,    43,    45,
    47,    49,    52,    54,    56,    58,    60,    62,    64,    66,
    68,    70,    72,    73,    80,    85,    88,    90,    92,    94,
    97,   101,   106,   112,   115,   117,   121,   123,   127,   129,
   132,   134,   137,   139,   143,   145,   149,   151,   155,   158,
   160,   162,   166,   171,   175,   180,   184,   186,   190,   192,
   196,   199,   202,   204,   208,   210,   214,   216,   218,   220,
   222,   224,   226,   228,   232,   237,   241,   244,   245,   250,
   252,   255,   258,   264,   272,   278,   284,   292,   301,   302,
   312,   316,   319,   322,   326,   328,   332,   333,   335,   337,
   339,   341,   343,   345,   347,   351,   353,   358,   362,   367,
   371,   375,   378,   381,   383,   386,   389,   392,   397,   402,
   407,   409,   411,   413,   415,   417,   419,   421,   425,   429,
   433,   435,   439,   443,   445,   449,   453,   455,   459,   463,
   467,   471,   473,   477,   481,   483,   487,   489,   493,   495,
   499,   501,   505,   507,   511,   513,   519,   521,   525,   527,
   529,   531,   533,   535,   537,   539,   541,   543,   545
};

static const short yyrhs[] = {    92,
     0,    91,    92,     0,    93,     0,    95,     0,     0,    97,
   115,    94,   124,     0,    96,     0,    97,    71,     0,    97,
   112,    71,     0,    99,     0,    98,    99,     0,    24,     0,
    26,     0,    25,     0,    27,     0,    31,     0,   100,     0,
   102,     0,   107,     0,     4,     0,   101,     0,   101,   100,
     0,    16,     0,    17,     0,    11,     0,    18,     0,    14,
     0,    12,     0,    13,     0,    19,     0,    20,     0,    15,
     0,     0,   104,     3,   103,    72,   105,    73,     0,   104,
    72,   105,    73,     0,   104,     3,     0,    21,     0,    22,
     0,   106,     0,   105,   106,     0,    97,   114,    71,     0,
    23,    72,   108,    73,     0,    23,     3,    72,   108,    73,
     0,    23,     3,     0,   109,     0,   108,    74,   109,     0,
     3,     0,     3,    60,   149,     0,    99,     0,    99,   111,
     0,    75,     0,    75,   111,     0,   113,     0,   112,    74,
   113,     0,   115,     0,   115,    60,   120,     0,   115,     0,
   114,    74,   115,     0,   111,   116,     0,   116,     0,     3,
     0,    76,   115,    77,     0,   116,    78,   149,    79,     0,
   116,    78,    79,     0,   116,    76,   117,    77,     0,   116,
    76,    77,     0,   118,     0,   118,    74,    29,     0,   119,
     0,   118,    74,   119,     0,    99,   115,     0,    99,   111,
     0,   149,     0,    72,   121,    73,     0,   120,     0,   121,
    74,   120,     0,   123,     0,   124,     0,   127,     0,   128,
     0,   129,     0,   131,     0,    96,     0,     3,    80,   122,
     0,    38,   149,    80,   122,     0,    39,    80,   122,     0,
    72,    73,     0,     0,    72,   125,   126,    73,     0,   122,
     0,   126,   122,     0,   133,    71,     0,    32,    76,   132,
    77,   122,     0,    32,    76,   132,    77,   122,    33,   122,
     0,    37,    76,   132,    77,   122,     0,    35,    76,   132,
    77,   122,     0,    36,   122,    35,    76,   132,    77,    71,
     0,    34,    76,   127,   133,    71,   133,    77,   122,     0,
     0,    34,    76,    96,   130,   133,    71,   133,    77,   122,
     0,    40,     3,    71,     0,    43,    71,     0,    42,    71,
     0,    41,   133,    71,     0,   149,     0,   132,    74,   149,
     0,     0,   132,     0,     3,     0,     5,     0,     6,     0,
     9,     0,     7,     0,    10,     0,    76,   132,    77,     0,
   134,     0,   135,    78,   132,    79,     0,   135,    76,    77,
     0,   135,    76,   132,    77,     0,   135,    45,     3,     0,
   135,    46,     3,     0,   135,    48,     0,   135,    49,     0,
   135,     0,    48,   136,     0,    49,   136,     0,   137,   136,
     0,    76,   110,    77,   136,     0,    47,    76,   136,    77,
     0,    47,    76,   110,    77,     0,    81,     0,    75,     0,
    82,     0,    83,     0,    84,     0,    85,     0,   136,     0,
   138,    75,   136,     0,   138,    86,   136,     0,   138,    87,
   136,     0,   138,     0,   139,    82,   138,     0,   139,    83,
   138,     0,   139,     0,   140,    50,   139,     0,   140,    51,
   139,     0,   140,     0,   141,    56,   140,     0,   141,    54,
   140,     0,   141,    57,   140,     0,   141,    55,   140,     0,
   141,     0,   142,    52,   141,     0,   142,    53,   141,     0,
   142,     0,   143,    81,   142,     0,   143,     0,   144,    88,
   143,     0,   144,     0,   145,    89,   144,     0,   145,     0,
   146,    58,   145,     0,   146,     0,   147,    59,   146,     0,
   147,     0,   147,    90,   132,    80,   148,     0,   148,     0,
   136,   150,   149,     0,    60,     0,    63,     0,    64,     0,
    65,     0,    61,     0,    62,     0,    66,     0,    67,     0,
    70,     0,    68,     0,    69,     0
};

#endif

#if YYDEBUG != 0
static const short yyrline[] = { 0,
    80,    81,    85,    86,    90,    96,   103,   110,   114,   121,
   125,   132,   134,   136,   138,   140,   145,   147,   149,   151,
   156,   158,   163,   165,   167,   169,   171,   173,   175,   177,
   179,   181,   186,   192,   197,   202,   210,   212,   217,   219,
   228,   235,   237,   239,   244,   250,   259,   263,   270,   272,
   277,   281,   289,   291,   299,   301,   309,   311,   319,   324,
   329,   333,   335,   341,   347,   354,   365,   369,   379,   383,
   391,   397,   404,   408,   415,   419,   427,   429,   431,   433,
   435,   437,   439,   446,   453,   460,   470,   474,   479,   488,
   490,   498,   505,   509,   513,   520,   524,   528,   534,   543,
   556,   561,   565,   569,   576,   580,   588,   590,   595,   599,
   603,   607,   611,   615,   619,   624,   626,   630,   634,   638,
   642,   646,   650,   657,   661,   665,   669,   673,   677,   681,
   688,   690,   692,   694,   696,   698,   703,   705,   709,   713,
   720,   722,   726,   733,   735,   739,   746,   748,   752,   756,
   760,   767,   769,   773,   780,   782,   789,   791,   798,   800,
   807,   809,   816,   818,   825,   827,   834,   836,   843,   845,
   847,   849,   851,   853,   855,   857,   859,   861,   863
};

static const char * const yytname[] = {   "$","error","$undefined.","IDENTIFIER",
"USERTYPE","CINT","CUINT","CFLOAT","SCHAR","STRING","CBOOL","SHORT","LONG","SIGNED",
"UNSIGNED","BOOL","VOID","CHAR","INT","FLOAT","DOUBLE","STRUCT","UNION","ENUM",
"TYPEDEF","STATIC","EXTERN","AUTO","CONST","ELLIPSIS","VOLATILE","REGISTER",
"IF","ELSE","FOR","WHILE","DO","SWITCH","CASE","DEFAULT","GOTO","RETURN","BREAK",
"CONTINUE","ASM","NTOMEM","PTOMEM","SIZEOF","INCR","DECR","LSH","RSH","EQ","UEQ",
"GTR","GEQ","LES","LEQ","LAND","LOR","ASSIGN","ADDAS","SUBAS","MULAS","DIVAS",
"MODAS","LSHAS","RSHAS","XORAS","ORAS","ANDAS","';'","'{'","'}'","','","'*'",
"'('","')'","'['","']'","':'","'&'","'+'","'-'","'~'","'!'","'/'","'%'","'^'",
"'|'","'?'","C_code","translation_unit","function_definition","@1","global_declaration",
"declaration","declaration_specifiers","storage_specifier","type_specifier",
"basic_type","basic_type_word","struct_specifier","@2","struct","struct_declaration_list",
"struct_declaration","enum_specifier","enumerator_list","enumerator","abstract_type_specifier",
"pointer","init_declarator_list","init_declarator","declarator_list","declarator",
"direct_declarator","parameter_type_list","parameter_list","parameter_declaration",
"initializer","initializer_list","statement","labeled_statement","compound_statement",
"@3","statement_list","expression_statement","selection_statement","iteration_statement",
"@4","jump_statement","expression","null_expression","primary_expression","postfix_expression",
"unary_expression","unary_operator","multiplicative_expression","additive_expression",
"shift_expression","relational_expression","equality_expression","and_expression",
"exclusive_or_expression","inclusive_or_expression","logical_and_expression",
"logical_or_expression","conditional_expression","assignment_expression","assignment_operator",
""
};
#endif

static const short yyr1[] = {     0,
    91,    91,    92,    92,    94,    93,    95,    96,    96,    97,
    97,    98,    98,    98,    98,    98,    99,    99,    99,    99,
   100,   100,   101,   101,   101,   101,   101,   101,   101,   101,
   101,   101,   103,   102,   102,   102,   104,   104,   105,   105,
   106,   107,   107,   107,   108,   108,   109,   109,   110,   110,
   111,   111,   112,   112,   113,   113,   114,   114,   115,   115,
   116,   116,   116,   116,   116,   116,   117,   117,   118,   118,
   119,   119,   120,   120,   121,   121,   122,   122,   122,   122,
   122,   122,   122,   123,   123,   123,   124,   125,   124,   126,
   126,   127,   128,   128,   128,   129,   129,   129,   130,   129,
   131,   131,   131,   131,   132,   132,   133,   133,   134,   134,
   134,   134,   134,   134,   134,   135,   135,   135,   135,   135,
   135,   135,   135,   136,   136,   136,   136,   136,   136,   136,
   137,   137,   137,   137,   137,   137,   138,   138,   138,   138,
   139,   139,   139,   140,   140,   140,   141,   141,   141,   141,
   141,   142,   142,   142,   143,   143,   144,   144,   145,   145,
   146,   146,   147,   147,   148,   148,   149,   149,   150,   150,
   150,   150,   150,   150,   150,   150,   150,   150,   150
};

static const short yyr2[] = {     0,
     1,     2,     1,     1,     0,     4,     1,     2,     3,     1,
     2,     1,     1,     1,     1,     1,     1,     1,     1,     1,
     1,     2,     1,     1,     1,     1,     1,     1,     1,     1,
     1,     1,     0,     6,     4,     2,     1,     1,     1,     2,
     3,     4,     5,     2,     1,     3,     1,     3,     1,     2,
     1,     2,     1,     3,     1,     3,     1,     3,     2,     1,
     1,     3,     4,     3,     4,     3,     1,     3,     1,     3,
     2,     2,     1,     3,     1,     3,     1,     1,     1,     1,
     1,     1,     1,     3,     4,     3,     2,     0,     4,     1,
     2,     2,     5,     7,     5,     5,     7,     8,     0,     9,
     3,     2,     2,     3,     1,     3,     0,     1,     1,     1,
     1,     1,     1,     1,     3,     1,     4,     3,     4,     3,
     3,     2,     2,     1,     2,     2,     2,     4,     4,     4,
     1,     1,     1,     1,     1,     1,     1,     3,     3,     3,
     1,     3,     3,     1,     3,     3,     1,     3,     3,     3,
     3,     1,     3,     3,     1,     3,     1,     3,     1,     3,
     1,     3,     1,     3,     1,     5,     1,     3,     1,     1,
     1,     1,     1,     1,     1,     1,     1,     1,     1
};

static const short yydefact[] = {     0,
    20,    25,    28,    29,    27,    32,    23,    24,    26,    30,
    31,    37,    38,     0,    12,    14,    13,    15,    16,     0,
     1,     3,     4,     7,     0,     0,    10,    17,    21,    18,
     0,    19,    44,     0,     2,    61,     8,    51,     0,     0,
     0,    53,    55,    60,    11,    22,    36,     0,     0,    47,
     0,    45,    52,     0,    59,     9,     0,     0,     0,     0,
     0,     0,     0,     0,    39,     0,     0,    42,     0,    62,
    54,    55,   109,   110,   111,   113,   112,   114,     0,     0,
     0,     0,   132,     0,   131,   133,   134,   135,   136,    56,
   116,   124,   137,     0,   141,   144,   147,   152,   155,   157,
   159,   161,   163,   165,   167,    73,    88,     6,    66,     0,
     0,    67,    69,    64,     0,     0,     0,    57,    35,    40,
    43,    48,    46,     0,   125,   126,    75,     0,    49,     0,
     0,   105,     0,     0,   122,   123,     0,     0,   169,   173,
   174,   170,   171,   172,   175,   176,   178,   179,   177,     0,
   127,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
    87,   107,    72,    71,    65,     0,    63,     0,    41,     0,
     0,     0,    74,     0,    50,     0,     0,   115,   120,   121,
   118,     0,     0,   168,   138,   139,   140,   137,   142,   143,
   145,   146,   149,   151,   148,   150,   153,   154,   156,   158,
   160,   162,   164,     0,   109,     0,     0,     0,   107,     0,
     0,     0,     0,   107,     0,     0,    83,     0,    90,    77,
    78,   107,    79,    80,    81,    82,   108,     0,    68,    70,
    34,    58,   130,   129,    76,   128,   106,   119,   117,     0,
   107,     0,   107,     0,     0,     0,     0,   107,     0,     0,
   103,   102,    89,    91,    92,   166,    84,     0,    99,   107,
     0,     0,     0,   107,    86,   101,   104,   107,   107,     0,
   107,     0,   107,    85,    93,     0,   107,    96,     0,    95,
   107,   107,     0,     0,    94,     0,   107,    97,   107,    98,
   100,     0,     0
};

static const short yydefgoto[] = {    20,
    21,    22,    59,    23,   227,   228,    26,    27,    28,    29,
    30,    62,    31,    64,    65,    32,    51,    52,   130,    40,
    41,    42,   117,    72,    44,   111,   112,   113,    90,   128,
   229,   230,   231,   172,   232,   233,   234,   235,   279,   236,
   237,   238,    91,    92,    93,    94,    95,    96,    97,    98,
    99,   100,   101,   102,   103,   104,   105,   132,   150
};

static const short yypact[] = {   686,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,-32768,-32768,    39,-32768,-32768,-32768,-32768,-32768,   662,
-32768,-32768,-32768,-32768,     8,   537,-32768,-32768,   707,-32768,
    40,-32768,   -68,     9,-32768,-32768,-32768,   -52,     5,     6,
   -22,-32768,   -24,   -45,-32768,-32768,   -58,   686,     9,   -13,
    12,-32768,-32768,   -39,   -45,-32768,     5,    67,   -32,   314,
   387,   -21,     5,   599,-32768,    72,   498,-32768,     9,-32768,
-32768,    -7,-32768,-32768,-32768,-32768,-32768,-32768,   -19,   498,
   498,    67,-32768,   404,-32768,-32768,-32768,-32768,-32768,-32768,
-32768,   -20,   181,   498,   -41,    76,   111,     7,   112,   -14,
   -23,   -18,    11,   -53,-32768,-32768,    37,-32768,-32768,     5,
    44,    43,-32768,-32768,    50,   686,     4,-32768,-32768,-32768,
-32768,-32768,-32768,   404,-32768,-32768,-32768,    94,   -52,    56,
    53,-32768,   137,   144,-32768,-32768,   451,   498,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,   498,
-32768,   498,   498,   498,   498,   498,   498,   498,   498,   498,
   498,   498,   498,   498,   498,   498,   498,   498,   498,   498,
-32768,   274,     6,-32768,-32768,   502,-32768,   623,-32768,     5,
    78,    86,-32768,    67,-32768,   498,   498,-32768,-32768,-32768,
-32768,    54,   -47,-32768,-32768,-32768,-32768,-32768,   -41,   -41,
    76,    76,   111,   111,   111,   111,     7,     7,   112,   -14,
   -23,   -18,    11,   -61,    90,    96,    98,   101,   274,   103,

⌨️ 快捷键说明

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