Update.
[glibc.git] / intl / plural.c
blobf9165b7868635206bf9b1bcdd0595e10e6ba8d13
2 /* A Bison parser, made from plural.y
3 by GNU Bison version 1.28 */
5 #define YYBISON 1 /* Identify Bison output. */
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 NUMBER 257
16 #line 1 "plural.y"
18 /* Expression parsing for plural form selection.
19 Copyright (C) 2000 Free Software Foundation, Inc.
20 Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
22 The GNU C Library is free software; you can redistribute it and/or
23 modify it under the terms of the GNU Library General Public License as
24 published by the Free Software Foundation; either version 2 of the
25 License, or (at your option) any later version.
27 The GNU C Library is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 Library General Public License for more details.
32 You should have received a copy of the GNU Library General Public
33 License along with the GNU C Library; see the file COPYING.LIB. If not,
34 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
35 Boston, MA 02111-1307, USA. */
37 #include <stdarg.h>
38 #include <stdlib.h>
39 #include "gettext.h"
40 #include "gettextP.h"
42 #define YYLEX_PARAM &((struct parse_args *) arg)->cp
43 #define YYPARSE_PARAM arg
45 #line 32 "plural.y"
46 typedef union {
47 unsigned long int num;
48 struct expression *exp;
49 } YYSTYPE;
50 #line 37 "plural.y"
52 /* Prototypes for local functions. */
53 static struct expression *new_exp (enum operator op, ...);
54 static int yylex (YYSTYPE *lval, const char **pexp);
55 static void yyerror (const char *str);
56 #include <stdio.h>
58 #ifndef __cplusplus
59 #ifndef __STDC__
60 #define const
61 #endif
62 #endif
66 #define YYFINAL 31
67 #define YYFLAG -32768
68 #define YYNTBASE 18
70 #define YYTRANSLATE(x) ((unsigned)(x) <= 257 ? yytranslate[x] : 20)
72 static const char yytranslate[] = { 0,
73 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
74 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
75 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
76 2, 2, 7, 2, 2, 2, 12, 5, 2, 16,
77 17, 10, 8, 2, 9, 2, 11, 2, 2, 2,
78 2, 2, 2, 2, 2, 2, 2, 14, 2, 2,
79 6, 2, 3, 2, 2, 2, 2, 2, 2, 2,
80 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
81 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
82 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
83 2, 2, 2, 2, 2, 2, 2, 2, 2, 15,
84 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
85 2, 2, 2, 4, 2, 2, 2, 2, 2, 2,
86 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
87 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
88 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
89 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
90 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
91 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
92 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
93 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
94 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
95 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
96 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
97 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
98 2, 2, 2, 2, 2, 1, 13
101 #if YYDEBUG != 0
102 static const short yyprhs[] = { 0,
103 0, 2, 8, 12, 16, 20, 24, 28, 32, 36,
104 40, 44, 46, 48
107 static const short yyrhs[] = { 19,
108 0, 19, 3, 19, 14, 19, 0, 19, 4, 19,
109 0, 19, 5, 19, 0, 19, 6, 19, 0, 19,
110 7, 19, 0, 19, 8, 19, 0, 19, 9, 19,
111 0, 19, 10, 19, 0, 19, 11, 19, 0, 19,
112 12, 19, 0, 15, 0, 13, 0, 16, 19, 17,
116 #endif
118 #if YYDEBUG != 0
119 static const short yyrline[] = { 0,
120 55, 61, 66, 71, 76, 81, 86, 91, 96, 101,
121 106, 111, 116, 122
123 #endif
126 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
128 static const char * const yytname[] = { "$","error","$undefined.","'?'","'|'",
129 "'&'","'='","'!'","'+'","'-'","'*'","'/'","'%'","NUMBER","':'","'n'","'('","')'",
130 "start","exp", NULL
132 #endif
134 static const short yyr1[] = { 0,
135 18, 19, 19, 19, 19, 19, 19, 19, 19, 19,
136 19, 19, 19, 19
139 static const short yyr2[] = { 0,
140 1, 5, 3, 3, 3, 3, 3, 3, 3, 3,
141 3, 1, 1, 3
144 static const short yydefact[] = { 0,
145 13, 12, 0, 1, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 14, 0, 3, 4, 5,
147 6, 7, 8, 9, 10, 11, 0, 2, 0, 0,
151 static const short yydefgoto[] = { 29,
155 static const short yypact[] = { 58,
156 -32768,-32768, 58, 37, 10, 58, 58, 58, 58, 58,
157 58, 58, 58, 58, 58,-32768, 25, 45, 52, 57,
158 57, 65, 65,-32768,-32768,-32768, 58, 37, 1, 2,
159 -32768
162 static const short yypgoto[] = {-32768,
167 #define YYLAST 77
170 static const short yytable[] = { 5,
171 30, 31, 17, 18, 19, 20, 21, 22, 23, 24,
172 25, 26, 6, 7, 8, 9, 10, 11, 12, 13,
173 14, 15, 0, 28, 0, 0, 16, 6, 7, 8,
174 9, 10, 11, 12, 13, 14, 15, 0, 27, 6,
175 7, 8, 9, 10, 11, 12, 13, 14, 15, 8,
176 9, 10, 11, 12, 13, 14, 15, 9, 10, 11,
177 12, 13, 14, 15, 11, 12, 13, 14, 15, 0,
178 1, 0, 2, 3, 13, 14, 15
181 static const short yycheck[] = { 3,
182 0, 0, 6, 7, 8, 9, 10, 11, 12, 13,
183 14, 15, 3, 4, 5, 6, 7, 8, 9, 10,
184 11, 12, -1, 27, -1, -1, 17, 3, 4, 5,
185 6, 7, 8, 9, 10, 11, 12, -1, 14, 3,
186 4, 5, 6, 7, 8, 9, 10, 11, 12, 5,
187 6, 7, 8, 9, 10, 11, 12, 6, 7, 8,
188 9, 10, 11, 12, 8, 9, 10, 11, 12, -1,
189 13, -1, 15, 16, 10, 11, 12
191 #define YYPURE 1
193 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
194 #line 3 "/usr/share/bison.simple"
195 /* This file comes from bison-1.28. */
197 /* Skeleton output parser for bison,
198 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
200 This program is free software; you can redistribute it and/or modify
201 it under the terms of the GNU General Public License as published by
202 the Free Software Foundation; either version 2, or (at your option)
203 any later version.
205 This program is distributed in the hope that it will be useful,
206 but WITHOUT ANY WARRANTY; without even the implied warranty of
207 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
208 GNU General Public License for more details.
210 You should have received a copy of the GNU General Public License
211 along with this program; if not, write to the Free Software
212 Foundation, Inc., 59 Temple Place - Suite 330,
213 Boston, MA 02111-1307, USA. */
215 /* As a special exception, when this file is copied by Bison into a
216 Bison output file, you may use that output file without restriction.
217 This special exception was added by the Free Software Foundation
218 in version 1.24 of Bison. */
220 /* This is the parser code that is written into each bison parser
221 when the %semantic_parser declaration is not specified in the grammar.
222 It was written by Richard Stallman by simplifying the hairy parser
223 used when %semantic_parser is specified. */
225 #ifndef YYSTACK_USE_ALLOCA
226 #ifdef alloca
227 #define YYSTACK_USE_ALLOCA
228 #else /* alloca not defined */
229 #ifdef __GNUC__
230 #define YYSTACK_USE_ALLOCA
231 #define alloca __builtin_alloca
232 #else /* not GNU C. */
233 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
234 #define YYSTACK_USE_ALLOCA
235 #include <alloca.h>
236 #else /* not sparc */
237 /* We think this test detects Watcom and Microsoft C. */
238 /* This used to test MSDOS, but that is a bad idea
239 since that symbol is in the user namespace. */
240 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
241 #if 0 /* No need for malloc.h, which pollutes the namespace;
242 instead, just don't use alloca. */
243 #include <malloc.h>
244 #endif
245 #else /* not MSDOS, or __TURBOC__ */
246 #if defined(_AIX)
247 /* I don't know what this was needed for, but it pollutes the namespace.
248 So I turned it off. rms, 2 May 1997. */
249 /* #include <malloc.h> */
250 #pragma alloca
251 #define YYSTACK_USE_ALLOCA
252 #else /* not MSDOS, or __TURBOC__, or _AIX */
253 #if 0
254 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
255 and on HPUX 10. Eventually we can turn this on. */
256 #define YYSTACK_USE_ALLOCA
257 #define alloca __builtin_alloca
258 #endif /* __hpux */
259 #endif
260 #endif /* not _AIX */
261 #endif /* not MSDOS, or __TURBOC__ */
262 #endif /* not sparc */
263 #endif /* not GNU C */
264 #endif /* alloca not defined */
265 #endif /* YYSTACK_USE_ALLOCA not defined */
267 #ifdef YYSTACK_USE_ALLOCA
268 #define YYSTACK_ALLOC alloca
269 #else
270 #define YYSTACK_ALLOC malloc
271 #endif
273 /* Note: there must be only one dollar sign in this file.
274 It is replaced by the list of actions, each action
275 as one case of the switch. */
277 #define yyerrok (yyerrstatus = 0)
278 #define yyclearin (yychar = YYEMPTY)
279 #define YYEMPTY -2
280 #define YYEOF 0
281 #define YYACCEPT goto yyacceptlab
282 #define YYABORT goto yyabortlab
283 #define YYERROR goto yyerrlab1
284 /* Like YYERROR except do call yyerror.
285 This remains here temporarily to ease the
286 transition to the new meaning of YYERROR, for GCC.
287 Once GCC version 2 has supplanted version 1, this can go. */
288 #define YYFAIL goto yyerrlab
289 #define YYRECOVERING() (!!yyerrstatus)
290 #define YYBACKUP(token, value) \
291 do \
292 if (yychar == YYEMPTY && yylen == 1) \
293 { yychar = (token), yylval = (value); \
294 yychar1 = YYTRANSLATE (yychar); \
295 YYPOPSTACK; \
296 goto yybackup; \
298 else \
299 { yyerror ("syntax error: cannot back up"); YYERROR; } \
300 while (0)
302 #define YYTERROR 1
303 #define YYERRCODE 256
305 #ifndef YYPURE
306 #define YYLEX yylex()
307 #endif
309 #ifdef YYPURE
310 #ifdef YYLSP_NEEDED
311 #ifdef YYLEX_PARAM
312 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
313 #else
314 #define YYLEX yylex(&yylval, &yylloc)
315 #endif
316 #else /* not YYLSP_NEEDED */
317 #ifdef YYLEX_PARAM
318 #define YYLEX yylex(&yylval, YYLEX_PARAM)
319 #else
320 #define YYLEX yylex(&yylval)
321 #endif
322 #endif /* not YYLSP_NEEDED */
323 #endif
325 /* If nonreentrant, generate the variables here */
327 #ifndef YYPURE
329 int yychar; /* the lookahead symbol */
330 YYSTYPE yylval; /* the semantic value of the */
331 /* lookahead symbol */
333 #ifdef YYLSP_NEEDED
334 YYLTYPE yylloc; /* location data for the lookahead */
335 /* symbol */
336 #endif
338 int yynerrs; /* number of parse errors so far */
339 #endif /* not YYPURE */
341 #if YYDEBUG != 0
342 int yydebug; /* nonzero means print parse trace */
343 /* Since this is uninitialized, it does not stop multiple parsers
344 from coexisting. */
345 #endif
347 /* YYINITDEPTH indicates the initial size of the parser's stacks */
349 #ifndef YYINITDEPTH
350 #define YYINITDEPTH 200
351 #endif
353 /* YYMAXDEPTH is the maximum size the stacks can grow to
354 (effective only if the built-in stack extension method is used). */
356 #if YYMAXDEPTH == 0
357 #undef YYMAXDEPTH
358 #endif
360 #ifndef YYMAXDEPTH
361 #define YYMAXDEPTH 10000
362 #endif
364 /* Define __yy_memcpy. Note that the size argument
365 should be passed with type unsigned int, because that is what the non-GCC
366 definitions require. With GCC, __builtin_memcpy takes an arg
367 of type size_t, but it can handle unsigned int. */
369 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
370 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
371 #else /* not GNU C or C++ */
372 #ifndef __cplusplus
374 /* This is the most reliable way to avoid incompatibilities
375 in available built-in functions on various systems. */
376 static void
377 __yy_memcpy (to, from, count)
378 char *to;
379 char *from;
380 unsigned int count;
382 register char *f = from;
383 register char *t = to;
384 register int i = count;
386 while (i-- > 0)
387 *t++ = *f++;
390 #else /* __cplusplus */
392 /* This is the most reliable way to avoid incompatibilities
393 in available built-in functions on various systems. */
394 static void
395 __yy_memcpy (char *to, char *from, unsigned int count)
397 register char *t = to;
398 register char *f = from;
399 register int i = count;
401 while (i-- > 0)
402 *t++ = *f++;
405 #endif
406 #endif
408 #line 217 "/usr/share/bison.simple"
410 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
411 into yyparse. The argument should have type void *.
412 It should actually point to an object.
413 Grammar actions can access the variable by casting it
414 to the proper pointer type. */
416 #ifdef YYPARSE_PARAM
417 #ifdef __cplusplus
418 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
419 #define YYPARSE_PARAM_DECL
420 #else /* not __cplusplus */
421 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
422 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
423 #endif /* not __cplusplus */
424 #else /* not YYPARSE_PARAM */
425 #define YYPARSE_PARAM_ARG
426 #define YYPARSE_PARAM_DECL
427 #endif /* not YYPARSE_PARAM */
429 /* Prevent warning if -Wstrict-prototypes. */
430 #ifdef __GNUC__
431 #ifdef YYPARSE_PARAM
432 int yyparse (void *);
433 #else
434 int yyparse (void);
435 #endif
436 #endif
439 yyparse(YYPARSE_PARAM_ARG)
440 YYPARSE_PARAM_DECL
442 register int yystate;
443 register int yyn;
444 register short *yyssp;
445 register YYSTYPE *yyvsp;
446 int yyerrstatus; /* number of tokens to shift before error messages enabled */
447 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
449 short yyssa[YYINITDEPTH]; /* the state stack */
450 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
452 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
453 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
455 #ifdef YYLSP_NEEDED
456 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
457 YYLTYPE *yyls = yylsa;
458 YYLTYPE *yylsp;
460 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
461 #else
462 #define YYPOPSTACK (yyvsp--, yyssp--)
463 #endif
465 int yystacksize = YYINITDEPTH;
466 int yyfree_stacks = 0;
468 #ifdef YYPURE
469 int yychar;
470 YYSTYPE yylval;
471 int yynerrs;
472 #ifdef YYLSP_NEEDED
473 YYLTYPE yylloc;
474 #endif
475 #endif
477 YYSTYPE yyval; /* the variable used to return */
478 /* semantic values from the action */
479 /* routines */
481 int yylen;
483 #if YYDEBUG != 0
484 if (yydebug)
485 fprintf(stderr, "Starting parse\n");
486 #endif
488 yystate = 0;
489 yyerrstatus = 0;
490 yynerrs = 0;
491 yychar = YYEMPTY; /* Cause a token to be read. */
493 /* Initialize stack pointers.
494 Waste one element of value and location stack
495 so that they stay on the same level as the state stack.
496 The wasted elements are never initialized. */
498 yyssp = yyss - 1;
499 yyvsp = yyvs;
500 #ifdef YYLSP_NEEDED
501 yylsp = yyls;
502 #endif
504 /* Push a new state, which is found in yystate . */
505 /* In all cases, when you get here, the value and location stacks
506 have just been pushed. so pushing a state here evens the stacks. */
507 yynewstate:
509 *++yyssp = yystate;
511 if (yyssp >= yyss + yystacksize - 1)
513 /* Give user a chance to reallocate the stack */
514 /* Use copies of these so that the &'s don't force the real ones into memory. */
515 YYSTYPE *yyvs1 = yyvs;
516 short *yyss1 = yyss;
517 #ifdef YYLSP_NEEDED
518 YYLTYPE *yyls1 = yyls;
519 #endif
521 /* Get the current used size of the three stacks, in elements. */
522 int size = yyssp - yyss + 1;
524 #ifdef yyoverflow
525 /* Each stack pointer address is followed by the size of
526 the data in use in that stack, in bytes. */
527 #ifdef YYLSP_NEEDED
528 /* This used to be a conditional around just the two extra args,
529 but that might be undefined if yyoverflow is a macro. */
530 yyoverflow("parser stack overflow",
531 &yyss1, size * sizeof (*yyssp),
532 &yyvs1, size * sizeof (*yyvsp),
533 &yyls1, size * sizeof (*yylsp),
534 &yystacksize);
535 #else
536 yyoverflow("parser stack overflow",
537 &yyss1, size * sizeof (*yyssp),
538 &yyvs1, size * sizeof (*yyvsp),
539 &yystacksize);
540 #endif
542 yyss = yyss1; yyvs = yyvs1;
543 #ifdef YYLSP_NEEDED
544 yyls = yyls1;
545 #endif
546 #else /* no yyoverflow */
547 /* Extend the stack our own way. */
548 if (yystacksize >= YYMAXDEPTH)
550 yyerror("parser stack overflow");
551 if (yyfree_stacks)
553 free (yyss);
554 free (yyvs);
555 #ifdef YYLSP_NEEDED
556 free (yyls);
557 #endif
559 return 2;
561 yystacksize *= 2;
562 if (yystacksize > YYMAXDEPTH)
563 yystacksize = YYMAXDEPTH;
564 #ifndef YYSTACK_USE_ALLOCA
565 yyfree_stacks = 1;
566 #endif
567 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
568 __yy_memcpy ((char *)yyss, (char *)yyss1,
569 size * (unsigned int) sizeof (*yyssp));
570 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
571 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
572 size * (unsigned int) sizeof (*yyvsp));
573 #ifdef YYLSP_NEEDED
574 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
575 __yy_memcpy ((char *)yyls, (char *)yyls1,
576 size * (unsigned int) sizeof (*yylsp));
577 #endif
578 #endif /* no yyoverflow */
580 yyssp = yyss + size - 1;
581 yyvsp = yyvs + size - 1;
582 #ifdef YYLSP_NEEDED
583 yylsp = yyls + size - 1;
584 #endif
586 #if YYDEBUG != 0
587 if (yydebug)
588 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
589 #endif
591 if (yyssp >= yyss + yystacksize - 1)
592 YYABORT;
595 #if YYDEBUG != 0
596 if (yydebug)
597 fprintf(stderr, "Entering state %d\n", yystate);
598 #endif
600 goto yybackup;
601 yybackup:
603 /* Do appropriate processing given the current state. */
604 /* Read a lookahead token if we need one and don't already have one. */
605 /* yyresume: */
607 /* First try to decide what to do without reference to lookahead token. */
609 yyn = yypact[yystate];
610 if (yyn == YYFLAG)
611 goto yydefault;
613 /* Not known => get a lookahead token if don't already have one. */
615 /* yychar is either YYEMPTY or YYEOF
616 or a valid token in external form. */
618 if (yychar == YYEMPTY)
620 #if YYDEBUG != 0
621 if (yydebug)
622 fprintf(stderr, "Reading a token: ");
623 #endif
624 yychar = YYLEX;
627 /* Convert token to internal form (in yychar1) for indexing tables with */
629 if (yychar <= 0) /* This means end of input. */
631 yychar1 = 0;
632 yychar = YYEOF; /* Don't call YYLEX any more */
634 #if YYDEBUG != 0
635 if (yydebug)
636 fprintf(stderr, "Now at end of input.\n");
637 #endif
639 else
641 yychar1 = YYTRANSLATE(yychar);
643 #if YYDEBUG != 0
644 if (yydebug)
646 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
647 /* Give the individual parser a way to print the precise meaning
648 of a token, for further debugging info. */
649 #ifdef YYPRINT
650 YYPRINT (stderr, yychar, yylval);
651 #endif
652 fprintf (stderr, ")\n");
654 #endif
657 yyn += yychar1;
658 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
659 goto yydefault;
661 yyn = yytable[yyn];
663 /* yyn is what to do for this token type in this state.
664 Negative => reduce, -yyn is rule number.
665 Positive => shift, yyn is new state.
666 New state is final state => don't bother to shift,
667 just return success.
668 0, or most negative number => error. */
670 if (yyn < 0)
672 if (yyn == YYFLAG)
673 goto yyerrlab;
674 yyn = -yyn;
675 goto yyreduce;
677 else if (yyn == 0)
678 goto yyerrlab;
680 if (yyn == YYFINAL)
681 YYACCEPT;
683 /* Shift the lookahead token. */
685 #if YYDEBUG != 0
686 if (yydebug)
687 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
688 #endif
690 /* Discard the token being shifted unless it is eof. */
691 if (yychar != YYEOF)
692 yychar = YYEMPTY;
694 *++yyvsp = yylval;
695 #ifdef YYLSP_NEEDED
696 *++yylsp = yylloc;
697 #endif
699 /* count tokens shifted since error; after three, turn off error status. */
700 if (yyerrstatus) yyerrstatus--;
702 yystate = yyn;
703 goto yynewstate;
705 /* Do the default action for the current state. */
706 yydefault:
708 yyn = yydefact[yystate];
709 if (yyn == 0)
710 goto yyerrlab;
712 /* Do a reduction. yyn is the number of a rule to reduce with. */
713 yyreduce:
714 yylen = yyr2[yyn];
715 if (yylen > 0)
716 yyval = yyvsp[1-yylen]; /* implement default value of the action */
718 #if YYDEBUG != 0
719 if (yydebug)
721 int i;
723 fprintf (stderr, "Reducing via rule %d (line %d), ",
724 yyn, yyrline[yyn]);
726 /* Print the symbols being reduced, and their result. */
727 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
728 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
729 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
731 #endif
734 switch (yyn) {
736 case 1:
737 #line 56 "plural.y"
739 ((struct parse_args *) arg)->res = yyvsp[0].exp;
741 break;}
742 case 2:
743 #line 62 "plural.y"
745 if ((yyval.exp = new_exp (qmop, yyvsp[-4].exp, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
746 YYABORT
748 break;}
749 case 3:
750 #line 67 "plural.y"
752 if ((yyval.exp = new_exp (lor, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
753 YYABORT
755 break;}
756 case 4:
757 #line 72 "plural.y"
759 if ((yyval.exp = new_exp (land, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
760 YYABORT
762 break;}
763 case 5:
764 #line 77 "plural.y"
766 if ((yyval.exp = new_exp (equal, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
767 YYABORT
769 break;}
770 case 6:
771 #line 82 "plural.y"
773 if ((yyval.exp = new_exp (not_equal, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
774 YYABORT
776 break;}
777 case 7:
778 #line 87 "plural.y"
780 if ((yyval.exp = new_exp (plus, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
781 YYABORT
783 break;}
784 case 8:
785 #line 92 "plural.y"
787 if ((yyval.exp = new_exp (minus, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
788 YYABORT
790 break;}
791 case 9:
792 #line 97 "plural.y"
794 if ((yyval.exp = new_exp (mult, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
795 YYABORT
797 break;}
798 case 10:
799 #line 102 "plural.y"
801 if ((yyval.exp = new_exp (divide, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
802 YYABORT
804 break;}
805 case 11:
806 #line 107 "plural.y"
808 if ((yyval.exp = new_exp (module, yyvsp[-2].exp, yyvsp[0].exp, NULL)) == NULL)
809 YYABORT
811 break;}
812 case 12:
813 #line 112 "plural.y"
815 if ((yyval.exp = new_exp (var, NULL)) == NULL)
816 YYABORT
818 break;}
819 case 13:
820 #line 117 "plural.y"
822 if ((yyval.exp = new_exp (num, NULL)) == NULL)
823 YYABORT;
824 yyval.exp->val.num = yyvsp[0].num
826 break;}
827 case 14:
828 #line 123 "plural.y"
830 yyval.exp = yyvsp[-1].exp
832 break;}
834 /* the action file gets copied in in place of this dollarsign */
835 #line 543 "/usr/share/bison.simple"
837 yyvsp -= yylen;
838 yyssp -= yylen;
839 #ifdef YYLSP_NEEDED
840 yylsp -= yylen;
841 #endif
843 #if YYDEBUG != 0
844 if (yydebug)
846 short *ssp1 = yyss - 1;
847 fprintf (stderr, "state stack now");
848 while (ssp1 != yyssp)
849 fprintf (stderr, " %d", *++ssp1);
850 fprintf (stderr, "\n");
852 #endif
854 *++yyvsp = yyval;
856 #ifdef YYLSP_NEEDED
857 yylsp++;
858 if (yylen == 0)
860 yylsp->first_line = yylloc.first_line;
861 yylsp->first_column = yylloc.first_column;
862 yylsp->last_line = (yylsp-1)->last_line;
863 yylsp->last_column = (yylsp-1)->last_column;
864 yylsp->text = 0;
866 else
868 yylsp->last_line = (yylsp+yylen-1)->last_line;
869 yylsp->last_column = (yylsp+yylen-1)->last_column;
871 #endif
873 /* Now "shift" the result of the reduction.
874 Determine what state that goes to,
875 based on the state we popped back to
876 and the rule number reduced by. */
878 yyn = yyr1[yyn];
880 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
881 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
882 yystate = yytable[yystate];
883 else
884 yystate = yydefgoto[yyn - YYNTBASE];
886 goto yynewstate;
888 yyerrlab: /* here on detecting error */
890 if (! yyerrstatus)
891 /* If not already recovering from an error, report this error. */
893 ++yynerrs;
895 #ifdef YYERROR_VERBOSE
896 yyn = yypact[yystate];
898 if (yyn > YYFLAG && yyn < YYLAST)
900 int size = 0;
901 char *msg;
902 int x, count;
904 count = 0;
905 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
906 for (x = (yyn < 0 ? -yyn : 0);
907 x < (sizeof(yytname) / sizeof(char *)); x++)
908 if (yycheck[x + yyn] == x)
909 size += strlen(yytname[x]) + 15, count++;
910 msg = (char *) malloc(size + 15);
911 if (msg != 0)
913 strcpy(msg, "parse error");
915 if (count < 5)
917 count = 0;
918 for (x = (yyn < 0 ? -yyn : 0);
919 x < (sizeof(yytname) / sizeof(char *)); x++)
920 if (yycheck[x + yyn] == x)
922 strcat(msg, count == 0 ? ", expecting `" : " or `");
923 strcat(msg, yytname[x]);
924 strcat(msg, "'");
925 count++;
928 yyerror(msg);
929 free(msg);
931 else
932 yyerror ("parse error; also virtual memory exceeded");
934 else
935 #endif /* YYERROR_VERBOSE */
936 yyerror("parse error");
939 goto yyerrlab1;
940 yyerrlab1: /* here on error raised explicitly by an action */
942 if (yyerrstatus == 3)
944 /* if just tried and failed to reuse lookahead token after an error, discard it. */
946 /* return failure if at end of input */
947 if (yychar == YYEOF)
948 YYABORT;
950 #if YYDEBUG != 0
951 if (yydebug)
952 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
953 #endif
955 yychar = YYEMPTY;
958 /* Else will try to reuse lookahead token
959 after shifting the error token. */
961 yyerrstatus = 3; /* Each real token shifted decrements this */
963 goto yyerrhandle;
965 yyerrdefault: /* current state does not do anything special for the error token. */
967 #if 0
968 /* This is wrong; only states that explicitly want error tokens
969 should shift them. */
970 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
971 if (yyn) goto yydefault;
972 #endif
974 yyerrpop: /* pop the current state because it cannot handle the error token */
976 if (yyssp == yyss) YYABORT;
977 yyvsp--;
978 yystate = *--yyssp;
979 #ifdef YYLSP_NEEDED
980 yylsp--;
981 #endif
983 #if YYDEBUG != 0
984 if (yydebug)
986 short *ssp1 = yyss - 1;
987 fprintf (stderr, "Error: state stack now");
988 while (ssp1 != yyssp)
989 fprintf (stderr, " %d", *++ssp1);
990 fprintf (stderr, "\n");
992 #endif
994 yyerrhandle:
996 yyn = yypact[yystate];
997 if (yyn == YYFLAG)
998 goto yyerrdefault;
1000 yyn += YYTERROR;
1001 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1002 goto yyerrdefault;
1004 yyn = yytable[yyn];
1005 if (yyn < 0)
1007 if (yyn == YYFLAG)
1008 goto yyerrpop;
1009 yyn = -yyn;
1010 goto yyreduce;
1012 else if (yyn == 0)
1013 goto yyerrpop;
1015 if (yyn == YYFINAL)
1016 YYACCEPT;
1018 #if YYDEBUG != 0
1019 if (yydebug)
1020 fprintf(stderr, "Shifting error token, ");
1021 #endif
1023 *++yyvsp = yylval;
1024 #ifdef YYLSP_NEEDED
1025 *++yylsp = yylloc;
1026 #endif
1028 yystate = yyn;
1029 goto yynewstate;
1031 yyacceptlab:
1032 /* YYACCEPT comes here. */
1033 if (yyfree_stacks)
1035 free (yyss);
1036 free (yyvs);
1037 #ifdef YYLSP_NEEDED
1038 free (yyls);
1039 #endif
1041 return 0;
1043 yyabortlab:
1044 /* YYABORT comes here. */
1045 if (yyfree_stacks)
1047 free (yyss);
1048 free (yyvs);
1049 #ifdef YYLSP_NEEDED
1050 free (yyls);
1051 #endif
1053 return 1;
1055 #line 128 "plural.y"
1058 static struct expression *
1059 new_exp (enum operator op, ...)
1061 struct expression *newp = (struct expression *) malloc (sizeof (*newp));
1062 va_list va;
1063 struct expression *next;
1065 va_start (va, op);
1067 if (newp == NULL)
1068 while ((next = va_arg (va, struct expression *)) != NULL)
1069 __gettext_free_exp (next);
1070 else
1072 newp->operation = op;
1073 next = va_arg (va, struct expression *);
1074 if (next != NULL)
1076 newp->val.args3.bexp = next;
1077 next = va_arg (va, struct expression *);
1078 if (next != NULL)
1080 newp->val.args3.tbranch = next;
1081 next = va_arg (va, struct expression *);
1082 if (next != NULL)
1083 newp->val.args3.fbranch = next;
1088 va_end (va);
1090 return newp;
1093 void
1094 internal_function
1095 __gettext_free_exp (struct expression *exp)
1097 if (exp == NULL)
1098 return;
1100 /* Handle the recursive case. */
1101 switch (exp->operation)
1103 case qmop:
1104 __gettext_free_exp (exp->val.args3.fbranch);
1105 /* FALLTHROUGH */
1107 case mult:
1108 case divide:
1109 case module:
1110 case plus:
1111 case minus:
1112 case equal:
1113 case not_equal:
1114 case land:
1115 case lor:
1116 __gettext_free_exp (exp->val.args2.right);
1117 __gettext_free_exp (exp->val.args2.left);
1118 break;
1120 default:
1121 break;
1124 free (exp);
1128 static int
1129 yylex (YYSTYPE *lval, const char **pexp)
1131 const char *exp = *pexp;
1132 int result;
1134 while (1)
1136 if (exp[0] == '\\' && exp[1] == '\n')
1138 exp += 2;
1139 continue;
1141 if (exp[0] != '\0' && exp[0] != ' ' && exp[0] != '\t')
1142 break;
1144 ++exp;
1147 result = *exp++;
1148 switch (result)
1150 case '0' ... '9':
1152 unsigned long int n = exp[-1] - '0';
1153 while (exp[0] >= '0' && exp[0] <= '9')
1155 n *= 10;
1156 n += exp[0] - '0';
1157 ++exp;
1159 lval->num = n;
1160 result = NUMBER;
1162 break;
1164 case '=':
1165 case '!':
1166 if (exp[0] == '=')
1167 ++exp;
1168 else
1169 result = YYERRCODE;
1170 break;
1172 case '&':
1173 case '|':
1174 if (exp[0] == result)
1175 ++exp;
1176 else
1177 result = YYERRCODE;
1178 break;
1180 case 'n':
1181 case '*':
1182 case '/':
1183 case '%':
1184 case '+':
1185 case '-':
1186 case '?':
1187 case ':':
1188 case '(':
1189 case ')':
1190 /* Nothing, just return the character. */
1191 break;
1193 case '\n':
1194 case '\0':
1195 /* Be safe and let the user call this function again. */
1196 --exp;
1197 result = YYEOF;
1198 break;
1200 default:
1201 result = YYERRCODE;
1202 #if YYDEBUG != 0
1203 --exp;
1204 #endif
1205 break;
1208 *pexp = exp;
1210 return result;
1214 static void
1215 yyerror (const char *str)
1217 /* Do nothing. We don't print error messages here. */