GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* A Bison parser, made from calc.y1by GNU bison 1.34. */23#define YYBISON 1 /* Identify Bison output. */45# define EOS 2576# define BAD 2587# define HELP 2598# define HEX 2609# define DECIMAL 26110# define QUIT 26211# define ABS 26312# define BIN 26413# define FIB 26514# define GCD 26615# define KRON 26716# define LCM 26817# define LUCNUM 26918# define NEXTPRIME 27019# define POWM 27120# define ROOT 27221# define SQRT 27322# define NUMBER 27423# define VARIABLE 27524# define LOR 27625# define LAND 27726# define EQ 27827# define NE 27928# define LE 28029# define GE 28130# define LSHIFT 28231# define RSHIFT 28332# define UMINUS 2843334#line 1 "calc.y"3536/* A simple integer desk calculator using yacc and gmp.3738Copyright 2000, 2001, 2002 Free Software Foundation, Inc.3940This file is part of the GNU MP Library.4142This program is free software; you can redistribute it and/or modify it under43the terms of the GNU General Public License as published by the Free Software44Foundation; either version 2 of the License, or (at your option) any later45version.4647This program is distributed in the hope that it will be useful, but WITHOUT ANY48WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A49PARTICULAR PURPOSE. See the GNU General Public License for more details.5051You should have received a copy of the GNU General Public License along with52this program; if not, write to the Free Software Foundation, Inc., 51 Franklin53Street, Fifth Floor, Boston, MA 02110-1301, USA. */545556/* This is a simple program, meant only to show one way to use GMP for this57sort of thing. There's few features, and error checking is minimal.58Standard input is read, calc_help() below shows the inputs accepted.5960Expressions are evaluated as they're read. If user defined functions61were wanted it'd be necessary to build a parse tree like pexpr.c does, or62a list of operations for a stack based evaluator. That would also make63it possible to detect and optimize evaluations "mod m" like pexpr.c does.6465A stack is used for intermediate values in the expression evaluation,66separate from the yacc parser stack. This is simple, makes error67recovery easy, minimizes the junk around mpz calls in the rules, and68saves initializing or clearing "mpz_t"s during a calculation. A69disadvantage though is that variables must be copied to the stack to be70worked on. A more sophisticated calculator or language system might be71able to avoid that when executing a compiled or semi-compiled form.7273Avoiding repeated initializing and clearing of "mpz_t"s is important. In74this program the time spent parsing is obviously much greater than any75possible saving from this, but a proper calculator or language should76take some trouble over it. Don't be surprised if an init/clear takes 377or more times as long as a 10 limb addition, depending on the system (see78the mpz_init_realloc_clear example in tune/README). */798081#include <stdio.h>82#include <stdlib.h>83#include <string.h>84#include "gmp.h"85#define NO_CALC_H /* because it conflicts with normal calc.c stuff */86#include "calc-common.h"878889#define numberof(x) (sizeof (x) / sizeof ((x)[0]))909192void93calc_help (void)94{95printf ("Examples:\n");96printf (" 2+3*4 expressions are evaluated\n");97printf (" x=5^6 variables a to z can be set and used\n");98printf ("Operators:\n");99printf (" + - * arithmetic\n");100printf (" / %% division and remainder (rounding towards negative infinity)\n");101printf (" ^ exponentiation\n");102printf (" ! factorial\n");103printf (" << >> left and right shifts\n");104printf (" <= >= > \\ comparisons, giving 1 if true, 0 if false\n");105printf (" == != < /\n");106printf (" && || logical and/or, giving 1 if true, 0 if false\n");107printf ("Functions:\n");108printf (" abs(n) absolute value\n");109printf (" bin(n,m) binomial coefficient\n");110printf (" fib(n) fibonacci number\n");111printf (" gcd(a,b,..) greatest common divisor\n");112printf (" kron(a,b) kronecker symbol\n");113printf (" lcm(a,b,..) least common multiple\n");114printf (" lucnum(n) lucas number\n");115printf (" nextprime(n) next prime after n\n");116printf (" powm(b,e,m) modulo powering, b^e%%m\n");117printf (" root(n,r) r-th root\n");118printf (" sqrt(n) square root\n");119printf ("Other:\n");120printf (" hex \\ set hex or decimal for input and output\n");121printf (" decimal / (\"0x\" can be used for hex too)\n");122printf (" quit exit program (EOF works too)\n");123printf (" ; statements are separated with a ; or newline\n");124printf (" \\ continue expressions with \\ before newline\n");125printf (" # xxx comments are # though to newline\n");126printf ("Hex numbers must be entered in upper case, to distinguish them from the\n");127printf ("variables a to f (like in bc).\n");128}129130131int ibase = 0;132int obase = 10;133134135/* The stack is a fixed size, which means there's a limit on the nesting136allowed in expressions. A more sophisticated program could let it grow137dynamically. */138139mpz_t stack[100];140mpz_ptr sp = stack[0];141142#define CHECK_OVERFLOW() \143if (sp >= stack[numberof(stack)]) \144{ \145fprintf (stderr, \146"Value stack overflow, too much nesting in expression\n"); \147YYERROR; \148}149150#define CHECK_EMPTY() \151if (sp != stack[0]) \152{ \153fprintf (stderr, "Oops, expected the value stack to be empty\n"); \154sp = stack[0]; \155}156157158mpz_t variable[26];159160#define CHECK_VARIABLE(var) \161if ((var) < 0 || (var) >= numberof (variable)) \162{ \163fprintf (stderr, "Oops, bad variable somehow: %d\n", var); \164YYERROR; \165}166167168#define CHECK_UI(name,z) \169if (! mpz_fits_ulong_p (z)) \170{ \171fprintf (stderr, "%s too big\n", name); \172YYERROR; \173}174175176#line 143 "calc.y"177#ifndef YYSTYPE178typedef union {179char *str;180int var;181} yystype;182# define YYSTYPE yystype183#endif184#ifndef YYDEBUG185# define YYDEBUG 0186#endif187188189190#define YYFINAL 118191#define YYFLAG -32768192#define YYNTBASE 44193194/* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */195#define YYTRANSLATE(x) ((unsigned)(x) <= 284 ? yytranslate[x] : 50)196197/* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */198static const char yytranslate[] =199{2000, 2, 2, 2, 2, 2, 2, 2, 2, 2,2012, 2, 2, 2, 2, 2, 2, 2, 2, 2,2022, 2, 2, 2, 2, 2, 2, 2, 2, 2,2032, 2, 2, 39, 2, 2, 2, 36, 2, 2,20441, 42, 34, 32, 43, 33, 2, 35, 2, 2,2052, 2, 2, 2, 2, 2, 2, 2, 2, 2,20624, 40, 25, 2, 2, 2, 2, 2, 2, 2,2072, 2, 2, 2, 2, 2, 2, 2, 2, 2,2082, 2, 2, 2, 2, 2, 2, 2, 2, 2,2092, 2, 2, 2, 38, 2, 2, 2, 2, 2,2102, 2, 2, 2, 2, 2, 2, 2, 2, 2,2112, 2, 2, 2, 2, 2, 2, 2, 2, 2,2122, 2, 2, 2, 2, 2, 2, 2, 2, 2,2132, 2, 2, 2, 2, 2, 2, 2, 2, 2,2142, 2, 2, 2, 2, 2, 2, 2, 2, 2,2152, 2, 2, 2, 2, 2, 2, 2, 2, 2,2162, 2, 2, 2, 2, 2, 2, 2, 2, 2,2172, 2, 2, 2, 2, 2, 2, 2, 2, 2,2182, 2, 2, 2, 2, 2, 2, 2, 2, 2,2192, 2, 2, 2, 2, 2, 2, 2, 2, 2,2202, 2, 2, 2, 2, 2, 2, 2, 2, 2,2212, 2, 2, 2, 2, 2, 2, 2, 2, 2,2222, 2, 2, 2, 2, 2, 2, 2, 2, 2,2232, 2, 2, 2, 2, 2, 2, 2, 2, 2,2242, 2, 2, 2, 2, 2, 2, 2, 2, 2,2252, 2, 2, 2, 2, 2, 1, 3, 4, 5,2266, 7, 8, 9, 10, 11, 12, 13, 14, 15,22716, 17, 18, 19, 20, 21, 22, 23, 26, 27,22828, 29, 30, 31, 37229};230231#if YYDEBUG232static const short yyprhs[] =233{2340, 0, 2, 5, 8, 12, 15, 16, 18, 22,23524, 26, 28, 30, 34, 38, 42, 46, 50, 54,23658, 62, 66, 69, 72, 76, 80, 84, 88, 92,23796, 100, 104, 109, 116, 121, 126, 133, 138, 143,238148, 157, 164, 169, 171, 173, 175, 179, 181239};240static const short yyrhs[] =241{24246, 0, 45, 46, 0, 46, 3, 0, 45, 46,2433, 0, 1, 3, 0, 0, 47, 0, 21, 40,24447, 0, 5, 0, 6, 0, 7, 0, 8, 0,24541, 47, 42, 0, 47, 32, 47, 0, 47, 33,24647, 0, 47, 34, 47, 0, 47, 35, 47, 0,24747, 36, 47, 0, 47, 38, 47, 0, 47, 30,24847, 0, 47, 31, 47, 0, 47, 39, 0, 33,24947, 0, 47, 24, 47, 0, 47, 28, 47, 0,25047, 26, 47, 0, 47, 27, 47, 0, 47, 29,25147, 0, 47, 25, 47, 0, 47, 23, 47, 0,25247, 22, 47, 0, 9, 41, 47, 42, 0, 10,25341, 47, 43, 47, 42, 0, 11, 41, 47, 42,2540, 12, 41, 48, 42, 0, 13, 41, 47, 43,25547, 42, 0, 14, 41, 49, 42, 0, 15, 41,25647, 42, 0, 16, 41, 47, 42, 0, 17, 41,25747, 43, 47, 43, 47, 42, 0, 18, 41, 47,25843, 47, 42, 0, 19, 41, 47, 42, 0, 21,2590, 20, 0, 47, 0, 48, 43, 47, 0, 47,2600, 49, 43, 47, 0261};262263#endif264265#if YYDEBUG266/* YYRLINE[YYN] -- source line where rule number YYN was defined. */267static const short yyrline[] =268{2690, 167, 169, 171, 173, 174, 176, 178, 183, 189,270190, 191, 192, 197, 199, 200, 201, 202, 203, 204,271206, 208, 210, 212, 214, 215, 216, 217, 218, 219,272221, 222, 224, 225, 227, 229, 230, 232, 233, 235,273236, 237, 239, 241, 247, 257, 259, 261, 263274};275#endif276277278#if (YYDEBUG) || defined YYERROR_VERBOSE279280/* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */281static const char *const yytname[] =282{283"$", "error", "$undefined.", "EOS", "BAD", "HELP", "HEX", "DECIMAL",284"QUIT", "ABS", "BIN", "FIB", "GCD", "KRON", "LCM", "LUCNUM",285"NEXTPRIME", "POWM", "ROOT", "SQRT", "NUMBER", "VARIABLE", "LOR",286"LAND", "'<'", "'>'", "EQ", "NE", "LE", "GE", "LSHIFT", "RSHIFT", "'+'",287"'-'", "'*'", "'/'", "'%'", "UMINUS", "'^'", "'!'", "'='", "'('", "')'",288"','", "top", "statements", "statement", "e", "gcdlist", "lcmlist", 0289};290#endif291292/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */293static const short yyr1[] =294{2950, 44, 44, 45, 45, 45, 46, 46, 46, 46,29646, 46, 46, 47, 47, 47, 47, 47, 47, 47,29747, 47, 47, 47, 47, 47, 47, 47, 47, 47,29847, 47, 47, 47, 47, 47, 47, 47, 47, 47,29947, 47, 47, 47, 47, 48, 48, 49, 49300};301302/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */303static const short yyr2[] =304{3050, 1, 2, 2, 3, 2, 0, 1, 3, 1,3061, 1, 1, 3, 3, 3, 3, 3, 3, 3,3073, 3, 2, 2, 3, 3, 3, 3, 3, 3,3083, 3, 4, 6, 4, 4, 6, 4, 4, 4,3098, 6, 4, 1, 1, 1, 3, 1, 3310};311312/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE313doesn't specify something else to do. Zero means the default is an314error. */315static const short yydefact[] =316{3170, 0, 9, 10, 11, 12, 0, 0, 0, 0,3180, 0, 0, 0, 0, 0, 0, 44, 43, 0,3190, 6, 1, 7, 5, 0, 0, 0, 0, 0,3200, 0, 0, 0, 0, 0, 0, 43, 23, 0,3212, 3, 0, 0, 0, 0, 0, 0, 0, 0,3220, 0, 0, 0, 0, 0, 0, 0, 22, 0,3230, 0, 45, 0, 0, 47, 0, 0, 0, 0,3240, 0, 8, 13, 4, 31, 30, 24, 29, 26,32527, 25, 28, 20, 21, 14, 15, 16, 17, 18,32619, 32, 0, 34, 35, 0, 0, 37, 0, 38,32739, 0, 0, 42, 0, 46, 0, 48, 0, 0,32833, 36, 0, 41, 0, 40, 0, 0, 0329};330331static const short yydefgoto[] =332{333116, 21, 22, 23, 63, 66334};335336static const short yypact[] =337{33839, 17,-32768,-32768,-32768,-32768, -20, 0, 2, 25,33928, 30, 33, 34, 37, 40, 46,-32768, -18, 122,340122, 89, 67, 462,-32768, 122, 122, 122, 122, 122,341122, 122, 122, 122, 122, 122, 122,-32768, -36, 252,34287,-32768, 122, 122, 122, 122, 122, 122, 122, 122,343122, 122, 122, 122, 122, 122, 122, 122,-32768, 273,344142, 294, 462, -38, 164, 462, -24, 315, 336, 186,345208, 357, 462,-32768,-32768, 479, 495, 511, 511, 511,346511, 511, 511, 29, 29, 50, 50, -36, -36, -36,347-36,-32768, 122,-32768,-32768, 122, 122,-32768, 122,-32768,348-32768, 122, 122,-32768, 378, 462, 399, 462, 230, 420,349-32768,-32768, 122,-32768, 441,-32768, 91, 92,-32768350};351352static const short yypgoto[] =353{354-32768,-32768, 90, -19,-32768,-32768355};356357358#define YYLAST 550359360361static const short yytable[] =362{36338, 39, 57, 58, 94, 95, 59, 60, 61, 62,36464, 65, 67, 68, 69, 70, 71, 72, 97, 98,36524, 25, 36, 75, 76, 77, 78, 79, 80, 81,36682, 83, 84, 85, 86, 87, 88, 89, 90, -6,3671, 26, -6, 27, 2, 3, 4, 5, 6, 7,3688, 9, 10, 11, 12, 13, 14, 15, 16, 17,36918, 52, 53, 54, 55, 56, 28, 57, 58, 29,37041, 30, 19, 104, 31, 32, 105, 106, 33, 107,37120, 34, 108, 109, 54, 55, 56, 35, 57, 58,37274, 117, 118, 114, 2, 3, 4, 5, 6, 7,3738, 9, 10, 11, 12, 13, 14, 15, 16, 17,37418, 40, 0, 0, 0, 0, 0, 0, 0, 0,3750, 0, 19, 0, 0, 0, 0, 0, 0, 0,37620, 6, 7, 8, 9, 10, 11, 12, 13, 14,37715, 16, 17, 37, 0, 0, 0, 0, 0, 0,3780, 0, 0, 0, 0, 19, 0, 0, 0, 0,3790, 0, 0, 20, 42, 43, 44, 45, 46, 47,38048, 49, 50, 51, 52, 53, 54, 55, 56, 0,38157, 58, 0, 0, 0, 92, 42, 43, 44, 45,38246, 47, 48, 49, 50, 51, 52, 53, 54, 55,38356, 0, 57, 58, 0, 0, 0, 96, 42, 43,38444, 45, 46, 47, 48, 49, 50, 51, 52, 53,38554, 55, 56, 0, 57, 58, 0, 0, 0, 101,38642, 43, 44, 45, 46, 47, 48, 49, 50, 51,38752, 53, 54, 55, 56, 0, 57, 58, 0, 0,3880, 102, 42, 43, 44, 45, 46, 47, 48, 49,38950, 51, 52, 53, 54, 55, 56, 0, 57, 58,3900, 0, 0, 112, 42, 43, 44, 45, 46, 47,39148, 49, 50, 51, 52, 53, 54, 55, 56, 0,39257, 58, 0, 0, 73, 42, 43, 44, 45, 46,39347, 48, 49, 50, 51, 52, 53, 54, 55, 56,3940, 57, 58, 0, 0, 91, 42, 43, 44, 45,39546, 47, 48, 49, 50, 51, 52, 53, 54, 55,39656, 0, 57, 58, 0, 0, 93, 42, 43, 44,39745, 46, 47, 48, 49, 50, 51, 52, 53, 54,39855, 56, 0, 57, 58, 0, 0, 99, 42, 43,39944, 45, 46, 47, 48, 49, 50, 51, 52, 53,40054, 55, 56, 0, 57, 58, 0, 0, 100, 42,40143, 44, 45, 46, 47, 48, 49, 50, 51, 52,40253, 54, 55, 56, 0, 57, 58, 0, 0, 103,40342, 43, 44, 45, 46, 47, 48, 49, 50, 51,40452, 53, 54, 55, 56, 0, 57, 58, 0, 0,405110, 42, 43, 44, 45, 46, 47, 48, 49, 50,40651, 52, 53, 54, 55, 56, 0, 57, 58, 0,4070, 111, 42, 43, 44, 45, 46, 47, 48, 49,40850, 51, 52, 53, 54, 55, 56, 0, 57, 58,4090, 0, 113, 42, 43, 44, 45, 46, 47, 48,41049, 50, 51, 52, 53, 54, 55, 56, 0, 57,41158, 0, 0, 115, 42, 43, 44, 45, 46, 47,41248, 49, 50, 51, 52, 53, 54, 55, 56, 0,41357, 58, 43, 44, 45, 46, 47, 48, 49, 50,41451, 52, 53, 54, 55, 56, 0, 57, 58, 44,41545, 46, 47, 48, 49, 50, 51, 52, 53, 54,41655, 56, 0, 57, 58,-32768,-32768,-32768,-32768,-32768,417-32768, 50, 51, 52, 53, 54, 55, 56, 0, 57,41858419};420421static const short yycheck[] =422{42319, 20, 38, 39, 42, 43, 25, 26, 27, 28,42429, 30, 31, 32, 33, 34, 35, 36, 42, 43,4253, 41, 40, 42, 43, 44, 45, 46, 47, 48,42649, 50, 51, 52, 53, 54, 55, 56, 57, 0,4271, 41, 3, 41, 5, 6, 7, 8, 9, 10,42811, 12, 13, 14, 15, 16, 17, 18, 19, 20,42921, 32, 33, 34, 35, 36, 41, 38, 39, 41,4303, 41, 33, 92, 41, 41, 95, 96, 41, 98,43141, 41, 101, 102, 34, 35, 36, 41, 38, 39,4323, 0, 0, 112, 5, 6, 7, 8, 9, 10,43311, 12, 13, 14, 15, 16, 17, 18, 19, 20,43421, 21, -1, -1, -1, -1, -1, -1, -1, -1,435-1, -1, 33, -1, -1, -1, -1, -1, -1, -1,43641, 9, 10, 11, 12, 13, 14, 15, 16, 17,43718, 19, 20, 21, -1, -1, -1, -1, -1, -1,438-1, -1, -1, -1, -1, 33, -1, -1, -1, -1,439-1, -1, -1, 41, 22, 23, 24, 25, 26, 27,44028, 29, 30, 31, 32, 33, 34, 35, 36, -1,44138, 39, -1, -1, -1, 43, 22, 23, 24, 25,44226, 27, 28, 29, 30, 31, 32, 33, 34, 35,44336, -1, 38, 39, -1, -1, -1, 43, 22, 23,44424, 25, 26, 27, 28, 29, 30, 31, 32, 33,44534, 35, 36, -1, 38, 39, -1, -1, -1, 43,44622, 23, 24, 25, 26, 27, 28, 29, 30, 31,44732, 33, 34, 35, 36, -1, 38, 39, -1, -1,448-1, 43, 22, 23, 24, 25, 26, 27, 28, 29,44930, 31, 32, 33, 34, 35, 36, -1, 38, 39,450-1, -1, -1, 43, 22, 23, 24, 25, 26, 27,45128, 29, 30, 31, 32, 33, 34, 35, 36, -1,45238, 39, -1, -1, 42, 22, 23, 24, 25, 26,45327, 28, 29, 30, 31, 32, 33, 34, 35, 36,454-1, 38, 39, -1, -1, 42, 22, 23, 24, 25,45526, 27, 28, 29, 30, 31, 32, 33, 34, 35,45636, -1, 38, 39, -1, -1, 42, 22, 23, 24,45725, 26, 27, 28, 29, 30, 31, 32, 33, 34,45835, 36, -1, 38, 39, -1, -1, 42, 22, 23,45924, 25, 26, 27, 28, 29, 30, 31, 32, 33,46034, 35, 36, -1, 38, 39, -1, -1, 42, 22,46123, 24, 25, 26, 27, 28, 29, 30, 31, 32,46233, 34, 35, 36, -1, 38, 39, -1, -1, 42,46322, 23, 24, 25, 26, 27, 28, 29, 30, 31,46432, 33, 34, 35, 36, -1, 38, 39, -1, -1,46542, 22, 23, 24, 25, 26, 27, 28, 29, 30,46631, 32, 33, 34, 35, 36, -1, 38, 39, -1,467-1, 42, 22, 23, 24, 25, 26, 27, 28, 29,46830, 31, 32, 33, 34, 35, 36, -1, 38, 39,469-1, -1, 42, 22, 23, 24, 25, 26, 27, 28,47029, 30, 31, 32, 33, 34, 35, 36, -1, 38,47139, -1, -1, 42, 22, 23, 24, 25, 26, 27,47228, 29, 30, 31, 32, 33, 34, 35, 36, -1,47338, 39, 23, 24, 25, 26, 27, 28, 29, 30,47431, 32, 33, 34, 35, 36, -1, 38, 39, 24,47525, 26, 27, 28, 29, 30, 31, 32, 33, 34,47635, 36, -1, 38, 39, 24, 25, 26, 27, 28,47729, 30, 31, 32, 33, 34, 35, 36, -1, 38,47839479};480/* -*-C-*- Note some compilers choke on comments on `#line' lines. */481#line 3 "/usr/share/bison/bison.simple"482483/* Skeleton output parser for bison,484485Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software486Foundation, Inc.487488This program is free software; you can redistribute it and/or modify489it under the terms of the GNU General Public License as published by490the Free Software Foundation; either version 2, or (at your option)491any later version.492493This program is distributed in the hope that it will be useful,494but WITHOUT ANY WARRANTY; without even the implied warranty of495MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the496GNU General Public License for more details.497498You should have received a copy of the GNU General Public License499along with this program; if not, write to the Free Software500Foundation, Inc., 51 Franklin Street, Fifth Floor,501Boston, MA 02110-1301, USA. */502503/* As a special exception, when this file is copied by Bison into a504Bison output file, you may use that output file without restriction.505This special exception was added by the Free Software Foundation506in version 1.24 of Bison. */507508/* This is the parser code that is written into each bison parser when509the %semantic_parser declaration is not specified in the grammar.510It was written by Richard Stallman by simplifying the hairy parser511used when %semantic_parser is specified. */512513/* All symbols defined below should begin with yy or YY, to avoid514infringing on user name space. This should be done even for local515variables, as they might otherwise be expanded by user macros.516There are some unavoidable exceptions within include files to517define necessary library symbols; they are noted "INFRINGES ON518USER NAME SPACE" below. */519520#if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)521522/* The parser invokes alloca or malloc; define the necessary symbols. */523524# if YYSTACK_USE_ALLOCA525# define YYSTACK_ALLOC alloca526# else527# ifndef YYSTACK_USE_ALLOCA528# if defined (alloca) || defined (_ALLOCA_H)529# define YYSTACK_ALLOC alloca530# else531# ifdef __GNUC__532# define YYSTACK_ALLOC __builtin_alloca533# endif534# endif535# endif536# endif537538# ifdef YYSTACK_ALLOC539/* Pacify GCC's `empty if-body' warning. */540# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)541# else542# if defined (__STDC__) || defined (__cplusplus)543# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */544# define YYSIZE_T size_t545# endif546# define YYSTACK_ALLOC malloc547# define YYSTACK_FREE free548# endif549550/* A type that is properly aligned for any stack member. */551union yyalloc552{553short yyss;554YYSTYPE yyvs;555# if YYLSP_NEEDED556YYLTYPE yyls;557# endif558};559560/* The size of the maximum gap between one aligned stack and the next. */561# define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)562563/* The size of an array large to enough to hold all stacks, each with564N elements. */565# if YYLSP_NEEDED566# define YYSTACK_BYTES(N) \567((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \568+ 2 * YYSTACK_GAP_MAX)569# else570# define YYSTACK_BYTES(N) \571((N) * (sizeof (short) + sizeof (YYSTYPE)) \572+ YYSTACK_GAP_MAX)573# endif574575/* Relocate the TYPE STACK from its old location to the new one. The576local variables YYSIZE and YYSTACKSIZE give the old and new number of577elements in the stack, and YYPTR gives the new location of the578stack. Advance YYPTR to a properly aligned location for the next579stack. */580# define YYSTACK_RELOCATE(Type, Stack) \581do \582{ \583YYSIZE_T yynewbytes; \584yymemcpy ((char *) yyptr, (char *) (Stack), \585yysize * (YYSIZE_T) sizeof (Type)); \586Stack = &yyptr->Stack; \587yynewbytes = yystacksize * sizeof (Type) + YYSTACK_GAP_MAX; \588yyptr += yynewbytes / sizeof (*yyptr); \589} \590while (0)591592#endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */593594595#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)596# define YYSIZE_T __SIZE_TYPE__597#endif598#if ! defined (YYSIZE_T) && defined (size_t)599# define YYSIZE_T size_t600#endif601#if ! defined (YYSIZE_T)602# if defined (__STDC__) || defined (__cplusplus)603# include <stddef.h> /* INFRINGES ON USER NAME SPACE */604# define YYSIZE_T size_t605# endif606#endif607#if ! defined (YYSIZE_T)608# define YYSIZE_T unsigned int609#endif610611#define yyerrok (yyerrstatus = 0)612#define yyclearin (yychar = YYEMPTY)613#define YYEMPTY -2614#define YYEOF 0615#define YYACCEPT goto yyacceptlab616#define YYABORT goto yyabortlab617#define YYERROR goto yyerrlab1618/* Like YYERROR except do call yyerror. This remains here temporarily619to ease the transition to the new meaning of YYERROR, for GCC.620Once GCC version 2 has supplanted version 1, this can go. */621#define YYFAIL goto yyerrlab622#define YYRECOVERING() (!!yyerrstatus)623#define YYBACKUP(Token, Value) \624do \625if (yychar == YYEMPTY && yylen == 1) \626{ \627yychar = (Token); \628yylval = (Value); \629yychar1 = YYTRANSLATE (yychar); \630YYPOPSTACK; \631goto yybackup; \632} \633else \634{ \635yyerror ("syntax error: cannot back up"); \636YYERROR; \637} \638while (0)639640#define YYTERROR 1641#define YYERRCODE 256642643644/* YYLLOC_DEFAULT -- Compute the default location (before the actions645are run).646647When YYLLOC_DEFAULT is run, CURRENT is set the location of the648first token. By default, to implement support for ranges, extend649its range to the last symbol. */650651#ifndef YYLLOC_DEFAULT652# define YYLLOC_DEFAULT(Current, Rhs, N) \653Current.last_line = Rhs[N].last_line; \654Current.last_column = Rhs[N].last_column;655#endif656657658/* YYLEX -- calling `yylex' with the right arguments. */659660#if YYPURE661# if YYLSP_NEEDED662# ifdef YYLEX_PARAM663# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)664# else665# define YYLEX yylex (&yylval, &yylloc)666# endif667# else /* !YYLSP_NEEDED */668# ifdef YYLEX_PARAM669# define YYLEX yylex (&yylval, YYLEX_PARAM)670# else671# define YYLEX yylex (&yylval)672# endif673# endif /* !YYLSP_NEEDED */674#else /* !YYPURE */675# define YYLEX yylex ()676#endif /* !YYPURE */677678679/* Enable debugging if requested. */680#if YYDEBUG681682# ifndef YYFPRINTF683# include <stdio.h> /* INFRINGES ON USER NAME SPACE */684# define YYFPRINTF fprintf685# endif686687# define YYDPRINTF(Args) \688do { \689if (yydebug) \690YYFPRINTF Args; \691} while (0)692/* Nonzero means print parse trace. It is left uninitialized so that693multiple parsers can coexist. */694int yydebug;695#else /* !YYDEBUG */696# define YYDPRINTF(Args)697#endif /* !YYDEBUG */698699/* YYINITDEPTH -- initial size of the parser's stacks. */700#ifndef YYINITDEPTH701# define YYINITDEPTH 200702#endif703704/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only705if the built-in stack extension method is used).706707Do not make this value too large; the results are undefined if708SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)709evaluated with infinite-precision integer arithmetic. */710711#if YYMAXDEPTH == 0712# undef YYMAXDEPTH713#endif714715#ifndef YYMAXDEPTH716# define YYMAXDEPTH 10000717#endif718719#if ! defined (yyoverflow) && ! defined (yymemcpy)720# if __GNUC__ > 1 /* GNU C and GNU C++ define this. */721# define yymemcpy __builtin_memcpy722# else /* not GNU C or C++ */723724/* This is the most reliable way to avoid incompatibilities725in available built-in functions on various systems. */726static void727# if defined (__STDC__) || defined (__cplusplus)728yymemcpy (char *yyto, const char *yyfrom, YYSIZE_T yycount)729# else730yymemcpy (yyto, yyfrom, yycount)731char *yyto;732const char *yyfrom;733YYSIZE_T yycount;734# endif735{736register const char *yyf = yyfrom;737register char *yyt = yyto;738register YYSIZE_T yyi = yycount;739740while (yyi-- != 0)741*yyt++ = *yyf++;742}743# endif744#endif745746#ifdef YYERROR_VERBOSE747748# ifndef yystrlen749# if defined (__GLIBC__) && defined (_STRING_H)750# define yystrlen strlen751# else752/* Return the length of YYSTR. */753static YYSIZE_T754# if defined (__STDC__) || defined (__cplusplus)755yystrlen (const char *yystr)756# else757yystrlen (yystr)758const char *yystr;759# endif760{761register const char *yys = yystr;762763while (*yys++ != '\0')764continue;765766return yys - yystr - 1;767}768# endif769# endif770771# ifndef yystpcpy772# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)773# define yystpcpy stpcpy774# else775/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in776YYDEST. */777static char *778# if defined (__STDC__) || defined (__cplusplus)779yystpcpy (char *yydest, const char *yysrc)780# else781yystpcpy (yydest, yysrc)782char *yydest;783const char *yysrc;784# endif785{786register char *yyd = yydest;787register const char *yys = yysrc;788789while ((*yyd++ = *yys++) != '\0')790continue;791792return yyd - 1;793}794# endif795# endif796#endif797798#line 319 "/usr/share/bison/bison.simple"799800801/* The user can define YYPARSE_PARAM as the name of an argument to be passed802into yyparse. The argument should have type void *.803It should actually point to an object.804Grammar actions can access the variable by casting it805to the proper pointer type. */806807#ifdef YYPARSE_PARAM808# if defined (__STDC__) || defined (__cplusplus)809# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM810# define YYPARSE_PARAM_DECL811# else812# define YYPARSE_PARAM_ARG YYPARSE_PARAM813# define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;814# endif815#else /* !YYPARSE_PARAM */816# define YYPARSE_PARAM_ARG817# define YYPARSE_PARAM_DECL818#endif /* !YYPARSE_PARAM */819820/* Prevent warning if -Wstrict-prototypes. */821#ifdef __GNUC__822# ifdef YYPARSE_PARAM823int yyparse (void *);824# else825int yyparse (void);826# endif827#endif828829/* YY_DECL_VARIABLES -- depending whether we use a pure parser,830variables are global, or local to YYPARSE. */831832#define YY_DECL_NON_LSP_VARIABLES \833/* The lookahead symbol. */ \834int yychar; \835\836/* The semantic value of the lookahead symbol. */ \837YYSTYPE yylval; \838\839/* Number of parse errors so far. */ \840int yynerrs;841842#if YYLSP_NEEDED843# define YY_DECL_VARIABLES \844YY_DECL_NON_LSP_VARIABLES \845\846/* Location data for the lookahead symbol. */ \847YYLTYPE yylloc;848#else849# define YY_DECL_VARIABLES \850YY_DECL_NON_LSP_VARIABLES851#endif852853854/* If nonreentrant, generate the variables here. */855856#if !YYPURE857YY_DECL_VARIABLES858#endif /* !YYPURE */859860int861yyparse (YYPARSE_PARAM_ARG)862YYPARSE_PARAM_DECL863{864/* If reentrant, generate the variables here. */865#if YYPURE866YY_DECL_VARIABLES867#endif /* !YYPURE */868869register int yystate;870register int yyn;871int yyresult;872/* Number of tokens to shift before error messages enabled. */873int yyerrstatus;874/* Lookahead token as an internal (translated) token number. */875int yychar1 = 0;876877/* Three stacks and their tools:878`yyss': related to states,879`yyvs': related to semantic values,880`yyls': related to locations.881882Refer to the stacks thru separate pointers, to allow yyoverflow883to reallocate them elsewhere. */884885/* The state stack. */886short yyssa[YYINITDEPTH];887short *yyss = yyssa;888register short *yyssp;889890/* The semantic value stack. */891YYSTYPE yyvsa[YYINITDEPTH];892YYSTYPE *yyvs = yyvsa;893register YYSTYPE *yyvsp;894895#if YYLSP_NEEDED896/* The location stack. */897YYLTYPE yylsa[YYINITDEPTH];898YYLTYPE *yyls = yylsa;899YYLTYPE *yylsp;900#endif901902#if YYLSP_NEEDED903# define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)904#else905# define YYPOPSTACK (yyvsp--, yyssp--)906#endif907908YYSIZE_T yystacksize = YYINITDEPTH;909910911/* The variables used to return semantic value and location from the912action routines. */913YYSTYPE yyval;914#if YYLSP_NEEDED915YYLTYPE yyloc;916#endif917918/* When reducing, the number of symbols on the RHS of the reduced919rule. */920int yylen;921922YYDPRINTF ((stderr, "Starting parse\n"));923924yystate = 0;925yyerrstatus = 0;926yynerrs = 0;927yychar = YYEMPTY; /* Cause a token to be read. */928929/* Initialize stack pointers.930Waste one element of value and location stack931so that they stay on the same level as the state stack.932The wasted elements are never initialized. */933934yyssp = yyss;935yyvsp = yyvs;936#if YYLSP_NEEDED937yylsp = yyls;938#endif939goto yysetstate;940941/*------------------------------------------------------------.942| yynewstate -- Push a new state, which is found in yystate. |943`------------------------------------------------------------*/944yynewstate:945/* In all cases, when you get here, the value and location stacks946have just been pushed. so pushing a state here evens the stacks.947*/948yyssp++;949950yysetstate:951*yyssp = yystate;952953if (yyssp >= yyss + yystacksize - 1)954{955/* Get the current used size of the three stacks, in elements. */956YYSIZE_T yysize = yyssp - yyss + 1;957958#ifdef yyoverflow959{960/* Give user a chance to reallocate the stack. Use copies of961these so that the &'s don't force the real ones into962memory. */963YYSTYPE *yyvs1 = yyvs;964short *yyss1 = yyss;965966/* Each stack pointer address is followed by the size of the967data in use in that stack, in bytes. */968# if YYLSP_NEEDED969YYLTYPE *yyls1 = yyls;970/* This used to be a conditional around just the two extra args,971but that might be undefined if yyoverflow is a macro. */972yyoverflow ("parser stack overflow",973&yyss1, yysize * sizeof (*yyssp),974&yyvs1, yysize * sizeof (*yyvsp),975&yyls1, yysize * sizeof (*yylsp),976&yystacksize);977yyls = yyls1;978# else979yyoverflow ("parser stack overflow",980&yyss1, yysize * sizeof (*yyssp),981&yyvs1, yysize * sizeof (*yyvsp),982&yystacksize);983# endif984yyss = yyss1;985yyvs = yyvs1;986}987#else /* no yyoverflow */988/* Extend the stack our own way. */989if (yystacksize >= YYMAXDEPTH)990goto yyoverflowlab;991yystacksize *= 2;992if (yystacksize > YYMAXDEPTH)993yystacksize = YYMAXDEPTH;994995{996short *yyss1 = yyss;997union yyalloc *yyptr =998(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));999if (! yyptr)1000goto yyoverflowlab;1001YYSTACK_RELOCATE (short, yyss);1002YYSTACK_RELOCATE (YYSTYPE, yyvs);1003# if YYLSP_NEEDED1004YYSTACK_RELOCATE (YYLTYPE, yyls);1005# endif1006# undef YYSTACK_RELOCATE1007if (yyss1 != yyssa)1008YYSTACK_FREE (yyss1);1009}1010#endif /* no yyoverflow */10111012yyssp = yyss + yysize - 1;1013yyvsp = yyvs + yysize - 1;1014#if YYLSP_NEEDED1015yylsp = yyls + yysize - 1;1016#endif10171018YYDPRINTF ((stderr, "Stack size increased to %lu\n",1019(unsigned long int) yystacksize));10201021if (yyssp >= yyss + yystacksize - 1)1022YYABORT;1023}10241025YYDPRINTF ((stderr, "Entering state %d\n", yystate));10261027goto yybackup;102810291030/*-----------.1031| yybackup. |1032`-----------*/1033yybackup:10341035/* Do appropriate processing given the current state. */1036/* Read a lookahead token if we need one and don't already have one. */1037/* yyresume: */10381039/* First try to decide what to do without reference to lookahead token. */10401041yyn = yypact[yystate];1042if (yyn == YYFLAG)1043goto yydefault;10441045/* Not known => get a lookahead token if don't already have one. */10461047/* yychar is either YYEMPTY or YYEOF1048or a valid token in external form. */10491050if (yychar == YYEMPTY)1051{1052YYDPRINTF ((stderr, "Reading a token: "));1053yychar = YYLEX;1054}10551056/* Convert token to internal form (in yychar1) for indexing tables with */10571058if (yychar <= 0) /* This means end of input. */1059{1060yychar1 = 0;1061yychar = YYEOF; /* Don't call YYLEX any more */10621063YYDPRINTF ((stderr, "Now at end of input.\n"));1064}1065else1066{1067yychar1 = YYTRANSLATE (yychar);10681069#if YYDEBUG1070/* We have to keep this `#if YYDEBUG', since we use variables1071which are defined only if `YYDEBUG' is set. */1072if (yydebug)1073{1074YYFPRINTF (stderr, "Next token is %d (%s",1075yychar, yytname[yychar1]);1076/* Give the individual parser a way to print the precise1077meaning of a token, for further debugging info. */1078# ifdef YYPRINT1079YYPRINT (stderr, yychar, yylval);1080# endif1081YYFPRINTF (stderr, ")\n");1082}1083#endif1084}10851086yyn += yychar1;1087if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)1088goto yydefault;10891090yyn = yytable[yyn];10911092/* yyn is what to do for this token type in this state.1093Negative => reduce, -yyn is rule number.1094Positive => shift, yyn is new state.1095New state is final state => don't bother to shift,1096just return success.10970, or most negative number => error. */10981099if (yyn < 0)1100{1101if (yyn == YYFLAG)1102goto yyerrlab;1103yyn = -yyn;1104goto yyreduce;1105}1106else if (yyn == 0)1107goto yyerrlab;11081109if (yyn == YYFINAL)1110YYACCEPT;11111112/* Shift the lookahead token. */1113YYDPRINTF ((stderr, "Shifting token %d (%s), ",1114yychar, yytname[yychar1]));11151116/* Discard the token being shifted unless it is eof. */1117if (yychar != YYEOF)1118yychar = YYEMPTY;11191120*++yyvsp = yylval;1121#if YYLSP_NEEDED1122*++yylsp = yylloc;1123#endif11241125/* Count tokens shifted since error; after three, turn off error1126status. */1127if (yyerrstatus)1128yyerrstatus--;11291130yystate = yyn;1131goto yynewstate;113211331134/*-----------------------------------------------------------.1135| yydefault -- do the default action for the current state. |1136`-----------------------------------------------------------*/1137yydefault:1138yyn = yydefact[yystate];1139if (yyn == 0)1140goto yyerrlab;1141goto yyreduce;114211431144/*-----------------------------.1145| yyreduce -- Do a reduction. |1146`-----------------------------*/1147yyreduce:1148/* yyn is the number of a rule to reduce with. */1149yylen = yyr2[yyn];11501151/* If YYLEN is nonzero, implement the default value of the action:1152`$$ = $1'.11531154Otherwise, the following line sets YYVAL to the semantic value of1155the lookahead token. This behavior is undocumented and Bison1156users should not rely upon it. Assigning to YYVAL1157unconditionally makes the parser a bit smaller, and it avoids a1158GCC warning that YYVAL may be used uninitialized. */1159yyval = yyvsp[1-yylen];11601161#if YYLSP_NEEDED1162/* Similarly for the default location. Let the user run additional1163commands if for instance locations are ranges. */1164yyloc = yylsp[1-yylen];1165YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);1166#endif11671168#if YYDEBUG1169/* We have to keep this `#if YYDEBUG', since we use variables which1170are defined only if `YYDEBUG' is set. */1171if (yydebug)1172{1173int yyi;11741175YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",1176yyn, yyrline[yyn]);11771178/* Print the symbols being reduced, and their result. */1179for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)1180YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);1181YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);1182}1183#endif11841185switch (yyn) {11861187case 5:1188#line 174 "calc.y"1189{ sp = stack[0]; yyerrok; }1190break;1191case 7:1192#line 178 "calc.y"1193{1194mpz_out_str (stdout, obase, sp); putchar ('\n');1195sp--;1196CHECK_EMPTY ();1197}1198break;1199case 8:1200#line 183 "calc.y"1201{1202CHECK_VARIABLE (yyvsp[-2].var);1203mpz_swap (variable[yyvsp[-2].var], sp);1204sp--;1205CHECK_EMPTY ();1206}1207break;1208case 9:1209#line 189 "calc.y"1210{ calc_help (); }1211break;1212case 10:1213#line 190 "calc.y"1214{ ibase = 16; obase = -16; }1215break;1216case 11:1217#line 191 "calc.y"1218{ ibase = 0; obase = 10; }1219break;1220case 12:1221#line 192 "calc.y"1222{ exit (0); }1223break;1224case 14:1225#line 199 "calc.y"1226{ sp--; mpz_add (sp, sp, sp+1); }1227break;1228case 15:1229#line 200 "calc.y"1230{ sp--; mpz_sub (sp, sp, sp+1); }1231break;1232case 16:1233#line 201 "calc.y"1234{ sp--; mpz_mul (sp, sp, sp+1); }1235break;1236case 17:1237#line 202 "calc.y"1238{ sp--; mpz_fdiv_q (sp, sp, sp+1); }1239break;1240case 18:1241#line 203 "calc.y"1242{ sp--; mpz_fdiv_r (sp, sp, sp+1); }1243break;1244case 19:1245#line 204 "calc.y"1246{ CHECK_UI ("Exponent", sp);1247sp--; mpz_pow_ui (sp, sp, mpz_get_ui (sp+1)); }1248break;1249case 20:1250#line 206 "calc.y"1251{ CHECK_UI ("Shift count", sp);1252sp--; mpz_mul_2exp (sp, sp, mpz_get_ui (sp+1)); }1253break;1254case 21:1255#line 208 "calc.y"1256{ CHECK_UI ("Shift count", sp);1257sp--; mpz_fdiv_q_2exp (sp, sp, mpz_get_ui (sp+1)); }1258break;1259case 22:1260#line 210 "calc.y"1261{ CHECK_UI ("Factorial", sp);1262mpz_fac_ui (sp, mpz_get_ui (sp)); }1263break;1264case 23:1265#line 212 "calc.y"1266{ mpz_neg (sp, sp); }1267break;1268case 24:1269#line 214 "calc.y"1270{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) < 0); }1271break;1272case 25:1273#line 215 "calc.y"1274{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) <= 0); }1275break;1276case 26:1277#line 216 "calc.y"1278{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) == 0); }1279break;1280case 27:1281#line 217 "calc.y"1282{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) != 0); }1283break;1284case 28:1285#line 218 "calc.y"1286{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) >= 0); }1287break;1288case 29:1289#line 219 "calc.y"1290{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) > 0); }1291break;1292case 30:1293#line 221 "calc.y"1294{ sp--; mpz_set_ui (sp, mpz_sgn (sp) && mpz_sgn (sp+1)); }1295break;1296case 31:1297#line 222 "calc.y"1298{ sp--; mpz_set_ui (sp, mpz_sgn (sp) || mpz_sgn (sp+1)); }1299break;1300case 32:1301#line 224 "calc.y"1302{ mpz_abs (sp, sp); }1303break;1304case 33:1305#line 225 "calc.y"1306{ sp--; CHECK_UI ("Binomial base", sp+1);1307mpz_bin_ui (sp, sp, mpz_get_ui (sp+1)); }1308break;1309case 34:1310#line 227 "calc.y"1311{ CHECK_UI ("Fibonacci", sp);1312mpz_fib_ui (sp, mpz_get_ui (sp)); }1313break;1314case 36:1315#line 230 "calc.y"1316{ sp--; mpz_set_si (sp,1317mpz_kronecker (sp, sp+1)); }1318break;1319case 38:1320#line 233 "calc.y"1321{ CHECK_UI ("Lucas number", sp);1322mpz_lucnum_ui (sp, mpz_get_ui (sp)); }1323break;1324case 39:1325#line 235 "calc.y"1326{ mpz_nextprime (sp, sp); }1327break;1328case 40:1329#line 236 "calc.y"1330{ sp -= 2; mpz_powm (sp, sp, sp+1, sp+2); }1331break;1332case 41:1333#line 237 "calc.y"1334{ sp--; CHECK_UI ("Nth-root", sp+1);1335mpz_root (sp, sp, mpz_get_ui (sp+1)); }1336break;1337case 42:1338#line 239 "calc.y"1339{ mpz_sqrt (sp, sp); }1340break;1341case 43:1342#line 241 "calc.y"1343{1344sp++;1345CHECK_OVERFLOW ();1346CHECK_VARIABLE (yyvsp[0].var);1347mpz_set (sp, variable[yyvsp[0].var]);1348}1349break;1350case 44:1351#line 247 "calc.y"1352{1353sp++;1354CHECK_OVERFLOW ();1355if (mpz_set_str (sp, yyvsp[0].str, ibase) != 0)1356{1357fprintf (stderr, "Invalid number: %s\n", yyvsp[0].str);1358YYERROR;1359}1360}1361break;1362case 46:1363#line 259 "calc.y"1364{ sp--; mpz_gcd (sp, sp, sp+1); }1365break;1366case 48:1367#line 263 "calc.y"1368{ sp--; mpz_lcm (sp, sp, sp+1); }1369break;1370}13711372#line 705 "/usr/share/bison/bison.simple"137313741375yyvsp -= yylen;1376yyssp -= yylen;1377#if YYLSP_NEEDED1378yylsp -= yylen;1379#endif13801381#if YYDEBUG1382if (yydebug)1383{1384short *yyssp1 = yyss - 1;1385YYFPRINTF (stderr, "state stack now");1386while (yyssp1 != yyssp)1387YYFPRINTF (stderr, " %d", *++yyssp1);1388YYFPRINTF (stderr, "\n");1389}1390#endif13911392*++yyvsp = yyval;1393#if YYLSP_NEEDED1394*++yylsp = yyloc;1395#endif13961397/* Now `shift' the result of the reduction. Determine what state1398that goes to, based on the state we popped back to and the rule1399number reduced by. */14001401yyn = yyr1[yyn];14021403yystate = yypgoto[yyn - YYNTBASE] + *yyssp;1404if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)1405yystate = yytable[yystate];1406else1407yystate = yydefgoto[yyn - YYNTBASE];14081409goto yynewstate;141014111412/*------------------------------------.1413| yyerrlab -- here on detecting error |1414`------------------------------------*/1415yyerrlab:1416/* If not already recovering from an error, report this error. */1417if (!yyerrstatus)1418{1419++yynerrs;14201421#ifdef YYERROR_VERBOSE1422yyn = yypact[yystate];14231424if (yyn > YYFLAG && yyn < YYLAST)1425{1426YYSIZE_T yysize = 0;1427char *yymsg;1428int yyx, yycount;14291430yycount = 0;1431/* Start YYX at -YYN if negative to avoid negative indexes in1432YYCHECK. */1433for (yyx = yyn < 0 ? -yyn : 0;1434yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)1435if (yycheck[yyx + yyn] == yyx)1436yysize += yystrlen (yytname[yyx]) + 15, yycount++;1437yysize += yystrlen ("parse error, unexpected ") + 1;1438yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);1439yymsg = (char *) YYSTACK_ALLOC (yysize);1440if (yymsg != 0)1441{1442char *yyp = yystpcpy (yymsg, "parse error, unexpected ");1443yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);14441445if (yycount < 5)1446{1447yycount = 0;1448for (yyx = yyn < 0 ? -yyn : 0;1449yyx < (int) (sizeof (yytname) / sizeof (char *));1450yyx++)1451if (yycheck[yyx + yyn] == yyx)1452{1453const char *yyq = ! yycount ? ", expecting " : " or ";1454yyp = yystpcpy (yyp, yyq);1455yyp = yystpcpy (yyp, yytname[yyx]);1456yycount++;1457}1458}1459yyerror (yymsg);1460YYSTACK_FREE (yymsg);1461}1462else1463yyerror ("parse error; also virtual memory exhausted");1464}1465else1466#endif /* defined (YYERROR_VERBOSE) */1467yyerror ("parse error");1468}1469goto yyerrlab1;147014711472/*--------------------------------------------------.1473| yyerrlab1 -- error raised explicitly by an action |1474`--------------------------------------------------*/1475yyerrlab1:1476if (yyerrstatus == 3)1477{1478/* If just tried and failed to reuse lookahead token after an1479error, discard it. */14801481/* return failure if at end of input */1482if (yychar == YYEOF)1483YYABORT;1484YYDPRINTF ((stderr, "Discarding token %d (%s).\n",1485yychar, yytname[yychar1]));1486yychar = YYEMPTY;1487}14881489/* Else will try to reuse lookahead token after shifting the error1490token. */14911492yyerrstatus = 3; /* Each real token shifted decrements this */14931494goto yyerrhandle;149514961497/*-------------------------------------------------------------------.1498| yyerrdefault -- current state does not do anything special for the |1499| error token. |1500`-------------------------------------------------------------------*/1501yyerrdefault:1502#if 01503/* This is wrong; only states that explicitly want error tokens1504should shift them. */15051506/* If its default is to accept any token, ok. Otherwise pop it. */1507yyn = yydefact[yystate];1508if (yyn)1509goto yydefault;1510#endif151115121513/*---------------------------------------------------------------.1514| yyerrpop -- pop the current state because it cannot handle the |1515| error token |1516`---------------------------------------------------------------*/1517yyerrpop:1518if (yyssp == yyss)1519YYABORT;1520yyvsp--;1521yystate = *--yyssp;1522#if YYLSP_NEEDED1523yylsp--;1524#endif15251526#if YYDEBUG1527if (yydebug)1528{1529short *yyssp1 = yyss - 1;1530YYFPRINTF (stderr, "Error: state stack now");1531while (yyssp1 != yyssp)1532YYFPRINTF (stderr, " %d", *++yyssp1);1533YYFPRINTF (stderr, "\n");1534}1535#endif15361537/*--------------.1538| yyerrhandle. |1539`--------------*/1540yyerrhandle:1541yyn = yypact[yystate];1542if (yyn == YYFLAG)1543goto yyerrdefault;15441545yyn += YYTERROR;1546if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)1547goto yyerrdefault;15481549yyn = yytable[yyn];1550if (yyn < 0)1551{1552if (yyn == YYFLAG)1553goto yyerrpop;1554yyn = -yyn;1555goto yyreduce;1556}1557else if (yyn == 0)1558goto yyerrpop;15591560if (yyn == YYFINAL)1561YYACCEPT;15621563YYDPRINTF ((stderr, "Shifting error token, "));15641565*++yyvsp = yylval;1566#if YYLSP_NEEDED1567*++yylsp = yylloc;1568#endif15691570yystate = yyn;1571goto yynewstate;157215731574/*-------------------------------------.1575| yyacceptlab -- YYACCEPT comes here. |1576`-------------------------------------*/1577yyacceptlab:1578yyresult = 0;1579goto yyreturn;15801581/*-----------------------------------.1582| yyabortlab -- YYABORT comes here. |1583`-----------------------------------*/1584yyabortlab:1585yyresult = 1;1586goto yyreturn;15871588/*---------------------------------------------.1589| yyoverflowab -- parser overflow comes here. |1590`---------------------------------------------*/1591yyoverflowlab:1592yyerror ("parser stack overflow");1593yyresult = 2;1594/* Fall through. */15951596yyreturn:1597#ifndef yyoverflow1598if (yyss != yyssa)1599YYSTACK_FREE (yyss);1600#endif1601return yyresult;1602}1603#line 265 "calc.y"160416051606yyerror (char *s)1607{1608fprintf (stderr, "%s\n", s);1609}16101611int calc_option_readline = -1;16121613int1614main (int argc, char *argv[])1615{1616int i;16171618for (i = 1; i < argc; i++)1619{1620if (strcmp (argv[i], "--readline") == 0)1621calc_option_readline = 1;1622else if (strcmp (argv[i], "--noreadline") == 0)1623calc_option_readline = 0;1624else if (strcmp (argv[i], "--help") == 0)1625{1626printf ("Usage: calc [--option]...\n");1627printf (" --readline use readline\n");1628printf (" --noreadline don't use readline\n");1629printf (" --help this message\n");1630printf ("Readline is only available when compiled in,\n");1631printf ("and in that case it's the default on a tty.\n");1632exit (0);1633}1634else1635{1636fprintf (stderr, "Unrecognised option: %s\n", argv[i]);1637exit (1);1638}1639}16401641#if WITH_READLINE1642calc_init_readline ();1643#else1644if (calc_option_readline == 1)1645{1646fprintf (stderr, "Readline support not available\n");1647exit (1);1648}1649#endif16501651for (i = 0; i < numberof (variable); i++)1652mpz_init (variable[i]);16531654for (i = 0; i < numberof (stack); i++)1655mpz_init (stack[i]);16561657return yyparse ();1658}165916601661