Imported Upstream version 1.22.4
[platform/upstream/groff.git] / src / preproc / refer / label.cpp
1 /* A Bison parser, made by GNU Bison 3.2.  */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5    Copyright (C) 1984, 1989-1990, 2000-2015, 2018 Free Software Foundation, Inc.
6
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.
11
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.
16
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/>.  */
19
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.
29
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35
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.  */
42
43 /* Undocumented macros, especially those whose name start with YY_,
44    are private implementation details.  Do not rely on them.  */
45
46 /* Identify Bison output.  */
47 #define YYBISON 1
48
49 /* Bison version.  */
50 #define YYBISON_VERSION "3.2"
51
52 /* Skeleton name.  */
53 #define YYSKELETON_NAME "yacc.c"
54
55 /* Pure parsers.  */
56 #define YYPURE 0
57
58 /* Push parsers.  */
59 #define YYPUSH 0
60
61 /* Pull parsers.  */
62 #define YYPULL 1
63
64
65
66
67 /* First part of user prologue.  */
68 #line 20 "../src/preproc/refer/label.ypp" /* yacc.c:338  */
69
70
71 #include "refer.h"
72 #include "refid.h"
73 #include "ref.h"
74 #include "token.h"
75
76 int yylex();
77 void yyerror(const char *);
78 int yyparse();
79
80 static const char *format_serial(char c, int n);
81
82 struct label_info {
83   int start;
84   int length;
85   int count;
86   int total;
87   label_info(const string &);
88 };
89
90 label_info *lookup_label(const string &label);
91
92 struct expression {
93   enum {
94     // Does the tentative label depend on the reference?
95     CONTAINS_VARIABLE = 01, 
96     CONTAINS_STAR = 02,
97     CONTAINS_FORMAT = 04,
98     CONTAINS_AT = 010
99   };
100   virtual ~expression() { }
101   virtual void evaluate(int, const reference &, string &,
102                         substring_position &) = 0;
103   virtual unsigned analyze() { return 0; }
104 };
105
106 class at_expr : public expression {
107 public:
108   at_expr() { }
109   void evaluate(int, const reference &, string &, substring_position &);
110   unsigned analyze() { return CONTAINS_VARIABLE|CONTAINS_AT; }
111 };
112
113 class format_expr : public expression {
114   char type;
115   int width;
116   int first_number;
117 public:
118   format_expr(char c, int w = 0, int f = 1)
119     : type(c), width(w), first_number(f) { }
120   void evaluate(int, const reference &, string &, substring_position &);
121   unsigned analyze() { return CONTAINS_FORMAT; }
122 };
123
124 class field_expr : public expression {
125   int number;
126   char name;
127 public:
128   field_expr(char nm, int num) : number(num), name(nm) { }
129   void evaluate(int, const reference &, string &, substring_position &);
130   unsigned analyze() { return CONTAINS_VARIABLE; }
131 };
132
133 class literal_expr : public expression {
134   string s;
135 public:
136   literal_expr(const char *ptr, int len) : s(ptr, len) { }
137   void evaluate(int, const reference &, string &, substring_position &);
138 };
139
140 class unary_expr : public expression {
141 protected:
142   expression *expr;
143 public:
144   unary_expr(expression *e) : expr(e) { }
145   ~unary_expr() { delete expr; }
146   void evaluate(int, const reference &, string &, substring_position &) = 0;
147   unsigned analyze() { return expr ? expr->analyze() : 0; }
148 };
149
150 // This caches the analysis of an expression.
151
152 class analyzed_expr : public unary_expr {
153   unsigned flags;
154 public:
155   analyzed_expr(expression *);
156   void evaluate(int, const reference &, string &, substring_position &);
157   unsigned analyze() { return flags; }
158 };
159
160 class star_expr : public unary_expr {
161 public:
162   star_expr(expression *e) : unary_expr(e) { }
163   void evaluate(int, const reference &, string &, substring_position &);
164   unsigned analyze() {
165     return ((expr ? (expr->analyze() & ~CONTAINS_VARIABLE) : 0)
166             | CONTAINS_STAR);
167   }
168 };
169
170 typedef void map_func(const char *, const char *, string &);
171
172 class map_expr : public unary_expr {
173   map_func *func;
174 public:
175   map_expr(expression *e, map_func *f) : unary_expr(e), func(f) { }
176   void evaluate(int, const reference &, string &, substring_position &);
177 };
178   
179 typedef const char *extractor_func(const char *, const char *, const char **);
180
181 class extractor_expr : public unary_expr {
182   int part;
183   extractor_func *func;
184 public:
185   enum { BEFORE = +1, MATCH = 0, AFTER = -1 };
186   extractor_expr(expression *e, extractor_func *f, int pt)
187     : unary_expr(e), part(pt), func(f) { }
188   void evaluate(int, const reference &, string &, substring_position &);
189 };
190
191 class truncate_expr : public unary_expr {
192   int n;
193 public:
194   truncate_expr(expression *e, int i) : unary_expr(e), n(i) { } 
195   void evaluate(int, const reference &, string &, substring_position &);
196 };
197
198 class separator_expr : public unary_expr {
199 public:
200   separator_expr(expression *e) : unary_expr(e) { }
201   void evaluate(int, const reference &, string &, substring_position &);
202 };
203
204 class binary_expr : public expression {
205 protected:
206   expression *expr1;
207   expression *expr2;
208 public:
209   binary_expr(expression *e1, expression *e2) : expr1(e1), expr2(e2) { }
210   ~binary_expr() { delete expr1; delete expr2; }
211   void evaluate(int, const reference &, string &, substring_position &) = 0;
212   unsigned analyze() {
213     return (expr1 ? expr1->analyze() : 0) | (expr2 ? expr2->analyze() : 0);
214   }
215 };
216
217 class alternative_expr : public binary_expr {
218 public:
219   alternative_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }
220   void evaluate(int, const reference &, string &, substring_position &);
221 };
222
223 class list_expr : public binary_expr {
224 public:
225   list_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }
226   void evaluate(int, const reference &, string &, substring_position &);
227 };
228
229 class substitute_expr : public binary_expr {
230 public:
231   substitute_expr(expression *e1, expression *e2) : binary_expr(e1, e2) { }
232   void evaluate(int, const reference &, string &, substring_position &);
233 };
234
235 class ternary_expr : public expression {
236 protected:
237   expression *expr1;
238   expression *expr2;
239   expression *expr3;
240 public:
241   ternary_expr(expression *e1, expression *e2, expression *e3)
242     : expr1(e1), expr2(e2), expr3(e3) { }
243   ~ternary_expr() { delete expr1; delete expr2; delete expr3; }
244   void evaluate(int, const reference &, string &, substring_position &) = 0;
245   unsigned analyze() {
246     return ((expr1 ? expr1->analyze() : 0)
247             | (expr2 ? expr2->analyze() : 0)
248             | (expr3 ? expr3->analyze() : 0));
249   }
250 };
251
252 class conditional_expr : public ternary_expr {
253 public:
254   conditional_expr(expression *e1, expression *e2, expression *e3)
255     : ternary_expr(e1, e2, e3) { }
256   void evaluate(int, const reference &, string &, substring_position &);
257 };
258
259 static expression *parsed_label = 0;
260 static expression *parsed_date_label = 0;
261 static expression *parsed_short_label = 0;
262
263 static expression *parse_result;
264
265 string literals;
266
267
268 #line 269 "src/preproc/refer/label.cpp" /* yacc.c:338  */
269 # ifndef YY_NULLPTR
270 #  if defined __cplusplus
271 #   if 201103L <= __cplusplus
272 #    define YY_NULLPTR nullptr
273 #   else
274 #    define YY_NULLPTR 0
275 #   endif
276 #  else
277 #   define YY_NULLPTR ((void*)0)
278 #  endif
279 # endif
280
281 /* Enabling verbose error messages.  */
282 #ifdef YYERROR_VERBOSE
283 # undef YYERROR_VERBOSE
284 # define YYERROR_VERBOSE 1
285 #else
286 # define YYERROR_VERBOSE 0
287 #endif
288
289 /* In a future release of Bison, this section will be replaced
290    by #include "y.tab.h".  */
291 #ifndef YY_YY_SRC_PREPROC_REFER_LABEL_HPP_INCLUDED
292 # define YY_YY_SRC_PREPROC_REFER_LABEL_HPP_INCLUDED
293 /* Debug traces.  */
294 #ifndef YYDEBUG
295 # define YYDEBUG 0
296 #endif
297 #if YYDEBUG
298 extern int yydebug;
299 #endif
300
301 /* Token type.  */
302 #ifndef YYTOKENTYPE
303 # define YYTOKENTYPE
304   enum yytokentype
305   {
306     TOKEN_LETTER = 258,
307     TOKEN_LITERAL = 259,
308     TOKEN_DIGIT = 260
309   };
310 #endif
311 /* Tokens.  */
312 #define TOKEN_LETTER 258
313 #define TOKEN_LITERAL 259
314 #define TOKEN_DIGIT 260
315
316 /* Value type.  */
317 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
318
319 union YYSTYPE
320 {
321 #line 220 "../src/preproc/refer/label.ypp" /* yacc.c:353  */
322
323   int num;
324   expression *expr;
325   struct { int ndigits; int val; } dig;
326   struct { int start; int len; } str;
327
328 #line 329 "src/preproc/refer/label.cpp" /* yacc.c:353  */
329 };
330
331 typedef union YYSTYPE YYSTYPE;
332 # define YYSTYPE_IS_TRIVIAL 1
333 # define YYSTYPE_IS_DECLARED 1
334 #endif
335
336
337 extern YYSTYPE yylval;
338
339 int yyparse (void);
340
341 #endif /* !YY_YY_SRC_PREPROC_REFER_LABEL_HPP_INCLUDED  */
342
343
344
345 #ifdef short
346 # undef short
347 #endif
348
349 #ifdef YYTYPE_UINT8
350 typedef YYTYPE_UINT8 yytype_uint8;
351 #else
352 typedef unsigned char yytype_uint8;
353 #endif
354
355 #ifdef YYTYPE_INT8
356 typedef YYTYPE_INT8 yytype_int8;
357 #else
358 typedef signed char yytype_int8;
359 #endif
360
361 #ifdef YYTYPE_UINT16
362 typedef YYTYPE_UINT16 yytype_uint16;
363 #else
364 typedef unsigned short yytype_uint16;
365 #endif
366
367 #ifdef YYTYPE_INT16
368 typedef YYTYPE_INT16 yytype_int16;
369 #else
370 typedef short yytype_int16;
371 #endif
372
373 #ifndef YYSIZE_T
374 # ifdef __SIZE_TYPE__
375 #  define YYSIZE_T __SIZE_TYPE__
376 # elif defined size_t
377 #  define YYSIZE_T size_t
378 # elif ! defined YYSIZE_T
379 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
380 #  define YYSIZE_T size_t
381 # else
382 #  define YYSIZE_T unsigned
383 # endif
384 #endif
385
386 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
387
388 #ifndef YY_
389 # if defined YYENABLE_NLS && YYENABLE_NLS
390 #  if ENABLE_NLS
391 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
392 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
393 #  endif
394 # endif
395 # ifndef YY_
396 #  define YY_(Msgid) Msgid
397 # endif
398 #endif
399
400 #ifndef YY_ATTRIBUTE
401 # if (defined __GNUC__                                               \
402       && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
403      || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
404 #  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
405 # else
406 #  define YY_ATTRIBUTE(Spec) /* empty */
407 # endif
408 #endif
409
410 #ifndef YY_ATTRIBUTE_PURE
411 # define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
412 #endif
413
414 #ifndef YY_ATTRIBUTE_UNUSED
415 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
416 #endif
417
418 /* Suppress unused-variable warnings by "using" E.  */
419 #if ! defined lint || defined __GNUC__
420 # define YYUSE(E) ((void) (E))
421 #else
422 # define YYUSE(E) /* empty */
423 #endif
424
425 #if defined __GNUC__ && ! defined __ICC && 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")
433 #else
434 # define YY_INITIAL_VALUE(Value) Value
435 #endif
436 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
437 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
438 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
439 #endif
440 #ifndef YY_INITIAL_VALUE
441 # define YY_INITIAL_VALUE(Value) /* Nothing. */
442 #endif
443
444
445 #if ! defined yyoverflow || YYERROR_VERBOSE
446
447 /* The parser invokes alloca or malloc; define the necessary symbols.  */
448
449 # ifdef YYSTACK_USE_ALLOCA
450 #  if YYSTACK_USE_ALLOCA
451 #   ifdef __GNUC__
452 #    define YYSTACK_ALLOC __builtin_alloca
453 #   elif defined __BUILTIN_VA_ARG_INCR
454 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
455 #   elif defined _AIX
456 #    define YYSTACK_ALLOC __alloca
457 #   elif defined _MSC_VER
458 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
459 #    define alloca _alloca
460 #   else
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
467 #     endif
468 #    endif
469 #   endif
470 #  endif
471 # endif
472
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 */
482 #  endif
483 # else
484 #  define YYSTACK_ALLOC YYMALLOC
485 #  define YYSTACK_FREE YYFREE
486 #  ifndef YYSTACK_ALLOC_MAXIMUM
487 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
488 #  endif
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
495 #   endif
496 #  endif
497 #  ifndef YYMALLOC
498 #   define YYMALLOC malloc
499 #   if ! defined malloc && ! defined EXIT_SUCCESS
500 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
501 #   endif
502 #  endif
503 #  ifndef YYFREE
504 #   define YYFREE free
505 #   if ! defined free && ! defined EXIT_SUCCESS
506 void free (void *); /* INFRINGES ON USER NAME SPACE */
507 #   endif
508 #  endif
509 # endif
510 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
511
512
513 #if (! defined yyoverflow \
514      && (! defined __cplusplus \
515          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
516
517 /* A type that is properly aligned for any stack member.  */
518 union yyalloc
519 {
520   yytype_int16 yyss_alloc;
521   YYSTYPE yyvs_alloc;
522 };
523
524 /* The size of the maximum gap between one aligned stack and the next.  */
525 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
526
527 /* The size of an array large to enough to hold all stacks, each with
528    N elements.  */
529 # define YYSTACK_BYTES(N) \
530      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
531       + YYSTACK_GAP_MAXIMUM)
532
533 # define YYCOPY_NEEDED 1
534
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
539    stack.  */
540 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
541     do                                                                  \
542       {                                                                 \
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);                          \
548       }                                                                 \
549     while (0)
550
551 #endif
552
553 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
554 /* Copy COUNT objects from SRC to DST.  The source and destination do
555    not overlap.  */
556 # ifndef YYCOPY
557 #  if defined __GNUC__ && 1 < __GNUC__
558 #   define YYCOPY(Dst, Src, Count) \
559       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
560 #  else
561 #   define YYCOPY(Dst, Src, Count)              \
562       do                                        \
563         {                                       \
564           YYSIZE_T yyi;                         \
565           for (yyi = 0; yyi < (Count); yyi++)   \
566             (Dst)[yyi] = (Src)[yyi];            \
567         }                                       \
568       while (0)
569 #  endif
570 # endif
571 #endif /* !YYCOPY_NEEDED */
572
573 /* YYFINAL -- State number of the termination state.  */
574 #define YYFINAL  21
575 /* YYLAST -- Last index in YYTABLE.  */
576 #define YYLAST   39
577
578 /* YYNTOKENS -- Number of terminals.  */
579 #define YYNTOKENS  21
580 /* YYNNTS -- Number of nonterminals.  */
581 #define YYNNTS  12
582 /* YYNRULES -- Number of rules.  */
583 #define YYNRULES  34
584 /* YYNSTATES -- Number of states.  */
585 #define YYNSTATES  49
586
587 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
588    by yylex, with out-of-bounds checking.  */
589 #define YYUNDEFTOK  2
590 #define YYMAXUTOK   260
591
592 #define YYTRANSLATE(YYX)                                                \
593   ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
594
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[] =
598 {
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,
625        5
626 };
627
628 #if YYDEBUG
629   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
630 static const yytype_uint16 yyrline[] =
631 {
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
636 };
637 #endif
638
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[] =
643 {
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
649 };
650 #endif
651
652 # ifdef YYPRINT
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[] =
656 {
657        0,   256,   257,   258,   259,   260,    63,    58,   124,    38,
658      126,    64,    37,    46,    43,    45,    42,    40,    41,    60,
659       62
660 };
661 # endif
662
663 #define YYPACT_NINF -26
664
665 #define yypact_value_is_default(Yystate) \
666   (!!((Yystate) == (-26)))
667
668 #define YYTABLE_NINF -1
669
670 #define yytable_value_is_error(Yytable_value) \
671   0
672
673   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
674      STATE-NUM.  */
675 static const yytype_int8 yypact[] =
676 {
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
682 };
683
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[] =
688 {
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
694 };
695
696   /* YYPGOTO[NTERM-NUM].  */
697 static const yytype_int8 yypgoto[] =
698 {
699      -26,   -26,    -7,    -4,   -26,    -1,   -11,    13,   -26,   -25,
700      -26,   -26
701 };
702
703   /* YYDEFGOTO[NTERM-NUM].  */
704 static const yytype_int8 yydefgoto[] =
705 {
706       -1,     7,     8,     9,    10,    11,    12,    13,    47,    15,
707       18,    41
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_uint8 yytable[] =
714 {
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
719 };
720
721 static const yytype_int8 yycheck[] =
722 {
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
727 };
728
729   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
730      symbol of state STATE-NUM.  */
731 static const yytype_uint8 yystos[] =
732 {
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
738 };
739
740   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
741 static const yytype_uint8 yyr1[] =
742 {
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,
746       31,    31,    32,    32,    32
747 };
748
749   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
750 static const yytype_uint8 yyr2[] =
751 {
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,
755        1,     2,     0,     1,     1
756 };
757
758
759 #define yyerrok         (yyerrstatus = 0)
760 #define yyclearin       (yychar = YYEMPTY)
761 #define YYEMPTY         (-2)
762 #define YYEOF           0
763
764 #define YYACCEPT        goto yyacceptlab
765 #define YYABORT         goto yyabortlab
766 #define YYERROR         goto yyerrorlab
767
768
769 #define YYRECOVERING()  (!!yyerrstatus)
770
771 #define YYBACKUP(Token, Value)                                  \
772 do                                                              \
773   if (yychar == YYEMPTY)                                        \
774     {                                                           \
775       yychar = (Token);                                         \
776       yylval = (Value);                                         \
777       YYPOPSTACK (yylen);                                       \
778       yystate = *yyssp;                                         \
779       goto yybackup;                                            \
780     }                                                           \
781   else                                                          \
782     {                                                           \
783       yyerror (YY_("syntax error: cannot back up")); \
784       YYERROR;                                                  \
785     }                                                           \
786 while (0)
787
788 /* Error token number */
789 #define YYTERROR        1
790 #define YYERRCODE       256
791
792
793
794 /* Enable debugging if requested.  */
795 #if YYDEBUG
796
797 # ifndef YYFPRINTF
798 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
799 #  define YYFPRINTF fprintf
800 # endif
801
802 # define YYDPRINTF(Args)                        \
803 do {                                            \
804   if (yydebug)                                  \
805     YYFPRINTF Args;                             \
806 } while (0)
807
808 /* This macro is provided for backward compatibility. */
809 #ifndef YY_LOCATION_PRINT
810 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
811 #endif
812
813
814 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
815 do {                                                                      \
816   if (yydebug)                                                            \
817     {                                                                     \
818       YYFPRINTF (stderr, "%s ", Title);                                   \
819       yy_symbol_print (stderr,                                            \
820                   Type, Value); \
821       YYFPRINTF (stderr, "\n");                                           \
822     }                                                                     \
823 } while (0)
824
825
826 /*-----------------------------------.
827 | Print this symbol's value on YYO.  |
828 `-----------------------------------*/
829
830 static void
831 yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
832 {
833   FILE *yyoutput = yyo;
834   YYUSE (yyoutput);
835   if (!yyvaluep)
836     return;
837 # ifdef YYPRINT
838   if (yytype < YYNTOKENS)
839     YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
840 # endif
841   YYUSE (yytype);
842 }
843
844
845 /*---------------------------.
846 | Print this symbol on YYO.  |
847 `---------------------------*/
848
849 static void
850 yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
851 {
852   YYFPRINTF (yyo, "%s %s (",
853              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
854
855   yy_symbol_value_print (yyo, yytype, yyvaluep);
856   YYFPRINTF (yyo, ")");
857 }
858
859 /*------------------------------------------------------------------.
860 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
861 | TOP (included).                                                   |
862 `------------------------------------------------------------------*/
863
864 static void
865 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
866 {
867   YYFPRINTF (stderr, "Stack now");
868   for (; yybottom <= yytop; yybottom++)
869     {
870       int yybot = *yybottom;
871       YYFPRINTF (stderr, " %d", yybot);
872     }
873   YYFPRINTF (stderr, "\n");
874 }
875
876 # define YY_STACK_PRINT(Bottom, Top)                            \
877 do {                                                            \
878   if (yydebug)                                                  \
879     yy_stack_print ((Bottom), (Top));                           \
880 } while (0)
881
882
883 /*------------------------------------------------.
884 | Report that the YYRULE is going to be reduced.  |
885 `------------------------------------------------*/
886
887 static void
888 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
889 {
890   unsigned long yylno = yyrline[yyrule];
891   int yynrhs = yyr2[yyrule];
892   int yyi;
893   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
894              yyrule - 1, yylno);
895   /* The symbols being reduced.  */
896   for (yyi = 0; yyi < yynrhs; yyi++)
897     {
898       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
899       yy_symbol_print (stderr,
900                        yystos[yyssp[yyi + 1 - yynrhs]],
901                        &(yyvsp[(yyi + 1) - (yynrhs)])
902                                               );
903       YYFPRINTF (stderr, "\n");
904     }
905 }
906
907 # define YY_REDUCE_PRINT(Rule)          \
908 do {                                    \
909   if (yydebug)                          \
910     yy_reduce_print (yyssp, yyvsp, Rule); \
911 } while (0)
912
913 /* Nonzero means print parse trace.  It is left uninitialized so that
914    multiple parsers can coexist.  */
915 int yydebug;
916 #else /* !YYDEBUG */
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 */
922
923
924 /* YYINITDEPTH -- initial size of the parser's stacks.  */
925 #ifndef YYINITDEPTH
926 # define YYINITDEPTH 200
927 #endif
928
929 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
930    if the built-in stack extension method is used).
931
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.  */
935
936 #ifndef YYMAXDEPTH
937 # define YYMAXDEPTH 10000
938 #endif
939
940
941 #if YYERROR_VERBOSE
942
943 # ifndef yystrlen
944 #  if defined __GLIBC__ && defined _STRING_H
945 #   define yystrlen strlen
946 #  else
947 /* Return the length of YYSTR.  */
948 static YYSIZE_T
949 yystrlen (const char *yystr)
950 {
951   YYSIZE_T yylen;
952   for (yylen = 0; yystr[yylen]; yylen++)
953     continue;
954   return yylen;
955 }
956 #  endif
957 # endif
958
959 # ifndef yystpcpy
960 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
961 #   define yystpcpy stpcpy
962 #  else
963 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
964    YYDEST.  */
965 static char *
966 yystpcpy (char *yydest, const char *yysrc)
967 {
968   char *yyd = yydest;
969   const char *yys = yysrc;
970
971   while ((*yyd++ = *yys++) != '\0')
972     continue;
973
974   return yyd - 1;
975 }
976 #  endif
977 # endif
978
979 # ifndef yytnamerr
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
986    would have been.  */
987 static YYSIZE_T
988 yytnamerr (char *yyres, const char *yystr)
989 {
990   if (*yystr == '"')
991     {
992       YYSIZE_T yyn = 0;
993       char const *yyp = yystr;
994
995       for (;;)
996         switch (*++yyp)
997           {
998           case '\'':
999           case ',':
1000             goto do_not_strip_quotes;
1001
1002           case '\\':
1003             if (*++yyp != '\\')
1004               goto do_not_strip_quotes;
1005             /* Fall through.  */
1006           default:
1007             if (yyres)
1008               yyres[yyn] = *yyp;
1009             yyn++;
1010             break;
1011
1012           case '"':
1013             if (yyres)
1014               yyres[yyn] = '\0';
1015             return yyn;
1016           }
1017     do_not_strip_quotes: ;
1018     }
1019
1020   if (! yyres)
1021     return yystrlen (yystr);
1022
1023   return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres);
1024 }
1025 # endif
1026
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
1029    YYSSP.
1030
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.  */
1035 static int
1036 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1037                 yytype_int16 *yyssp, int yytoken)
1038 {
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
1047      "expected"). */
1048   int yycount = 0;
1049
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.
1072   */
1073   if (yytoken != YYEMPTY)
1074     {
1075       int yyn = yypact[*yyssp];
1076       yyarg[yycount++] = yytname[yytoken];
1077       if (!yypact_value_is_default (yyn))
1078         {
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;
1086           int yyx;
1087
1088           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1089             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1090                 && !yytable_value_is_error (yytable[yyx + yyn]))
1091               {
1092                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1093                   {
1094                     yycount = 1;
1095                     yysize = yysize0;
1096                     break;
1097                   }
1098                 yyarg[yycount++] = yytname[yyx];
1099                 {
1100                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1101                   if (! (yysize <= yysize1
1102                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1103                     return 2;
1104                   yysize = yysize1;
1105                 }
1106               }
1107         }
1108     }
1109
1110   switch (yycount)
1111     {
1112 # define YYCASE_(N, S)                      \
1113       case N:                               \
1114         yyformat = S;                       \
1115       break
1116     default: /* Avoid compiler warnings. */
1117       YYCASE_(0, YY_("syntax error"));
1118       YYCASE_(1, YY_("syntax error, unexpected %s"));
1119       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1120       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1121       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1122       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1123 # undef YYCASE_
1124     }
1125
1126   {
1127     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1128     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1129       return 2;
1130     yysize = yysize1;
1131   }
1132
1133   if (*yymsg_alloc < yysize)
1134     {
1135       *yymsg_alloc = 2 * yysize;
1136       if (! (yysize <= *yymsg_alloc
1137              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1138         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1139       return 1;
1140     }
1141
1142   /* Avoid sprintf, as that infringes on the user's name space.
1143      Don't have undefined behavior even if the translation
1144      produced a string with the wrong number of "%s"s.  */
1145   {
1146     char *yyp = *yymsg;
1147     int yyi = 0;
1148     while ((*yyp = *yyformat) != '\0')
1149       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1150         {
1151           yyp += yytnamerr (yyp, yyarg[yyi++]);
1152           yyformat += 2;
1153         }
1154       else
1155         {
1156           yyp++;
1157           yyformat++;
1158         }
1159   }
1160   return 0;
1161 }
1162 #endif /* YYERROR_VERBOSE */
1163
1164 /*-----------------------------------------------.
1165 | Release the memory associated to this symbol.  |
1166 `-----------------------------------------------*/
1167
1168 static void
1169 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1170 {
1171   YYUSE (yyvaluep);
1172   if (!yymsg)
1173     yymsg = "Deleting";
1174   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1175
1176   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1177   YYUSE (yytype);
1178   YY_IGNORE_MAYBE_UNINITIALIZED_END
1179 }
1180
1181
1182
1183
1184 /* The lookahead symbol.  */
1185 int yychar;
1186
1187 /* The semantic value of the lookahead symbol.  */
1188 YYSTYPE yylval;
1189 /* Number of syntax errors so far.  */
1190 int yynerrs;
1191
1192
1193 /*----------.
1194 | yyparse.  |
1195 `----------*/
1196
1197 int
1198 yyparse (void)
1199 {
1200     int yystate;
1201     /* Number of tokens to shift before error messages enabled.  */
1202     int yyerrstatus;
1203
1204     /* The stacks and their tools:
1205        'yyss': related to states.
1206        'yyvs': related to semantic values.
1207
1208        Refer to the stacks through separate pointers, to allow yyoverflow
1209        to reallocate them elsewhere.  */
1210
1211     /* The state stack.  */
1212     yytype_int16 yyssa[YYINITDEPTH];
1213     yytype_int16 *yyss;
1214     yytype_int16 *yyssp;
1215
1216     /* The semantic value stack.  */
1217     YYSTYPE yyvsa[YYINITDEPTH];
1218     YYSTYPE *yyvs;
1219     YYSTYPE *yyvsp;
1220
1221     YYSIZE_T yystacksize;
1222
1223   int yyn;
1224   int yyresult;
1225   /* Lookahead token as an internal (translated) token number.  */
1226   int yytoken = 0;
1227   /* The variables used to return semantic value and location from the
1228      action routines.  */
1229   YYSTYPE yyval;
1230
1231 #if YYERROR_VERBOSE
1232   /* Buffer for error messages, and its allocated size.  */
1233   char yymsgbuf[128];
1234   char *yymsg = yymsgbuf;
1235   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1236 #endif
1237
1238 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1239
1240   /* The number of symbols on the RHS of the reduced rule.
1241      Keep to zero when no symbol should be popped.  */
1242   int yylen = 0;
1243
1244   yyssp = yyss = yyssa;
1245   yyvsp = yyvs = yyvsa;
1246   yystacksize = YYINITDEPTH;
1247
1248   YYDPRINTF ((stderr, "Starting parse\n"));
1249
1250   yystate = 0;
1251   yyerrstatus = 0;
1252   yynerrs = 0;
1253   yychar = YYEMPTY; /* Cause a token to be read.  */
1254   goto yysetstate;
1255
1256 /*------------------------------------------------------------.
1257 | yynewstate -- Push a new state, which is found in yystate.  |
1258 `------------------------------------------------------------*/
1259  yynewstate:
1260   /* In all cases, when you get here, the value and location stacks
1261      have just been pushed.  So pushing a state here evens the stacks.  */
1262   yyssp++;
1263
1264  yysetstate:
1265   *yyssp = (yytype_int16) yystate;
1266
1267   if (yyss + yystacksize - 1 <= yyssp)
1268     {
1269       /* Get the current used size of the three stacks, in elements.  */
1270       YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1);
1271
1272 #ifdef yyoverflow
1273       {
1274         /* Give user a chance to reallocate the stack.  Use copies of
1275            these so that the &'s don't force the real ones into
1276            memory.  */
1277         YYSTYPE *yyvs1 = yyvs;
1278         yytype_int16 *yyss1 = yyss;
1279
1280         /* Each stack pointer address is followed by the size of the
1281            data in use in that stack, in bytes.  This used to be a
1282            conditional around just the two extra args, but that might
1283            be undefined if yyoverflow is a macro.  */
1284         yyoverflow (YY_("memory exhausted"),
1285                     &yyss1, yysize * sizeof (*yyssp),
1286                     &yyvs1, yysize * sizeof (*yyvsp),
1287                     &yystacksize);
1288         yyss = yyss1;
1289         yyvs = yyvs1;
1290       }
1291 #else /* no yyoverflow */
1292 # ifndef YYSTACK_RELOCATE
1293       goto yyexhaustedlab;
1294 # else
1295       /* Extend the stack our own way.  */
1296       if (YYMAXDEPTH <= yystacksize)
1297         goto yyexhaustedlab;
1298       yystacksize *= 2;
1299       if (YYMAXDEPTH < yystacksize)
1300         yystacksize = YYMAXDEPTH;
1301
1302       {
1303         yytype_int16 *yyss1 = yyss;
1304         union yyalloc *yyptr =
1305           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1306         if (! yyptr)
1307           goto yyexhaustedlab;
1308         YYSTACK_RELOCATE (yyss_alloc, yyss);
1309         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1310 #  undef YYSTACK_RELOCATE
1311         if (yyss1 != yyssa)
1312           YYSTACK_FREE (yyss1);
1313       }
1314 # endif
1315 #endif /* no yyoverflow */
1316
1317       yyssp = yyss + yysize - 1;
1318       yyvsp = yyvs + yysize - 1;
1319
1320       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1321                   (unsigned long) yystacksize));
1322
1323       if (yyss + yystacksize - 1 <= yyssp)
1324         YYABORT;
1325     }
1326
1327   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1328
1329   if (yystate == YYFINAL)
1330     YYACCEPT;
1331
1332   goto yybackup;
1333
1334 /*-----------.
1335 | yybackup.  |
1336 `-----------*/
1337 yybackup:
1338
1339   /* Do appropriate processing given the current state.  Read a
1340      lookahead token if we need one and don't already have one.  */
1341
1342   /* First try to decide what to do without reference to lookahead token.  */
1343   yyn = yypact[yystate];
1344   if (yypact_value_is_default (yyn))
1345     goto yydefault;
1346
1347   /* Not known => get a lookahead token if don't already have one.  */
1348
1349   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1350   if (yychar == YYEMPTY)
1351     {
1352       YYDPRINTF ((stderr, "Reading a token: "));
1353       yychar = yylex ();
1354     }
1355
1356   if (yychar <= YYEOF)
1357     {
1358       yychar = yytoken = YYEOF;
1359       YYDPRINTF ((stderr, "Now at end of input.\n"));
1360     }
1361   else
1362     {
1363       yytoken = YYTRANSLATE (yychar);
1364       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1365     }
1366
1367   /* If the proper action on seeing token YYTOKEN is to reduce or to
1368      detect an error, take that action.  */
1369   yyn += yytoken;
1370   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1371     goto yydefault;
1372   yyn = yytable[yyn];
1373   if (yyn <= 0)
1374     {
1375       if (yytable_value_is_error (yyn))
1376         goto yyerrlab;
1377       yyn = -yyn;
1378       goto yyreduce;
1379     }
1380
1381   /* Count tokens shifted since error; after three, turn off error
1382      status.  */
1383   if (yyerrstatus)
1384     yyerrstatus--;
1385
1386   /* Shift the lookahead token.  */
1387   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1388
1389   /* Discard the shifted token.  */
1390   yychar = YYEMPTY;
1391
1392   yystate = yyn;
1393   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1394   *++yyvsp = yylval;
1395   YY_IGNORE_MAYBE_UNINITIALIZED_END
1396
1397   goto yynewstate;
1398
1399
1400 /*-----------------------------------------------------------.
1401 | yydefault -- do the default action for the current state.  |
1402 `-----------------------------------------------------------*/
1403 yydefault:
1404   yyn = yydefact[yystate];
1405   if (yyn == 0)
1406     goto yyerrlab;
1407   goto yyreduce;
1408
1409
1410 /*-----------------------------.
1411 | yyreduce -- Do a reduction.  |
1412 `-----------------------------*/
1413 yyreduce:
1414   /* yyn is the number of a rule to reduce with.  */
1415   yylen = yyr2[yyn];
1416
1417   /* If YYLEN is nonzero, implement the default value of the action:
1418      '$$ = $1'.
1419
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];
1426
1427
1428   YY_REDUCE_PRINT (yyn);
1429   switch (yyn)
1430     {
1431         case 2:
1432 #line 249 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1433     { parse_result = ((yyvsp[0].expr) ? new analyzed_expr((yyvsp[0].expr)) : 0); }
1434 #line 1435 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1435     break;
1436
1437   case 3:
1438 #line 254 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1439     { (yyval.expr) = (yyvsp[0].expr); }
1440 #line 1441 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1441     break;
1442
1443   case 4:
1444 #line 256 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1445     { (yyval.expr) = new conditional_expr((yyvsp[-4].expr), (yyvsp[-2].expr), (yyvsp[0].expr)); }
1446 #line 1447 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1447     break;
1448
1449   case 5:
1450 #line 261 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1451     { (yyval.expr) = 0; }
1452 #line 1453 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1453     break;
1454
1455   case 6:
1456 #line 263 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1457     { (yyval.expr) = (yyvsp[0].expr); }
1458 #line 1459 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1459     break;
1460
1461   case 7:
1462 #line 268 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1463     { (yyval.expr) = (yyvsp[0].expr); }
1464 #line 1465 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1465     break;
1466
1467   case 8:
1468 #line 270 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1469     { (yyval.expr) = new alternative_expr((yyvsp[-2].expr), (yyvsp[0].expr)); }
1470 #line 1471 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1471     break;
1472
1473   case 9:
1474 #line 272 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1475     { (yyval.expr) = new conditional_expr((yyvsp[-2].expr), (yyvsp[0].expr), 0); }
1476 #line 1477 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1477     break;
1478
1479   case 10:
1480 #line 277 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1481     { (yyval.expr) = (yyvsp[0].expr); }
1482 #line 1483 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1483     break;
1484
1485   case 11:
1486 #line 279 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1487     { (yyval.expr) = new list_expr((yyvsp[-1].expr), (yyvsp[0].expr)); }
1488 #line 1489 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1489     break;
1490
1491   case 12:
1492 #line 284 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1493     { (yyval.expr) = (yyvsp[0].expr); }
1494 #line 1495 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1495     break;
1496
1497   case 13:
1498 #line 286 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1499     { (yyval.expr) = new substitute_expr((yyvsp[-2].expr), (yyvsp[0].expr)); }
1500 #line 1501 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1501     break;
1502
1503   case 14:
1504 #line 291 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1505     { (yyval.expr) = new at_expr; }
1506 #line 1507 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1507     break;
1508
1509   case 15:
1510 #line 293 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1511     {
1512                   (yyval.expr) = new literal_expr(literals.contents() + (yyvsp[0].str).start,
1513                                         (yyvsp[0].str).len);
1514                 }
1515 #line 1516 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1516     break;
1517
1518   case 16:
1519 #line 298 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1520     { (yyval.expr) = new field_expr((yyvsp[0].num), 0); }
1521 #line 1522 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1522     break;
1523
1524   case 17:
1525 #line 300 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1526     { (yyval.expr) = new field_expr((yyvsp[-1].num), (yyvsp[0].num) - 1); }
1527 #line 1528 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1528     break;
1529
1530   case 18:
1531 #line 302 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1532     {
1533                   switch ((yyvsp[0].num)) {
1534                   case 'I':
1535                   case 'i':
1536                   case 'A':
1537                   case 'a':
1538                     (yyval.expr) = new format_expr((yyvsp[0].num));
1539                     break;
1540                   default:
1541                     command_error("unrecognized format '%1'", char((yyvsp[0].num)));
1542                     (yyval.expr) = new format_expr('a');
1543                     break;
1544                   }
1545                 }
1546 #line 1547 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1547     break;
1548
1549   case 19:
1550 #line 318 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1551     {
1552                   (yyval.expr) = new format_expr('0', (yyvsp[0].dig).ndigits, (yyvsp[0].dig).val);
1553                 }
1554 #line 1555 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1555     break;
1556
1557   case 20:
1558 #line 322 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1559     {
1560                   switch ((yyvsp[-1].num)) {
1561                   case 'l':
1562                     (yyval.expr) = new map_expr((yyvsp[-4].expr), lowercase);
1563                     break;
1564                   case 'u':
1565                     (yyval.expr) = new map_expr((yyvsp[-4].expr), uppercase);
1566                     break;
1567                   case 'c':
1568                     (yyval.expr) = new map_expr((yyvsp[-4].expr), capitalize);
1569                     break;
1570                   case 'r':
1571                     (yyval.expr) = new map_expr((yyvsp[-4].expr), reverse_name);
1572                     break;
1573                   case 'a':
1574                     (yyval.expr) = new map_expr((yyvsp[-4].expr), abbreviate_name);
1575                     break;
1576                   case 'y':
1577                     (yyval.expr) = new extractor_expr((yyvsp[-4].expr), find_year, (yyvsp[-2].num));
1578                     break;
1579                   case 'n':
1580                     (yyval.expr) = new extractor_expr((yyvsp[-4].expr), find_last_name, (yyvsp[-2].num));
1581                     break;
1582                   default:
1583                     (yyval.expr) = (yyvsp[-4].expr);
1584                     command_error("unknown function '%1'", char((yyvsp[-1].num)));
1585                     break;
1586                   }
1587                 }
1588 #line 1589 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1589     break;
1590
1591   case 21:
1592 #line 353 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1593     { (yyval.expr) = new truncate_expr((yyvsp[-2].expr), (yyvsp[0].num)); }
1594 #line 1595 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1595     break;
1596
1597   case 22:
1598 #line 355 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1599     { (yyval.expr) = new truncate_expr((yyvsp[-2].expr), -(yyvsp[0].num)); }
1600 #line 1601 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1601     break;
1602
1603   case 23:
1604 #line 357 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1605     { (yyval.expr) = new star_expr((yyvsp[-1].expr)); }
1606 #line 1607 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1607     break;
1608
1609   case 24:
1610 #line 359 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1611     { (yyval.expr) = (yyvsp[-1].expr); }
1612 #line 1613 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1613     break;
1614
1615   case 25:
1616 #line 361 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1617     { (yyval.expr) = new separator_expr((yyvsp[-1].expr)); }
1618 #line 1619 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1619     break;
1620
1621   case 26:
1622 #line 366 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1623     { (yyval.num) = -1; }
1624 #line 1625 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1625     break;
1626
1627   case 27:
1628 #line 368 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1629     { (yyval.num) = (yyvsp[0].num); }
1630 #line 1631 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1631     break;
1632
1633   case 28:
1634 #line 373 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1635     { (yyval.num) = (yyvsp[0].num); }
1636 #line 1637 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1637     break;
1638
1639   case 29:
1640 #line 375 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1641     { (yyval.num) = (yyvsp[-1].num)*10 + (yyvsp[0].num); }
1642 #line 1643 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1643     break;
1644
1645   case 30:
1646 #line 380 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1647     { (yyval.dig).ndigits = 1; (yyval.dig).val = (yyvsp[0].num); }
1648 #line 1649 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1649     break;
1650
1651   case 31:
1652 #line 382 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1653     { (yyval.dig).ndigits = (yyvsp[-1].dig).ndigits + 1; (yyval.dig).val = (yyvsp[-1].dig).val*10 + (yyvsp[0].num); }
1654 #line 1655 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1655     break;
1656
1657   case 32:
1658 #line 388 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1659     { (yyval.num) = 0; }
1660 #line 1661 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1661     break;
1662
1663   case 33:
1664 #line 390 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1665     { (yyval.num) = 1; }
1666 #line 1667 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1667     break;
1668
1669   case 34:
1670 #line 392 "../src/preproc/refer/label.ypp" /* yacc.c:1645  */
1671     { (yyval.num) = -1; }
1672 #line 1673 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1673     break;
1674
1675
1676 #line 1677 "src/preproc/refer/label.cpp" /* yacc.c:1645  */
1677       default: break;
1678     }
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);
1691
1692   YYPOPSTACK (yylen);
1693   yylen = 0;
1694   YY_STACK_PRINT (yyss, yyssp);
1695
1696   *++yyvsp = yyval;
1697
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.  */
1701   {
1702     const int yylhs = yyr1[yyn] - YYNTOKENS;
1703     const int yyi = yypgoto[yylhs] + *yyssp;
1704     yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1705                ? yytable[yyi]
1706                : yydefgoto[yylhs]);
1707   }
1708
1709   goto yynewstate;
1710
1711
1712 /*--------------------------------------.
1713 | yyerrlab -- here on detecting error.  |
1714 `--------------------------------------*/
1715 yyerrlab:
1716   /* Make sure we have latest lookahead translation.  See comments at
1717      user semantic actions for why this is necessary.  */
1718   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1719
1720   /* If not already recovering from an error, report this error.  */
1721   if (!yyerrstatus)
1722     {
1723       ++yynerrs;
1724 #if ! YYERROR_VERBOSE
1725       yyerror (YY_("syntax error"));
1726 #else
1727 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1728                                         yyssp, yytoken)
1729       {
1730         char const *yymsgp = YY_("syntax error");
1731         int yysyntax_error_status;
1732         yysyntax_error_status = YYSYNTAX_ERROR;
1733         if (yysyntax_error_status == 0)
1734           yymsgp = yymsg;
1735         else if (yysyntax_error_status == 1)
1736           {
1737             if (yymsg != yymsgbuf)
1738               YYSTACK_FREE (yymsg);
1739             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1740             if (!yymsg)
1741               {
1742                 yymsg = yymsgbuf;
1743                 yymsg_alloc = sizeof yymsgbuf;
1744                 yysyntax_error_status = 2;
1745               }
1746             else
1747               {
1748                 yysyntax_error_status = YYSYNTAX_ERROR;
1749                 yymsgp = yymsg;
1750               }
1751           }
1752         yyerror (yymsgp);
1753         if (yysyntax_error_status == 2)
1754           goto yyexhaustedlab;
1755       }
1756 # undef YYSYNTAX_ERROR
1757 #endif
1758     }
1759
1760
1761
1762   if (yyerrstatus == 3)
1763     {
1764       /* If just tried and failed to reuse lookahead token after an
1765          error, discard it.  */
1766
1767       if (yychar <= YYEOF)
1768         {
1769           /* Return failure if at end of input.  */
1770           if (yychar == YYEOF)
1771             YYABORT;
1772         }
1773       else
1774         {
1775           yydestruct ("Error: discarding",
1776                       yytoken, &yylval);
1777           yychar = YYEMPTY;
1778         }
1779     }
1780
1781   /* Else will try to reuse lookahead token after shifting the error
1782      token.  */
1783   goto yyerrlab1;
1784
1785
1786 /*---------------------------------------------------.
1787 | yyerrorlab -- error raised explicitly by YYERROR.  |
1788 `---------------------------------------------------*/
1789 yyerrorlab:
1790
1791   /* Pacify compilers like GCC when the user code never invokes
1792      YYERROR and the label yyerrorlab therefore never appears in user
1793      code.  */
1794   if (/*CONSTCOND*/ 0)
1795      goto yyerrorlab;
1796
1797   /* Do not reclaim the symbols of the rule whose action triggered
1798      this YYERROR.  */
1799   YYPOPSTACK (yylen);
1800   yylen = 0;
1801   YY_STACK_PRINT (yyss, yyssp);
1802   yystate = *yyssp;
1803   goto yyerrlab1;
1804
1805
1806 /*-------------------------------------------------------------.
1807 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1808 `-------------------------------------------------------------*/
1809 yyerrlab1:
1810   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1811
1812   for (;;)
1813     {
1814       yyn = yypact[yystate];
1815       if (!yypact_value_is_default (yyn))
1816         {
1817           yyn += YYTERROR;
1818           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1819             {
1820               yyn = yytable[yyn];
1821               if (0 < yyn)
1822                 break;
1823             }
1824         }
1825
1826       /* Pop the current state because it cannot handle the error token.  */
1827       if (yyssp == yyss)
1828         YYABORT;
1829
1830
1831       yydestruct ("Error: popping",
1832                   yystos[yystate], yyvsp);
1833       YYPOPSTACK (1);
1834       yystate = *yyssp;
1835       YY_STACK_PRINT (yyss, yyssp);
1836     }
1837
1838   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1839   *++yyvsp = yylval;
1840   YY_IGNORE_MAYBE_UNINITIALIZED_END
1841
1842
1843   /* Shift the error token.  */
1844   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1845
1846   yystate = yyn;
1847   goto yynewstate;
1848
1849
1850 /*-------------------------------------.
1851 | yyacceptlab -- YYACCEPT comes here.  |
1852 `-------------------------------------*/
1853 yyacceptlab:
1854   yyresult = 0;
1855   goto yyreturn;
1856
1857 /*-----------------------------------.
1858 | yyabortlab -- YYABORT comes here.  |
1859 `-----------------------------------*/
1860 yyabortlab:
1861   yyresult = 1;
1862   goto yyreturn;
1863
1864 #if !defined yyoverflow || YYERROR_VERBOSE
1865 /*-------------------------------------------------.
1866 | yyexhaustedlab -- memory exhaustion comes here.  |
1867 `-------------------------------------------------*/
1868 yyexhaustedlab:
1869   yyerror (YY_("memory exhausted"));
1870   yyresult = 2;
1871   /* Fall through.  */
1872 #endif
1873
1874 yyreturn:
1875   if (yychar != YYEMPTY)
1876     {
1877       /* Make sure we have latest lookahead translation.  See comments at
1878          user semantic actions for why this is necessary.  */
1879       yytoken = YYTRANSLATE (yychar);
1880       yydestruct ("Cleanup: discarding lookahead",
1881                   yytoken, &yylval);
1882     }
1883   /* Do not reclaim the symbols of the rule whose action triggered
1884      this YYABORT or YYACCEPT.  */
1885   YYPOPSTACK (yylen);
1886   YY_STACK_PRINT (yyss, yyssp);
1887   while (yyssp != yyss)
1888     {
1889       yydestruct ("Cleanup: popping",
1890                   yystos[*yyssp], yyvsp);
1891       YYPOPSTACK (1);
1892     }
1893 #ifndef yyoverflow
1894   if (yyss != yyssa)
1895     YYSTACK_FREE (yyss);
1896 #endif
1897 #if YYERROR_VERBOSE
1898   if (yymsg != yymsgbuf)
1899     YYSTACK_FREE (yymsg);
1900 #endif
1901   return yyresult;
1902 }
1903 #line 395 "../src/preproc/refer/label.ypp" /* yacc.c:1903  */
1904
1905
1906 /* bison defines const to be empty unless __STDC__ is defined, which it
1907 isn't under cfront */
1908
1909 #ifdef const
1910 #undef const
1911 #endif
1912
1913 const char *spec_ptr;
1914 const char *spec_end;
1915 const char *spec_cur;
1916
1917 static char uppercase_array[] = {
1918   'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
1919   'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
1920   'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
1921   'Y', 'Z',
1922 };
1923   
1924 static char lowercase_array[] = {
1925   'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
1926   'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
1927   'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
1928   'y', 'z',
1929 };
1930
1931 int yylex()
1932 {
1933   while (spec_ptr < spec_end && csspace(*spec_ptr))
1934     spec_ptr++;
1935   spec_cur = spec_ptr;
1936   if (spec_ptr >= spec_end)
1937     return 0;
1938   unsigned char c = *spec_ptr++;
1939   if (csalpha(c)) {
1940     yylval.num = c;
1941     return TOKEN_LETTER;
1942   }
1943   if (csdigit(c)) {
1944     yylval.num = c - '0';
1945     return TOKEN_DIGIT;
1946   }
1947   if (c == '\'') {
1948     yylval.str.start = literals.length();
1949     for (; spec_ptr < spec_end; spec_ptr++) {
1950       if (*spec_ptr == '\'') {
1951         if (++spec_ptr < spec_end && *spec_ptr == '\'')
1952           literals += '\'';
1953         else {
1954           yylval.str.len = literals.length() - yylval.str.start;
1955           return TOKEN_LITERAL;
1956         }
1957       }
1958       else
1959         literals += *spec_ptr;
1960     }
1961     yylval.str.len = literals.length() - yylval.str.start;
1962     return TOKEN_LITERAL;
1963   }
1964   return c;
1965 }
1966
1967 int set_label_spec(const char *label_spec)
1968 {
1969   spec_cur = spec_ptr = label_spec;
1970   spec_end = strchr(label_spec, '\0');
1971   literals.clear();
1972   if (yyparse())
1973     return 0;
1974   delete parsed_label;
1975   parsed_label = parse_result;
1976   return 1;
1977 }
1978
1979 int set_date_label_spec(const char *label_spec)
1980 {
1981   spec_cur = spec_ptr = label_spec;
1982   spec_end = strchr(label_spec, '\0');
1983   literals.clear();
1984   if (yyparse())
1985     return 0;
1986   delete parsed_date_label;
1987   parsed_date_label = parse_result;
1988   return 1;
1989 }
1990
1991 int set_short_label_spec(const char *label_spec)
1992 {
1993   spec_cur = spec_ptr = label_spec;
1994   spec_end = strchr(label_spec, '\0');
1995   literals.clear();
1996   if (yyparse())
1997     return 0;
1998   delete parsed_short_label;
1999   parsed_short_label = parse_result;
2000   return 1;
2001 }
2002
2003 void yyerror(const char *message)
2004 {
2005   if (spec_cur < spec_end)
2006     command_error("label specification %1 before '%2'", message, spec_cur);
2007   else
2008     command_error("label specification %1 at end of string",
2009                   message, spec_cur);
2010 }
2011
2012 void at_expr::evaluate(int tentative, const reference &ref,
2013                        string &result, substring_position &)
2014 {
2015   if (tentative)
2016     ref.canonicalize_authors(result);
2017   else {
2018     const char *end, *start = ref.get_authors(&end);
2019     if (start)
2020       result.append(start, end - start);
2021   }
2022 }
2023
2024 void format_expr::evaluate(int tentative, const reference &ref,
2025                            string &result, substring_position &)
2026 {
2027   if (tentative)
2028     return;
2029   const label_info *lp = ref.get_label_ptr();
2030   int num = lp == 0 ? ref.get_number() : lp->count;
2031   if (type != '0')
2032     result += format_serial(type, num + 1);
2033   else {
2034     const char *ptr = i_to_a(num + first_number);
2035     int pad = width - strlen(ptr);
2036     while (--pad >= 0)
2037       result += '0';
2038     result += ptr;
2039   }
2040 }
2041
2042 static const char *format_serial(char c, int n)
2043 {
2044   assert(n > 0);
2045   static char buf[128]; // more than enough.
2046   switch (c) {
2047   case 'i':
2048   case 'I':
2049     {
2050       char *p = buf;
2051       // troff uses z and w to represent 10000 and 5000 in Roman
2052       // numerals; I can find no historical basis for this usage
2053       const char *s = c == 'i' ? "zwmdclxvi" : "ZWMDCLXVI";
2054       if (n >= 40000)
2055         return i_to_a(n);
2056       while (n >= 10000) {
2057         *p++ = s[0];
2058         n -= 10000;
2059       }
2060       for (int i = 1000; i > 0; i /= 10, s += 2) {
2061         int m = n/i;
2062         n -= m*i;
2063         switch (m) {
2064         case 3:
2065           *p++ = s[2];
2066           /* falls through */
2067         case 2:
2068           *p++ = s[2];
2069           /* falls through */
2070         case 1:
2071           *p++ = s[2];
2072           break;
2073         case 4:
2074           *p++ = s[2];
2075           *p++ = s[1];
2076           break;
2077         case 8:
2078           *p++ = s[1];
2079           *p++ = s[2];
2080           *p++ = s[2];
2081           *p++ = s[2];
2082           break;
2083         case 7:
2084           *p++ = s[1];
2085           *p++ = s[2];
2086           *p++ = s[2];
2087           break;
2088         case 6:
2089           *p++ = s[1];
2090           *p++ = s[2];
2091           break;
2092         case 5:
2093           *p++ = s[1];
2094           break;
2095         case 9:
2096           *p++ = s[2];
2097           *p++ = s[0];
2098         }
2099       }
2100       *p = 0;
2101       break;
2102     }
2103   case 'a':
2104   case 'A':
2105     {
2106       char *p = buf;
2107       // this is derived from troff/reg.c
2108       while (n > 0) {
2109         int d = n % 26;
2110         if (d == 0)
2111           d = 26;
2112         n -= d;
2113         n /= 26;
2114         *p++ = c == 'a' ? lowercase_array[d - 1] :
2115                                uppercase_array[d - 1];
2116       }
2117       *p-- = 0;
2118       // Reverse it.
2119       char *q = buf;
2120       while (q < p) {
2121         char temp = *q;
2122         *q = *p;
2123         *p = temp;
2124         --p;
2125         ++q;
2126       }
2127       break;
2128     }
2129   default:
2130     assert(0);
2131   }
2132   return buf;
2133 }
2134
2135 void field_expr::evaluate(int, const reference &ref,
2136                           string &result, substring_position &)
2137 {
2138   const char *end;
2139   const char *start = ref.get_field(name, &end);
2140   if (start) {
2141     start = nth_field(number, start, &end);
2142     if (start)
2143       result.append(start, end - start);
2144   }
2145 }
2146
2147 void literal_expr::evaluate(int, const reference &,
2148                             string &result, substring_position &)
2149 {
2150   result += s;
2151 }
2152
2153 analyzed_expr::analyzed_expr(expression *e)
2154 : unary_expr(e), flags(e ? e->analyze() : 0)
2155 {
2156 }
2157
2158 void analyzed_expr::evaluate(int tentative, const reference &ref,
2159                              string &result, substring_position &pos)
2160 {
2161   if (expr)
2162     expr->evaluate(tentative, ref, result, pos);
2163 }
2164
2165 void star_expr::evaluate(int tentative, const reference &ref,
2166                          string &result, substring_position &pos)
2167 {
2168   const label_info *lp = ref.get_label_ptr();
2169   if (!tentative
2170       && (lp == 0 || lp->total > 1)
2171       && expr)
2172     expr->evaluate(tentative, ref, result, pos);
2173 }
2174
2175 void separator_expr::evaluate(int tentative, const reference &ref,
2176                               string &result, substring_position &pos)
2177 {
2178   int start_length = result.length();
2179   int is_first = pos.start < 0;
2180   if (expr)
2181     expr->evaluate(tentative, ref, result, pos);
2182   if (is_first) {
2183     pos.start = start_length;
2184     pos.length = result.length() - start_length;
2185   }
2186 }
2187
2188 void map_expr::evaluate(int tentative, const reference &ref,
2189                         string &result, substring_position &)
2190 {
2191   if (expr) {
2192     string temp;
2193     substring_position temp_pos;
2194     expr->evaluate(tentative, ref, temp, temp_pos);
2195     (*func)(temp.contents(), temp.contents() + temp.length(), result);
2196   }
2197 }
2198
2199 void extractor_expr::evaluate(int tentative, const reference &ref,
2200                               string &result, substring_position &)
2201 {
2202   if (expr) {
2203     string temp;
2204     substring_position temp_pos;
2205     expr->evaluate(tentative, ref, temp, temp_pos);
2206     const char *end, *start = (*func)(temp.contents(),
2207                                       temp.contents() + temp.length(),
2208                                       &end);
2209     switch (part) {
2210     case BEFORE:
2211       if (start)
2212         result.append(temp.contents(), start - temp.contents());
2213       else
2214         result += temp;
2215       break;
2216     case MATCH:
2217       if (start)
2218         result.append(start, end - start);
2219       break;
2220     case AFTER:
2221       if (start)
2222         result.append(end, temp.contents() + temp.length() - end);
2223       break;
2224     default:
2225       assert(0);
2226     }
2227   }
2228 }
2229
2230 static void first_part(int len, const char *ptr, const char *end,
2231                           string &result)
2232 {
2233   for (;;) {
2234     const char *token_start = ptr;
2235     if (!get_token(&ptr, end))
2236       break;
2237     const token_info *ti = lookup_token(token_start, ptr);
2238     int counts = ti->sortify_non_empty(token_start, ptr);
2239     if (counts && --len < 0)
2240       break;
2241     if (counts || ti->is_accent())
2242       result.append(token_start, ptr - token_start);
2243   }
2244 }
2245
2246 static void last_part(int len, const char *ptr, const char *end,
2247                       string &result)
2248 {
2249   const char *start = ptr;
2250   int count = 0;
2251   for (;;) {
2252     const char *token_start = ptr;
2253     if (!get_token(&ptr, end))
2254       break;
2255     const token_info *ti = lookup_token(token_start, ptr);
2256     if (ti->sortify_non_empty(token_start, ptr))
2257       count++;
2258   }
2259   ptr = start;
2260   int skip = count - len;
2261   if (skip > 0) {
2262     for (;;) {
2263       const char *token_start = ptr;
2264       if (!get_token(&ptr, end))
2265         assert(0);
2266       const token_info *ti = lookup_token(token_start, ptr);
2267       if (ti->sortify_non_empty(token_start, ptr) && --skip < 0) {
2268         ptr = token_start;
2269         break;
2270       }
2271     }
2272   }
2273   first_part(len, ptr, end, result);
2274 }
2275
2276 void truncate_expr::evaluate(int tentative, const reference &ref,
2277                              string &result, substring_position &)
2278 {
2279   if (expr) {
2280     string temp;
2281     substring_position temp_pos;
2282     expr->evaluate(tentative, ref, temp, temp_pos);
2283     const char *start = temp.contents();
2284     const char *end = start + temp.length();
2285     if (n > 0)
2286       first_part(n, start, end, result);
2287     else if (n < 0)
2288       last_part(-n, start, end, result);
2289   }
2290 }
2291
2292 void alternative_expr::evaluate(int tentative, const reference &ref,
2293                                 string &result, substring_position &pos)
2294 {
2295   int start_length = result.length();
2296   if (expr1)
2297     expr1->evaluate(tentative, ref, result, pos);
2298   if (result.length() == start_length && expr2)
2299     expr2->evaluate(tentative, ref, result, pos);
2300 }
2301
2302 void list_expr::evaluate(int tentative, const reference &ref,
2303                          string &result, substring_position &pos)
2304 {
2305   if (expr1)
2306     expr1->evaluate(tentative, ref, result, pos);
2307   if (expr2)
2308     expr2->evaluate(tentative, ref, result, pos);
2309 }
2310
2311 void substitute_expr::evaluate(int tentative, const reference &ref,
2312                                string &result, substring_position &pos)
2313 {
2314   int start_length = result.length();
2315   if (expr1)
2316     expr1->evaluate(tentative, ref, result, pos);
2317   if (result.length() > start_length && result[result.length() - 1] == '-') {
2318     // ought to see if pos covers the -
2319     result.set_length(result.length() - 1);
2320     if (expr2)
2321       expr2->evaluate(tentative, ref, result, pos);
2322   }
2323 }
2324
2325 void conditional_expr::evaluate(int tentative, const reference &ref,
2326                                 string &result, substring_position &pos)
2327 {
2328   string temp;
2329   substring_position temp_pos;
2330   if (expr1)
2331     expr1->evaluate(tentative, ref, temp, temp_pos);
2332   if (temp.length() > 0) {
2333     if (expr2)
2334       expr2->evaluate(tentative, ref, result, pos);
2335   }
2336   else {
2337     if (expr3)
2338       expr3->evaluate(tentative, ref, result, pos);
2339   }
2340 }
2341
2342 void reference::pre_compute_label()
2343 {
2344   if (parsed_label != 0
2345       && (parsed_label->analyze() & expression::CONTAINS_VARIABLE)) {
2346     label.clear();
2347     substring_position temp_pos;
2348     parsed_label->evaluate(1, *this, label, temp_pos);
2349     label_ptr = lookup_label(label);
2350   }
2351 }
2352
2353 void reference::compute_label()
2354 {
2355   label.clear();
2356   if (parsed_label)
2357     parsed_label->evaluate(0, *this, label, separator_pos);
2358   if (short_label_flag && parsed_short_label)
2359     parsed_short_label->evaluate(0, *this, short_label, short_separator_pos);
2360   if (date_as_label) {
2361     string new_date;
2362     if (parsed_date_label) {
2363       substring_position temp_pos;
2364       parsed_date_label->evaluate(0, *this, new_date, temp_pos);
2365     }
2366     set_date(new_date);
2367   }
2368   if (label_ptr)
2369     label_ptr->count += 1;
2370 }
2371
2372 void reference::immediate_compute_label()
2373 {
2374   if (label_ptr)
2375     label_ptr->total = 2;       // force use of disambiguator
2376   compute_label();
2377 }
2378
2379 int reference::merge_labels(reference **v, int n, label_type type,
2380                             string &result)
2381 {
2382   if (abbreviate_label_ranges)
2383     return merge_labels_by_number(v, n, type, result);
2384   else
2385     return merge_labels_by_parts(v, n, type, result);
2386 }
2387
2388 int reference::merge_labels_by_number(reference **v, int n, label_type type,
2389                                       string &result)
2390 {
2391   if (n <= 1)
2392     return 0;
2393   int num = get_number();
2394   // Only merge three or more labels.
2395   if (v[0]->get_number() != num + 1
2396       || v[1]->get_number() != num + 2)
2397     return 0;
2398   int i;
2399   for (i = 2; i < n; i++)
2400     if (v[i]->get_number() != num + i + 1)
2401       break;
2402   result = get_label(type);
2403   result += label_range_indicator;
2404   result += v[i - 1]->get_label(type);
2405   return i;
2406 }
2407
2408 const substring_position &reference::get_separator_pos(label_type type) const
2409 {
2410   if (type == SHORT_LABEL && short_label_flag)
2411     return short_separator_pos;
2412   else
2413     return separator_pos;
2414 }
2415
2416 const string &reference::get_label(label_type type) const
2417 {
2418   if (type == SHORT_LABEL && short_label_flag)
2419     return short_label; 
2420   else
2421     return label;
2422 }
2423
2424 int reference::merge_labels_by_parts(reference **v, int n, label_type type,
2425                                      string &result)
2426 {
2427   if (n <= 0)
2428     return 0;
2429   const string &lb = get_label(type);
2430   const substring_position &sp = get_separator_pos(type);
2431   if (sp.start < 0
2432       || sp.start != v[0]->get_separator_pos(type).start 
2433       || memcmp(lb.contents(), v[0]->get_label(type).contents(),
2434                 sp.start) != 0)
2435     return 0;
2436   result = lb;
2437   int i = 0;
2438   do {
2439     result += separate_label_second_parts;
2440     const substring_position &s = v[i]->get_separator_pos(type);
2441     int sep_end_pos = s.start + s.length;
2442     result.append(v[i]->get_label(type).contents() + sep_end_pos,
2443                   v[i]->get_label(type).length() - sep_end_pos);
2444   } while (++i < n
2445            && sp.start == v[i]->get_separator_pos(type).start
2446            && memcmp(lb.contents(), v[i]->get_label(type).contents(),
2447                      sp.start) == 0);
2448   return i;
2449 }
2450
2451 string label_pool;
2452
2453 label_info::label_info(const string &s)
2454 : start(label_pool.length()), length(s.length()), count(0), total(1)
2455 {
2456   label_pool += s;
2457 }
2458
2459 static label_info **label_table = 0;
2460 static int label_table_size = 0;
2461 static int label_table_used = 0;
2462
2463 label_info *lookup_label(const string &label)
2464 {
2465   if (label_table == 0) {
2466     label_table = new label_info *[17];
2467     label_table_size = 17;
2468     for (int i = 0; i < 17; i++)
2469       label_table[i] = 0;
2470   }
2471   unsigned h = hash_string(label.contents(), label.length()) % label_table_size;
2472   label_info **ptr;
2473   for (ptr = label_table + h;
2474        *ptr != 0;
2475        (ptr == label_table)
2476        ? (ptr = label_table + label_table_size - 1)
2477        : ptr--)
2478     if ((*ptr)->length == label.length()
2479         && memcmp(label_pool.contents() + (*ptr)->start, label.contents(),
2480                   label.length()) == 0) {
2481       (*ptr)->total += 1;
2482       return *ptr;
2483     }
2484   label_info *result = *ptr = new label_info(label);
2485   if (++label_table_used * 2 > label_table_size) {
2486     // Rehash the table.
2487     label_info **old_table = label_table;
2488     int old_size = label_table_size;
2489     label_table_size = next_size(label_table_size);
2490     label_table = new label_info *[label_table_size];
2491     int i;
2492     for (i = 0; i < label_table_size; i++)
2493       label_table[i] = 0;
2494     for (i = 0; i < old_size; i++)
2495       if (old_table[i]) {
2496         h = hash_string(label_pool.contents() + old_table[i]->start,
2497                         old_table[i]->length);
2498         label_info **p;
2499         for (p = label_table + (h % label_table_size);
2500              *p != 0;
2501              (p == label_table)
2502              ? (p = label_table + label_table_size - 1)
2503              : --p)
2504             ;
2505         *p = old_table[i];
2506         }
2507     a_delete old_table;
2508   }
2509   return result;
2510 }
2511
2512 void clear_labels()
2513 {
2514   for (int i = 0; i < label_table_size; i++) {
2515     delete label_table[i];
2516     label_table[i] = 0;
2517   }
2518   label_table_used = 0;
2519   label_pool.clear();
2520 }
2521
2522 static void consider_authors(reference **start, reference **end, int i);
2523
2524 void compute_labels(reference **v, int n)
2525 {
2526   if (parsed_label
2527       && (parsed_label->analyze() & expression::CONTAINS_AT)
2528       && sort_fields.length() >= 2
2529       && sort_fields[0] == 'A'
2530       && sort_fields[1] == '+')
2531     consider_authors(v, v + n, 0);
2532   for (int i = 0; i < n; i++)
2533     v[i]->compute_label();
2534 }
2535
2536
2537 /* A reference with a list of authors <A0,A1,...,AN> _needs_ author i
2538 where 0 <= i <= N if there exists a reference with a list of authors
2539 <B0,B1,...,BM> such that <A0,A1,...,AN> != <B0,B1,...,BM> and M >= i
2540 and Aj = Bj for 0 <= j < i. In this case if we can't say "A0,
2541 A1,...,A(i-1) et al" because this would match both <A0,A1,...,AN> and
2542 <B0,B1,...,BM>.  If a reference needs author i we only have to call
2543 need_author(j) for some j >= i such that the reference also needs
2544 author j. */
2545
2546 /* This function handles 2 tasks:
2547 determine which authors are needed (cannot be elided with et al.);
2548 determine which authors can have only last names in the labels.
2549
2550 References >= start and < end have the same first i author names.
2551 Also they're sorted by A+. */
2552
2553 static void consider_authors(reference **start, reference **end, int i)
2554 {
2555   if (start >= end)
2556     return;
2557   reference **p = start;
2558   if (i >= (*p)->get_nauthors()) {
2559     for (++p; p < end && i >= (*p)->get_nauthors(); p++)
2560       ;
2561     if (p < end && i > 0) {
2562       // If we have an author list <A B C> and an author list <A B C D>,
2563       // then both lists need C.
2564       for (reference **q = start; q < end; q++)
2565         (*q)->need_author(i - 1);
2566     }
2567     start = p;
2568   }
2569   while (p < end) {
2570     reference **last_name_start = p;
2571     reference **name_start = p;
2572     for (++p;
2573          p < end && i < (*p)->get_nauthors()
2574          && same_author_last_name(**last_name_start, **p, i);
2575          p++) {
2576       if (!same_author_name(**name_start, **p, i)) {
2577         consider_authors(name_start, p, i + 1);
2578         name_start = p;
2579       }
2580     }
2581     consider_authors(name_start, p, i + 1);
2582     if (last_name_start == name_start) {
2583       for (reference **q = last_name_start; q < p; q++)
2584         (*q)->set_last_name_unambiguous(i);
2585     }
2586     // If we have an author list <A B C D> and <A B C E>, then the lists
2587     // need author D and E respectively.
2588     if (name_start > start || p < end) {
2589       for (reference **q = last_name_start; q < p; q++)
2590         (*q)->need_author(i);
2591     }
2592   }
2593 }
2594
2595 int same_author_last_name(const reference &r1, const reference &r2, int n)
2596 {
2597   const char *ae1;
2598   const char *as1 = r1.get_sort_field(0, n, 0, &ae1);
2599   const char *ae2;
2600   const char *as2 = r2.get_sort_field(0, n, 0, &ae2);
2601   if (!as1 && !as2) return 1;   // they are the same
2602   if (!as1 || !as2) return 0;
2603   return ae1 - as1 == ae2 - as2 && memcmp(as1, as2, ae1 - as1) == 0;
2604 }
2605
2606 int same_author_name(const reference &r1, const reference &r2, int n)
2607 {
2608   const char *ae1;
2609   const char *as1 = r1.get_sort_field(0, n, -1, &ae1);
2610   const char *ae2;
2611   const char *as2 = r2.get_sort_field(0, n, -1, &ae2);
2612   if (!as1 && !as2) return 1;   // they are the same
2613   if (!as1 || !as2) return 0;
2614   return ae1 - as1 == ae2 - as2 && memcmp(as1, as2, ae1 - as1) == 0;
2615 }
2616
2617
2618 void int_set::set(int i)
2619 {
2620   assert(i >= 0);
2621   int bytei = i >> 3;
2622   if (bytei >= v.length()) {
2623     int old_length = v.length();
2624     v.set_length(bytei + 1);
2625     for (int j = old_length; j <= bytei; j++)
2626       v[j] = 0;
2627   }
2628   v[bytei] |= 1 << (i & 7);
2629 }
2630
2631 int int_set::get(int i) const
2632 {
2633   assert(i >= 0);
2634   int bytei = i >> 3;
2635   return bytei >= v.length() ? 0 : (v[bytei] & (1 << (i & 7))) != 0;
2636 }
2637
2638 void reference::set_last_name_unambiguous(int i)
2639 {
2640   last_name_unambiguous.set(i);
2641 }
2642
2643 void reference::need_author(int n)
2644 {
2645   if (n > last_needed_author)
2646     last_needed_author = n;
2647 }
2648
2649 const char *reference::get_authors(const char **end) const
2650 {
2651   if (!computed_authors) {
2652     ((reference *)this)->computed_authors = 1;
2653     string &result = ((reference *)this)->authors;
2654     int na = get_nauthors();
2655     result.clear();
2656     for (int i = 0; i < na; i++) {
2657       if (last_name_unambiguous.get(i)) {
2658         const char *e, *start = get_author_last_name(i, &e);
2659         assert(start != 0);
2660         result.append(start, e - start);
2661       }
2662       else {
2663         const char *e, *start = get_author(i, &e);
2664         assert(start != 0);
2665         result.append(start, e - start);
2666       }
2667       if (i == last_needed_author
2668           && et_al.length() > 0
2669           && et_al_min_elide > 0
2670           && last_needed_author + et_al_min_elide < na
2671           && na >= et_al_min_total) {
2672         result += et_al;
2673         break;
2674       }
2675       if (i < na - 1) {
2676         if (na == 2)
2677           result += join_authors_exactly_two;
2678         else if (i < na - 2)
2679           result += join_authors_default;
2680         else
2681           result += join_authors_last_two;
2682       }
2683     }
2684   }
2685   const char *start = authors.contents();
2686   *end = start + authors.length();
2687   return start;
2688 }
2689
2690 int reference::get_nauthors() const
2691 {
2692   if (nauthors < 0) {
2693     const char *dummy;
2694     int na;
2695     for (na = 0; get_author(na, &dummy) != 0; na++)
2696       ;
2697     ((reference *)this)->nauthors = na;
2698   }
2699   return nauthors;
2700 }