calc_yacc.c

来自「利用flex和bison做的简易C语言编译器核心 支持C语言的大部分运算操作」· C语言 代码 · 共 2,282 行 · 第 1/5 页

C
2,282
字号
       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,    33,    34,    37,    38,    39,      40,    48};#if YYDEBUG/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in   YYRHS.  */static const yytype_uint8 yyprhs[] ={       0,     0,     3,     5,     6,     9,    11,    13,    15,    17,      19,    21,    25,    31,    39,    43,    47,    55,    61,    64,      66,    68,    70,    72,    74,    78,    82,    86,    90,    94,      98,   102,   106,   110,   114,   118,   122,   126,   130,   134,     138,   142,   146,   150,   153,   156,   159,   163,   168,   172,     174};/* YYRHS -- A `-1'-separated list of the rules' RHS.  */static const yytype_int8 yyrhs[] ={      57,     0,    -1,    58,    -1,    -1,    58,    59,    -1,    49,      -1,    64,    -1,    60,    -1,    61,    -1,    62,    -1,    63,      -1,    50,    58,    51,    -1,     9,    52,    65,    53,    59,      -1,     9,    52,    65,    53,    59,    11,    59,    -1,    12,       3,    49,    -1,     3,    54,    59,    -1,    14,    59,    15,      52,    65,    53,    49,    -1,    15,    52,    65,    53,    59,      -1,    65,    49,    -1,     7,    -1,     6,    -1,     5,    -1,       4,    -1,     3,    -1,     3,     8,    65,    -1,    65,    28,      65,    -1,    65,    29,    65,    -1,    65,    30,    65,    -1,      65,    31,    65,    -1,    65,    32,    65,    -1,    65,    34,      65,    -1,    65,    33,    65,    -1,    65,    37,    65,    -1,      65,    38,    65,    -1,    65,    36,    65,    -1,    65,    35,      65,    -1,    65,    40,    65,    -1,    65,    39,    65,    -1,      65,    41,    65,    -1,    65,    42,    65,    -1,    65,    43,      65,    -1,    65,    44,    65,    -1,    65,    45,    65,    -1,      46,    65,    -1,    47,    65,    -1,    42,    65,    -1,     3,      52,    53,    -1,     3,    52,    66,    53,    -1,    52,    65,      53,    -1,    65,    -1,    66,    55,    65,    -1};/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */static const yytype_uint8 yyrline[] ={       0,    96,    96,   100,   101,   105,   106,   107,   108,   109,     110,   111,   115,   116,   120,   124,   128,   129,   133,   137,     138,   139,   140,   141,   142,   143,   144,   145,   146,   147,     148,   149,   150,   151,   152,   153,   154,   155,   156,   157,     158,   159,   160,   161,   162,   163,   164,   165,   166,   170,     171};#endif#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */static const char *const yytname[] ={  "$end", "error", "$undefined", "IDENTIFIER", "CONSTANT_S", "CONSTANT_C",  "CONSTANT_I", "CONSTANT_R", "ASS", "IF", "IFX", "ELSE", "GOTO", "LABE",  "DO", "WH", "CALL", "ASSIGN", "ASSADD", "ASSSUB", "ASSMUL", "ASSDIV",  "ASSBAL", "ASSAND", "ASSXOR", "ASSOOR", "ASSSHL", "ASSSHR", "OOR", "AND",  "'|'", "'^'", "'&'", "CNE", "CEQ", "'>'", "'<'", "CLE", "CGE", "SHR",  "SHL", "'+'", "'-'", "'*'", "'/'", "'%'", "'!'", "'~'", "UMI", "';'",  "'{'", "'}'", "'('", "')'", "':'", "','", "$accept", "procedure",  "stmt_list", "stmt_item", "ifxx_stmt", "goto_stmt", "labe_stmt",  "loop_stmt", "expr_stmt", "expr_item", "expr_list", 0};#endif# ifdef YYPRINT/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to   token YYLEX-NUM.  */static const yytype_uint16 yytoknum[] ={       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,     275,   276,   277,   278,   279,   280,   281,   282,   283,   284,     124,    94,    38,   285,   286,    62,    60,   287,   288,   289,     290,    43,    45,    42,    47,    37,    33,   126,   291,    59,     123,   125,    40,    41,    58,    44};# endif/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */static const yytype_uint8 yyr1[] ={       0,    56,    57,    58,    58,    59,    59,    59,    59,    59,      59,    59,    60,    60,    61,    62,    63,    63,    64,    65,      65,    65,    65,    65,    65,    65,    65,    65,    65,    65,      65,    65,    65,    65,    65,    65,    65,    65,    65,    65,      65,    65,    65,    65,    65,    65,    65,    65,    65,    66,      66};/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */static const yytype_uint8 yyr2[] ={       0,     2,     1,     0,     2,     1,     1,     1,     1,     1,       1,     3,     5,     7,     3,     3,     7,     5,     2,     1,       1,     1,     1,     1,     3,     3,     3,     3,     3,     3,       3,     3,     3,     3,     3,     3,     3,     3,     3,     3,       3,     3,     3,     2,     2,     2,     3,     4,     3,     1,       3};/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero   means the default is an error.  */static const yytype_uint8 yydefact[] ={       3,     0,     2,     1,    23,    22,    21,    20,    19,     0,       0,     0,     0,     0,     0,     0,     5,     3,     0,     4,       7,     8,     9,    10,     6,     0,     0,     0,     0,     0,       0,     0,     0,    23,    45,    43,    44,     0,     0,     0,       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,       0,     0,     0,     0,     0,     0,     0,    18,    24,    46,      49,     0,    15,     0,    14,     0,     0,    11,    48,    25,      26,    27,    28,    29,    31,    30,    35,    34,    32,    33,      37,    36,    38,    39,    40,    41,    42,    47,     0,     0,       0,     0,    50,    12,     0,    17,     0,     0,    13,    16};/* YYDEFGOTO[NTERM-NUM].  */static const yytype_int8 yydefgoto[] ={      -1,     1,     2,    19,    20,    21,    22,    23,    24,    25,      61};/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing   STATE-NUM.  */#define YYPACT_NINF -41static const yytype_int16 yypact[] ={     -41,    10,    83,   -41,    16,   -41,   -41,   -41,   -41,   -34,      26,    83,   -22,   110,   110,   110,   -41,   -41,   110,   -41,     -41,   -41,   -41,   -41,   -41,   239,   110,     9,    83,   110,     -18,    35,   110,     1,   -41,   -41,   -41,    60,   135,   110,     110,   110,   110,   110,   110,   110,   110,   110,   110,   110,     110,   110,   110,   110,   110,   110,   110,   -41,   261,   -41,     261,   -32,   -41,   161,   -41,     0,   187,   -41,   -41,   278,     106,   293,   307,   320,   331,   331,    79,    79,    79,    79,     -40,   -40,   -17,   -17,   -41,   -41,   -41,   -41,   110,    83,     110,    83,   261,    43,   213,   -41,    83,     8,   -41,   -41};/* YYPGOTO[NTERM-NUM].  */static const yytype_int8 yypgoto[] ={     -41,   -41,    41,   -11,   -41,   -41,   -41,   -41,   -41,    -7,     -41};/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If   positive, shift that token.  If negative, reduce the rule which   number is the opposite.  If zero, do what YYDEFACT says.   If YYTABLE_NINF, syntax error.  */#define YYTABLE_NINF -1static const yytype_uint8 yytable[] ={      31,    52,    53,    54,    55,    56,    34,    35,    36,    26,       3,    38,    33,     5,     6,     7,     8,    62,    29,    58,      60,    87,    63,    88,    26,    66,    54,    55,    56,    30,      32,    64,    69,    70,    71,    72,    73,    74,    75,    76,      77,    78,    79,    80,    81,    82,    83,    84,    85,    86,      65,    13,    90,    27,    96,    14,    15,    99,    37,     0,       0,    18,    59,     4,     5,     6,     7,     8,    27,     9,      28,     0,    10,     0,    11,    12,     0,     0,    93,     0,      95,    92,     0,    94,     0,    98,     4,     5,     6,     7,       8,     0,     9,     0,     0,    10,     0,    11,    12,     0,       0,     0,    13,     0,     0,     0,    14,    15,     0,    16,      17,    67,    18,    33,     5,     6,     7,     8,    50,    51,      52,    53,    54,    55,    56,    13,     0,     0,     0,    14,      15,     0,    16,    17,     0,    18,    41,    42,    43,    44,      45,    46,    47,    48,    49,    50,    51,    52,    53,    54,      55,    56,    13,     0,     0,     0,    14,    15,     0,     0,       0,     0,    18,    39,    40,    41,    42,    43,    44,    45,      46,    47,    48,    49,    50,    51,    52,    53,    54,    55,      56,     0,     0,     0,     0,     0,     0,     0,    68,    39,      40,    41,    42,    43,    44,    45,    46,    47,    48,    49,      50,    51,    52,    53,    54,    55,    56,     0,     0,     0,       0,     0,     0,     0,    89,    39,    40,    41,    42,    43,      44,    45,    46,    47,    48,    49,    50,    51,    52,    53,      54,    55,    56,     0,     0,     0,     0,     0,     0,     0,      91,    39,    40,    41,    42,    43,    44,    45,    46,    47,      48,    49,    50,    51,    52,    53,    54,    55,    56,     0,       0,     0,     0,     0,     0,     0,    97,    39,    40,    41,      42,    43,    44,    45,    46,    47,    48,    49,    50,    51,      52,    53,    54,    55,    56,     0,     0,     0,    57,    39,      40,    41,    42,    43,    44,    45,    46,    47,    48,    49,      50,    51,    52,    53,    54,    55,    56,    40,    41,    42,      43,    44,    45,    46,    47,    48,    49,    50,    51,    52,      53,    54,    55,    56,    42,    43,    44,    45,    46,    47,      48,    49,    50,    51,    52,    53,    54,    55,    56,    43,      44,    45,    46,    47,    48,    49,    50,    51,    52,    53,      54,    55,    56,    44,    45,    46,    47,    48,    49,    50,      51,    52,    53,    54,    55,    56,    46,    47,    48,    49,      50,    51,    52,    53,    54,    55,    56};static const yytype_int8 yycheck[] ={      11,    41,    42,    43,    44,    45,    13,    14,    15,     8,       0,    18,     3,     4,     5,     6,     7,    28,    52,    26,      27,    53,    29,    55,     8,    32,    43,    44,    45,     3,      52,    49,    39,    40,    41,    42,    43,    44,    45,    46,      47,    48,    49,    50,    51,    52,    53,    54,    55,    56,      15,    42,    52,    52,    11,    46,    47,    49,    17,    -1,      -1,    52,    53,     3,     4,     5,     6,     7,    52,     9,      54,    -1,    12,    -1,    14,    15,    -1,    -1,    89,    -1,      91,    88,    -1,    90,    -1,    96,     3,     4,     5,     6,       7,    -1,     9,    -1,    -1,    12,    -1,    14,    15,    -1,      -1,    -1,    42,    -1,    -1,    -1,    46,    47,    -1,    49,      50,    51,    52,     3,     4,     5,     6,     7,    39,    40,      41,    42,    43,    44,    45,    42,    -1,    -1,    -1,    46,      47,    -1,    49,    50,    -1,    52,    30,    31,    32,    33,      34,    35,    36,    37,    38,    39,    40,    41,    42,    43,      44,    45,    42,    -1,    -1,    -1,    46,    47,    -1,    -1,      -1,    -1,    52,    28,    29,    30,    31,    32,    33,    34,      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,      45,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    53,    28,      29,    30,    31,    32,    33,    34,    35,    36,    37,    38,      39,    40,    41,    42,    43,    44,    45,    -1,    -1,    -1,      -1,    -1,    -1,    -1,    53,    28,    29,    30,    31,    32,      33,    34,    35,    36,    37,    38,    39,    40,    41,    42,      43,    44,    45,    -1,    -1,    -1,    -1,    -1,    -1,    -1,      53,    28,    29,    30,    31,    32,    33,    34,    35,    36,      37,    38,    39,    40,    41,    42,    43,    44,    45,    -1,      -1,    -1,    -1,    -1,    -1,    -1,    53,    28,    29,    30,      31,    32,    33,    34,    35,    36,    37,    38,    39,    40,      41,    42,    43,    44,    45,    -1,    -1,    -1,    49,    28,      29,    30,    31,    32,    33,    34,    35,    36,    37,    38,      39,    40,    41,    42,    43,    44,    45,    29,    30,    31,      32,    33,    34,    35,    36,    37,    38,    39,    40,    41,      42,    43,    44,    45,    31,    32,    33,    34,    35,    36,      37,    38,    39,    40,    41,    42,    43,    44,    45,    32,      33,    34,    35,    36,    37,    38,    39,    40,    41,    42,      43,    44,    45,    33,    34,    35,    36,    37,    38,    39,      40,    41,    42,    43,    44,    45,    35,    36,    37,    38,      39,    40,    41,    42,    43,    44,    45};/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing   symbol of state STATE-NUM.  */static const yytype_uint8 yystos[] ={       0,    57,    58,     0,     3,     4,     5,     6,     7,     9,      12,    14,    15,    42,    46,    47,    49,    50,    52,    59,      60,    61,    62,    63,    64,    65,     8,    52,    54,    52,       3,    59,    52,     3,    65,    65,    65,    58,    65,    28,      29,    30,    31,    32,    33,    34,    35,    36,    37,    38,      39,    40,    41,    42,    43,    44,    45,    49,    65,    53,      65,    66,    59,    65,    49,    15,    65,    51,    53,    65,      65,    65,    65,    65,    65,    65,    65,    65,    65,    65,      65,    65,    65,    65,    65,    65,    65,    53,    55,    53,      52,    53,    65,    59,    65,    59,    11,    53,    59,    49};#define yyerrok		(yyerrstatus = 0)#define yyclearin	(yychar = YYEMPTY)#define YYEMPTY		(-2)#define YYEOF		0#define YYACCEPT	goto yyacceptlab#define YYABORT		goto yyabortlab#define YYERROR		goto yyerrorlab/* Like YYERROR except do call yyerror.  This remains here temporarily   to ease the transition to the new meaning of YYERROR, for GCC.   Once GCC version 2 has supplanted version 1, this can go.  */#define YYFAIL		goto yyerrlab#define YYRECOVERING()  (!!yyerrstatus)#define YYBACKUP(Token, Value)					\do								\  if (yychar == YYEMPTY && yylen == 1)				\    {								\      yychar = (Token);						\      yylval = (Value);						\      yytoken = YYTRANSLATE (yychar);				\      YYPOPSTACK (1);						\      goto yybackup;						\    }								\  else								\    {								\      yyerror (YY_("syntax error: cannot back up")); \      YYERROR;							\    }								\while (YYID (0))#define YYTERROR	1#define YYERRCODE	256/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].   If N is 0, then set CURRENT to the empty location which ends   the previous symbol: RHS[0] (always defined).  */#define YYRHSLOC(Rhs, K) ((Rhs)[K])#ifndef YYLLOC_DEFAULT# define YYLLOC_DEFAULT(Current, Rhs, N)				\    do									\      if (YYID (N))                                                    \	{								\	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\	}								\      else								\	{								\	  (Current).first_line   = (Current).last_line   =		\	    YYRHSLOC (Rhs, 0).last_line;				\	  (Current).first_column = (Current).last_column =		\	    YYRHSLOC (Rhs, 0).last_column;				\	}								\    while (YYID (0))#endif/* YY_LOCATION_PRINT -- Print the location on the stream.   This macro was not mandated originally: define only if we know   we won't break user code: when these are the locations we know.  */#ifndef YY_LOCATION_PRINT# if YYLTYPE_IS_TRIVIAL#  define YY_LOCATION_PRINT(File, Loc)			\     fprintf (File, "%d.%d-%d.%d",			\	      (Loc).first_line, (Loc).first_column,	\	      (Loc).last_line,  (Loc).last_column)# else#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)# endif#endif/* YYLEX -- calling `yylex' with the right arguments.  */#ifdef YYLEX_PARAM# define YYLEX yylex (YYLEX_PARAM)#else# define YYLEX yylex ()#endif/* Enable debugging if requested.  */#if YYDEBUG# ifndef YYFPRINTF#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */#  define YYFPRINTF fprintf# endif# define YYDPRINTF(Args)			\do {						\  if (yydebug)					\    YYFPRINTF Args;				\} while (YYID (0))# define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \do {									  \  if (yydebug)								  \    {									  \      YYFPRINTF (stderr, "%s ", Title);					  \      yy_symbol_print (stderr,						  \		  Type, Value); \      YYFPRINTF (stderr, "\n");						  \    }									  \} while (YYID (0))/*--------------------------------.| Print this symbol on YYOUTPUT.  |`--------------------------------*//*ARGSUSED*/#if (defined __STDC__ || defined __C99__FUNC__ \     || defined __cplusplus || defined _MSC_VER)static voidyy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)#elsestatic voidyy_symbol_value_print (yyoutput, yytype, yyvaluep)    FILE *yyoutput;    int yytype;    YYSTYPE const * const yyvaluep;#endif{  if (!yyvaluep)    return;# ifdef YYPRINT  if (yytype < YYNTOKENS)    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);# else  YYUSE (yyoutput);# endif  switch (yytype)    {      default:	break;    }}/*--------------------------------.| Print this symbol on YYOUTPUT.  |`--------------------------------*/#if (defined __STDC__ || defined __C99__FUNC__ \     || defined __cplusplus || defined _MSC_VER)static voidyy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)#elsestatic voidyy_symbol_print (yyoutput, yytype, yyvaluep)    FILE *yyoutput;    int yytype;    YYSTYPE const * const yyvaluep;#endif{  if (yytype < YYNTOKENS)    YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);  else    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);  yy_symbol_value_print (yyoutput, yytype, yyvaluep);  YYFPRINTF (yyoutput, ")");}/*------------------------------------------------------------------.| yy_stack_print -- Print the state stack from its BOTTOM up to its || TOP (included).                                                   |`------------------------------------------------------------------*/#if (defined __STDC__ || defined __C99__FUNC__ \     || defined __cplusplus || defined _MSC_VER)static voidyy_stack_print (yytype_int16 *bottom, yytype_int16 *top)#elsestatic voidyy_stack_print (bottom, top)

⌨️ 快捷键说明

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