1/* A Bison parser, made by GNU Bison 2.5. */ 2 3/* Bison implementation for Yacc-like parsers in C 4 5 Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20/* As a special exception, you may create a larger work that contains 21 part or all of the Bison parser skeleton and distribute that work 22 under terms of your choice, so long as that work isn't itself a 23 parser generator using the skeleton or a modified version thereof 24 as a parser skeleton. Alternatively, if you modify or redistribute 25 the parser skeleton itself, you may (at your option) remove this 26 special exception, which will cause the skeleton and the resulting 27 Bison output files to be licensed under the GNU General Public 28 License without this special exception. 29 30 This special exception was added by the Free Software Foundation in 31 version 2.2 of Bison. */ 32 33/* C LALR(1) parser skeleton written by Richard Stallman, by 34 simplifying the original so-called "semantic" parser. */ 35 36/* All symbols defined below should begin with yy or YY, to avoid 37 infringing on user name space. This should be done even for local 38 variables, as they might otherwise be expanded by user macros. 39 There are some unavoidable exceptions within include files to 40 define necessary library symbols; they are noted "INFRINGES ON 41 USER NAME SPACE" below. */ 42 43/* Identify Bison output. */ 44#define YYBISON 1 45 46/* Bison version. */ 47#define YYBISON_VERSION "2.5" 48 49/* Skeleton name. */ 50#define YYSKELETON_NAME "yacc.c" 51 52/* Pure parsers. */ 53#define YYPURE 0 54 55/* Push parsers. */ 56#define YYPUSH 0 57 58/* Pull parsers. */ 59#define YYPULL 1 60 61/* Using locations. */ 62#define YYLSP_NEEDED 0 63 64 65 66/* Copy the first part of user declarations. */ 67 68/* Line 268 of yacc.c */ 69#line 1 "calc.y" 70 71/* A simple integer desk calculator using yacc and gmp. 72 73Copyright 2000, 2001, 2002 Free Software Foundation, Inc. 74 75This file is part of the GNU MP Library. 76 77This program is free software; you can redistribute it and/or modify it under 78the terms of the GNU General Public License as published by the Free Software 79Foundation; either version 3 of the License, or (at your option) any later 80version. 81 82This program is distributed in the hope that it will be useful, but WITHOUT ANY 83WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 84PARTICULAR PURPOSE. See the GNU General Public License for more details. 85 86You should have received a copy of the GNU General Public License along with 87this program. If not, see http://www.gnu.org/licenses/. */ 88 89 90/* This is a simple program, meant only to show one way to use GMP for this 91 sort of thing. There's few features, and error checking is minimal. 92 Standard input is read, calc_help() below shows the inputs accepted. 93 94 Expressions are evaluated as they're read. If user defined functions 95 were wanted it'd be necessary to build a parse tree like pexpr.c does, or 96 a list of operations for a stack based evaluator. That would also make 97 it possible to detect and optimize evaluations "mod m" like pexpr.c does. 98 99 A stack is used for intermediate values in the expression evaluation, 100 separate from the yacc parser stack. This is simple, makes error 101 recovery easy, minimizes the junk around mpz calls in the rules, and 102 saves initializing or clearing "mpz_t"s during a calculation. A 103 disadvantage though is that variables must be copied to the stack to be 104 worked on. A more sophisticated calculator or language system might be 105 able to avoid that when executing a compiled or semi-compiled form. 106 107 Avoiding repeated initializing and clearing of "mpz_t"s is important. In 108 this program the time spent parsing is obviously much greater than any 109 possible saving from this, but a proper calculator or language should 110 take some trouble over it. Don't be surprised if an init/clear takes 3 111 or more times as long as a 10 limb addition, depending on the system (see 112 the mpz_init_realloc_clear example in tune/README). */ 113 114 115#include <stdio.h> 116#include <stdlib.h> 117#include <string.h> 118#include "gmp.h" 119#define NO_CALC_H /* because it conflicts with normal calc.c stuff */ 120#include "calc-common.h" 121 122 123#define numberof(x) (sizeof (x) / sizeof ((x)[0])) 124 125 126void 127calc_help (void) 128{ 129 printf ("Examples:\n"); 130 printf (" 2+3*4 expressions are evaluated\n"); 131 printf (" x=5^6 variables a to z can be set and used\n"); 132 printf ("Operators:\n"); 133 printf (" + - * arithmetic\n"); 134 printf (" / %% division and remainder (rounding towards negative infinity)\n"); 135 printf (" ^ exponentiation\n"); 136 printf (" ! factorial\n"); 137 printf (" << >> left and right shifts\n"); 138 printf (" <= >= > \\ comparisons, giving 1 if true, 0 if false\n"); 139 printf (" == != < /\n"); 140 printf (" && || logical and/or, giving 1 if true, 0 if false\n"); 141 printf ("Functions:\n"); 142 printf (" abs(n) absolute value\n"); 143 printf (" bin(n,m) binomial coefficient\n"); 144 printf (" fib(n) fibonacci number\n"); 145 printf (" gcd(a,b,..) greatest common divisor\n"); 146 printf (" kron(a,b) kronecker symbol\n"); 147 printf (" lcm(a,b,..) least common multiple\n"); 148 printf (" lucnum(n) lucas number\n"); 149 printf (" nextprime(n) next prime after n\n"); 150 printf (" powm(b,e,m) modulo powering, b^e%%m\n"); 151 printf (" root(n,r) r-th root\n"); 152 printf (" sqrt(n) square root\n"); 153 printf ("Other:\n"); 154 printf (" hex \\ set hex or decimal for input and output\n"); 155 printf (" decimal / (\"0x\" can be used for hex too)\n"); 156 printf (" quit exit program (EOF works too)\n"); 157 printf (" ; statements are separated with a ; or newline\n"); 158 printf (" \\ continue expressions with \\ before newline\n"); 159 printf (" # xxx comments are # though to newline\n"); 160 printf ("Hex numbers must be entered in upper case, to distinguish them from the\n"); 161 printf ("variables a to f (like in bc).\n"); 162} 163 164 165int ibase = 0; 166int obase = 10; 167 168 169/* The stack is a fixed size, which means there's a limit on the nesting 170 allowed in expressions. A more sophisticated program could let it grow 171 dynamically. */ 172 173mpz_t stack[100]; 174mpz_ptr sp = stack[0]; 175 176#define CHECK_OVERFLOW() \ 177 if (sp >= stack[numberof(stack)]) /* FIXME */ \ 178 { \ 179 fprintf (stderr, \ 180 "Value stack overflow, too much nesting in expression\n"); \ 181 YYERROR; \ 182 } 183 184#define CHECK_EMPTY() \ 185 if (sp != stack[0]) \ 186 { \ 187 fprintf (stderr, "Oops, expected the value stack to be empty\n"); \ 188 sp = stack[0]; \ 189 } 190 191 192mpz_t variable[26]; 193 194#define CHECK_VARIABLE(var) \ 195 if ((var) < 0 || (var) >= numberof (variable)) \ 196 { \ 197 fprintf (stderr, "Oops, bad variable somehow: %d\n", var); \ 198 YYERROR; \ 199 } 200 201 202#define CHECK_UI(name,z) \ 203 if (! mpz_fits_ulong_p (z)) \ 204 { \ 205 fprintf (stderr, "%s too big\n", name); \ 206 YYERROR; \ 207 } 208 209 210 211/* Line 268 of yacc.c */ 212#line 213 "calc.c" 213 214/* Enabling traces. */ 215#ifndef YYDEBUG 216# define YYDEBUG 0 217#endif 218 219/* Enabling verbose error messages. */ 220#ifdef YYERROR_VERBOSE 221# undef YYERROR_VERBOSE 222# define YYERROR_VERBOSE 1 223#else 224# define YYERROR_VERBOSE 0 225#endif 226 227/* Enabling the token table. */ 228#ifndef YYTOKEN_TABLE 229# define YYTOKEN_TABLE 0 230#endif 231 232 233/* Tokens. */ 234#ifndef YYTOKENTYPE 235# define YYTOKENTYPE 236 /* Put the tokens into the symbol table, so that GDB and other debuggers 237 know about them. */ 238 enum yytokentype { 239 EOS = 258, 240 BAD = 259, 241 HELP = 260, 242 HEX = 261, 243 DECIMAL = 262, 244 QUIT = 263, 245 ABS = 264, 246 BIN = 265, 247 FIB = 266, 248 GCD = 267, 249 KRON = 268, 250 LCM = 269, 251 LUCNUM = 270, 252 NEXTPRIME = 271, 253 POWM = 272, 254 ROOT = 273, 255 SQRT = 274, 256 NUMBER = 275, 257 VARIABLE = 276, 258 LOR = 277, 259 LAND = 278, 260 GE = 279, 261 LE = 280, 262 NE = 281, 263 EQ = 282, 264 RSHIFT = 283, 265 LSHIFT = 284, 266 UMINUS = 285 267 }; 268#endif 269/* Tokens. */ 270#define EOS 258 271#define BAD 259 272#define HELP 260 273#define HEX 261 274#define DECIMAL 262 275#define QUIT 263 276#define ABS 264 277#define BIN 265 278#define FIB 266 279#define GCD 267 280#define KRON 268 281#define LCM 269 282#define LUCNUM 270 283#define NEXTPRIME 271 284#define POWM 272 285#define ROOT 273 286#define SQRT 274 287#define NUMBER 275 288#define VARIABLE 276 289#define LOR 277 290#define LAND 278 291#define GE 279 292#define LE 280 293#define NE 281 294#define EQ 282 295#define RSHIFT 283 296#define LSHIFT 284 297#define UMINUS 285 298 299 300 301 302#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 303typedef union YYSTYPE 304{ 305 306/* Line 293 of yacc.c */ 307#line 142 "calc.y" 308 309 char *str; 310 int var; 311 312 313 314/* Line 293 of yacc.c */ 315#line 316 "calc.c" 316} YYSTYPE; 317# define YYSTYPE_IS_TRIVIAL 1 318# define yystype YYSTYPE /* obsolescent; will be withdrawn */ 319# define YYSTYPE_IS_DECLARED 1 320#endif 321 322 323/* Copy the second part of user declarations. */ 324 325 326/* Line 343 of yacc.c */ 327#line 328 "calc.c" 328 329#ifdef short 330# undef short 331#endif 332 333#ifdef YYTYPE_UINT8 334typedef YYTYPE_UINT8 yytype_uint8; 335#else 336typedef unsigned char yytype_uint8; 337#endif 338 339#ifdef YYTYPE_INT8 340typedef YYTYPE_INT8 yytype_int8; 341#elif (defined __STDC__ || defined __C99__FUNC__ \ 342 || defined __cplusplus || defined _MSC_VER) 343typedef signed char yytype_int8; 344#else 345typedef short int yytype_int8; 346#endif 347 348#ifdef YYTYPE_UINT16 349typedef YYTYPE_UINT16 yytype_uint16; 350#else 351typedef unsigned short int yytype_uint16; 352#endif 353 354#ifdef YYTYPE_INT16 355typedef YYTYPE_INT16 yytype_int16; 356#else 357typedef short int yytype_int16; 358#endif 359 360#ifndef YYSIZE_T 361# ifdef __SIZE_TYPE__ 362# define YYSIZE_T __SIZE_TYPE__ 363# elif defined size_t 364# define YYSIZE_T size_t 365# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ 366 || defined __cplusplus || defined _MSC_VER) 367# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ 368# define YYSIZE_T size_t 369# else 370# define YYSIZE_T unsigned int 371# endif 372#endif 373 374#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) 375 376#ifndef YY_ 377# if defined YYENABLE_NLS && YYENABLE_NLS 378# if ENABLE_NLS 379# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ 380# define YY_(msgid) dgettext ("bison-runtime", msgid) 381# endif 382# endif 383# ifndef YY_ 384# define YY_(msgid) msgid 385# endif 386#endif 387 388/* Suppress unused-variable warnings by "using" E. */ 389#if ! defined lint || defined __GNUC__ 390# define YYUSE(e) ((void) (e)) 391#else 392# define YYUSE(e) /* empty */ 393#endif 394 395/* Identity function, used to suppress warnings about constant conditions. */ 396#ifndef lint 397# define YYID(n) (n) 398#else 399#if (defined __STDC__ || defined __C99__FUNC__ \ 400 || defined __cplusplus || defined _MSC_VER) 401static int 402YYID (int yyi) 403#else 404static int 405YYID (yyi) 406 int yyi; 407#endif 408{ 409 return yyi; 410} 411#endif 412 413#if ! defined yyoverflow || YYERROR_VERBOSE 414 415/* The parser invokes alloca or malloc; define the necessary symbols. */ 416 417# ifdef YYSTACK_USE_ALLOCA 418# if YYSTACK_USE_ALLOCA 419# ifdef __GNUC__ 420# define YYSTACK_ALLOC __builtin_alloca 421# elif defined __BUILTIN_VA_ARG_INCR 422# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ 423# elif defined _AIX 424# define YYSTACK_ALLOC __alloca 425# elif defined _MSC_VER 426# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ 427# define alloca _alloca 428# else 429# define YYSTACK_ALLOC alloca 430# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ 431 || defined __cplusplus || defined _MSC_VER) 432# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 433# ifndef EXIT_SUCCESS 434# define EXIT_SUCCESS 0 435# endif 436# endif 437# endif 438# endif 439# endif 440 441# ifdef YYSTACK_ALLOC 442 /* Pacify GCC's `empty if-body' warning. */ 443# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) 444# ifndef YYSTACK_ALLOC_MAXIMUM 445 /* The OS might guarantee only one guard page at the bottom of the stack, 446 and a page size can be as small as 4096 bytes. So we cannot safely 447 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 448 to allow for a few compiler-allocated temporary stack slots. */ 449# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 450# endif 451# else 452# define YYSTACK_ALLOC YYMALLOC 453# define YYSTACK_FREE YYFREE 454# ifndef YYSTACK_ALLOC_MAXIMUM 455# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 456# endif 457# if (defined __cplusplus && ! defined EXIT_SUCCESS \ 458 && ! ((defined YYMALLOC || defined malloc) \ 459 && (defined YYFREE || defined free))) 460# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 461# ifndef EXIT_SUCCESS 462# define EXIT_SUCCESS 0 463# endif 464# endif 465# ifndef YYMALLOC 466# define YYMALLOC malloc 467# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ 468 || defined __cplusplus || defined _MSC_VER) 469void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 470# endif 471# endif 472# ifndef YYFREE 473# define YYFREE free 474# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ 475 || defined __cplusplus || defined _MSC_VER) 476void free (void *); /* INFRINGES ON USER NAME SPACE */ 477# endif 478# endif 479# endif 480#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ 481 482 483#if (! defined yyoverflow \ 484 && (! defined __cplusplus \ 485 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 486 487/* A type that is properly aligned for any stack member. */ 488union yyalloc 489{ 490 yytype_int16 yyss_alloc; 491 YYSTYPE yyvs_alloc; 492}; 493 494/* The size of the maximum gap between one aligned stack and the next. */ 495# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) 496 497/* The size of an array large to enough to hold all stacks, each with 498 N elements. */ 499# define YYSTACK_BYTES(N) \ 500 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ 501 + YYSTACK_GAP_MAXIMUM) 502 503# define YYCOPY_NEEDED 1 504 505/* Relocate STACK from its old location to the new one. The 506 local variables YYSIZE and YYSTACKSIZE give the old and new number of 507 elements in the stack, and YYPTR gives the new location of the 508 stack. Advance YYPTR to a properly aligned location for the next 509 stack. */ 510# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ 511 do \ 512 { \ 513 YYSIZE_T yynewbytes; \ 514 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ 515 Stack = &yyptr->Stack_alloc; \ 516 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ 517 yyptr += yynewbytes / sizeof (*yyptr); \ 518 } \ 519 while (YYID (0)) 520 521#endif 522 523#if defined YYCOPY_NEEDED && YYCOPY_NEEDED 524/* Copy COUNT objects from FROM to TO. The source and destination do 525 not overlap. */ 526# ifndef YYCOPY 527# if defined __GNUC__ && 1 < __GNUC__ 528# define YYCOPY(To, From, Count) \ 529 __builtin_memcpy (To, From, (Count) * sizeof (*(From))) 530# else 531# define YYCOPY(To, From, Count) \ 532 do \ 533 { \ 534 YYSIZE_T yyi; \ 535 for (yyi = 0; yyi < (Count); yyi++) \ 536 (To)[yyi] = (From)[yyi]; \ 537 } \ 538 while (YYID (0)) 539# endif 540# endif 541#endif /* !YYCOPY_NEEDED */ 542 543/* YYFINAL -- State number of the termination state. */ 544#define YYFINAL 41 545/* YYLAST -- Last index in YYTABLE. */ 546#define YYLAST 552 547 548/* YYNTOKENS -- Number of terminals. */ 549#define YYNTOKENS 44 550/* YYNNTS -- Number of nonterminals. */ 551#define YYNNTS 7 552/* YYNRULES -- Number of rules. */ 553#define YYNRULES 49 554/* YYNRULES -- Number of states. */ 555#define YYNSTATES 118 556 557/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ 558#define YYUNDEFTOK 2 559#define YYMAXUTOK 285 560 561#define YYTRANSLATE(YYX) \ 562 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) 563 564/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ 565static const yytype_uint8 yytranslate[] = 566{ 567 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 569 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 570 2, 2, 2, 39, 2, 2, 2, 36, 2, 2, 571 41, 42, 34, 32, 43, 33, 2, 35, 2, 2, 572 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 573 24, 40, 25, 2, 2, 2, 2, 2, 2, 2, 574 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 575 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 576 2, 2, 2, 2, 38, 2, 2, 2, 2, 2, 577 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 578 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 579 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 580 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 581 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 582 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 583 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 584 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 585 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 586 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 587 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 588 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 589 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 590 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 591 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 592 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 593 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 594 15, 16, 17, 18, 19, 20, 21, 22, 23, 26, 595 27, 28, 29, 30, 31, 37 596}; 597 598#if YYDEBUG 599/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in 600 YYRHS. */ 601static const yytype_uint8 yyprhs[] = 602{ 603 0, 0, 3, 5, 8, 11, 15, 18, 19, 21, 604 25, 27, 29, 31, 33, 37, 41, 45, 49, 53, 605 57, 61, 65, 69, 72, 75, 79, 83, 87, 91, 606 95, 99, 103, 107, 112, 119, 124, 129, 136, 141, 607 146, 151, 160, 167, 172, 174, 176, 178, 182, 184 608}; 609 610/* YYRHS -- A `-1'-separated list of the rules' RHS. */ 611static const yytype_int8 yyrhs[] = 612{ 613 45, 0, -1, 47, -1, 46, 47, -1, 47, 3, 614 -1, 46, 47, 3, -1, 1, 3, -1, -1, 48, 615 -1, 21, 40, 48, -1, 5, -1, 6, -1, 7, 616 -1, 8, -1, 41, 48, 42, -1, 48, 32, 48, 617 -1, 48, 33, 48, -1, 48, 34, 48, -1, 48, 618 35, 48, -1, 48, 36, 48, -1, 48, 38, 48, 619 -1, 48, 31, 48, -1, 48, 30, 48, -1, 48, 620 39, -1, 33, 48, -1, 48, 24, 48, -1, 48, 621 27, 48, -1, 48, 29, 48, -1, 48, 28, 48, 622 -1, 48, 26, 48, -1, 48, 25, 48, -1, 48, 623 23, 48, -1, 48, 22, 48, -1, 9, 41, 48, 624 42, -1, 10, 41, 48, 43, 48, 42, -1, 11, 625 41, 48, 42, -1, 12, 41, 49, 42, -1, 13, 626 41, 48, 43, 48, 42, -1, 14, 41, 50, 42, 627 -1, 15, 41, 48, 42, -1, 16, 41, 48, 42, 628 -1, 17, 41, 48, 43, 48, 43, 48, 42, -1, 629 18, 41, 48, 43, 48, 42, -1, 19, 41, 48, 630 42, -1, 21, -1, 20, -1, 48, -1, 49, 43, 631 48, -1, 48, -1, 50, 43, 48, -1 632}; 633 634/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 635static const yytype_uint16 yyrline[] = 636{ 637 0, 167, 167, 168, 171, 172, 173, 175, 177, 182, 638 188, 189, 190, 191, 197, 198, 199, 200, 201, 202, 639 203, 205, 207, 209, 211, 213, 214, 215, 216, 217, 640 218, 220, 221, 223, 224, 226, 228, 229, 231, 232, 641 234, 235, 236, 238, 240, 246, 257, 258, 261, 262 642}; 643#endif 644 645#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE 646/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 647 First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 648static const char *const yytname[] = 649{ 650 "$end", "error", "$undefined", "EOS", "BAD", "HELP", "HEX", "DECIMAL", 651 "QUIT", "ABS", "BIN", "FIB", "GCD", "KRON", "LCM", "LUCNUM", "NEXTPRIME", 652 "POWM", "ROOT", "SQRT", "NUMBER", "VARIABLE", "LOR", "LAND", "'<'", 653 "'>'", "GE", "LE", "NE", "EQ", "RSHIFT", "LSHIFT", "'+'", "'-'", "'*'", 654 "'/'", "'%'", "UMINUS", "'^'", "'!'", "'='", "'('", "')'", "','", 655 "$accept", "top", "statements", "statement", "e", "gcdlist", "lcmlist", 0 656}; 657#endif 658 659# ifdef YYPRINT 660/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to 661 token YYLEX-NUM. */ 662static const yytype_uint16 yytoknum[] = 663{ 664 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 665 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 666 275, 276, 277, 278, 60, 62, 279, 280, 281, 282, 667 283, 284, 43, 45, 42, 47, 37, 285, 94, 33, 668 61, 40, 41, 44 669}; 670# endif 671 672/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 673static const yytype_uint8 yyr1[] = 674{ 675 0, 44, 45, 45, 46, 46, 46, 47, 47, 47, 676 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 677 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 678 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 679 48, 48, 48, 48, 48, 48, 49, 49, 50, 50 680}; 681 682/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ 683static const yytype_uint8 yyr2[] = 684{ 685 0, 2, 1, 2, 2, 3, 2, 0, 1, 3, 686 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 687 3, 3, 3, 2, 2, 3, 3, 3, 3, 3, 688 3, 3, 3, 4, 6, 4, 4, 6, 4, 4, 689 4, 8, 6, 4, 1, 1, 1, 3, 1, 3 690}; 691 692/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. 693 Performed when YYTABLE doesn't specify something else to do. Zero 694 means the default is an error. */ 695static const yytype_uint8 yydefact[] = 696{ 697 0, 0, 10, 11, 12, 13, 0, 0, 0, 0, 698 0, 0, 0, 0, 0, 0, 0, 45, 44, 0, 699 0, 0, 7, 2, 8, 6, 0, 0, 0, 0, 700 0, 0, 0, 0, 0, 0, 0, 0, 44, 24, 701 0, 1, 3, 4, 0, 0, 0, 0, 0, 0, 702 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 703 23, 0, 0, 0, 46, 0, 0, 48, 0, 0, 704 0, 0, 0, 0, 9, 14, 5, 32, 31, 25, 705 30, 29, 26, 28, 27, 22, 21, 15, 16, 17, 706 18, 19, 20, 33, 0, 35, 36, 0, 0, 38, 707 0, 39, 40, 0, 0, 43, 0, 47, 0, 49, 708 0, 0, 34, 37, 0, 42, 0, 41 709}; 710 711/* YYDEFGOTO[NTERM-NUM]. */ 712static const yytype_int8 yydefgoto[] = 713{ 714 -1, 21, 22, 23, 24, 65, 68 715}; 716 717/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 718 STATE-NUM. */ 719#define YYPACT_NINF -39 720static const yytype_int16 yypact[] = 721{ 722 41, 3, -39, -39, -39, -39, 2, 4, 27, 32, 723 35, 36, 39, 42, 45, 46, 47, -39, -18, 124, 724 124, 89, 91, 87, 464, -39, 124, 124, 124, 124, 725 124, 124, 124, 124, 124, 124, 124, 124, -39, -36, 726 254, -39, 88, -39, 124, 124, 124, 124, 124, 124, 727 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 728 -39, 275, 144, 296, 464, -38, 166, 464, 29, 317, 729 338, 188, 210, 359, 464, -39, -39, 481, 497, 513, 730 513, 513, 513, 513, 513, 31, 31, -15, -15, -36, 731 -36, -36, -36, -39, 124, -39, -39, 124, 124, -39, 732 124, -39, -39, 124, 124, -39, 380, 464, 401, 464, 733 232, 422, -39, -39, 124, -39, 443, -39 734}; 735 736/* YYPGOTO[NTERM-NUM]. */ 737static const yytype_int8 yypgoto[] = 738{ 739 -39, -39, -39, 70, -19, -39, -39 740}; 741 742/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If 743 positive, shift that token. If negative, reduce the rule which 744 number is the opposite. If YYTABLE_NINF, syntax error. */ 745#define YYTABLE_NINF -8 746static const yytype_int8 yytable[] = 747{ 748 39, 40, 59, 60, 96, 97, 25, 61, 62, 63, 749 64, 66, 67, 69, 70, 71, 72, 73, 74, 56, 750 57, 58, 37, 59, 60, 77, 78, 79, 80, 81, 751 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 752 92, -7, 1, 26, -7, 27, 2, 3, 4, 5, 753 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 754 16, 17, 18, 54, 55, 56, 57, 58, 28, 59, 755 60, 99, 100, 29, 19, 106, 30, 31, 107, 108, 756 32, 109, 20, 33, 110, 111, 34, 35, 36, 41, 757 43, 76, 42, 0, 0, 116, 2, 3, 4, 5, 758 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 759 16, 17, 18, 0, 0, 0, 0, 0, 0, 0, 760 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 761 0, 0, 20, 6, 7, 8, 9, 10, 11, 12, 762 13, 14, 15, 16, 17, 38, 0, 0, 0, 0, 763 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 764 0, 0, 0, 0, 0, 20, 44, 45, 46, 47, 765 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 766 58, 0, 59, 60, 0, 0, 0, 94, 44, 45, 767 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 768 56, 57, 58, 0, 59, 60, 0, 0, 0, 98, 769 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 770 54, 55, 56, 57, 58, 0, 59, 60, 0, 0, 771 0, 103, 44, 45, 46, 47, 48, 49, 50, 51, 772 52, 53, 54, 55, 56, 57, 58, 0, 59, 60, 773 0, 0, 0, 104, 44, 45, 46, 47, 48, 49, 774 50, 51, 52, 53, 54, 55, 56, 57, 58, 0, 775 59, 60, 0, 0, 0, 114, 44, 45, 46, 47, 776 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 777 58, 0, 59, 60, 0, 0, 75, 44, 45, 46, 778 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 779 57, 58, 0, 59, 60, 0, 0, 93, 44, 45, 780 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 781 56, 57, 58, 0, 59, 60, 0, 0, 95, 44, 782 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 783 55, 56, 57, 58, 0, 59, 60, 0, 0, 101, 784 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 785 54, 55, 56, 57, 58, 0, 59, 60, 0, 0, 786 102, 44, 45, 46, 47, 48, 49, 50, 51, 52, 787 53, 54, 55, 56, 57, 58, 0, 59, 60, 0, 788 0, 105, 44, 45, 46, 47, 48, 49, 50, 51, 789 52, 53, 54, 55, 56, 57, 58, 0, 59, 60, 790 0, 0, 112, 44, 45, 46, 47, 48, 49, 50, 791 51, 52, 53, 54, 55, 56, 57, 58, 0, 59, 792 60, 0, 0, 113, 44, 45, 46, 47, 48, 49, 793 50, 51, 52, 53, 54, 55, 56, 57, 58, 0, 794 59, 60, 0, 0, 115, 44, 45, 46, 47, 48, 795 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 796 0, 59, 60, 0, 0, 117, 44, 45, 46, 47, 797 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 798 58, 0, 59, 60, 45, 46, 47, 48, 49, 50, 799 51, 52, 53, 54, 55, 56, 57, 58, 0, 59, 800 60, 46, 47, 48, 49, 50, 51, 52, 53, 54, 801 55, 56, 57, 58, 0, 59, 60, -8, -8, -8, 802 -8, -8, -8, 52, 53, 54, 55, 56, 57, 58, 803 0, 59, 60 804}; 805 806#define yypact_value_is_default(yystate) \ 807 ((yystate) == (-39)) 808 809#define yytable_value_is_error(yytable_value) \ 810 ((yytable_value) == (-8)) 811 812static const yytype_int8 yycheck[] = 813{ 814 19, 20, 38, 39, 42, 43, 3, 26, 27, 28, 815 29, 30, 31, 32, 33, 34, 35, 36, 37, 34, 816 35, 36, 40, 38, 39, 44, 45, 46, 47, 48, 817 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 818 59, 0, 1, 41, 3, 41, 5, 6, 7, 8, 819 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 820 19, 20, 21, 32, 33, 34, 35, 36, 41, 38, 821 39, 42, 43, 41, 33, 94, 41, 41, 97, 98, 822 41, 100, 41, 41, 103, 104, 41, 41, 41, 0, 823 3, 3, 22, -1, -1, 114, 5, 6, 7, 8, 824 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 825 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, 826 -1, -1, -1, -1, 33, -1, -1, -1, -1, -1, 827 -1, -1, 41, 9, 10, 11, 12, 13, 14, 15, 828 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, 829 -1, -1, -1, -1, -1, -1, -1, 33, -1, -1, 830 -1, -1, -1, -1, -1, 41, 22, 23, 24, 25, 831 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 832 36, -1, 38, 39, -1, -1, -1, 43, 22, 23, 833 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 834 34, 35, 36, -1, 38, 39, -1, -1, -1, 43, 835 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 836 32, 33, 34, 35, 36, -1, 38, 39, -1, -1, 837 -1, 43, 22, 23, 24, 25, 26, 27, 28, 29, 838 30, 31, 32, 33, 34, 35, 36, -1, 38, 39, 839 -1, -1, -1, 43, 22, 23, 24, 25, 26, 27, 840 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, 841 38, 39, -1, -1, -1, 43, 22, 23, 24, 25, 842 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 843 36, -1, 38, 39, -1, -1, 42, 22, 23, 24, 844 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 845 35, 36, -1, 38, 39, -1, -1, 42, 22, 23, 846 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 847 34, 35, 36, -1, 38, 39, -1, -1, 42, 22, 848 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 849 33, 34, 35, 36, -1, 38, 39, -1, -1, 42, 850 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 851 32, 33, 34, 35, 36, -1, 38, 39, -1, -1, 852 42, 22, 23, 24, 25, 26, 27, 28, 29, 30, 853 31, 32, 33, 34, 35, 36, -1, 38, 39, -1, 854 -1, 42, 22, 23, 24, 25, 26, 27, 28, 29, 855 30, 31, 32, 33, 34, 35, 36, -1, 38, 39, 856 -1, -1, 42, 22, 23, 24, 25, 26, 27, 28, 857 29, 30, 31, 32, 33, 34, 35, 36, -1, 38, 858 39, -1, -1, 42, 22, 23, 24, 25, 26, 27, 859 28, 29, 30, 31, 32, 33, 34, 35, 36, -1, 860 38, 39, -1, -1, 42, 22, 23, 24, 25, 26, 861 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 862 -1, 38, 39, -1, -1, 42, 22, 23, 24, 25, 863 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 864 36, -1, 38, 39, 23, 24, 25, 26, 27, 28, 865 29, 30, 31, 32, 33, 34, 35, 36, -1, 38, 866 39, 24, 25, 26, 27, 28, 29, 30, 31, 32, 867 33, 34, 35, 36, -1, 38, 39, 24, 25, 26, 868 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 869 -1, 38, 39 870}; 871 872/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 873 symbol of state STATE-NUM. */ 874static const yytype_uint8 yystos[] = 875{ 876 0, 1, 5, 6, 7, 8, 9, 10, 11, 12, 877 13, 14, 15, 16, 17, 18, 19, 20, 21, 33, 878 41, 45, 46, 47, 48, 3, 41, 41, 41, 41, 879 41, 41, 41, 41, 41, 41, 41, 40, 21, 48, 880 48, 0, 47, 3, 22, 23, 24, 25, 26, 27, 881 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 882 39, 48, 48, 48, 48, 49, 48, 48, 50, 48, 883 48, 48, 48, 48, 48, 42, 3, 48, 48, 48, 884 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 885 48, 48, 48, 42, 43, 42, 42, 43, 43, 42, 886 43, 42, 42, 43, 43, 42, 48, 48, 48, 48, 887 48, 48, 42, 42, 43, 42, 48, 42 888}; 889 890#define yyerrok (yyerrstatus = 0) 891#define yyclearin (yychar = YYEMPTY) 892#define YYEMPTY (-2) 893#define YYEOF 0 894 895#define YYACCEPT goto yyacceptlab 896#define YYABORT goto yyabortlab 897#define YYERROR goto yyerrorlab 898 899 900/* Like YYERROR except do call yyerror. This remains here temporarily 901 to ease the transition to the new meaning of YYERROR, for GCC. 902 Once GCC version 2 has supplanted version 1, this can go. However, 903 YYFAIL appears to be in use. Nevertheless, it is formally deprecated 904 in Bison 2.4.2's NEWS entry, where a plan to phase it out is 905 discussed. */ 906 907#define YYFAIL goto yyerrlab 908#if defined YYFAIL 909 /* This is here to suppress warnings from the GCC cpp's 910 -Wunused-macros. Normally we don't worry about that warning, but 911 some users do, and we want to make it easy for users to remove 912 YYFAIL uses, which will produce warnings from Bison 2.5. */ 913#endif 914 915#define YYRECOVERING() (!!yyerrstatus) 916 917#define YYBACKUP(Token, Value) \ 918do \ 919 if (yychar == YYEMPTY && yylen == 1) \ 920 { \ 921 yychar = (Token); \ 922 yylval = (Value); \ 923 YYPOPSTACK (1); \ 924 goto yybackup; \ 925 } \ 926 else \ 927 { \ 928 yyerror (YY_("syntax error: cannot back up")); \ 929 YYERROR; \ 930 } \ 931while (YYID (0)) 932 933 934#define YYTERROR 1 935#define YYERRCODE 256 936 937 938/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. 939 If N is 0, then set CURRENT to the empty location which ends 940 the previous symbol: RHS[0] (always defined). */ 941 942#define YYRHSLOC(Rhs, K) ((Rhs)[K]) 943#ifndef YYLLOC_DEFAULT 944# define YYLLOC_DEFAULT(Current, Rhs, N) \ 945 do \ 946 if (YYID (N)) \ 947 { \ 948 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ 949 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ 950 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ 951 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ 952 } \ 953 else \ 954 { \ 955 (Current).first_line = (Current).last_line = \ 956 YYRHSLOC (Rhs, 0).last_line; \ 957 (Current).first_column = (Current).last_column = \ 958 YYRHSLOC (Rhs, 0).last_column; \ 959 } \ 960 while (YYID (0)) 961#endif 962 963 964/* This macro is provided for backward compatibility. */ 965 966#ifndef YY_LOCATION_PRINT 967# define YY_LOCATION_PRINT(File, Loc) ((void) 0) 968#endif 969 970 971/* YYLEX -- calling `yylex' with the right arguments. */ 972 973#ifdef YYLEX_PARAM 974# define YYLEX yylex (YYLEX_PARAM) 975#else 976# define YYLEX yylex () 977#endif 978 979/* Enable debugging if requested. */ 980#if YYDEBUG 981 982# ifndef YYFPRINTF 983# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ 984# define YYFPRINTF fprintf 985# endif 986 987# define YYDPRINTF(Args) \ 988do { \ 989 if (yydebug) \ 990 YYFPRINTF Args; \ 991} while (YYID (0)) 992 993# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ 994do { \ 995 if (yydebug) \ 996 { \ 997 YYFPRINTF (stderr, "%s ", Title); \ 998 yy_symbol_print (stderr, \ 999 Type, Value); \ 1000 YYFPRINTF (stderr, "\n"); \ 1001 } \ 1002} while (YYID (0)) 1003 1004 1005/*--------------------------------. 1006| Print this symbol on YYOUTPUT. | 1007`--------------------------------*/ 1008 1009/*ARGSUSED*/ 1010#if (defined __STDC__ || defined __C99__FUNC__ \ 1011 || defined __cplusplus || defined _MSC_VER) 1012static void 1013yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) 1014#else 1015static void 1016yy_symbol_value_print (yyoutput, yytype, yyvaluep) 1017 FILE *yyoutput; 1018 int yytype; 1019 YYSTYPE const * const yyvaluep; 1020#endif 1021{ 1022 if (!yyvaluep) 1023 return; 1024# ifdef YYPRINT 1025 if (yytype < YYNTOKENS) 1026 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); 1027# else 1028 YYUSE (yyoutput); 1029# endif 1030 switch (yytype) 1031 { 1032 default: 1033 break; 1034 } 1035} 1036 1037 1038/*--------------------------------. 1039| Print this symbol on YYOUTPUT. | 1040`--------------------------------*/ 1041 1042#if (defined __STDC__ || defined __C99__FUNC__ \ 1043 || defined __cplusplus || defined _MSC_VER) 1044static void 1045yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) 1046#else 1047static void 1048yy_symbol_print (yyoutput, yytype, yyvaluep) 1049 FILE *yyoutput; 1050 int yytype; 1051 YYSTYPE const * const yyvaluep; 1052#endif 1053{ 1054 if (yytype < YYNTOKENS) 1055 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); 1056 else 1057 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); 1058 1059 yy_symbol_value_print (yyoutput, yytype, yyvaluep); 1060 YYFPRINTF (yyoutput, ")"); 1061} 1062 1063/*------------------------------------------------------------------. 1064| yy_stack_print -- Print the state stack from its BOTTOM up to its | 1065| TOP (included). | 1066`------------------------------------------------------------------*/ 1067 1068#if (defined __STDC__ || defined __C99__FUNC__ \ 1069 || defined __cplusplus || defined _MSC_VER) 1070static void 1071yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) 1072#else 1073static void 1074yy_stack_print (yybottom, yytop) 1075 yytype_int16 *yybottom; 1076 yytype_int16 *yytop; 1077#endif 1078{ 1079 YYFPRINTF (stderr, "Stack now"); 1080 for (; yybottom <= yytop; yybottom++) 1081 { 1082 int yybot = *yybottom; 1083 YYFPRINTF (stderr, " %d", yybot); 1084 } 1085 YYFPRINTF (stderr, "\n"); 1086} 1087 1088# define YY_STACK_PRINT(Bottom, Top) \ 1089do { \ 1090 if (yydebug) \ 1091 yy_stack_print ((Bottom), (Top)); \ 1092} while (YYID (0)) 1093 1094 1095/*------------------------------------------------. 1096| Report that the YYRULE is going to be reduced. | 1097`------------------------------------------------*/ 1098 1099#if (defined __STDC__ || defined __C99__FUNC__ \ 1100 || defined __cplusplus || defined _MSC_VER) 1101static void 1102yy_reduce_print (YYSTYPE *yyvsp, int yyrule) 1103#else 1104static void 1105yy_reduce_print (yyvsp, yyrule) 1106 YYSTYPE *yyvsp; 1107 int yyrule; 1108#endif 1109{ 1110 int yynrhs = yyr2[yyrule]; 1111 int yyi; 1112 unsigned long int yylno = yyrline[yyrule]; 1113 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", 1114 yyrule - 1, yylno); 1115 /* The symbols being reduced. */ 1116 for (yyi = 0; yyi < yynrhs; yyi++) 1117 { 1118 YYFPRINTF (stderr, " $%d = ", yyi + 1); 1119 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], 1120 &(yyvsp[(yyi + 1) - (yynrhs)]) 1121 ); 1122 YYFPRINTF (stderr, "\n"); 1123 } 1124} 1125 1126# define YY_REDUCE_PRINT(Rule) \ 1127do { \ 1128 if (yydebug) \ 1129 yy_reduce_print (yyvsp, Rule); \ 1130} while (YYID (0)) 1131 1132/* Nonzero means print parse trace. It is left uninitialized so that 1133 multiple parsers can coexist. */ 1134int yydebug; 1135#else /* !YYDEBUG */ 1136# define YYDPRINTF(Args) 1137# define YY_SYMBOL_PRINT(Title, Type, Value, Location) 1138# define YY_STACK_PRINT(Bottom, Top) 1139# define YY_REDUCE_PRINT(Rule) 1140#endif /* !YYDEBUG */ 1141 1142 1143/* YYINITDEPTH -- initial size of the parser's stacks. */ 1144#ifndef YYINITDEPTH 1145# define YYINITDEPTH 200 1146#endif 1147 1148/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 1149 if the built-in stack extension method is used). 1150 1151 Do not make this value too large; the results are undefined if 1152 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 1153 evaluated with infinite-precision integer arithmetic. */ 1154 1155#ifndef YYMAXDEPTH 1156# define YYMAXDEPTH 10000 1157#endif 1158 1159 1160#if YYERROR_VERBOSE 1161 1162# ifndef yystrlen 1163# if defined __GLIBC__ && defined _STRING_H 1164# define yystrlen strlen 1165# else 1166/* Return the length of YYSTR. */ 1167#if (defined __STDC__ || defined __C99__FUNC__ \ 1168 || defined __cplusplus || defined _MSC_VER) 1169static YYSIZE_T 1170yystrlen (const char *yystr) 1171#else 1172static YYSIZE_T 1173yystrlen (yystr) 1174 const char *yystr; 1175#endif 1176{ 1177 YYSIZE_T yylen; 1178 for (yylen = 0; yystr[yylen]; yylen++) 1179 continue; 1180 return yylen; 1181} 1182# endif 1183# endif 1184 1185# ifndef yystpcpy 1186# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE 1187# define yystpcpy stpcpy 1188# else 1189/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in 1190 YYDEST. */ 1191#if (defined __STDC__ || defined __C99__FUNC__ \ 1192 || defined __cplusplus || defined _MSC_VER) 1193static char * 1194yystpcpy (char *yydest, const char *yysrc) 1195#else 1196static char * 1197yystpcpy (yydest, yysrc) 1198 char *yydest; 1199 const char *yysrc; 1200#endif 1201{ 1202 char *yyd = yydest; 1203 const char *yys = yysrc; 1204 1205 while ((*yyd++ = *yys++) != '\0') 1206 continue; 1207 1208 return yyd - 1; 1209} 1210# endif 1211# endif 1212 1213# ifndef yytnamerr 1214/* Copy to YYRES the contents of YYSTR after stripping away unnecessary 1215 quotes and backslashes, so that it's suitable for yyerror. The 1216 heuristic is that double-quoting is unnecessary unless the string 1217 contains an apostrophe, a comma, or backslash (other than 1218 backslash-backslash). YYSTR is taken from yytname. If YYRES is 1219 null, do not copy; instead, return the length of what the result 1220 would have been. */ 1221static YYSIZE_T 1222yytnamerr (char *yyres, const char *yystr) 1223{ 1224 if (*yystr == '"') 1225 { 1226 YYSIZE_T yyn = 0; 1227 char const *yyp = yystr; 1228 1229 for (;;) 1230 switch (*++yyp) 1231 { 1232 case '\'': 1233 case ',': 1234 goto do_not_strip_quotes; 1235 1236 case '\\': 1237 if (*++yyp != '\\') 1238 goto do_not_strip_quotes; 1239 /* Fall through. */ 1240 default: 1241 if (yyres) 1242 yyres[yyn] = *yyp; 1243 yyn++; 1244 break; 1245 1246 case '"': 1247 if (yyres) 1248 yyres[yyn] = '\0'; 1249 return yyn; 1250 } 1251 do_not_strip_quotes: ; 1252 } 1253 1254 if (! yyres) 1255 return yystrlen (yystr); 1256 1257 return yystpcpy (yyres, yystr) - yyres; 1258} 1259# endif 1260 1261/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message 1262 about the unexpected token YYTOKEN for the state stack whose top is 1263 YYSSP. 1264 1265 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is 1266 not large enough to hold the message. In that case, also set 1267 *YYMSG_ALLOC to the required number of bytes. Return 2 if the 1268 required number of bytes is too large to store. */ 1269static int 1270yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, 1271 yytype_int16 *yyssp, int yytoken) 1272{ 1273 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); 1274 YYSIZE_T yysize = yysize0; 1275 YYSIZE_T yysize1; 1276 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; 1277 /* Internationalized format string. */ 1278 const char *yyformat = 0; 1279 /* Arguments of yyformat. */ 1280 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; 1281 /* Number of reported tokens (one for the "unexpected", one per 1282 "expected"). */ 1283 int yycount = 0; 1284 1285 /* There are many possibilities here to consider: 1286 - Assume YYFAIL is not used. It's too flawed to consider. See 1287 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html> 1288 for details. YYERROR is fine as it does not invoke this 1289 function. 1290 - If this state is a consistent state with a default action, then 1291 the only way this function was invoked is if the default action 1292 is an error action. In that case, don't check for expected 1293 tokens because there are none. 1294 - The only way there can be no lookahead present (in yychar) is if 1295 this state is a consistent state with a default action. Thus, 1296 detecting the absence of a lookahead is sufficient to determine 1297 that there is no unexpected or expected token to report. In that 1298 case, just report a simple "syntax error". 1299 - Don't assume there isn't a lookahead just because this state is a 1300 consistent state with a default action. There might have been a 1301 previous inconsistent state, consistent state with a non-default 1302 action, or user semantic action that manipulated yychar. 1303 - Of course, the expected token list depends on states to have 1304 correct lookahead information, and it depends on the parser not 1305 to perform extra reductions after fetching a lookahead from the 1306 scanner and before detecting a syntax error. Thus, state merging 1307 (from LALR or IELR) and default reductions corrupt the expected 1308 token list. However, the list is correct for canonical LR with 1309 one exception: it will still contain any token that will not be 1310 accepted due to an error action in a later state. 1311 */ 1312 if (yytoken != YYEMPTY) 1313 { 1314 int yyn = yypact[*yyssp]; 1315 yyarg[yycount++] = yytname[yytoken]; 1316 if (!yypact_value_is_default (yyn)) 1317 { 1318 /* Start YYX at -YYN if negative to avoid negative indexes in 1319 YYCHECK. In other words, skip the first -YYN actions for 1320 this state because they are default actions. */ 1321 int yyxbegin = yyn < 0 ? -yyn : 0; 1322 /* Stay within bounds of both yycheck and yytname. */ 1323 int yychecklim = YYLAST - yyn + 1; 1324 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 1325 int yyx; 1326 1327 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 1328 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR 1329 && !yytable_value_is_error (yytable[yyx + yyn])) 1330 { 1331 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) 1332 { 1333 yycount = 1; 1334 yysize = yysize0; 1335 break; 1336 } 1337 yyarg[yycount++] = yytname[yyx]; 1338 yysize1 = yysize + yytnamerr (0, yytname[yyx]); 1339 if (! (yysize <= yysize1 1340 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) 1341 return 2; 1342 yysize = yysize1; 1343 } 1344 } 1345 } 1346 1347 switch (yycount) 1348 { 1349# define YYCASE_(N, S) \ 1350 case N: \ 1351 yyformat = S; \ 1352 break 1353 YYCASE_(0, YY_("syntax error")); 1354 YYCASE_(1, YY_("syntax error, unexpected %s")); 1355 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); 1356 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); 1357 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); 1358 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); 1359# undef YYCASE_ 1360 } 1361 1362 yysize1 = yysize + yystrlen (yyformat); 1363 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) 1364 return 2; 1365 yysize = yysize1; 1366 1367 if (*yymsg_alloc < yysize) 1368 { 1369 *yymsg_alloc = 2 * yysize; 1370 if (! (yysize <= *yymsg_alloc 1371 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) 1372 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; 1373 return 1; 1374 } 1375 1376 /* Avoid sprintf, as that infringes on the user's name space. 1377 Don't have undefined behavior even if the translation 1378 produced a string with the wrong number of "%s"s. */ 1379 { 1380 char *yyp = *yymsg; 1381 int yyi = 0; 1382 while ((*yyp = *yyformat) != '\0') 1383 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) 1384 { 1385 yyp += yytnamerr (yyp, yyarg[yyi++]); 1386 yyformat += 2; 1387 } 1388 else 1389 { 1390 yyp++; 1391 yyformat++; 1392 } 1393 } 1394 return 0; 1395} 1396#endif /* YYERROR_VERBOSE */ 1397 1398/*-----------------------------------------------. 1399| Release the memory associated to this symbol. | 1400`-----------------------------------------------*/ 1401 1402/*ARGSUSED*/ 1403#if (defined __STDC__ || defined __C99__FUNC__ \ 1404 || defined __cplusplus || defined _MSC_VER) 1405static void 1406yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) 1407#else 1408static void 1409yydestruct (yymsg, yytype, yyvaluep) 1410 const char *yymsg; 1411 int yytype; 1412 YYSTYPE *yyvaluep; 1413#endif 1414{ 1415 YYUSE (yyvaluep); 1416 1417 if (!yymsg) 1418 yymsg = "Deleting"; 1419 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); 1420 1421 switch (yytype) 1422 { 1423 1424 default: 1425 break; 1426 } 1427} 1428 1429 1430/* Prevent warnings from -Wmissing-prototypes. */ 1431#ifdef YYPARSE_PARAM 1432#if defined __STDC__ || defined __cplusplus 1433int yyparse (void *YYPARSE_PARAM); 1434#else 1435int yyparse (); 1436#endif 1437#else /* ! YYPARSE_PARAM */ 1438#if defined __STDC__ || defined __cplusplus 1439int yyparse (void); 1440#else 1441int yyparse (); 1442#endif 1443#endif /* ! YYPARSE_PARAM */ 1444 1445 1446/* The lookahead symbol. */ 1447int yychar; 1448 1449/* The semantic value of the lookahead symbol. */ 1450YYSTYPE yylval; 1451 1452/* Number of syntax errors so far. */ 1453int yynerrs; 1454 1455 1456/*----------. 1457| yyparse. | 1458`----------*/ 1459 1460#ifdef YYPARSE_PARAM 1461#if (defined __STDC__ || defined __C99__FUNC__ \ 1462 || defined __cplusplus || defined _MSC_VER) 1463int 1464yyparse (void *YYPARSE_PARAM) 1465#else 1466int 1467yyparse (YYPARSE_PARAM) 1468 void *YYPARSE_PARAM; 1469#endif 1470#else /* ! YYPARSE_PARAM */ 1471#if (defined __STDC__ || defined __C99__FUNC__ \ 1472 || defined __cplusplus || defined _MSC_VER) 1473int 1474yyparse (void) 1475#else 1476int 1477yyparse () 1478 1479#endif 1480#endif 1481{ 1482 int yystate; 1483 /* Number of tokens to shift before error messages enabled. */ 1484 int yyerrstatus; 1485 1486 /* The stacks and their tools: 1487 `yyss': related to states. 1488 `yyvs': related to semantic values. 1489 1490 Refer to the stacks thru separate pointers, to allow yyoverflow 1491 to reallocate them elsewhere. */ 1492 1493 /* The state stack. */ 1494 yytype_int16 yyssa[YYINITDEPTH]; 1495 yytype_int16 *yyss; 1496 yytype_int16 *yyssp; 1497 1498 /* The semantic value stack. */ 1499 YYSTYPE yyvsa[YYINITDEPTH]; 1500 YYSTYPE *yyvs; 1501 YYSTYPE *yyvsp; 1502 1503 YYSIZE_T yystacksize; 1504 1505 int yyn; 1506 int yyresult; 1507 /* Lookahead token as an internal (translated) token number. */ 1508 int yytoken; 1509 /* The variables used to return semantic value and location from the 1510 action routines. */ 1511 YYSTYPE yyval; 1512 1513#if YYERROR_VERBOSE 1514 /* Buffer for error messages, and its allocated size. */ 1515 char yymsgbuf[128]; 1516 char *yymsg = yymsgbuf; 1517 YYSIZE_T yymsg_alloc = sizeof yymsgbuf; 1518#endif 1519 1520#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) 1521 1522 /* The number of symbols on the RHS of the reduced rule. 1523 Keep to zero when no symbol should be popped. */ 1524 int yylen = 0; 1525 1526 yytoken = 0; 1527 yyss = yyssa; 1528 yyvs = yyvsa; 1529 yystacksize = YYINITDEPTH; 1530 1531 YYDPRINTF ((stderr, "Starting parse\n")); 1532 1533 yystate = 0; 1534 yyerrstatus = 0; 1535 yynerrs = 0; 1536 yychar = YYEMPTY; /* Cause a token to be read. */ 1537 1538 /* Initialize stack pointers. 1539 Waste one element of value and location stack 1540 so that they stay on the same level as the state stack. 1541 The wasted elements are never initialized. */ 1542 yyssp = yyss; 1543 yyvsp = yyvs; 1544 1545 goto yysetstate; 1546 1547/*------------------------------------------------------------. 1548| yynewstate -- Push a new state, which is found in yystate. | 1549`------------------------------------------------------------*/ 1550 yynewstate: 1551 /* In all cases, when you get here, the value and location stacks 1552 have just been pushed. So pushing a state here evens the stacks. */ 1553 yyssp++; 1554 1555 yysetstate: 1556 *yyssp = yystate; 1557 1558 if (yyss + yystacksize - 1 <= yyssp) 1559 { 1560 /* Get the current used size of the three stacks, in elements. */ 1561 YYSIZE_T yysize = yyssp - yyss + 1; 1562 1563#ifdef yyoverflow 1564 { 1565 /* Give user a chance to reallocate the stack. Use copies of 1566 these so that the &'s don't force the real ones into 1567 memory. */ 1568 YYSTYPE *yyvs1 = yyvs; 1569 yytype_int16 *yyss1 = yyss; 1570 1571 /* Each stack pointer address is followed by the size of the 1572 data in use in that stack, in bytes. This used to be a 1573 conditional around just the two extra args, but that might 1574 be undefined if yyoverflow is a macro. */ 1575 yyoverflow (YY_("memory exhausted"), 1576 &yyss1, yysize * sizeof (*yyssp), 1577 &yyvs1, yysize * sizeof (*yyvsp), 1578 &yystacksize); 1579 1580 yyss = yyss1; 1581 yyvs = yyvs1; 1582 } 1583#else /* no yyoverflow */ 1584# ifndef YYSTACK_RELOCATE 1585 goto yyexhaustedlab; 1586# else 1587 /* Extend the stack our own way. */ 1588 if (YYMAXDEPTH <= yystacksize) 1589 goto yyexhaustedlab; 1590 yystacksize *= 2; 1591 if (YYMAXDEPTH < yystacksize) 1592 yystacksize = YYMAXDEPTH; 1593 1594 { 1595 yytype_int16 *yyss1 = yyss; 1596 union yyalloc *yyptr = 1597 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); 1598 if (! yyptr) 1599 goto yyexhaustedlab; 1600 YYSTACK_RELOCATE (yyss_alloc, yyss); 1601 YYSTACK_RELOCATE (yyvs_alloc, yyvs); 1602# undef YYSTACK_RELOCATE 1603 if (yyss1 != yyssa) 1604 YYSTACK_FREE (yyss1); 1605 } 1606# endif 1607#endif /* no yyoverflow */ 1608 1609 yyssp = yyss + yysize - 1; 1610 yyvsp = yyvs + yysize - 1; 1611 1612 YYDPRINTF ((stderr, "Stack size increased to %lu\n", 1613 (unsigned long int) yystacksize)); 1614 1615 if (yyss + yystacksize - 1 <= yyssp) 1616 YYABORT; 1617 } 1618 1619 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 1620 1621 if (yystate == YYFINAL) 1622 YYACCEPT; 1623 1624 goto yybackup; 1625 1626/*-----------. 1627| yybackup. | 1628`-----------*/ 1629yybackup: 1630 1631 /* Do appropriate processing given the current state. Read a 1632 lookahead token if we need one and don't already have one. */ 1633 1634 /* First try to decide what to do without reference to lookahead token. */ 1635 yyn = yypact[yystate]; 1636 if (yypact_value_is_default (yyn)) 1637 goto yydefault; 1638 1639 /* Not known => get a lookahead token if don't already have one. */ 1640 1641 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ 1642 if (yychar == YYEMPTY) 1643 { 1644 YYDPRINTF ((stderr, "Reading a token: ")); 1645 yychar = YYLEX; 1646 } 1647 1648 if (yychar <= YYEOF) 1649 { 1650 yychar = yytoken = YYEOF; 1651 YYDPRINTF ((stderr, "Now at end of input.\n")); 1652 } 1653 else 1654 { 1655 yytoken = YYTRANSLATE (yychar); 1656 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 1657 } 1658 1659 /* If the proper action on seeing token YYTOKEN is to reduce or to 1660 detect an error, take that action. */ 1661 yyn += yytoken; 1662 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1663 goto yydefault; 1664 yyn = yytable[yyn]; 1665 if (yyn <= 0) 1666 { 1667 if (yytable_value_is_error (yyn)) 1668 goto yyerrlab; 1669 yyn = -yyn; 1670 goto yyreduce; 1671 } 1672 1673 /* Count tokens shifted since error; after three, turn off error 1674 status. */ 1675 if (yyerrstatus) 1676 yyerrstatus--; 1677 1678 /* Shift the lookahead token. */ 1679 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1680 1681 /* Discard the shifted token. */ 1682 yychar = YYEMPTY; 1683 1684 yystate = yyn; 1685 *++yyvsp = yylval; 1686 1687 goto yynewstate; 1688 1689 1690/*-----------------------------------------------------------. 1691| yydefault -- do the default action for the current state. | 1692`-----------------------------------------------------------*/ 1693yydefault: 1694 yyn = yydefact[yystate]; 1695 if (yyn == 0) 1696 goto yyerrlab; 1697 goto yyreduce; 1698 1699 1700/*-----------------------------. 1701| yyreduce -- Do a reduction. | 1702`-----------------------------*/ 1703yyreduce: 1704 /* yyn is the number of a rule to reduce with. */ 1705 yylen = yyr2[yyn]; 1706 1707 /* If YYLEN is nonzero, implement the default value of the action: 1708 `$$ = $1'. 1709 1710 Otherwise, the following line sets YYVAL to garbage. 1711 This behavior is undocumented and Bison 1712 users should not rely upon it. Assigning to YYVAL 1713 unconditionally makes the parser a bit smaller, and it avoids a 1714 GCC warning that YYVAL may be used uninitialized. */ 1715 yyval = yyvsp[1-yylen]; 1716 1717 1718 YY_REDUCE_PRINT (yyn); 1719 switch (yyn) 1720 { 1721 case 6: 1722 1723/* Line 1806 of yacc.c */ 1724#line 173 "calc.y" 1725 { sp = stack[0]; yyerrok; } 1726 break; 1727 1728 case 8: 1729 1730/* Line 1806 of yacc.c */ 1731#line 177 "calc.y" 1732 { 1733 mpz_out_str (stdout, obase, sp); putchar ('\n'); 1734 sp--; 1735 CHECK_EMPTY (); 1736 } 1737 break; 1738 1739 case 9: 1740 1741/* Line 1806 of yacc.c */ 1742#line 182 "calc.y" 1743 { 1744 CHECK_VARIABLE ((yyvsp[(1) - (3)].var)); 1745 mpz_swap (variable[(yyvsp[(1) - (3)].var)], sp); 1746 sp--; 1747 CHECK_EMPTY (); 1748 } 1749 break; 1750 1751 case 10: 1752 1753/* Line 1806 of yacc.c */ 1754#line 188 "calc.y" 1755 { calc_help (); } 1756 break; 1757 1758 case 11: 1759 1760/* Line 1806 of yacc.c */ 1761#line 189 "calc.y" 1762 { ibase = 16; obase = -16; } 1763 break; 1764 1765 case 12: 1766 1767/* Line 1806 of yacc.c */ 1768#line 190 "calc.y" 1769 { ibase = 0; obase = 10; } 1770 break; 1771 1772 case 13: 1773 1774/* Line 1806 of yacc.c */ 1775#line 191 "calc.y" 1776 { exit (0); } 1777 break; 1778 1779 case 15: 1780 1781/* Line 1806 of yacc.c */ 1782#line 198 "calc.y" 1783 { sp--; mpz_add (sp, sp, sp+1); } 1784 break; 1785 1786 case 16: 1787 1788/* Line 1806 of yacc.c */ 1789#line 199 "calc.y" 1790 { sp--; mpz_sub (sp, sp, sp+1); } 1791 break; 1792 1793 case 17: 1794 1795/* Line 1806 of yacc.c */ 1796#line 200 "calc.y" 1797 { sp--; mpz_mul (sp, sp, sp+1); } 1798 break; 1799 1800 case 18: 1801 1802/* Line 1806 of yacc.c */ 1803#line 201 "calc.y" 1804 { sp--; mpz_fdiv_q (sp, sp, sp+1); } 1805 break; 1806 1807 case 19: 1808 1809/* Line 1806 of yacc.c */ 1810#line 202 "calc.y" 1811 { sp--; mpz_fdiv_r (sp, sp, sp+1); } 1812 break; 1813 1814 case 20: 1815 1816/* Line 1806 of yacc.c */ 1817#line 203 "calc.y" 1818 { CHECK_UI ("Exponent", sp); 1819 sp--; mpz_pow_ui (sp, sp, mpz_get_ui (sp+1)); } 1820 break; 1821 1822 case 21: 1823 1824/* Line 1806 of yacc.c */ 1825#line 205 "calc.y" 1826 { CHECK_UI ("Shift count", sp); 1827 sp--; mpz_mul_2exp (sp, sp, mpz_get_ui (sp+1)); } 1828 break; 1829 1830 case 22: 1831 1832/* Line 1806 of yacc.c */ 1833#line 207 "calc.y" 1834 { CHECK_UI ("Shift count", sp); 1835 sp--; mpz_fdiv_q_2exp (sp, sp, mpz_get_ui (sp+1)); } 1836 break; 1837 1838 case 23: 1839 1840/* Line 1806 of yacc.c */ 1841#line 209 "calc.y" 1842 { CHECK_UI ("Factorial", sp); 1843 mpz_fac_ui (sp, mpz_get_ui (sp)); } 1844 break; 1845 1846 case 24: 1847 1848/* Line 1806 of yacc.c */ 1849#line 211 "calc.y" 1850 { mpz_neg (sp, sp); } 1851 break; 1852 1853 case 25: 1854 1855/* Line 1806 of yacc.c */ 1856#line 213 "calc.y" 1857 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) < 0); } 1858 break; 1859 1860 case 26: 1861 1862/* Line 1806 of yacc.c */ 1863#line 214 "calc.y" 1864 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) <= 0); } 1865 break; 1866 1867 case 27: 1868 1869/* Line 1806 of yacc.c */ 1870#line 215 "calc.y" 1871 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) == 0); } 1872 break; 1873 1874 case 28: 1875 1876/* Line 1806 of yacc.c */ 1877#line 216 "calc.y" 1878 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) != 0); } 1879 break; 1880 1881 case 29: 1882 1883/* Line 1806 of yacc.c */ 1884#line 217 "calc.y" 1885 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) >= 0); } 1886 break; 1887 1888 case 30: 1889 1890/* Line 1806 of yacc.c */ 1891#line 218 "calc.y" 1892 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) > 0); } 1893 break; 1894 1895 case 31: 1896 1897/* Line 1806 of yacc.c */ 1898#line 220 "calc.y" 1899 { sp--; mpz_set_ui (sp, mpz_sgn (sp) && mpz_sgn (sp+1)); } 1900 break; 1901 1902 case 32: 1903 1904/* Line 1806 of yacc.c */ 1905#line 221 "calc.y" 1906 { sp--; mpz_set_ui (sp, mpz_sgn (sp) || mpz_sgn (sp+1)); } 1907 break; 1908 1909 case 33: 1910 1911/* Line 1806 of yacc.c */ 1912#line 223 "calc.y" 1913 { mpz_abs (sp, sp); } 1914 break; 1915 1916 case 34: 1917 1918/* Line 1806 of yacc.c */ 1919#line 224 "calc.y" 1920 { sp--; CHECK_UI ("Binomial base", sp+1); 1921 mpz_bin_ui (sp, sp, mpz_get_ui (sp+1)); } 1922 break; 1923 1924 case 35: 1925 1926/* Line 1806 of yacc.c */ 1927#line 226 "calc.y" 1928 { CHECK_UI ("Fibonacci", sp); 1929 mpz_fib_ui (sp, mpz_get_ui (sp)); } 1930 break; 1931 1932 case 37: 1933 1934/* Line 1806 of yacc.c */ 1935#line 229 "calc.y" 1936 { sp--; mpz_set_si (sp, 1937 mpz_kronecker (sp, sp+1)); } 1938 break; 1939 1940 case 39: 1941 1942/* Line 1806 of yacc.c */ 1943#line 232 "calc.y" 1944 { CHECK_UI ("Lucas number", sp); 1945 mpz_lucnum_ui (sp, mpz_get_ui (sp)); } 1946 break; 1947 1948 case 40: 1949 1950/* Line 1806 of yacc.c */ 1951#line 234 "calc.y" 1952 { mpz_nextprime (sp, sp); } 1953 break; 1954 1955 case 41: 1956 1957/* Line 1806 of yacc.c */ 1958#line 235 "calc.y" 1959 { sp -= 2; mpz_powm (sp, sp, sp+1, sp+2); } 1960 break; 1961 1962 case 42: 1963 1964/* Line 1806 of yacc.c */ 1965#line 236 "calc.y" 1966 { sp--; CHECK_UI ("Nth-root", sp+1); 1967 mpz_root (sp, sp, mpz_get_ui (sp+1)); } 1968 break; 1969 1970 case 43: 1971 1972/* Line 1806 of yacc.c */ 1973#line 238 "calc.y" 1974 { mpz_sqrt (sp, sp); } 1975 break; 1976 1977 case 44: 1978 1979/* Line 1806 of yacc.c */ 1980#line 240 "calc.y" 1981 { 1982 sp++; 1983 CHECK_OVERFLOW (); 1984 CHECK_VARIABLE ((yyvsp[(1) - (1)].var)); 1985 mpz_set (sp, variable[(yyvsp[(1) - (1)].var)]); 1986 } 1987 break; 1988 1989 case 45: 1990 1991/* Line 1806 of yacc.c */ 1992#line 246 "calc.y" 1993 { 1994 sp++; 1995 CHECK_OVERFLOW (); 1996 if (mpz_set_str (sp, (yyvsp[(1) - (1)].str), ibase) != 0) 1997 { 1998 fprintf (stderr, "Invalid number: %s\n", (yyvsp[(1) - (1)].str)); 1999 YYERROR; 2000 } 2001 } 2002 break; 2003 2004 case 47: 2005 2006/* Line 1806 of yacc.c */ 2007#line 258 "calc.y" 2008 { sp--; mpz_gcd (sp, sp, sp+1); } 2009 break; 2010 2011 case 49: 2012 2013/* Line 1806 of yacc.c */ 2014#line 262 "calc.y" 2015 { sp--; mpz_lcm (sp, sp, sp+1); } 2016 break; 2017 2018 2019 2020/* Line 1806 of yacc.c */ 2021#line 2022 "calc.c" 2022 default: break; 2023 } 2024 /* User semantic actions sometimes alter yychar, and that requires 2025 that yytoken be updated with the new translation. We take the 2026 approach of translating immediately before every use of yytoken. 2027 One alternative is translating here after every semantic action, 2028 but that translation would be missed if the semantic action invokes 2029 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or 2030 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an 2031 incorrect destructor might then be invoked immediately. In the 2032 case of YYERROR or YYBACKUP, subsequent parser actions might lead 2033 to an incorrect destructor call or verbose syntax error message 2034 before the lookahead is translated. */ 2035 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); 2036 2037 YYPOPSTACK (yylen); 2038 yylen = 0; 2039 YY_STACK_PRINT (yyss, yyssp); 2040 2041 *++yyvsp = yyval; 2042 2043 /* Now `shift' the result of the reduction. Determine what state 2044 that goes to, based on the state we popped back to and the rule 2045 number reduced by. */ 2046 2047 yyn = yyr1[yyn]; 2048 2049 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; 2050 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) 2051 yystate = yytable[yystate]; 2052 else 2053 yystate = yydefgoto[yyn - YYNTOKENS]; 2054 2055 goto yynewstate; 2056 2057 2058/*------------------------------------. 2059| yyerrlab -- here on detecting error | 2060`------------------------------------*/ 2061yyerrlab: 2062 /* Make sure we have latest lookahead translation. See comments at 2063 user semantic actions for why this is necessary. */ 2064 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); 2065 2066 /* If not already recovering from an error, report this error. */ 2067 if (!yyerrstatus) 2068 { 2069 ++yynerrs; 2070#if ! YYERROR_VERBOSE 2071 yyerror (YY_("syntax error")); 2072#else 2073# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ 2074 yyssp, yytoken) 2075 { 2076 char const *yymsgp = YY_("syntax error"); 2077 int yysyntax_error_status; 2078 yysyntax_error_status = YYSYNTAX_ERROR; 2079 if (yysyntax_error_status == 0) 2080 yymsgp = yymsg; 2081 else if (yysyntax_error_status == 1) 2082 { 2083 if (yymsg != yymsgbuf) 2084 YYSTACK_FREE (yymsg); 2085 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); 2086 if (!yymsg) 2087 { 2088 yymsg = yymsgbuf; 2089 yymsg_alloc = sizeof yymsgbuf; 2090 yysyntax_error_status = 2; 2091 } 2092 else 2093 { 2094 yysyntax_error_status = YYSYNTAX_ERROR; 2095 yymsgp = yymsg; 2096 } 2097 } 2098 yyerror (yymsgp); 2099 if (yysyntax_error_status == 2) 2100 goto yyexhaustedlab; 2101 } 2102# undef YYSYNTAX_ERROR 2103#endif 2104 } 2105 2106 2107 2108 if (yyerrstatus == 3) 2109 { 2110 /* If just tried and failed to reuse lookahead token after an 2111 error, discard it. */ 2112 2113 if (yychar <= YYEOF) 2114 { 2115 /* Return failure if at end of input. */ 2116 if (yychar == YYEOF) 2117 YYABORT; 2118 } 2119 else 2120 { 2121 yydestruct ("Error: discarding", 2122 yytoken, &yylval); 2123 yychar = YYEMPTY; 2124 } 2125 } 2126 2127 /* Else will try to reuse lookahead token after shifting the error 2128 token. */ 2129 goto yyerrlab1; 2130 2131 2132/*---------------------------------------------------. 2133| yyerrorlab -- error raised explicitly by YYERROR. | 2134`---------------------------------------------------*/ 2135yyerrorlab: 2136 2137 /* Pacify compilers like GCC when the user code never invokes 2138 YYERROR and the label yyerrorlab therefore never appears in user 2139 code. */ 2140 if (/*CONSTCOND*/ 0) 2141 goto yyerrorlab; 2142 2143 /* Do not reclaim the symbols of the rule which action triggered 2144 this YYERROR. */ 2145 YYPOPSTACK (yylen); 2146 yylen = 0; 2147 YY_STACK_PRINT (yyss, yyssp); 2148 yystate = *yyssp; 2149 goto yyerrlab1; 2150 2151 2152/*-------------------------------------------------------------. 2153| yyerrlab1 -- common code for both syntax error and YYERROR. | 2154`-------------------------------------------------------------*/ 2155yyerrlab1: 2156 yyerrstatus = 3; /* Each real token shifted decrements this. */ 2157 2158 for (;;) 2159 { 2160 yyn = yypact[yystate]; 2161 if (!yypact_value_is_default (yyn)) 2162 { 2163 yyn += YYTERROR; 2164 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) 2165 { 2166 yyn = yytable[yyn]; 2167 if (0 < yyn) 2168 break; 2169 } 2170 } 2171 2172 /* Pop the current state because it cannot handle the error token. */ 2173 if (yyssp == yyss) 2174 YYABORT; 2175 2176 2177 yydestruct ("Error: popping", 2178 yystos[yystate], yyvsp); 2179 YYPOPSTACK (1); 2180 yystate = *yyssp; 2181 YY_STACK_PRINT (yyss, yyssp); 2182 } 2183 2184 *++yyvsp = yylval; 2185 2186 2187 /* Shift the error token. */ 2188 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); 2189 2190 yystate = yyn; 2191 goto yynewstate; 2192 2193 2194/*-------------------------------------. 2195| yyacceptlab -- YYACCEPT comes here. | 2196`-------------------------------------*/ 2197yyacceptlab: 2198 yyresult = 0; 2199 goto yyreturn; 2200 2201/*-----------------------------------. 2202| yyabortlab -- YYABORT comes here. | 2203`-----------------------------------*/ 2204yyabortlab: 2205 yyresult = 1; 2206 goto yyreturn; 2207 2208#if !defined(yyoverflow) || YYERROR_VERBOSE 2209/*-------------------------------------------------. 2210| yyexhaustedlab -- memory exhaustion comes here. | 2211`-------------------------------------------------*/ 2212yyexhaustedlab: 2213 yyerror (YY_("memory exhausted")); 2214 yyresult = 2; 2215 /* Fall through. */ 2216#endif 2217 2218yyreturn: 2219 if (yychar != YYEMPTY) 2220 { 2221 /* Make sure we have latest lookahead translation. See comments at 2222 user semantic actions for why this is necessary. */ 2223 yytoken = YYTRANSLATE (yychar); 2224 yydestruct ("Cleanup: discarding lookahead", 2225 yytoken, &yylval); 2226 } 2227 /* Do not reclaim the symbols of the rule which action triggered 2228 this YYABORT or YYACCEPT. */ 2229 YYPOPSTACK (yylen); 2230 YY_STACK_PRINT (yyss, yyssp); 2231 while (yyssp != yyss) 2232 { 2233 yydestruct ("Cleanup: popping", 2234 yystos[*yyssp], yyvsp); 2235 YYPOPSTACK (1); 2236 } 2237#ifndef yyoverflow 2238 if (yyss != yyssa) 2239 YYSTACK_FREE (yyss); 2240#endif 2241#if YYERROR_VERBOSE 2242 if (yymsg != yymsgbuf) 2243 YYSTACK_FREE (yymsg); 2244#endif 2245 /* Make sure YYID is used. */ 2246 return YYID (yyresult); 2247} 2248 2249 2250 2251/* Line 2067 of yacc.c */ 2252#line 264 "calc.y" 2253 2254 2255yyerror (char *s) 2256{ 2257 fprintf (stderr, "%s\n", s); 2258} 2259 2260int calc_option_readline = -1; 2261 2262int 2263main (int argc, char *argv[]) 2264{ 2265 int i; 2266 2267 for (i = 1; i < argc; i++) 2268 { 2269 if (strcmp (argv[i], "--readline") == 0) 2270 calc_option_readline = 1; 2271 else if (strcmp (argv[i], "--noreadline") == 0) 2272 calc_option_readline = 0; 2273 else if (strcmp (argv[i], "--help") == 0) 2274 { 2275 printf ("Usage: calc [--option]...\n"); 2276 printf (" --readline use readline\n"); 2277 printf (" --noreadline don't use readline\n"); 2278 printf (" --help this message\n"); 2279 printf ("Readline is only available when compiled in,\n"); 2280 printf ("and in that case it's the default on a tty.\n"); 2281 exit (0); 2282 } 2283 else 2284 { 2285 fprintf (stderr, "Unrecognised option: %s\n", argv[i]); 2286 exit (1); 2287 } 2288 } 2289 2290#if WITH_READLINE 2291 calc_init_readline (); 2292#else 2293 if (calc_option_readline == 1) 2294 { 2295 fprintf (stderr, "Readline support not available\n"); 2296 exit (1); 2297 } 2298#endif 2299 2300 for (i = 0; i < numberof (variable); i++) 2301 mpz_init (variable[i]); 2302 2303 for (i = 0; i < numberof (stack); i++) 2304 mpz_init (stack[i]); 2305 2306 return yyparse (); 2307} 2308 2309