This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / intl / plural.c
blob8883ff83b4154fa9a6cf538f62997a7933bb7066
1 /* A Bison parser, made from plural.y
2 by GNU bison 1.35. */
4 #define YYBISON 1 /* Identify Bison output. */
6 #define yyparse __gettextparse
7 #define yylex __gettextlex
8 #define yyerror __gettexterror
9 #define yylval __gettextlval
10 #define yychar __gettextchar
11 #define yydebug __gettextdebug
12 #define yynerrs __gettextnerrs
13 # define EQUOP2 257
14 # define CMPOP2 258
15 # define ADDOP2 259
16 # define MULOP2 260
17 # define NUMBER 261
19 #line 1 "plural.y"
21 /* Expression parsing for plural form selection.
22 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
23 Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
25 This program is free software; you can redistribute it and/or modify it
26 under the terms of the GNU Library General Public License as published
27 by the Free Software Foundation; either version 2, or (at your option)
28 any later version.
30 This program is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 Library General Public License for more details.
35 You should have received a copy of the GNU Library General Public
36 License along with this program; if not, write to the Free Software
37 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
38 USA. */
40 /* The bison generated parser uses alloca. AIX 3 forces us to put this
41 declaration at the beginning of the file. The declaration in bison's
42 skeleton file comes too late. This must come before <config.h>
43 because <config.h> may include arbitrary system headers. */
44 #if defined _AIX && !defined __GNUC__
45 #pragma alloca
46 #endif
48 #ifdef HAVE_CONFIG_H
49 # include <config.h>
50 #endif
52 #include <stddef.h>
53 #include <stdlib.h>
54 #include "plural-exp.h"
56 /* The main function generated by the parser is called __gettextparse,
57 but we want it to be called PLURAL_PARSE. */
58 #ifndef _LIBC
59 # define __gettextparse PLURAL_PARSE
60 #endif
62 #define YYLEX_PARAM &((struct parse_args *) arg)->cp
63 #define YYPARSE_PARAM arg
65 #line 49 "plural.y"
66 #ifndef YYSTYPE
67 typedef union {
68 unsigned long int num;
69 enum operator op;
70 struct expression *exp;
71 } yystype;
72 # define YYSTYPE yystype
73 # define YYSTYPE_IS_TRIVIAL 1
74 #endif
75 #line 55 "plural.y"
77 /* Prototypes for local functions. */
79 #ifndef __GNUC__
80 #define inline /* nothing: don't inline if the compiler is not GCC */
81 #endif
83 static struct expression *new_exp PARAMS ((int nargs, enum operator op,
84 struct expression * const *args));
85 static inline struct expression *new_exp_0 PARAMS ((enum operator op));
86 static inline struct expression *new_exp_1 PARAMS ((enum operator op,
87 struct expression *right));
88 static struct expression *new_exp_2 PARAMS ((enum operator op,
89 struct expression *left,
90 struct expression *right));
91 static inline struct expression *new_exp_3 PARAMS ((enum operator op,
92 struct expression *bexp,
93 struct expression *tbranch,
94 struct expression *fbranch));
95 static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
96 static void yyerror PARAMS ((const char *str));
98 /* Allocation of expressions. */
100 static struct expression *
101 new_exp (nargs, op, args)
102 int nargs;
103 enum operator op;
104 struct expression * const *args;
106 int i;
107 struct expression *newp;
109 /* If any of the argument could not be malloc'ed, just return NULL. */
110 for (i = nargs - 1; i >= 0; i--)
111 if (args[i] == NULL)
112 goto fail;
114 /* Allocate a new expression. */
115 newp = (struct expression *) malloc (sizeof (*newp));
116 if (newp != NULL)
118 newp->nargs = nargs;
119 newp->operation = op;
120 for (i = nargs - 1; i >= 0; i--)
121 newp->val.args[i] = args[i];
122 return newp;
125 fail:
126 for (i = nargs - 1; i >= 0; i--)
127 FREE_EXPRESSION (args[i]);
129 return NULL;
132 static inline struct expression *
133 new_exp_0 (op)
134 enum operator op;
136 return new_exp (0, op, NULL);
139 static inline struct expression *
140 new_exp_1 (op, right)
141 enum operator op;
142 struct expression *right;
144 struct expression *args[1];
146 args[0] = right;
147 return new_exp (1, op, args);
150 static struct expression *
151 new_exp_2 (op, left, right)
152 enum operator op;
153 struct expression *left;
154 struct expression *right;
156 struct expression *args[2];
158 args[0] = left;
159 args[1] = right;
160 return new_exp (2, op, args);
163 static inline struct expression *
164 new_exp_3 (op, bexp, tbranch, fbranch)
165 enum operator op;
166 struct expression *bexp;
167 struct expression *tbranch;
168 struct expression *fbranch;
170 struct expression *args[3];
172 args[0] = bexp;
173 args[1] = tbranch;
174 args[2] = fbranch;
175 return new_exp (3, op, args);
178 #ifndef YYDEBUG
179 # define YYDEBUG 0
180 #endif
184 #define YYFINAL 27
185 #define YYFLAG -32768
186 #define YYNTBASE 16
188 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
189 #define YYTRANSLATE(x) ((unsigned)(x) <= 261 ? yytranslate[x] : 18)
191 /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
192 static const char yytranslate[] =
194 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
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, 10, 2, 2, 2, 2, 5, 2,
198 14, 15, 2, 2, 2, 2, 2, 2, 2, 2,
199 2, 2, 2, 2, 2, 2, 2, 2, 12, 2,
200 2, 2, 2, 3, 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 13, 2, 2, 2, 2, 2, 2, 2, 2, 2,
206 2, 2, 2, 2, 4, 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, 1, 6, 7, 8,
220 9, 11
223 #if YYDEBUG
224 static const short yyprhs[] =
226 0, 0, 2, 8, 12, 16, 20, 24, 28, 32,
227 35, 37, 39
229 static const short yyrhs[] =
231 17, 0, 17, 3, 17, 12, 17, 0, 17, 4,
232 17, 0, 17, 5, 17, 0, 17, 6, 17, 0,
233 17, 7, 17, 0, 17, 8, 17, 0, 17, 9,
234 17, 0, 10, 17, 0, 13, 0, 11, 0, 14,
235 17, 15, 0
238 #endif
240 #if YYDEBUG
241 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
242 static const short yyrline[] =
244 0, 179, 187, 191, 195, 199, 203, 207, 211, 215,
245 219, 223, 228
247 #endif
250 #if (YYDEBUG) || defined YYERROR_VERBOSE
252 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
253 static const char *const yytname[] =
255 "$", "error", "$undefined.", "'?'", "'|'", "'&'", "EQUOP2", "CMPOP2",
256 "ADDOP2", "MULOP2", "'!'", "NUMBER", "':'", "'n'", "'('", "')'",
257 "start", "exp", 0
259 #endif
261 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
262 static const short yyr1[] =
264 0, 16, 17, 17, 17, 17, 17, 17, 17, 17,
265 17, 17, 17
268 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
269 static const short yyr2[] =
271 0, 1, 5, 3, 3, 3, 3, 3, 3, 2,
272 1, 1, 3
275 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
276 doesn't specify something else to do. Zero means the default is an
277 error. */
278 static const short yydefact[] =
280 0, 0, 11, 10, 0, 1, 9, 0, 0, 0,
281 0, 0, 0, 0, 0, 12, 0, 3, 4, 5,
282 6, 7, 8, 0, 2, 0, 0, 0
285 static const short yydefgoto[] =
287 25, 5
290 static const short yypact[] =
292 -9, -9,-32768,-32768, -9, 34,-32768, 11, -9, -9,
293 -9, -9, -9, -9, -9,-32768, 24, 39, 43, 16,
294 26, -3,-32768, -9, 34, 21, 53,-32768
297 static const short yypgoto[] =
299 -32768, -1
303 #define YYLAST 53
306 static const short yytable[] =
308 6, 1, 2, 7, 3, 4, 14, 16, 17, 18,
309 19, 20, 21, 22, 8, 9, 10, 11, 12, 13,
310 14, 26, 24, 12, 13, 14, 15, 8, 9, 10,
311 11, 12, 13, 14, 13, 14, 23, 8, 9, 10,
312 11, 12, 13, 14, 10, 11, 12, 13, 14, 11,
313 12, 13, 14, 27
316 static const short yycheck[] =
318 1, 10, 11, 4, 13, 14, 9, 8, 9, 10,
319 11, 12, 13, 14, 3, 4, 5, 6, 7, 8,
320 9, 0, 23, 7, 8, 9, 15, 3, 4, 5,
321 6, 7, 8, 9, 8, 9, 12, 3, 4, 5,
322 6, 7, 8, 9, 5, 6, 7, 8, 9, 6,
323 7, 8, 9, 0
325 #define YYPURE 1
327 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
328 #line 3 "/usr/share/bison/bison.simple"
330 /* Skeleton output parser for bison,
332 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
333 Foundation, Inc.
335 This program is free software; you can redistribute it and/or modify
336 it under the terms of the GNU General Public License as published by
337 the Free Software Foundation; either version 2, or (at your option)
338 any later version.
340 This program is distributed in the hope that it will be useful,
341 but WITHOUT ANY WARRANTY; without even the implied warranty of
342 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
343 GNU General Public License for more details.
345 You should have received a copy of the GNU General Public License
346 along with this program; if not, write to the Free Software
347 Foundation, Inc., 59 Temple Place - Suite 330,
348 Boston, MA 02111-1307, USA. */
350 /* As a special exception, when this file is copied by Bison into a
351 Bison output file, you may use that output file without restriction.
352 This special exception was added by the Free Software Foundation
353 in version 1.24 of Bison. */
355 /* This is the parser code that is written into each bison parser when
356 the %semantic_parser declaration is not specified in the grammar.
357 It was written by Richard Stallman by simplifying the hairy parser
358 used when %semantic_parser is specified. */
360 /* All symbols defined below should begin with yy or YY, to avoid
361 infringing on user name space. This should be done even for local
362 variables, as they might otherwise be expanded by user macros.
363 There are some unavoidable exceptions within include files to
364 define necessary library symbols; they are noted "INFRINGES ON
365 USER NAME SPACE" below. */
367 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
369 /* The parser invokes alloca or malloc; define the necessary symbols. */
371 # if YYSTACK_USE_ALLOCA
372 # define YYSTACK_ALLOC alloca
373 # else
374 # ifndef YYSTACK_USE_ALLOCA
375 # if defined (alloca) || defined (_ALLOCA_H)
376 # define YYSTACK_ALLOC alloca
377 # else
378 # ifdef __GNUC__
379 # define YYSTACK_ALLOC __builtin_alloca
380 # endif
381 # endif
382 # endif
383 # endif
385 # ifdef YYSTACK_ALLOC
386 /* Pacify GCC's `empty if-body' warning. */
387 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
388 # else
389 # if defined (__STDC__) || defined (__cplusplus)
390 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
391 # define YYSIZE_T size_t
392 # endif
393 # define YYSTACK_ALLOC malloc
394 # define YYSTACK_FREE free
395 # endif
396 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
399 #if (! defined (yyoverflow) \
400 && (! defined (__cplusplus) \
401 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
403 /* A type that is properly aligned for any stack member. */
404 union yyalloc
406 short yyss;
407 YYSTYPE yyvs;
408 # if YYLSP_NEEDED
409 YYLTYPE yyls;
410 # endif
413 /* The size of the maximum gap between one aligned stack and the next. */
414 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
416 /* The size of an array large to enough to hold all stacks, each with
417 N elements. */
418 # if YYLSP_NEEDED
419 # define YYSTACK_BYTES(N) \
420 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
421 + 2 * YYSTACK_GAP_MAX)
422 # else
423 # define YYSTACK_BYTES(N) \
424 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
425 + YYSTACK_GAP_MAX)
426 # endif
428 /* Copy COUNT objects from FROM to TO. The source and destination do
429 not overlap. */
430 # ifndef YYCOPY
431 # if 1 < __GNUC__
432 # define YYCOPY(To, From, Count) \
433 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
434 # else
435 # define YYCOPY(To, From, Count) \
436 do \
438 register YYSIZE_T yyi; \
439 for (yyi = 0; yyi < (Count); yyi++) \
440 (To)[yyi] = (From)[yyi]; \
442 while (0)
443 # endif
444 # endif
446 /* Relocate STACK from its old location to the new one. The
447 local variables YYSIZE and YYSTACKSIZE give the old and new number of
448 elements in the stack, and YYPTR gives the new location of the
449 stack. Advance YYPTR to a properly aligned location for the next
450 stack. */
451 # define YYSTACK_RELOCATE(Stack) \
452 do \
454 YYSIZE_T yynewbytes; \
455 YYCOPY (&yyptr->Stack, Stack, yysize); \
456 Stack = &yyptr->Stack; \
457 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \
458 yyptr += yynewbytes / sizeof (*yyptr); \
460 while (0)
462 #endif
465 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
466 # define YYSIZE_T __SIZE_TYPE__
467 #endif
468 #if ! defined (YYSIZE_T) && defined (size_t)
469 # define YYSIZE_T size_t
470 #endif
471 #if ! defined (YYSIZE_T)
472 # if defined (__STDC__) || defined (__cplusplus)
473 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
474 # define YYSIZE_T size_t
475 # endif
476 #endif
477 #if ! defined (YYSIZE_T)
478 # define YYSIZE_T unsigned int
479 #endif
481 #define yyerrok (yyerrstatus = 0)
482 #define yyclearin (yychar = YYEMPTY)
483 #define YYEMPTY -2
484 #define YYEOF 0
485 #define YYACCEPT goto yyacceptlab
486 #define YYABORT goto yyabortlab
487 #define YYERROR goto yyerrlab1
488 /* Like YYERROR except do call yyerror. This remains here temporarily
489 to ease the transition to the new meaning of YYERROR, for GCC.
490 Once GCC version 2 has supplanted version 1, this can go. */
491 #define YYFAIL goto yyerrlab
492 #define YYRECOVERING() (!!yyerrstatus)
493 #define YYBACKUP(Token, Value) \
494 do \
495 if (yychar == YYEMPTY && yylen == 1) \
497 yychar = (Token); \
498 yylval = (Value); \
499 yychar1 = YYTRANSLATE (yychar); \
500 YYPOPSTACK; \
501 goto yybackup; \
503 else \
505 yyerror ("syntax error: cannot back up"); \
506 YYERROR; \
508 while (0)
510 #define YYTERROR 1
511 #define YYERRCODE 256
514 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
515 are run).
517 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
518 first token. By default, to implement support for ranges, extend
519 its range to the last symbol. */
521 #ifndef YYLLOC_DEFAULT
522 # define YYLLOC_DEFAULT(Current, Rhs, N) \
523 Current.last_line = Rhs[N].last_line; \
524 Current.last_column = Rhs[N].last_column;
525 #endif
528 /* YYLEX -- calling `yylex' with the right arguments. */
530 #if YYPURE
531 # if YYLSP_NEEDED
532 # ifdef YYLEX_PARAM
533 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
534 # else
535 # define YYLEX yylex (&yylval, &yylloc)
536 # endif
537 # else /* !YYLSP_NEEDED */
538 # ifdef YYLEX_PARAM
539 # define YYLEX yylex (&yylval, YYLEX_PARAM)
540 # else
541 # define YYLEX yylex (&yylval)
542 # endif
543 # endif /* !YYLSP_NEEDED */
544 #else /* !YYPURE */
545 # define YYLEX yylex ()
546 #endif /* !YYPURE */
549 /* Enable debugging if requested. */
550 #if YYDEBUG
552 # ifndef YYFPRINTF
553 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
554 # define YYFPRINTF fprintf
555 # endif
557 # define YYDPRINTF(Args) \
558 do { \
559 if (yydebug) \
560 YYFPRINTF Args; \
561 } while (0)
562 /* Nonzero means print parse trace. It is left uninitialized so that
563 multiple parsers can coexist. */
564 int yydebug;
565 #else /* !YYDEBUG */
566 # define YYDPRINTF(Args)
567 #endif /* !YYDEBUG */
569 /* YYINITDEPTH -- initial size of the parser's stacks. */
570 #ifndef YYINITDEPTH
571 # define YYINITDEPTH 200
572 #endif
574 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
575 if the built-in stack extension method is used).
577 Do not make this value too large; the results are undefined if
578 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
579 evaluated with infinite-precision integer arithmetic. */
581 #if YYMAXDEPTH == 0
582 # undef YYMAXDEPTH
583 #endif
585 #ifndef YYMAXDEPTH
586 # define YYMAXDEPTH 10000
587 #endif
589 #ifdef YYERROR_VERBOSE
591 # ifndef yystrlen
592 # if defined (__GLIBC__) && defined (_STRING_H)
593 # define yystrlen strlen
594 # else
595 /* Return the length of YYSTR. */
596 static YYSIZE_T
597 # if defined (__STDC__) || defined (__cplusplus)
598 yystrlen (const char *yystr)
599 # else
600 yystrlen (yystr)
601 const char *yystr;
602 # endif
604 register const char *yys = yystr;
606 while (*yys++ != '\0')
607 continue;
609 return yys - yystr - 1;
611 # endif
612 # endif
614 # ifndef yystpcpy
615 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
616 # define yystpcpy stpcpy
617 # else
618 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
619 YYDEST. */
620 static char *
621 # if defined (__STDC__) || defined (__cplusplus)
622 yystpcpy (char *yydest, const char *yysrc)
623 # else
624 yystpcpy (yydest, yysrc)
625 char *yydest;
626 const char *yysrc;
627 # endif
629 register char *yyd = yydest;
630 register const char *yys = yysrc;
632 while ((*yyd++ = *yys++) != '\0')
633 continue;
635 return yyd - 1;
637 # endif
638 # endif
639 #endif
641 #line 315 "/usr/share/bison/bison.simple"
644 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
645 into yyparse. The argument should have type void *.
646 It should actually point to an object.
647 Grammar actions can access the variable by casting it
648 to the proper pointer type. */
650 #ifdef YYPARSE_PARAM
651 # if defined (__STDC__) || defined (__cplusplus)
652 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
653 # define YYPARSE_PARAM_DECL
654 # else
655 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
656 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
657 # endif
658 #else /* !YYPARSE_PARAM */
659 # define YYPARSE_PARAM_ARG
660 # define YYPARSE_PARAM_DECL
661 #endif /* !YYPARSE_PARAM */
663 /* Prevent warning if -Wstrict-prototypes. */
664 #ifdef __GNUC__
665 # ifdef YYPARSE_PARAM
666 int yyparse (void *);
667 # else
668 int yyparse (void);
669 # endif
670 #endif
672 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
673 variables are global, or local to YYPARSE. */
675 #define YY_DECL_NON_LSP_VARIABLES \
676 /* The lookahead symbol. */ \
677 int yychar; \
679 /* The semantic value of the lookahead symbol. */ \
680 YYSTYPE yylval; \
682 /* Number of parse errors so far. */ \
683 int yynerrs;
685 #if YYLSP_NEEDED
686 # define YY_DECL_VARIABLES \
687 YY_DECL_NON_LSP_VARIABLES \
689 /* Location data for the lookahead symbol. */ \
690 YYLTYPE yylloc;
691 #else
692 # define YY_DECL_VARIABLES \
693 YY_DECL_NON_LSP_VARIABLES
694 #endif
697 /* If nonreentrant, generate the variables here. */
699 #if !YYPURE
700 YY_DECL_VARIABLES
701 #endif /* !YYPURE */
704 yyparse (YYPARSE_PARAM_ARG)
705 YYPARSE_PARAM_DECL
707 /* If reentrant, generate the variables here. */
708 #if YYPURE
709 YY_DECL_VARIABLES
710 #endif /* !YYPURE */
712 register int yystate;
713 register int yyn;
714 int yyresult;
715 /* Number of tokens to shift before error messages enabled. */
716 int yyerrstatus;
717 /* Lookahead token as an internal (translated) token number. */
718 int yychar1 = 0;
720 /* Three stacks and their tools:
721 `yyss': related to states,
722 `yyvs': related to semantic values,
723 `yyls': related to locations.
725 Refer to the stacks thru separate pointers, to allow yyoverflow
726 to reallocate them elsewhere. */
728 /* The state stack. */
729 short yyssa[YYINITDEPTH];
730 short *yyss = yyssa;
731 register short *yyssp;
733 /* The semantic value stack. */
734 YYSTYPE yyvsa[YYINITDEPTH];
735 YYSTYPE *yyvs = yyvsa;
736 register YYSTYPE *yyvsp;
738 #if YYLSP_NEEDED
739 /* The location stack. */
740 YYLTYPE yylsa[YYINITDEPTH];
741 YYLTYPE *yyls = yylsa;
742 YYLTYPE *yylsp;
743 #endif
745 #if YYLSP_NEEDED
746 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
747 #else
748 # define YYPOPSTACK (yyvsp--, yyssp--)
749 #endif
751 YYSIZE_T yystacksize = YYINITDEPTH;
754 /* The variables used to return semantic value and location from the
755 action routines. */
756 YYSTYPE yyval;
757 #if YYLSP_NEEDED
758 YYLTYPE yyloc;
759 #endif
761 /* When reducing, the number of symbols on the RHS of the reduced
762 rule. */
763 int yylen;
765 YYDPRINTF ((stderr, "Starting parse\n"));
767 yystate = 0;
768 yyerrstatus = 0;
769 yynerrs = 0;
770 yychar = YYEMPTY; /* Cause a token to be read. */
772 /* Initialize stack pointers.
773 Waste one element of value and location stack
774 so that they stay on the same level as the state stack.
775 The wasted elements are never initialized. */
777 yyssp = yyss;
778 yyvsp = yyvs;
779 #if YYLSP_NEEDED
780 yylsp = yyls;
781 #endif
782 goto yysetstate;
784 /*------------------------------------------------------------.
785 | yynewstate -- Push a new state, which is found in yystate. |
786 `------------------------------------------------------------*/
787 yynewstate:
788 /* In all cases, when you get here, the value and location stacks
789 have just been pushed. so pushing a state here evens the stacks.
791 yyssp++;
793 yysetstate:
794 *yyssp = yystate;
796 if (yyssp >= yyss + yystacksize - 1)
798 /* Get the current used size of the three stacks, in elements. */
799 YYSIZE_T yysize = yyssp - yyss + 1;
801 #ifdef yyoverflow
803 /* Give user a chance to reallocate the stack. Use copies of
804 these so that the &'s don't force the real ones into
805 memory. */
806 YYSTYPE *yyvs1 = yyvs;
807 short *yyss1 = yyss;
809 /* Each stack pointer address is followed by the size of the
810 data in use in that stack, in bytes. */
811 # if YYLSP_NEEDED
812 YYLTYPE *yyls1 = yyls;
813 /* This used to be a conditional around just the two extra args,
814 but that might be undefined if yyoverflow is a macro. */
815 yyoverflow ("parser stack overflow",
816 &yyss1, yysize * sizeof (*yyssp),
817 &yyvs1, yysize * sizeof (*yyvsp),
818 &yyls1, yysize * sizeof (*yylsp),
819 &yystacksize);
820 yyls = yyls1;
821 # else
822 yyoverflow ("parser stack overflow",
823 &yyss1, yysize * sizeof (*yyssp),
824 &yyvs1, yysize * sizeof (*yyvsp),
825 &yystacksize);
826 # endif
827 yyss = yyss1;
828 yyvs = yyvs1;
830 #else /* no yyoverflow */
831 # ifndef YYSTACK_RELOCATE
832 goto yyoverflowlab;
833 # else
834 /* Extend the stack our own way. */
835 if (yystacksize >= YYMAXDEPTH)
836 goto yyoverflowlab;
837 yystacksize *= 2;
838 if (yystacksize > YYMAXDEPTH)
839 yystacksize = YYMAXDEPTH;
842 short *yyss1 = yyss;
843 union yyalloc *yyptr =
844 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
845 if (! yyptr)
846 goto yyoverflowlab;
847 YYSTACK_RELOCATE (yyss);
848 YYSTACK_RELOCATE (yyvs);
849 # if YYLSP_NEEDED
850 YYSTACK_RELOCATE (yyls);
851 # endif
852 # undef YYSTACK_RELOCATE
853 if (yyss1 != yyssa)
854 YYSTACK_FREE (yyss1);
856 # endif
857 #endif /* no yyoverflow */
859 yyssp = yyss + yysize - 1;
860 yyvsp = yyvs + yysize - 1;
861 #if YYLSP_NEEDED
862 yylsp = yyls + yysize - 1;
863 #endif
865 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
866 (unsigned long int) yystacksize));
868 if (yyssp >= yyss + yystacksize - 1)
869 YYABORT;
872 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
874 goto yybackup;
877 /*-----------.
878 | yybackup. |
879 `-----------*/
880 yybackup:
882 /* Do appropriate processing given the current state. */
883 /* Read a lookahead token if we need one and don't already have one. */
884 /* yyresume: */
886 /* First try to decide what to do without reference to lookahead token. */
888 yyn = yypact[yystate];
889 if (yyn == YYFLAG)
890 goto yydefault;
892 /* Not known => get a lookahead token if don't already have one. */
894 /* yychar is either YYEMPTY or YYEOF
895 or a valid token in external form. */
897 if (yychar == YYEMPTY)
899 YYDPRINTF ((stderr, "Reading a token: "));
900 yychar = YYLEX;
903 /* Convert token to internal form (in yychar1) for indexing tables with */
905 if (yychar <= 0) /* This means end of input. */
907 yychar1 = 0;
908 yychar = YYEOF; /* Don't call YYLEX any more */
910 YYDPRINTF ((stderr, "Now at end of input.\n"));
912 else
914 yychar1 = YYTRANSLATE (yychar);
916 #if YYDEBUG
917 /* We have to keep this `#if YYDEBUG', since we use variables
918 which are defined only if `YYDEBUG' is set. */
919 if (yydebug)
921 YYFPRINTF (stderr, "Next token is %d (%s",
922 yychar, yytname[yychar1]);
923 /* Give the individual parser a way to print the precise
924 meaning of a token, for further debugging info. */
925 # ifdef YYPRINT
926 YYPRINT (stderr, yychar, yylval);
927 # endif
928 YYFPRINTF (stderr, ")\n");
930 #endif
933 yyn += yychar1;
934 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
935 goto yydefault;
937 yyn = yytable[yyn];
939 /* yyn is what to do for this token type in this state.
940 Negative => reduce, -yyn is rule number.
941 Positive => shift, yyn is new state.
942 New state is final state => don't bother to shift,
943 just return success.
944 0, or most negative number => error. */
946 if (yyn < 0)
948 if (yyn == YYFLAG)
949 goto yyerrlab;
950 yyn = -yyn;
951 goto yyreduce;
953 else if (yyn == 0)
954 goto yyerrlab;
956 if (yyn == YYFINAL)
957 YYACCEPT;
959 /* Shift the lookahead token. */
960 YYDPRINTF ((stderr, "Shifting token %d (%s), ",
961 yychar, yytname[yychar1]));
963 /* Discard the token being shifted unless it is eof. */
964 if (yychar != YYEOF)
965 yychar = YYEMPTY;
967 *++yyvsp = yylval;
968 #if YYLSP_NEEDED
969 *++yylsp = yylloc;
970 #endif
972 /* Count tokens shifted since error; after three, turn off error
973 status. */
974 if (yyerrstatus)
975 yyerrstatus--;
977 yystate = yyn;
978 goto yynewstate;
981 /*-----------------------------------------------------------.
982 | yydefault -- do the default action for the current state. |
983 `-----------------------------------------------------------*/
984 yydefault:
985 yyn = yydefact[yystate];
986 if (yyn == 0)
987 goto yyerrlab;
988 goto yyreduce;
991 /*-----------------------------.
992 | yyreduce -- Do a reduction. |
993 `-----------------------------*/
994 yyreduce:
995 /* yyn is the number of a rule to reduce with. */
996 yylen = yyr2[yyn];
998 /* If YYLEN is nonzero, implement the default value of the action:
999 `$$ = $1'.
1001 Otherwise, the following line sets YYVAL to the semantic value of
1002 the lookahead token. This behavior is undocumented and Bison
1003 users should not rely upon it. Assigning to YYVAL
1004 unconditionally makes the parser a bit smaller, and it avoids a
1005 GCC warning that YYVAL may be used uninitialized. */
1006 yyval = yyvsp[1-yylen];
1008 #if YYLSP_NEEDED
1009 /* Similarly for the default location. Let the user run additional
1010 commands if for instance locations are ranges. */
1011 yyloc = yylsp[1-yylen];
1012 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1013 #endif
1015 #if YYDEBUG
1016 /* We have to keep this `#if YYDEBUG', since we use variables which
1017 are defined only if `YYDEBUG' is set. */
1018 if (yydebug)
1020 int yyi;
1022 YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
1023 yyn, yyrline[yyn]);
1025 /* Print the symbols being reduced, and their result. */
1026 for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
1027 YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
1028 YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1030 #endif
1032 switch (yyn) {
1034 case 1:
1035 #line 180 "plural.y"
1037 if (yyvsp[0].exp == NULL)
1038 YYABORT;
1039 ((struct parse_args *) arg)->res = yyvsp[0].exp;
1041 break;
1042 case 2:
1043 #line 188 "plural.y"
1045 yyval.exp = new_exp_3 (qmop, yyvsp[-4].exp, yyvsp[-2].exp, yyvsp[0].exp);
1047 break;
1048 case 3:
1049 #line 192 "plural.y"
1051 yyval.exp = new_exp_2 (lor, yyvsp[-2].exp, yyvsp[0].exp);
1053 break;
1054 case 4:
1055 #line 196 "plural.y"
1057 yyval.exp = new_exp_2 (land, yyvsp[-2].exp, yyvsp[0].exp);
1059 break;
1060 case 5:
1061 #line 200 "plural.y"
1063 yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
1065 break;
1066 case 6:
1067 #line 204 "plural.y"
1069 yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
1071 break;
1072 case 7:
1073 #line 208 "plural.y"
1075 yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
1077 break;
1078 case 8:
1079 #line 212 "plural.y"
1081 yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp);
1083 break;
1084 case 9:
1085 #line 216 "plural.y"
1087 yyval.exp = new_exp_1 (lnot, yyvsp[0].exp);
1089 break;
1090 case 10:
1091 #line 220 "plural.y"
1093 yyval.exp = new_exp_0 (var);
1095 break;
1096 case 11:
1097 #line 224 "plural.y"
1099 if ((yyval.exp = new_exp_0 (num)) != NULL)
1100 yyval.exp->val.num = yyvsp[0].num;
1102 break;
1103 case 12:
1104 #line 229 "plural.y"
1106 yyval.exp = yyvsp[-1].exp;
1108 break;
1111 #line 705 "/usr/share/bison/bison.simple"
1114 yyvsp -= yylen;
1115 yyssp -= yylen;
1116 #if YYLSP_NEEDED
1117 yylsp -= yylen;
1118 #endif
1120 #if YYDEBUG
1121 if (yydebug)
1123 short *yyssp1 = yyss - 1;
1124 YYFPRINTF (stderr, "state stack now");
1125 while (yyssp1 != yyssp)
1126 YYFPRINTF (stderr, " %d", *++yyssp1);
1127 YYFPRINTF (stderr, "\n");
1129 #endif
1131 *++yyvsp = yyval;
1132 #if YYLSP_NEEDED
1133 *++yylsp = yyloc;
1134 #endif
1136 /* Now `shift' the result of the reduction. Determine what state
1137 that goes to, based on the state we popped back to and the rule
1138 number reduced by. */
1140 yyn = yyr1[yyn];
1142 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1143 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1144 yystate = yytable[yystate];
1145 else
1146 yystate = yydefgoto[yyn - YYNTBASE];
1148 goto yynewstate;
1151 /*------------------------------------.
1152 | yyerrlab -- here on detecting error |
1153 `------------------------------------*/
1154 yyerrlab:
1155 /* If not already recovering from an error, report this error. */
1156 if (!yyerrstatus)
1158 ++yynerrs;
1160 #ifdef YYERROR_VERBOSE
1161 yyn = yypact[yystate];
1163 if (yyn > YYFLAG && yyn < YYLAST)
1165 YYSIZE_T yysize = 0;
1166 char *yymsg;
1167 int yyx, yycount;
1169 yycount = 0;
1170 /* Start YYX at -YYN if negative to avoid negative indexes in
1171 YYCHECK. */
1172 for (yyx = yyn < 0 ? -yyn : 0;
1173 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1174 if (yycheck[yyx + yyn] == yyx)
1175 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1176 yysize += yystrlen ("parse error, unexpected ") + 1;
1177 yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
1178 yymsg = (char *) YYSTACK_ALLOC (yysize);
1179 if (yymsg != 0)
1181 char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
1182 yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
1184 if (yycount < 5)
1186 yycount = 0;
1187 for (yyx = yyn < 0 ? -yyn : 0;
1188 yyx < (int) (sizeof (yytname) / sizeof (char *));
1189 yyx++)
1190 if (yycheck[yyx + yyn] == yyx)
1192 const char *yyq = ! yycount ? ", expecting " : " or ";
1193 yyp = yystpcpy (yyp, yyq);
1194 yyp = yystpcpy (yyp, yytname[yyx]);
1195 yycount++;
1198 yyerror (yymsg);
1199 YYSTACK_FREE (yymsg);
1201 else
1202 yyerror ("parse error; also virtual memory exhausted");
1204 else
1205 #endif /* defined (YYERROR_VERBOSE) */
1206 yyerror ("parse error");
1208 goto yyerrlab1;
1211 /*--------------------------------------------------.
1212 | yyerrlab1 -- error raised explicitly by an action |
1213 `--------------------------------------------------*/
1214 yyerrlab1:
1215 if (yyerrstatus == 3)
1217 /* If just tried and failed to reuse lookahead token after an
1218 error, discard it. */
1220 /* return failure if at end of input */
1221 if (yychar == YYEOF)
1222 YYABORT;
1223 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
1224 yychar, yytname[yychar1]));
1225 yychar = YYEMPTY;
1228 /* Else will try to reuse lookahead token after shifting the error
1229 token. */
1231 yyerrstatus = 3; /* Each real token shifted decrements this */
1233 goto yyerrhandle;
1236 /*-------------------------------------------------------------------.
1237 | yyerrdefault -- current state does not do anything special for the |
1238 | error token. |
1239 `-------------------------------------------------------------------*/
1240 yyerrdefault:
1241 #if 0
1242 /* This is wrong; only states that explicitly want error tokens
1243 should shift them. */
1245 /* If its default is to accept any token, ok. Otherwise pop it. */
1246 yyn = yydefact[yystate];
1247 if (yyn)
1248 goto yydefault;
1249 #endif
1252 /*---------------------------------------------------------------.
1253 | yyerrpop -- pop the current state because it cannot handle the |
1254 | error token |
1255 `---------------------------------------------------------------*/
1256 yyerrpop:
1257 if (yyssp == yyss)
1258 YYABORT;
1259 yyvsp--;
1260 yystate = *--yyssp;
1261 #if YYLSP_NEEDED
1262 yylsp--;
1263 #endif
1265 #if YYDEBUG
1266 if (yydebug)
1268 short *yyssp1 = yyss - 1;
1269 YYFPRINTF (stderr, "Error: state stack now");
1270 while (yyssp1 != yyssp)
1271 YYFPRINTF (stderr, " %d", *++yyssp1);
1272 YYFPRINTF (stderr, "\n");
1274 #endif
1276 /*--------------.
1277 | yyerrhandle. |
1278 `--------------*/
1279 yyerrhandle:
1280 yyn = yypact[yystate];
1281 if (yyn == YYFLAG)
1282 goto yyerrdefault;
1284 yyn += YYTERROR;
1285 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1286 goto yyerrdefault;
1288 yyn = yytable[yyn];
1289 if (yyn < 0)
1291 if (yyn == YYFLAG)
1292 goto yyerrpop;
1293 yyn = -yyn;
1294 goto yyreduce;
1296 else if (yyn == 0)
1297 goto yyerrpop;
1299 if (yyn == YYFINAL)
1300 YYACCEPT;
1302 YYDPRINTF ((stderr, "Shifting error token, "));
1304 *++yyvsp = yylval;
1305 #if YYLSP_NEEDED
1306 *++yylsp = yylloc;
1307 #endif
1309 yystate = yyn;
1310 goto yynewstate;
1313 /*-------------------------------------.
1314 | yyacceptlab -- YYACCEPT comes here. |
1315 `-------------------------------------*/
1316 yyacceptlab:
1317 yyresult = 0;
1318 goto yyreturn;
1320 /*-----------------------------------.
1321 | yyabortlab -- YYABORT comes here. |
1322 `-----------------------------------*/
1323 yyabortlab:
1324 yyresult = 1;
1325 goto yyreturn;
1327 /*---------------------------------------------.
1328 | yyoverflowab -- parser overflow comes here. |
1329 `---------------------------------------------*/
1330 yyoverflowlab:
1331 yyerror ("parser stack overflow");
1332 yyresult = 2;
1333 /* Fall through. */
1335 yyreturn:
1336 #ifndef yyoverflow
1337 if (yyss != yyssa)
1338 YYSTACK_FREE (yyss);
1339 #endif
1340 return yyresult;
1342 #line 234 "plural.y"
1345 void
1346 internal_function
1347 FREE_EXPRESSION (exp)
1348 struct expression *exp;
1350 if (exp == NULL)
1351 return;
1353 /* Handle the recursive case. */
1354 switch (exp->nargs)
1356 case 3:
1357 FREE_EXPRESSION (exp->val.args[2]);
1358 /* FALLTHROUGH */
1359 case 2:
1360 FREE_EXPRESSION (exp->val.args[1]);
1361 /* FALLTHROUGH */
1362 case 1:
1363 FREE_EXPRESSION (exp->val.args[0]);
1364 /* FALLTHROUGH */
1365 default:
1366 break;
1369 free (exp);
1373 static int
1374 yylex (lval, pexp)
1375 YYSTYPE *lval;
1376 const char **pexp;
1378 const char *exp = *pexp;
1379 int result;
1381 while (1)
1383 if (exp[0] == '\0')
1385 *pexp = exp;
1386 return YYEOF;
1389 if (exp[0] != ' ' && exp[0] != '\t')
1390 break;
1392 ++exp;
1395 result = *exp++;
1396 switch (result)
1398 case '0': case '1': case '2': case '3': case '4':
1399 case '5': case '6': case '7': case '8': case '9':
1401 unsigned long int n = result - '0';
1402 while (exp[0] >= '0' && exp[0] <= '9')
1404 n *= 10;
1405 n += exp[0] - '0';
1406 ++exp;
1408 lval->num = n;
1409 result = NUMBER;
1411 break;
1413 case '=':
1414 if (exp[0] == '=')
1416 ++exp;
1417 lval->op = equal;
1418 result = EQUOP2;
1420 else
1421 result = YYERRCODE;
1422 break;
1424 case '!':
1425 if (exp[0] == '=')
1427 ++exp;
1428 lval->op = not_equal;
1429 result = EQUOP2;
1431 break;
1433 case '&':
1434 case '|':
1435 if (exp[0] == result)
1436 ++exp;
1437 else
1438 result = YYERRCODE;
1439 break;
1441 case '<':
1442 if (exp[0] == '=')
1444 ++exp;
1445 lval->op = less_or_equal;
1447 else
1448 lval->op = less_than;
1449 result = CMPOP2;
1450 break;
1452 case '>':
1453 if (exp[0] == '=')
1455 ++exp;
1456 lval->op = greater_or_equal;
1458 else
1459 lval->op = greater_than;
1460 result = CMPOP2;
1461 break;
1463 case '*':
1464 lval->op = mult;
1465 result = MULOP2;
1466 break;
1468 case '/':
1469 lval->op = divide;
1470 result = MULOP2;
1471 break;
1473 case '%':
1474 lval->op = module;
1475 result = MULOP2;
1476 break;
1478 case '+':
1479 lval->op = plus;
1480 result = ADDOP2;
1481 break;
1483 case '-':
1484 lval->op = minus;
1485 result = ADDOP2;
1486 break;
1488 case 'n':
1489 case '?':
1490 case ':':
1491 case '(':
1492 case ')':
1493 /* Nothing, just return the character. */
1494 break;
1496 case ';':
1497 case '\n':
1498 case '\0':
1499 /* Be safe and let the user call this function again. */
1500 --exp;
1501 result = YYEOF;
1502 break;
1504 default:
1505 result = YYERRCODE;
1506 #if YYDEBUG != 0
1507 --exp;
1508 #endif
1509 break;
1512 *pexp = exp;
1514 return result;
1518 static void
1519 yyerror (str)
1520 const char *str;
1522 /* Do nothing. We don't print error messages here. */