LCOV - code coverage report
Current view: top level - home/branden/src/GIT/groff/build/src/preproc/refer - label.cpp (source / functions) Hit Total Coverage
Test: GNU roff Lines: 89 206 43.2 %
Date: 2026-01-16 17:51:41 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14