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