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