2
/* A Bison parser, made from calc.y
3
by GNU Bison version 1.28 */
5
#define YYBISON 1 /* Identify Bison output. */
36
/* A simple integer desk calculator using yacc and gmp.
38
Copyright 2000, 2001 Free Software Foundation, Inc.
40
This file is part of the GNU MP Library.
42
This program is free software; you can redistribute it and/or modify it under
43
the terms of the GNU General Public License as published by the Free Software
44
Foundation; either version 2 of the License, or (at your option) any later
47
This program is distributed in the hope that it will be useful, but WITHOUT ANY
48
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
49
PARTICULAR PURPOSE. See the GNU General Public License for more details.
51
You should have received a copy of the GNU General Public License along with
52
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
53
Place - Suite 330, Boston, MA 02111-1307, USA. */
56
/* This is a simple program, meant only to show one way to use GMP for this
57
sort of thing. There's few features, and error checking is minimal.
58
Standard input is read, there's no command line options.
61
2+3*4 expressions are evaluated
62
x=5^6 variables a to z can be set and used
66
/ % division and remainder (rounding towards negative infinity)
69
<< >> left and right shifts
70
<= >= > \ comparisons, giving 1 if true, 0 if false
72
&& || logical and/or, giving 1 if true, 0 if false
76
bin(n,m) binomial coefficient
77
fib(n) fibonacci number
78
gcd(a,b,..) greatest common divisor
79
kron(a,b) kronecker symbol
80
lcm(a,b,..) least common multiple
81
nextprime(n) next prime after n
82
powm(b,e,m) modulo powering, b^e%m
87
hex \ set hex or decimal for input and output
88
decimal / ("0x" can be used for hex too)
89
quit exit program (EOF works too)
90
; statements are separated with a ; or newline
91
\ continue expressions with \ before newline
92
# xxx comments are # though to newline
94
Hex numbers must be entered in upper case, to distinguish them from the
95
variables a to f (like in bc).
98
Expressions are evaluated as they're read. If user defined functions
99
were wanted it'd be necessary to build a parse tree like pexpr.c does, or
100
a list of operations for a stack based evaluator. That would also make
101
it possible to detect and optimize evaluations "mod m" like pexpr.c does.
103
A stack is used for intermediate values in the expression evaluation,
104
separate from the yacc parser stack. This is simple, makes error
105
recovery easy, minimizes the junk around mpz calls in the rules, and
106
saves initializing or clearing "mpz_t"s during a calculation. A
107
disadvantage though is that variables must be copied to the stack to be
108
worked on. A more sophisticated calculator or language system might be
109
able to avoid that when executing a compiled or semi-compiled form.
111
Avoiding repeated initializing and clearing of "mpz_t"s is important. In
112
this program the time spent parsing is obviously much greater than any
113
possible saving from this, but a proper calculator or language should
114
take some trouble over it. Don't be surprised if an init/clear takes 3
115
or more times as long as a 10 limb addition, depending on the system (see
116
the mpz_init_realloc_clear example in tune/README). */
124
#define numberof(x) (sizeof (x) / sizeof ((x)[0]))
131
/* The stack is a fixed size, which means there's a limit on the nesting
132
allowed in expressions. A more sophisticated program could let it grow
136
mpz_ptr sp = stack[0];
138
#define CHECK_OVERFLOW() \
139
if (sp >= stack[numberof(stack)]) \
142
"Value stack overflow, too much nesting in expression\n"); \
146
#define CHECK_EMPTY() \
147
if (sp != stack[0]) \
149
fprintf (stderr, "Oops, expected the value stack to be empty\n"); \
156
#define CHECK_VARIABLE(var) \
157
if ((var) < 0 || (var) >= numberof (variable)) \
159
fprintf (stderr, "Oops, bad variable somehow: %d\n", var); \
164
#define CHECK_UI(name,z) \
165
if (! mpz_fits_ulong_p (z)) \
168
"Operand must fit in an \"unsigned long\" for %s\n", name); \
189
#define YYFLAG -32768
192
#define YYTRANSLATE(x) ((unsigned)(x) <= 282 ? yytranslate[x] : 48)
194
static const char yytranslate[] = { 0,
195
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
196
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
197
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
198
2, 2, 37, 2, 2, 2, 34, 2, 2, 39,
199
40, 32, 30, 41, 31, 2, 33, 2, 2, 2,
200
2, 2, 2, 2, 2, 2, 2, 2, 2, 22,
201
38, 23, 2, 2, 2, 2, 2, 2, 2, 2,
202
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
203
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
204
2, 2, 2, 36, 2, 2, 2, 2, 2, 2,
205
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
206
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
207
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
208
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
209
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
210
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
211
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
212
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
213
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
214
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
215
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
216
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
217
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
218
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
219
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
220
2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
221
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
222
17, 18, 19, 20, 21, 24, 25, 26, 27, 28,
227
static const short yyprhs[] = { 0,
228
0, 2, 5, 8, 12, 15, 16, 18, 22, 24,
229
26, 28, 32, 36, 40, 44, 48, 52, 56, 60,
230
64, 67, 70, 74, 78, 82, 86, 90, 94, 98,
231
102, 107, 114, 119, 124, 131, 136, 141, 150, 157,
232
162, 164, 166, 168, 172, 174
235
static const short yyrhs[] = { 44,
236
0, 43, 44, 0, 44, 3, 0, 43, 44, 3,
237
0, 1, 3, 0, 0, 45, 0, 19, 38, 45,
238
0, 5, 0, 6, 0, 7, 0, 39, 45, 40,
239
0, 45, 30, 45, 0, 45, 31, 45, 0, 45,
240
32, 45, 0, 45, 33, 45, 0, 45, 34, 45,
241
0, 45, 36, 45, 0, 45, 28, 45, 0, 45,
242
29, 45, 0, 45, 37, 0, 31, 45, 0, 45,
243
22, 45, 0, 45, 26, 45, 0, 45, 24, 45,
244
0, 45, 25, 45, 0, 45, 27, 45, 0, 45,
245
23, 45, 0, 45, 21, 45, 0, 45, 20, 45,
246
0, 8, 39, 45, 40, 0, 9, 39, 45, 41,
247
45, 40, 0, 10, 39, 45, 40, 0, 11, 39,
248
46, 40, 0, 12, 39, 45, 41, 45, 40, 0,
249
13, 39, 47, 40, 0, 14, 39, 45, 40, 0,
250
15, 39, 45, 41, 45, 41, 45, 40, 0, 16,
251
39, 45, 41, 45, 40, 0, 17, 39, 45, 40,
252
0, 19, 0, 18, 0, 45, 0, 46, 41, 45,
253
0, 45, 0, 47, 41, 45, 0
259
static const short yyrline[] = { 0,
260
164, 166, 168, 170, 171, 173, 175, 180, 186, 187,
261
188, 193, 195, 196, 197, 198, 199, 200, 202, 204,
262
206, 208, 210, 211, 212, 213, 214, 215, 217, 218,
263
220, 221, 223, 225, 226, 228, 229, 230, 231, 233,
264
235, 241, 251, 253, 255, 257
269
#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
271
static const char * const yytname[] = { "$","error","$undefined.","EOS","BAD",
272
"HEX","DECIMAL","QUIT","ABS","BIN","FIB","GCD","KRON","LCM","NEXTPRIME","POWM",
273
"ROOT","SQRT","NUMBER","VARIABLE","LOR","LAND","'<'","'>'","EQ","NE","LE","GE",
274
"LSHIFT","RSHIFT","'+'","'-'","'*'","'/'","'%'","UMINUS","'^'","'!'","'='","'('",
275
"')'","','","top","statements","statement","e","gcdlist","lcmlist", NULL
279
static const short yyr1[] = { 0,
280
42, 42, 43, 43, 43, 44, 44, 44, 44, 44,
281
44, 45, 45, 45, 45, 45, 45, 45, 45, 45,
282
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
283
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
284
45, 45, 46, 46, 47, 47
287
static const short yyr2[] = { 0,
288
1, 2, 2, 3, 2, 0, 1, 3, 1, 1,
289
1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
290
2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
291
4, 6, 4, 4, 6, 4, 4, 8, 6, 4,
295
static const short yydefact[] = { 0,
296
0, 9, 10, 11, 0, 0, 0, 0, 0, 0,
297
0, 0, 0, 0, 42, 41, 0, 0, 6, 1,
298
7, 5, 0, 0, 0, 0, 0, 0, 0, 0,
299
0, 0, 0, 41, 22, 0, 2, 3, 0, 0,
300
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
301
0, 0, 0, 0, 21, 0, 0, 0, 43, 0,
302
0, 45, 0, 0, 0, 0, 0, 8, 12, 4,
303
30, 29, 23, 28, 25, 26, 24, 27, 19, 20,
304
13, 14, 15, 16, 17, 18, 31, 0, 33, 34,
305
0, 0, 36, 0, 37, 0, 0, 40, 0, 44,
306
0, 46, 0, 0, 32, 35, 0, 39, 0, 38,
310
static const short yydefgoto[] = { 111,
314
static const short yypact[] = { 39,
315
16,-32768,-32768,-32768, -19, -18, -1, 2, 4, 25,
316
28, 30, 33, 34,-32768, 38, 118, 118, 86, 65,
317
437,-32768, 118, 118, 118, 118, 118, 118, 118, 118,
318
118, 118, 118,-32768, -34, 248, 81,-32768, 118, 118,
319
118, 118, 118, 118, 118, 118, 118, 118, 118, 118,
320
118, 118, 118, 118,-32768, 269, 138, 290, 437, -36,
321
160, 437, -23, 311, 182, 204, 332, 437,-32768,-32768,
322
454, 470, 486, 486, 486, 486, 486, 486, 29, 29,
323
49, 49, -34, -34, -34, -34,-32768, 118,-32768,-32768,
324
118, 118,-32768, 118,-32768, 118, 118,-32768, 353, 437,
325
374, 437, 226, 395,-32768,-32768, 118,-32768, 416,-32768,
329
static const short yypgoto[] = {-32768,
330
-32768, 70, -17,-32768,-32768
337
static const short yytable[] = { 35,
338
36, 54, 55, 90, 91, 56, 57, 58, 59, 61,
339
62, 64, 65, 66, 67, 68, 93, 94, 22, 23,
340
24, 71, 72, 73, 74, 75, 76, 77, 78, 79,
341
80, 81, 82, 83, 84, 85, 86, 25, -6, 1,
342
26, -6, 27, 2, 3, 4, 5, 6, 7, 8,
343
9, 10, 11, 12, 13, 14, 15, 16, 49, 50,
344
51, 52, 53, 28, 54, 55, 29, 38, 30, 17,
345
99, 31, 32, 100, 101, 33, 102, 18, 103, 104,
346
51, 52, 53, 70, 54, 55, 112, 113, 37, 109,
347
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
348
12, 13, 14, 15, 16, 0, 0, 0, 0, 0,
349
0, 0, 0, 0, 0, 0, 17, 0, 0, 0,
350
0, 0, 0, 0, 18, 5, 6, 7, 8, 9,
351
10, 11, 12, 13, 14, 15, 34, 0, 0, 0,
352
0, 0, 0, 0, 0, 0, 0, 0, 17, 0,
353
0, 0, 0, 0, 0, 0, 18, 39, 40, 41,
354
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
355
52, 53, 0, 54, 55, 0, 0, 0, 88, 39,
356
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
357
50, 51, 52, 53, 0, 54, 55, 0, 0, 0,
358
92, 39, 40, 41, 42, 43, 44, 45, 46, 47,
359
48, 49, 50, 51, 52, 53, 0, 54, 55, 0,
360
0, 0, 96, 39, 40, 41, 42, 43, 44, 45,
361
46, 47, 48, 49, 50, 51, 52, 53, 0, 54,
362
55, 0, 0, 0, 97, 39, 40, 41, 42, 43,
363
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
364
0, 54, 55, 0, 0, 0, 107, 39, 40, 41,
365
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
366
52, 53, 0, 54, 55, 0, 0, 69, 39, 40,
367
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
368
51, 52, 53, 0, 54, 55, 0, 0, 87, 39,
369
40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
370
50, 51, 52, 53, 0, 54, 55, 0, 0, 89,
371
39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
372
49, 50, 51, 52, 53, 0, 54, 55, 0, 0,
373
95, 39, 40, 41, 42, 43, 44, 45, 46, 47,
374
48, 49, 50, 51, 52, 53, 0, 54, 55, 0,
375
0, 98, 39, 40, 41, 42, 43, 44, 45, 46,
376
47, 48, 49, 50, 51, 52, 53, 0, 54, 55,
377
0, 0, 105, 39, 40, 41, 42, 43, 44, 45,
378
46, 47, 48, 49, 50, 51, 52, 53, 0, 54,
379
55, 0, 0, 106, 39, 40, 41, 42, 43, 44,
380
45, 46, 47, 48, 49, 50, 51, 52, 53, 0,
381
54, 55, 0, 0, 108, 39, 40, 41, 42, 43,
382
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
383
0, 54, 55, 0, 0, 110, 39, 40, 41, 42,
384
43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
385
53, 0, 54, 55, 40, 41, 42, 43, 44, 45,
386
46, 47, 48, 49, 50, 51, 52, 53, 0, 54,
387
55, 41, 42, 43, 44, 45, 46, 47, 48, 49,
388
50, 51, 52, 53, 0, 54, 55,-32768,-32768,-32768,
389
-32768,-32768,-32768, 47, 48, 49, 50, 51, 52, 53,
393
static const short yycheck[] = { 17,
394
18, 36, 37, 40, 41, 23, 24, 25, 26, 27,
395
28, 29, 30, 31, 32, 33, 40, 41, 3, 39,
396
39, 39, 40, 41, 42, 43, 44, 45, 46, 47,
397
48, 49, 50, 51, 52, 53, 54, 39, 0, 1,
398
39, 3, 39, 5, 6, 7, 8, 9, 10, 11,
399
12, 13, 14, 15, 16, 17, 18, 19, 30, 31,
400
32, 33, 34, 39, 36, 37, 39, 3, 39, 31,
401
88, 39, 39, 91, 92, 38, 94, 39, 96, 97,
402
32, 33, 34, 3, 36, 37, 0, 0, 19, 107,
403
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
404
15, 16, 17, 18, 19, -1, -1, -1, -1, -1,
405
-1, -1, -1, -1, -1, -1, 31, -1, -1, -1,
406
-1, -1, -1, -1, 39, 8, 9, 10, 11, 12,
407
13, 14, 15, 16, 17, 18, 19, -1, -1, -1,
408
-1, -1, -1, -1, -1, -1, -1, -1, 31, -1,
409
-1, -1, -1, -1, -1, -1, 39, 20, 21, 22,
410
23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
411
33, 34, -1, 36, 37, -1, -1, -1, 41, 20,
412
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
413
31, 32, 33, 34, -1, 36, 37, -1, -1, -1,
414
41, 20, 21, 22, 23, 24, 25, 26, 27, 28,
415
29, 30, 31, 32, 33, 34, -1, 36, 37, -1,
416
-1, -1, 41, 20, 21, 22, 23, 24, 25, 26,
417
27, 28, 29, 30, 31, 32, 33, 34, -1, 36,
418
37, -1, -1, -1, 41, 20, 21, 22, 23, 24,
419
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
420
-1, 36, 37, -1, -1, -1, 41, 20, 21, 22,
421
23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
422
33, 34, -1, 36, 37, -1, -1, 40, 20, 21,
423
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
424
32, 33, 34, -1, 36, 37, -1, -1, 40, 20,
425
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
426
31, 32, 33, 34, -1, 36, 37, -1, -1, 40,
427
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
428
30, 31, 32, 33, 34, -1, 36, 37, -1, -1,
429
40, 20, 21, 22, 23, 24, 25, 26, 27, 28,
430
29, 30, 31, 32, 33, 34, -1, 36, 37, -1,
431
-1, 40, 20, 21, 22, 23, 24, 25, 26, 27,
432
28, 29, 30, 31, 32, 33, 34, -1, 36, 37,
433
-1, -1, 40, 20, 21, 22, 23, 24, 25, 26,
434
27, 28, 29, 30, 31, 32, 33, 34, -1, 36,
435
37, -1, -1, 40, 20, 21, 22, 23, 24, 25,
436
26, 27, 28, 29, 30, 31, 32, 33, 34, -1,
437
36, 37, -1, -1, 40, 20, 21, 22, 23, 24,
438
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
439
-1, 36, 37, -1, -1, 40, 20, 21, 22, 23,
440
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
441
34, -1, 36, 37, 21, 22, 23, 24, 25, 26,
442
27, 28, 29, 30, 31, 32, 33, 34, -1, 36,
443
37, 22, 23, 24, 25, 26, 27, 28, 29, 30,
444
31, 32, 33, 34, -1, 36, 37, 22, 23, 24,
445
25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
448
/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
449
#line 3 "/usr/share/misc/bison.simple"
450
/* This file comes from bison-1.28. */
452
/* Skeleton output parser for bison,
453
Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
455
This program is free software; you can redistribute it and/or modify
456
it under the terms of the GNU General Public License as published by
457
the Free Software Foundation; either version 2, or (at your option)
460
This program is distributed in the hope that it will be useful,
461
but WITHOUT ANY WARRANTY; without even the implied warranty of
462
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
463
GNU General Public License for more details.
465
You should have received a copy of the GNU General Public License
466
along with this program; if not, write to the Free Software
467
Foundation, Inc., 59 Temple Place - Suite 330,
468
Boston, MA 02111-1307, USA. */
470
/* As a special exception, when this file is copied by Bison into a
471
Bison output file, you may use that output file without restriction.
472
This special exception was added by the Free Software Foundation
473
in version 1.24 of Bison. */
475
/* This is the parser code that is written into each bison parser
476
when the %semantic_parser declaration is not specified in the grammar.
477
It was written by Richard Stallman by simplifying the hairy parser
478
used when %semantic_parser is specified. */
480
#ifndef YYSTACK_USE_ALLOCA
482
#define YYSTACK_USE_ALLOCA
483
#else /* alloca not defined */
485
#define YYSTACK_USE_ALLOCA
486
#define alloca __builtin_alloca
487
#else /* not GNU C. */
488
#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
489
#define YYSTACK_USE_ALLOCA
491
#else /* not sparc */
492
/* We think this test detects Watcom and Microsoft C. */
493
/* This used to test MSDOS, but that is a bad idea
494
since that symbol is in the user namespace. */
495
#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
496
#if 0 /* No need for malloc.h, which pollutes the namespace;
497
instead, just don't use alloca. */
500
#else /* not MSDOS, or __TURBOC__ */
502
/* I don't know what this was needed for, but it pollutes the namespace.
503
So I turned it off. rms, 2 May 1997. */
504
/* #include <malloc.h> */
506
#define YYSTACK_USE_ALLOCA
507
#else /* not MSDOS, or __TURBOC__, or _AIX */
509
#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
510
and on HPUX 10. Eventually we can turn this on. */
511
#define YYSTACK_USE_ALLOCA
512
#define alloca __builtin_alloca
515
#endif /* not _AIX */
516
#endif /* not MSDOS, or __TURBOC__ */
517
#endif /* not sparc */
518
#endif /* not GNU C */
519
#endif /* alloca not defined */
520
#endif /* YYSTACK_USE_ALLOCA not defined */
522
#ifdef YYSTACK_USE_ALLOCA
523
#define YYSTACK_ALLOC alloca
525
#define YYSTACK_ALLOC malloc
528
/* Note: there must be only one dollar sign in this file.
529
It is replaced by the list of actions, each action
530
as one case of the switch. */
532
#define yyerrok (yyerrstatus = 0)
533
#define yyclearin (yychar = YYEMPTY)
536
#define YYACCEPT goto yyacceptlab
537
#define YYABORT goto yyabortlab
538
#define YYERROR goto yyerrlab1
539
/* Like YYERROR except do call yyerror.
540
This remains here temporarily to ease the
541
transition to the new meaning of YYERROR, for GCC.
542
Once GCC version 2 has supplanted version 1, this can go. */
543
#define YYFAIL goto yyerrlab
544
#define YYRECOVERING() (!!yyerrstatus)
545
#define YYBACKUP(token, value) \
547
if (yychar == YYEMPTY && yylen == 1) \
548
{ yychar = (token), yylval = (value); \
549
yychar1 = YYTRANSLATE (yychar); \
554
{ yyerror ("syntax error: cannot back up"); YYERROR; } \
558
#define YYERRCODE 256
561
#define YYLEX yylex()
567
#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
569
#define YYLEX yylex(&yylval, &yylloc)
571
#else /* not YYLSP_NEEDED */
573
#define YYLEX yylex(&yylval, YYLEX_PARAM)
575
#define YYLEX yylex(&yylval)
577
#endif /* not YYLSP_NEEDED */
580
/* If nonreentrant, generate the variables here */
584
int yychar; /* the lookahead symbol */
585
YYSTYPE yylval; /* the semantic value of the */
586
/* lookahead symbol */
589
YYLTYPE yylloc; /* location data for the lookahead */
593
int yynerrs; /* number of parse errors so far */
594
#endif /* not YYPURE */
597
int yydebug; /* nonzero means print parse trace */
598
/* Since this is uninitialized, it does not stop multiple parsers
602
/* YYINITDEPTH indicates the initial size of the parser's stacks */
605
#define YYINITDEPTH 200
608
/* YYMAXDEPTH is the maximum size the stacks can grow to
609
(effective only if the built-in stack extension method is used). */
616
#define YYMAXDEPTH 10000
619
/* Define __yy_memcpy. Note that the size argument
620
should be passed with type unsigned int, because that is what the non-GCC
621
definitions require. With GCC, __builtin_memcpy takes an arg
622
of type size_t, but it can handle unsigned int. */
624
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
625
#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
626
#else /* not GNU C or C++ */
629
/* This is the most reliable way to avoid incompatibilities
630
in available built-in functions on various systems. */
632
__yy_memcpy (to, from, count)
637
register char *f = from;
638
register char *t = to;
639
register int i = count;
645
#else /* __cplusplus */
647
/* This is the most reliable way to avoid incompatibilities
648
in available built-in functions on various systems. */
650
__yy_memcpy (char *to, char *from, unsigned int count)
652
register char *t = to;
653
register char *f = from;
654
register int i = count;
663
#line 217 "/usr/share/misc/bison.simple"
665
/* The user can define YYPARSE_PARAM as the name of an argument to be passed
666
into yyparse. The argument should have type void *.
667
It should actually point to an object.
668
Grammar actions can access the variable by casting it
669
to the proper pointer type. */
673
#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
674
#define YYPARSE_PARAM_DECL
675
#else /* not __cplusplus */
676
#define YYPARSE_PARAM_ARG YYPARSE_PARAM
677
#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
678
#endif /* not __cplusplus */
679
#else /* not YYPARSE_PARAM */
680
#define YYPARSE_PARAM_ARG
681
#define YYPARSE_PARAM_DECL
682
#endif /* not YYPARSE_PARAM */
684
/* Prevent warning if -Wstrict-prototypes. */
687
int yyparse (void *);
694
yyparse(YYPARSE_PARAM_ARG)
697
register int yystate;
699
register short *yyssp;
700
register YYSTYPE *yyvsp;
701
int yyerrstatus; /* number of tokens to shift before error messages enabled */
702
int yychar1 = 0; /* lookahead token as an internal (translated) token number */
704
short yyssa[YYINITDEPTH]; /* the state stack */
705
YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
707
short *yyss = yyssa; /* refer to the stacks thru separate pointers */
708
YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
711
YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
712
YYLTYPE *yyls = yylsa;
715
#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
717
#define YYPOPSTACK (yyvsp--, yyssp--)
720
int yystacksize = YYINITDEPTH;
721
int yyfree_stacks = 0;
732
YYSTYPE yyval; /* the variable used to return */
733
/* semantic values from the action */
740
fprintf(stderr, "Starting parse\n");
746
yychar = YYEMPTY; /* Cause a token to be read. */
748
/* Initialize stack pointers.
749
Waste one element of value and location stack
750
so that they stay on the same level as the state stack.
751
The wasted elements are never initialized. */
759
/* Push a new state, which is found in yystate . */
760
/* In all cases, when you get here, the value and location stacks
761
have just been pushed. so pushing a state here evens the stacks. */
766
if (yyssp >= yyss + yystacksize - 1)
768
/* Give user a chance to reallocate the stack */
769
/* Use copies of these so that the &'s don't force the real ones into memory. */
770
YYSTYPE *yyvs1 = yyvs;
773
YYLTYPE *yyls1 = yyls;
776
/* Get the current used size of the three stacks, in elements. */
777
int size = yyssp - yyss + 1;
780
/* Each stack pointer address is followed by the size of
781
the data in use in that stack, in bytes. */
783
/* This used to be a conditional around just the two extra args,
784
but that might be undefined if yyoverflow is a macro. */
785
yyoverflow("parser stack overflow",
786
&yyss1, size * sizeof (*yyssp),
787
&yyvs1, size * sizeof (*yyvsp),
788
&yyls1, size * sizeof (*yylsp),
791
yyoverflow("parser stack overflow",
792
&yyss1, size * sizeof (*yyssp),
793
&yyvs1, size * sizeof (*yyvsp),
797
yyss = yyss1; yyvs = yyvs1;
801
#else /* no yyoverflow */
802
/* Extend the stack our own way. */
803
if (yystacksize >= YYMAXDEPTH)
805
yyerror("parser stack overflow");
817
if (yystacksize > YYMAXDEPTH)
818
yystacksize = YYMAXDEPTH;
819
#ifndef YYSTACK_USE_ALLOCA
822
yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
823
__yy_memcpy ((char *)yyss, (char *)yyss1,
824
size * (unsigned int) sizeof (*yyssp));
825
yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
826
__yy_memcpy ((char *)yyvs, (char *)yyvs1,
827
size * (unsigned int) sizeof (*yyvsp));
829
yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
830
__yy_memcpy ((char *)yyls, (char *)yyls1,
831
size * (unsigned int) sizeof (*yylsp));
833
#endif /* no yyoverflow */
835
yyssp = yyss + size - 1;
836
yyvsp = yyvs + size - 1;
838
yylsp = yyls + size - 1;
843
fprintf(stderr, "Stack size increased to %d\n", yystacksize);
846
if (yyssp >= yyss + yystacksize - 1)
852
fprintf(stderr, "Entering state %d\n", yystate);
858
/* Do appropriate processing given the current state. */
859
/* Read a lookahead token if we need one and don't already have one. */
862
/* First try to decide what to do without reference to lookahead token. */
864
yyn = yypact[yystate];
868
/* Not known => get a lookahead token if don't already have one. */
870
/* yychar is either YYEMPTY or YYEOF
871
or a valid token in external form. */
873
if (yychar == YYEMPTY)
877
fprintf(stderr, "Reading a token: ");
882
/* Convert token to internal form (in yychar1) for indexing tables with */
884
if (yychar <= 0) /* This means end of input. */
887
yychar = YYEOF; /* Don't call YYLEX any more */
891
fprintf(stderr, "Now at end of input.\n");
896
yychar1 = YYTRANSLATE(yychar);
901
fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
902
/* Give the individual parser a way to print the precise meaning
903
of a token, for further debugging info. */
905
YYPRINT (stderr, yychar, yylval);
907
fprintf (stderr, ")\n");
913
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
918
/* yyn is what to do for this token type in this state.
919
Negative => reduce, -yyn is rule number.
920
Positive => shift, yyn is new state.
921
New state is final state => don't bother to shift,
923
0, or most negative number => error. */
938
/* Shift the lookahead token. */
942
fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
945
/* Discard the token being shifted unless it is eof. */
954
/* count tokens shifted since error; after three, turn off error status. */
955
if (yyerrstatus) yyerrstatus--;
960
/* Do the default action for the current state. */
963
yyn = yydefact[yystate];
967
/* Do a reduction. yyn is the number of a rule to reduce with. */
971
yyval = yyvsp[1-yylen]; /* implement default value of the action */
978
fprintf (stderr, "Reducing via rule %d (line %d), ",
981
/* Print the symbols being reduced, and their result. */
982
for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
983
fprintf (stderr, "%s ", yytname[yyrhs[i]]);
984
fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
993
{ sp = stack[0]; yyerrok; ;
998
mpz_out_str (stdout, obase, sp); putchar ('\n');
1006
CHECK_VARIABLE (yyvsp[-2].var);
1007
mpz_swap (variable[yyvsp[-2].var], sp);
1014
{ ibase = 16; obase = -16; ;
1018
{ ibase = 0; obase = 10; ;
1026
{ sp--; mpz_add (sp, sp, sp+1); ;
1030
{ sp--; mpz_sub (sp, sp, sp+1); ;
1034
{ sp--; mpz_mul (sp, sp, sp+1); ;
1038
{ sp--; mpz_fdiv_q (sp, sp, sp+1); ;
1042
{ sp--; mpz_fdiv_r (sp, sp, sp+1); ;
1046
{ CHECK_UI ("exponentiation", sp);
1047
sp--; mpz_pow_ui (sp, sp, mpz_get_ui (sp+1)); ;
1051
{ CHECK_UI ("lshift", sp);
1052
sp--; mpz_mul_2exp (sp, sp, mpz_get_ui (sp+1)); ;
1056
{ CHECK_UI ("rshift", sp);
1057
sp--; mpz_fdiv_q_2exp (sp, sp, mpz_get_ui (sp+1)); ;
1061
{ CHECK_UI ("factorial", sp);
1062
mpz_fac_ui (sp, mpz_get_ui (sp)); ;
1066
{ mpz_neg (sp, sp); ;
1070
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) < 0); ;
1074
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) <= 0); ;
1078
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) == 0); ;
1082
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) != 0); ;
1086
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) >= 0); ;
1090
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) > 0); ;
1094
{ sp--; mpz_set_ui (sp, mpz_sgn (sp) && mpz_sgn (sp+1)); ;
1098
{ sp--; mpz_set_ui (sp, mpz_sgn (sp) || mpz_sgn (sp+1)); ;
1102
{ mpz_abs (sp, sp); ;
1106
{ sp--; CHECK_UI ("binomial", sp+1);
1107
mpz_bin_ui (sp, sp, mpz_get_ui (sp+1)); ;
1111
{ CHECK_UI ("fibonacci", sp);
1112
mpz_fib_ui (sp, mpz_get_ui (sp)); ;
1116
{ sp--; mpz_set_si (sp,
1117
mpz_kronecker (sp, sp+1)); ;
1121
{ mpz_nextprime (sp, sp); ;
1125
{ sp -= 2; mpz_powm (sp, sp, sp+1, sp+2); ;
1129
{ sp--; CHECK_UI ("nth-root", sp+1);
1130
mpz_root (sp, sp, mpz_get_ui (sp+1)); ;
1134
{ mpz_sqrt (sp, sp); ;
1141
CHECK_VARIABLE (yyvsp[0].var);
1142
mpz_set (sp, variable[yyvsp[0].var]);
1150
if (mpz_set_str (sp, yyvsp[0].str, ibase) != 0)
1152
fprintf (stderr, "Invalid number: %s\n", yyvsp[0].str);
1159
{ sp--; mpz_gcd (sp, sp, sp+1); ;
1163
{ sp--; mpz_lcm (sp, sp, sp+1); ;
1166
/* the action file gets copied in in place of this dollarsign */
1167
#line 543 "/usr/share/misc/bison.simple"
1178
short *ssp1 = yyss - 1;
1179
fprintf (stderr, "state stack now");
1180
while (ssp1 != yyssp)
1181
fprintf (stderr, " %d", *++ssp1);
1182
fprintf (stderr, "\n");
1192
yylsp->first_line = yylloc.first_line;
1193
yylsp->first_column = yylloc.first_column;
1194
yylsp->last_line = (yylsp-1)->last_line;
1195
yylsp->last_column = (yylsp-1)->last_column;
1200
yylsp->last_line = (yylsp+yylen-1)->last_line;
1201
yylsp->last_column = (yylsp+yylen-1)->last_column;
1205
/* Now "shift" the result of the reduction.
1206
Determine what state that goes to,
1207
based on the state we popped back to
1208
and the rule number reduced by. */
1212
yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1213
if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1214
yystate = yytable[yystate];
1216
yystate = yydefgoto[yyn - YYNTBASE];
1220
yyerrlab: /* here on detecting error */
1223
/* If not already recovering from an error, report this error. */
1227
#ifdef YYERROR_VERBOSE
1228
yyn = yypact[yystate];
1230
if (yyn > YYFLAG && yyn < YYLAST)
1237
/* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1238
for (x = (yyn < 0 ? -yyn : 0);
1239
x < (sizeof(yytname) / sizeof(char *)); x++)
1240
if (yycheck[x + yyn] == x)
1241
size += strlen(yytname[x]) + 15, count++;
1242
msg = (char *) malloc(size + 15);
1245
strcpy(msg, "parse error");
1250
for (x = (yyn < 0 ? -yyn : 0);
1251
x < (sizeof(yytname) / sizeof(char *)); x++)
1252
if (yycheck[x + yyn] == x)
1254
strcat(msg, count == 0 ? ", expecting `" : " or `");
1255
strcat(msg, yytname[x]);
1264
yyerror ("parse error; also virtual memory exceeded");
1267
#endif /* YYERROR_VERBOSE */
1268
yyerror("parse error");
1272
yyerrlab1: /* here on error raised explicitly by an action */
1274
if (yyerrstatus == 3)
1276
/* if just tried and failed to reuse lookahead token after an error, discard it. */
1278
/* return failure if at end of input */
1279
if (yychar == YYEOF)
1284
fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1290
/* Else will try to reuse lookahead token
1291
after shifting the error token. */
1293
yyerrstatus = 3; /* Each real token shifted decrements this */
1297
yyerrdefault: /* current state does not do anything special for the error token. */
1300
/* This is wrong; only states that explicitly want error tokens
1301
should shift them. */
1302
yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1303
if (yyn) goto yydefault;
1306
yyerrpop: /* pop the current state because it cannot handle the error token */
1308
if (yyssp == yyss) YYABORT;
1318
short *ssp1 = yyss - 1;
1319
fprintf (stderr, "Error: state stack now");
1320
while (ssp1 != yyssp)
1321
fprintf (stderr, " %d", *++ssp1);
1322
fprintf (stderr, "\n");
1328
yyn = yypact[yystate];
1333
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1352
fprintf(stderr, "Shifting error token, ");
1364
/* YYACCEPT comes here. */
1376
/* YYABORT comes here. */
1392
fprintf (stderr, "%s\n", s);
1400
for (i = 0; i < numberof (variable); i++)
1401
mpz_init (variable[i]);
1403
for (i = 0; i < numberof (stack); i++)
1404
mpz_init (stack[i]);