1 /* A Bison parser, made by GNU Bison 3.0.2. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
43 /* Identify Bison output. */
47 #define YYBISON_VERSION "3.0.2"
50 #define YYSKELETON_NAME "yacc.c"
64 /* Copy the first part of user declarations. */
65 #line 20 "label.y" /* yacc.c:339 */
74 void yyerror(const char *);
77 static const char *format_serial(char c, int n);
84 label_info(const string &);
87 label_info *lookup_label(const string &label);
91 // Does the tentative label depend on the reference?
92 CONTAINS_VARIABLE = 01,
97 virtual ~expression() { }
98 virtual void evaluate(int, const reference &, string &,
99 substring_position &) = 0;
100 virtual unsigned analyze() { return 0; }
103 class at_expr : public expression {
106 void evaluate(int, const reference &, string &, substring_position &);
107 unsigned analyze() { return CONTAINS_VARIABLE|CONTAINS_AT; }
110 class format_expr : public expression {
115 format_expr(char c, int w = 0, int f = 1)
116 : type(c), width(w), first_number(f) { }
117 void evaluate(int, const reference &, string &, substring_position &);
118 unsigned analyze() { return CONTAINS_FORMAT; }
121 class field_expr : public expression {
125 field_expr(char nm, int num) : number(num), name(nm) { }
126 void evaluate(int, const reference &, string &, substring_position &);
127 unsigned analyze() { return CONTAINS_VARIABLE; }
130 class literal_expr : public expression {
133 literal_expr(const char *ptr, int len) : s(ptr, len) { }
134 void evaluate(int, const reference &, string &, substring_position &);
137 class unary_expr : public expression {
141 unary_expr(expression *e) : expr(e) { }
142 ~unary_expr() { delete expr; }
143 void evaluate(int, const reference &, string &, substring_position &) = 0;
144 unsigned analyze() { return expr ? expr->analyze() : 0; }
147 // This caches the analysis of an expression.
149 class analyzed_expr : public unary_expr {
152 analyzed_expr(expression *);
153 void evaluate(int, const reference &, string &, substring_position &);
154 unsigned analyze() { return flags; }
157 class star_expr : public unary_expr {
159 star_expr(expression *e) : unary_expr(e) { }
160 void evaluate(int, const reference &, string &, substring_position &);
162 return ((expr ? (expr->analyze() & ~CONTAINS_VARIABLE) : 0)
167 typedef void map_func(const char *, const char *, string &);
169 class map_expr : public unary_expr {
172 map_expr(expression *e, map_func *f) : unary_expr(e), func(f) { }
173 void evaluate(int, const reference &, string &, substring_position &);
176 typedef const char *extractor_func(const char *, const char *, const char **);
178 class extractor_expr : public unary_expr {
180 extractor_func *func;
182 enum { BEFORE = +1, MATCH = 0, AFTER = -1 };
183 extractor_expr(expression *e, extractor_func *f, int pt)
184 : unary_expr(e), part(pt), func(f) { }
185 void evaluate(int, const reference &, string &, substring_position &);
188 class truncate_expr : public unary_expr {
191 truncate_expr(expression *e, int i) : unary_expr(e), n(i) { }
192 void evaluate(int, const reference &, string &, substring_position &);
195 class separator_expr : public unary_expr {
197 separator_expr(expression *e) : unary_expr(e) { }
198 void evaluate(int, const reference &, string &, substring_position &);
201 class binary_expr : public expression {
206 binary_expr(expression *e1, expression *e2) : expr1(e1), expr2(e2) { }
207 ~binary_expr() { delete expr1; delete expr2; }
208 void evaluate(int, const reference &, string &, substring_position &) = 0;
210 return (expr1 ? expr1->analyze() : 0) | (expr2 ? expr2->analyze() : 0);
214 class alternative_expr : public binary_expr {
216 alternative_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }
217 void evaluate(int, const reference &, string &, substring_position &);
220 class list_expr : public binary_expr {
222 list_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }
223 void evaluate(int, const reference &, string &, substring_position &);
226 class substitute_expr : public binary_expr {
228 substitute_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }
229 void evaluate(int, const reference &, string &, substring_position &);
232 class ternary_expr : public expression {
238 ternary_expr(expression *e1, expression *e2, expression *e3)
239 : expr1(e1), expr2(e2), expr3(e3) { }
240 ~ternary_expr() { delete expr1; delete expr2; delete expr3; }
241 void evaluate(int, const reference &, string &, substring_position &) = 0;
243 return ((expr1 ? expr1->analyze() : 0)
244 | (expr2 ? expr2->analyze() : 0)
245 | (expr3 ? expr3->analyze() : 0));
249 class conditional_expr : public ternary_expr {
251 conditional_expr(expression *e1, expression *e2, expression *e3)
252 : ternary_expr(e1, e2, e3) { }
253 void evaluate(int, const reference &, string &, substring_position &);
256 static expression *parsed_label = 0;
257 static expression *parsed_date_label = 0;
258 static expression *parsed_short_label = 0;
260 static expression *parse_result;
265 #line 266 "label.cpp" /* yacc.c:339 */
268 # if defined __cplusplus && 201103L <= __cplusplus
269 # define YY_NULLPTR nullptr
271 # define YY_NULLPTR 0
275 /* Enabling verbose error messages. */
276 #ifdef YYERROR_VERBOSE
277 # undef YYERROR_VERBOSE
278 # define YYERROR_VERBOSE 1
280 # define YYERROR_VERBOSE 0
303 #define TOKEN_LETTER 258
304 #define TOKEN_LITERAL 259
305 #define TOKEN_DIGIT 260
308 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
309 typedef union YYSTYPE YYSTYPE;
312 #line 220 "label.y" /* yacc.c:355 */
316 struct { int ndigits; int val; } dig;
317 struct { int start; int len; } str;
319 #line 320 "label.cpp" /* yacc.c:355 */
321 # define YYSTYPE_IS_TRIVIAL 1
322 # define YYSTYPE_IS_DECLARED 1
326 extern YYSTYPE yylval;
332 /* Copy the second part of user declarations. */
334 #line 335 "label.cpp" /* yacc.c:358 */
341 typedef YYTYPE_UINT8 yytype_uint8;
343 typedef unsigned char yytype_uint8;
347 typedef YYTYPE_INT8 yytype_int8;
349 typedef signed char yytype_int8;
353 typedef YYTYPE_UINT16 yytype_uint16;
355 typedef unsigned short int yytype_uint16;
359 typedef YYTYPE_INT16 yytype_int16;
361 typedef short int yytype_int16;
365 # ifdef __SIZE_TYPE__
366 # define YYSIZE_T __SIZE_TYPE__
367 # elif defined size_t
368 # define YYSIZE_T size_t
369 # elif ! defined YYSIZE_T
370 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
371 # define YYSIZE_T size_t
373 # define YYSIZE_T unsigned int
377 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
380 # if defined YYENABLE_NLS && YYENABLE_NLS
382 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
383 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
387 # define YY_(Msgid) Msgid
392 # if (defined __GNUC__ \
393 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
394 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
395 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
397 # define YY_ATTRIBUTE(Spec) /* empty */
401 #ifndef YY_ATTRIBUTE_PURE
402 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
405 #ifndef YY_ATTRIBUTE_UNUSED
406 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
409 #if !defined _Noreturn \
410 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
411 # if defined _MSC_VER && 1200 <= _MSC_VER
412 # define _Noreturn __declspec (noreturn)
414 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
418 /* Suppress unused-variable warnings by "using" E. */
419 #if ! defined lint || defined __GNUC__
420 # define YYUSE(E) ((void) (E))
422 # define YYUSE(E) /* empty */
425 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
426 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
427 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
428 _Pragma ("GCC diagnostic push") \
429 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
430 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
431 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
432 _Pragma ("GCC diagnostic pop")
434 # define YY_INITIAL_VALUE(Value) Value
436 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
437 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
438 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
440 #ifndef YY_INITIAL_VALUE
441 # define YY_INITIAL_VALUE(Value) /* Nothing. */
445 #if ! defined yyoverflow || YYERROR_VERBOSE
447 /* The parser invokes alloca or malloc; define the necessary symbols. */
449 # ifdef YYSTACK_USE_ALLOCA
450 # if YYSTACK_USE_ALLOCA
452 # define YYSTACK_ALLOC __builtin_alloca
453 # elif defined __BUILTIN_VA_ARG_INCR
454 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
456 # define YYSTACK_ALLOC __alloca
457 # elif defined _MSC_VER
458 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
459 # define alloca _alloca
461 # define YYSTACK_ALLOC alloca
462 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
463 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
464 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
465 # ifndef EXIT_SUCCESS
466 # define EXIT_SUCCESS 0
473 # ifdef YYSTACK_ALLOC
474 /* Pacify GCC's 'empty if-body' warning. */
475 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
476 # ifndef YYSTACK_ALLOC_MAXIMUM
477 /* The OS might guarantee only one guard page at the bottom of the stack,
478 and a page size can be as small as 4096 bytes. So we cannot safely
479 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
480 to allow for a few compiler-allocated temporary stack slots. */
481 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
484 # define YYSTACK_ALLOC YYMALLOC
485 # define YYSTACK_FREE YYFREE
486 # ifndef YYSTACK_ALLOC_MAXIMUM
487 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
489 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
490 && ! ((defined YYMALLOC || defined malloc) \
491 && (defined YYFREE || defined free)))
492 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
493 # ifndef EXIT_SUCCESS
494 # define EXIT_SUCCESS 0
498 # define YYMALLOC malloc
499 # if ! defined malloc && ! defined EXIT_SUCCESS
500 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
505 # if ! defined free && ! defined EXIT_SUCCESS
506 void free (void *); /* INFRINGES ON USER NAME SPACE */
510 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
513 #if (! defined yyoverflow \
514 && (! defined __cplusplus \
515 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
517 /* A type that is properly aligned for any stack member. */
520 yytype_int16 yyss_alloc;
524 /* The size of the maximum gap between one aligned stack and the next. */
525 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
527 /* The size of an array large to enough to hold all stacks, each with
529 # define YYSTACK_BYTES(N) \
530 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
531 + YYSTACK_GAP_MAXIMUM)
533 # define YYCOPY_NEEDED 1
535 /* Relocate STACK from its old location to the new one. The
536 local variables YYSIZE and YYSTACKSIZE give the old and new number of
537 elements in the stack, and YYPTR gives the new location of the
538 stack. Advance YYPTR to a properly aligned location for the next
540 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
543 YYSIZE_T yynewbytes; \
544 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
545 Stack = &yyptr->Stack_alloc; \
546 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
547 yyptr += yynewbytes / sizeof (*yyptr); \
553 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
554 /* Copy COUNT objects from SRC to DST. The source and destination do
557 # if defined __GNUC__ && 1 < __GNUC__
558 # define YYCOPY(Dst, Src, Count) \
559 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
561 # define YYCOPY(Dst, Src, Count) \
565 for (yyi = 0; yyi < (Count); yyi++) \
566 (Dst)[yyi] = (Src)[yyi]; \
571 #endif /* !YYCOPY_NEEDED */
573 /* YYFINAL -- State number of the termination state. */
575 /* YYLAST -- Last index in YYTABLE. */
578 /* YYNTOKENS -- Number of terminals. */
580 /* YYNNTS -- Number of nonterminals. */
582 /* YYNRULES -- Number of rules. */
584 /* YYNSTATES -- Number of states. */
587 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
588 by yylex, with out-of-bounds checking. */
590 #define YYMAXUTOK 260
592 #define YYTRANSLATE(YYX) \
593 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
595 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
596 as returned by yylex, without out-of-bounds checking. */
597 static const yytype_uint8 yytranslate[] =
599 0, 2, 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, 12, 9, 2,
603 17, 18, 16, 14, 2, 15, 13, 2, 2, 2,
604 2, 2, 2, 2, 2, 2, 2, 2, 7, 2,
605 19, 2, 20, 6, 11, 2, 2, 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, 8, 2, 10, 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, 2, 2, 2, 2,
619 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
620 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
621 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
622 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
623 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
624 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
629 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
630 static const yytype_uint16 yyrline[] =
632 0, 248, 248, 253, 255, 261, 262, 267, 269, 271,
633 276, 278, 283, 285, 290, 292, 297, 299, 301, 317,
634 321, 352, 354, 356, 358, 360, 366, 367, 372, 374,
635 379, 381, 388, 389, 391
639 #if YYDEBUG || YYERROR_VERBOSE || 0
640 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
641 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
642 static const char *const yytname[] =
644 "$end", "error", "$undefined", "TOKEN_LETTER", "TOKEN_LITERAL",
645 "TOKEN_DIGIT", "'?'", "':'", "'|'", "'&'", "'~'", "'@'", "'%'", "'.'",
646 "'+'", "'-'", "'*'", "'('", "')'", "'<'", "'>'", "$accept", "expr",
647 "conditional", "optional_conditional", "alternative", "list",
648 "substitute", "string", "optional_number", "number", "digits", "flag", YY_NULLPTR
653 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
654 (internal) symbol number NUM (which must be that of a token). */
655 static const yytype_uint16 yytoknum[] =
657 0, 256, 257, 258, 259, 260, 63, 58, 124, 38,
658 126, 64, 37, 46, 43, 45, 42, 40, 41, 60,
663 #define YYPACT_NINF -26
665 #define yypact_value_is_default(Yystate) \
666 (!!((Yystate) == (-26)))
668 #define YYTABLE_NINF -1
670 #define yytable_value_is_error(Yytable_value) \
673 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
675 static const yytype_int8 yypact[] =
677 2, 11, -26, -26, 12, 2, 2, 24, -26, -26,
678 21, 2, 18, -6, -26, 26, -26, -26, 27, 15,
679 14, -26, 2, 2, 2, 18, 2, -3, 11, 11,
680 -26, -26, -26, -26, -26, 28, 2, 2, -6, -26,
681 -26, 33, 26, 26, 2, 11, -26, -26, 26
684 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
685 Performed when YYTABLE does not specify something else to do. Zero
686 means the default is an error. */
687 static const yytype_uint8 yydefact[] =
689 5, 16, 15, 14, 0, 5, 5, 0, 6, 2,
690 3, 7, 10, 12, 28, 17, 18, 30, 19, 0,
691 0, 1, 5, 0, 0, 11, 0, 32, 0, 0,
692 23, 29, 31, 24, 25, 0, 8, 9, 13, 33,
693 34, 0, 21, 22, 0, 26, 4, 20, 27
696 /* YYPGOTO[NTERM-NUM]. */
697 static const yytype_int8 yypgoto[] =
699 -26, -26, -7, -4, -26, -1, -11, 13, -26, -25,
703 /* YYDEFGOTO[NTERM-NUM]. */
704 static const yytype_int8 yydefgoto[] =
706 -1, 7, 8, 9, 10, 11, 12, 13, 47, 15,
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_uint8 yytable[] =
715 25, 19, 20, 42, 43, 1, 2, 27, 28, 29,
716 30, 39, 40, 3, 4, 16, 14, 17, 35, 5,
717 48, 6, 36, 37, 21, 25, 25, 22, 26, 23,
718 24, 31, 32, 33, 34, 44, 45, 46, 0, 38
721 static const yytype_int8 yycheck[] =
723 11, 5, 6, 28, 29, 3, 4, 13, 14, 15,
724 16, 14, 15, 11, 12, 3, 5, 5, 22, 17,
725 45, 19, 23, 24, 0, 36, 37, 6, 10, 8,
726 9, 5, 5, 18, 20, 7, 3, 44, -1, 26
729 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
730 symbol of state STATE-NUM. */
731 static const yytype_uint8 yystos[] =
733 0, 3, 4, 11, 12, 17, 19, 22, 23, 24,
734 25, 26, 27, 28, 5, 30, 3, 5, 31, 24,
735 24, 0, 6, 8, 9, 27, 10, 13, 14, 15,
736 16, 5, 5, 18, 20, 24, 26, 26, 28, 14,
737 15, 32, 30, 30, 7, 3, 23, 29, 30
740 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
741 static const yytype_uint8 yyr1[] =
743 0, 21, 22, 23, 23, 24, 24, 25, 25, 25,
744 26, 26, 27, 27, 28, 28, 28, 28, 28, 28,
745 28, 28, 28, 28, 28, 28, 29, 29, 30, 30,
749 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
750 static const yytype_uint8 yyr2[] =
752 0, 2, 1, 1, 5, 0, 1, 1, 3, 3,
753 1, 2, 1, 3, 1, 1, 1, 2, 2, 2,
754 5, 3, 3, 2, 3, 3, 0, 1, 1, 2,
759 #define yyerrok (yyerrstatus = 0)
760 #define yyclearin (yychar = YYEMPTY)
764 #define YYACCEPT goto yyacceptlab
765 #define YYABORT goto yyabortlab
766 #define YYERROR goto yyerrorlab
769 #define YYRECOVERING() (!!yyerrstatus)
771 #define YYBACKUP(Token, Value) \
773 if (yychar == YYEMPTY) \
777 YYPOPSTACK (yylen); \
783 yyerror (YY_("syntax error: cannot back up")); \
788 /* Error token number */
790 #define YYERRCODE 256
794 /* Enable debugging if requested. */
798 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
799 # define YYFPRINTF fprintf
802 # define YYDPRINTF(Args) \
808 /* This macro is provided for backward compatibility. */
809 #ifndef YY_LOCATION_PRINT
810 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
814 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
818 YYFPRINTF (stderr, "%s ", Title); \
819 yy_symbol_print (stderr, \
821 YYFPRINTF (stderr, "\n"); \
826 /*----------------------------------------.
827 | Print this symbol's value on YYOUTPUT. |
828 `----------------------------------------*/
831 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
833 FILE *yyo = yyoutput;
838 if (yytype < YYNTOKENS)
839 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
845 /*--------------------------------.
846 | Print this symbol on YYOUTPUT. |
847 `--------------------------------*/
850 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
852 YYFPRINTF (yyoutput, "%s %s (",
853 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
855 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
856 YYFPRINTF (yyoutput, ")");
859 /*------------------------------------------------------------------.
860 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
862 `------------------------------------------------------------------*/
865 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
867 YYFPRINTF (stderr, "Stack now");
868 for (; yybottom <= yytop; yybottom++)
870 int yybot = *yybottom;
871 YYFPRINTF (stderr, " %d", yybot);
873 YYFPRINTF (stderr, "\n");
876 # define YY_STACK_PRINT(Bottom, Top) \
879 yy_stack_print ((Bottom), (Top)); \
883 /*------------------------------------------------.
884 | Report that the YYRULE is going to be reduced. |
885 `------------------------------------------------*/
888 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
890 unsigned long int yylno = yyrline[yyrule];
891 int yynrhs = yyr2[yyrule];
893 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
895 /* The symbols being reduced. */
896 for (yyi = 0; yyi < yynrhs; yyi++)
898 YYFPRINTF (stderr, " $%d = ", yyi + 1);
899 yy_symbol_print (stderr,
900 yystos[yyssp[yyi + 1 - yynrhs]],
901 &(yyvsp[(yyi + 1) - (yynrhs)])
903 YYFPRINTF (stderr, "\n");
907 # define YY_REDUCE_PRINT(Rule) \
910 yy_reduce_print (yyssp, yyvsp, Rule); \
913 /* Nonzero means print parse trace. It is left uninitialized so that
914 multiple parsers can coexist. */
917 # define YYDPRINTF(Args)
918 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
919 # define YY_STACK_PRINT(Bottom, Top)
920 # define YY_REDUCE_PRINT(Rule)
921 #endif /* !YYDEBUG */
924 /* YYINITDEPTH -- initial size of the parser's stacks. */
926 # define YYINITDEPTH 200
929 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
930 if the built-in stack extension method is used).
932 Do not make this value too large; the results are undefined if
933 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
934 evaluated with infinite-precision integer arithmetic. */
937 # define YYMAXDEPTH 10000
944 # if defined __GLIBC__ && defined _STRING_H
945 # define yystrlen strlen
947 /* Return the length of YYSTR. */
949 yystrlen (const char *yystr)
952 for (yylen = 0; yystr[yylen]; yylen++)
960 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
961 # define yystpcpy stpcpy
963 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
966 yystpcpy (char *yydest, const char *yysrc)
969 const char *yys = yysrc;
971 while ((*yyd++ = *yys++) != '\0')
980 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
981 quotes and backslashes, so that it's suitable for yyerror. The
982 heuristic is that double-quoting is unnecessary unless the string
983 contains an apostrophe, a comma, or backslash (other than
984 backslash-backslash). YYSTR is taken from yytname. If YYRES is
985 null, do not copy; instead, return the length of what the result
988 yytnamerr (char *yyres, const char *yystr)
993 char const *yyp = yystr;
1000 goto do_not_strip_quotes;
1004 goto do_not_strip_quotes;
1017 do_not_strip_quotes: ;
1021 return yystrlen (yystr);
1023 return yystpcpy (yyres, yystr) - yyres;
1027 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1028 about the unexpected token YYTOKEN for the state stack whose top is
1031 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1032 not large enough to hold the message. In that case, also set
1033 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1034 required number of bytes is too large to store. */
1036 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1037 yytype_int16 *yyssp, int yytoken)
1039 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1040 YYSIZE_T yysize = yysize0;
1041 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1042 /* Internationalized format string. */
1043 const char *yyformat = YY_NULLPTR;
1044 /* Arguments of yyformat. */
1045 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1046 /* Number of reported tokens (one for the "unexpected", one per
1050 /* There are many possibilities here to consider:
1051 - If this state is a consistent state with a default action, then
1052 the only way this function was invoked is if the default action
1053 is an error action. In that case, don't check for expected
1054 tokens because there are none.
1055 - The only way there can be no lookahead present (in yychar) is if
1056 this state is a consistent state with a default action. Thus,
1057 detecting the absence of a lookahead is sufficient to determine
1058 that there is no unexpected or expected token to report. In that
1059 case, just report a simple "syntax error".
1060 - Don't assume there isn't a lookahead just because this state is a
1061 consistent state with a default action. There might have been a
1062 previous inconsistent state, consistent state with a non-default
1063 action, or user semantic action that manipulated yychar.
1064 - Of course, the expected token list depends on states to have
1065 correct lookahead information, and it depends on the parser not
1066 to perform extra reductions after fetching a lookahead from the
1067 scanner and before detecting a syntax error. Thus, state merging
1068 (from LALR or IELR) and default reductions corrupt the expected
1069 token list. However, the list is correct for canonical LR with
1070 one exception: it will still contain any token that will not be
1071 accepted due to an error action in a later state.
1073 if (yytoken != YYEMPTY)
1075 int yyn = yypact[*yyssp];
1076 yyarg[yycount++] = yytname[yytoken];
1077 if (!yypact_value_is_default (yyn))
1079 /* Start YYX at -YYN if negative to avoid negative indexes in
1080 YYCHECK. In other words, skip the first -YYN actions for
1081 this state because they are default actions. */
1082 int yyxbegin = yyn < 0 ? -yyn : 0;
1083 /* Stay within bounds of both yycheck and yytname. */
1084 int yychecklim = YYLAST - yyn + 1;
1085 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1088 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1089 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1090 && !yytable_value_is_error (yytable[yyx + yyn]))
1092 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1098 yyarg[yycount++] = yytname[yyx];
1100 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1101 if (! (yysize <= yysize1
1102 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1112 # define YYCASE_(N, S) \
1116 YYCASE_(0, YY_("syntax error"));
1117 YYCASE_(1, YY_("syntax error, unexpected %s"));
1118 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1119 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1120 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1121 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1126 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1127 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1132 if (*yymsg_alloc < yysize)
1134 *yymsg_alloc = 2 * yysize;
1135 if (! (yysize <= *yymsg_alloc
1136 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1137 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1141 /* Avoid sprintf, as that infringes on the user's name space.
1142 Don't have undefined behavior even if the translation
1143 produced a string with the wrong number of "%s"s. */
1147 while ((*yyp = *yyformat) != '\0')
1148 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1150 yyp += yytnamerr (yyp, yyarg[yyi++]);
1161 #endif /* YYERROR_VERBOSE */
1163 /*-----------------------------------------------.
1164 | Release the memory associated to this symbol. |
1165 `-----------------------------------------------*/
1168 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1173 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1175 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1177 YY_IGNORE_MAYBE_UNINITIALIZED_END
1183 /* The lookahead symbol. */
1186 /* The semantic value of the lookahead symbol. */
1188 /* Number of syntax errors so far. */
1200 /* Number of tokens to shift before error messages enabled. */
1203 /* The stacks and their tools:
1204 'yyss': related to states.
1205 'yyvs': related to semantic values.
1207 Refer to the stacks through separate pointers, to allow yyoverflow
1208 to reallocate them elsewhere. */
1210 /* The state stack. */
1211 yytype_int16 yyssa[YYINITDEPTH];
1213 yytype_int16 *yyssp;
1215 /* The semantic value stack. */
1216 YYSTYPE yyvsa[YYINITDEPTH];
1220 YYSIZE_T yystacksize;
1224 /* Lookahead token as an internal (translated) token number. */
1226 /* The variables used to return semantic value and location from the
1231 /* Buffer for error messages, and its allocated size. */
1233 char *yymsg = yymsgbuf;
1234 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1237 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1239 /* The number of symbols on the RHS of the reduced rule.
1240 Keep to zero when no symbol should be popped. */
1243 yyssp = yyss = yyssa;
1244 yyvsp = yyvs = yyvsa;
1245 yystacksize = YYINITDEPTH;
1247 YYDPRINTF ((stderr, "Starting parse\n"));
1252 yychar = YYEMPTY; /* Cause a token to be read. */
1255 /*------------------------------------------------------------.
1256 | yynewstate -- Push a new state, which is found in yystate. |
1257 `------------------------------------------------------------*/
1259 /* In all cases, when you get here, the value and location stacks
1260 have just been pushed. So pushing a state here evens the stacks. */
1266 if (yyss + yystacksize - 1 <= yyssp)
1268 /* Get the current used size of the three stacks, in elements. */
1269 YYSIZE_T yysize = yyssp - yyss + 1;
1273 /* Give user a chance to reallocate the stack. Use copies of
1274 these so that the &'s don't force the real ones into
1276 YYSTYPE *yyvs1 = yyvs;
1277 yytype_int16 *yyss1 = yyss;
1279 /* Each stack pointer address is followed by the size of the
1280 data in use in that stack, in bytes. This used to be a
1281 conditional around just the two extra args, but that might
1282 be undefined if yyoverflow is a macro. */
1283 yyoverflow (YY_("memory exhausted"),
1284 &yyss1, yysize * sizeof (*yyssp),
1285 &yyvs1, yysize * sizeof (*yyvsp),
1291 #else /* no yyoverflow */
1292 # ifndef YYSTACK_RELOCATE
1293 goto yyexhaustedlab;
1295 /* Extend the stack our own way. */
1296 if (YYMAXDEPTH <= yystacksize)
1297 goto yyexhaustedlab;
1299 if (YYMAXDEPTH < yystacksize)
1300 yystacksize = YYMAXDEPTH;
1303 yytype_int16 *yyss1 = yyss;
1304 union yyalloc *yyptr =
1305 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1307 goto yyexhaustedlab;
1308 YYSTACK_RELOCATE (yyss_alloc, yyss);
1309 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1310 # undef YYSTACK_RELOCATE
1312 YYSTACK_FREE (yyss1);
1315 #endif /* no yyoverflow */
1317 yyssp = yyss + yysize - 1;
1318 yyvsp = yyvs + yysize - 1;
1320 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1321 (unsigned long int) yystacksize));
1323 if (yyss + yystacksize - 1 <= yyssp)
1327 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1329 if (yystate == YYFINAL)
1339 /* Do appropriate processing given the current state. Read a
1340 lookahead token if we need one and don't already have one. */
1342 /* First try to decide what to do without reference to lookahead token. */
1343 yyn = yypact[yystate];
1344 if (yypact_value_is_default (yyn))
1347 /* Not known => get a lookahead token if don't already have one. */
1349 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1350 if (yychar == YYEMPTY)
1352 YYDPRINTF ((stderr, "Reading a token: "));
1356 if (yychar <= YYEOF)
1358 yychar = yytoken = YYEOF;
1359 YYDPRINTF ((stderr, "Now at end of input.\n"));
1363 yytoken = YYTRANSLATE (yychar);
1364 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1367 /* If the proper action on seeing token YYTOKEN is to reduce or to
1368 detect an error, take that action. */
1370 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1375 if (yytable_value_is_error (yyn))
1381 /* Count tokens shifted since error; after three, turn off error
1386 /* Shift the lookahead token. */
1387 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1389 /* Discard the shifted token. */
1393 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1395 YY_IGNORE_MAYBE_UNINITIALIZED_END
1400 /*-----------------------------------------------------------.
1401 | yydefault -- do the default action for the current state. |
1402 `-----------------------------------------------------------*/
1404 yyn = yydefact[yystate];
1410 /*-----------------------------.
1411 | yyreduce -- Do a reduction. |
1412 `-----------------------------*/
1414 /* yyn is the number of a rule to reduce with. */
1417 /* If YYLEN is nonzero, implement the default value of the action:
1420 Otherwise, the following line sets YYVAL to garbage.
1421 This behavior is undocumented and Bison
1422 users should not rely upon it. Assigning to YYVAL
1423 unconditionally makes the parser a bit smaller, and it avoids a
1424 GCC warning that YYVAL may be used uninitialized. */
1425 yyval = yyvsp[1-yylen];
1428 YY_REDUCE_PRINT (yyn);
1432 #line 249 "label.y" /* yacc.c:1646 */
1433 { parse_result = ((yyvsp[0].expr) ? new analyzed_expr((yyvsp[0].expr)) : 0); }
1434 #line 1435 "label.cpp" /* yacc.c:1646 */
1438 #line 254 "label.y" /* yacc.c:1646 */
1439 { (yyval.expr) = (yyvsp[0].expr); }
1440 #line 1441 "label.cpp" /* yacc.c:1646 */
1444 #line 256 "label.y" /* yacc.c:1646 */
1445 { (yyval.expr) = new conditional_expr((yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].expr)); }
1446 #line 1447 "label.cpp" /* yacc.c:1646 */
1450 #line 261 "label.y" /* yacc.c:1646 */
1451 { (yyval.expr) = 0; }
1452 #line 1453 "label.cpp" /* yacc.c:1646 */
1456 #line 263 "label.y" /* yacc.c:1646 */
1457 { (yyval.expr) = (yyvsp[0].expr); }
1458 #line 1459 "label.cpp" /* yacc.c:1646 */
1462 #line 268 "label.y" /* yacc.c:1646 */
1463 { (yyval.expr) = (yyvsp[0].expr); }
1464 #line 1465 "label.cpp" /* yacc.c:1646 */
1468 #line 270 "label.y" /* yacc.c:1646 */
1469 { (yyval.expr) = new alternative_expr((yyvsp[-2].expr), (yyvsp[0].expr)); }
1470 #line 1471 "label.cpp" /* yacc.c:1646 */
1474 #line 272 "label.y" /* yacc.c:1646 */
1475 { (yyval.expr) = new conditional_expr((yyvsp[-2].expr), (yyvsp[0].expr), 0); }
1476 #line 1477 "label.cpp" /* yacc.c:1646 */
1480 #line 277 "label.y" /* yacc.c:1646 */
1481 { (yyval.expr) = (yyvsp[0].expr); }
1482 #line 1483 "label.cpp" /* yacc.c:1646 */
1486 #line 279 "label.y" /* yacc.c:1646 */
1487 { (yyval.expr) = new list_expr((yyvsp[-1].expr), (yyvsp[0].expr)); }
1488 #line 1489 "label.cpp" /* yacc.c:1646 */
1492 #line 284 "label.y" /* yacc.c:1646 */
1493 { (yyval.expr) = (yyvsp[0].expr); }
1494 #line 1495 "label.cpp" /* yacc.c:1646 */
1498 #line 286 "label.y" /* yacc.c:1646 */
1499 { (yyval.expr) = new substitute_expr((yyvsp[-2].expr), (yyvsp[0].expr)); }
1500 #line 1501 "label.cpp" /* yacc.c:1646 */
1504 #line 291 "label.y" /* yacc.c:1646 */
1505 { (yyval.expr) = new at_expr; }
1506 #line 1507 "label.cpp" /* yacc.c:1646 */
1510 #line 293 "label.y" /* yacc.c:1646 */
1512 (yyval.expr) = new literal_expr(literals.contents() + (yyvsp[0].str).start,
1513 (yyvsp[0].str).len);
1515 #line 1516 "label.cpp" /* yacc.c:1646 */
1519 #line 298 "label.y" /* yacc.c:1646 */
1520 { (yyval.expr) = new field_expr((yyvsp[0].num), 0); }
1521 #line 1522 "label.cpp" /* yacc.c:1646 */
1525 #line 300 "label.y" /* yacc.c:1646 */
1526 { (yyval.expr) = new field_expr((yyvsp[-1].num), (yyvsp[0].num) - 1); }
1527 #line 1528 "label.cpp" /* yacc.c:1646 */
1531 #line 302 "label.y" /* yacc.c:1646 */
1533 switch ((yyvsp[0].num)) {
1538 (yyval.expr) = new format_expr((yyvsp[0].num));
1541 command_error("unrecognized format `%1'", char((yyvsp[0].num)));
1542 (yyval.expr) = new format_expr('a');
1546 #line 1547 "label.cpp" /* yacc.c:1646 */
1550 #line 318 "label.y" /* yacc.c:1646 */
1552 (yyval.expr) = new format_expr('0', (yyvsp[0].dig).ndigits, (yyvsp[0].dig).val);
1554 #line 1555 "label.cpp" /* yacc.c:1646 */
1558 #line 322 "label.y" /* yacc.c:1646 */
1560 switch ((yyvsp[-1].num)) {
1562 (yyval.expr) = new map_expr((yyvsp[-4].expr), lowercase);
1565 (yyval.expr) = new map_expr((yyvsp[-4].expr), uppercase);
1568 (yyval.expr) = new map_expr((yyvsp[-4].expr), capitalize);
1571 (yyval.expr) = new map_expr((yyvsp[-4].expr), reverse_name);
1574 (yyval.expr) = new map_expr((yyvsp[-4].expr), abbreviate_name);
1577 (yyval.expr) = new extractor_expr((yyvsp[-4].expr), find_year, (yyvsp[-2].num));
1580 (yyval.expr) = new extractor_expr((yyvsp[-4].expr), find_last_name, (yyvsp[-2].num));
1583 (yyval.expr) = (yyvsp[-4].expr);
1584 command_error("unknown function `%1'", char((yyvsp[-1].num)));
1588 #line 1589 "label.cpp" /* yacc.c:1646 */
1592 #line 353 "label.y" /* yacc.c:1646 */
1593 { (yyval.expr) = new truncate_expr((yyvsp[-2].expr), (yyvsp[0].num)); }
1594 #line 1595 "label.cpp" /* yacc.c:1646 */
1598 #line 355 "label.y" /* yacc.c:1646 */
1599 { (yyval.expr) = new truncate_expr((yyvsp[-2].expr), -(yyvsp[0].num)); }
1600 #line 1601 "label.cpp" /* yacc.c:1646 */
1604 #line 357 "label.y" /* yacc.c:1646 */
1605 { (yyval.expr) = new star_expr((yyvsp[-1].expr)); }
1606 #line 1607 "label.cpp" /* yacc.c:1646 */
1610 #line 359 "label.y" /* yacc.c:1646 */
1611 { (yyval.expr) = (yyvsp[-1].expr); }
1612 #line 1613 "label.cpp" /* yacc.c:1646 */
1616 #line 361 "label.y" /* yacc.c:1646 */
1617 { (yyval.expr) = new separator_expr((yyvsp[-1].expr)); }
1618 #line 1619 "label.cpp" /* yacc.c:1646 */
1622 #line 366 "label.y" /* yacc.c:1646 */
1623 { (yyval.num) = -1; }
1624 #line 1625 "label.cpp" /* yacc.c:1646 */
1628 #line 368 "label.y" /* yacc.c:1646 */
1629 { (yyval.num) = (yyvsp[0].num); }
1630 #line 1631 "label.cpp" /* yacc.c:1646 */
1634 #line 373 "label.y" /* yacc.c:1646 */
1635 { (yyval.num) = (yyvsp[0].num); }
1636 #line 1637 "label.cpp" /* yacc.c:1646 */
1640 #line 375 "label.y" /* yacc.c:1646 */
1641 { (yyval.num) = (yyvsp[-1].num)*10 + (yyvsp[0].num); }
1642 #line 1643 "label.cpp" /* yacc.c:1646 */
1646 #line 380 "label.y" /* yacc.c:1646 */
1647 { (yyval.dig).ndigits = 1; (yyval.dig).val = (yyvsp[0].num); }
1648 #line 1649 "label.cpp" /* yacc.c:1646 */
1652 #line 382 "label.y" /* yacc.c:1646 */
1653 { (yyval.dig).ndigits = (yyvsp[-1].dig).ndigits + 1; (yyval.dig).val = (yyvsp[-1].dig).val*10 + (yyvsp[0].num); }
1654 #line 1655 "label.cpp" /* yacc.c:1646 */
1658 #line 388 "label.y" /* yacc.c:1646 */
1659 { (yyval.num) = 0; }
1660 #line 1661 "label.cpp" /* yacc.c:1646 */
1664 #line 390 "label.y" /* yacc.c:1646 */
1665 { (yyval.num) = 1; }
1666 #line 1667 "label.cpp" /* yacc.c:1646 */
1670 #line 392 "label.y" /* yacc.c:1646 */
1671 { (yyval.num) = -1; }
1672 #line 1673 "label.cpp" /* yacc.c:1646 */
1676 #line 1677 "label.cpp" /* yacc.c:1646 */
1679 /* User semantic actions sometimes alter yychar, and that requires
1680 that yytoken be updated with the new translation. We take the
1681 approach of translating immediately before every use of yytoken.
1682 One alternative is translating here after every semantic action,
1683 but that translation would be missed if the semantic action invokes
1684 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1685 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1686 incorrect destructor might then be invoked immediately. In the
1687 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1688 to an incorrect destructor call or verbose syntax error message
1689 before the lookahead is translated. */
1690 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1694 YY_STACK_PRINT (yyss, yyssp);
1698 /* Now 'shift' the result of the reduction. Determine what state
1699 that goes to, based on the state we popped back to and the rule
1700 number reduced by. */
1704 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1705 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1706 yystate = yytable[yystate];
1708 yystate = yydefgoto[yyn - YYNTOKENS];
1713 /*--------------------------------------.
1714 | yyerrlab -- here on detecting error. |
1715 `--------------------------------------*/
1717 /* Make sure we have latest lookahead translation. See comments at
1718 user semantic actions for why this is necessary. */
1719 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1721 /* If not already recovering from an error, report this error. */
1725 #if ! YYERROR_VERBOSE
1726 yyerror (YY_("syntax error"));
1728 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1731 char const *yymsgp = YY_("syntax error");
1732 int yysyntax_error_status;
1733 yysyntax_error_status = YYSYNTAX_ERROR;
1734 if (yysyntax_error_status == 0)
1736 else if (yysyntax_error_status == 1)
1738 if (yymsg != yymsgbuf)
1739 YYSTACK_FREE (yymsg);
1740 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1744 yymsg_alloc = sizeof yymsgbuf;
1745 yysyntax_error_status = 2;
1749 yysyntax_error_status = YYSYNTAX_ERROR;
1754 if (yysyntax_error_status == 2)
1755 goto yyexhaustedlab;
1757 # undef YYSYNTAX_ERROR
1763 if (yyerrstatus == 3)
1765 /* If just tried and failed to reuse lookahead token after an
1766 error, discard it. */
1768 if (yychar <= YYEOF)
1770 /* Return failure if at end of input. */
1771 if (yychar == YYEOF)
1776 yydestruct ("Error: discarding",
1782 /* Else will try to reuse lookahead token after shifting the error
1787 /*---------------------------------------------------.
1788 | yyerrorlab -- error raised explicitly by YYERROR. |
1789 `---------------------------------------------------*/
1792 /* Pacify compilers like GCC when the user code never invokes
1793 YYERROR and the label yyerrorlab therefore never appears in user
1795 if (/*CONSTCOND*/ 0)
1798 /* Do not reclaim the symbols of the rule whose action triggered
1802 YY_STACK_PRINT (yyss, yyssp);
1807 /*-------------------------------------------------------------.
1808 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1809 `-------------------------------------------------------------*/
1811 yyerrstatus = 3; /* Each real token shifted decrements this. */
1815 yyn = yypact[yystate];
1816 if (!yypact_value_is_default (yyn))
1819 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1827 /* Pop the current state because it cannot handle the error token. */
1832 yydestruct ("Error: popping",
1833 yystos[yystate], yyvsp);
1836 YY_STACK_PRINT (yyss, yyssp);
1839 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1841 YY_IGNORE_MAYBE_UNINITIALIZED_END
1844 /* Shift the error token. */
1845 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1851 /*-------------------------------------.
1852 | yyacceptlab -- YYACCEPT comes here. |
1853 `-------------------------------------*/
1858 /*-----------------------------------.
1859 | yyabortlab -- YYABORT comes here. |
1860 `-----------------------------------*/
1865 #if !defined yyoverflow || YYERROR_VERBOSE
1866 /*-------------------------------------------------.
1867 | yyexhaustedlab -- memory exhaustion comes here. |
1868 `-------------------------------------------------*/
1870 yyerror (YY_("memory exhausted"));
1876 if (yychar != YYEMPTY)
1878 /* Make sure we have latest lookahead translation. See comments at
1879 user semantic actions for why this is necessary. */
1880 yytoken = YYTRANSLATE (yychar);
1881 yydestruct ("Cleanup: discarding lookahead",
1884 /* Do not reclaim the symbols of the rule whose action triggered
1885 this YYABORT or YYACCEPT. */
1887 YY_STACK_PRINT (yyss, yyssp);
1888 while (yyssp != yyss)
1890 yydestruct ("Cleanup: popping",
1891 yystos[*yyssp], yyvsp);
1896 YYSTACK_FREE (yyss);
1899 if (yymsg != yymsgbuf)
1900 YYSTACK_FREE (yymsg);
1904 #line 395 "label.y" /* yacc.c:1906 */
1907 /* bison defines const to be empty unless __STDC__ is defined, which it
1908 isn't under cfront */
1914 const char *spec_ptr;
1915 const char *spec_end;
1916 const char *spec_cur;
1918 static char uppercase_array[] = {
1919 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
1920 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
1921 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
1925 static char lowercase_array[] = {
1926 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
1927 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
1928 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
1934 while (spec_ptr < spec_end && csspace(*spec_ptr))
1936 spec_cur = spec_ptr;
1937 if (spec_ptr >= spec_end)
1939 unsigned char c = *spec_ptr++;
1942 return TOKEN_LETTER;
1945 yylval.num = c - '0';
1949 yylval.str.start = literals.length();
1950 for (; spec_ptr < spec_end; spec_ptr++) {
1951 if (*spec_ptr == '\'') {
1952 if (++spec_ptr < spec_end && *spec_ptr == '\'')
1955 yylval.str.len = literals.length() - yylval.str.start;
1956 return TOKEN_LITERAL;
1960 literals += *spec_ptr;
1962 yylval.str.len = literals.length() - yylval.str.start;
1963 return TOKEN_LITERAL;
1968 int set_label_spec(const char *label_spec)
1970 spec_cur = spec_ptr = label_spec;
1971 spec_end = strchr(label_spec, '\0');
1975 delete parsed_label;
1976 parsed_label = parse_result;
1980 int set_date_label_spec(const char *label_spec)
1982 spec_cur = spec_ptr = label_spec;
1983 spec_end = strchr(label_spec, '\0');
1987 delete parsed_date_label;
1988 parsed_date_label = parse_result;
1992 int set_short_label_spec(const char *label_spec)
1994 spec_cur = spec_ptr = label_spec;
1995 spec_end = strchr(label_spec, '\0');
1999 delete parsed_short_label;
2000 parsed_short_label = parse_result;
2004 void yyerror(const char *message)
2006 if (spec_cur < spec_end)
2007 command_error("label specification %1 before `%2'", message, spec_cur);
2009 command_error("label specification %1 at end of string",
2013 void at_expr::evaluate(int tentative, const reference &ref,
2014 string &result, substring_position &)
2017 ref.canonicalize_authors(result);
2019 const char *end, *start = ref.get_authors(&end);
2021 result.append(start, end - start);
2025 void format_expr::evaluate(int tentative, const reference &ref,
2026 string &result, substring_position &)
2030 const label_info *lp = ref.get_label_ptr();
2031 int num = lp == 0 ? ref.get_number() : lp->count;
2033 result += format_serial(type, num + 1);
2035 const char *ptr = i_to_a(num + first_number);
2036 int pad = width - strlen(ptr);
2043 static const char *format_serial(char c, int n)
2046 static char buf[128]; // more than enough.
2052 // troff uses z and w to represent 10000 and 5000 in Roman
2053 // numerals; I can find no historical basis for this usage
2054 const char *s = c == 'i' ? "zwmdclxvi" : "ZWMDCLXVI";
2057 while (n >= 10000) {
2061 for (int i = 1000; i > 0; i /= 10, s += 2) {
2108 // this is derived from troff/reg.c
2115 *p++ = c == 'a' ? lowercase_array[d - 1] :
2116 uppercase_array[d - 1];
2136 void field_expr::evaluate(int, const reference &ref,
2137 string &result, substring_position &)
2140 const char *start = ref.get_field(name, &end);
2142 start = nth_field(number, start, &end);
2144 result.append(start, end - start);
2148 void literal_expr::evaluate(int, const reference &,
2149 string &result, substring_position &)
2154 analyzed_expr::analyzed_expr(expression *e)
2155 : unary_expr(e), flags(e ? e->analyze() : 0)
2159 void analyzed_expr::evaluate(int tentative, const reference &ref,
2160 string &result, substring_position &pos)
2163 expr->evaluate(tentative, ref, result, pos);
2166 void star_expr::evaluate(int tentative, const reference &ref,
2167 string &result, substring_position &pos)
2169 const label_info *lp = ref.get_label_ptr();
2171 && (lp == 0 || lp->total > 1)
2173 expr->evaluate(tentative, ref, result, pos);
2176 void separator_expr::evaluate(int tentative, const reference &ref,
2177 string &result, substring_position &pos)
2179 int start_length = result.length();
2180 int is_first = pos.start < 0;
2182 expr->evaluate(tentative, ref, result, pos);
2184 pos.start = start_length;
2185 pos.length = result.length() - start_length;
2189 void map_expr::evaluate(int tentative, const reference &ref,
2190 string &result, substring_position &)
2194 substring_position temp_pos;
2195 expr->evaluate(tentative, ref, temp, temp_pos);
2196 (*func)(temp.contents(), temp.contents() + temp.length(), result);
2200 void extractor_expr::evaluate(int tentative, const reference &ref,
2201 string &result, substring_position &)
2205 substring_position temp_pos;
2206 expr->evaluate(tentative, ref, temp, temp_pos);
2207 const char *end, *start = (*func)(temp.contents(),
2208 temp.contents() + temp.length(),
2213 result.append(temp.contents(), start - temp.contents());
2219 result.append(start, end - start);
2223 result.append(end, temp.contents() + temp.length() - end);
2231 static void first_part(int len, const char *ptr, const char *end,
2235 const char *token_start = ptr;
2236 if (!get_token(&ptr, end))
2238 const token_info *ti = lookup_token(token_start, ptr);
2239 int counts = ti->sortify_non_empty(token_start, ptr);
2240 if (counts && --len < 0)
2242 if (counts || ti->is_accent())
2243 result.append(token_start, ptr - token_start);
2247 static void last_part(int len, const char *ptr, const char *end,
2250 const char *start = ptr;
2253 const char *token_start = ptr;
2254 if (!get_token(&ptr, end))
2256 const token_info *ti = lookup_token(token_start, ptr);
2257 if (ti->sortify_non_empty(token_start, ptr))
2261 int skip = count - len;
2264 const char *token_start = ptr;
2265 if (!get_token(&ptr, end))
2267 const token_info *ti = lookup_token(token_start, ptr);
2268 if (ti->sortify_non_empty(token_start, ptr) && --skip < 0) {
2274 first_part(len, ptr, end, result);
2277 void truncate_expr::evaluate(int tentative, const reference &ref,
2278 string &result, substring_position &)
2282 substring_position temp_pos;
2283 expr->evaluate(tentative, ref, temp, temp_pos);
2284 const char *start = temp.contents();
2285 const char *end = start + temp.length();
2287 first_part(n, start, end, result);
2289 last_part(-n, start, end, result);
2293 void alternative_expr::evaluate(int tentative, const reference &ref,
2294 string &result, substring_position &pos)
2296 int start_length = result.length();
2298 expr1->evaluate(tentative, ref, result, pos);
2299 if (result.length() == start_length && expr2)
2300 expr2->evaluate(tentative, ref, result, pos);
2303 void list_expr::evaluate(int tentative, const reference &ref,
2304 string &result, substring_position &pos)
2307 expr1->evaluate(tentative, ref, result, pos);
2309 expr2->evaluate(tentative, ref, result, pos);
2312 void substitute_expr::evaluate(int tentative, const reference &ref,
2313 string &result, substring_position &pos)
2315 int start_length = result.length();
2317 expr1->evaluate(tentative, ref, result, pos);
2318 if (result.length() > start_length && result[result.length() - 1] == '-') {
2319 // ought to see if pos covers the -
2320 result.set_length(result.length() - 1);
2322 expr2->evaluate(tentative, ref, result, pos);
2326 void conditional_expr::evaluate(int tentative, const reference &ref,
2327 string &result, substring_position &pos)
2330 substring_position temp_pos;
2332 expr1->evaluate(tentative, ref, temp, temp_pos);
2333 if (temp.length() > 0) {
2335 expr2->evaluate(tentative, ref, result, pos);
2339 expr3->evaluate(tentative, ref, result, pos);
2343 void reference::pre_compute_label()
2345 if (parsed_label != 0
2346 && (parsed_label->analyze() & expression::CONTAINS_VARIABLE)) {
2348 substring_position temp_pos;
2349 parsed_label->evaluate(1, *this, label, temp_pos);
2350 label_ptr = lookup_label(label);
2354 void reference::compute_label()
2358 parsed_label->evaluate(0, *this, label, separator_pos);
2359 if (short_label_flag && parsed_short_label)
2360 parsed_short_label->evaluate(0, *this, short_label, short_separator_pos);
2361 if (date_as_label) {
2363 if (parsed_date_label) {
2364 substring_position temp_pos;
2365 parsed_date_label->evaluate(0, *this, new_date, temp_pos);
2370 label_ptr->count += 1;
2373 void reference::immediate_compute_label()
2376 label_ptr->total = 2; // force use of disambiguator
2380 int reference::merge_labels(reference **v, int n, label_type type,
2383 if (abbreviate_label_ranges)
2384 return merge_labels_by_number(v, n, type, result);
2386 return merge_labels_by_parts(v, n, type, result);
2389 int reference::merge_labels_by_number(reference **v, int n, label_type type,
2394 int num = get_number();
2395 // Only merge three or more labels.
2396 if (v[0]->get_number() != num + 1
2397 || v[1]->get_number() != num + 2)
2400 for (i = 2; i < n; i++)
2401 if (v[i]->get_number() != num + i + 1)
2403 result = get_label(type);
2404 result += label_range_indicator;
2405 result += v[i - 1]->get_label(type);
2409 const substring_position &reference::get_separator_pos(label_type type) const
2411 if (type == SHORT_LABEL && short_label_flag)
2412 return short_separator_pos;
2414 return separator_pos;
2417 const string &reference::get_label(label_type type) const
2419 if (type == SHORT_LABEL && short_label_flag)
2425 int reference::merge_labels_by_parts(reference **v, int n, label_type type,
2430 const string &lb = get_label(type);
2431 const substring_position &sp = get_separator_pos(type);
2433 || sp.start != v[0]->get_separator_pos(type).start
2434 || memcmp(lb.contents(), v[0]->get_label(type).contents(),
2440 result += separate_label_second_parts;
2441 const substring_position &s = v[i]->get_separator_pos(type);
2442 int sep_end_pos = s.start + s.length;
2443 result.append(v[i]->get_label(type).contents() + sep_end_pos,
2444 v[i]->get_label(type).length() - sep_end_pos);
2446 && sp.start == v[i]->get_separator_pos(type).start
2447 && memcmp(lb.contents(), v[i]->get_label(type).contents(),
2454 label_info::label_info(const string &s)
2455 : start(label_pool.length()), length(s.length()), count(0), total(1)
2460 static label_info **label_table = 0;
2461 static int label_table_size = 0;
2462 static int label_table_used = 0;
2464 label_info *lookup_label(const string &label)
2466 if (label_table == 0) {
2467 label_table = new label_info *[17];
2468 label_table_size = 17;
2469 for (int i = 0; i < 17; i++)
2472 unsigned h = hash_string(label.contents(), label.length()) % label_table_size;
2474 for (ptr = label_table + h;
2476 (ptr == label_table)
2477 ? (ptr = label_table + label_table_size - 1)
2479 if ((*ptr)->length == label.length()
2480 && memcmp(label_pool.contents() + (*ptr)->start, label.contents(),
2481 label.length()) == 0) {
2485 label_info *result = *ptr = new label_info(label);
2486 if (++label_table_used * 2 > label_table_size) {
2487 // Rehash the table.
2488 label_info **old_table = label_table;
2489 int old_size = label_table_size;
2490 label_table_size = next_size(label_table_size);
2491 label_table = new label_info *[label_table_size];
2493 for (i = 0; i < label_table_size; i++)
2495 for (i = 0; i < old_size; i++)
2497 h = hash_string(label_pool.contents() + old_table[i]->start,
2498 old_table[i]->length);
2500 for (p = label_table + (h % label_table_size);
2503 ? (p = label_table + label_table_size - 1)
2515 for (int i = 0; i < label_table_size; i++) {
2516 delete label_table[i];
2519 label_table_used = 0;
2523 static void consider_authors(reference **start, reference **end, int i);
2525 void compute_labels(reference **v, int n)
2528 && (parsed_label->analyze() & expression::CONTAINS_AT)
2529 && sort_fields.length() >= 2
2530 && sort_fields[0] == 'A'
2531 && sort_fields[1] == '+')
2532 consider_authors(v, v + n, 0);
2533 for (int i = 0; i < n; i++)
2534 v[i]->compute_label();
2538 /* A reference with a list of authors <A0,A1,...,AN> _needs_ author i
2539 where 0 <= i <= N if there exists a reference with a list of authors
2540 <B0,B1,...,BM> such that <A0,A1,...,AN> != <B0,B1,...,BM> and M >= i
2541 and Aj = Bj for 0 <= j < i. In this case if we can't say ``A0,
2542 A1,...,A(i-1) et al'' because this would match both <A0,A1,...,AN> and
2543 <B0,B1,...,BM>. If a reference needs author i we only have to call
2544 need_author(j) for some j >= i such that the reference also needs
2547 /* This function handles 2 tasks:
2548 determine which authors are needed (cannot be elided with et al.);
2549 determine which authors can have only last names in the labels.
2551 References >= start and < end have the same first i author names.
2552 Also they're sorted by A+. */
2554 static void consider_authors(reference **start, reference **end, int i)
2558 reference **p = start;
2559 if (i >= (*p)->get_nauthors()) {
2560 for (++p; p < end && i >= (*p)->get_nauthors(); p++)
2562 if (p < end && i > 0) {
2563 // If we have an author list <A B C> and an author list <A B C D>,
2564 // then both lists need C.
2565 for (reference **q = start; q < end; q++)
2566 (*q)->need_author(i - 1);
2571 reference **last_name_start = p;
2572 reference **name_start = p;
2574 p < end && i < (*p)->get_nauthors()
2575 && same_author_last_name(**last_name_start, **p, i);
2577 if (!same_author_name(**name_start, **p, i)) {
2578 consider_authors(name_start, p, i + 1);
2582 consider_authors(name_start, p, i + 1);
2583 if (last_name_start == name_start) {
2584 for (reference **q = last_name_start; q < p; q++)
2585 (*q)->set_last_name_unambiguous(i);
2587 // If we have an author list <A B C D> and <A B C E>, then the lists
2588 // need author D and E respectively.
2589 if (name_start > start || p < end) {
2590 for (reference **q = last_name_start; q < p; q++)
2591 (*q)->need_author(i);
2596 int same_author_last_name(const reference &r1, const reference &r2, int n)
2599 const char *as1 = r1.get_sort_field(0, n, 0, &ae1);
2601 const char *as2 = r2.get_sort_field(0, n, 0, &ae2);
2602 if (!as1 && !as2) return 1; // they are the same
2603 if (!as1 || !as2) return 0;
2604 return ae1 - as1 == ae2 - as2 && memcmp(as1, as2, ae1 - as1) == 0;
2607 int same_author_name(const reference &r1, const reference &r2, int n)
2610 const char *as1 = r1.get_sort_field(0, n, -1, &ae1);
2612 const char *as2 = r2.get_sort_field(0, n, -1, &ae2);
2613 if (!as1 && !as2) return 1; // they are the same
2614 if (!as1 || !as2) return 0;
2615 return ae1 - as1 == ae2 - as2 && memcmp(as1, as2, ae1 - as1) == 0;
2619 void int_set::set(int i)
2623 if (bytei >= v.length()) {
2624 int old_length = v.length();
2625 v.set_length(bytei + 1);
2626 for (int j = old_length; j <= bytei; j++)
2629 v[bytei] |= 1 << (i & 7);
2632 int int_set::get(int i) const
2636 return bytei >= v.length() ? 0 : (v[bytei] & (1 << (i & 7))) != 0;
2639 void reference::set_last_name_unambiguous(int i)
2641 last_name_unambiguous.set(i);
2644 void reference::need_author(int n)
2646 if (n > last_needed_author)
2647 last_needed_author = n;
2650 const char *reference::get_authors(const char **end) const
2652 if (!computed_authors) {
2653 ((reference *)this)->computed_authors = 1;
2654 string &result = ((reference *)this)->authors;
2655 int na = get_nauthors();
2657 for (int i = 0; i < na; i++) {
2658 if (last_name_unambiguous.get(i)) {
2659 const char *e, *start = get_author_last_name(i, &e);
2661 result.append(start, e - start);
2664 const char *e, *start = get_author(i, &e);
2666 result.append(start, e - start);
2668 if (i == last_needed_author
2669 && et_al.length() > 0
2670 && et_al_min_elide > 0
2671 && last_needed_author + et_al_min_elide < na
2672 && na >= et_al_min_total) {
2678 result += join_authors_exactly_two;
2679 else if (i < na - 2)
2680 result += join_authors_default;
2682 result += join_authors_last_two;
2686 const char *start = authors.contents();
2687 *end = start + authors.length();
2691 int reference::get_nauthors() const
2696 for (na = 0; get_author(na, &dummy) != 0; na++)
2698 ((reference *)this)->nauthors = na;