~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gmp3/demos/calc/calc.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*  A Bison parser, made from calc.y
 
3
    by GNU Bison version 1.28  */
 
4
 
 
5
#define YYBISON 1  /* Identify Bison output.  */
 
6
 
 
7
#define EOS     257
 
8
#define BAD     258
 
9
#define HEX     259
 
10
#define DECIMAL 260
 
11
#define QUIT    261
 
12
#define ABS     262
 
13
#define BIN     263
 
14
#define FIB     264
 
15
#define GCD     265
 
16
#define KRON    266
 
17
#define LCM     267
 
18
#define NEXTPRIME       268
 
19
#define POWM    269
 
20
#define ROOT    270
 
21
#define SQRT    271
 
22
#define NUMBER  272
 
23
#define VARIABLE        273
 
24
#define LOR     274
 
25
#define LAND    275
 
26
#define EQ      276
 
27
#define NE      277
 
28
#define LE      278
 
29
#define GE      279
 
30
#define LSHIFT  280
 
31
#define RSHIFT  281
 
32
#define UMINUS  282
 
33
 
 
34
#line 1 "calc.y"
 
35
 
 
36
/* A simple integer desk calculator using yacc and gmp.
 
37
 
 
38
Copyright 2000, 2001 Free Software Foundation, Inc.
 
39
 
 
40
This file is part of the GNU MP Library.
 
41
 
 
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
 
45
version.
 
46
 
 
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.
 
50
 
 
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. */
 
54
 
 
55
 
 
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.
 
59
 
 
60
   Examples:
 
61
       2+3*4        expressions are evaluated
 
62
       x=5^6        variables a to z can be set and used
 
63
 
 
64
   Operators:
 
65
       + - *        arithmetic
 
66
       / %          division and remainder (rounding towards negative infinity)
 
67
       ^            exponentiation
 
68
       !            factorial
 
69
       << >>        left and right shifts
 
70
       <= >= >      \ comparisons, giving 1 if true, 0 if false
 
71
       == != <      /
 
72
       && ||        logical and/or, giving 1 if true, 0 if false
 
73
 
 
74
   Functions:
 
75
       abs(n)       absolute value
 
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
 
83
       root(n,r)    r-th root
 
84
       sqrt(n)      square root
 
85
 
 
86
   Other:
 
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
 
93
 
 
94
   Hex numbers must be entered in upper case, to distinguish them from the
 
95
   variables a to f (like in bc).
 
96
 
 
97
 
 
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.
 
102
 
 
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.
 
110
 
 
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).  */
 
117
 
 
118
 
 
119
#include <stdio.h>
 
120
#include <stdlib.h>
 
121
 
 
122
#include "gmp.h"
 
123
 
 
124
#define numberof(x)  (sizeof (x) / sizeof ((x)[0]))
 
125
 
 
126
 
 
127
int  ibase = 0;
 
128
int  obase = 10;
 
129
 
 
130
 
 
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
 
133
   dynamically.  */
 
134
 
 
135
mpz_t    stack[100];
 
136
mpz_ptr  sp = stack[0];
 
137
 
 
138
#define CHECK_OVERFLOW()                                                  \
 
139
  if (sp >= stack[numberof(stack)])                                       \
 
140
    {                                                                     \
 
141
      fprintf (stderr,                                                    \
 
142
               "Value stack overflow, too much nesting in expression\n"); \
 
143
      YYERROR;                                                            \
 
144
    }
 
145
 
 
146
#define CHECK_EMPTY()                                                   \
 
147
  if (sp != stack[0])                                                   \
 
148
    {                                                                   \
 
149
      fprintf (stderr, "Oops, expected the value stack to be empty\n"); \
 
150
      sp = stack[0];                                                    \
 
151
    }
 
152
 
 
153
 
 
154
mpz_t  variable[26];
 
155
 
 
156
#define CHECK_VARIABLE(var)                                             \
 
157
  if ((var) < 0 || (var) >= numberof (variable))                        \
 
158
    {                                                                   \
 
159
      fprintf (stderr, "Oops, bad variable somehow: %d\n", var);        \
 
160
      YYERROR;                                                          \
 
161
    }
 
162
 
 
163
 
 
164
#define CHECK_UI(name,z)                                                   \
 
165
  if (! mpz_fits_ulong_p (z))                                              \
 
166
    {                                                                      \
 
167
      fprintf (stderr,                                                     \
 
168
               "Operand must fit in an \"unsigned long\" for %s\n", name); \
 
169
      YYERROR;                                                             \
 
170
    }
 
171
 
 
172
 
 
173
#line 140 "calc.y"
 
174
typedef union {
 
175
  char  *str;
 
176
  int   var;
 
177
} YYSTYPE;
 
178
#include <stdio.h>
 
179
 
 
180
#ifndef __cplusplus
 
181
#ifndef __STDC__
 
182
#define const
 
183
#endif
 
184
#endif
 
185
 
 
186
 
 
187
 
 
188
#define YYFINAL         113
 
189
#define YYFLAG          -32768
 
190
#define YYNTBASE        42
 
191
 
 
192
#define YYTRANSLATE(x) ((unsigned)(x) <= 282 ? yytranslate[x] : 48)
 
193
 
 
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,
 
223
    29,    35
 
224
};
 
225
 
 
226
#if YYDEBUG != 0
 
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
 
233
};
 
234
 
 
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
 
254
};
 
255
 
 
256
#endif
 
257
 
 
258
#if YYDEBUG != 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
 
265
};
 
266
#endif
 
267
 
 
268
 
 
269
#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
 
270
 
 
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
 
276
};
 
277
#endif
 
278
 
 
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
 
285
};
 
286
 
 
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,
 
292
     1,     1,     1,     3,     1,     3
 
293
};
 
294
 
 
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,
 
307
     0,     0,     0
 
308
};
 
309
 
 
310
static const short yydefgoto[] = {   111,
 
311
    19,    20,    21,    60,    63
 
312
};
 
313
 
 
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,
 
326
    87,    88,-32768
 
327
};
 
328
 
 
329
static const short yypgoto[] = {-32768,
 
330
-32768,    70,   -17,-32768,-32768
 
331
};
 
332
 
 
333
 
 
334
#define YYLAST          523
 
335
 
 
336
 
 
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,
 
390
     0,    54,    55
 
391
};
 
392
 
 
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,
 
446
    -1,    36,    37
 
447
};
 
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.  */
 
451
 
 
452
/* Skeleton output parser for bison,
 
453
   Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
 
454
 
 
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)
 
458
   any later version.
 
459
 
 
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.
 
464
 
 
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.  */
 
469
 
 
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.  */
 
474
 
 
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.  */
 
479
 
 
480
#ifndef YYSTACK_USE_ALLOCA
 
481
#ifdef alloca
 
482
#define YYSTACK_USE_ALLOCA
 
483
#else /* alloca not defined */
 
484
#ifdef __GNUC__
 
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
 
490
#include <alloca.h>
 
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.  */
 
498
#include <malloc.h>
 
499
#endif
 
500
#else /* not MSDOS, or __TURBOC__ */
 
501
#if defined(_AIX)
 
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>  */
 
505
 #pragma alloca
 
506
#define YYSTACK_USE_ALLOCA
 
507
#else /* not MSDOS, or __TURBOC__, or _AIX */
 
508
#if 0
 
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
 
513
#endif /* __hpux */
 
514
#endif
 
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 */
 
521
 
 
522
#ifdef YYSTACK_USE_ALLOCA
 
523
#define YYSTACK_ALLOC alloca
 
524
#else
 
525
#define YYSTACK_ALLOC malloc
 
526
#endif
 
527
 
 
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.  */
 
531
 
 
532
#define yyerrok         (yyerrstatus = 0)
 
533
#define yyclearin       (yychar = YYEMPTY)
 
534
#define YYEMPTY         -2
 
535
#define YYEOF           0
 
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) \
 
546
do                                                              \
 
547
  if (yychar == YYEMPTY && yylen == 1)                          \
 
548
    { yychar = (token), yylval = (value);                       \
 
549
      yychar1 = YYTRANSLATE (yychar);                           \
 
550
      YYPOPSTACK;                                               \
 
551
      goto yybackup;                                            \
 
552
    }                                                           \
 
553
  else                                                          \
 
554
    { yyerror ("syntax error: cannot back up"); YYERROR; }      \
 
555
while (0)
 
556
 
 
557
#define YYTERROR        1
 
558
#define YYERRCODE       256
 
559
 
 
560
#ifndef YYPURE
 
561
#define YYLEX           yylex()
 
562
#endif
 
563
 
 
564
#ifdef YYPURE
 
565
#ifdef YYLSP_NEEDED
 
566
#ifdef YYLEX_PARAM
 
567
#define YYLEX           yylex(&yylval, &yylloc, YYLEX_PARAM)
 
568
#else
 
569
#define YYLEX           yylex(&yylval, &yylloc)
 
570
#endif
 
571
#else /* not YYLSP_NEEDED */
 
572
#ifdef YYLEX_PARAM
 
573
#define YYLEX           yylex(&yylval, YYLEX_PARAM)
 
574
#else
 
575
#define YYLEX           yylex(&yylval)
 
576
#endif
 
577
#endif /* not YYLSP_NEEDED */
 
578
#endif
 
579
 
 
580
/* If nonreentrant, generate the variables here */
 
581
 
 
582
#ifndef YYPURE
 
583
 
 
584
int     yychar;                 /*  the lookahead symbol                */
 
585
YYSTYPE yylval;                 /*  the semantic value of the           */
 
586
                                /*  lookahead symbol                    */
 
587
 
 
588
#ifdef YYLSP_NEEDED
 
589
YYLTYPE yylloc;                 /*  location data for the lookahead     */
 
590
                                /*  symbol                              */
 
591
#endif
 
592
 
 
593
int yynerrs;                    /*  number of parse errors so far       */
 
594
#endif  /* not YYPURE */
 
595
 
 
596
#if YYDEBUG != 0
 
597
int yydebug;                    /*  nonzero means print parse trace     */
 
598
/* Since this is uninitialized, it does not stop multiple parsers
 
599
   from coexisting.  */
 
600
#endif
 
601
 
 
602
/*  YYINITDEPTH indicates the initial size of the parser's stacks       */
 
603
 
 
604
#ifndef YYINITDEPTH
 
605
#define YYINITDEPTH 200
 
606
#endif
 
607
 
 
608
/*  YYMAXDEPTH is the maximum size the stacks can grow to
 
609
    (effective only if the built-in stack extension method is used).  */
 
610
 
 
611
#if YYMAXDEPTH == 0
 
612
#undef YYMAXDEPTH
 
613
#endif
 
614
 
 
615
#ifndef YYMAXDEPTH
 
616
#define YYMAXDEPTH 10000
 
617
#endif
 
618
 
 
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.  */
 
623
 
 
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++ */
 
627
#ifndef __cplusplus
 
628
 
 
629
/* This is the most reliable way to avoid incompatibilities
 
630
   in available built-in functions on various systems.  */
 
631
static void
 
632
__yy_memcpy (to, from, count)
 
633
     char *to;
 
634
     char *from;
 
635
     unsigned int count;
 
636
{
 
637
  register char *f = from;
 
638
  register char *t = to;
 
639
  register int i = count;
 
640
 
 
641
  while (i-- > 0)
 
642
    *t++ = *f++;
 
643
}
 
644
 
 
645
#else /* __cplusplus */
 
646
 
 
647
/* This is the most reliable way to avoid incompatibilities
 
648
   in available built-in functions on various systems.  */
 
649
static void
 
650
__yy_memcpy (char *to, char *from, unsigned int count)
 
651
{
 
652
  register char *t = to;
 
653
  register char *f = from;
 
654
  register int i = count;
 
655
 
 
656
  while (i-- > 0)
 
657
    *t++ = *f++;
 
658
}
 
659
 
 
660
#endif
 
661
#endif
 
662
 
 
663
#line 217 "/usr/share/misc/bison.simple"
 
664
 
 
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.  */
 
670
 
 
671
#ifdef YYPARSE_PARAM
 
672
#ifdef __cplusplus
 
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 */
 
683
 
 
684
/* Prevent warning if -Wstrict-prototypes.  */
 
685
#ifdef __GNUC__
 
686
#ifdef YYPARSE_PARAM
 
687
int yyparse (void *);
 
688
#else
 
689
int yyparse (void);
 
690
#endif
 
691
#endif
 
692
 
 
693
int
 
694
yyparse(YYPARSE_PARAM_ARG)
 
695
     YYPARSE_PARAM_DECL
 
696
{
 
697
  register int yystate;
 
698
  register int yyn;
 
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 */
 
703
 
 
704
  short yyssa[YYINITDEPTH];     /*  the state stack                     */
 
705
  YYSTYPE yyvsa[YYINITDEPTH];   /*  the semantic value stack            */
 
706
 
 
707
  short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
 
708
  YYSTYPE *yyvs = yyvsa;        /*  to allow yyoverflow to reallocate them elsewhere */
 
709
 
 
710
#ifdef YYLSP_NEEDED
 
711
  YYLTYPE yylsa[YYINITDEPTH];   /*  the location stack                  */
 
712
  YYLTYPE *yyls = yylsa;
 
713
  YYLTYPE *yylsp;
 
714
 
 
715
#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
 
716
#else
 
717
#define YYPOPSTACK   (yyvsp--, yyssp--)
 
718
#endif
 
719
 
 
720
  int yystacksize = YYINITDEPTH;
 
721
  int yyfree_stacks = 0;
 
722
 
 
723
#ifdef YYPURE
 
724
  int yychar;
 
725
  YYSTYPE yylval;
 
726
  int yynerrs;
 
727
#ifdef YYLSP_NEEDED
 
728
  YYLTYPE yylloc;
 
729
#endif
 
730
#endif
 
731
 
 
732
  YYSTYPE yyval;                /*  the variable used to return         */
 
733
                                /*  semantic values from the action     */
 
734
                                /*  routines                            */
 
735
 
 
736
  int yylen;
 
737
 
 
738
#if YYDEBUG != 0
 
739
  if (yydebug)
 
740
    fprintf(stderr, "Starting parse\n");
 
741
#endif
 
742
 
 
743
  yystate = 0;
 
744
  yyerrstatus = 0;
 
745
  yynerrs = 0;
 
746
  yychar = YYEMPTY;             /* Cause a token to be read.  */
 
747
 
 
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.  */
 
752
 
 
753
  yyssp = yyss - 1;
 
754
  yyvsp = yyvs;
 
755
#ifdef YYLSP_NEEDED
 
756
  yylsp = yyls;
 
757
#endif
 
758
 
 
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.  */
 
762
yynewstate:
 
763
 
 
764
  *++yyssp = yystate;
 
765
 
 
766
  if (yyssp >= yyss + yystacksize - 1)
 
767
    {
 
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;
 
771
      short *yyss1 = yyss;
 
772
#ifdef YYLSP_NEEDED
 
773
      YYLTYPE *yyls1 = yyls;
 
774
#endif
 
775
 
 
776
      /* Get the current used size of the three stacks, in elements.  */
 
777
      int size = yyssp - yyss + 1;
 
778
 
 
779
#ifdef yyoverflow
 
780
      /* Each stack pointer address is followed by the size of
 
781
         the data in use in that stack, in bytes.  */
 
782
#ifdef YYLSP_NEEDED
 
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),
 
789
                 &yystacksize);
 
790
#else
 
791
      yyoverflow("parser stack overflow",
 
792
                 &yyss1, size * sizeof (*yyssp),
 
793
                 &yyvs1, size * sizeof (*yyvsp),
 
794
                 &yystacksize);
 
795
#endif
 
796
 
 
797
      yyss = yyss1; yyvs = yyvs1;
 
798
#ifdef YYLSP_NEEDED
 
799
      yyls = yyls1;
 
800
#endif
 
801
#else /* no yyoverflow */
 
802
      /* Extend the stack our own way.  */
 
803
      if (yystacksize >= YYMAXDEPTH)
 
804
        {
 
805
          yyerror("parser stack overflow");
 
806
          if (yyfree_stacks)
 
807
            {
 
808
              free (yyss);
 
809
              free (yyvs);
 
810
#ifdef YYLSP_NEEDED
 
811
              free (yyls);
 
812
#endif
 
813
            }
 
814
          return 2;
 
815
        }
 
816
      yystacksize *= 2;
 
817
      if (yystacksize > YYMAXDEPTH)
 
818
        yystacksize = YYMAXDEPTH;
 
819
#ifndef YYSTACK_USE_ALLOCA
 
820
      yyfree_stacks = 1;
 
821
#endif
 
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));
 
828
#ifdef YYLSP_NEEDED
 
829
      yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
 
830
      __yy_memcpy ((char *)yyls, (char *)yyls1,
 
831
                   size * (unsigned int) sizeof (*yylsp));
 
832
#endif
 
833
#endif /* no yyoverflow */
 
834
 
 
835
      yyssp = yyss + size - 1;
 
836
      yyvsp = yyvs + size - 1;
 
837
#ifdef YYLSP_NEEDED
 
838
      yylsp = yyls + size - 1;
 
839
#endif
 
840
 
 
841
#if YYDEBUG != 0
 
842
      if (yydebug)
 
843
        fprintf(stderr, "Stack size increased to %d\n", yystacksize);
 
844
#endif
 
845
 
 
846
      if (yyssp >= yyss + yystacksize - 1)
 
847
        YYABORT;
 
848
    }
 
849
 
 
850
#if YYDEBUG != 0
 
851
  if (yydebug)
 
852
    fprintf(stderr, "Entering state %d\n", yystate);
 
853
#endif
 
854
 
 
855
  goto yybackup;
 
856
 yybackup:
 
857
 
 
858
/* Do appropriate processing given the current state.  */
 
859
/* Read a lookahead token if we need one and don't already have one.  */
 
860
/* yyresume: */
 
861
 
 
862
  /* First try to decide what to do without reference to lookahead token.  */
 
863
 
 
864
  yyn = yypact[yystate];
 
865
  if (yyn == YYFLAG)
 
866
    goto yydefault;
 
867
 
 
868
  /* Not known => get a lookahead token if don't already have one.  */
 
869
 
 
870
  /* yychar is either YYEMPTY or YYEOF
 
871
     or a valid token in external form.  */
 
872
 
 
873
  if (yychar == YYEMPTY)
 
874
    {
 
875
#if YYDEBUG != 0
 
876
      if (yydebug)
 
877
        fprintf(stderr, "Reading a token: ");
 
878
#endif
 
879
      yychar = YYLEX;
 
880
    }
 
881
 
 
882
  /* Convert token to internal form (in yychar1) for indexing tables with */
 
883
 
 
884
  if (yychar <= 0)              /* This means end of input. */
 
885
    {
 
886
      yychar1 = 0;
 
887
      yychar = YYEOF;           /* Don't call YYLEX any more */
 
888
 
 
889
#if YYDEBUG != 0
 
890
      if (yydebug)
 
891
        fprintf(stderr, "Now at end of input.\n");
 
892
#endif
 
893
    }
 
894
  else
 
895
    {
 
896
      yychar1 = YYTRANSLATE(yychar);
 
897
 
 
898
#if YYDEBUG != 0
 
899
      if (yydebug)
 
900
        {
 
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.  */
 
904
#ifdef YYPRINT
 
905
          YYPRINT (stderr, yychar, yylval);
 
906
#endif
 
907
          fprintf (stderr, ")\n");
 
908
        }
 
909
#endif
 
910
    }
 
911
 
 
912
  yyn += yychar1;
 
913
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
 
914
    goto yydefault;
 
915
 
 
916
  yyn = yytable[yyn];
 
917
 
 
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,
 
922
       just return success.
 
923
     0, or most negative number => error.  */
 
924
 
 
925
  if (yyn < 0)
 
926
    {
 
927
      if (yyn == YYFLAG)
 
928
        goto yyerrlab;
 
929
      yyn = -yyn;
 
930
      goto yyreduce;
 
931
    }
 
932
  else if (yyn == 0)
 
933
    goto yyerrlab;
 
934
 
 
935
  if (yyn == YYFINAL)
 
936
    YYACCEPT;
 
937
 
 
938
  /* Shift the lookahead token.  */
 
939
 
 
940
#if YYDEBUG != 0
 
941
  if (yydebug)
 
942
    fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
 
943
#endif
 
944
 
 
945
  /* Discard the token being shifted unless it is eof.  */
 
946
  if (yychar != YYEOF)
 
947
    yychar = YYEMPTY;
 
948
 
 
949
  *++yyvsp = yylval;
 
950
#ifdef YYLSP_NEEDED
 
951
  *++yylsp = yylloc;
 
952
#endif
 
953
 
 
954
  /* count tokens shifted since error; after three, turn off error status.  */
 
955
  if (yyerrstatus) yyerrstatus--;
 
956
 
 
957
  yystate = yyn;
 
958
  goto yynewstate;
 
959
 
 
960
/* Do the default action for the current state.  */
 
961
yydefault:
 
962
 
 
963
  yyn = yydefact[yystate];
 
964
  if (yyn == 0)
 
965
    goto yyerrlab;
 
966
 
 
967
/* Do a reduction.  yyn is the number of a rule to reduce with.  */
 
968
yyreduce:
 
969
  yylen = yyr2[yyn];
 
970
  if (yylen > 0)
 
971
    yyval = yyvsp[1-yylen]; /* implement default value of the action */
 
972
 
 
973
#if YYDEBUG != 0
 
974
  if (yydebug)
 
975
    {
 
976
      int i;
 
977
 
 
978
      fprintf (stderr, "Reducing via rule %d (line %d), ",
 
979
               yyn, yyrline[yyn]);
 
980
 
 
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]]);
 
985
    }
 
986
#endif
 
987
 
 
988
 
 
989
  switch (yyn) {
 
990
 
 
991
case 5:
 
992
#line 171 "calc.y"
 
993
{ sp = stack[0]; yyerrok; ;
 
994
    break;}
 
995
case 7:
 
996
#line 175 "calc.y"
 
997
{
 
998
      mpz_out_str (stdout, obase, sp); putchar ('\n');
 
999
      sp--;
 
1000
      CHECK_EMPTY ();
 
1001
    ;
 
1002
    break;}
 
1003
case 8:
 
1004
#line 180 "calc.y"
 
1005
{
 
1006
      CHECK_VARIABLE (yyvsp[-2].var);
 
1007
      mpz_swap (variable[yyvsp[-2].var], sp);
 
1008
      sp--;
 
1009
      CHECK_EMPTY ();
 
1010
    ;
 
1011
    break;}
 
1012
case 9:
 
1013
#line 186 "calc.y"
 
1014
{ ibase = 16; obase = -16; ;
 
1015
    break;}
 
1016
case 10:
 
1017
#line 187 "calc.y"
 
1018
{ ibase = 0;  obase = 10; ;
 
1019
    break;}
 
1020
case 11:
 
1021
#line 188 "calc.y"
 
1022
{ exit (0); ;
 
1023
    break;}
 
1024
case 13:
 
1025
#line 195 "calc.y"
 
1026
{ sp--; mpz_add    (sp, sp, sp+1); ;
 
1027
    break;}
 
1028
case 14:
 
1029
#line 196 "calc.y"
 
1030
{ sp--; mpz_sub    (sp, sp, sp+1); ;
 
1031
    break;}
 
1032
case 15:
 
1033
#line 197 "calc.y"
 
1034
{ sp--; mpz_mul    (sp, sp, sp+1); ;
 
1035
    break;}
 
1036
case 16:
 
1037
#line 198 "calc.y"
 
1038
{ sp--; mpz_fdiv_q (sp, sp, sp+1); ;
 
1039
    break;}
 
1040
case 17:
 
1041
#line 199 "calc.y"
 
1042
{ sp--; mpz_fdiv_r (sp, sp, sp+1); ;
 
1043
    break;}
 
1044
case 18:
 
1045
#line 200 "calc.y"
 
1046
{ CHECK_UI ("exponentiation", sp);
 
1047
                     sp--; mpz_pow_ui (sp, sp, mpz_get_ui (sp+1)); ;
 
1048
    break;}
 
1049
case 19:
 
1050
#line 202 "calc.y"
 
1051
{ CHECK_UI ("lshift", sp);
 
1052
                     sp--; mpz_mul_2exp (sp, sp, mpz_get_ui (sp+1)); ;
 
1053
    break;}
 
1054
case 20:
 
1055
#line 204 "calc.y"
 
1056
{ CHECK_UI ("rshift", sp);
 
1057
                     sp--; mpz_fdiv_q_2exp (sp, sp, mpz_get_ui (sp+1)); ;
 
1058
    break;}
 
1059
case 21:
 
1060
#line 206 "calc.y"
 
1061
{ CHECK_UI ("factorial", sp);
 
1062
                     mpz_fac_ui (sp, mpz_get_ui (sp)); ;
 
1063
    break;}
 
1064
case 22:
 
1065
#line 208 "calc.y"
 
1066
{ mpz_neg (sp, sp); ;
 
1067
    break;}
 
1068
case 23:
 
1069
#line 210 "calc.y"
 
1070
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) <  0); ;
 
1071
    break;}
 
1072
case 24:
 
1073
#line 211 "calc.y"
 
1074
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) <= 0); ;
 
1075
    break;}
 
1076
case 25:
 
1077
#line 212 "calc.y"
 
1078
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) == 0); ;
 
1079
    break;}
 
1080
case 26:
 
1081
#line 213 "calc.y"
 
1082
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) != 0); ;
 
1083
    break;}
 
1084
case 27:
 
1085
#line 214 "calc.y"
 
1086
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) >= 0); ;
 
1087
    break;}
 
1088
case 28:
 
1089
#line 215 "calc.y"
 
1090
{ sp--; mpz_set_ui (sp, mpz_cmp (sp, sp+1) >  0); ;
 
1091
    break;}
 
1092
case 29:
 
1093
#line 217 "calc.y"
 
1094
{ sp--; mpz_set_ui (sp, mpz_sgn (sp) && mpz_sgn (sp+1)); ;
 
1095
    break;}
 
1096
case 30:
 
1097
#line 218 "calc.y"
 
1098
{ sp--; mpz_set_ui (sp, mpz_sgn (sp) || mpz_sgn (sp+1)); ;
 
1099
    break;}
 
1100
case 31:
 
1101
#line 220 "calc.y"
 
1102
{ mpz_abs (sp, sp); ;
 
1103
    break;}
 
1104
case 32:
 
1105
#line 221 "calc.y"
 
1106
{ sp--; CHECK_UI ("binomial", sp+1);
 
1107
                                    mpz_bin_ui (sp, sp, mpz_get_ui (sp+1)); ;
 
1108
    break;}
 
1109
case 33:
 
1110
#line 223 "calc.y"
 
1111
{ CHECK_UI ("fibonacci", sp);
 
1112
                                    mpz_fib_ui (sp, mpz_get_ui (sp)); ;
 
1113
    break;}
 
1114
case 35:
 
1115
#line 226 "calc.y"
 
1116
{ sp--; mpz_set_si (sp,
 
1117
                                          mpz_kronecker (sp, sp+1)); ;
 
1118
    break;}
 
1119
case 37:
 
1120
#line 229 "calc.y"
 
1121
{ mpz_nextprime (sp, sp); ;
 
1122
    break;}
 
1123
case 38:
 
1124
#line 230 "calc.y"
 
1125
{ sp -= 2; mpz_powm (sp, sp, sp+1, sp+2); ;
 
1126
    break;}
 
1127
case 39:
 
1128
#line 231 "calc.y"
 
1129
{ sp--; CHECK_UI ("nth-root", sp+1);
 
1130
                                    mpz_root (sp, sp, mpz_get_ui (sp+1)); ;
 
1131
    break;}
 
1132
case 40:
 
1133
#line 233 "calc.y"
 
1134
{ mpz_sqrt (sp, sp); ;
 
1135
    break;}
 
1136
case 41:
 
1137
#line 235 "calc.y"
 
1138
{
 
1139
        sp++;
 
1140
        CHECK_OVERFLOW ();
 
1141
        CHECK_VARIABLE (yyvsp[0].var);
 
1142
        mpz_set (sp, variable[yyvsp[0].var]);
 
1143
      ;
 
1144
    break;}
 
1145
case 42:
 
1146
#line 241 "calc.y"
 
1147
{
 
1148
        sp++;
 
1149
        CHECK_OVERFLOW ();
 
1150
        if (mpz_set_str (sp, yyvsp[0].str, ibase) != 0)
 
1151
          {
 
1152
            fprintf (stderr, "Invalid number: %s\n", yyvsp[0].str);
 
1153
            YYERROR;
 
1154
          }
 
1155
      ;
 
1156
    break;}
 
1157
case 44:
 
1158
#line 253 "calc.y"
 
1159
{ sp--; mpz_gcd (sp, sp, sp+1); ;
 
1160
    break;}
 
1161
case 46:
 
1162
#line 257 "calc.y"
 
1163
{ sp--; mpz_lcm (sp, sp, sp+1); ;
 
1164
    break;}
 
1165
}
 
1166
   /* the action file gets copied in in place of this dollarsign */
 
1167
#line 543 "/usr/share/misc/bison.simple"
 
1168
 
 
1169
  yyvsp -= yylen;
 
1170
  yyssp -= yylen;
 
1171
#ifdef YYLSP_NEEDED
 
1172
  yylsp -= yylen;
 
1173
#endif
 
1174
 
 
1175
#if YYDEBUG != 0
 
1176
  if (yydebug)
 
1177
    {
 
1178
      short *ssp1 = yyss - 1;
 
1179
      fprintf (stderr, "state stack now");
 
1180
      while (ssp1 != yyssp)
 
1181
        fprintf (stderr, " %d", *++ssp1);
 
1182
      fprintf (stderr, "\n");
 
1183
    }
 
1184
#endif
 
1185
 
 
1186
  *++yyvsp = yyval;
 
1187
 
 
1188
#ifdef YYLSP_NEEDED
 
1189
  yylsp++;
 
1190
  if (yylen == 0)
 
1191
    {
 
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;
 
1196
      yylsp->text = 0;
 
1197
    }
 
1198
  else
 
1199
    {
 
1200
      yylsp->last_line = (yylsp+yylen-1)->last_line;
 
1201
      yylsp->last_column = (yylsp+yylen-1)->last_column;
 
1202
    }
 
1203
#endif
 
1204
 
 
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.  */
 
1209
 
 
1210
  yyn = yyr1[yyn];
 
1211
 
 
1212
  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
 
1213
  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
 
1214
    yystate = yytable[yystate];
 
1215
  else
 
1216
    yystate = yydefgoto[yyn - YYNTBASE];
 
1217
 
 
1218
  goto yynewstate;
 
1219
 
 
1220
yyerrlab:   /* here on detecting error */
 
1221
 
 
1222
  if (! yyerrstatus)
 
1223
    /* If not already recovering from an error, report this error.  */
 
1224
    {
 
1225
      ++yynerrs;
 
1226
 
 
1227
#ifdef YYERROR_VERBOSE
 
1228
      yyn = yypact[yystate];
 
1229
 
 
1230
      if (yyn > YYFLAG && yyn < YYLAST)
 
1231
        {
 
1232
          int size = 0;
 
1233
          char *msg;
 
1234
          int x, count;
 
1235
 
 
1236
          count = 0;
 
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);
 
1243
          if (msg != 0)
 
1244
            {
 
1245
              strcpy(msg, "parse error");
 
1246
 
 
1247
              if (count < 5)
 
1248
                {
 
1249
                  count = 0;
 
1250
                  for (x = (yyn < 0 ? -yyn : 0);
 
1251
                       x < (sizeof(yytname) / sizeof(char *)); x++)
 
1252
                    if (yycheck[x + yyn] == x)
 
1253
                      {
 
1254
                        strcat(msg, count == 0 ? ", expecting `" : " or `");
 
1255
                        strcat(msg, yytname[x]);
 
1256
                        strcat(msg, "'");
 
1257
                        count++;
 
1258
                      }
 
1259
                }
 
1260
              yyerror(msg);
 
1261
              free(msg);
 
1262
            }
 
1263
          else
 
1264
            yyerror ("parse error; also virtual memory exceeded");
 
1265
        }
 
1266
      else
 
1267
#endif /* YYERROR_VERBOSE */
 
1268
        yyerror("parse error");
 
1269
    }
 
1270
 
 
1271
  goto yyerrlab1;
 
1272
yyerrlab1:   /* here on error raised explicitly by an action */
 
1273
 
 
1274
  if (yyerrstatus == 3)
 
1275
    {
 
1276
      /* if just tried and failed to reuse lookahead token after an error, discard it.  */
 
1277
 
 
1278
      /* return failure if at end of input */
 
1279
      if (yychar == YYEOF)
 
1280
        YYABORT;
 
1281
 
 
1282
#if YYDEBUG != 0
 
1283
      if (yydebug)
 
1284
        fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
 
1285
#endif
 
1286
 
 
1287
      yychar = YYEMPTY;
 
1288
    }
 
1289
 
 
1290
  /* Else will try to reuse lookahead token
 
1291
     after shifting the error token.  */
 
1292
 
 
1293
  yyerrstatus = 3;              /* Each real token shifted decrements this */
 
1294
 
 
1295
  goto yyerrhandle;
 
1296
 
 
1297
yyerrdefault:  /* current state does not do anything special for the error token. */
 
1298
 
 
1299
#if 0
 
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;
 
1304
#endif
 
1305
 
 
1306
yyerrpop:   /* pop the current state because it cannot handle the error token */
 
1307
 
 
1308
  if (yyssp == yyss) YYABORT;
 
1309
  yyvsp--;
 
1310
  yystate = *--yyssp;
 
1311
#ifdef YYLSP_NEEDED
 
1312
  yylsp--;
 
1313
#endif
 
1314
 
 
1315
#if YYDEBUG != 0
 
1316
  if (yydebug)
 
1317
    {
 
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");
 
1323
    }
 
1324
#endif
 
1325
 
 
1326
yyerrhandle:
 
1327
 
 
1328
  yyn = yypact[yystate];
 
1329
  if (yyn == YYFLAG)
 
1330
    goto yyerrdefault;
 
1331
 
 
1332
  yyn += YYTERROR;
 
1333
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
 
1334
    goto yyerrdefault;
 
1335
 
 
1336
  yyn = yytable[yyn];
 
1337
  if (yyn < 0)
 
1338
    {
 
1339
      if (yyn == YYFLAG)
 
1340
        goto yyerrpop;
 
1341
      yyn = -yyn;
 
1342
      goto yyreduce;
 
1343
    }
 
1344
  else if (yyn == 0)
 
1345
    goto yyerrpop;
 
1346
 
 
1347
  if (yyn == YYFINAL)
 
1348
    YYACCEPT;
 
1349
 
 
1350
#if YYDEBUG != 0
 
1351
  if (yydebug)
 
1352
    fprintf(stderr, "Shifting error token, ");
 
1353
#endif
 
1354
 
 
1355
  *++yyvsp = yylval;
 
1356
#ifdef YYLSP_NEEDED
 
1357
  *++yylsp = yylloc;
 
1358
#endif
 
1359
 
 
1360
  yystate = yyn;
 
1361
  goto yynewstate;
 
1362
 
 
1363
 yyacceptlab:
 
1364
  /* YYACCEPT comes here.  */
 
1365
  if (yyfree_stacks)
 
1366
    {
 
1367
      free (yyss);
 
1368
      free (yyvs);
 
1369
#ifdef YYLSP_NEEDED
 
1370
      free (yyls);
 
1371
#endif
 
1372
    }
 
1373
  return 0;
 
1374
 
 
1375
 yyabortlab:
 
1376
  /* YYABORT comes here.  */
 
1377
  if (yyfree_stacks)
 
1378
    {
 
1379
      free (yyss);
 
1380
      free (yyvs);
 
1381
#ifdef YYLSP_NEEDED
 
1382
      free (yyls);
 
1383
#endif
 
1384
    }
 
1385
  return 1;
 
1386
}
 
1387
#line 259 "calc.y"
 
1388
 
 
1389
 
 
1390
yyerror (char *s)
 
1391
{
 
1392
  fprintf (stderr, "%s\n", s);
 
1393
}
 
1394
 
 
1395
int
 
1396
main (void)
 
1397
{
 
1398
  int  i;
 
1399
 
 
1400
  for (i = 0; i < numberof (variable); i++)
 
1401
    mpz_init (variable[i]);
 
1402
 
 
1403
  for (i = 0; i < numberof (stack); i++)
 
1404
    mpz_init (stack[i]);
 
1405
 
 
1406
  return yyparse ();
 
1407
}