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

📄 y.tab.c

📁 本源码为一个编译原理课程设计程序,它采用了YACC和LEX实现了一个功能强大的计算器编译器!
💻 C
📖 第 1 页 / 共 3 页
字号:
#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 {     CLEAR = 258,     EXIT = 259,     LIST = 260,     ERASE = 261,     DEC = 262,     HEX = 263,     OCT = 264,     HELP = 265,     NUM = 266,     REG = 267,     ADD = 268,     SUB = 269,     MUL = 270,     DIV = 271,     MOD = 272,     LSHIFT = 273,     RSHIFT = 274,     AND = 275,     OR = 276,     NOT = 277,     LESS = 278,     MORE = 279,     BITAND = 280,     BITOR = 281,     BITXOR = 282,     BITREV = 283,     SIN = 284,     COS = 285,     TAN = 286,     ABS = 287,     SQRT = 288,     LOG = 289,     RMINUS = 290   };#endif#define CLEAR 258#define EXIT 259#define LIST 260#define ERASE 261#define DEC 262#define HEX 263#define OCT 264#define HELP 265#define NUM 266#define REG 267#define ADD 268#define SUB 269#define MUL 270#define DIV 271#define MOD 272#define LSHIFT 273#define RSHIFT 274#define AND 275#define OR 276#define NOT 277#define LESS 278#define MORE 279#define BITAND 280#define BITOR 281#define BITXOR 282#define BITREV 283#define SIN 284#define COS 285#define TAN 286#define ABS 287#define SQRT 288#define LOG 289#define RMINUS 290/* Copy the first part of user declarations.  */#line 1 "calc.y"#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include "lex.yy.c"  //这是词法分析器生成的文件,必须包含!YYSTYPE reg[26]={0};BIGINT ival;enum Display{DEC_ON, HEX_ON, OCT_ON};enum Display dflag=DEC_ON;int i;/* 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)typedef int YYSTYPE;# 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 173 "y.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  2/* YYLAST -- Last index in YYTABLE.  */#define YYLAST   188/* YYNTOKENS -- Number of terminals. */#define YYNTOKENS  40/* YYNNTS -- Number of nonterminals. */#define YYNNTS  5/* YYNRULES -- Number of rules. */#define YYNRULES  42/* YYNRULES -- Number of states. */#define YYNSTATES  73/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */#define YYUNDEFTOK  2#define YYMAXUTOK   290#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,      36,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,      38,    39,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,    37,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,       2,     2,     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};#if YYDEBUG/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in   YYRHS.  */static const unsigned char yyprhs[] ={       0,     0,     3,     7,    10,    14,    18,    19,    21,    25,      29,    33,    37,    41,    45,    49,    53,    57,    61,    65,      69,    73,    77,    81,    85,    88,    91,    94,    96,    98,     101,   104,   107,   110,   113,   116,   118,   120,   122,   124,     126,   128,   130};/* YYRHS -- A `-1'-separated list of the rules' RHS. */static const yysigned_char yyrhs[] ={      41,     0,    -1,    41,    42,    36,    -1,    41,    36,    -1,      41,     1,    36,    -1,    41,    44,    36,    -1,    -1,    43,      -1,    12,    37,    43,    -1,    43,    13,    43,    -1,    43,      14,    43,    -1,    43,    15,    43,    -1,    43,    16,    43,      -1,    43,    17,    43,    -1,    43,    25,    43,    -1,    43,      26,    43,    -1,    43,    27,    43,    -1,    43,    18,    43,      -1,    43,    19,    43,    -1,    43,    20,    43,    -1,    43,      21,    43,    -1,    43,    23,    43,    -1,    43,    24,    43,      -1,    38,    43,    39,    -1,    14,    43,    -1,    28,    43,      -1,    22,    43,    -1,    11,    -1,    12,    -1,    29,    43,      -1,    30,    43,    -1,    31,    43,    -1,    34,    43,    -1,      32,    43,    -1,    33,    43,    -1,     4,    -1,     3,    -1,       8,    -1,     7,    -1,     9,    -1,     5,    -1,     6,    -1,      10,    -1};/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */static const unsigned char yyrline[] ={       0,    38,    38,    39,    40,    41,    42,    45,    50,    58,      59,    60,    61,    62,    63,    64,    65,    66,    67,    68,      69,    70,    71,    72,    73,    74,    75,    76,    77,    78,      79,    80,    81,    82,    83,    86,    87,    88,    89,    90,      91,   100,   101};#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", "CLEAR", "EXIT", "LIST", "ERASE", "DEC",   "HEX", "OCT", "HELP", "NUM", "REG", "ADD", "SUB", "MUL", "DIV", "MOD",   "LSHIFT", "RSHIFT", "AND", "OR", "NOT", "LESS", "MORE", "BITAND",   "BITOR", "BITXOR", "BITREV", "SIN", "COS", "TAN", "ABS", "SQRT", "LOG",   "RMINUS", "'\\n'", "'='", "'('", "')'", "$accept", "lines", "statement",   "expr", "cmdline", 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,   280,   281,   282,   283,   284,     285,   286,   287,   288,   289,   290,    10,    61,    40,    41};# endif/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */static const unsigned char yyr1[] ={       0,    40,    41,    41,    41,    41,    41,    42,    42,    43,      43,    43,    43,    43,    43,    43,    43,    43,    43,    43,      43,    43,    43,    43,    43,    43,    43,    43,    43,    43,      43,    43,    43,    43,    43,    44,    44,    44,    44,    44,      44,    44,    44};/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */static const unsigned char yyr2[] ={       0,     2,     3,     2,     3,     3,     0,     1,     3,     3,       3,     3,     3,     3,     3,     3,     3,     3,     3,     3,       3,     3,     3,     3,     2,     2,     2,     1,     1,     2,       2,     2,     2,     2,     2,     1,     1,     1,     1,     1,       1,     1,     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[] ={       6,     0,     1,     0,    36,    35,    40,    41,    38,    37,      39,    42,    27,    28,     0,     0,     0,     0,     0,     0,       0,     0,     0,     3,     0,     0,     7,     0,     4,     0,      28,    24,    26,    25,    29,    30,    31,    33,    34,    32,       0,     2,     0,     0,     0,     0,     0,     0,     0,     0,       0,     0,     0,     0,     0,     0,     5,     8,    23,     9,      10,    11,    12,    13,    17,    18,    19,    20,    21,    22,      14,    15,    16};/* YYDEFGOTO[NTERM-NUM]. */static const yysigned_char yydefgoto[] ={      -1,     1,    25,    26,    27};/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing   STATE-NUM.  */#define YYPACT_NINF -28static const short yypact[] ={     -28,    42,   -28,   -27,   -28,   -28,   -28,   -28,   -28,   -28,     -28,   -28,   -28,   -23,    55,    55,    55,    55,    55,    55,      55,    55,    55,   -28,    55,   -13,    98,   -12,   -28,    55,     -28,   -28,   -28,   -28,   -28,   -28,   -28,   -28,   -28,   -28,      81,   -28,    55,    55,    55,    55,    55,    55,    55,    55,      55,    55,    55,    55,    55,    55,   -28,    98,   -28,    -4,      -4,   -28,   -28,   -28,   171,   171,   128,   113,    44,    44,       3,   143,   158};/* YYPGOTO[NTERM-NUM].  */static const yysigned_char yypgoto[] ={     -28,   -28,   -28,   -14,   -28};/* 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 unsigned char yytable[] ={      31,    32,    33,    34,    35,    36,    37,    38,    39,    28,      40,    44,    45,    46,    29,    57,    42,    43,    44,    45,      46,    47,    48,    41,    56,     0,    51,    52,    59,    60,      61,    62,    63,    64,    65,    66,    67,    68,    69,    70,      71,    72,     2,     3,     0,     4,     5,     6,     7,     8,       9,    10,    11,    12,    13,     0,    14,    42,    43,    44,      45,    46,    47,    48,    15,     0,    12,    30,     0,    14,      16,    17,    18,    19,    20,    21,    22,    15,    23,     0,      24,     0,     0,    16,    17,    18,    19,    20,    21,    22,       0,     0,     0,    24,    42,    43,    44,    45,    46,    47,      48,    49,    50,     0,    51,    52,    53,    54,    55,     0,       0,    42,    43,    44,    45,    46,    47,    48,    49,    50,      58,    51,    52,    53,    54,    55,    42,    43,    44,    45,      46,    47,    48,    49,     0,     0,    51,    52,    53,    54,      55,    42,    43,    44,    45,    46,    47,    48,     0,     0,       0,    51,    52,    53,    54,    55,    42,    43,    44,    45,      46,    47,    48,     0,     0,     0,    51,    52,    53,     0,      55,    42,    43,    44,    45,    46,    47,    48,     0,     0,       0,    51,    52,    53,    42,    43,    44,    45,    46};static const yysigned_char yycheck[] ={      14,    15,    16,    17,    18,    19,    20,    21,    22,    36,      24,    15,    16,    17,    37,    29,    13,    14,    15,    16,      17,    18,    19,    36,    36,    -1,    23,    24,    42,    43,      44,    45,    46,    47,    48,    49,    50,    51,    52,    53,      54,    55,     0,     1,    -1,     3,     4,     5,     6,     7,       8,     9,    10,    11,    12,    -1,    14,    13,    14,    15,      16,    17,    18,    19,    22,    -1,    11,    12,    -1,    14,      28,    29,    30,    31,    32,    33,    34,    22,    36,    -1,      38,    -1,    -1,    28,    29,    30,    31,    32,    33,    34,      -1,    -1,    -1,    38,    13,    14,    15,    16,    17,    18,      19,    20,    21,    -1,    23,    24,    25,    26,    27,    -1,      -1,    13,    14,    15,    16,    17,    18,    19,    20,    21,      39,    23,    24,    25,    26,    27,    13,    14,    15,    16,      17,    18,    19,    20,    -1,    -1,    23,    24,    25,    26,      27,    13,    14,    15,    16,    17,    18,    19,    -1,    -1,      -1,    23,    24,    25,    26,    27,    13,    14,    15,    16,      17,    18,    19,    -1,    -1,    -1,    23,    24,    25,    -1,      27,    13,    14,    15,    16,    17,    18,    19,    -1,    -1,      -1,    23,    24,    25,    13,    14,    15,    16,    17};/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing   symbol of state STATE-NUM.  */static const unsigned char yystos[] ={       0,    41,     0,     1,     3,     4,     5,     6,     7,     8,       9,    10,    11,    12,    14,    22,    28,    29,    30,    31,      32,    33,    34,    36,    38,    42,    43,    44,    36,    37,      12,    43,    43,    43,    43,    43,    43,    43,    43,    43,      43,    36,    13,    14,    15,    16,    17,    18,    19,    20,      21,    23,    24,    25,    26,    27,    36,    43,    39,    43,      43,    43,    43,    43,    43,    43,    43,    43,    43,    43,      43,    43,    43};#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)# define YYSIZE_T __SIZE_TYPE__#endif#if ! defined (YYSIZE_T) && defined (size_t)# define YYSIZE_T size_t#endif#if ! defined (YYSIZE_T)# if defined (__STDC__) || defined (__cplusplus)#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */#  define YYSIZE_T size_t# endif#endif#if ! defined (YYSIZE_T)# define YYSIZE_T unsigned int#endif#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 yyerrlab1/* 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.  */

⌨️ 快捷键说明

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