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