]> sourceware.org Git - glibc.git/blob - intl/plural.c
Update from recent BSD source.
[glibc.git] / intl / plural.c
1
2 /* A Bison parser, made from plural.y
3 by GNU Bison version 1.28 */
4
5 #define YYBISON 1 /* Identify Bison output. */
6
7 #define yyparse __gettextparse
8 #define yylex __gettextlex
9 #define yyerror __gettexterror
10 #define yylval __gettextlval
11 #define yychar __gettextchar
12 #define yydebug __gettextdebug
13 #define yynerrs __gettextnerrs
14 #define EQUOP2 257
15 #define CMPOP2 258
16 #define ADDOP2 259
17 #define MULOP2 260
18 #define NUMBER 261
19
20 #line 1 "plural.y"
21
22 /* Expression parsing for plural form selection.
23 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
24 This file is part of the GNU C Library.
25 Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
26
27 The GNU C Library is free software; you can redistribute it and/or
28 modify it under the terms of the GNU Lesser General Public
29 License as published by the Free Software Foundation; either
30 version 2.1 of the License, or (at your option) any later version.
31
32 The GNU C Library is distributed in the hope that it will be useful,
33 but WITHOUT ANY WARRANTY; without even the implied warranty of
34 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 Lesser General Public License for more details.
36
37 You should have received a copy of the GNU Lesser General Public
38 License along with the GNU C Library; if not, write to the Free
39 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
40 02111-1307 USA. */
41
42 #ifdef HAVE_CONFIG_H
43 # include <config.h>
44 #endif
45
46 #include <stdlib.h>
47 #include "gettextP.h"
48
49 /* Names for the libintl functions are a problem. They must not clash
50 with existing names and they should follow ANSI C. But this source
51 code is also used in GNU C Library where the names have a __
52 prefix. So we have to make a difference here. */
53 #ifdef _LIBC
54 # define FREE_EXPRESSION __gettext_free_exp
55 #else
56 # define FREE_EXPRESSION gettext_free_exp__
57 # define __gettextparse gettextparse__
58 #endif
59
60 #define YYLEX_PARAM &((struct parse_args *) arg)->cp
61 #define YYPARSE_PARAM arg
62
63 #line 46 "plural.y"
64 typedef union {
65 unsigned long int num;
66 enum operator op;
67 struct expression *exp;
68 } YYSTYPE;
69 #line 52 "plural.y"
70
71 /* Prototypes for local functions. */
72 static struct expression *new_exp PARAMS ((int nargs, enum operator op,
73 struct expression * const *args));
74 static inline struct expression *new_exp_0 PARAMS ((enum operator op));
75 static inline struct expression *new_exp_1 PARAMS ((enum operator op,
76 struct expression *right));
77 static struct expression *new_exp_2 PARAMS ((enum operator op,
78 struct expression *left,
79 struct expression *right));
80 static inline struct expression *new_exp_3 PARAMS ((enum operator op,
81 struct expression *bexp,
82 struct expression *tbranch,
83 struct expression *fbranch));
84 static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
85 static void yyerror PARAMS ((const char *str));
86
87 /* Allocation of expressions. */
88
89 static struct expression *
90 new_exp (nargs, op, args)
91 int nargs;
92 enum operator op;
93 struct expression * const *args;
94 {
95 int i;
96 struct expression *newp;
97
98 /* If any of the argument could not be malloc'ed, just return NULL. */
99 for (i = nargs - 1; i >= 0; i--)
100 if (args[i] == NULL)
101 goto fail;
102
103 /* Allocate a new expression. */
104 newp = (struct expression *) malloc (sizeof (*newp));
105 if (newp != NULL)
106 {
107 newp->nargs = nargs;
108 newp->operation = op;
109 for (i = nargs - 1; i >= 0; i--)
110 newp->val.args[i] = args[i];
111 return newp;
112 }
113
114 fail:
115 for (i = nargs - 1; i >= 0; i--)
116 FREE_EXPRESSION (args[i]);
117
118 return NULL;
119 }
120
121 static inline struct expression *
122 new_exp_0 (op)
123 enum operator op;
124 {
125 return new_exp (0, op, NULL);
126 }
127
128 static inline struct expression *
129 new_exp_1 (op, right)
130 enum operator op;
131 struct expression *right;
132 {
133 struct expression *args[1];
134
135 args[0] = right;
136 return new_exp (1, op, args);
137 }
138
139 static struct expression *
140 new_exp_2 (op, left, right)
141 enum operator op;
142 struct expression *left;
143 struct expression *right;
144 {
145 struct expression *args[2];
146
147 args[0] = left;
148 args[1] = right;
149 return new_exp (2, op, args);
150 }
151
152 static inline struct expression *
153 new_exp_3 (op, bexp, tbranch, fbranch)
154 enum operator op;
155 struct expression *bexp;
156 struct expression *tbranch;
157 struct expression *fbranch;
158 {
159 struct expression *args[3];
160
161 args[0] = bexp;
162 args[1] = tbranch;
163 args[2] = fbranch;
164 return new_exp (3, op, args);
165 }
166
167 #include <stdio.h>
168
169 #ifndef __cplusplus
170 #ifndef __STDC__
171 #define const
172 #endif
173 #endif
174
175
176
177 #define YYFINAL 27
178 #define YYFLAG -32768
179 #define YYNTBASE 16
180
181 #define YYTRANSLATE(x) ((unsigned)(x) <= 261 ? yytranslate[x] : 18)
182
183 static const char yytranslate[] = { 0,
184 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
185 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
186 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
187 2, 2, 10, 2, 2, 2, 2, 5, 2, 14,
188 15, 2, 2, 2, 2, 2, 2, 2, 2, 2,
189 2, 2, 2, 2, 2, 2, 2, 12, 2, 2,
190 2, 2, 3, 2, 2, 2, 2, 2, 2, 2,
191 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
193 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
194 2, 2, 2, 2, 2, 2, 2, 2, 2, 13,
195 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
196 2, 2, 2, 4, 2, 2, 2, 2, 2, 2,
197 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
198 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
199 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
200 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
201 2, 2, 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, 2, 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, 1, 6, 7, 8, 9,
210 11
211 };
212
213 #if YYDEBUG != 0
214 static const short yyprhs[] = { 0,
215 0, 2, 8, 12, 16, 20, 24, 28, 32, 35,
216 37, 39
217 };
218
219 static const short yyrhs[] = { 17,
220 0, 17, 3, 17, 12, 17, 0, 17, 4, 17,
221 0, 17, 5, 17, 0, 17, 6, 17, 0, 17,
222 7, 17, 0, 17, 8, 17, 0, 17, 9, 17,
223 0, 10, 17, 0, 13, 0, 11, 0, 14, 17,
224 15, 0
225 };
226
227 #endif
228
229 #if YYDEBUG != 0
230 static const short yyrline[] = { 0,
231 171, 179, 183, 187, 191, 195, 199, 203, 207, 211,
232 215, 220
233 };
234 #endif
235
236
237 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
238
239 static const char * const yytname[] = { "$","error","$undefined.","'?'","'|'",
240 "'&'","EQUOP2","CMPOP2","ADDOP2","MULOP2","'!'","NUMBER","':'","'n'","'('","')'",
241 "start","exp", NULL
242 };
243 #endif
244
245 static const short yyr1[] = { 0,
246 16, 17, 17, 17, 17, 17, 17, 17, 17, 17,
247 17, 17
248 };
249
250 static const short yyr2[] = { 0,
251 1, 5, 3, 3, 3, 3, 3, 3, 2, 1,
252 1, 3
253 };
254
255 static const short yydefact[] = { 0,
256 0, 11, 10, 0, 1, 9, 0, 0, 0, 0,
257 0, 0, 0, 0, 12, 0, 3, 4, 5, 6,
258 7, 8, 0, 2, 0, 0, 0
259 };
260
261 static const short yydefgoto[] = { 25,
262 5
263 };
264
265 static const short yypact[] = { -9,
266 -9,-32768,-32768, -9, 34,-32768, 11, -9, -9, -9,
267 -9, -9, -9, -9,-32768, 24, 39, 43, 16, 26,
268 -3,-32768, -9, 34, 21, 53,-32768
269 };
270
271 static const short yypgoto[] = {-32768,
272 -1
273 };
274
275
276 #define YYLAST 53
277
278
279 static const short yytable[] = { 6,
280 1, 2, 7, 3, 4, 14, 16, 17, 18, 19,
281 20, 21, 22, 8, 9, 10, 11, 12, 13, 14,
282 26, 24, 12, 13, 14, 15, 8, 9, 10, 11,
283 12, 13, 14, 13, 14, 23, 8, 9, 10, 11,
284 12, 13, 14, 10, 11, 12, 13, 14, 11, 12,
285 13, 14, 27
286 };
287
288 static const short yycheck[] = { 1,
289 10, 11, 4, 13, 14, 9, 8, 9, 10, 11,
290 12, 13, 14, 3, 4, 5, 6, 7, 8, 9,
291 0, 23, 7, 8, 9, 15, 3, 4, 5, 6,
292 7, 8, 9, 8, 9, 12, 3, 4, 5, 6,
293 7, 8, 9, 5, 6, 7, 8, 9, 6, 7,
294 8, 9, 0
295 };
296 #define YYPURE 1
297
298 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
299 #line 3 "/usr/share/bison.simple"
300 /* This file comes from bison-1.28. */
301
302 /* Skeleton output parser for bison,
303 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
304
305 This program is free software; you can redistribute it and/or modify
306 it under the terms of the GNU General Public License as published by
307 the Free Software Foundation; either version 2, or (at your option)
308 any later version.
309
310 This program is distributed in the hope that it will be useful,
311 but WITHOUT ANY WARRANTY; without even the implied warranty of
312 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
313 GNU General Public License for more details.
314
315 You should have received a copy of the GNU General Public License
316 along with this program; if not, write to the Free Software
317 Foundation, Inc., 59 Temple Place - Suite 330,
318 Boston, MA 02111-1307, USA. */
319
320 /* As a special exception, when this file is copied by Bison into a
321 Bison output file, you may use that output file without restriction.
322 This special exception was added by the Free Software Foundation
323 in version 1.24 of Bison. */
324
325 /* This is the parser code that is written into each bison parser
326 when the %semantic_parser declaration is not specified in the grammar.
327 It was written by Richard Stallman by simplifying the hairy parser
328 used when %semantic_parser is specified. */
329
330 #ifndef YYPARSE_RETURN_TYPE
331 #define YYPARSE_RETURN_TYPE int
332 #endif
333
334
335 #ifndef YYSTACK_USE_ALLOCA
336 #ifdef alloca
337 #define YYSTACK_USE_ALLOCA
338 #else /* alloca not defined */
339 #ifdef __GNUC__
340 #define YYSTACK_USE_ALLOCA
341 #define alloca __builtin_alloca
342 #else /* not GNU C. */
343 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
344 #define YYSTACK_USE_ALLOCA
345 #include <alloca.h>
346 #else /* not sparc */
347 /* We think this test detects Watcom and Microsoft C. */
348 /* This used to test MSDOS, but that is a bad idea
349 since that symbol is in the user namespace. */
350 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
351 #if 0 /* No need for malloc.h, which pollutes the namespace;
352 instead, just don't use alloca. */
353 #include <malloc.h>
354 #endif
355 #else /* not MSDOS, or __TURBOC__ */
356 #if defined(_AIX)
357 /* I don't know what this was needed for, but it pollutes the namespace.
358 So I turned it off. rms, 2 May 1997. */
359 /* #include <malloc.h> */
360 #pragma alloca
361 #define YYSTACK_USE_ALLOCA
362 #else /* not MSDOS, or __TURBOC__, or _AIX */
363 #if 0
364 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
365 and on HPUX 10. Eventually we can turn this on. */
366 #define YYSTACK_USE_ALLOCA
367 #define alloca __builtin_alloca
368 #endif /* __hpux */
369 #endif
370 #endif /* not _AIX */
371 #endif /* not MSDOS, or __TURBOC__ */
372 #endif /* not sparc */
373 #endif /* not GNU C */
374 #endif /* alloca not defined */
375 #endif /* YYSTACK_USE_ALLOCA not defined */
376
377 #ifdef YYSTACK_USE_ALLOCA
378 #define YYSTACK_ALLOC alloca
379 #else
380 #define YYSTACK_ALLOC malloc
381 #endif
382
383 /* Note: there must be only one dollar sign in this file.
384 It is replaced by the list of actions, each action
385 as one case of the switch. */
386
387 #define yyerrok (yyerrstatus = 0)
388 #define yyclearin (yychar = YYEMPTY)
389 #define YYEMPTY -2
390 #define YYEOF 0
391 #define YYACCEPT goto yyacceptlab
392 #define YYABORT goto yyabortlab
393 #define YYERROR goto yyerrlab1
394 /* Like YYERROR except do call yyerror.
395 This remains here temporarily to ease the
396 transition to the new meaning of YYERROR, for GCC.
397 Once GCC version 2 has supplanted version 1, this can go. */
398 #define YYFAIL goto yyerrlab
399 #define YYRECOVERING() (!!yyerrstatus)
400 #define YYBACKUP(token, value) \
401 do \
402 if (yychar == YYEMPTY && yylen == 1) \
403 { yychar = (token), yylval = (value); \
404 yychar1 = YYTRANSLATE (yychar); \
405 YYPOPSTACK; \
406 goto yybackup; \
407 } \
408 else \
409 { yyerror ("syntax error: cannot back up"); YYERROR; } \
410 while (0)
411
412 #define YYTERROR 1
413 #define YYERRCODE 256
414
415 #ifndef YYPURE
416 #define YYLEX yylex()
417 #endif
418
419 #ifdef YYPURE
420 #ifdef YYLSP_NEEDED
421 #ifdef YYLEX_PARAM
422 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
423 #else
424 #define YYLEX yylex(&yylval, &yylloc)
425 #endif
426 #else /* not YYLSP_NEEDED */
427 #ifdef YYLEX_PARAM
428 #define YYLEX yylex(&yylval, YYLEX_PARAM)
429 #else
430 #define YYLEX yylex(&yylval)
431 #endif
432 #endif /* not YYLSP_NEEDED */
433 #endif
434
435 /* If nonreentrant, generate the variables here */
436
437 #ifndef YYPURE
438
439 int yychar; /* the lookahead symbol */
440 YYSTYPE yylval; /* the semantic value of the */
441 /* lookahead symbol */
442
443 #ifdef YYLSP_NEEDED
444 YYLTYPE yylloc; /* location data for the lookahead */
445 /* symbol */
446 #endif
447
448 int yynerrs; /* number of parse errors so far */
449 #endif /* not YYPURE */
450
451 #if YYDEBUG != 0
452 int yydebug; /* nonzero means print parse trace */
453 /* Since this is uninitialized, it does not stop multiple parsers
454 from coexisting. */
455 #endif
456
457 /* YYINITDEPTH indicates the initial size of the parser's stacks */
458
459 #ifndef YYINITDEPTH
460 #define YYINITDEPTH 200
461 #endif
462
463 /* YYMAXDEPTH is the maximum size the stacks can grow to
464 (effective only if the built-in stack extension method is used). */
465
466 #if YYMAXDEPTH == 0
467 #undef YYMAXDEPTH
468 #endif
469
470 #ifndef YYMAXDEPTH
471 #define YYMAXDEPTH 10000
472 #endif
473 \f
474 /* Define __yy_memcpy. Note that the size argument
475 should be passed with type unsigned int, because that is what the non-GCC
476 definitions require. With GCC, __builtin_memcpy takes an arg
477 of type size_t, but it can handle unsigned int. */
478
479 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
480 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
481 #else /* not GNU C or C++ */
482 #ifndef __cplusplus
483
484 /* This is the most reliable way to avoid incompatibilities
485 in available built-in functions on various systems. */
486 static void
487 __yy_memcpy (to, from, count)
488 char *to;
489 char *from;
490 unsigned int count;
491 {
492 register char *f = from;
493 register char *t = to;
494 register int i = count;
495
496 while (i-- > 0)
497 *t++ = *f++;
498 }
499
500 #else /* __cplusplus */
501
502 /* This is the most reliable way to avoid incompatibilities
503 in available built-in functions on various systems. */
504 static void
505 __yy_memcpy (char *to, char *from, unsigned int count)
506 {
507 register char *t = to;
508 register char *f = from;
509 register int i = count;
510
511 while (i-- > 0)
512 *t++ = *f++;
513 }
514
515 #endif
516 #endif
517 \f
518 #line 222 "/usr/share/bison.simple"
519
520 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
521 into yyparse. The argument should have type void *.
522 It should actually point to an object.
523 Grammar actions can access the variable by casting it
524 to the proper pointer type. */
525
526 #ifdef YYPARSE_PARAM
527 #ifdef __cplusplus
528 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
529 #define YYPARSE_PARAM_DECL
530 #else /* not __cplusplus */
531 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
532 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
533 #endif /* not __cplusplus */
534 #else /* not YYPARSE_PARAM */
535 #define YYPARSE_PARAM_ARG
536 #define YYPARSE_PARAM_DECL
537 #endif /* not YYPARSE_PARAM */
538
539 /* Prevent warning if -Wstrict-prototypes. */
540 #ifdef __GNUC__
541 #ifdef YYPARSE_PARAM
542 YYPARSE_RETURN_TYPE
543 yyparse (void *);
544 #else
545 YYPARSE_RETURN_TYPE
546 yyparse (void);
547 #endif
548 #endif
549
550 YYPARSE_RETURN_TYPE
551 yyparse(YYPARSE_PARAM_ARG)
552 YYPARSE_PARAM_DECL
553 {
554 register int yystate;
555 register int yyn;
556 register short *yyssp;
557 register YYSTYPE *yyvsp;
558 int yyerrstatus; /* number of tokens to shift before error messages enabled */
559 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
560
561 short yyssa[YYINITDEPTH]; /* the state stack */
562 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
563
564 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
565 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
566
567 #ifdef YYLSP_NEEDED
568 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
569 YYLTYPE *yyls = yylsa;
570 YYLTYPE *yylsp;
571
572 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
573 #else
574 #define YYPOPSTACK (yyvsp--, yyssp--)
575 #endif
576
577 int yystacksize = YYINITDEPTH;
578 #ifndef YYSTACK_USE_ALLOCA
579 int yyfree_stacks = 0;
580 #endif
581
582 #ifdef YYPURE
583 int yychar;
584 YYSTYPE yylval;
585 int yynerrs;
586 #ifdef YYLSP_NEEDED
587 YYLTYPE yylloc;
588 #endif
589 #endif
590
591 YYSTYPE yyval; /* the variable used to return */
592 /* semantic values from the action */
593 /* routines */
594
595 int yylen;
596
597 #if YYDEBUG != 0
598 if (yydebug)
599 fprintf(stderr, "Starting parse\n");
600 #endif
601
602 yystate = 0;
603 yyerrstatus = 0;
604 yynerrs = 0;
605 yychar = YYEMPTY; /* Cause a token to be read. */
606
607 /* Initialize stack pointers.
608 Waste one element of value and location stack
609 so that they stay on the same level as the state stack.
610 The wasted elements are never initialized. */
611
612 yyssp = yyss - 1;
613 yyvsp = yyvs;
614 #ifdef YYLSP_NEEDED
615 yylsp = yyls;
616 #endif
617
618 /* Push a new state, which is found in yystate . */
619 /* In all cases, when you get here, the value and location stacks
620 have just been pushed. so pushing a state here evens the stacks. */
621 yynewstate:
622
623 *++yyssp = yystate;
624
625 if (yyssp >= yyss + yystacksize - 1)
626 {
627 /* Give user a chance to reallocate the stack */
628 /* Use copies of these so that the &'s don't force the real ones into memory. */
629 YYSTYPE *yyvs1 = yyvs;
630 short *yyss1 = yyss;
631 #ifdef YYLSP_NEEDED
632 YYLTYPE *yyls1 = yyls;
633 #endif
634
635 /* Get the current used size of the three stacks, in elements. */
636 int size = yyssp - yyss + 1;
637
638 #ifdef yyoverflow
639 /* Each stack pointer address is followed by the size of
640 the data in use in that stack, in bytes. */
641 #ifdef YYLSP_NEEDED
642 /* This used to be a conditional around just the two extra args,
643 but that might be undefined if yyoverflow is a macro. */
644 yyoverflow("parser stack overflow",
645 &yyss1, size * sizeof (*yyssp),
646 &yyvs1, size * sizeof (*yyvsp),
647 &yyls1, size * sizeof (*yylsp),
648 &yystacksize);
649 #else
650 yyoverflow("parser stack overflow",
651 &yyss1, size * sizeof (*yyssp),
652 &yyvs1, size * sizeof (*yyvsp),
653 &yystacksize);
654 #endif
655
656 yyss = yyss1; yyvs = yyvs1;
657 #ifdef YYLSP_NEEDED
658 yyls = yyls1;
659 #endif
660 #else /* no yyoverflow */
661 /* Extend the stack our own way. */
662 if (yystacksize >= YYMAXDEPTH)
663 {
664 yyerror("parser stack overflow");
665 #ifndef YYSTACK_USE_ALLOCA
666 if (yyfree_stacks)
667 {
668 free (yyss);
669 free (yyvs);
670 #ifdef YYLSP_NEEDED
671 free (yyls);
672 #endif
673 }
674 #endif
675 return 2;
676 }
677 yystacksize *= 2;
678 if (yystacksize > YYMAXDEPTH)
679 yystacksize = YYMAXDEPTH;
680 #ifndef YYSTACK_USE_ALLOCA
681 yyfree_stacks = 1;
682 #endif
683 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
684 __yy_memcpy ((char *)yyss, (char *)yyss1,
685 size * (unsigned int) sizeof (*yyssp));
686 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
687 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
688 size * (unsigned int) sizeof (*yyvsp));
689 #ifdef YYLSP_NEEDED
690 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
691 __yy_memcpy ((char *)yyls, (char *)yyls1,
692 size * (unsigned int) sizeof (*yylsp));
693 #endif
694 #endif /* no yyoverflow */
695
696 yyssp = yyss + size - 1;
697 yyvsp = yyvs + size - 1;
698 #ifdef YYLSP_NEEDED
699 yylsp = yyls + size - 1;
700 #endif
701
702 #if YYDEBUG != 0
703 if (yydebug)
704 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
705 #endif
706
707 if (yyssp >= yyss + yystacksize - 1)
708 YYABORT;
709 }
710
711 #if YYDEBUG != 0
712 if (yydebug)
713 fprintf(stderr, "Entering state %d\n", yystate);
714 #endif
715
716 goto yybackup;
717 yybackup:
718
719 /* Do appropriate processing given the current state. */
720 /* Read a lookahead token if we need one and don't already have one. */
721 /* yyresume: */
722
723 /* First try to decide what to do without reference to lookahead token. */
724
725 yyn = yypact[yystate];
726 if (yyn == YYFLAG)
727 goto yydefault;
728
729 /* Not known => get a lookahead token if don't already have one. */
730
731 /* yychar is either YYEMPTY or YYEOF
732 or a valid token in external form. */
733
734 if (yychar == YYEMPTY)
735 {
736 #if YYDEBUG != 0
737 if (yydebug)
738 fprintf(stderr, "Reading a token: ");
739 #endif
740 yychar = YYLEX;
741 }
742
743 /* Convert token to internal form (in yychar1) for indexing tables with */
744
745 if (yychar <= 0) /* This means end of input. */
746 {
747 yychar1 = 0;
748 yychar = YYEOF; /* Don't call YYLEX any more */
749
750 #if YYDEBUG != 0
751 if (yydebug)
752 fprintf(stderr, "Now at end of input.\n");
753 #endif
754 }
755 else
756 {
757 yychar1 = YYTRANSLATE(yychar);
758
759 #if YYDEBUG != 0
760 if (yydebug)
761 {
762 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
763 /* Give the individual parser a way to print the precise meaning
764 of a token, for further debugging info. */
765 #ifdef YYPRINT
766 YYPRINT (stderr, yychar, yylval);
767 #endif
768 fprintf (stderr, ")\n");
769 }
770 #endif
771 }
772
773 yyn += yychar1;
774 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
775 goto yydefault;
776
777 yyn = yytable[yyn];
778
779 /* yyn is what to do for this token type in this state.
780 Negative => reduce, -yyn is rule number.
781 Positive => shift, yyn is new state.
782 New state is final state => don't bother to shift,
783 just return success.
784 0, or most negative number => error. */
785
786 if (yyn < 0)
787 {
788 if (yyn == YYFLAG)
789 goto yyerrlab;
790 yyn = -yyn;
791 goto yyreduce;
792 }
793 else if (yyn == 0)
794 goto yyerrlab;
795
796 if (yyn == YYFINAL)
797 YYACCEPT;
798
799 /* Shift the lookahead token. */
800
801 #if YYDEBUG != 0
802 if (yydebug)
803 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
804 #endif
805
806 /* Discard the token being shifted unless it is eof. */
807 if (yychar != YYEOF)
808 yychar = YYEMPTY;
809
810 *++yyvsp = yylval;
811 #ifdef YYLSP_NEEDED
812 *++yylsp = yylloc;
813 #endif
814
815 /* count tokens shifted since error; after three, turn off error status. */
816 if (yyerrstatus) yyerrstatus--;
817
818 yystate = yyn;
819 goto yynewstate;
820
821 /* Do the default action for the current state. */
822 yydefault:
823
824 yyn = yydefact[yystate];
825 if (yyn == 0)
826 goto yyerrlab;
827
828 /* Do a reduction. yyn is the number of a rule to reduce with. */
829 yyreduce:
830 yylen = yyr2[yyn];
831 if (yylen > 0)
832 yyval = yyvsp[1-yylen]; /* implement default value of the action */
833
834 #if YYDEBUG != 0
835 if (yydebug)
836 {
837 int i;
838
839 fprintf (stderr, "Reducing via rule %d (line %d), ",
840 yyn, yyrline[yyn]);
841
842 /* Print the symbols being reduced, and their result. */
843 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
844 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
845 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
846 }
847 #endif
848
849
850 switch (yyn) {
851
852 case 1:
853 #line 172 "plural.y"
854 {
855 if (yyvsp[0].exp == NULL)
856 YYABORT;
857 ((struct parse_args *) arg)->res = yyvsp[0].exp;
858 ;
859 break;}
860 case 2:
861 #line 180 "plural.y"
862 {
863 yyval.exp = new_exp_3 (qmop, yyvsp[-4].exp, yyvsp[-2].exp, yyvsp[0].exp);
864 ;
865 break;}
866 case 3:
867 #line 184 "plural.y"
868 {
869 yyval.exp = new_exp_2 (lor, yyvsp[-2].exp, yyvsp[0].exp);
870 ;
871 break;}
872 case 4:
873 #line 188 "plural.y"
874 {
875 yyval.exp = new_exp_2 (land, yyvsp[-2].exp, yyvsp[0].exp);
876 ;
877 break;}
878 case 5:
879 #line 192 "plural.y"
880 {
881 yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
882 ;
883 break;}
884 case 6:
885 #line 196 "plural.y"
886 {
887 yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
888 ;
889 break;}
890 case 7:
891 #line 200 "plural.y"
892 {
893 yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
894 ;
895 break;}
896 case 8:
897 #line 204 "plural.y"
898 {
899 yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
900 ;
901 break;}
902 case 9:
903 #line 208 "plural.y"
904 {
905 yyval.exp = new_exp_1 (lnot, yyvsp[0].exp);
906 ;
907 break;}
908 case 10:
909 #line 212 "plural.y"
910 {
911 yyval.exp = new_exp_0 (var);
912 ;
913 break;}
914 case 11:
915 #line 216 "plural.y"
916 {
917 if ((yyval.exp = new_exp_0 (num)) != NULL)
918 yyval.exp->val.num = yyvsp[0].num;
919 ;
920 break;}
921 case 12:
922 #line 221 "plural.y"
923 {
924 yyval.exp = yyvsp[-1].exp;
925 ;
926 break;}
927 }
928 /* the action file gets copied in in place of this dollarsign */
929 #line 554 "/usr/share/bison.simple"
930 \f
931 yyvsp -= yylen;
932 yyssp -= yylen;
933 #ifdef YYLSP_NEEDED
934 yylsp -= yylen;
935 #endif
936
937 #if YYDEBUG != 0
938 if (yydebug)
939 {
940 short *ssp1 = yyss - 1;
941 fprintf (stderr, "state stack now");
942 while (ssp1 != yyssp)
943 fprintf (stderr, " %d", *++ssp1);
944 fprintf (stderr, "\n");
945 }
946 #endif
947
948 *++yyvsp = yyval;
949
950 #ifdef YYLSP_NEEDED
951 yylsp++;
952 if (yylen == 0)
953 {
954 yylsp->first_line = yylloc.first_line;
955 yylsp->first_column = yylloc.first_column;
956 yylsp->last_line = (yylsp-1)->last_line;
957 yylsp->last_column = (yylsp-1)->last_column;
958 yylsp->text = 0;
959 }
960 else
961 {
962 yylsp->last_line = (yylsp+yylen-1)->last_line;
963 yylsp->last_column = (yylsp+yylen-1)->last_column;
964 }
965 #endif
966
967 /* Now "shift" the result of the reduction.
968 Determine what state that goes to,
969 based on the state we popped back to
970 and the rule number reduced by. */
971
972 yyn = yyr1[yyn];
973
974 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
975 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
976 yystate = yytable[yystate];
977 else
978 yystate = yydefgoto[yyn - YYNTBASE];
979
980 goto yynewstate;
981
982 yyerrlab: /* here on detecting error */
983
984 if (! yyerrstatus)
985 /* If not already recovering from an error, report this error. */
986 {
987 ++yynerrs;
988
989 #ifdef YYERROR_VERBOSE
990 yyn = yypact[yystate];
991
992 if (yyn > YYFLAG && yyn < YYLAST)
993 {
994 int size = 0;
995 char *msg;
996 int x, count;
997
998 count = 0;
999 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1000 for (x = (yyn < 0 ? -yyn : 0);
1001 x < (sizeof(yytname) / sizeof(char *)); x++)
1002 if (yycheck[x + yyn] == x)
1003 size += strlen(yytname[x]) + 15, count++;
1004 msg = (char *) malloc(size + 15);
1005 if (msg != 0)
1006 {
1007 strcpy(msg, "parse error");
1008
1009 if (count < 5)
1010 {
1011 count = 0;
1012 for (x = (yyn < 0 ? -yyn : 0);
1013 x < (sizeof(yytname) / sizeof(char *)); x++)
1014 if (yycheck[x + yyn] == x)
1015 {
1016 strcat(msg, count == 0 ? ", expecting `" : " or `");
1017 strcat(msg, yytname[x]);
1018 strcat(msg, "'");
1019 count++;
1020 }
1021 }
1022 yyerror(msg);
1023 free(msg);
1024 }
1025 else
1026 yyerror ("parse error; also virtual memory exceeded");
1027 }
1028 else
1029 #endif /* YYERROR_VERBOSE */
1030 yyerror("parse error");
1031 }
1032
1033 goto yyerrlab1;
1034 yyerrlab1: /* here on error raised explicitly by an action */
1035
1036 if (yyerrstatus == 3)
1037 {
1038 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1039
1040 /* return failure if at end of input */
1041 if (yychar == YYEOF)
1042 YYABORT;
1043
1044 #if YYDEBUG != 0
1045 if (yydebug)
1046 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1047 #endif
1048
1049 yychar = YYEMPTY;
1050 }
1051
1052 /* Else will try to reuse lookahead token
1053 after shifting the error token. */
1054
1055 yyerrstatus = 3; /* Each real token shifted decrements this */
1056
1057 goto yyerrhandle;
1058
1059 yyerrdefault: /* current state does not do anything special for the error token. */
1060
1061 #if 0
1062 /* This is wrong; only states that explicitly want error tokens
1063 should shift them. */
1064 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1065 if (yyn) goto yydefault;
1066 #endif
1067
1068 yyerrpop: /* pop the current state because it cannot handle the error token */
1069
1070 if (yyssp == yyss) YYABORT;
1071 yyvsp--;
1072 yystate = *--yyssp;
1073 #ifdef YYLSP_NEEDED
1074 yylsp--;
1075 #endif
1076
1077 #if YYDEBUG != 0
1078 if (yydebug)
1079 {
1080 short *ssp1 = yyss - 1;
1081 fprintf (stderr, "Error: state stack now");
1082 while (ssp1 != yyssp)
1083 fprintf (stderr, " %d", *++ssp1);
1084 fprintf (stderr, "\n");
1085 }
1086 #endif
1087
1088 yyerrhandle:
1089
1090 yyn = yypact[yystate];
1091 if (yyn == YYFLAG)
1092 goto yyerrdefault;
1093
1094 yyn += YYTERROR;
1095 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1096 goto yyerrdefault;
1097
1098 yyn = yytable[yyn];
1099 if (yyn < 0)
1100 {
1101 if (yyn == YYFLAG)
1102 goto yyerrpop;
1103 yyn = -yyn;
1104 goto yyreduce;
1105 }
1106 else if (yyn == 0)
1107 goto yyerrpop;
1108
1109 if (yyn == YYFINAL)
1110 YYACCEPT;
1111
1112 #if YYDEBUG != 0
1113 if (yydebug)
1114 fprintf(stderr, "Shifting error token, ");
1115 #endif
1116
1117 *++yyvsp = yylval;
1118 #ifdef YYLSP_NEEDED
1119 *++yylsp = yylloc;
1120 #endif
1121
1122 yystate = yyn;
1123 goto yynewstate;
1124
1125 yyacceptlab:
1126 /* YYACCEPT comes here. */
1127 #ifndef YYSTACK_USE_ALLOCA
1128 if (yyfree_stacks)
1129 {
1130 free (yyss);
1131 free (yyvs);
1132 #ifdef YYLSP_NEEDED
1133 free (yyls);
1134 #endif
1135 }
1136 #endif
1137 return 0;
1138
1139 yyabortlab:
1140 /* YYABORT comes here. */
1141 #ifndef YYSTACK_USE_ALLOCA
1142 if (yyfree_stacks)
1143 {
1144 free (yyss);
1145 free (yyvs);
1146 #ifdef YYLSP_NEEDED
1147 free (yyls);
1148 #endif
1149 }
1150 #endif
1151 return 1;
1152 }
1153 #line 226 "plural.y"
1154
1155
1156 void
1157 internal_function
1158 FREE_EXPRESSION (exp)
1159 struct expression *exp;
1160 {
1161 if (exp == NULL)
1162 return;
1163
1164 /* Handle the recursive case. */
1165 switch (exp->nargs)
1166 {
1167 case 3:
1168 FREE_EXPRESSION (exp->val.args[2]);
1169 /* FALLTHROUGH */
1170 case 2:
1171 FREE_EXPRESSION (exp->val.args[1]);
1172 /* FALLTHROUGH */
1173 case 1:
1174 FREE_EXPRESSION (exp->val.args[0]);
1175 /* FALLTHROUGH */
1176 default:
1177 break;
1178 }
1179
1180 free (exp);
1181 }
1182
1183
1184 static int
1185 yylex (lval, pexp)
1186 YYSTYPE *lval;
1187 const char **pexp;
1188 {
1189 const char *exp = *pexp;
1190 int result;
1191
1192 while (1)
1193 {
1194 if (exp[0] == '\0')
1195 {
1196 *pexp = exp;
1197 return YYEOF;
1198 }
1199
1200 if (exp[0] != ' ' && exp[0] != '\t')
1201 break;
1202
1203 ++exp;
1204 }
1205
1206 result = *exp++;
1207 switch (result)
1208 {
1209 case '0': case '1': case '2': case '3': case '4':
1210 case '5': case '6': case '7': case '8': case '9':
1211 {
1212 unsigned long int n = result - '0';
1213 while (exp[0] >= '0' && exp[0] <= '9')
1214 {
1215 n *= 10;
1216 n += exp[0] - '0';
1217 ++exp;
1218 }
1219 lval->num = n;
1220 result = NUMBER;
1221 }
1222 break;
1223
1224 case '=':
1225 if (exp[0] == '=')
1226 {
1227 ++exp;
1228 lval->op = equal;
1229 result = EQUOP2;
1230 }
1231 else
1232 result = YYERRCODE;
1233 break;
1234
1235 case '!':
1236 if (exp[0] == '=')
1237 {
1238 ++exp;
1239 lval->op = not_equal;
1240 result = EQUOP2;
1241 }
1242 break;
1243
1244 case '&':
1245 case '|':
1246 if (exp[0] == result)
1247 ++exp;
1248 else
1249 result = YYERRCODE;
1250 break;
1251
1252 case '<':
1253 if (exp[0] == '=')
1254 {
1255 ++exp;
1256 lval->op = less_or_equal;
1257 }
1258 else
1259 lval->op = less_than;
1260 result = CMPOP2;
1261 break;
1262
1263 case '>':
1264 if (exp[0] == '=')
1265 {
1266 ++exp;
1267 lval->op = greater_or_equal;
1268 }
1269 else
1270 lval->op = greater_than;
1271 result = CMPOP2;
1272 break;
1273
1274 case '*':
1275 lval->op = mult;
1276 result = MULOP2;
1277 break;
1278
1279 case '/':
1280 lval->op = divide;
1281 result = MULOP2;
1282 break;
1283
1284 case '%':
1285 lval->op = module;
1286 result = MULOP2;
1287 break;
1288
1289 case '+':
1290 lval->op = plus;
1291 result = ADDOP2;
1292 break;
1293
1294 case '-':
1295 lval->op = minus;
1296 result = ADDOP2;
1297 break;
1298
1299 case 'n':
1300 case '?':
1301 case ':':
1302 case '(':
1303 case ')':
1304 /* Nothing, just return the character. */
1305 break;
1306
1307 case ';':
1308 case '\n':
1309 case '\0':
1310 /* Be safe and let the user call this function again. */
1311 --exp;
1312 result = YYEOF;
1313 break;
1314
1315 default:
1316 result = YYERRCODE;
1317 #if YYDEBUG != 0
1318 --exp;
1319 #endif
1320 break;
1321 }
1322
1323 *pexp = exp;
1324
1325 return result;
1326 }
1327
1328
1329 static void
1330 yyerror (str)
1331 const char *str;
1332 {
1333 /* Do nothing. We don't print error messages here. */
1334 }
This page took 0.090931 seconds and 5 git commands to generate.