calc.c revision 1.1.1.1 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
1164 #if YYERROR_VERBOSE
1165
1166 # ifndef yystrlen
1167 # if defined __GLIBC__ && defined _STRING_H
1168 # define yystrlen strlen
1169 # else
1170 /* Return the length of YYSTR. */
1171 #if (defined __STDC__ || defined __C99__FUNC__ \
1172 || defined __cplusplus || defined _MSC_VER)
1173 static YYSIZE_T
1174 yystrlen (const char *yystr)
1175 #else
1176 static YYSIZE_T
1177 yystrlen (yystr)
1178 const char *yystr;
1179 #endif
1180 {
1181 YYSIZE_T yylen;
1182 for (yylen = 0; yystr[yylen]; yylen++)
1183 continue;
1184 return yylen;
1185 }
1186 # endif
1187 # endif
1188
1189 # ifndef yystpcpy
1190 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1191 # define yystpcpy stpcpy
1192 # else
1193 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1194 YYDEST. */
1195 #if (defined __STDC__ || defined __C99__FUNC__ \
1196 || defined __cplusplus || defined _MSC_VER)
1197 static char *
1198 yystpcpy (char *yydest, const char *yysrc)
1199 #else
1200 static char *
1201 yystpcpy (yydest, yysrc)
1202 char *yydest;
1203 const char *yysrc;
1204 #endif
1205 {
1206 char *yyd = yydest;
1207 const char *yys = yysrc;
1208
1209 while ((*yyd++ = *yys++) != '\0')
1210 continue;
1211
1212 return yyd - 1;
1213 }
1214 # endif
1215 # endif
1216
1217 # ifndef yytnamerr
1218 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1219 quotes and backslashes, so that it's suitable for yyerror. The
1220 heuristic is that double-quoting is unnecessary unless the string
1221 contains an apostrophe, a comma, or backslash (other than
1222 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1223 null, do not copy; instead, return the length of what the result
1224 would have been. */
1225 static YYSIZE_T
1226 yytnamerr (char *yyres, const char *yystr)
1227 {
1228 if (*yystr == '"')
1229 {
1230 YYSIZE_T yyn = 0;
1231 char const *yyp = yystr;
1232
1233 for (;;)
1234 switch (*++yyp)
1235 {
1236 case '\'':
1237 case ',':
1238 goto do_not_strip_quotes;
1239
1240 case '\\':
1241 if (*++yyp != '\\')
1242 goto do_not_strip_quotes;
1243 /* Fall through. */
1244 default:
1245 if (yyres)
1246 yyres[yyn] = *yyp;
1247 yyn++;
1248 break;
1249
1250 case '"':
1251 if (yyres)
1252 yyres[yyn] = '\0';
1253 return yyn;
1254 }
1255 do_not_strip_quotes: ;
1256 }
1257
1258 if (! yyres)
1259 return yystrlen (yystr);
1260
1261 return yystpcpy (yyres, yystr) - yyres;
1262 }
1263 # endif
1264
1265 /* Copy into YYRESULT an error message about the unexpected token
1266 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1267 including the terminating null byte. If YYRESULT is null, do not
1268 copy anything; just return the number of bytes that would be
1269 copied. As a special case, return 0 if an ordinary "syntax error"
1270 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1271 size calculation. */
1272 static YYSIZE_T
1273 yysyntax_error (char *yyresult, int yystate, int yychar)
1274 {
1275 int yyn = yypact[yystate];
1276
1277 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1278 return 0;
1279 else
1280 {
1281 int yytype = YYTRANSLATE (yychar);
1282 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1283 YYSIZE_T yysize = yysize0;
1284 YYSIZE_T yysize1;
1285 int yysize_overflow = 0;
1286 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1287 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1288 int yyx;
1289
1290 # if 0
1291 /* This is so xgettext sees the translatable formats that are
1292 constructed on the fly. */
1293 YY_("syntax error, unexpected %s");
1294 YY_("syntax error, unexpected %s, expecting %s");
1295 YY_("syntax error, unexpected %s, expecting %s or %s");
1296 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1297 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1298 # endif
1299 char *yyfmt;
1300 char const *yyf;
1301 static char const yyunexpected[] = "syntax error, unexpected %s";
1302 static char const yyexpecting[] = ", expecting %s";
1303 static char const yyor[] = " or %s";
1304 char yyformat[sizeof yyunexpected
1305 + sizeof yyexpecting - 1
1306 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1307 * (sizeof yyor - 1))];
1308 char const *yyprefix = yyexpecting;
1309
1310 /* Start YYX at -YYN if negative to avoid negative indexes in
1311 YYCHECK. */
1312 int yyxbegin = yyn < 0 ? -yyn : 0;
1313
1314 /* Stay within bounds of both yycheck and yytname. */
1315 int yychecklim = YYLAST - yyn + 1;
1316 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1317 int yycount = 1;
1318
1319 yyarg[0] = yytname[yytype];
1320 yyfmt = yystpcpy (yyformat, yyunexpected);
1321
1322 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1323 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1324 {
1325 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1326 {
1327 yycount = 1;
1328 yysize = yysize0;
1329 yyformat[sizeof yyunexpected - 1] = '\0';
1330 break;
1331 }
1332 yyarg[yycount++] = yytname[yyx];
1333 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1334 yysize_overflow |= (yysize1 < yysize);
1335 yysize = yysize1;
1336 yyfmt = yystpcpy (yyfmt, yyprefix);
1337 yyprefix = yyor;
1338 }
1339
1340 yyf = YY_(yyformat);
1341 yysize1 = yysize + yystrlen (yyf);
1342 yysize_overflow |= (yysize1 < yysize);
1343 yysize = yysize1;
1344
1345 if (yysize_overflow)
1346 return YYSIZE_MAXIMUM;
1347
1348 if (yyresult)
1349 {
1350 /* Avoid sprintf, as that infringes on the user's name space.
1351 Don't have undefined behavior even if the translation
1352 produced a string with the wrong number of "%s"s. */
1353 char *yyp = yyresult;
1354 int yyi = 0;
1355 while ((*yyp = *yyf) != '\0')
1356 {
1357 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1358 {
1359 yyp += yytnamerr (yyp, yyarg[yyi++]);
1360 yyf += 2;
1361 }
1362 else
1363 {
1364 yyp++;
1365 yyf++;
1366 }
1367 }
1368 }
1369 return yysize;
1370 }
1371 }
1372 #endif /* YYERROR_VERBOSE */
1373
1374
1376 /*-----------------------------------------------.
1377 | Release the memory associated to this symbol. |
1378 `-----------------------------------------------*/
1379
1380 /*ARGSUSED*/
1381 #if (defined __STDC__ || defined __C99__FUNC__ \
1382 || defined __cplusplus || defined _MSC_VER)
1383 static void
1384 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1385 #else
1386 static void
1387 yydestruct (yymsg, yytype, yyvaluep)
1388 const char *yymsg;
1389 int yytype;
1390 YYSTYPE *yyvaluep;
1391 #endif
1392 {
1393 YYUSE (yyvaluep);
1394
1395 if (!yymsg)
1396 yymsg = "Deleting";
1397 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1398
1399 switch (yytype)
1400 {
1401
1402 default:
1403 break;
1404 }
1405 }
1406
1407 /* Prevent warnings from -Wmissing-prototypes. */
1408 #ifdef YYPARSE_PARAM
1409 #if defined __STDC__ || defined __cplusplus
1410 int yyparse (void *YYPARSE_PARAM);
1411 #else
1412 int yyparse ();
1413 #endif
1414 #else /* ! YYPARSE_PARAM */
1415 #if defined __STDC__ || defined __cplusplus
1416 int yyparse (void);
1417 #else
1418 int yyparse ();
1419 #endif
1420 #endif /* ! YYPARSE_PARAM */
1421
1422
1423 /* The lookahead symbol. */
1424 int yychar;
1425
1426 /* The semantic value of the lookahead symbol. */
1427 YYSTYPE yylval;
1428
1429 /* Number of syntax errors so far. */
1430 int yynerrs;
1431
1432
1433
1434 /*-------------------------.
1435 | yyparse or yypush_parse. |
1436 `-------------------------*/
1437
1438 #ifdef YYPARSE_PARAM
1439 #if (defined __STDC__ || defined __C99__FUNC__ \
1440 || defined __cplusplus || defined _MSC_VER)
1441 int
1442 yyparse (void *YYPARSE_PARAM)
1443 #else
1444 int
1445 yyparse (YYPARSE_PARAM)
1446 void *YYPARSE_PARAM;
1447 #endif
1448 #else /* ! YYPARSE_PARAM */
1449 #if (defined __STDC__ || defined __C99__FUNC__ \
1450 || defined __cplusplus || defined _MSC_VER)
1451 int
1452 yyparse (void)
1453 #else
1454 int
1455 yyparse ()
1456
1457 #endif
1458 #endif
1459 {
1460
1461
1462 int yystate;
1463 /* Number of tokens to shift before error messages enabled. */
1464 int yyerrstatus;
1465
1466 /* The stacks and their tools:
1467 `yyss': related to states.
1468 `yyvs': related to semantic values.
1469
1470 Refer to the stacks thru separate pointers, to allow yyoverflow
1471 to reallocate them elsewhere. */
1472
1473 /* The state stack. */
1474 yytype_int16 yyssa[YYINITDEPTH];
1475 yytype_int16 *yyss;
1476 yytype_int16 *yyssp;
1477
1478 /* The semantic value stack. */
1479 YYSTYPE yyvsa[YYINITDEPTH];
1480 YYSTYPE *yyvs;
1481 YYSTYPE *yyvsp;
1482
1483 YYSIZE_T yystacksize;
1484
1485 int yyn;
1486 int yyresult;
1487 /* Lookahead token as an internal (translated) token number. */
1488 int yytoken;
1489 /* The variables used to return semantic value and location from the
1490 action routines. */
1491 YYSTYPE yyval;
1492
1493 #if YYERROR_VERBOSE
1494 /* Buffer for error messages, and its allocated size. */
1495 char yymsgbuf[128];
1496 char *yymsg = yymsgbuf;
1497 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1498 #endif
1499
1500 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1501
1502 /* The number of symbols on the RHS of the reduced rule.
1503 Keep to zero when no symbol should be popped. */
1504 int yylen = 0;
1505
1506 yytoken = 0;
1507 yyss = yyssa;
1508 yyvs = yyvsa;
1509 yystacksize = YYINITDEPTH;
1510
1511 YYDPRINTF ((stderr, "Starting parse\n"));
1512
1513 yystate = 0;
1514 yyerrstatus = 0;
1515 yynerrs = 0;
1516 yychar = YYEMPTY; /* Cause a token to be read. */
1517
1518 /* Initialize stack pointers.
1519 Waste one element of value and location stack
1520 so that they stay on the same level as the state stack.
1521 The wasted elements are never initialized. */
1522 yyssp = yyss;
1523 yyvsp = yyvs;
1524
1525 goto yysetstate;
1526
1527 /*------------------------------------------------------------.
1528 | yynewstate -- Push a new state, which is found in yystate. |
1529 `------------------------------------------------------------*/
1530 yynewstate:
1531 /* In all cases, when you get here, the value and location stacks
1532 have just been pushed. So pushing a state here evens the stacks. */
1533 yyssp++;
1534
1535 yysetstate:
1536 *yyssp = yystate;
1537
1538 if (yyss + yystacksize - 1 <= yyssp)
1539 {
1540 /* Get the current used size of the three stacks, in elements. */
1541 YYSIZE_T yysize = yyssp - yyss + 1;
1542
1543 #ifdef yyoverflow
1544 {
1545 /* Give user a chance to reallocate the stack. Use copies of
1546 these so that the &'s don't force the real ones into
1547 memory. */
1548 YYSTYPE *yyvs1 = yyvs;
1549 yytype_int16 *yyss1 = yyss;
1550
1551 /* Each stack pointer address is followed by the size of the
1552 data in use in that stack, in bytes. This used to be a
1553 conditional around just the two extra args, but that might
1554 be undefined if yyoverflow is a macro. */
1555 yyoverflow (YY_("memory exhausted"),
1556 &yyss1, yysize * sizeof (*yyssp),
1557 &yyvs1, yysize * sizeof (*yyvsp),
1558 &yystacksize);
1559
1560 yyss = yyss1;
1561 yyvs = yyvs1;
1562 }
1563 #else /* no yyoverflow */
1564 # ifndef YYSTACK_RELOCATE
1565 goto yyexhaustedlab;
1566 # else
1567 /* Extend the stack our own way. */
1568 if (YYMAXDEPTH <= yystacksize)
1569 goto yyexhaustedlab;
1570 yystacksize *= 2;
1571 if (YYMAXDEPTH < yystacksize)
1572 yystacksize = YYMAXDEPTH;
1573
1574 {
1575 yytype_int16 *yyss1 = yyss;
1576 union yyalloc *yyptr =
1577 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1578 if (! yyptr)
1579 goto yyexhaustedlab;
1580 YYSTACK_RELOCATE (yyss_alloc, yyss);
1581 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1582 # undef YYSTACK_RELOCATE
1583 if (yyss1 != yyssa)
1584 YYSTACK_FREE (yyss1);
1585 }
1586 # endif
1587 #endif /* no yyoverflow */
1588
1589 yyssp = yyss + yysize - 1;
1590 yyvsp = yyvs + yysize - 1;
1591
1592 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1593 (unsigned long int) yystacksize));
1594
1595 if (yyss + yystacksize - 1 <= yyssp)
1596 YYABORT;
1597 }
1598
1599 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1600
1601 if (yystate == YYFINAL)
1602 YYACCEPT;
1603
1604 goto yybackup;
1605
1606 /*-----------.
1607 | yybackup. |
1608 `-----------*/
1609 yybackup:
1610
1611 /* Do appropriate processing given the current state. Read a
1612 lookahead token if we need one and don't already have one. */
1613
1614 /* First try to decide what to do without reference to lookahead token. */
1615 yyn = yypact[yystate];
1616 if (yyn == YYPACT_NINF)
1617 goto yydefault;
1618
1619 /* Not known => get a lookahead token if don't already have one. */
1620
1621 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1622 if (yychar == YYEMPTY)
1623 {
1624 YYDPRINTF ((stderr, "Reading a token: "));
1625 yychar = YYLEX;
1626 }
1627
1628 if (yychar <= YYEOF)
1629 {
1630 yychar = yytoken = YYEOF;
1631 YYDPRINTF ((stderr, "Now at end of input.\n"));
1632 }
1633 else
1634 {
1635 yytoken = YYTRANSLATE (yychar);
1636 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1637 }
1638
1639 /* If the proper action on seeing token YYTOKEN is to reduce or to
1640 detect an error, take that action. */
1641 yyn += yytoken;
1642 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1643 goto yydefault;
1644 yyn = yytable[yyn];
1645 if (yyn <= 0)
1646 {
1647 if (yyn == 0 || yyn == YYTABLE_NINF)
1648 goto yyerrlab;
1649 yyn = -yyn;
1650 goto yyreduce;
1651 }
1652
1653 /* Count tokens shifted since error; after three, turn off error
1654 status. */
1655 if (yyerrstatus)
1656 yyerrstatus--;
1657
1658 /* Shift the lookahead token. */
1659 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1660
1661 /* Discard the shifted token. */
1662 yychar = YYEMPTY;
1663
1664 yystate = yyn;
1665 *++yyvsp = yylval;
1666
1667 goto yynewstate;
1668
1669
1670 /*-----------------------------------------------------------.
1671 | yydefault -- do the default action for the current state. |
1672 `-----------------------------------------------------------*/
1673 yydefault:
1674 yyn = yydefact[yystate];
1675 if (yyn == 0)
1676 goto yyerrlab;
1677 goto yyreduce;
1678
1679
1680 /*-----------------------------.
1681 | yyreduce -- Do a reduction. |
1682 `-----------------------------*/
1683 yyreduce:
1684 /* yyn is the number of a rule to reduce with. */
1685 yylen = yyr2[yyn];
1686
1687 /* If YYLEN is nonzero, implement the default value of the action:
1688 `$$ = $1'.
1689
1690 Otherwise, the following line sets YYVAL to garbage.
1691 This behavior is undocumented and Bison
1692 users should not rely upon it. Assigning to YYVAL
1693 unconditionally makes the parser a bit smaller, and it avoids a
1694 GCC warning that YYVAL may be used uninitialized. */
1695 yyval = yyvsp[1-yylen];
1696
1697
1698 YY_REDUCE_PRINT (yyn);
1699 switch (yyn)
1700 {
1701 case 6:
1702
1703 /* Line 1464 of yacc.c */
1704 #line 173 "calc.y"
1705 { sp = stack[0]; yyerrok; }
1706 break;
1707
1708 case 8:
1709
1710 /* Line 1464 of yacc.c */
1711 #line 177 "calc.y"
1712 {
1713 mpz_out_str (stdout, obase, sp); putchar ('\n');
1714 sp--;
1715 CHECK_EMPTY ();
1716 }
1717 break;
1718
1719 case 9:
1720
1721 /* Line 1464 of yacc.c */
1722 #line 182 "calc.y"
1723 {
1724 CHECK_VARIABLE ((yyvsp[(1) - (3)].var));
1725 mpz_swap (variable[(yyvsp[(1) - (3)].var)], sp);
1726 sp--;
1727 CHECK_EMPTY ();
1728 }
1729 break;
1730
1731 case 10:
1732
1733 /* Line 1464 of yacc.c */
1734 #line 188 "calc.y"
1735 { calc_help (); }
1736 break;
1737
1738 case 11:
1739
1740 /* Line 1464 of yacc.c */
1741 #line 189 "calc.y"
1742 { ibase = 16; obase = -16; }
1743 break;
1744
1745 case 12:
1746
1747 /* Line 1464 of yacc.c */
1748 #line 190 "calc.y"
1749 { ibase = 0; obase = 10; }
1750 break;
1751
1752 case 13:
1753
1754 /* Line 1464 of yacc.c */
1755 #line 191 "calc.y"
1756 { exit (0); }
1757 break;
1758
1759 case 15:
1760
1761 /* Line 1464 of yacc.c */
1762 #line 198 "calc.y"
1763 { sp--; mpz_add (sp, sp, sp+1); }
1764 break;
1765
1766 case 16:
1767
1768 /* Line 1464 of yacc.c */
1769 #line 199 "calc.y"
1770 { sp--; mpz_sub (sp, sp, sp+1); }
1771 break;
1772
1773 case 17:
1774
1775 /* Line 1464 of yacc.c */
1776 #line 200 "calc.y"
1777 { sp--; mpz_mul (sp, sp, sp+1); }
1778 break;
1779
1780 case 18:
1781
1782 /* Line 1464 of yacc.c */
1783 #line 201 "calc.y"
1784 { sp--; mpz_fdiv_q (sp, sp, sp+1); }
1785 break;
1786
1787 case 19:
1788
1789 /* Line 1464 of yacc.c */
1790 #line 202 "calc.y"
1791 { sp--; mpz_fdiv_r (sp, sp, sp+1); }
1792 break;
1793
1794 case 20:
1795
1796 /* Line 1464 of yacc.c */
1797 #line 203 "calc.y"
1798 { CHECK_UI ("Exponent", sp);
1799 sp--; mpz_pow_ui (sp, sp, mpz_get_ui (sp+1)); }
1800 break;
1801
1802 case 21:
1803
1804 /* Line 1464 of yacc.c */
1805 #line 205 "calc.y"
1806 { CHECK_UI ("Shift count", sp);
1807 sp--; mpz_mul_2exp (sp, sp, mpz_get_ui (sp+1)); }
1808 break;
1809
1810 case 22:
1811
1812 /* Line 1464 of yacc.c */
1813 #line 207 "calc.y"
1814 { CHECK_UI ("Shift count", sp);
1815 sp--; mpz_fdiv_q_2exp (sp, sp, mpz_get_ui (sp+1)); }
1816 break;
1817
1818 case 23:
1819
1820 /* Line 1464 of yacc.c */
1821 #line 209 "calc.y"
1822 { CHECK_UI ("Factorial", sp);
1823 mpz_fac_ui (sp, mpz_get_ui (sp)); }
1824 break;
1825
1826 case 24:
1827
1828 /* Line 1464 of yacc.c */
1829 #line 211 "calc.y"
1830 { mpz_neg (sp, sp); }
1831 break;
1832
1833 case 25:
1834
1835 /* Line 1464 of yacc.c */
1836 #line 213 "calc.y"
1837 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) < 0); }
1838 break;
1839
1840 case 26:
1841
1842 /* Line 1464 of yacc.c */
1843 #line 214 "calc.y"
1844 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) <= 0); }
1845 break;
1846
1847 case 27:
1848
1849 /* Line 1464 of yacc.c */
1850 #line 215 "calc.y"
1851 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) == 0); }
1852 break;
1853
1854 case 28:
1855
1856 /* Line 1464 of yacc.c */
1857 #line 216 "calc.y"
1858 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) != 0); }
1859 break;
1860
1861 case 29:
1862
1863 /* Line 1464 of yacc.c */
1864 #line 217 "calc.y"
1865 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) >= 0); }
1866 break;
1867
1868 case 30:
1869
1870 /* Line 1464 of yacc.c */
1871 #line 218 "calc.y"
1872 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) > 0); }
1873 break;
1874
1875 case 31:
1876
1877 /* Line 1464 of yacc.c */
1878 #line 220 "calc.y"
1879 { sp--; mpz_set_ui (sp, mpz_sgn (sp) && mpz_sgn (sp+1)); }
1880 break;
1881
1882 case 32:
1883
1884 /* Line 1464 of yacc.c */
1885 #line 221 "calc.y"
1886 { sp--; mpz_set_ui (sp, mpz_sgn (sp) || mpz_sgn (sp+1)); }
1887 break;
1888
1889 case 33:
1890
1891 /* Line 1464 of yacc.c */
1892 #line 223 "calc.y"
1893 { mpz_abs (sp, sp); }
1894 break;
1895
1896 case 34:
1897
1898 /* Line 1464 of yacc.c */
1899 #line 224 "calc.y"
1900 { sp--; CHECK_UI ("Binomial base", sp+1);
1901 mpz_bin_ui (sp, sp, mpz_get_ui (sp+1)); }
1902 break;
1903
1904 case 35:
1905
1906 /* Line 1464 of yacc.c */
1907 #line 226 "calc.y"
1908 { CHECK_UI ("Fibonacci", sp);
1909 mpz_fib_ui (sp, mpz_get_ui (sp)); }
1910 break;
1911
1912 case 37:
1913
1914 /* Line 1464 of yacc.c */
1915 #line 229 "calc.y"
1916 { sp--; mpz_set_si (sp,
1917 mpz_kronecker (sp, sp+1)); }
1918 break;
1919
1920 case 39:
1921
1922 /* Line 1464 of yacc.c */
1923 #line 232 "calc.y"
1924 { CHECK_UI ("Lucas number", sp);
1925 mpz_lucnum_ui (sp, mpz_get_ui (sp)); }
1926 break;
1927
1928 case 40:
1929
1930 /* Line 1464 of yacc.c */
1931 #line 234 "calc.y"
1932 { mpz_nextprime (sp, sp); }
1933 break;
1934
1935 case 41:
1936
1937 /* Line 1464 of yacc.c */
1938 #line 235 "calc.y"
1939 { sp -= 2; mpz_powm (sp, sp, sp+1, sp+2); }
1940 break;
1941
1942 case 42:
1943
1944 /* Line 1464 of yacc.c */
1945 #line 236 "calc.y"
1946 { sp--; CHECK_UI ("Nth-root", sp+1);
1947 mpz_root (sp, sp, mpz_get_ui (sp+1)); }
1948 break;
1949
1950 case 43:
1951
1952 /* Line 1464 of yacc.c */
1953 #line 238 "calc.y"
1954 { mpz_sqrt (sp, sp); }
1955 break;
1956
1957 case 44:
1958
1959 /* Line 1464 of yacc.c */
1960 #line 240 "calc.y"
1961 {
1962 sp++;
1963 CHECK_OVERFLOW ();
1964 CHECK_VARIABLE ((yyvsp[(1) - (1)].var));
1965 mpz_set (sp, variable[(yyvsp[(1) - (1)].var)]);
1966 }
1967 break;
1968
1969 case 45:
1970
1971 /* Line 1464 of yacc.c */
1972 #line 246 "calc.y"
1973 {
1974 sp++;
1975 CHECK_OVERFLOW ();
1976 if (mpz_set_str (sp, (yyvsp[(1) - (1)].str), ibase) != 0)
1977 {
1978 fprintf (stderr, "Invalid number: %s\n", (yyvsp[(1) - (1)].str));
1979 YYERROR;
1980 }
1981 }
1982 break;
1983
1984 case 47:
1985
1986 /* Line 1464 of yacc.c */
1987 #line 258 "calc.y"
1988 { sp--; mpz_gcd (sp, sp, sp+1); }
1989 break;
1990
1991 case 49:
1992
1993 /* Line 1464 of yacc.c */
1994 #line 262 "calc.y"
1995 { sp--; mpz_lcm (sp, sp, sp+1); }
1996 break;
1997
1998
1999
2000 /* Line 1464 of yacc.c */
2001 #line 2000 "calc.c"
2002 default: break;
2003 }
2004 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2005
2006 YYPOPSTACK (yylen);
2007 yylen = 0;
2008 YY_STACK_PRINT (yyss, yyssp);
2009
2010 *++yyvsp = yyval;
2011
2012 /* Now `shift' the result of the reduction. Determine what state
2013 that goes to, based on the state we popped back to and the rule
2014 number reduced by. */
2015
2016 yyn = yyr1[yyn];
2017
2018 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2019 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2020 yystate = yytable[yystate];
2021 else
2022 yystate = yydefgoto[yyn - YYNTOKENS];
2023
2024 goto yynewstate;
2025
2026
2027 /*------------------------------------.
2028 | yyerrlab -- here on detecting error |
2029 `------------------------------------*/
2030 yyerrlab:
2031 /* If not already recovering from an error, report this error. */
2032 if (!yyerrstatus)
2033 {
2034 ++yynerrs;
2035 #if ! YYERROR_VERBOSE
2036 yyerror (YY_("syntax error"));
2037 #else
2038 {
2039 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2040 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2041 {
2042 YYSIZE_T yyalloc = 2 * yysize;
2043 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2044 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2045 if (yymsg != yymsgbuf)
2046 YYSTACK_FREE (yymsg);
2047 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2048 if (yymsg)
2049 yymsg_alloc = yyalloc;
2050 else
2051 {
2052 yymsg = yymsgbuf;
2053 yymsg_alloc = sizeof yymsgbuf;
2054 }
2055 }
2056
2057 if (0 < yysize && yysize <= yymsg_alloc)
2058 {
2059 (void) yysyntax_error (yymsg, yystate, yychar);
2060 yyerror (yymsg);
2061 }
2062 else
2063 {
2064 yyerror (YY_("syntax error"));
2065 if (yysize != 0)
2066 goto yyexhaustedlab;
2067 }
2068 }
2069 #endif
2070 }
2071
2072
2073
2074 if (yyerrstatus == 3)
2075 {
2076 /* If just tried and failed to reuse lookahead token after an
2077 error, discard it. */
2078
2079 if (yychar <= YYEOF)
2080 {
2081 /* Return failure if at end of input. */
2082 if (yychar == YYEOF)
2083 YYABORT;
2084 }
2085 else
2086 {
2087 yydestruct ("Error: discarding",
2088 yytoken, &yylval);
2089 yychar = YYEMPTY;
2090 }
2091 }
2092
2093 /* Else will try to reuse lookahead token after shifting the error
2094 token. */
2095 goto yyerrlab1;
2096
2097
2098 /*---------------------------------------------------.
2099 | yyerrorlab -- error raised explicitly by YYERROR. |
2100 `---------------------------------------------------*/
2101 yyerrorlab:
2102
2103 /* Pacify compilers like GCC when the user code never invokes
2104 YYERROR and the label yyerrorlab therefore never appears in user
2105 code. */
2106 if (/*CONSTCOND*/ 0)
2107 goto yyerrorlab;
2108
2109 /* Do not reclaim the symbols of the rule which action triggered
2110 this YYERROR. */
2111 YYPOPSTACK (yylen);
2112 yylen = 0;
2113 YY_STACK_PRINT (yyss, yyssp);
2114 yystate = *yyssp;
2115 goto yyerrlab1;
2116
2117
2118 /*-------------------------------------------------------------.
2119 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2120 `-------------------------------------------------------------*/
2121 yyerrlab1:
2122 yyerrstatus = 3; /* Each real token shifted decrements this. */
2123
2124 for (;;)
2125 {
2126 yyn = yypact[yystate];
2127 if (yyn != YYPACT_NINF)
2128 {
2129 yyn += YYTERROR;
2130 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2131 {
2132 yyn = yytable[yyn];
2133 if (0 < yyn)
2134 break;
2135 }
2136 }
2137
2138 /* Pop the current state because it cannot handle the error token. */
2139 if (yyssp == yyss)
2140 YYABORT;
2141
2142
2143 yydestruct ("Error: popping",
2144 yystos[yystate], yyvsp);
2145 YYPOPSTACK (1);
2146 yystate = *yyssp;
2147 YY_STACK_PRINT (yyss, yyssp);
2148 }
2149
2150 *++yyvsp = yylval;
2151
2152
2153 /* Shift the error token. */
2154 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2155
2156 yystate = yyn;
2157 goto yynewstate;
2158
2159
2160 /*-------------------------------------.
2161 | yyacceptlab -- YYACCEPT comes here. |
2162 `-------------------------------------*/
2163 yyacceptlab:
2164 yyresult = 0;
2165 goto yyreturn;
2166
2167 /*-----------------------------------.
2168 | yyabortlab -- YYABORT comes here. |
2169 `-----------------------------------*/
2170 yyabortlab:
2171 yyresult = 1;
2172 goto yyreturn;
2173
2174 #if !defined(yyoverflow) || YYERROR_VERBOSE
2175 /*-------------------------------------------------.
2176 | yyexhaustedlab -- memory exhaustion comes here. |
2177 `-------------------------------------------------*/
2178 yyexhaustedlab:
2179 yyerror (YY_("memory exhausted"));
2180 yyresult = 2;
2181 /* Fall through. */
2182 #endif
2183
2184 yyreturn:
2185 if (yychar != YYEMPTY)
2186 yydestruct ("Cleanup: discarding lookahead",
2187 yytoken, &yylval);
2188 /* Do not reclaim the symbols of the rule which action triggered
2189 this YYABORT or YYACCEPT. */
2190 YYPOPSTACK (yylen);
2191 YY_STACK_PRINT (yyss, yyssp);
2192 while (yyssp != yyss)
2193 {
2194 yydestruct ("Cleanup: popping",
2195 yystos[*yyssp], yyvsp);
2196 YYPOPSTACK (1);
2197 }
2198 #ifndef yyoverflow
2199 if (yyss != yyssa)
2200 YYSTACK_FREE (yyss);
2201 #endif
2202 #if YYERROR_VERBOSE
2203 if (yymsg != yymsgbuf)
2204 YYSTACK_FREE (yymsg);
2205 #endif
2206 /* Make sure YYID is used. */
2207 return YYID (yyresult);
2208 }
2209
2210
2211
2212 /* Line 1684 of yacc.c */
2213 #line 264 "calc.y"
2214
2215
2216 yyerror (char *s)
2217 {
2218 fprintf (stderr, "%s\n", s);
2219 }
2220
2221 int calc_option_readline = -1;
2222
2223 int
2224 main (int argc, char *argv[])
2225 {
2226 int i;
2227
2228 for (i = 1; i < argc; i++)
2229 {
2230 if (strcmp (argv[i], "--readline") == 0)
2231 calc_option_readline = 1;
2232 else if (strcmp (argv[i], "--noreadline") == 0)
2233 calc_option_readline = 0;
2234 else if (strcmp (argv[i], "--help") == 0)
2235 {
2236 printf ("Usage: calc [--option]...\n");
2237 printf (" --readline use readline\n");
2238 printf (" --noreadline don't use readline\n");
2239 printf (" --help this message\n");
2240 printf ("Readline is only available when compiled in,\n");
2241 printf ("and in that case it's the default on a tty.\n");
2242 exit (0);
2243 }
2244 else
2245 {
2246 fprintf (stderr, "Unrecognised option: %s\n", argv[i]);
2247 exit (1);
2248 }
2249 }
2250
2251 #if WITH_READLINE
2252 calc_init_readline ();
2253 #else
2254 if (calc_option_readline == 1)
2255 {
2256 fprintf (stderr, "Readline support not available\n");
2257 exit (1);
2258 }
2259 #endif
2260
2261 for (i = 0; i < numberof (variable); i++)
2262 mpz_init (variable[i]);
2263
2264 for (i = 0; i < numberof (stack); i++)
2265 mpz_init (stack[i]);
2266
2267 return yyparse ();
2268 }
2269
2270