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

📄 yacc.tab.cpp

📁 c语言的简化编译器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
#include "stdafx.h"
/* A Bison parser, made by GNU Bison 1.875.  */

/* Skeleton parser for Yacc-like parsing with Bison,
   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

/* As a special exception, when this file is copied by Bison into a
   Bison output file, you may use that output file without restriction.
   This special exception was added by the Free Software Foundation
   in version 1.24 of Bison.  */

/* Written by Richard Stallman by simplifying the original so called
   ``semantic'' parser.  */

/* All symbols defined below should begin with yy or YY, to avoid
   infringing on user name space.  This should be done even for local
   variables, as they might otherwise be expanded by user macros.
   There are some unavoidable exceptions within include files to
   define necessary library symbols; they are noted "INFRINGES ON
   USER NAME SPACE" below.  */

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

/* Skeleton name.  */
#define YYSKELETON_NAME "yacc.c"

/* Pure parsers.  */
#define YYPURE 0

/* Using locations.  */
#define YYLSP_NEEDED 0



/* Tokens.  */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
   /* Put the tokens into the symbol table, so that GDB and other debuggers
      know about them.  */
   enum yytokentype {
     tINT = 258,
     tVOID = 259,
     tBOOL = 260,
     tSTRING = 261,
     tAND = 262,
     tOR = 263,
     tEQUALS = 264,
     tGEQUALS = 265,
     tLEQUALS = 266,
     tNEQUALS = 267,
     tIF = 268,
     tELSE = 269,
     tWHILE = 270,
     tFOR = 271,
     tRETURN = 272,
     tBREAK = 273,
     tCONTINUE = 274,
     tERROR = 275,
     tIDENTIFIER = 276,
     tINTCONST = 277,
     tBOOLCONST = 278,
     tSTRINGCONST = 279
   };
#endif
#define tINT 258
#define tVOID 259
#define tBOOL 260
#define tSTRING 261
#define tAND 262
#define tOR 263
#define tEQUALS 264
#define tGEQUALS 265
#define tLEQUALS 266
#define tNEQUALS 267
#define tIF 268
#define tELSE 269
#define tWHILE 270
#define tFOR 271
#define tRETURN 272
#define tBREAK 273
#define tCONTINUE 274
#define tERROR 275
#define tIDENTIFIER 276
#define tINTCONST 277
#define tBOOLCONST 278
#define tSTRINGCONST 279




/* Copy the first part of user declarations.  */
#line 5 "yacc.y"

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "error.h"
#include "tree.h" 


int yylex();

extern SCRIPTCOLLECTION *thescriptcollection;


/* Enabling traces.  */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif

/* Enabling verbose error messages.  */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 0
#endif

#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 21 "yacc.y"
typedef union YYSTYPE {
  struct SCRIPTCOLLECTION *scriptcollection;    
  struct TOPLEVEL *toplevel;
  struct FUNCTION *function;  
  struct TYPE *type;
  struct EXP *exp;
  struct DECL *decl;
  struct FORINIT *forinit;
  struct STM *stm;
  struct LVALUE *lvalue;
  
  char *identifier;
  int intconst;
  int boolconst; 
  char *stringconst;
} YYSTYPE;
/* Line 191 of yacc.c.  */
#line 153 "yacc.tab.c"
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif



/* Copy the second part of user declarations.  */


/* Line 214 of yacc.c.  */
#line 165 "yacc.tab.c"

#if ! defined (yyoverflow) || YYERROR_VERBOSE

/* The parser invokes alloca or malloc; define the necessary symbols.  */

# if YYSTACK_USE_ALLOCA
#  define YYSTACK_ALLOC alloca
# else
#  ifndef YYSTACK_USE_ALLOCA
#   if defined (alloca) || defined (_ALLOCA_H)
#    define YYSTACK_ALLOC alloca
#   else
#    ifdef __GNUC__
#     define YYSTACK_ALLOC __builtin_alloca
#    endif
#   endif
#  endif
# endif

# ifdef YYSTACK_ALLOC
   /* Pacify GCC's `empty if-body' warning. */
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
# else
#  if defined (__STDC__) || defined (__cplusplus)
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
#   define YYSIZE_T size_t
#  endif
#  define YYSTACK_ALLOC malloc
#  define YYSTACK_FREE free
# endif
#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */


#if (! defined (yyoverflow) \
     && (! defined (__cplusplus) \
	 || (YYSTYPE_IS_TRIVIAL)))

/* A type that is properly aligned for any stack member.  */
union yyalloc
{
  short yyss;
  YYSTYPE yyvs;
  };

/* The size of the maximum gap between one aligned stack and the next.  */
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)

/* The size of an array large to enough to hold all stacks, each with
   N elements.  */
# define YYSTACK_BYTES(N) \
     ((N) * (sizeof (short) + sizeof (YYSTYPE))				\
      + YYSTACK_GAP_MAXIMUM)

/* Copy COUNT objects from FROM to TO.  The source and destination do
   not overlap.  */
# ifndef YYCOPY
#  if 1 < __GNUC__
#   define YYCOPY(To, From, Count) \
      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
#  else
#   define YYCOPY(To, From, Count)		\
      do					\
	{					\
	  register YYSIZE_T yyi;		\
	  for (yyi = 0; yyi < (Count); yyi++)	\
	    (To)[yyi] = (From)[yyi];		\
	}					\
      while (0)
#  endif
# endif

/* Relocate STACK from its old location to the new one.  The
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
   elements in the stack, and YYPTR gives the new location of the
   stack.  Advance YYPTR to a properly aligned location for the next
   stack.  */
# define YYSTACK_RELOCATE(Stack)					\
    do									\
      {									\
	YYSIZE_T yynewbytes;						\
	YYCOPY (&yyptr->Stack, Stack, yysize);				\
	Stack = &yyptr->Stack;						\
	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
	yyptr += yynewbytes / sizeof (*yyptr);				\
      }									\
    while (0)

#endif

#if defined (__STDC__) || defined (__cplusplus)
   typedef signed char yysigned_char;
#else
   typedef short yysigned_char;
#endif

/* YYFINAL -- State number of the termination state. */
#define YYFINAL  13
/* YYLAST -- Last index in YYTABLE.  */
#define YYLAST   395

/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS  40
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS  24
/* YYNRULES -- Number of rules. */
#define YYNRULES  71
/* YYNRULES -- Number of states. */
#define YYNSTATES  131

/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
#define YYUNDEFTOK  2
#define YYMAXUTOK   279

#define YYTRANSLATE(YYX) 						\
  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)

/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
static const unsigned 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,    39,     2,     2,     2,    33,     2,     2,
      35,    25,    31,    29,    36,    30,     2,    32,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,    34,
      27,    26,    28,     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,    37,     2,    38,     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,     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
};

#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
   YYRHS.  */
static const unsigned char yyprhs[] =
{
       0,     0,     3,     5,     6,     8,    10,    13,    15,    18,
      22,    23,    26,    28,    30,    32,    39,    46,    47,    49,
      51,    55,    58,    61,    65,    67,    70,    72,    75,    79,
      85,    93,    99,   109,   111,   113,   116,   117,   119,   121,
     125,   127,   129,   133,   137,   141,   145,   149,   153,   157,
     161,   165,   169,   173,   177,   181,   185,   187,   190,   193,
     198,   200,   202,   204,   206,   208,   212,   217,   218,   220,
     222,   226
};

/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yysigned_char yyrhs[] =
{
      41,     0,    -1,    42,    -1,    -1,    43,    -1,    44,    -1,
      44,    43,    -1,    48,    -1,    45,    34,    -1,    47,    21,
      46,    -1,    -1,    26,    58,    -1,     3,    -1,     5,    -1,
       6,    -1,    47,    21,    35,    49,    25,    52,    -1,     4,
      21,    35,    49,    25,    52,    -1,    -1,    50,    -1,    51,
      -1,    51,    36,    50,    -1,    47,    21,    -1,    37,    38,
      -1,    37,    53,    38,    -1,    54,    -1,    53,    54,    -1,
      34,    -1,    17,    34,    -1,    17,    58,    34,    -1,    13,
      35,    58,    25,    54,    -1,    13,    35,    58,    25,    54,
      14,    54,    -1,    15,    35,    58,    25,    54,    -1,    16,
      35,    55,    34,    58,    34,    61,    25,    54,    -1,    52,
      -1,    45,    -1,    58,    34,    -1,    -1,    56,    -1,    57,
      -1,    57,    36,    56,    -1,    45,    -1,    58,    -1,    63,
      26,    58,    -1,    58,     9,    58,    -1,    58,    12,    58,
      -1,    58,    27,    58,    -1,    58,    28,    58,    -1,    58,
      11,    58,    -1,    58,    10,    58,    -1,    58,    29,    58,
      -1,    58,    30,    58,    -1,    58,    31,    58,    -1,    58,
      32,    58,    -1,    58,    33,    58,    -1,    58,     7,    58,
      -1,    58,     8,    58,    -1,    59,    -1,    30,    59,    -1,
      39,    59,    -1,    35,    47,    25,    59,    -1,    60,    -1,
      22,    -1,    23,    -1,    24,    -1,    63,    -1,    35,    58,
      25,    -1,    21,    35,    61,    25,    -1,    -1,    62,    -1,
      58,    -1,    58,    36,    62,    -1,    21,    -1
};

/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
static const unsigned short yyrline[] =
{
       0,    73,    73,    78,    79,    83,    85,    89,    91,    95,
     100,   101,   105,   107,   109,   113,   115,   121,   122,   126,
     128,   132,   136,   138,   142,   144,   149,   151,   153,   155,
     157,   159,   161,   163,   165,   167,   172,   173,   177,   179,
     183,   185,   191,   193,   195,   197,   199,   201,   203,   205,
     207,   209,   211,   213,   215,   217,   219,   223,   225,   227,
     229,   233,   235,   237,   239,   241,   243,   248,   249,   253,
     255,   259
};
#endif

#if YYDEBUG || YYERROR_VERBOSE
/* YYTNME[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", "tINT", "tVOID", "tBOOL", "tSTRING", 
  "tAND", "tOR", "tEQUALS", "tGEQUALS", "tLEQUALS", "tNEQUALS", "tIF", 
  "tELSE", "tWHILE", "tFOR", "tRETURN", "tBREAK", "tCONTINUE", "tERROR", 
  "tIDENTIFIER", "tINTCONST", "tBOOLCONST", "tSTRINGCONST", "')'", "'='", 
  "'<'", "'>'", "'+'", "'-'", "'*'", "'/'", "'%'", "';'", "'('", "','", 
  "'{'", "'}'", "'!'", "$accept", "scriptcollection", "toplevels", 
  "netoplevels", "toplevel", "simpledecl", "initialization", "type", 
  "function", "formals", "neformals", "formal", "compoundstm", "nestms", 
  "stm", "forinits", "neforinits", "forinit", "exp", "unaryexp", 
  "unarypostfixexp", "exps", "neexps", "lvalue", 0
};
#endif

# ifdef YYPRINT
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
   token YYLEX-NUM.  */
static const unsigned short 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,    41,    61,    60,    62,    43,
      45,    42,    47,    37,    59,    40,    44,   123,   125,    33
};
# endif

/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
static const unsigned char yyr1[] =
{
       0,    40,    41,    42,    42,    43,    43,    44,    44,    45,
      46,    46,    47,    47,    47,    48,    48,    49,    49,    50,
      50,    51,    52,    52,    53,    53,    54,    54,    54,    54,
      54,    54,    54,    54,    54,    54,    55,    55,    56,    56,
      57,    57,    58,    58,    58,    58,    58,    58,    58,    58,
      58,    58,    58,    58,    58,    58,    58,    59,    59,    59,
      59,    60,    60,    60,    60,    60,    60,    61,    61,    62,
      62,    63
};

/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
static const unsigned char yyr2[] =
{
       0,     2,     1,     0,     1,     1,     2,     1,     2,     3,
       0,     2,     1,     1,     1,     6,     6,     0,     1,     1,
       3,     2,     2,     3,     1,     2,     1,     2,     3,     5,
       7,     5,     9,     1,     1,     2,     0,     1,     1,     3,
       1,     1,     3,     3,     3,     3,     3,     3,     3,     3,
       3,     3,     3,     3,     3,     3,     1,     2,     2,     4,
       1,     1,     1,     1,     1,     3,     4,     0,     1,     1,
       3,     1
};

/* 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 unsigned char yydefact[] =
{
       3,    12,     0,    13,    14,     0,     2,     4,     5,     0,
       0,     7,     0,     1,     6,     8,    10,    17,     0,    17,
       9,     0,     0,    18,    19,    71,    61,    62,    63,     0,
       0,     0,    11,    56,    60,    64,     0,    21,     0,     0,
      67,    57,    64,     0,     0,    58,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,    16,    20,    69,     0,    68,     0,    65,    54,
      55,    43,    48,    47,    44,    45,    46,    49,    50,    51,
      52,    53,    42,    15,     0,     0,     0,     0,    26,    22,
      34,     0,    33,     0,    24,     0,     0,    66,    59,     0,

⌨️ 快捷键说明

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