blob: cc653a21d72a7d1cc473be28a7b4ffa3125310f0 [file] [log] [blame]
Austin Schuhbb1338c2024-06-15 19:31:16 -07001/* original parser id follows */
2/* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
3/* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
4
5#define YYBYACC 1
6#define YYMAJOR 1
7#define YYMINOR 9
8#define YYPATCH 20170201
9
10#define YYEMPTY (-1)
11#define yyclearin (yychar = YYEMPTY)
12#define yyerrok (yyerrflag = 0)
13#define YYRECOVERING() (yyerrflag != 0)
14#define YYENOMEM (-2)
15#define YYEOF 0
16#define YYPREFIX "yy"
17
18#define YYPURE 0
19
20#line 2 "../../../gmp/demos/calc/calc.y"
21/* A simple integer desk calculator using yacc and gmp.
22
23Copyright 2000-2002 Free Software Foundation, Inc.
24
25This file is part of the GNU MP Library.
26
27This program is free software; you can redistribute it and/or modify it under
28the terms of the GNU General Public License as published by the Free Software
29Foundation; either version 3 of the License, or (at your option) any later
30version.
31
32This program is distributed in the hope that it will be useful, but WITHOUT ANY
33WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
34PARTICULAR PURPOSE. See the GNU General Public License for more details.
35
36You should have received a copy of the GNU General Public License along with
37this program. If not, see https://www.gnu.org/licenses/. */
38
39
40/* This is a simple program, meant only to show one way to use GMP for this
41 sort of thing. There's few features, and error checking is minimal.
42 Standard input is read, calc_help() below shows the inputs accepted.
43
44 Expressions are evaluated as they're read. If user defined functions
45 were wanted it'd be necessary to build a parse tree like pexpr.c does, or
46 a list of operations for a stack based evaluator. That would also make
47 it possible to detect and optimize evaluations "mod m" like pexpr.c does.
48
49 A stack is used for intermediate values in the expression evaluation,
50 separate from the yacc parser stack. This is simple, makes error
51 recovery easy, minimizes the junk around mpz calls in the rules, and
52 saves initializing or clearing "mpz_t"s during a calculation. A
53 disadvantage though is that variables must be copied to the stack to be
54 worked on. A more sophisticated calculator or language system might be
55 able to avoid that when executing a compiled or semi-compiled form.
56
57 Avoiding repeated initializing and clearing of "mpz_t"s is important. In
58 this program the time spent parsing is obviously much greater than any
59 possible saving from this, but a proper calculator or language should
60 take some trouble over it. Don't be surprised if an init/clear takes 3
61 or more times as long as a 10 limb addition, depending on the system (see
62 the mpz_init_realloc_clear example in tune/README). */
63
64
65#include <stdio.h>
66#include <stdlib.h>
67#include <string.h>
68#include "gmp.h"
69#define NO_CALC_H /* because it conflicts with normal calc.c stuff */
70#include "calc-common.h"
71
72
73#define numberof(x) (sizeof (x) / sizeof ((x)[0]))
74
75
76void
77calc_help (void)
78{
79 printf ("Examples:\n");
80 printf (" 2+3*4 expressions are evaluated\n");
81 printf (" x=5^6 variables a to z can be set and used\n");
82 printf ("Operators:\n");
83 printf (" + - * arithmetic\n");
84 printf (" / %% division and remainder (rounding towards negative infinity)\n");
85 printf (" ^ exponentiation\n");
86 printf (" ! factorial\n");
87 printf (" << >> left and right shifts\n");
88 printf (" <= >= > \\ comparisons, giving 1 if true, 0 if false\n");
89 printf (" == != < /\n");
90 printf (" && || logical and/or, giving 1 if true, 0 if false\n");
91 printf ("Functions:\n");
92 printf (" abs(n) absolute value\n");
93 printf (" bin(n,m) binomial coefficient\n");
94 printf (" fib(n) fibonacci number\n");
95 printf (" gcd(a,b,..) greatest common divisor\n");
96 printf (" kron(a,b) kronecker symbol\n");
97 printf (" lcm(a,b,..) least common multiple\n");
98 printf (" lucnum(n) lucas number\n");
99 printf (" nextprime(n) next prime after n\n");
100 printf (" powm(b,e,m) modulo powering, b^e%%m\n");
101 printf (" root(n,r) r-th root\n");
102 printf (" sqrt(n) square root\n");
103 printf ("Other:\n");
104 printf (" hex \\ set hex or decimal for input and output\n");
105 printf (" decimal / (\"0x\" can be used for hex too)\n");
106 printf (" quit exit program (EOF works too)\n");
107 printf (" ; statements are separated with a ; or newline\n");
108 printf (" \\ continue expressions with \\ before newline\n");
109 printf (" # xxx comments are # though to newline\n");
110 printf ("Hex numbers must be entered in upper case, to distinguish them from the\n");
111 printf ("variables a to f (like in bc).\n");
112}
113
114
115int ibase = 0;
116int obase = 10;
117
118
119/* The stack is a fixed size, which means there's a limit on the nesting
120 allowed in expressions. A more sophisticated program could let it grow
121 dynamically. */
122
123mpz_t stack[100];
124mpz_ptr sp = stack[0];
125
126#define CHECK_OVERFLOW() \
127 if (sp >= stack[numberof(stack)]) /* FIXME */ \
128 { \
129 fprintf (stderr, \
130 "Value stack overflow, too much nesting in expression\n"); \
131 YYERROR; \
132 }
133
134#define CHECK_EMPTY() \
135 if (sp != stack[0]) \
136 { \
137 fprintf (stderr, "Oops, expected the value stack to be empty\n"); \
138 sp = stack[0]; \
139 }
140
141
142mpz_t variable[26];
143
144#define CHECK_VARIABLE(var) \
145 if ((var) < 0 || (var) >= numberof (variable)) \
146 { \
147 fprintf (stderr, "Oops, bad variable somehow: %d\n", var); \
148 YYERROR; \
149 }
150
151
152#define CHECK_UI(name,z) \
153 if (! mpz_fits_ulong_p (z)) \
154 { \
155 fprintf (stderr, "%s too big\n", name); \
156 YYERROR; \
157 }
158
159#ifdef YYSTYPE
160#undef YYSTYPE_IS_DECLARED
161#define YYSTYPE_IS_DECLARED 1
162#endif
163#ifndef YYSTYPE_IS_DECLARED
164#define YYSTYPE_IS_DECLARED 1
165#line 142 "../../../gmp/demos/calc/calc.y"
166typedef union {
167 char *str;
168 int var;
169} YYSTYPE;
170#endif /* !YYSTYPE_IS_DECLARED */
171#line 172 "calc.c"
172
173/* compatibility with bison */
174#ifdef YYPARSE_PARAM
175/* compatibility with FreeBSD */
176# ifdef YYPARSE_PARAM_TYPE
177# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
178# else
179# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
180# endif
181#else
182# define YYPARSE_DECL() yyparse(void)
183#endif
184
185/* Parameters sent to lex. */
186#ifdef YYLEX_PARAM
187# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
188# define YYLEX yylex(YYLEX_PARAM)
189#else
190# define YYLEX_DECL() yylex(void)
191# define YYLEX yylex()
192#endif
193
194/* Parameters sent to yyerror. */
195#ifndef YYERROR_DECL
196#define YYERROR_DECL() yyerror(const char *s)
197#endif
198#ifndef YYERROR_CALL
199#define YYERROR_CALL(msg) yyerror(msg)
200#endif
201
202extern int YYPARSE_DECL();
203
204#define EOS 257
205#define BAD 258
206#define HELP 259
207#define HEX 260
208#define DECIMAL 261
209#define QUIT 262
210#define ABS 263
211#define BIN 264
212#define FIB 265
213#define GCD 266
214#define KRON 267
215#define LCM 268
216#define LUCNUM 269
217#define NEXTPRIME 270
218#define POWM 271
219#define ROOT 272
220#define SQRT 273
221#define NUMBER 274
222#define VARIABLE 275
223#define LOR 276
224#define LAND 277
225#define EQ 278
226#define NE 279
227#define LE 280
228#define GE 281
229#define LSHIFT 282
230#define RSHIFT 283
231#define UMINUS 284
232#define YYERRCODE 256
233typedef int YYINT;
234static const YYINT yylhs[] = { -1,
235 0, 0, 2, 2, 2, 1, 1, 1, 1, 1,
236 1, 1, 3, 3, 3, 3, 3, 3, 3, 3,
237 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
238 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
239 3, 3, 3, 3, 4, 4, 5, 5,
240};
241static const YYINT yylen[] = { 2,
242 1, 2, 2, 3, 2, 0, 1, 3, 1, 1,
243 1, 1, 3, 3, 3, 3, 3, 3, 3, 3,
244 3, 2, 2, 3, 3, 3, 3, 3, 3, 3,
245 3, 4, 6, 4, 4, 6, 4, 4, 4, 8,
246 6, 4, 1, 1, 1, 3, 1, 3,
247};
248static const YYINT yydefred[] = { 0,
249 0, 9, 10, 11, 12, 0, 0, 0, 0, 0,
250 0, 0, 0, 0, 0, 0, 44, 0, 0, 0,
251 0, 0, 0, 0, 5, 0, 0, 0, 0, 0,
252 0, 0, 0, 0, 0, 0, 0, 43, 0, 0,
253 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
254 0, 0, 0, 0, 0, 0, 0, 0, 22, 0,
255 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
256 0, 0, 0, 13, 4, 0, 0, 0, 0, 0,
257 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
258 0, 32, 0, 34, 35, 0, 0, 37, 0, 38,
259 39, 0, 0, 42, 0, 0, 0, 0, 0, 0,
260 33, 36, 0, 41, 0, 40,
261};
262static const YYINT yydgoto[] = { 21,
263 22, 23, 24, 64, 67,
264};
265static const YYINT yysindex[] = { 742,
266 -257, 0, 0, 0, 0, -22, -20, -17, -5, 5,
267 18, 20, 22, 25, 28, 29, 0, -54, 808, 808,
268 0, -244, 786, 667, 0, 808, 808, 808, 808, 808,
269 808, 808, 808, 808, 808, 808, 808, 0, -27, 203,
270 0, -217, 808, 808, 808, 808, 808, 808, 808, 808,
271 808, 808, 808, 808, 808, 808, 808, 808, 0, 454,
272 465, 487, 667, -33, 498, 667, -16, 520, 531, 542,
273 564, 586, 667, 0, 0, 678, 929, -28, -28, -28,
274 -28, -28, -28, -21, -21, -6, -6, -27, -27, -27,
275 -27, 0, 808, 0, 0, 808, 808, 0, 808, 0,
276 0, 808, 808, 0, 597, 667, 608, 667, 619, 645,
277 0, 0, 808, 0, 656, 0,
278};
279static const YYINT yyrindex[] = { 2,
280 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
281 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
282 0, 50, 2, 3, 0, 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0, 10, 0,
284 0, 71, 0, 0, 0, 0, 0, 0, 0, 0,
285 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
286 0, 0, -12, 0, 0, -11, 0, 0, 0, 0,
287 0, 0, 4, 0, 0, 193, 64, 166, 178, 182,
288 187, 189, 191, 139, 151, 112, 124, 37, 49, 76,
289 85, 0, 0, 0, 0, 0, 0, 0, 0, 0,
290 0, 0, 0, 0, 0, -2, 0, 15, 0, 0,
291 0, 0, 0, 0, 0, 0,
292};
293static const YYINT yygindex[] = { 0,
294 52, 0, 1065, 0, 0,
295};
296#define YYTABLESIZE 1212
297static const YYINT yytable[] = { 25,
298 43, 6, 7, 8, 59, 59, 37, 95, 57, 23,
299 96, 59, 41, 55, 53, 57, 54, 26, 56, 27,
300 55, 53, 28, 54, 98, 56, 59, 99, 45, 47,
301 57, 45, 47, 43, 29, 55, 16, 43, 46, 75,
302 56, 46, 43, 43, 30, 43, 23, 43, 17, 1,
303 23, 23, 23, 23, 23, 48, 23, 31, 48, 32,
304 43, 33, 43, 30, 34, 58, 58, 35, 36, 23,
305 2, 23, 58, 16, 42, 18, 0, 16, 16, 16,
306 16, 16, 0, 16, 19, 17, 0, 58, 0, 17,
307 17, 17, 17, 17, 43, 17, 16, 0, 16, 0,
308 0, 0, 0, 0, 30, 0, 0, 30, 17, 0,
309 17, 14, 18, 0, 0, 0, 18, 18, 18, 18,
310 18, 19, 18, 15, 0, 19, 19, 19, 19, 19,
311 0, 19, 0, 0, 0, 18, 0, 18, 20, 0,
312 0, 0, 0, 0, 19, 0, 19, 0, 0, 0,
313 21, 0, 14, 0, 14, 14, 14, 0, 0, 0,
314 0, 0, 0, 0, 15, 24, 15, 15, 15, 0,
315 0, 14, 0, 14, 0, 0, 0, 29, 0, 20,
316 0, 26, 20, 15, 0, 15, 27, 0, 25, 0,
317 28, 21, 31, 0, 21, 0, 0, 0, 20, 0,
318 20, 0, 0, 0, 0, 0, 24, 0, 0, 24,
319 21, 0, 21, 0, 0, 0, 0, 0, 29, 0,
320 0, 29, 26, 0, 0, 26, 0, 27, 0, 25,
321 27, 28, 25, 31, 28, 59, 31, 0, 0, 57,
322 0, 0, 0, 74, 55, 53, 0, 54, 0, 56,
323 0, 0, 0, 51, 52, 0, 0, 43, 6, 7,
324 8, 0, 45, 0, 46, 0, 23, 0, 0, 0,
325 0, 0, 0, 0, 0, 0, 43, 43, 43, 43,
326 43, 43, 43, 43, 0, 23, 23, 23, 23, 23,
327 23, 23, 23, 16, 0, 0, 58, 0, 0, 0,
328 0, 0, 0, 0, 0, 17, 0, 0, 0, 0,
329 0, 0, 16, 16, 16, 16, 16, 16, 16, 16,
330 30, 0, 0, 0, 17, 17, 17, 17, 17, 17,
331 17, 17, 18, 0, 0, 0, 0, 0, 0, 30,
332 30, 19, 0, 0, 0, 0, 0, 0, 0, 0,
333 0, 18, 18, 18, 18, 18, 18, 18, 18, 0,
334 19, 19, 19, 19, 19, 19, 19, 19, 14, 0,
335 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
336 15, 0, 0, 0, 0, 0, 0, 14, 14, 14,
337 14, 14, 14, 14, 14, 20, 0, 0, 0, 15,
338 15, 15, 15, 15, 15, 15, 15, 21, 0, 0,
339 0, 0, 0, 0, 20, 20, 20, 20, 20, 20,
340 20, 20, 24, 0, 0, 0, 21, 21, 21, 21,
341 21, 21, 21, 21, 29, 0, 0, 0, 26, 0,
342 0, 24, 24, 27, 0, 25, 0, 28, 0, 31,
343 0, 0, 0, 29, 29, 0, 0, 26, 26, 0,
344 0, 0, 27, 27, 25, 25, 28, 28, 31, 0,
345 0, 0, 0, 0, 0, 0, 0, 0, 43, 44,
346 47, 48, 49, 50, 51, 52, 59, 0, 0, 0,
347 57, 0, 0, 0, 92, 55, 53, 59, 54, 0,
348 56, 57, 0, 0, 0, 0, 55, 53, 93, 54,
349 0, 56, 0, 45, 0, 46, 0, 0, 0, 59,
350 0, 0, 0, 57, 45, 0, 46, 94, 55, 53,
351 59, 54, 0, 56, 57, 0, 0, 0, 0, 55,
352 53, 97, 54, 0, 56, 0, 45, 58, 46, 0,
353 0, 0, 59, 0, 0, 0, 57, 45, 58, 46,
354 100, 55, 53, 59, 54, 0, 56, 57, 0, 0,
355 0, 101, 55, 53, 59, 54, 0, 56, 57, 45,
356 58, 46, 0, 55, 53, 102, 54, 0, 56, 0,
357 45, 58, 46, 0, 0, 0, 59, 0, 0, 0,
358 57, 45, 0, 46, 0, 55, 53, 103, 54, 0,
359 56, 0, 0, 58, 0, 0, 0, 0, 59, 0,
360 0, 0, 57, 45, 58, 46, 104, 55, 53, 59,
361 54, 0, 56, 57, 0, 58, 0, 111, 55, 53,
362 59, 54, 0, 56, 57, 45, 0, 46, 112, 55,
363 53, 59, 54, 0, 56, 57, 45, 58, 46, 0,
364 55, 53, 113, 54, 0, 56, 0, 45, 0, 46,
365 0, 0, 0, 0, 0, 0, 0, 59, 45, 58,
366 46, 57, 0, 0, 0, 114, 55, 53, 59, 54,
367 58, 56, 57, 0, 0, 0, 116, 55, 53, 59,
368 54, 58, 56, 57, 45, 0, 46, 0, 55, 53,
369 59, 54, 58, 56, 57, 45, 0, 46, 0, 55,
370 53, 0, 54, 0, 56, 0, 45, 0, 46, 43,
371 44, 47, 48, 49, 50, 51, 52, 45, 58, 46,
372 43, 44, 47, 48, 49, 50, 51, 52, 0, 58,
373 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
374 58, 0, 43, 44, 47, 48, 49, 50, 51, 52,
375 0, 58, 0, 43, 44, 47, 48, 49, 50, 51,
376 52, 20, 0, 0, 0, 0, 19, 0, 0, 0,
377 0, 0, 0, 0, 0, 43, 44, 47, 48, 49,
378 50, 51, 52, 0, 0, 0, 43, 44, 47, 48,
379 49, 50, 51, 52, 0, 0, 0, 43, 44, 47,
380 48, 49, 50, 51, 52, 20, 0, 0, 0, 0,
381 19, 0, 0, 0, 0, 0, 0, 0, 0, 43,
382 44, 47, 48, 49, 50, 51, 52, 20, 0, 0,
383 0, 0, 19, 0, 0, 0, 0, 0, 0, 0,
384 0, 43, 44, 47, 48, 49, 50, 51, 52, 0,
385 0, 0, 43, 44, 47, 48, 49, 50, 51, 52,
386 0, 0, 0, 43, 44, 47, 48, 49, 50, 51,
387 52, 0, 0, 0, 43, 44, 47, 48, 49, 50,
388 51, 52, 0, 0, 0, 0, 0, 0, 0, 0,
389 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
390 43, 44, 47, 48, 49, 50, 51, 52, 0, 0,
391 0, 43, 44, 47, 48, 49, 50, 51, 52, 0,
392 0, 0, 43, 44, 47, 48, 49, 50, 51, 52,
393 0, 0, 0, 0, 44, 47, 48, 49, 50, 51,
394 52, 59, 0, 0, 0, 57, 0, 0, 0, 0,
395 55, 53, 0, 54, 0, 56, 0, 0, 0, 0,
396 0, 0, 0, 0, 0, 0, 0, 0, 45, 0,
397 46, 0, 0, 0, 0, 0, 0, 1, 0, 0,
398 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
399 12, 13, 14, 15, 16, 17, 18, 0, 0, 0,
400 0, 0, 58, 0, 0, 0, 0, 0, 0, 0,
401 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
402 0, 0, 0, 0, 2, 3, 4, 5, 6, 7,
403 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
404 18, 0, 0, 0, 0, 0, 0, 0, 0, 0,
405 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
406 16, 17, 38, 39, 40, 0, 0, 0, 0, 0,
407 60, 61, 62, 63, 65, 66, 68, 69, 70, 71,
408 72, 73, 0, 0, 0, 0, 0, 76, 77, 78,
409 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
410 89, 90, 91, 0, 0, 0, 0, 0, 0, 0,
411 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
412 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
413 0, 0, 0, 0, 0, 0, 0, 105, 0, 0,
414 106, 107, 0, 108, 0, 0, 109, 110, 0, 0,
415 0, 0, 0, 0, 0, 0, 0, 115, 0, 0,
416 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
417 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
418 0, 0, 0, 0, 0, 0, 47, 48, 49, 50,
419 51, 52,
420};
421static const YYINT yycheck[] = { 257,
422 0, 0, 0, 0, 33, 33, 61, 41, 37, 0,
423 44, 33, 257, 42, 43, 37, 45, 40, 47, 40,
424 42, 43, 40, 45, 41, 47, 33, 44, 41, 41,
425 37, 44, 44, 33, 40, 42, 0, 37, 41, 257,
426 47, 44, 42, 43, 40, 45, 37, 47, 0, 0,
427 41, 42, 43, 44, 45, 41, 47, 40, 44, 40,
428 60, 40, 62, 0, 40, 94, 94, 40, 40, 60,
429 0, 62, 94, 37, 23, 0, -1, 41, 42, 43,
430 44, 45, -1, 47, 0, 37, -1, 94, -1, 41,
431 42, 43, 44, 45, 94, 47, 60, -1, 62, -1,
432 -1, -1, -1, -1, 41, -1, -1, 44, 60, -1,
433 62, 0, 37, -1, -1, -1, 41, 42, 43, 44,
434 45, 37, 47, 0, -1, 41, 42, 43, 44, 45,
435 -1, 47, -1, -1, -1, 60, -1, 62, 0, -1,
436 -1, -1, -1, -1, 60, -1, 62, -1, -1, -1,
437 0, -1, 41, -1, 43, 44, 45, -1, -1, -1,
438 -1, -1, -1, -1, 41, 0, 43, 44, 45, -1,
439 -1, 60, -1, 62, -1, -1, -1, 0, -1, 41,
440 -1, 0, 44, 60, -1, 62, 0, -1, 0, -1,
441 0, 41, 0, -1, 44, -1, -1, -1, 60, -1,
442 62, -1, -1, -1, -1, -1, 41, -1, -1, 44,
443 60, -1, 62, -1, -1, -1, -1, -1, 41, -1,
444 -1, 44, 41, -1, -1, 44, -1, 41, -1, 41,
445 44, 41, 44, 41, 44, 33, 44, -1, -1, 37,
446 -1, -1, -1, 41, 42, 43, -1, 45, -1, 47,
447 -1, -1, -1, 282, 283, -1, -1, 257, 257, 257,
448 257, -1, 60, -1, 62, -1, 257, -1, -1, -1,
449 -1, -1, -1, -1, -1, -1, 276, 277, 278, 279,
450 280, 281, 282, 283, -1, 276, 277, 278, 279, 280,
451 281, 282, 283, 257, -1, -1, 94, -1, -1, -1,
452 -1, -1, -1, -1, -1, 257, -1, -1, -1, -1,
453 -1, -1, 276, 277, 278, 279, 280, 281, 282, 283,
454 257, -1, -1, -1, 276, 277, 278, 279, 280, 281,
455 282, 283, 257, -1, -1, -1, -1, -1, -1, 276,
456 277, 257, -1, -1, -1, -1, -1, -1, -1, -1,
457 -1, 276, 277, 278, 279, 280, 281, 282, 283, -1,
458 276, 277, 278, 279, 280, 281, 282, 283, 257, -1,
459 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
460 257, -1, -1, -1, -1, -1, -1, 276, 277, 278,
461 279, 280, 281, 282, 283, 257, -1, -1, -1, 276,
462 277, 278, 279, 280, 281, 282, 283, 257, -1, -1,
463 -1, -1, -1, -1, 276, 277, 278, 279, 280, 281,
464 282, 283, 257, -1, -1, -1, 276, 277, 278, 279,
465 280, 281, 282, 283, 257, -1, -1, -1, 257, -1,
466 -1, 276, 277, 257, -1, 257, -1, 257, -1, 257,
467 -1, -1, -1, 276, 277, -1, -1, 276, 277, -1,
468 -1, -1, 276, 277, 276, 277, 276, 277, 276, -1,
469 -1, -1, -1, -1, -1, -1, -1, -1, 276, 277,
470 278, 279, 280, 281, 282, 283, 33, -1, -1, -1,
471 37, -1, -1, -1, 41, 42, 43, 33, 45, -1,
472 47, 37, -1, -1, -1, -1, 42, 43, 44, 45,
473 -1, 47, -1, 60, -1, 62, -1, -1, -1, 33,
474 -1, -1, -1, 37, 60, -1, 62, 41, 42, 43,
475 33, 45, -1, 47, 37, -1, -1, -1, -1, 42,
476 43, 44, 45, -1, 47, -1, 60, 94, 62, -1,
477 -1, -1, 33, -1, -1, -1, 37, 60, 94, 62,
478 41, 42, 43, 33, 45, -1, 47, 37, -1, -1,
479 -1, 41, 42, 43, 33, 45, -1, 47, 37, 60,
480 94, 62, -1, 42, 43, 44, 45, -1, 47, -1,
481 60, 94, 62, -1, -1, -1, 33, -1, -1, -1,
482 37, 60, -1, 62, -1, 42, 43, 44, 45, -1,
483 47, -1, -1, 94, -1, -1, -1, -1, 33, -1,
484 -1, -1, 37, 60, 94, 62, 41, 42, 43, 33,
485 45, -1, 47, 37, -1, 94, -1, 41, 42, 43,
486 33, 45, -1, 47, 37, 60, -1, 62, 41, 42,
487 43, 33, 45, -1, 47, 37, 60, 94, 62, -1,
488 42, 43, 44, 45, -1, 47, -1, 60, -1, 62,
489 -1, -1, -1, -1, -1, -1, -1, 33, 60, 94,
490 62, 37, -1, -1, -1, 41, 42, 43, 33, 45,
491 94, 47, 37, -1, -1, -1, 41, 42, 43, 33,
492 45, 94, 47, 37, 60, -1, 62, -1, 42, 43,
493 33, 45, 94, 47, 37, 60, -1, 62, -1, 42,
494 43, -1, 45, -1, 47, -1, 60, -1, 62, 276,
495 277, 278, 279, 280, 281, 282, 283, 60, 94, 62,
496 276, 277, 278, 279, 280, 281, 282, 283, -1, 94,
497 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
498 94, -1, 276, 277, 278, 279, 280, 281, 282, 283,
499 -1, 94, -1, 276, 277, 278, 279, 280, 281, 282,
500 283, 40, -1, -1, -1, -1, 45, -1, -1, -1,
501 -1, -1, -1, -1, -1, 276, 277, 278, 279, 280,
502 281, 282, 283, -1, -1, -1, 276, 277, 278, 279,
503 280, 281, 282, 283, -1, -1, -1, 276, 277, 278,
504 279, 280, 281, 282, 283, 40, -1, -1, -1, -1,
505 45, -1, -1, -1, -1, -1, -1, -1, -1, 276,
506 277, 278, 279, 280, 281, 282, 283, 40, -1, -1,
507 -1, -1, 45, -1, -1, -1, -1, -1, -1, -1,
508 -1, 276, 277, 278, 279, 280, 281, 282, 283, -1,
509 -1, -1, 276, 277, 278, 279, 280, 281, 282, 283,
510 -1, -1, -1, 276, 277, 278, 279, 280, 281, 282,
511 283, -1, -1, -1, 276, 277, 278, 279, 280, 281,
512 282, 283, -1, -1, -1, -1, -1, -1, -1, -1,
513 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
514 276, 277, 278, 279, 280, 281, 282, 283, -1, -1,
515 -1, 276, 277, 278, 279, 280, 281, 282, 283, -1,
516 -1, -1, 276, 277, 278, 279, 280, 281, 282, 283,
517 -1, -1, -1, -1, 277, 278, 279, 280, 281, 282,
518 283, 33, -1, -1, -1, 37, -1, -1, -1, -1,
519 42, 43, -1, 45, -1, 47, -1, -1, -1, -1,
520 -1, -1, -1, -1, -1, -1, -1, -1, 60, -1,
521 62, -1, -1, -1, -1, -1, -1, 256, -1, -1,
522 259, 260, 261, 262, 263, 264, 265, 266, 267, 268,
523 269, 270, 271, 272, 273, 274, 275, -1, -1, -1,
524 -1, -1, 94, -1, -1, -1, -1, -1, -1, -1,
525 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
526 -1, -1, -1, -1, 259, 260, 261, 262, 263, 264,
527 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
528 275, -1, -1, -1, -1, -1, -1, -1, -1, -1,
529 263, 264, 265, 266, 267, 268, 269, 270, 271, 272,
530 273, 274, 275, 19, 20, -1, -1, -1, -1, -1,
531 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
532 36, 37, -1, -1, -1, -1, -1, 43, 44, 45,
533 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
534 56, 57, 58, -1, -1, -1, -1, -1, -1, -1,
535 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
536 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
537 -1, -1, -1, -1, -1, -1, -1, 93, -1, -1,
538 96, 97, -1, 99, -1, -1, 102, 103, -1, -1,
539 -1, -1, -1, -1, -1, -1, -1, 113, -1, -1,
540 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
541 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
542 -1, -1, -1, -1, -1, -1, 278, 279, 280, 281,
543 282, 283,
544};
545#define YYFINAL 21
546#ifndef YYDEBUG
547#define YYDEBUG 0
548#endif
549#define YYMAXTOKEN 284
550#define YYUNDFTOKEN 292
551#define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
552#if YYDEBUG
553static const char *const yyname[] = {
554
555"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
556"'!'",0,0,0,"'%'",0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,
5570,0,0,0,0,"'<'","'='","'>'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5580,0,0,0,0,"'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5590,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5600,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5610,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5620,0,0,0,0,0,0,0,0,0,"EOS","BAD","HELP","HEX","DECIMAL","QUIT","ABS","BIN","FIB",
563"GCD","KRON","LCM","LUCNUM","NEXTPRIME","POWM","ROOT","SQRT","NUMBER",
564"VARIABLE","LOR","LAND","EQ","NE","LE","GE","LSHIFT","RSHIFT","UMINUS",0,0,0,0,
5650,0,0,"illegal-symbol",
566};
567static const char *const yyrule[] = {
568"$accept : top",
569"top : statement",
570"top : statements statement",
571"statements : statement EOS",
572"statements : statements statement EOS",
573"statements : error EOS",
574"statement :",
575"statement : e",
576"statement : VARIABLE '=' e",
577"statement : HELP",
578"statement : HEX",
579"statement : DECIMAL",
580"statement : QUIT",
581"e : '(' e ')'",
582"e : e '+' e",
583"e : e '-' e",
584"e : e '*' e",
585"e : e '/' e",
586"e : e '%' e",
587"e : e '^' e",
588"e : e LSHIFT e",
589"e : e RSHIFT e",
590"e : e '!'",
591"e : '-' e",
592"e : e '<' e",
593"e : e LE e",
594"e : e EQ e",
595"e : e NE e",
596"e : e GE e",
597"e : e '>' e",
598"e : e LAND e",
599"e : e LOR e",
600"e : ABS '(' e ')'",
601"e : BIN '(' e ',' e ')'",
602"e : FIB '(' e ')'",
603"e : GCD '(' gcdlist ')'",
604"e : KRON '(' e ',' e ')'",
605"e : LCM '(' lcmlist ')'",
606"e : LUCNUM '(' e ')'",
607"e : NEXTPRIME '(' e ')'",
608"e : POWM '(' e ',' e ',' e ')'",
609"e : ROOT '(' e ',' e ')'",
610"e : SQRT '(' e ')'",
611"e : VARIABLE",
612"e : NUMBER",
613"gcdlist : e",
614"gcdlist : gcdlist ',' e",
615"lcmlist : e",
616"lcmlist : lcmlist ',' e",
617
618};
619#endif
620
621int yydebug;
622int yynerrs;
623
624int yyerrflag;
625int yychar;
626YYSTYPE yyval;
627YYSTYPE yylval;
628
629/* define the initial stack-sizes */
630#ifdef YYSTACKSIZE
631#undef YYMAXDEPTH
632#define YYMAXDEPTH YYSTACKSIZE
633#else
634#ifdef YYMAXDEPTH
635#define YYSTACKSIZE YYMAXDEPTH
636#else
637#define YYSTACKSIZE 10000
638#define YYMAXDEPTH 10000
639#endif
640#endif
641
642#define YYINITSTACKSIZE 200
643
644typedef struct {
645 unsigned stacksize;
646 YYINT *s_base;
647 YYINT *s_mark;
648 YYINT *s_last;
649 YYSTYPE *l_base;
650 YYSTYPE *l_mark;
651} YYSTACKDATA;
652/* variables for the parser stack */
653static YYSTACKDATA yystack;
654#line 265 "../../../gmp/demos/calc/calc.y"
655
656yyerror (char *s)
657{
658 fprintf (stderr, "%s\n", s);
659}
660
661int calc_option_readline = -1;
662
663int
664main (int argc, char *argv[])
665{
666 int i;
667
668 for (i = 1; i < argc; i++)
669 {
670 if (strcmp (argv[i], "--readline") == 0)
671 calc_option_readline = 1;
672 else if (strcmp (argv[i], "--noreadline") == 0)
673 calc_option_readline = 0;
674 else if (strcmp (argv[i], "--help") == 0)
675 {
676 printf ("Usage: calc [--option]...\n");
677 printf (" --readline use readline\n");
678 printf (" --noreadline don't use readline\n");
679 printf (" --help this message\n");
680 printf ("Readline is only available when compiled in,\n");
681 printf ("and in that case it's the default on a tty.\n");
682 exit (0);
683 }
684 else
685 {
686 fprintf (stderr, "Unrecognised option: %s\n", argv[i]);
687 exit (1);
688 }
689 }
690
691#if WITH_READLINE
692 calc_init_readline ();
693#else
694 if (calc_option_readline == 1)
695 {
696 fprintf (stderr, "Readline support not available\n");
697 exit (1);
698 }
699#endif
700
701 for (i = 0; i < numberof (variable); i++)
702 mpz_init (variable[i]);
703
704 for (i = 0; i < numberof (stack); i++)
705 mpz_init (stack[i]);
706
707 return yyparse ();
708}
709#line 710 "calc.c"
710
711#if YYDEBUG
712#include <stdio.h> /* needed for printf */
713#endif
714
715#include <stdlib.h> /* needed for malloc, etc */
716#include <string.h> /* needed for memset */
717
718/* allocate initial stack or double stack size, up to YYMAXDEPTH */
719static int yygrowstack(YYSTACKDATA *data)
720{
721 int i;
722 unsigned newsize;
723 YYINT *newss;
724 YYSTYPE *newvs;
725
726 if ((newsize = data->stacksize) == 0)
727 newsize = YYINITSTACKSIZE;
728 else if (newsize >= YYMAXDEPTH)
729 return YYENOMEM;
730 else if ((newsize *= 2) > YYMAXDEPTH)
731 newsize = YYMAXDEPTH;
732
733 i = (int) (data->s_mark - data->s_base);
734 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
735 if (newss == 0)
736 return YYENOMEM;
737
738 data->s_base = newss;
739 data->s_mark = newss + i;
740
741 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
742 if (newvs == 0)
743 return YYENOMEM;
744
745 data->l_base = newvs;
746 data->l_mark = newvs + i;
747
748 data->stacksize = newsize;
749 data->s_last = data->s_base + newsize - 1;
750 return 0;
751}
752
753#if YYPURE || defined(YY_NO_LEAKS)
754static void yyfreestack(YYSTACKDATA *data)
755{
756 free(data->s_base);
757 free(data->l_base);
758 memset(data, 0, sizeof(*data));
759}
760#else
761#define yyfreestack(data) /* nothing */
762#endif
763
764#define YYABORT goto yyabort
765#define YYREJECT goto yyabort
766#define YYACCEPT goto yyaccept
767#define YYERROR goto yyerrlab
768
769int
770YYPARSE_DECL()
771{
772 int yym, yyn, yystate;
773#if YYDEBUG
774 const char *yys;
775
776 if ((yys = getenv("YYDEBUG")) != 0)
777 {
778 yyn = *yys;
779 if (yyn >= '0' && yyn <= '9')
780 yydebug = yyn - '0';
781 }
782#endif
783
784 yym = 0;
785 yyn = 0;
786 yynerrs = 0;
787 yyerrflag = 0;
788 yychar = YYEMPTY;
789 yystate = 0;
790
791#if YYPURE
792 memset(&yystack, 0, sizeof(yystack));
793#endif
794
795 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
796 yystack.s_mark = yystack.s_base;
797 yystack.l_mark = yystack.l_base;
798 yystate = 0;
799 *yystack.s_mark = 0;
800
801yyloop:
802 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
803 if (yychar < 0)
804 {
805 yychar = YYLEX;
806 if (yychar < 0) yychar = YYEOF;
807#if YYDEBUG
808 if (yydebug)
809 {
810 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
811 printf("%sdebug: state %d, reading %d (%s)\n",
812 YYPREFIX, yystate, yychar, yys);
813 }
814#endif
815 }
816 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
817 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
818 {
819#if YYDEBUG
820 if (yydebug)
821 printf("%sdebug: state %d, shifting to state %d\n",
822 YYPREFIX, yystate, yytable[yyn]);
823#endif
824 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
825 yystate = yytable[yyn];
826 *++yystack.s_mark = yytable[yyn];
827 *++yystack.l_mark = yylval;
828 yychar = YYEMPTY;
829 if (yyerrflag > 0) --yyerrflag;
830 goto yyloop;
831 }
832 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
833 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
834 {
835 yyn = yytable[yyn];
836 goto yyreduce;
837 }
838 if (yyerrflag != 0) goto yyinrecovery;
839
840 YYERROR_CALL("syntax error");
841
842 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
843yyerrlab:
844 ++yynerrs;
845
846yyinrecovery:
847 if (yyerrflag < 3)
848 {
849 yyerrflag = 3;
850 for (;;)
851 {
852 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
853 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
854 {
855#if YYDEBUG
856 if (yydebug)
857 printf("%sdebug: state %d, error recovery shifting\
858 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
859#endif
860 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
861 yystate = yytable[yyn];
862 *++yystack.s_mark = yytable[yyn];
863 *++yystack.l_mark = yylval;
864 goto yyloop;
865 }
866 else
867 {
868#if YYDEBUG
869 if (yydebug)
870 printf("%sdebug: error recovery discarding state %d\n",
871 YYPREFIX, *yystack.s_mark);
872#endif
873 if (yystack.s_mark <= yystack.s_base) goto yyabort;
874 --yystack.s_mark;
875 --yystack.l_mark;
876 }
877 }
878 }
879 else
880 {
881 if (yychar == YYEOF) goto yyabort;
882#if YYDEBUG
883 if (yydebug)
884 {
885 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
886 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
887 YYPREFIX, yystate, yychar, yys);
888 }
889#endif
890 yychar = YYEMPTY;
891 goto yyloop;
892 }
893
894yyreduce:
895#if YYDEBUG
896 if (yydebug)
897 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
898 YYPREFIX, yystate, yyn, yyrule[yyn]);
899#endif
900 yym = yylen[yyn];
901 if (yym > 0)
902 yyval = yystack.l_mark[1-yym];
903 else
904 memset(&yyval, 0, sizeof yyval);
905
906 switch (yyn)
907 {
908case 5:
909#line 173 "../../../gmp/demos/calc/calc.y"
910 { sp = stack[0]; yyerrok; }
911break;
912case 7:
913#line 177 "../../../gmp/demos/calc/calc.y"
914 {
915 mpz_out_str (stdout, obase, sp); putchar ('\n');
916 sp--;
917 CHECK_EMPTY ();
918 }
919break;
920case 8:
921#line 182 "../../../gmp/demos/calc/calc.y"
922 {
923 CHECK_VARIABLE (yystack.l_mark[-2].var);
924 mpz_swap (variable[yystack.l_mark[-2].var], sp);
925 sp--;
926 CHECK_EMPTY ();
927 }
928break;
929case 9:
930#line 188 "../../../gmp/demos/calc/calc.y"
931 { calc_help (); }
932break;
933case 10:
934#line 189 "../../../gmp/demos/calc/calc.y"
935 { ibase = 16; obase = -16; }
936break;
937case 11:
938#line 190 "../../../gmp/demos/calc/calc.y"
939 { ibase = 0; obase = 10; }
940break;
941case 12:
942#line 191 "../../../gmp/demos/calc/calc.y"
943 { exit (0); }
944break;
945case 14:
946#line 198 "../../../gmp/demos/calc/calc.y"
947 { sp--; mpz_add (sp, sp, sp+1); }
948break;
949case 15:
950#line 199 "../../../gmp/demos/calc/calc.y"
951 { sp--; mpz_sub (sp, sp, sp+1); }
952break;
953case 16:
954#line 200 "../../../gmp/demos/calc/calc.y"
955 { sp--; mpz_mul (sp, sp, sp+1); }
956break;
957case 17:
958#line 201 "../../../gmp/demos/calc/calc.y"
959 { sp--; mpz_fdiv_q (sp, sp, sp+1); }
960break;
961case 18:
962#line 202 "../../../gmp/demos/calc/calc.y"
963 { sp--; mpz_fdiv_r (sp, sp, sp+1); }
964break;
965case 19:
966#line 203 "../../../gmp/demos/calc/calc.y"
967 { CHECK_UI ("Exponent", sp);
968 sp--; mpz_pow_ui (sp, sp, mpz_get_ui (sp+1)); }
969break;
970case 20:
971#line 205 "../../../gmp/demos/calc/calc.y"
972 { CHECK_UI ("Shift count", sp);
973 sp--; mpz_mul_2exp (sp, sp, mpz_get_ui (sp+1)); }
974break;
975case 21:
976#line 207 "../../../gmp/demos/calc/calc.y"
977 { CHECK_UI ("Shift count", sp);
978 sp--; mpz_fdiv_q_2exp (sp, sp, mpz_get_ui (sp+1)); }
979break;
980case 22:
981#line 209 "../../../gmp/demos/calc/calc.y"
982 { CHECK_UI ("Factorial", sp);
983 mpz_fac_ui (sp, mpz_get_ui (sp)); }
984break;
985case 23:
986#line 211 "../../../gmp/demos/calc/calc.y"
987 { mpz_neg (sp, sp); }
988break;
989case 24:
990#line 213 "../../../gmp/demos/calc/calc.y"
991 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) < 0); }
992break;
993case 25:
994#line 214 "../../../gmp/demos/calc/calc.y"
995 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) <= 0); }
996break;
997case 26:
998#line 215 "../../../gmp/demos/calc/calc.y"
999 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) == 0); }
1000break;
1001case 27:
1002#line 216 "../../../gmp/demos/calc/calc.y"
1003 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) != 0); }
1004break;
1005case 28:
1006#line 217 "../../../gmp/demos/calc/calc.y"
1007 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) >= 0); }
1008break;
1009case 29:
1010#line 218 "../../../gmp/demos/calc/calc.y"
1011 { sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) > 0); }
1012break;
1013case 30:
1014#line 220 "../../../gmp/demos/calc/calc.y"
1015 { sp--; mpz_set_ui (sp, mpz_sgn (sp) && mpz_sgn (sp+1)); }
1016break;
1017case 31:
1018#line 221 "../../../gmp/demos/calc/calc.y"
1019 { sp--; mpz_set_ui (sp, mpz_sgn (sp) || mpz_sgn (sp+1)); }
1020break;
1021case 32:
1022#line 223 "../../../gmp/demos/calc/calc.y"
1023 { mpz_abs (sp, sp); }
1024break;
1025case 33:
1026#line 224 "../../../gmp/demos/calc/calc.y"
1027 { sp--; CHECK_UI ("Binomial base", sp+1);
1028 mpz_bin_ui (sp, sp, mpz_get_ui (sp+1)); }
1029break;
1030case 34:
1031#line 226 "../../../gmp/demos/calc/calc.y"
1032 { CHECK_UI ("Fibonacci", sp);
1033 mpz_fib_ui (sp, mpz_get_ui (sp)); }
1034break;
1035case 36:
1036#line 229 "../../../gmp/demos/calc/calc.y"
1037 { sp--; mpz_set_si (sp,
1038 mpz_kronecker (sp, sp+1)); }
1039break;
1040case 38:
1041#line 232 "../../../gmp/demos/calc/calc.y"
1042 { CHECK_UI ("Lucas number", sp);
1043 mpz_lucnum_ui (sp, mpz_get_ui (sp)); }
1044break;
1045case 39:
1046#line 234 "../../../gmp/demos/calc/calc.y"
1047 { mpz_nextprime (sp, sp); }
1048break;
1049case 40:
1050#line 235 "../../../gmp/demos/calc/calc.y"
1051 { sp -= 2; mpz_powm (sp, sp, sp+1, sp+2); }
1052break;
1053case 41:
1054#line 236 "../../../gmp/demos/calc/calc.y"
1055 { sp--; CHECK_UI ("Nth-root", sp+1);
1056 mpz_root (sp, sp, mpz_get_ui (sp+1)); }
1057break;
1058case 42:
1059#line 238 "../../../gmp/demos/calc/calc.y"
1060 { mpz_sqrt (sp, sp); }
1061break;
1062case 43:
1063#line 240 "../../../gmp/demos/calc/calc.y"
1064 {
1065 sp++;
1066 CHECK_OVERFLOW ();
1067 CHECK_VARIABLE (yystack.l_mark[0].var);
1068 mpz_set (sp, variable[yystack.l_mark[0].var]);
1069 }
1070break;
1071case 44:
1072#line 246 "../../../gmp/demos/calc/calc.y"
1073 {
1074 sp++;
1075 CHECK_OVERFLOW ();
1076 if (mpz_set_str (sp, yystack.l_mark[0].str, ibase) != 0)
1077 {
1078 fprintf (stderr, "Invalid number: %s\n", yystack.l_mark[0].str);
1079 YYERROR;
1080 }
1081 }
1082break;
1083case 46:
1084#line 258 "../../../gmp/demos/calc/calc.y"
1085 { sp--; mpz_gcd (sp, sp, sp+1); }
1086break;
1087case 48:
1088#line 262 "../../../gmp/demos/calc/calc.y"
1089 { sp--; mpz_lcm (sp, sp, sp+1); }
1090break;
1091#line 1092 "calc.c"
1092 }
1093 yystack.s_mark -= yym;
1094 yystate = *yystack.s_mark;
1095 yystack.l_mark -= yym;
1096 yym = yylhs[yyn];
1097 if (yystate == 0 && yym == 0)
1098 {
1099#if YYDEBUG
1100 if (yydebug)
1101 printf("%sdebug: after reduction, shifting from state 0 to\
1102 state %d\n", YYPREFIX, YYFINAL);
1103#endif
1104 yystate = YYFINAL;
1105 *++yystack.s_mark = YYFINAL;
1106 *++yystack.l_mark = yyval;
1107 if (yychar < 0)
1108 {
1109 yychar = YYLEX;
1110 if (yychar < 0) yychar = YYEOF;
1111#if YYDEBUG
1112 if (yydebug)
1113 {
1114 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1115 printf("%sdebug: state %d, reading %d (%s)\n",
1116 YYPREFIX, YYFINAL, yychar, yys);
1117 }
1118#endif
1119 }
1120 if (yychar == YYEOF) goto yyaccept;
1121 goto yyloop;
1122 }
1123 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1124 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1125 yystate = yytable[yyn];
1126 else
1127 yystate = yydgoto[yym];
1128#if YYDEBUG
1129 if (yydebug)
1130 printf("%sdebug: after reduction, shifting from state %d \
1131to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
1132#endif
1133 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1134 *++yystack.s_mark = (YYINT) yystate;
1135 *++yystack.l_mark = yyval;
1136 goto yyloop;
1137
1138yyoverflow:
1139 YYERROR_CALL("yacc stack overflow");
1140
1141yyabort:
1142 yyfreestack(&yystack);
1143 return (1);
1144
1145yyaccept:
1146 yyfreestack(&yystack);
1147 return (0);
1148}