1 /* A Bison parser, made by GNU Bison 3.8.2. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
6 Inc.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
20
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
30
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
33
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
36
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
40
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
47
48 /* Identify Bison output, and Bison version. */
49 #define YYBISON 30802
50
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.8.2"
53
54 /* Skeleton name. */
55 #define YYSKELETON_NAME "yacc.c"
56
57 /* Pure parsers. */
58 #define YYPURE 2
59
60 /* Push parsers. */
61 #define YYPUSH 0
62
63 /* Pull parsers. */
64 #define YYPULL 1
65
66
67
68
69 /* First part of user prologue. */
70 #line 19 "cldr-plural.y"
71
72 #ifdef HAVE_CONFIG_H
73 # include <config.h>
74 #endif
75
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <string.h>
79 #include <unistd.h>
80 #include "unistr.h"
81 #include "xalloc.h"
82
83 #include "cldr-plural-exp.h"
84 #include "cldr-plural.h"
85
86 /* Prototypes for local functions. */
87 static int yylex (YYSTYPE *lval, struct cldr_plural_parse_args *arg);
88 static void yyerror (struct cldr_plural_parse_args *arg, const char *str);
89
90 /* Allocation of expressions. */
91
92 static struct cldr_plural_rule_ty *
93 new_rule (char *name, struct cldr_plural_condition_ty *condition)
94 {
95 struct cldr_plural_rule_ty *result =
96 XMALLOC (struct cldr_plural_rule_ty);
97 result->name = name;
98 result->condition = condition;
99 return result;
100 }
101
102 static struct cldr_plural_condition_ty *
103 new_leaf_condition (struct cldr_plural_relation_ty *relation)
104 {
105 struct cldr_plural_condition_ty *result =
106 XMALLOC (struct cldr_plural_condition_ty);
107 result->type = CLDR_PLURAL_CONDITION_RELATION;
108 result->value.relation = relation;
109 return result;
110 }
111
112 static struct cldr_plural_condition_ty *
113 new_branch_condition (enum cldr_plural_condition type,
114 struct cldr_plural_condition_ty *condition0,
115 struct cldr_plural_condition_ty *condition1)
116 {
117 struct cldr_plural_condition_ty *result =
118 XMALLOC (struct cldr_plural_condition_ty);
119 result->type = type;
120 result->value.conditions[0] = condition0;
121 result->value.conditions[1] = condition1;
122 return result;
123 }
124
125 static struct cldr_plural_relation_ty *
126 new_relation (struct cldr_plural_expression_ty *expression,
127 enum cldr_plural_relation type,
128 struct cldr_plural_range_list_ty *ranges)
129 {
130 struct cldr_plural_relation_ty *result =
131 XMALLOC (struct cldr_plural_relation_ty);
132 result->expression = expression;
133 result->type = type;
134 result->ranges = ranges;
135 return result;
136 }
137
138 static struct cldr_plural_expression_ty *
139 new_expression (int operand, int mod)
140 {
141 struct cldr_plural_expression_ty *result =
142 XMALLOC (struct cldr_plural_expression_ty);
143 result->operand = operand;
144 result->mod = mod;
145 return result;
146 }
147
148 static struct cldr_plural_range_list_ty *
149 add_range (struct cldr_plural_range_list_ty *ranges,
150 struct cldr_plural_range_ty *range)
151 {
152 if (ranges->nitems == ranges->nitems_max)
153 {
154 ranges->nitems_max = ranges->nitems_max * 2 + 1;
155 ranges->items = xrealloc (ranges->items,
156 sizeof (struct cldr_plural_range_ty *)
157 * ranges->nitems_max);
158 }
159 ranges->items[ranges->nitems++] = range;
160 return ranges;
161 }
162
163 static struct cldr_plural_range_ty *
164 new_range (struct cldr_plural_operand_ty *start,
165 struct cldr_plural_operand_ty *end)
166 {
167 struct cldr_plural_range_ty *result =
168 XMALLOC (struct cldr_plural_range_ty);
169 result->start = start;
170 result->end = end;
171 return result;
172 }
173
174 #line 175 "cldr-plural.c"
175
176 # ifndef YY_CAST
177 # ifdef __cplusplus
178 # define YY_CAST(Type, Val) static_cast<Type> (Val)
179 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
180 # else
181 # define YY_CAST(Type, Val) ((Type) (Val))
182 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
183 # endif
184 # endif
185 # ifndef YY_NULLPTR
186 # if defined __cplusplus
187 # if 201103L <= __cplusplus
188 # define YY_NULLPTR nullptr
189 # else
190 # define YY_NULLPTR 0
191 # endif
192 # else
193 # define YY_NULLPTR ((void*)0)
194 # endif
195 # endif
196
197 #include "cldr-plural.h"
198 /* Symbol kind. */
199 enum yysymbol_kind_t
200 {
201 YYSYMBOL_YYEMPTY = -2,
202 YYSYMBOL_YYEOF = 0, /* "end of file" */
203 YYSYMBOL_YYerror = 1, /* error */
204 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
205 YYSYMBOL_AND = 3, /* AND */
206 YYSYMBOL_OR = 4, /* OR */
207 YYSYMBOL_RANGE = 5, /* RANGE */
208 YYSYMBOL_ELLIPSIS = 6, /* ELLIPSIS */
209 YYSYMBOL_OTHER = 7, /* OTHER */
210 YYSYMBOL_AT_INTEGER = 8, /* AT_INTEGER */
211 YYSYMBOL_AT_DECIMAL = 9, /* AT_DECIMAL */
212 YYSYMBOL_KEYWORD = 10, /* KEYWORD */
213 YYSYMBOL_INTEGER = 11, /* INTEGER */
214 YYSYMBOL_DECIMAL = 12, /* DECIMAL */
215 YYSYMBOL_OPERAND = 13, /* OPERAND */
216 YYSYMBOL_14_ = 14, /* ';' */
217 YYSYMBOL_15_ = 15, /* ':' */
218 YYSYMBOL_16_ = 16, /* '=' */
219 YYSYMBOL_17_ = 17, /* '!' */
220 YYSYMBOL_18_ = 18, /* '%' */
221 YYSYMBOL_19_ = 19, /* ',' */
222 YYSYMBOL_20_ = 20, /* '~' */
223 YYSYMBOL_YYACCEPT = 21, /* $accept */
224 YYSYMBOL_rules = 22, /* rules */
225 YYSYMBOL_rule = 23, /* rule */
226 YYSYMBOL_condition = 24, /* condition */
227 YYSYMBOL_and_condition = 25, /* and_condition */
228 YYSYMBOL_relation = 26, /* relation */
229 YYSYMBOL_expression = 27, /* expression */
230 YYSYMBOL_range_list = 28, /* range_list */
231 YYSYMBOL_range_or_integer = 29, /* range_or_integer */
232 YYSYMBOL_range = 30, /* range */
233 YYSYMBOL_samples = 31, /* samples */
234 YYSYMBOL_at_integer = 32, /* at_integer */
235 YYSYMBOL_at_decimal = 33, /* at_decimal */
236 YYSYMBOL_sample_list = 34, /* sample_list */
237 YYSYMBOL_sample_list1 = 35, /* sample_list1 */
238 YYSYMBOL_sample_ellipsis = 36, /* sample_ellipsis */
239 YYSYMBOL_sample_range = 37 /* sample_range */
240 };
241 typedef enum yysymbol_kind_t yysymbol_kind_t;
242
243
244
245
246 #ifdef short
247 # undef short
248 #endif
249
250 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
251 <limits.h> and (if available) <stdint.h> are included
252 so that the code can choose integer types of a good width. */
253
254 #ifndef __PTRDIFF_MAX__
255 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
256 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
257 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
258 # define YY_STDINT_H
259 # endif
260 #endif
261
262 /* Narrow types that promote to a signed type and that can represent a
263 signed or unsigned integer of at least N bits. In tables they can
264 save space and decrease cache pressure. Promoting to a signed type
265 helps avoid bugs in integer arithmetic. */
266
267 #ifdef __INT_LEAST8_MAX__
268 typedef __INT_LEAST8_TYPE__ yytype_int8;
269 #elif defined YY_STDINT_H
270 typedef int_least8_t yytype_int8;
271 #else
272 typedef signed char yytype_int8;
273 #endif
274
275 #ifdef __INT_LEAST16_MAX__
276 typedef __INT_LEAST16_TYPE__ yytype_int16;
277 #elif defined YY_STDINT_H
278 typedef int_least16_t yytype_int16;
279 #else
280 typedef short yytype_int16;
281 #endif
282
283 /* Work around bug in HP-UX 11.23, which defines these macros
284 incorrectly for preprocessor constants. This workaround can likely
285 be removed in 2023, as HPE has promised support for HP-UX 11.23
286 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
287 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
288 #ifdef __hpux
289 # undef UINT_LEAST8_MAX
290 # undef UINT_LEAST16_MAX
291 # define UINT_LEAST8_MAX 255
292 # define UINT_LEAST16_MAX 65535
293 #endif
294
295 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
296 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
297 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
298 && UINT_LEAST8_MAX <= INT_MAX)
299 typedef uint_least8_t yytype_uint8;
300 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
301 typedef unsigned char yytype_uint8;
302 #else
303 typedef short yytype_uint8;
304 #endif
305
306 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
307 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
308 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
309 && UINT_LEAST16_MAX <= INT_MAX)
310 typedef uint_least16_t yytype_uint16;
311 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
312 typedef unsigned short yytype_uint16;
313 #else
314 typedef int yytype_uint16;
315 #endif
316
317 #ifndef YYPTRDIFF_T
318 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
319 # define YYPTRDIFF_T __PTRDIFF_TYPE__
320 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
321 # elif defined PTRDIFF_MAX
322 # ifndef ptrdiff_t
323 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
324 # endif
325 # define YYPTRDIFF_T ptrdiff_t
326 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
327 # else
328 # define YYPTRDIFF_T long
329 # define YYPTRDIFF_MAXIMUM LONG_MAX
330 # endif
331 #endif
332
333 #ifndef YYSIZE_T
334 # ifdef __SIZE_TYPE__
335 # define YYSIZE_T __SIZE_TYPE__
336 # elif defined size_t
337 # define YYSIZE_T size_t
338 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
339 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
340 # define YYSIZE_T size_t
341 # else
342 # define YYSIZE_T unsigned
343 # endif
344 #endif
345
346 #define YYSIZE_MAXIMUM \
347 YY_CAST (YYPTRDIFF_T, \
348 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
349 ? YYPTRDIFF_MAXIMUM \
350 : YY_CAST (YYSIZE_T, -1)))
351
352 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
353
354
355 /* Stored state numbers (used for stacks). */
356 typedef yytype_int8 yy_state_t;
357
358 /* State numbers in computations. */
359 typedef int yy_state_fast_t;
360
361 #ifndef YY_
362 # if defined YYENABLE_NLS && YYENABLE_NLS
363 # if ENABLE_NLS
364 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
365 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
366 # endif
367 # endif
368 # ifndef YY_
369 # define YY_(Msgid) Msgid
370 # endif
371 #endif
372
373
374 #ifndef YY_ATTRIBUTE_PURE
375 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
376 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
377 # else
378 # define YY_ATTRIBUTE_PURE
379 # endif
380 #endif
381
382 #ifndef YY_ATTRIBUTE_UNUSED
383 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
384 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
385 # else
386 # define YY_ATTRIBUTE_UNUSED
387 # endif
388 #endif
389
390 /* Suppress unused-variable warnings by "using" E. */
391 #if ! defined lint || defined __GNUC__
392 # define YY_USE(E) ((void) (E))
393 #else
394 # define YY_USE(E) /* empty */
395 #endif
396
397 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
398 #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
399 # if __GNUC__ * 100 + __GNUC_MINOR__ < 407
400 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
401 _Pragma ("GCC diagnostic push") \
402 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
403 # else
404 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
405 _Pragma ("GCC diagnostic push") \
406 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
407 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
408 # endif
409 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
410 _Pragma ("GCC diagnostic pop")
411 #else
412 # define YY_INITIAL_VALUE(Value) Value
413 #endif
414 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
415 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
416 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
417 #endif
418 #ifndef YY_INITIAL_VALUE
419 # define YY_INITIAL_VALUE(Value) /* Nothing. */
420 #endif
421
422 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
423 # define YY_IGNORE_USELESS_CAST_BEGIN \
424 _Pragma ("GCC diagnostic push") \
425 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
426 # define YY_IGNORE_USELESS_CAST_END \
427 _Pragma ("GCC diagnostic pop")
428 #endif
429 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
430 # define YY_IGNORE_USELESS_CAST_BEGIN
431 # define YY_IGNORE_USELESS_CAST_END
432 #endif
433
434
435 #define YY_ASSERT(E) ((void) (0 && (E)))
436
437 #if !defined yyoverflow
438
439 /* The parser invokes alloca or malloc; define the necessary symbols. */
440
441 # ifdef YYSTACK_USE_ALLOCA
442 # if YYSTACK_USE_ALLOCA
443 # ifdef __GNUC__
444 # define YYSTACK_ALLOC __builtin_alloca
445 # elif defined __BUILTIN_VA_ARG_INCR
446 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
447 # elif defined _AIX
448 # define YYSTACK_ALLOC __alloca
449 # elif defined _MSC_VER
450 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
451 # define alloca _alloca
452 # else
453 # define YYSTACK_ALLOC alloca
454 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
455 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
456 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
457 # ifndef EXIT_SUCCESS
458 # define EXIT_SUCCESS 0
459 # endif
460 # endif
461 # endif
462 # endif
463 # endif
464
465 # ifdef YYSTACK_ALLOC
466 /* Pacify GCC's 'empty if-body' warning. */
467 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
468 # ifndef YYSTACK_ALLOC_MAXIMUM
469 /* The OS might guarantee only one guard page at the bottom of the stack,
470 and a page size can be as small as 4096 bytes. So we cannot safely
471 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
472 to allow for a few compiler-allocated temporary stack slots. */
473 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
474 # endif
475 # else
476 # define YYSTACK_ALLOC YYMALLOC
477 # define YYSTACK_FREE YYFREE
478 # ifndef YYSTACK_ALLOC_MAXIMUM
479 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
480 # endif
481 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
482 && ! ((defined YYMALLOC || defined malloc) \
483 && (defined YYFREE || defined free)))
484 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
485 # ifndef EXIT_SUCCESS
486 # define EXIT_SUCCESS 0
487 # endif
488 # endif
489 # ifndef YYMALLOC
490 # define YYMALLOC malloc
491 # if ! defined malloc && ! defined EXIT_SUCCESS
492 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
493 # endif
494 # endif
495 # ifndef YYFREE
496 # define YYFREE free
497 # if ! defined free && ! defined EXIT_SUCCESS
498 void free (void *); /* INFRINGES ON USER NAME SPACE */
499 # endif
500 # endif
501 # endif
502 #endif /* !defined yyoverflow */
503
504 #if (! defined yyoverflow \
505 && (! defined __cplusplus \
506 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
507
508 /* A type that is properly aligned for any stack member. */
509 union yyalloc
510 {
511 yy_state_t yyss_alloc;
512 YYSTYPE yyvs_alloc;
513 };
514
515 /* The size of the maximum gap between one aligned stack and the next. */
516 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
517
518 /* The size of an array large to enough to hold all stacks, each with
519 N elements. */
520 # define YYSTACK_BYTES(N) \
521 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
522 + YYSTACK_GAP_MAXIMUM)
523
524 # define YYCOPY_NEEDED 1
525
526 /* Relocate STACK from its old location to the new one. The
527 local variables YYSIZE and YYSTACKSIZE give the old and new number of
528 elements in the stack, and YYPTR gives the new location of the
529 stack. Advance YYPTR to a properly aligned location for the next
530 stack. */
531 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
532 do \
533 { \
534 YYPTRDIFF_T yynewbytes; \
535 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
536 Stack = &yyptr->Stack_alloc; \
537 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
538 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
539 } \
540 while (0)
541
542 #endif
543
544 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
545 /* Copy COUNT objects from SRC to DST. The source and destination do
546 not overlap. */
547 # ifndef YYCOPY
548 # if defined __GNUC__ && 1 < __GNUC__
549 # define YYCOPY(Dst, Src, Count) \
550 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
551 # else
552 # define YYCOPY(Dst, Src, Count) \
553 do \
554 { \
555 YYPTRDIFF_T yyi; \
556 for (yyi = 0; yyi < (Count); yyi++) \
557 (Dst)[yyi] = (Src)[yyi]; \
558 } \
559 while (0)
560 # endif
561 # endif
562 #endif /* !YYCOPY_NEEDED */
563
564 /* YYFINAL -- State number of the termination state. */
565 #define YYFINAL 7
566 /* YYLAST -- Last index in YYTABLE. */
567 #define YYLAST 55
568
569 /* YYNTOKENS -- Number of terminals. */
570 #define YYNTOKENS 21
571 /* YYNNTS -- Number of nonterminals. */
572 #define YYNNTS 17
573 /* YYNRULES -- Number of rules. */
574 #define YYNRULES 32
575 /* YYNSTATES -- Number of states. */
576 #define YYNSTATES 52
577
578 /* YYMAXUTOK -- Last valid token kind. */
579 #define YYMAXUTOK 268
580
581
582 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
583 as returned by yylex, with out-of-bounds checking. */
584 #define YYTRANSLATE(YYX) \
585 (0 <= (YYX) && (YYX) <= YYMAXUTOK \
586 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
587 : YYSYMBOL_YYUNDEF)
588
589 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
590 as returned by yylex. */
591 static const yytype_int8 yytranslate[] =
592 {
593 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
594 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
595 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
596 2, 2, 2, 17, 2, 2, 2, 18, 2, 2,
597 2, 2, 2, 2, 19, 2, 2, 2, 2, 2,
598 2, 2, 2, 2, 2, 2, 2, 2, 15, 14,
599 2, 16, 2, 2, 2, 2, 2, 2, 2, 2,
600 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
601 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
602 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
603 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
604 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
605 2, 2, 2, 2, 2, 2, 20, 2, 2, 2,
606 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
607 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
608 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
609 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
610 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
611 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
612 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
613 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
614 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
615 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
616 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
617 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
618 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
619 5, 6, 7, 8, 9, 10, 11, 12, 13
620 };
621
622 #if YYDEBUG
623 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
624 static const yytype_int16 yyrline[] =
625 {
626 0, 161, 161, 162, 165, 178, 181, 185, 191, 195,
627 203, 207, 213, 217, 223, 230, 236, 240, 246, 253,
628 256, 257, 260, 261, 264, 266, 267, 269, 270, 273,
629 275, 277, 279
630 };
631 #endif
632
633 /** Accessing symbol of state STATE. */
634 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
635
636 #if YYDEBUG || 0
637 /* The user-facing name of the symbol whose (internal) number is
638 YYSYMBOL. No bounds checking. */
639 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
640
641 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
642 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
643 static const char *const yytname[] =
644 {
645 "\"end of file\"", "error", "\"invalid token\"", "AND", "OR", "RANGE",
646 "ELLIPSIS", "OTHER", "AT_INTEGER", "AT_DECIMAL", "KEYWORD", "INTEGER",
647 "DECIMAL", "OPERAND", "';'", "':'", "'='", "'!'", "'%'", "','", "'~'",
648 "$accept", "rules", "rule", "condition", "and_condition", "relation",
649 "expression", "range_list", "range_or_integer", "range", "samples",
650 "at_integer", "at_decimal", "sample_list", "sample_list1",
651 "sample_ellipsis", "sample_range", YY_NULLPTR
652 };
653
654 static const char *
655 yysymbol_name (yysymbol_kind_t yysymbol)
656 {
657 return yytname[yysymbol];
658 }
659 #endif
660
661 #define YYPACT_NINF (-20)
662
663 #define yypact_value_is_default(Yyn) \
664 ((Yyn) == YYPACT_NINF)
665
666 #define YYTABLE_NINF (-1)
667
668 #define yytable_value_is_error(Yyn) \
669 0
670
671 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
672 STATE-NUM. */
673 static const yytype_int8 yypact[] =
674 {
675 3, -11, -7, 0, -20, 4, -2, -20, 3, -9,
676 -20, 8, 2, 1, 15, -20, -1, -20, 5, 6,
677 -20, 9, -20, -9, -20, 10, -2, -20, -2, 11,
678 11, 12, 7, -5, -20, -20, -20, 15, -20, 19,
679 13, -20, -20, 13, -20, -20, -20, -20, 16, 11,
680 -20, -20
681 };
682
683 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
684 Performed when YYTABLE does not specify something else to do. Zero
685 means the default is an error. */
686 static const yytype_int8 yydefact[] =
687 {
688 0, 0, 0, 0, 2, 20, 0, 1, 0, 0,
689 5, 22, 12, 20, 6, 8, 0, 3, 31, 29,
690 21, 27, 25, 0, 19, 0, 0, 4, 0, 0,
691 0, 0, 0, 0, 24, 23, 13, 7, 9, 17,
692 10, 14, 16, 11, 32, 30, 28, 26, 0, 0,
693 18, 15
694 };
695
696 /* YYPGOTO[NTERM-NUM]. */
697 static const yytype_int8 yypgoto[] =
698 {
699 -20, -20, 21, -20, 14, 17, -20, 18, -19, -20,
700 20, -20, -20, 23, -20, -20, 22
701 };
702
703 /* YYDEFGOTO[NTERM-NUM]. */
704 static const yytype_int8 yydefgoto[] =
705 {
706 0, 3, 4, 13, 14, 15, 16, 40, 41, 42,
707 10, 11, 24, 20, 21, 34, 22
708 };
709
710 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
711 positive, shift that token. If negative, reduce the rule whose
712 number is the opposite. If YYTABLE_NINF, syntax error. */
713 static const yytype_int8 yytable[] =
714 {
715 7, 46, 18, 19, 5, 26, 18, 19, 6, 9,
716 1, 12, 9, 2, 8, 29, 30, 23, 28, 45,
717 25, 36, 39, 44, 48, 31, 32, 50, 33, 17,
718 51, 0, 49, 27, 0, 0, 0, 0, 0, 0,
719 37, 0, 0, 0, 0, 38, 35, 0, 43, 0,
720 0, 0, 0, 0, 0, 47
721 };
722
723 static const yytype_int8 yycheck[] =
724 {
725 0, 6, 11, 12, 15, 4, 11, 12, 15, 8,
726 7, 13, 8, 10, 14, 16, 17, 9, 3, 12,
727 18, 11, 11, 11, 5, 20, 20, 11, 19, 8,
728 49, -1, 19, 13, -1, -1, -1, -1, -1, -1,
729 26, -1, -1, -1, -1, 28, 23, -1, 30, -1,
730 -1, -1, -1, -1, -1, 33
731 };
732
733 /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
734 state STATE-NUM. */
735 static const yytype_int8 yystos[] =
736 {
737 0, 7, 10, 22, 23, 15, 15, 0, 14, 8,
738 31, 32, 13, 24, 25, 26, 27, 23, 11, 12,
739 34, 35, 37, 9, 33, 18, 4, 31, 3, 16,
740 17, 20, 20, 19, 36, 34, 11, 25, 26, 11,
741 28, 29, 30, 28, 11, 12, 6, 37, 5, 19,
742 11, 29
743 };
744
745 /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
746 static const yytype_int8 yyr1[] =
747 {
748 0, 21, 22, 22, 23, 23, 24, 24, 25, 25,
749 26, 26, 27, 27, 28, 28, 29, 29, 30, 31,
750 32, 32, 33, 33, 34, 35, 35, 36, 36, 37,
751 37, 37, 37
752 };
753
754 /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
755 static const yytype_int8 yyr2[] =
756 {
757 0, 2, 1, 3, 4, 3, 1, 3, 1, 3,
758 3, 3, 1, 3, 1, 3, 1, 1, 3, 2,
759 0, 2, 0, 2, 2, 1, 3, 0, 2, 1,
760 3, 1, 3
761 };
762
763
764 enum { YYENOMEM = -2 };
765
766 #define yyerrok (yyerrstatus = 0)
767 #define yyclearin (yychar = YYEMPTY)
768
769 #define YYACCEPT goto yyacceptlab
770 #define YYABORT goto yyabortlab
771 #define YYERROR goto yyerrorlab
772 #define YYNOMEM goto yyexhaustedlab
773
774
775 #define YYRECOVERING() (!!yyerrstatus)
776
777 #define YYBACKUP(Token, Value) \
778 do \
779 if (yychar == YYEMPTY) \
780 { \
781 yychar = (Token); \
782 yylval = (Value); \
783 YYPOPSTACK (yylen); \
784 yystate = *yyssp; \
785 goto yybackup; \
786 } \
787 else \
788 { \
789 yyerror (arg, YY_("syntax error: cannot back up")); \
790 YYERROR; \
791 } \
792 while (0)
793
794 /* Backward compatibility with an undocumented macro.
795 Use YYerror or YYUNDEF. */
796 #define YYERRCODE YYUNDEF
797
798
799 /* Enable debugging if requested. */
800 #if YYDEBUG
801
802 # ifndef YYFPRINTF
803 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
804 # define YYFPRINTF fprintf
805 # endif
806
807 # define YYDPRINTF(Args) \
808 do { \
809 if (yydebug) \
810 YYFPRINTF Args; \
811 } while (0)
812
813
814
815
816 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
817 do { \
818 if (yydebug) \
819 { \
820 YYFPRINTF (stderr, "%s ", Title); \
821 yy_symbol_print (stderr, \
822 Kind, Value, arg); \
823 YYFPRINTF (stderr, "\n"); \
824 } \
825 } while (0)
826
827
828 /*-----------------------------------.
829 | Print this symbol's value on YYO. |
830 `-----------------------------------*/
831
832 static void
833 yy_symbol_value_print (FILE *yyo,
834 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, struct cldr_plural_parse_args *arg)
835 {
836 FILE *yyoutput = yyo;
837 YY_USE (yyoutput);
838 YY_USE (arg);
839 if (!yyvaluep)
840 return;
841 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
842 YY_USE (yykind);
843 YY_IGNORE_MAYBE_UNINITIALIZED_END
844 }
845
846
847 /*---------------------------.
848 | Print this symbol on YYO. |
849 `---------------------------*/
850
851 static void
852 yy_symbol_print (FILE *yyo,
853 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, struct cldr_plural_parse_args *arg)
854 {
855 YYFPRINTF (yyo, "%s %s (",
856 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
857
858 yy_symbol_value_print (yyo, yykind, yyvaluep, arg);
859 YYFPRINTF (yyo, ")");
860 }
861
862 /*------------------------------------------------------------------.
863 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
864 | TOP (included). |
865 `------------------------------------------------------------------*/
866
867 static void
868 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
869 {
870 YYFPRINTF (stderr, "Stack now");
871 for (; yybottom <= yytop; yybottom++)
872 {
873 int yybot = *yybottom;
874 YYFPRINTF (stderr, " %d", yybot);
875 }
876 YYFPRINTF (stderr, "\n");
877 }
878
879 # define YY_STACK_PRINT(Bottom, Top) \
880 do { \
881 if (yydebug) \
882 yy_stack_print ((Bottom), (Top)); \
883 } while (0)
884
885
886 /*------------------------------------------------.
887 | Report that the YYRULE is going to be reduced. |
888 `------------------------------------------------*/
889
890 static void
891 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
892 int yyrule, struct cldr_plural_parse_args *arg)
893 {
894 int yylno = yyrline[yyrule];
895 int yynrhs = yyr2[yyrule];
896 int yyi;
897 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
898 yyrule - 1, yylno);
899 /* The symbols being reduced. */
900 for (yyi = 0; yyi < yynrhs; yyi++)
901 {
902 YYFPRINTF (stderr, " $%d = ", yyi + 1);
903 yy_symbol_print (stderr,
904 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
905 &yyvsp[(yyi + 1) - (yynrhs)], arg);
906 YYFPRINTF (stderr, "\n");
907 }
908 }
909
910 # define YY_REDUCE_PRINT(Rule) \
911 do { \
912 if (yydebug) \
913 yy_reduce_print (yyssp, yyvsp, Rule, arg); \
914 } while (0)
915
916 /* Nonzero means print parse trace. It is left uninitialized so that
917 multiple parsers can coexist. */
918 int yydebug;
919 #else /* !YYDEBUG */
920 # define YYDPRINTF(Args) ((void) 0)
921 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
922 # define YY_STACK_PRINT(Bottom, Top)
923 # define YY_REDUCE_PRINT(Rule)
924 #endif /* !YYDEBUG */
925
926
927 /* YYINITDEPTH -- initial size of the parser's stacks. */
928 #ifndef YYINITDEPTH
929 # define YYINITDEPTH 200
930 #endif
931
932 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
933 if the built-in stack extension method is used).
934
935 Do not make this value too large; the results are undefined if
936 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
937 evaluated with infinite-precision integer arithmetic. */
938
939 #ifndef YYMAXDEPTH
940 # define YYMAXDEPTH 10000
941 #endif
942
943
944
945
946
947
948 /*-----------------------------------------------.
949 | Release the memory associated to this symbol. |
950 `-----------------------------------------------*/
951
952 static void
953 yydestruct (const char *yymsg,
954 yysymbol_kind_t yykind, YYSTYPE *yyvaluep, struct cldr_plural_parse_args *arg)
955 {
956 YY_USE (yyvaluep);
957 YY_USE (arg);
958 if (!yymsg)
959 yymsg = "Deleting";
960 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
961
962 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
963 switch (yykind)
964 {
965 case YYSYMBOL_KEYWORD: /* KEYWORD */
966 #line 140 "cldr-plural.y"
967 { free (((*yyvaluep).sval)); }
968 #line 969 "cldr-plural.c"
969 break;
970
971 case YYSYMBOL_INTEGER: /* INTEGER */
972 #line 145 "cldr-plural.y"
973 { free (((*yyvaluep).oval)); }
974 #line 975 "cldr-plural.c"
975 break;
976
977 case YYSYMBOL_DECIMAL: /* DECIMAL */
978 #line 145 "cldr-plural.y"
979 { free (((*yyvaluep).oval)); }
980 #line 981 "cldr-plural.c"
981 break;
982
983 case YYSYMBOL_OPERAND: /* OPERAND */
984 #line 147 "cldr-plural.y"
985 { }
986 #line 987 "cldr-plural.c"
987 break;
988
989 case YYSYMBOL_condition: /* condition */
990 #line 141 "cldr-plural.y"
991 { cldr_plural_condition_free (((*yyvaluep).cval)); }
992 #line 993 "cldr-plural.c"
993 break;
994
995 case YYSYMBOL_and_condition: /* and_condition */
996 #line 141 "cldr-plural.y"
997 { cldr_plural_condition_free (((*yyvaluep).cval)); }
998 #line 999 "cldr-plural.c"
999 break;
1000
1001 case YYSYMBOL_relation: /* relation */
1002 #line 142 "cldr-plural.y"
1003 { cldr_plural_relation_free (((*yyvaluep).lval)); }
1004 #line 1005 "cldr-plural.c"
1005 break;
1006
1007 case YYSYMBOL_expression: /* expression */
1008 #line 143 "cldr-plural.y"
1009 { free (((*yyvaluep).eval)); }
1010 #line 1011 "cldr-plural.c"
1011 break;
1012
1013 case YYSYMBOL_range_list: /* range_list */
1014 #line 146 "cldr-plural.y"
1015 { cldr_plural_range_list_free (((*yyvaluep).rval)); }
1016 #line 1017 "cldr-plural.c"
1017 break;
1018
1019 case YYSYMBOL_range_or_integer: /* range_or_integer */
1020 #line 144 "cldr-plural.y"
1021 { cldr_plural_range_free (((*yyvaluep).gval)); }
1022 #line 1023 "cldr-plural.c"
1023 break;
1024
1025 case YYSYMBOL_range: /* range */
1026 #line 144 "cldr-plural.y"
1027 { cldr_plural_range_free (((*yyvaluep).gval)); }
1028 #line 1029 "cldr-plural.c"
1029 break;
1030
1031 default:
1032 break;
1033 }
1034 YY_IGNORE_MAYBE_UNINITIALIZED_END
1035 }
1036
1037
1038
1039
1040
1041
1042 /*----------.
1043 | yyparse. |
1044 `----------*/
1045
1046 int
1047 yyparse (struct cldr_plural_parse_args *arg)
1048 {
1049 /* Lookahead token kind. */
1050 int yychar;
1051
1052
1053 /* The semantic value of the lookahead symbol. */
1054 /* Default value used for initialization, for pacifying older GCCs
1055 or non-GCC compilers. */
1056 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1057 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1058
1059 /* Number of syntax errors so far. */
1060 int yynerrs = 0;
1061
1062 yy_state_fast_t yystate = 0;
1063 /* Number of tokens to shift before error messages enabled. */
1064 int yyerrstatus = 0;
1065
1066 /* Refer to the stacks through separate pointers, to allow yyoverflow
1067 to reallocate them elsewhere. */
1068
1069 /* Their size. */
1070 YYPTRDIFF_T yystacksize = YYINITDEPTH;
1071
1072 /* The state stack: array, bottom, top. */
1073 yy_state_t yyssa[YYINITDEPTH];
1074 yy_state_t *yyss = yyssa;
1075 yy_state_t *yyssp = yyss;
1076
1077 /* The semantic value stack: array, bottom, top. */
1078 YYSTYPE yyvsa[YYINITDEPTH];
1079 YYSTYPE *yyvs = yyvsa;
1080 YYSTYPE *yyvsp = yyvs;
1081
1082 int yyn;
1083 /* The return value of yyparse. */
1084 int yyresult;
1085 /* Lookahead symbol kind. */
1086 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1087 /* The variables used to return semantic value and location from the
1088 action routines. */
1089 YYSTYPE yyval;
1090
1091
1092
1093 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1094
1095 /* The number of symbols on the RHS of the reduced rule.
1096 Keep to zero when no symbol should be popped. */
1097 int yylen = 0;
1098
1099 YYDPRINTF ((stderr, "Starting parse\n"));
1100
1101 yychar = YYEMPTY; /* Cause a token to be read. */
1102
1103 goto yysetstate;
1104
1105
1106 /*------------------------------------------------------------.
1107 | yynewstate -- push a new state, which is found in yystate. |
1108 `------------------------------------------------------------*/
1109 yynewstate:
1110 /* In all cases, when you get here, the value and location stacks
1111 have just been pushed. So pushing a state here evens the stacks. */
1112 yyssp++;
1113
1114
1115 /*--------------------------------------------------------------------.
1116 | yysetstate -- set current state (the top of the stack) to yystate. |
1117 `--------------------------------------------------------------------*/
1118 yysetstate:
1119 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1120 YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1121 YY_IGNORE_USELESS_CAST_BEGIN
1122 *yyssp = YY_CAST (yy_state_t, yystate);
1123 YY_IGNORE_USELESS_CAST_END
1124 YY_STACK_PRINT (yyss, yyssp);
1125
1126 if (yyss + yystacksize - 1 <= yyssp)
1127 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1128 YYNOMEM;
1129 #else
1130 {
1131 /* Get the current used size of the three stacks, in elements. */
1132 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1133
1134 # if defined yyoverflow
1135 {
1136 /* Give user a chance to reallocate the stack. Use copies of
1137 these so that the &'s don't force the real ones into
1138 memory. */
1139 yy_state_t *yyss1 = yyss;
1140 YYSTYPE *yyvs1 = yyvs;
1141
1142 /* Each stack pointer address is followed by the size of the
1143 data in use in that stack, in bytes. This used to be a
1144 conditional around just the two extra args, but that might
1145 be undefined if yyoverflow is a macro. */
1146 yyoverflow (YY_("memory exhausted"),
1147 &yyss1, yysize * YYSIZEOF (*yyssp),
1148 &yyvs1, yysize * YYSIZEOF (*yyvsp),
1149 &yystacksize);
1150 yyss = yyss1;
1151 yyvs = yyvs1;
1152 }
1153 # else /* defined YYSTACK_RELOCATE */
1154 /* Extend the stack our own way. */
1155 if (YYMAXDEPTH <= yystacksize)
1156 YYNOMEM;
1157 yystacksize *= 2;
1158 if (YYMAXDEPTH < yystacksize)
1159 yystacksize = YYMAXDEPTH;
1160
1161 {
1162 yy_state_t *yyss1 = yyss;
1163 union yyalloc *yyptr =
1164 YY_CAST (union yyalloc *,
1165 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1166 if (! yyptr)
1167 YYNOMEM;
1168 YYSTACK_RELOCATE (yyss_alloc, yyss);
1169 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1170 # undef YYSTACK_RELOCATE
1171 if (yyss1 != yyssa)
1172 YYSTACK_FREE (yyss1);
1173 }
1174 # endif
1175
1176 yyssp = yyss + yysize - 1;
1177 yyvsp = yyvs + yysize - 1;
1178
1179 YY_IGNORE_USELESS_CAST_BEGIN
1180 YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1181 YY_CAST (long, yystacksize)));
1182 YY_IGNORE_USELESS_CAST_END
1183
1184 if (yyss + yystacksize - 1 <= yyssp)
1185 YYABORT;
1186 }
1187 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1188
1189
1190 if (yystate == YYFINAL)
1191 YYACCEPT;
1192
1193 goto yybackup;
1194
1195
1196 /*-----------.
1197 | yybackup. |
1198 `-----------*/
1199 yybackup:
1200 /* Do appropriate processing given the current state. Read a
1201 lookahead token if we need one and don't already have one. */
1202
1203 /* First try to decide what to do without reference to lookahead token. */
1204 yyn = yypact[yystate];
1205 if (yypact_value_is_default (yyn))
1206 goto yydefault;
1207
1208 /* Not known => get a lookahead token if don't already have one. */
1209
1210 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1211 if (yychar == YYEMPTY)
1212 {
1213 YYDPRINTF ((stderr, "Reading a token\n"));
1214 yychar = yylex (&yylval, arg);
1215 }
1216
1217 if (yychar <= YYEOF)
1218 {
1219 yychar = YYEOF;
1220 yytoken = YYSYMBOL_YYEOF;
1221 YYDPRINTF ((stderr, "Now at end of input.\n"));
1222 }
1223 else if (yychar == YYerror)
1224 {
1225 /* The scanner already issued an error message, process directly
1226 to error recovery. But do not keep the error token as
1227 lookahead, it is too special and may lead us to an endless
1228 loop in error recovery. */
1229 yychar = YYUNDEF;
1230 yytoken = YYSYMBOL_YYerror;
1231 goto yyerrlab1;
1232 }
1233 else
1234 {
1235 yytoken = YYTRANSLATE (yychar);
1236 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1237 }
1238
1239 /* If the proper action on seeing token YYTOKEN is to reduce or to
1240 detect an error, take that action. */
1241 yyn += yytoken;
1242 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1243 goto yydefault;
1244 yyn = yytable[yyn];
1245 if (yyn <= 0)
1246 {
1247 if (yytable_value_is_error (yyn))
1248 goto yyerrlab;
1249 yyn = -yyn;
1250 goto yyreduce;
1251 }
1252
1253 /* Count tokens shifted since error; after three, turn off error
1254 status. */
1255 if (yyerrstatus)
1256 yyerrstatus--;
1257
1258 /* Shift the lookahead token. */
1259 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1260 yystate = yyn;
1261 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1262 *++yyvsp = yylval;
1263 YY_IGNORE_MAYBE_UNINITIALIZED_END
1264
1265 /* Discard the shifted token. */
1266 yychar = YYEMPTY;
1267 goto yynewstate;
1268
1269
1270 /*-----------------------------------------------------------.
1271 | yydefault -- do the default action for the current state. |
1272 `-----------------------------------------------------------*/
1273 yydefault:
1274 yyn = yydefact[yystate];
1275 if (yyn == 0)
1276 goto yyerrlab;
1277 goto yyreduce;
1278
1279
1280 /*-----------------------------.
1281 | yyreduce -- do a reduction. |
1282 `-----------------------------*/
1283 yyreduce:
1284 /* yyn is the number of a rule to reduce with. */
1285 yylen = yyr2[yyn];
1286
1287 /* If YYLEN is nonzero, implement the default value of the action:
1288 '$$ = $1'.
1289
1290 Otherwise, the following line sets YYVAL to garbage.
1291 This behavior is undocumented and Bison
1292 users should not rely upon it. Assigning to YYVAL
1293 unconditionally makes the parser a bit smaller, and it avoids a
1294 GCC warning that YYVAL may be used uninitialized. */
1295 yyval = yyvsp[1-yylen];
1296
1297
1298 YY_REDUCE_PRINT (yyn);
1299 switch (yyn)
1300 {
1301 case 4: /* rule: KEYWORD ':' condition samples */
1302 #line 166 "cldr-plural.y"
1303 {
1304 struct cldr_plural_rule_ty *rule = new_rule ((yyvsp[-3].sval), (yyvsp[-1].cval));
1305 struct cldr_plural_rule_list_ty *result = arg->result;
1306 if (result->nitems == result->nitems_max)
1307 {
1308 result->nitems_max = result->nitems_max * 2 + 1;
1309 result->items = xrealloc (result->items,
1310 sizeof (struct cldr_plural_rule_ty *)
1311 * result->nitems_max);
1312 }
1313 result->items[result->nitems++] = rule;
1314 }
1315 #line 1316 "cldr-plural.c"
1316 break;
1317
1318 case 6: /* condition: and_condition */
1319 #line 182 "cldr-plural.y"
1320 {
1321 (yyval.cval) = (yyvsp[0].cval);
1322 }
1323 #line 1324 "cldr-plural.c"
1324 break;
1325
1326 case 7: /* condition: condition OR and_condition */
1327 #line 186 "cldr-plural.y"
1328 {
1329 (yyval.cval) = new_branch_condition (CLDR_PLURAL_CONDITION_OR, (yyvsp[-2].cval), (yyvsp[0].cval));
1330 }
1331 #line 1332 "cldr-plural.c"
1332 break;
1333
1334 case 8: /* and_condition: relation */
1335 #line 192 "cldr-plural.y"
1336 {
1337 (yyval.cval) = new_leaf_condition ((yyvsp[0].lval));
1338 }
1339 #line 1340 "cldr-plural.c"
1340 break;
1341
1342 case 9: /* and_condition: and_condition AND relation */
1343 #line 196 "cldr-plural.y"
1344 {
1345 (yyval.cval) = new_branch_condition (CLDR_PLURAL_CONDITION_AND,
1346 (yyvsp[-2].cval),
1347 new_leaf_condition ((yyvsp[0].lval)));
1348 }
1349 #line 1350 "cldr-plural.c"
1350 break;
1351
1352 case 10: /* relation: expression '=' range_list */
1353 #line 204 "cldr-plural.y"
1354 {
1355 (yyval.lval) = new_relation ((yyvsp[-2].eval), CLDR_PLURAL_RELATION_EQUAL, (yyvsp[0].rval));
1356 }
1357 #line 1358 "cldr-plural.c"
1358 break;
1359
1360 case 11: /* relation: expression '!' range_list */
1361 #line 208 "cldr-plural.y"
1362 {
1363 (yyval.lval) = new_relation ((yyvsp[-2].eval), CLDR_PLURAL_RELATION_NOT_EQUAL, (yyvsp[0].rval));
1364 }
1365 #line 1366 "cldr-plural.c"
1366 break;
1367
1368 case 12: /* expression: OPERAND */
1369 #line 214 "cldr-plural.y"
1370 {
1371 (yyval.eval) = new_expression ((yyvsp[0].ival), 0);
1372 }
1373 #line 1374 "cldr-plural.c"
1374 break;
1375
1376 case 13: /* expression: OPERAND '%' INTEGER */
1377 #line 218 "cldr-plural.y"
1378 {
1379 (yyval.eval) = new_expression ((yyvsp[-2].ival), (yyvsp[0].oval)->value.ival);
1380 }
1381 #line 1382 "cldr-plural.c"
1382 break;
1383
1384 case 14: /* range_list: range_or_integer */
1385 #line 224 "cldr-plural.y"
1386 {
1387 struct cldr_plural_range_list_ty *ranges =
1388 XMALLOC (struct cldr_plural_range_list_ty);
1389 memset (ranges, 0, sizeof (struct cldr_plural_range_list_ty));
1390 (yyval.rval) = add_range (ranges, (yyvsp[0].gval));
1391 }
1392 #line 1393 "cldr-plural.c"
1393 break;
1394
1395 case 15: /* range_list: range_list ',' range_or_integer */
1396 #line 231 "cldr-plural.y"
1397 {
1398 (yyval.rval) = add_range ((yyvsp[-2].rval), (yyvsp[0].gval));
1399 }
1400 #line 1401 "cldr-plural.c"
1401 break;
1402
1403 case 16: /* range_or_integer: range */
1404 #line 237 "cldr-plural.y"
1405 {
1406 (yyval.gval) = (yyvsp[0].gval);
1407 }
1408 #line 1409 "cldr-plural.c"
1409 break;
1410
1411 case 17: /* range_or_integer: INTEGER */
1412 #line 241 "cldr-plural.y"
1413 {
1414 (yyval.gval) = new_range ((yyvsp[0].oval), (yyvsp[0].oval));
1415 }
1416 #line 1417 "cldr-plural.c"
1417 break;
1418
1419 case 18: /* range: INTEGER RANGE INTEGER */
1420 #line 247 "cldr-plural.y"
1421 {
1422 (yyval.gval) = new_range ((yyvsp[-2].oval), (yyvsp[0].oval));
1423 }
1424 #line 1425 "cldr-plural.c"
1425 break;
1426
1427 case 29: /* sample_range: DECIMAL */
1428 #line 274 "cldr-plural.y"
1429 { free ((yyvsp[0].oval)); }
1430 #line 1431 "cldr-plural.c"
1431 break;
1432
1433 case 30: /* sample_range: DECIMAL '~' DECIMAL */
1434 #line 276 "cldr-plural.y"
1435 { free ((yyvsp[-2].oval)); free ((yyvsp[0].oval)); }
1436 #line 1437 "cldr-plural.c"
1437 break;
1438
1439 case 31: /* sample_range: INTEGER */
1440 #line 278 "cldr-plural.y"
1441 { free ((yyvsp[0].oval)); }
1442 #line 1443 "cldr-plural.c"
1443 break;
1444
1445 case 32: /* sample_range: INTEGER '~' INTEGER */
1446 #line 280 "cldr-plural.y"
1447 { free ((yyvsp[-2].oval)); free ((yyvsp[0].oval)); }
1448 #line 1449 "cldr-plural.c"
1449 break;
1450
1451
1452 #line 1453 "cldr-plural.c"
1453
1454 default: break;
1455 }
1456 /* User semantic actions sometimes alter yychar, and that requires
1457 that yytoken be updated with the new translation. We take the
1458 approach of translating immediately before every use of yytoken.
1459 One alternative is translating here after every semantic action,
1460 but that translation would be missed if the semantic action invokes
1461 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1462 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1463 incorrect destructor might then be invoked immediately. In the
1464 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1465 to an incorrect destructor call or verbose syntax error message
1466 before the lookahead is translated. */
1467 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
1468
1469 YYPOPSTACK (yylen);
1470 yylen = 0;
1471
1472 *++yyvsp = yyval;
1473
1474 /* Now 'shift' the result of the reduction. Determine what state
1475 that goes to, based on the state we popped back to and the rule
1476 number reduced by. */
1477 {
1478 const int yylhs = yyr1[yyn] - YYNTOKENS;
1479 const int yyi = yypgoto[yylhs] + *yyssp;
1480 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1481 ? yytable[yyi]
1482 : yydefgoto[yylhs]);
1483 }
1484
1485 goto yynewstate;
1486
1487
1488 /*--------------------------------------.
1489 | yyerrlab -- here on detecting error. |
1490 `--------------------------------------*/
1491 yyerrlab:
1492 /* Make sure we have latest lookahead translation. See comments at
1493 user semantic actions for why this is necessary. */
1494 yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
1495 /* If not already recovering from an error, report this error. */
1496 if (!yyerrstatus)
1497 {
1498 ++yynerrs;
1499 yyerror (arg, YY_("syntax error"));
1500 }
1501
1502 if (yyerrstatus == 3)
1503 {
1504 /* If just tried and failed to reuse lookahead token after an
1505 error, discard it. */
1506
1507 if (yychar <= YYEOF)
1508 {
1509 /* Return failure if at end of input. */
1510 if (yychar == YYEOF)
1511 YYABORT;
1512 }
1513 else
1514 {
1515 yydestruct ("Error: discarding",
1516 yytoken, &yylval, arg);
1517 yychar = YYEMPTY;
1518 }
1519 }
1520
1521 /* Else will try to reuse lookahead token after shifting the error
1522 token. */
1523 goto yyerrlab1;
1524
1525
1526 /*---------------------------------------------------.
1527 | yyerrorlab -- error raised explicitly by YYERROR. |
1528 `---------------------------------------------------*/
1529 yyerrorlab:
1530 /* Pacify compilers when the user code never invokes YYERROR and the
1531 label yyerrorlab therefore never appears in user code. */
1532 if (0)
1533 YYERROR;
1534 ++yynerrs;
1535
1536 /* Do not reclaim the symbols of the rule whose action triggered
1537 this YYERROR. */
1538 YYPOPSTACK (yylen);
1539 yylen = 0;
1540 YY_STACK_PRINT (yyss, yyssp);
1541 yystate = *yyssp;
1542 goto yyerrlab1;
1543
1544
1545 /*-------------------------------------------------------------.
1546 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1547 `-------------------------------------------------------------*/
1548 yyerrlab1:
1549 yyerrstatus = 3; /* Each real token shifted decrements this. */
1550
1551 /* Pop stack until we find a state that shifts the error token. */
1552 for (;;)
1553 {
1554 yyn = yypact[yystate];
1555 if (!yypact_value_is_default (yyn))
1556 {
1557 yyn += YYSYMBOL_YYerror;
1558 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
1559 {
1560 yyn = yytable[yyn];
1561 if (0 < yyn)
1562 break;
1563 }
1564 }
1565
1566 /* Pop the current state because it cannot handle the error token. */
1567 if (yyssp == yyss)
1568 YYABORT;
1569
1570
1571 yydestruct ("Error: popping",
1572 YY_ACCESSING_SYMBOL (yystate), yyvsp, arg);
1573 YYPOPSTACK (1);
1574 yystate = *yyssp;
1575 YY_STACK_PRINT (yyss, yyssp);
1576 }
1577
1578 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1579 *++yyvsp = yylval;
1580 YY_IGNORE_MAYBE_UNINITIALIZED_END
1581
1582
1583 /* Shift the error token. */
1584 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
1585
1586 yystate = yyn;
1587 goto yynewstate;
1588
1589
1590 /*-------------------------------------.
1591 | yyacceptlab -- YYACCEPT comes here. |
1592 `-------------------------------------*/
1593 yyacceptlab:
1594 yyresult = 0;
1595 goto yyreturnlab;
1596
1597
1598 /*-----------------------------------.
1599 | yyabortlab -- YYABORT comes here. |
1600 `-----------------------------------*/
1601 yyabortlab:
1602 yyresult = 1;
1603 goto yyreturnlab;
1604
1605
1606 /*-----------------------------------------------------------.
1607 | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
1608 `-----------------------------------------------------------*/
1609 yyexhaustedlab:
1610 yyerror (arg, YY_("memory exhausted"));
1611 yyresult = 2;
1612 goto yyreturnlab;
1613
1614
1615 /*----------------------------------------------------------.
1616 | yyreturnlab -- parsing is finished, clean up and return. |
1617 `----------------------------------------------------------*/
1618 yyreturnlab:
1619 if (yychar != YYEMPTY)
1620 {
1621 /* Make sure we have latest lookahead translation. See comments at
1622 user semantic actions for why this is necessary. */
1623 yytoken = YYTRANSLATE (yychar);
1624 yydestruct ("Cleanup: discarding lookahead",
1625 yytoken, &yylval, arg);
1626 }
1627 /* Do not reclaim the symbols of the rule whose action triggered
1628 this YYABORT or YYACCEPT. */
1629 YYPOPSTACK (yylen);
1630 YY_STACK_PRINT (yyss, yyssp);
1631 while (yyssp != yyss)
1632 {
1633 yydestruct ("Cleanup: popping",
1634 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, arg);
1635 YYPOPSTACK (1);
1636 }
1637 #ifndef yyoverflow
1638 if (yyss != yyssa)
1639 YYSTACK_FREE (yyss);
1640 #endif
1641
1642 return yyresult;
1643 }
1644
1645 #line 283 "cldr-plural.y"
1646
1647
1648 static int
1649 yylex (YYSTYPE *lval, struct cldr_plural_parse_args *arg)
1650 {
1651 const char *exp = arg->cp;
1652 ucs4_t uc;
1653 int length;
1654 int result;
1655 static char *buffer;
1656 static size_t bufmax;
1657 size_t bufpos;
1658
1659 while (1)
1660 {
1661 if (exp[0] == '\0')
1662 {
1663 arg->cp = exp;
1664 return YYEOF;
1665 }
1666
1667 if (exp[0] != ' ' && exp[0] != '\t')
1668 break;
1669
1670 ++exp;
1671 }
1672
1673 length = u8_mbtouc (&uc, (const uint8_t *) exp, arg->cp_end - exp);
1674 if (uc == 0x2026)
1675 {
1676 arg->cp = exp + length;
1677 return ELLIPSIS;
1678 }
1679 else if (strncmp ("...", exp, 3) == 0)
1680 {
1681 arg->cp = exp + 3;
1682 return ELLIPSIS;
1683 }
1684 else if (strncmp ("..", exp, 2) == 0)
1685 {
1686 arg->cp = exp + 2;
1687 return RANGE;
1688 }
1689 else if (strncmp ("other", exp, 5) == 0)
1690 {
1691 arg->cp = exp + 5;
1692 return OTHER;
1693 }
1694 else if (strncmp ("@integer", exp, 8) == 0)
1695 {
1696 arg->cp = exp + 8;
1697 return AT_INTEGER;
1698 }
1699 else if (strncmp ("@decimal", exp, 8) == 0)
1700 {
1701 arg->cp = exp + 8;
1702 return AT_DECIMAL;
1703 }
1704
1705 result = *exp++;
1706 switch (result)
1707 {
1708 case '0': case '1': case '2': case '3': case '4':
1709 case '5': case '6': case '7': case '8': case '9':
1710 {
1711 unsigned long int ival = result - '0';
1712
1713 while (exp[0] >= '0' && exp[0] <= '9')
1714 {
1715 ival *= 10;
1716 ival += exp[0] - '0';
1717 ++exp;
1718 }
1719
1720 lval->oval = XMALLOC (struct cldr_plural_operand_ty);
1721 if (exp[0] == '.' && exp[1] >= '0' && exp[1] <= '9')
1722 {
1723 double dval = ival;
1724 int denominator = 10, nfractions = 0;
1725 ++exp;
1726 while (exp[0] >= '0' && exp[0] <= '9')
1727 {
1728 dval += (exp[0] - '0') / (double) denominator;
1729 denominator *= 10;
1730 ++nfractions;
1731 ++exp;
1732 }
1733 lval->oval->type = CLDR_PLURAL_OPERAND_DECIMAL;
1734 lval->oval->value.dval.d = dval;
1735 lval->oval->value.dval.nfractions = nfractions;
1736 result = DECIMAL;
1737 }
1738 else
1739 {
1740 lval->oval->type = CLDR_PLURAL_OPERAND_INTEGER;
1741 lval->oval->value.ival = ival;
1742 result = INTEGER;
1743 }
1744 }
1745 break;
1746 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
1747 case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
1748 case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
1749 case 'v': case 'w': case 'x': case 'y': case 'z':
1750 bufpos = 0;
1751 for (;;)
1752 {
1753 if (bufpos >= bufmax)
1754 {
1755 bufmax = 2 * bufmax + 10;
1756 buffer = xrealloc (buffer, bufmax);
1757 }
1758 buffer[bufpos++] = result;
1759 result = *exp;
1760 switch (result)
1761 {
1762 case 'a': case 'b': case 'c': case 'd': case 'e':
1763 case 'f': case 'g': case 'h': case 'i': case 'j':
1764 case 'k': case 'l': case 'm': case 'n': case 'o':
1765 case 'p': case 'q': case 'r': case 's': case 't':
1766 case 'u': case 'v': case 'w': case 'x': case 'y':
1767 case 'z':
1768 ++exp;
1769 continue;
1770 default:
1771 break;
1772 }
1773 break;
1774 }
1775
1776 if (bufpos >= bufmax)
1777 {
1778 bufmax = 2 * bufmax + 10;
1779 buffer = xrealloc (buffer, bufmax);
1780 }
1781 buffer[bufpos] = '\0';
1782
1783 /* Operands. */
1784 if (bufpos == 1)
1785 {
1786 switch (buffer[0])
1787 {
1788 case 'n': case 'i': case 'f': case 't': case 'v': case 'w':
1789 arg->cp = exp;
1790 lval->ival = buffer[0];
1791 return OPERAND;
1792 default:
1793 break;
1794 }
1795 }
1796
1797 /* Keywords. */
1798 if (strcmp (buffer, "and") == 0)
1799 {
1800 arg->cp = exp;
1801 return AND;
1802 }
1803 else if (strcmp (buffer, "or") == 0)
1804 {
1805 arg->cp = exp;
1806 return OR;
1807 }
1808
1809 lval->sval = xstrdup (buffer);
1810 result = KEYWORD;
1811 break;
1812 case '!':
1813 if (exp[0] == '=')
1814 {
1815 ++exp;
1816 result = '!';
1817 }
1818 else
1819 result = YYERRCODE;
1820 break;
1821 default:
1822 break;
1823 }
1824
1825 arg->cp = exp;
1826
1827 return result;
1828 }
1829
1830 static void
1831 yyerror (struct cldr_plural_parse_args *arg, char const *s)
1832 {
1833 fprintf (stderr, "%s\n", s);
1834 }