"Fossies" - the Fresh Open Source Software Archive

Member "udunits-2.2.28/lib/parser.c" (8 Dec 2020, 64992 Bytes) of package /linux/privat/udunits-2.2.28.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "parser.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.2.26_vs_2.2.28.

    1 /* A Bison parser, made by GNU Bison 3.0.4.  */
    2 
    3 /* Bison implementation for Yacc-like parsers in C
    4 
    5    Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
    6 
    7    This program is free software: you can redistribute it and/or modify
    8    it under the terms of the GNU General Public License as published by
    9    the Free Software Foundation, either version 3 of the License, or
   10    (at your option) any later version.
   11 
   12    This program is distributed in the hope that it will be useful,
   13    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15    GNU General Public License for more details.
   16 
   17    You should have received a copy of the GNU General Public License
   18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
   19 
   20 /* As a special exception, you may create a larger work that contains
   21    part or all of the Bison parser skeleton and distribute that work
   22    under terms of your choice, so long as that work isn't itself a
   23    parser generator using the skeleton or a modified version thereof
   24    as a parser skeleton.  Alternatively, if you modify or redistribute
   25    the parser skeleton itself, you may (at your option) remove this
   26    special exception, which will cause the skeleton and the resulting
   27    Bison output files to be licensed under the GNU General Public
   28    License without this special exception.
   29 
   30    This special exception was added by the Free Software Foundation in
   31    version 2.2 of Bison.  */
   32 
   33 /* C LALR(1) parser skeleton written by Richard Stallman, by
   34    simplifying the original so-called "semantic" parser.  */
   35 
   36 /* All symbols defined below should begin with yy or YY, to avoid
   37    infringing on user name space.  This should be done even for local
   38    variables, as they might otherwise be expanded by user macros.
   39    There are some unavoidable exceptions within include files to
   40    define necessary library symbols; they are noted "INFRINGES ON
   41    USER NAME SPACE" below.  */
   42 
   43 /* Identify Bison output.  */
   44 #define YYBISON 1
   45 
   46 /* Bison version.  */
   47 #define YYBISON_VERSION "3.0.4"
   48 
   49 /* Skeleton name.  */
   50 #define YYSKELETON_NAME "yacc.c"
   51 
   52 /* Pure parsers.  */
   53 #define YYPURE 0
   54 
   55 /* Push parsers.  */
   56 #define YYPUSH 0
   57 
   58 /* Pull parsers.  */
   59 #define YYPULL 1
   60 
   61 
   62 /* Substitute the variable and function names.  */
   63 #define yyparse         utparse
   64 #define yylex           utlex
   65 #define yyerror         uterror
   66 #define yydebug         utdebug
   67 #define yynerrs         utnerrs
   68 
   69 #define yylval          utlval
   70 #define yychar          utchar
   71 
   72 /* Copy the first part of user declarations.  */
   73 #line 1 "parser.y" /* yacc.c:339  */
   74 
   75 /*
   76  * Copyright 2020 University Corporation for Atmospheric Research. All rights
   77  * reserved.
   78  *
   79  * This file is part of the UDUNITS-2 package.  See the file COPYRIGHT
   80  * in the top-level source-directory of the package for copying and
   81  * redistribution conditions.
   82  */
   83 /*
   84  * bison(1)-based parser for decoding formatted unit specifications.
   85  *
   86  * This module is thread-compatible but not thread-safe: multi-threaded access
   87  * must be externally synchronized.
   88  */
   89 
   90 /*LINTLIBRARY*/
   91 
   92 #include "config.h"
   93 
   94 #include "prefix.h"
   95 #include "udunits2.h"
   96 
   97 #include <assert.h>
   98 #include <ctype.h>
   99 #include <errno.h>
  100 #include <stddef.h>
  101 #include <stdio.h>
  102 #include <stdlib.h>
  103 #include <string.h>
  104 #ifndef _MSC_VER
  105 #include <strings.h>
  106 #endif
  107 
  108 extern int utlex (void);
  109 
  110 static ut_unit*     _finalUnit; /* fully-parsed specification */
  111 static ut_system*   _unitSystem;    /* The unit-system to use */
  112 static char*        _errorMessage;  /* last error-message */
  113 static ut_encoding  _encoding;  /* encoding of string to be parsed */
  114 static int      _restartScanner;/* restart scanner? */
  115 static int      _isTime;        /* product_exp is time? */
  116 
  117 
  118 /*
  119  * Removes leading and trailing whitespace from a string.
  120  *
  121  * Arguments:
  122  *  string      NUL-terminated string.  Will be modified if it
  123  *                      contains whitespace.
  124  *  encoding    The character-encoding of "string".
  125  * Returns:
  126  *      "string"
  127  */
  128 char*
  129 ut_trim(
  130     char* const         string,
  131     const ut_encoding   encoding)
  132 {
  133     static const char*  asciiSpace = " \t\n\r\f\v";
  134     static const char*  latin1Space = " \t\n\r\f\v\xa0";    /* add NBSP */
  135     const char*     whiteSpace;
  136     char*       start;
  137     char*       stop;
  138     size_t              len;
  139 
  140     whiteSpace =
  141     encoding == UT_LATIN1
  142         ? latin1Space
  143         : asciiSpace;
  144 
  145     start = string + strspn(string, whiteSpace);
  146 
  147     for (stop = start + strlen(start); stop > start; --stop)
  148      if (strchr(whiteSpace, stop[-1]) == NULL)
  149         break;
  150 
  151     len = stop - start;
  152 
  153     (void)memmove(string, start, len);
  154 
  155     string[len] = 0;
  156 
  157     ut_set_status(UT_SUCCESS);
  158 
  159     return start;
  160 }
  161 
  162 
  163 /*
  164  *  YACC error routine:
  165  */
  166 void
  167 uterror(
  168     char            *s)
  169 {
  170     static char*    nomem = "uterror(): out of memory";
  171 
  172     if (_errorMessage != NULL && _errorMessage != nomem)
  173     free(_errorMessage);
  174 
  175     _errorMessage = strdup(s);
  176 
  177     if (_errorMessage == NULL)
  178     _errorMessage = nomem;
  179 }
  180 
  181 /**
  182  * Parses an integer value into broken-down clock-time. The value is assumed to
  183  * have the form H[H[MM[SS]]].
  184  *
  185  * @param[in]  value   The integer value.
  186  * @param[out] hour    The hour field.
  187  * @param[out] minute  The minute field. Set to zero if appropriate.
  188  * @param[out] second  The second field. Set to zero if appropriate.
  189  */
  190 static void to_clock(
  191     unsigned long       value,
  192     unsigned* const     hour,
  193     unsigned* const     minute,
  194     unsigned* const     second)
  195 {
  196     if (value > 0)
  197         while (value < 10000)
  198             value *= 10;
  199 
  200     *hour = value / 10000;
  201     *minute = (value % 10000) / 100;
  202     *second = value % 100;
  203 }
  204 
  205 /**
  206  * Converts an integer value into a timezone offset as used by this package.
  207  *
  208  * @param[in]  value  The integer value. Must correspond to [+|-]H[H[MM]].
  209  * @param[out] time   The corresponding time as used by this package.
  210  * @retval     0      Success. "*time" is set.
  211  * @retval     -1     The integer value is invalid.
  212  */
  213 static int timezone_to_time(
  214     const long    value,
  215     double* const time)
  216 {
  217     unsigned hour, minute, second;
  218 
  219     if (value < -2400 || value > 2400)
  220         return -1;
  221 
  222     to_clock(value < 0 ? -value : value, &hour, &minute, &second);
  223 
  224     if (hour > 24 || minute >= 60)
  225         return -1;
  226 
  227     *time = (value >= 0)
  228             ? ut_encode_clock(hour, minute, second)
  229             : -ut_encode_clock(hour, minute, second);
  230 
  231     return 0;
  232 }
  233 
  234 /**
  235  * Converts an integer value into a time as used by this package.
  236  *
  237  * @param[in]  value  The integer value. Must correspond to H[H[MM[SS]]].
  238  * @param[out] time   The corresponding time as used by this package.
  239  * @retval     0      Success. "*time" is set.
  240  * @retval     -1     The integer value is invalid.
  241  */
  242 static int clock_to_time(
  243     const long    value,
  244     double* const time)
  245 {
  246     unsigned hour, minute, second;
  247 
  248     if (value < 0)
  249         return -1;
  250 
  251     to_clock(value, &hour, &minute, &second);
  252 
  253     if (hour > 24 || minute >= 60 || second > 60) /* allow leap second */
  254         return -1;
  255 
  256     *time = ut_encode_clock(hour, minute, second);
  257 
  258     return 0;
  259 }
  260 
  261 /**
  262  * Indicates if a unit is a (non-offset) time unit.
  263  *
  264  * @param[in] unit      The unit to be checked.
  265  * @retval    0         If and only if the unit is not a time unit.
  266  */
  267 static int isTime(
  268     const ut_unit* const unit)
  269 {
  270     ut_status   prev = ut_get_status();
  271     ut_unit*    second = ut_get_unit_by_name(_unitSystem, "second");
  272     int         isTime = ut_are_convertible(unit, second);
  273 
  274     ut_free(second);
  275     ut_set_status(prev);
  276     return isTime;
  277 }
  278 
  279 
  280 #line 281 "parser.c" /* yacc.c:339  */
  281 
  282 # ifndef YY_NULLPTR
  283 #  if defined __cplusplus && 201103L <= __cplusplus
  284 #   define YY_NULLPTR nullptr
  285 #  else
  286 #   define YY_NULLPTR 0
  287 #  endif
  288 # endif
  289 
  290 /* Enabling verbose error messages.  */
  291 #ifdef YYERROR_VERBOSE
  292 # undef YYERROR_VERBOSE
  293 # define YYERROR_VERBOSE 1
  294 #else
  295 # define YYERROR_VERBOSE 0
  296 #endif
  297 
  298 
  299 /* Debug traces.  */
  300 #ifndef YYDEBUG
  301 # define YYDEBUG 1
  302 #endif
  303 #if YYDEBUG
  304 extern int utdebug;
  305 #endif
  306 
  307 /* Token type.  */
  308 #ifndef YYTOKENTYPE
  309 # define YYTOKENTYPE
  310   enum yytokentype
  311   {
  312     ERR = 258,
  313     SHIFT = 259,
  314     MULTIPLY = 260,
  315     DIVIDE = 261,
  316     INT = 262,
  317     EXPONENT = 263,
  318     REAL = 264,
  319     ID = 265,
  320     DATE = 266,
  321     CLOCK = 267,
  322     TIMESTAMP = 268,
  323     LOGREF = 269
  324   };
  325 #endif
  326 /* Tokens.  */
  327 #define ERR 258
  328 #define SHIFT 259
  329 #define MULTIPLY 260
  330 #define DIVIDE 261
  331 #define INT 262
  332 #define EXPONENT 263
  333 #define REAL 264
  334 #define ID 265
  335 #define DATE 266
  336 #define CLOCK 267
  337 #define TIMESTAMP 268
  338 #define LOGREF 269
  339 
  340 /* Value type.  */
  341 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  342 
  343 union YYSTYPE
  344 {
  345 #line 208 "parser.y" /* yacc.c:355  */
  346 
  347     char*   id;         /* identifier */
  348     ut_unit*    unit;           /* "unit" structure */
  349     double  rval;           /* floating-point numerical value */
  350     long    ival;           /* integer numerical value */
  351 
  352 #line 353 "parser.c" /* yacc.c:355  */
  353 };
  354 
  355 typedef union YYSTYPE YYSTYPE;
  356 # define YYSTYPE_IS_TRIVIAL 1
  357 # define YYSTYPE_IS_DECLARED 1
  358 #endif
  359 
  360 
  361 extern YYSTYPE utlval;
  362 
  363 int utparse (void);
  364 
  365 
  366 
  367 /* Copy the second part of user declarations.  */
  368 
  369 #line 370 "parser.c" /* yacc.c:358  */
  370 
  371 #ifdef short
  372 # undef short
  373 #endif
  374 
  375 #ifdef YYTYPE_UINT8
  376 typedef YYTYPE_UINT8 yytype_uint8;
  377 #else
  378 typedef unsigned char yytype_uint8;
  379 #endif
  380 
  381 #ifdef YYTYPE_INT8
  382 typedef YYTYPE_INT8 yytype_int8;
  383 #else
  384 typedef signed char yytype_int8;
  385 #endif
  386 
  387 #ifdef YYTYPE_UINT16
  388 typedef YYTYPE_UINT16 yytype_uint16;
  389 #else
  390 typedef unsigned short int yytype_uint16;
  391 #endif
  392 
  393 #ifdef YYTYPE_INT16
  394 typedef YYTYPE_INT16 yytype_int16;
  395 #else
  396 typedef short int yytype_int16;
  397 #endif
  398 
  399 #ifndef YYSIZE_T
  400 # ifdef __SIZE_TYPE__
  401 #  define YYSIZE_T __SIZE_TYPE__
  402 # elif defined size_t
  403 #  define YYSIZE_T size_t
  404 # elif ! defined YYSIZE_T
  405 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  406 #  define YYSIZE_T size_t
  407 # else
  408 #  define YYSIZE_T unsigned int
  409 # endif
  410 #endif
  411 
  412 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
  413 
  414 #ifndef YY_
  415 # if defined YYENABLE_NLS && YYENABLE_NLS
  416 #  if ENABLE_NLS
  417 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
  418 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
  419 #  endif
  420 # endif
  421 # ifndef YY_
  422 #  define YY_(Msgid) Msgid
  423 # endif
  424 #endif
  425 
  426 #ifndef YY_ATTRIBUTE
  427 # if (defined __GNUC__                                               \
  428       && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
  429      || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
  430 #  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
  431 # else
  432 #  define YY_ATTRIBUTE(Spec) /* empty */
  433 # endif
  434 #endif
  435 
  436 #ifndef YY_ATTRIBUTE_PURE
  437 # define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
  438 #endif
  439 
  440 #ifndef YY_ATTRIBUTE_UNUSED
  441 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
  442 #endif
  443 
  444 #if !defined _Noreturn \
  445      && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
  446 # if defined _MSC_VER && 1200 <= _MSC_VER
  447 #  define _Noreturn __declspec (noreturn)
  448 # else
  449 #  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
  450 # endif
  451 #endif
  452 
  453 /* Suppress unused-variable warnings by "using" E.  */
  454 #if ! defined lint || defined __GNUC__
  455 # define YYUSE(E) ((void) (E))
  456 #else
  457 # define YYUSE(E) /* empty */
  458 #endif
  459 
  460 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
  461 /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
  462 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
  463     _Pragma ("GCC diagnostic push") \
  464     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
  465     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
  466 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
  467     _Pragma ("GCC diagnostic pop")
  468 #else
  469 # define YY_INITIAL_VALUE(Value) Value
  470 #endif
  471 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  472 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  473 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
  474 #endif
  475 #ifndef YY_INITIAL_VALUE
  476 # define YY_INITIAL_VALUE(Value) /* Nothing. */
  477 #endif
  478 
  479 
  480 #if ! defined yyoverflow || YYERROR_VERBOSE
  481 
  482 /* The parser invokes alloca or malloc; define the necessary symbols.  */
  483 
  484 # ifdef YYSTACK_USE_ALLOCA
  485 #  if YYSTACK_USE_ALLOCA
  486 #   ifdef __GNUC__
  487 #    define YYSTACK_ALLOC __builtin_alloca
  488 #   elif defined __BUILTIN_VA_ARG_INCR
  489 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
  490 #   elif defined _AIX
  491 #    define YYSTACK_ALLOC __alloca
  492 #   elif defined _MSC_VER
  493 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
  494 #    define alloca _alloca
  495 #   else
  496 #    define YYSTACK_ALLOC alloca
  497 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
  498 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  499       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
  500 #     ifndef EXIT_SUCCESS
  501 #      define EXIT_SUCCESS 0
  502 #     endif
  503 #    endif
  504 #   endif
  505 #  endif
  506 # endif
  507 
  508 # ifdef YYSTACK_ALLOC
  509    /* Pacify GCC's 'empty if-body' warning.  */
  510 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
  511 #  ifndef YYSTACK_ALLOC_MAXIMUM
  512     /* The OS might guarantee only one guard page at the bottom of the stack,
  513        and a page size can be as small as 4096 bytes.  So we cannot safely
  514        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
  515        to allow for a few compiler-allocated temporary stack slots.  */
  516 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
  517 #  endif
  518 # else
  519 #  define YYSTACK_ALLOC YYMALLOC
  520 #  define YYSTACK_FREE YYFREE
  521 #  ifndef YYSTACK_ALLOC_MAXIMUM
  522 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
  523 #  endif
  524 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
  525        && ! ((defined YYMALLOC || defined malloc) \
  526              && (defined YYFREE || defined free)))
  527 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  528 #   ifndef EXIT_SUCCESS
  529 #    define EXIT_SUCCESS 0
  530 #   endif
  531 #  endif
  532 #  ifndef YYMALLOC
  533 #   define YYMALLOC malloc
  534 #   if ! defined malloc && ! defined EXIT_SUCCESS
  535 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  536 #   endif
  537 #  endif
  538 #  ifndef YYFREE
  539 #   define YYFREE free
  540 #   if ! defined free && ! defined EXIT_SUCCESS
  541 void free (void *); /* INFRINGES ON USER NAME SPACE */
  542 #   endif
  543 #  endif
  544 # endif
  545 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
  546 
  547 
  548 #if (! defined yyoverflow \
  549      && (! defined __cplusplus \
  550          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  551 
  552 /* A type that is properly aligned for any stack member.  */
  553 union yyalloc
  554 {
  555   yytype_int16 yyss_alloc;
  556   YYSTYPE yyvs_alloc;
  557 };
  558 
  559 /* The size of the maximum gap between one aligned stack and the next.  */
  560 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
  561 
  562 /* The size of an array large to enough to hold all stacks, each with
  563    N elements.  */
  564 # define YYSTACK_BYTES(N) \
  565      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
  566       + YYSTACK_GAP_MAXIMUM)
  567 
  568 # define YYCOPY_NEEDED 1
  569 
  570 /* Relocate STACK from its old location to the new one.  The
  571    local variables YYSIZE and YYSTACKSIZE give the old and new number of
  572    elements in the stack, and YYPTR gives the new location of the
  573    stack.  Advance YYPTR to a properly aligned location for the next
  574    stack.  */
  575 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
  576     do                                                                  \
  577       {                                                                 \
  578         YYSIZE_T yynewbytes;                                            \
  579         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
  580         Stack = &yyptr->Stack_alloc;                                    \
  581         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  582         yyptr += yynewbytes / sizeof (*yyptr);                          \
  583       }                                                                 \
  584     while (0)
  585 
  586 #endif
  587 
  588 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
  589 /* Copy COUNT objects from SRC to DST.  The source and destination do
  590    not overlap.  */
  591 # ifndef YYCOPY
  592 #  if defined __GNUC__ && 1 < __GNUC__
  593 #   define YYCOPY(Dst, Src, Count) \
  594       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
  595 #  else
  596 #   define YYCOPY(Dst, Src, Count)              \
  597       do                                        \
  598         {                                       \
  599           YYSIZE_T yyi;                         \
  600           for (yyi = 0; yyi < (Count); yyi++)   \
  601             (Dst)[yyi] = (Src)[yyi];            \
  602         }                                       \
  603       while (0)
  604 #  endif
  605 # endif
  606 #endif /* !YYCOPY_NEEDED */
  607 
  608 /* YYFINAL -- State number of the termination state.  */
  609 #define YYFINAL  15
  610 /* YYLAST -- Last index in YYTABLE.  */
  611 #define YYLAST   95
  612 
  613 /* YYNTOKENS -- Number of terminals.  */
  614 #define YYNTOKENS  17
  615 /* YYNNTS -- Number of nonterminals.  */
  616 #define YYNNTS  8
  617 /* YYNRULES -- Number of rules.  */
  618 #define YYNRULES  35
  619 /* YYNSTATES -- Number of states.  */
  620 #define YYNSTATES  43
  621 
  622 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
  623    by yylex, with out-of-bounds checking.  */
  624 #define YYUNDEFTOK  2
  625 #define YYMAXUTOK   269
  626 
  627 #define YYTRANSLATE(YYX)                                                \
  628   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  629 
  630 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
  631    as returned by yylex, without out-of-bounds checking.  */
  632 static const yytype_uint8 yytranslate[] =
  633 {
  634        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  635        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  636        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  637        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  638       15,    16,     2,     2,     2,     2,     2,     2,     2,     2,
  639        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  640        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  641        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  642        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  643        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  644        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  645        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  646        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  647        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  648        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  649        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  650        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  651        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  652        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  653        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  654        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  655        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  656        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  657        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  658        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  659        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
  660        5,     6,     7,     8,     9,    10,    11,    12,    13,    14
  661 };
  662 
  663 #if YYDEBUG
  664   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
  665 static const yytype_uint16 yyrline[] =
  666 {
  667        0,   238,   238,   242,   246,   251,   254,   260,   266,   272,
  668      280,   284,   292,   298,   306,   312,   320,   328,   331,   337,
  669      343,   351,   404,   407,   413,   419,   425,   431,   434,   439,
  670      442,   445,   448,   467,   470,   473
  671 };
  672 #endif
  673 
  674 #if YYDEBUG || YYERROR_VERBOSE || 0
  675 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  676    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
  677 static const char *const yytname[] =
  678 {
  679   "$end", "error", "$undefined", "ERR", "SHIFT", "MULTIPLY", "DIVIDE",
  680   "INT", "EXPONENT", "REAL", "ID", "DATE", "CLOCK", "TIMESTAMP", "LOGREF",
  681   "'('", "')'", "$accept", "unit_spec", "shift_exp", "product_exp",
  682   "power_exp", "basic_exp", "number", "timestamp", YY_NULLPTR
  683 };
  684 #endif
  685 
  686 # ifdef YYPRINT
  687 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
  688    (internal) symbol number NUM (which must be that of a token).  */
  689 static const yytype_uint16 yytoknum[] =
  690 {
  691        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
  692      265,   266,   267,   268,   269,    40,    41
  693 };
  694 # endif
  695 
  696 #define YYPACT_NINF -10
  697 
  698 #define yypact_value_is_default(Yystate) \
  699   (!!((Yystate) == (-10)))
  700 
  701 #define YYTABLE_NINF -26
  702 
  703 #define yytable_value_is_error(Yytable_value) \
  704   0
  705 
  706   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  707      STATE-NUM.  */
  708 static const yytype_int8 yypact[] =
  709 {
  710       40,   -10,   -10,   -10,   -10,    80,    80,     2,   -10,    17,
  711      -10,     0,   -10,    29,    12,   -10,   -10,    70,    50,    60,
  712      -10,   -10,   -10,   -10,    48,   -10,   -10,   -10,   -10,   -10,
  713      -10,    -9,    56,   -10,   -10,   -10,   -10,   -10,    72,   -10,
  714      -10,   -10,   -10
  715 };
  716 
  717   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
  718      Performed when YYTABLE does not specify something else to do.  Zero
  719      means the default is an error.  */
  720 static const yytype_uint8 yydefact[] =
  721 {
  722        0,     4,    27,    28,    21,     0,     0,     0,     3,     0,
  723       10,     0,    26,     0,     0,     1,    12,     0,     0,     0,
  724       11,    20,    18,    19,    12,    24,    23,    22,     9,     7,
  725        6,    29,    33,     8,    14,    13,    16,    15,    30,    35,
  726       34,    32,    31
  727 };
  728 
  729   /* YYPGOTO[NTERM-NUM].  */
  730 static const yytype_int8 yypgoto[] =
  731 {
  732      -10,   -10,     5,     7,    67,   -10,   -10,   -10
  733 };
  734 
  735   /* YYDEFGOTO[NTERM-NUM].  */
  736 static const yytype_int8 yydefgoto[] =
  737 {
  738       -1,     7,     8,     9,    10,    11,    12,    33
  739 };
  740 
  741   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
  742      positive, shift that token.  If negative, reduce the rule whose
  743      number is the opposite.  If YYTABLE_NINF, syntax error.  */
  744 static const yytype_int8 yytable[] =
  745 {
  746      -17,    21,    15,    38,   -17,   -17,   -17,    22,    23,   -17,
  747      -17,    14,    13,    26,   -17,   -17,   -17,    -5,    16,     0,
  748        0,    17,    18,    19,     2,     0,     3,     4,    27,     0,
  749       24,     5,     6,    -5,    18,    19,     2,     0,     3,     4,
  750       -2,     1,     0,     5,     6,    25,     0,     2,   -25,     3,
  751        4,    34,   -25,     0,     5,     6,   -25,     2,     0,     3,
  752        4,    36,     0,     0,     5,     6,    39,     2,    40,     3,
  753        4,    28,     0,     0,     5,     6,    20,    29,     0,    30,
  754       20,    31,    41,    32,    42,    35,    37,     2,     0,     3,
  755        4,     0,     0,     0,     5,     6
  756 };
  757 
  758 static const yytype_int8 yycheck[] =
  759 {
  760        0,     1,     0,    12,     4,     5,     6,     7,     8,     9,
  761       10,     6,     5,     1,    14,    15,    16,     0,     1,    -1,
  762       -1,     4,     5,     6,     7,    -1,     9,    10,    16,    -1,
  763        1,    14,    15,    16,     5,     6,     7,    -1,     9,    10,
  764        0,     1,    -1,    14,    15,    16,    -1,     7,     0,     9,
  765       10,     1,     4,    -1,    14,    15,     8,     7,    -1,     9,
  766       10,     1,    -1,    -1,    14,    15,    10,     7,    12,     9,
  767       10,     1,    -1,    -1,    14,    15,     9,     7,    -1,     9,
  768       13,    11,    10,    13,    12,    18,    19,     7,    -1,     9,
  769       10,    -1,    -1,    -1,    14,    15
  770 };
  771 
  772   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  773      symbol of state STATE-NUM.  */
  774 static const yytype_uint8 yystos[] =
  775 {
  776        0,     1,     7,     9,    10,    14,    15,    18,    19,    20,
  777       21,    22,    23,    20,    19,     0,     1,     4,     5,     6,
  778       21,     1,     7,     8,     1,    16,     1,    16,     1,     7,
  779        9,    11,    13,    24,     1,    21,     1,    21,    12,    10,
  780       12,    10,    12
  781 };
  782 
  783   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
  784 static const yytype_uint8 yyr1[] =
  785 {
  786        0,    17,    18,    18,    18,    19,    19,    19,    19,    19,
  787       20,    20,    20,    20,    20,    20,    20,    21,    21,    21,
  788       21,    22,    22,    22,    22,    22,    22,    23,    23,    24,
  789       24,    24,    24,    24,    24,    24
  790 };
  791 
  792   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
  793 static const yytype_uint8 yyr2[] =
  794 {
  795        0,     2,     0,     1,     1,     1,     3,     3,     3,     3,
  796        1,     2,     2,     3,     3,     3,     3,     1,     2,     2,
  797        2,     1,     3,     3,     3,     3,     1,     1,     1,     1,
  798        2,     3,     3,     1,     2,     2
  799 };
  800 
  801 
  802 #define yyerrok         (yyerrstatus = 0)
  803 #define yyclearin       (yychar = YYEMPTY)
  804 #define YYEMPTY         (-2)
  805 #define YYEOF           0
  806 
  807 #define YYACCEPT        goto yyacceptlab
  808 #define YYABORT         goto yyabortlab
  809 #define YYERROR         goto yyerrorlab
  810 
  811 
  812 #define YYRECOVERING()  (!!yyerrstatus)
  813 
  814 #define YYBACKUP(Token, Value)                                  \
  815 do                                                              \
  816   if (yychar == YYEMPTY)                                        \
  817     {                                                           \
  818       yychar = (Token);                                         \
  819       yylval = (Value);                                         \
  820       YYPOPSTACK (yylen);                                       \
  821       yystate = *yyssp;                                         \
  822       goto yybackup;                                            \
  823     }                                                           \
  824   else                                                          \
  825     {                                                           \
  826       yyerror (YY_("syntax error: cannot back up")); \
  827       YYERROR;                                                  \
  828     }                                                           \
  829 while (0)
  830 
  831 /* Error token number */
  832 #define YYTERROR        1
  833 #define YYERRCODE       256
  834 
  835 
  836 
  837 /* Enable debugging if requested.  */
  838 #if YYDEBUG
  839 
  840 # ifndef YYFPRINTF
  841 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
  842 #  define YYFPRINTF fprintf
  843 # endif
  844 
  845 # define YYDPRINTF(Args)                        \
  846 do {                                            \
  847   if (yydebug)                                  \
  848     YYFPRINTF Args;                             \
  849 } while (0)
  850 
  851 /* This macro is provided for backward compatibility. */
  852 #ifndef YY_LOCATION_PRINT
  853 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  854 #endif
  855 
  856 
  857 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
  858 do {                                                                      \
  859   if (yydebug)                                                            \
  860     {                                                                     \
  861       YYFPRINTF (stderr, "%s ", Title);                                   \
  862       yy_symbol_print (stderr,                                            \
  863                   Type, Value); \
  864       YYFPRINTF (stderr, "\n");                                           \
  865     }                                                                     \
  866 } while (0)
  867 
  868 
  869 /*----------------------------------------.
  870 | Print this symbol's value on YYOUTPUT.  |
  871 `----------------------------------------*/
  872 
  873 static void
  874 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
  875 {
  876   FILE *yyo = yyoutput;
  877   YYUSE (yyo);
  878   if (!yyvaluep)
  879     return;
  880 # ifdef YYPRINT
  881   if (yytype < YYNTOKENS)
  882     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  883 # endif
  884   YYUSE (yytype);
  885 }
  886 
  887 
  888 /*--------------------------------.
  889 | Print this symbol on YYOUTPUT.  |
  890 `--------------------------------*/
  891 
  892 static void
  893 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
  894 {
  895   YYFPRINTF (yyoutput, "%s %s (",
  896              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
  897 
  898   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
  899   YYFPRINTF (yyoutput, ")");
  900 }
  901 
  902 /*------------------------------------------------------------------.
  903 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
  904 | TOP (included).                                                   |
  905 `------------------------------------------------------------------*/
  906 
  907 static void
  908 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
  909 {
  910   YYFPRINTF (stderr, "Stack now");
  911   for (; yybottom <= yytop; yybottom++)
  912     {
  913       int yybot = *yybottom;
  914       YYFPRINTF (stderr, " %d", yybot);
  915     }
  916   YYFPRINTF (stderr, "\n");
  917 }
  918 
  919 # define YY_STACK_PRINT(Bottom, Top)                            \
  920 do {                                                            \
  921   if (yydebug)                                                  \
  922     yy_stack_print ((Bottom), (Top));                           \
  923 } while (0)
  924 
  925 
  926 /*------------------------------------------------.
  927 | Report that the YYRULE is going to be reduced.  |
  928 `------------------------------------------------*/
  929 
  930 static void
  931 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
  932 {
  933   unsigned long int yylno = yyrline[yyrule];
  934   int yynrhs = yyr2[yyrule];
  935   int yyi;
  936   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
  937              yyrule - 1, yylno);
  938   /* The symbols being reduced.  */
  939   for (yyi = 0; yyi < yynrhs; yyi++)
  940     {
  941       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
  942       yy_symbol_print (stderr,
  943                        yystos[yyssp[yyi + 1 - yynrhs]],
  944                        &(yyvsp[(yyi + 1) - (yynrhs)])
  945                                               );
  946       YYFPRINTF (stderr, "\n");
  947     }
  948 }
  949 
  950 # define YY_REDUCE_PRINT(Rule)          \
  951 do {                                    \
  952   if (yydebug)                          \
  953     yy_reduce_print (yyssp, yyvsp, Rule); \
  954 } while (0)
  955 
  956 /* Nonzero means print parse trace.  It is left uninitialized so that
  957    multiple parsers can coexist.  */
  958 int yydebug;
  959 #else /* !YYDEBUG */
  960 # define YYDPRINTF(Args)
  961 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
  962 # define YY_STACK_PRINT(Bottom, Top)
  963 # define YY_REDUCE_PRINT(Rule)
  964 #endif /* !YYDEBUG */
  965 
  966 
  967 /* YYINITDEPTH -- initial size of the parser's stacks.  */
  968 #ifndef YYINITDEPTH
  969 # define YYINITDEPTH 200
  970 #endif
  971 
  972 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
  973    if the built-in stack extension method is used).
  974 
  975    Do not make this value too large; the results are undefined if
  976    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
  977    evaluated with infinite-precision integer arithmetic.  */
  978 
  979 #ifndef YYMAXDEPTH
  980 # define YYMAXDEPTH 10000
  981 #endif
  982 
  983 
  984 #if YYERROR_VERBOSE
  985 
  986 # ifndef yystrlen
  987 #  if defined __GLIBC__ && defined _STRING_H
  988 #   define yystrlen strlen
  989 #  else
  990 /* Return the length of YYSTR.  */
  991 static YYSIZE_T
  992 yystrlen (const char *yystr)
  993 {
  994   YYSIZE_T yylen;
  995   for (yylen = 0; yystr[yylen]; yylen++)
  996     continue;
  997   return yylen;
  998 }
  999 #  endif
 1000 # endif
 1001 
 1002 # ifndef yystpcpy
 1003 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
 1004 #   define yystpcpy stpcpy
 1005 #  else
 1006 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
 1007    YYDEST.  */
 1008 static char *
 1009 yystpcpy (char *yydest, const char *yysrc)
 1010 {
 1011   char *yyd = yydest;
 1012   const char *yys = yysrc;
 1013 
 1014   while ((*yyd++ = *yys++) != '\0')
 1015     continue;
 1016 
 1017   return yyd - 1;
 1018 }
 1019 #  endif
 1020 # endif
 1021 
 1022 # ifndef yytnamerr
 1023 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
 1024    quotes and backslashes, so that it's suitable for yyerror.  The
 1025    heuristic is that double-quoting is unnecessary unless the string
 1026    contains an apostrophe, a comma, or backslash (other than
 1027    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
 1028    null, do not copy; instead, return the length of what the result
 1029    would have been.  */
 1030 static YYSIZE_T
 1031 yytnamerr (char *yyres, const char *yystr)
 1032 {
 1033   if (*yystr == '"')
 1034     {
 1035       YYSIZE_T yyn = 0;
 1036       char const *yyp = yystr;
 1037 
 1038       for (;;)
 1039         switch (*++yyp)
 1040           {
 1041           case '\'':
 1042           case ',':
 1043             goto do_not_strip_quotes;
 1044 
 1045           case '\\':
 1046             if (*++yyp != '\\')
 1047               goto do_not_strip_quotes;
 1048             /* Fall through.  */
 1049           default:
 1050             if (yyres)
 1051               yyres[yyn] = *yyp;
 1052             yyn++;
 1053             break;
 1054 
 1055           case '"':
 1056             if (yyres)
 1057               yyres[yyn] = '\0';
 1058             return yyn;
 1059           }
 1060     do_not_strip_quotes: ;
 1061     }
 1062 
 1063   if (! yyres)
 1064     return yystrlen (yystr);
 1065 
 1066   return yystpcpy (yyres, yystr) - yyres;
 1067 }
 1068 # endif
 1069 
 1070 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
 1071    about the unexpected token YYTOKEN for the state stack whose top is
 1072    YYSSP.
 1073 
 1074    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
 1075    not large enough to hold the message.  In that case, also set
 1076    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
 1077    required number of bytes is too large to store.  */
 1078 static int
 1079 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
 1080                 yytype_int16 *yyssp, int yytoken)
 1081 {
 1082   YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
 1083   YYSIZE_T yysize = yysize0;
 1084   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
 1085   /* Internationalized format string. */
 1086   const char *yyformat = YY_NULLPTR;
 1087   /* Arguments of yyformat. */
 1088   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
 1089   /* Number of reported tokens (one for the "unexpected", one per
 1090      "expected"). */
 1091   int yycount = 0;
 1092 
 1093   /* There are many possibilities here to consider:
 1094      - If this state is a consistent state with a default action, then
 1095        the only way this function was invoked is if the default action
 1096        is an error action.  In that case, don't check for expected
 1097        tokens because there are none.
 1098      - The only way there can be no lookahead present (in yychar) is if
 1099        this state is a consistent state with a default action.  Thus,
 1100        detecting the absence of a lookahead is sufficient to determine
 1101        that there is no unexpected or expected token to report.  In that
 1102        case, just report a simple "syntax error".
 1103      - Don't assume there isn't a lookahead just because this state is a
 1104        consistent state with a default action.  There might have been a
 1105        previous inconsistent state, consistent state with a non-default
 1106        action, or user semantic action that manipulated yychar.
 1107      - Of course, the expected token list depends on states to have
 1108        correct lookahead information, and it depends on the parser not
 1109        to perform extra reductions after fetching a lookahead from the
 1110        scanner and before detecting a syntax error.  Thus, state merging
 1111        (from LALR or IELR) and default reductions corrupt the expected
 1112        token list.  However, the list is correct for canonical LR with
 1113        one exception: it will still contain any token that will not be
 1114        accepted due to an error action in a later state.
 1115   */
 1116   if (yytoken != YYEMPTY)
 1117     {
 1118       int yyn = yypact[*yyssp];
 1119       yyarg[yycount++] = yytname[yytoken];
 1120       if (!yypact_value_is_default (yyn))
 1121         {
 1122           /* Start YYX at -YYN if negative to avoid negative indexes in
 1123              YYCHECK.  In other words, skip the first -YYN actions for
 1124              this state because they are default actions.  */
 1125           int yyxbegin = yyn < 0 ? -yyn : 0;
 1126           /* Stay within bounds of both yycheck and yytname.  */
 1127           int yychecklim = YYLAST - yyn + 1;
 1128           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
 1129           int yyx;
 1130 
 1131           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
 1132             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
 1133                 && !yytable_value_is_error (yytable[yyx + yyn]))
 1134               {
 1135                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
 1136                   {
 1137                     yycount = 1;
 1138                     yysize = yysize0;
 1139                     break;
 1140                   }
 1141                 yyarg[yycount++] = yytname[yyx];
 1142                 {
 1143                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
 1144                   if (! (yysize <= yysize1
 1145                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
 1146                     return 2;
 1147                   yysize = yysize1;
 1148                 }
 1149               }
 1150         }
 1151     }
 1152 
 1153   switch (yycount)
 1154     {
 1155 # define YYCASE_(N, S)                      \
 1156       case N:                               \
 1157         yyformat = S;                       \
 1158       break
 1159       YYCASE_(0, YY_("syntax error"));
 1160       YYCASE_(1, YY_("syntax error, unexpected %s"));
 1161       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
 1162       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
 1163       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
 1164       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
 1165 # undef YYCASE_
 1166     }
 1167 
 1168   {
 1169     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
 1170     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
 1171       return 2;
 1172     yysize = yysize1;
 1173   }
 1174 
 1175   if (*yymsg_alloc < yysize)
 1176     {
 1177       *yymsg_alloc = 2 * yysize;
 1178       if (! (yysize <= *yymsg_alloc
 1179              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
 1180         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
 1181       return 1;
 1182     }
 1183 
 1184   /* Avoid sprintf, as that infringes on the user's name space.
 1185      Don't have undefined behavior even if the translation
 1186      produced a string with the wrong number of "%s"s.  */
 1187   {
 1188     char *yyp = *yymsg;
 1189     int yyi = 0;
 1190     while ((*yyp = *yyformat) != '\0')
 1191       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
 1192         {
 1193           yyp += yytnamerr (yyp, yyarg[yyi++]);
 1194           yyformat += 2;
 1195         }
 1196       else
 1197         {
 1198           yyp++;
 1199           yyformat++;
 1200         }
 1201   }
 1202   return 0;
 1203 }
 1204 #endif /* YYERROR_VERBOSE */
 1205 
 1206 /*-----------------------------------------------.
 1207 | Release the memory associated to this symbol.  |
 1208 `-----------------------------------------------*/
 1209 
 1210 static void
 1211 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
 1212 {
 1213   YYUSE (yyvaluep);
 1214   if (!yymsg)
 1215     yymsg = "Deleting";
 1216   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
 1217 
 1218   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
 1219   YYUSE (yytype);
 1220   YY_IGNORE_MAYBE_UNINITIALIZED_END
 1221 }
 1222 
 1223 
 1224 
 1225 
 1226 /* The lookahead symbol.  */
 1227 int yychar;
 1228 
 1229 /* The semantic value of the lookahead symbol.  */
 1230 YYSTYPE yylval;
 1231 /* Number of syntax errors so far.  */
 1232 int yynerrs;
 1233 
 1234 
 1235 /*----------.
 1236 | yyparse.  |
 1237 `----------*/
 1238 
 1239 int
 1240 yyparse (void)
 1241 {
 1242     int yystate;
 1243     /* Number of tokens to shift before error messages enabled.  */
 1244     int yyerrstatus;
 1245 
 1246     /* The stacks and their tools:
 1247        'yyss': related to states.
 1248        'yyvs': related to semantic values.
 1249 
 1250        Refer to the stacks through separate pointers, to allow yyoverflow
 1251        to reallocate them elsewhere.  */
 1252 
 1253     /* The state stack.  */
 1254     yytype_int16 yyssa[YYINITDEPTH];
 1255     yytype_int16 *yyss;
 1256     yytype_int16 *yyssp;
 1257 
 1258     /* The semantic value stack.  */
 1259     YYSTYPE yyvsa[YYINITDEPTH];
 1260     YYSTYPE *yyvs;
 1261     YYSTYPE *yyvsp;
 1262 
 1263     YYSIZE_T yystacksize;
 1264 
 1265   int yyn;
 1266   int yyresult;
 1267   /* Lookahead token as an internal (translated) token number.  */
 1268   int yytoken = 0;
 1269   /* The variables used to return semantic value and location from the
 1270      action routines.  */
 1271   YYSTYPE yyval;
 1272 
 1273 #if YYERROR_VERBOSE
 1274   /* Buffer for error messages, and its allocated size.  */
 1275   char yymsgbuf[128];
 1276   char *yymsg = yymsgbuf;
 1277   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
 1278 #endif
 1279 
 1280 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
 1281 
 1282   /* The number of symbols on the RHS of the reduced rule.
 1283      Keep to zero when no symbol should be popped.  */
 1284   int yylen = 0;
 1285 
 1286   yyssp = yyss = yyssa;
 1287   yyvsp = yyvs = yyvsa;
 1288   yystacksize = YYINITDEPTH;
 1289 
 1290   YYDPRINTF ((stderr, "Starting parse\n"));
 1291 
 1292   yystate = 0;
 1293   yyerrstatus = 0;
 1294   yynerrs = 0;
 1295   yychar = YYEMPTY; /* Cause a token to be read.  */
 1296   goto yysetstate;
 1297 
 1298 /*------------------------------------------------------------.
 1299 | yynewstate -- Push a new state, which is found in yystate.  |
 1300 `------------------------------------------------------------*/
 1301  yynewstate:
 1302   /* In all cases, when you get here, the value and location stacks
 1303      have just been pushed.  So pushing a state here evens the stacks.  */
 1304   yyssp++;
 1305 
 1306  yysetstate:
 1307   *yyssp = yystate;
 1308 
 1309   if (yyss + yystacksize - 1 <= yyssp)
 1310     {
 1311       /* Get the current used size of the three stacks, in elements.  */
 1312       YYSIZE_T yysize = yyssp - yyss + 1;
 1313 
 1314 #ifdef yyoverflow
 1315       {
 1316         /* Give user a chance to reallocate the stack.  Use copies of
 1317            these so that the &'s don't force the real ones into
 1318            memory.  */
 1319         YYSTYPE *yyvs1 = yyvs;
 1320         yytype_int16 *yyss1 = yyss;
 1321 
 1322         /* Each stack pointer address is followed by the size of the
 1323            data in use in that stack, in bytes.  This used to be a
 1324            conditional around just the two extra args, but that might
 1325            be undefined if yyoverflow is a macro.  */
 1326         yyoverflow (YY_("memory exhausted"),
 1327                     &yyss1, yysize * sizeof (*yyssp),
 1328                     &yyvs1, yysize * sizeof (*yyvsp),
 1329                     &yystacksize);
 1330 
 1331         yyss = yyss1;
 1332         yyvs = yyvs1;
 1333       }
 1334 #else /* no yyoverflow */
 1335 # ifndef YYSTACK_RELOCATE
 1336       goto yyexhaustedlab;
 1337 # else
 1338       /* Extend the stack our own way.  */
 1339       if (YYMAXDEPTH <= yystacksize)
 1340         goto yyexhaustedlab;
 1341       yystacksize *= 2;
 1342       if (YYMAXDEPTH < yystacksize)
 1343         yystacksize = YYMAXDEPTH;
 1344 
 1345       {
 1346         yytype_int16 *yyss1 = yyss;
 1347         union yyalloc *yyptr =
 1348           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
 1349         if (! yyptr)
 1350           goto yyexhaustedlab;
 1351         YYSTACK_RELOCATE (yyss_alloc, yyss);
 1352         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
 1353 #  undef YYSTACK_RELOCATE
 1354         if (yyss1 != yyssa)
 1355           YYSTACK_FREE (yyss1);
 1356       }
 1357 # endif
 1358 #endif /* no yyoverflow */
 1359 
 1360       yyssp = yyss + yysize - 1;
 1361       yyvsp = yyvs + yysize - 1;
 1362 
 1363       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
 1364                   (unsigned long int) yystacksize));
 1365 
 1366       if (yyss + yystacksize - 1 <= yyssp)
 1367         YYABORT;
 1368     }
 1369 
 1370   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
 1371 
 1372   if (yystate == YYFINAL)
 1373     YYACCEPT;
 1374 
 1375   goto yybackup;
 1376 
 1377 /*-----------.
 1378 | yybackup.  |
 1379 `-----------*/
 1380 yybackup:
 1381 
 1382   /* Do appropriate processing given the current state.  Read a
 1383      lookahead token if we need one and don't already have one.  */
 1384 
 1385   /* First try to decide what to do without reference to lookahead token.  */
 1386   yyn = yypact[yystate];
 1387   if (yypact_value_is_default (yyn))
 1388     goto yydefault;
 1389 
 1390   /* Not known => get a lookahead token if don't already have one.  */
 1391 
 1392   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
 1393   if (yychar == YYEMPTY)
 1394     {
 1395       YYDPRINTF ((stderr, "Reading a token: "));
 1396       yychar = yylex ();
 1397     }
 1398 
 1399   if (yychar <= YYEOF)
 1400     {
 1401       yychar = yytoken = YYEOF;
 1402       YYDPRINTF ((stderr, "Now at end of input.\n"));
 1403     }
 1404   else
 1405     {
 1406       yytoken = YYTRANSLATE (yychar);
 1407       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
 1408     }
 1409 
 1410   /* If the proper action on seeing token YYTOKEN is to reduce or to
 1411      detect an error, take that action.  */
 1412   yyn += yytoken;
 1413   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
 1414     goto yydefault;
 1415   yyn = yytable[yyn];
 1416   if (yyn <= 0)
 1417     {
 1418       if (yytable_value_is_error (yyn))
 1419         goto yyerrlab;
 1420       yyn = -yyn;
 1421       goto yyreduce;
 1422     }
 1423 
 1424   /* Count tokens shifted since error; after three, turn off error
 1425      status.  */
 1426   if (yyerrstatus)
 1427     yyerrstatus--;
 1428 
 1429   /* Shift the lookahead token.  */
 1430   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
 1431 
 1432   /* Discard the shifted token.  */
 1433   yychar = YYEMPTY;
 1434 
 1435   yystate = yyn;
 1436   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
 1437   *++yyvsp = yylval;
 1438   YY_IGNORE_MAYBE_UNINITIALIZED_END
 1439 
 1440   goto yynewstate;
 1441 
 1442 
 1443 /*-----------------------------------------------------------.
 1444 | yydefault -- do the default action for the current state.  |
 1445 `-----------------------------------------------------------*/
 1446 yydefault:
 1447   yyn = yydefact[yystate];
 1448   if (yyn == 0)
 1449     goto yyerrlab;
 1450   goto yyreduce;
 1451 
 1452 
 1453 /*-----------------------------.
 1454 | yyreduce -- Do a reduction.  |
 1455 `-----------------------------*/
 1456 yyreduce:
 1457   /* yyn is the number of a rule to reduce with.  */
 1458   yylen = yyr2[yyn];
 1459 
 1460   /* If YYLEN is nonzero, implement the default value of the action:
 1461      '$$ = $1'.
 1462 
 1463      Otherwise, the following line sets YYVAL to garbage.
 1464      This behavior is undocumented and Bison
 1465      users should not rely upon it.  Assigning to YYVAL
 1466      unconditionally makes the parser a bit smaller, and it avoids a
 1467      GCC warning that YYVAL may be used uninitialized.  */
 1468   yyval = yyvsp[1-yylen];
 1469 
 1470 
 1471   YY_REDUCE_PRINT (yyn);
 1472   switch (yyn)
 1473     {
 1474         case 2:
 1475 #line 238 "parser.y" /* yacc.c:1646  */
 1476     {
 1477             _finalUnit = ut_get_dimensionless_unit_one(_unitSystem);
 1478             YYACCEPT;
 1479         }
 1480 #line 1481 "parser.c" /* yacc.c:1646  */
 1481     break;
 1482 
 1483   case 3:
 1484 #line 242 "parser.y" /* yacc.c:1646  */
 1485     {
 1486             _finalUnit = (yyvsp[0].unit);
 1487             YYACCEPT;
 1488         }
 1489 #line 1490 "parser.c" /* yacc.c:1646  */
 1490     break;
 1491 
 1492   case 4:
 1493 #line 246 "parser.y" /* yacc.c:1646  */
 1494     {
 1495             YYABORT;
 1496         }
 1497 #line 1498 "parser.c" /* yacc.c:1646  */
 1498     break;
 1499 
 1500   case 5:
 1501 #line 251 "parser.y" /* yacc.c:1646  */
 1502     {
 1503             (yyval.unit) = (yyvsp[0].unit);
 1504         }
 1505 #line 1506 "parser.c" /* yacc.c:1646  */
 1506     break;
 1507 
 1508   case 6:
 1509 #line 254 "parser.y" /* yacc.c:1646  */
 1510     {
 1511             (yyval.unit) = ut_offset((yyvsp[-2].unit), (yyvsp[0].rval));
 1512             ut_free((yyvsp[-2].unit));
 1513             if ((yyval.unit) == NULL)
 1514             YYERROR;
 1515         }
 1516 #line 1517 "parser.c" /* yacc.c:1646  */
 1517     break;
 1518 
 1519   case 7:
 1520 #line 260 "parser.y" /* yacc.c:1646  */
 1521     {
 1522             (yyval.unit) = ut_offset((yyvsp[-2].unit), (yyvsp[0].ival));
 1523             ut_free((yyvsp[-2].unit));
 1524             if ((yyval.unit) == NULL)
 1525             YYERROR;
 1526         }
 1527 #line 1528 "parser.c" /* yacc.c:1646  */
 1528     break;
 1529 
 1530   case 8:
 1531 #line 266 "parser.y" /* yacc.c:1646  */
 1532     {
 1533             (yyval.unit) = ut_offset_by_time((yyvsp[-2].unit), (yyvsp[0].rval));
 1534             ut_free((yyvsp[-2].unit));
 1535             if ((yyval.unit) == NULL)
 1536             YYERROR;
 1537         }
 1538 #line 1539 "parser.c" /* yacc.c:1646  */
 1539     break;
 1540 
 1541   case 9:
 1542 #line 272 "parser.y" /* yacc.c:1646  */
 1543     {
 1544             ut_status   prev = ut_get_status();
 1545             ut_free((yyvsp[-2].unit));
 1546             ut_set_status(prev);
 1547             YYERROR;
 1548         }
 1549 #line 1550 "parser.c" /* yacc.c:1646  */
 1550     break;
 1551 
 1552   case 10:
 1553 #line 280 "parser.y" /* yacc.c:1646  */
 1554     {
 1555             (yyval.unit) = (yyvsp[0].unit);
 1556                     _isTime = isTime((yyval.unit));
 1557         }
 1558 #line 1559 "parser.c" /* yacc.c:1646  */
 1559     break;
 1560 
 1561   case 11:
 1562 #line 284 "parser.y" /* yacc.c:1646  */
 1563     {
 1564             (yyval.unit) = ut_multiply((yyvsp[-1].unit), (yyvsp[0].unit));
 1565                     _isTime = isTime((yyval.unit));
 1566             ut_free((yyvsp[-1].unit));
 1567             ut_free((yyvsp[0].unit));
 1568             if ((yyval.unit) == NULL)
 1569             YYERROR;
 1570         }
 1571 #line 1572 "parser.c" /* yacc.c:1646  */
 1572     break;
 1573 
 1574   case 12:
 1575 #line 292 "parser.y" /* yacc.c:1646  */
 1576     {
 1577             ut_status   prev = ut_get_status();
 1578             ut_free((yyvsp[-1].unit));
 1579             ut_set_status(prev);
 1580             YYERROR;
 1581         }
 1582 #line 1583 "parser.c" /* yacc.c:1646  */
 1583     break;
 1584 
 1585   case 13:
 1586 #line 298 "parser.y" /* yacc.c:1646  */
 1587     {
 1588             (yyval.unit) = ut_multiply((yyvsp[-2].unit), (yyvsp[0].unit));
 1589                     _isTime = isTime((yyval.unit));
 1590             ut_free((yyvsp[-2].unit));
 1591             ut_free((yyvsp[0].unit));
 1592             if ((yyval.unit) == NULL)
 1593             YYERROR;
 1594         }
 1595 #line 1596 "parser.c" /* yacc.c:1646  */
 1596     break;
 1597 
 1598   case 14:
 1599 #line 306 "parser.y" /* yacc.c:1646  */
 1600     {
 1601             ut_status   prev = ut_get_status();
 1602             ut_free((yyvsp[-2].unit));
 1603             ut_set_status(prev);
 1604             YYERROR;
 1605         }
 1606 #line 1607 "parser.c" /* yacc.c:1646  */
 1607     break;
 1608 
 1609   case 15:
 1610 #line 312 "parser.y" /* yacc.c:1646  */
 1611     {
 1612             (yyval.unit) = ut_divide((yyvsp[-2].unit), (yyvsp[0].unit));
 1613                     _isTime = isTime((yyval.unit));
 1614             ut_free((yyvsp[-2].unit));
 1615             ut_free((yyvsp[0].unit));
 1616             if ((yyval.unit) == NULL)
 1617             YYERROR;
 1618         }
 1619 #line 1620 "parser.c" /* yacc.c:1646  */
 1620     break;
 1621 
 1622   case 16:
 1623 #line 320 "parser.y" /* yacc.c:1646  */
 1624     {
 1625             ut_status   prev = ut_get_status();
 1626             ut_free((yyvsp[-2].unit));
 1627             ut_set_status(prev);
 1628             YYERROR;
 1629         }
 1630 #line 1631 "parser.c" /* yacc.c:1646  */
 1631     break;
 1632 
 1633   case 17:
 1634 #line 328 "parser.y" /* yacc.c:1646  */
 1635     {
 1636             (yyval.unit) = (yyvsp[0].unit);
 1637         }
 1638 #line 1639 "parser.c" /* yacc.c:1646  */
 1639     break;
 1640 
 1641   case 18:
 1642 #line 331 "parser.y" /* yacc.c:1646  */
 1643     {
 1644             (yyval.unit) = ut_raise((yyvsp[-1].unit), (yyvsp[0].ival));
 1645             ut_free((yyvsp[-1].unit));
 1646             if ((yyval.unit) == NULL)
 1647             YYERROR;
 1648         }
 1649 #line 1650 "parser.c" /* yacc.c:1646  */
 1650     break;
 1651 
 1652   case 19:
 1653 #line 337 "parser.y" /* yacc.c:1646  */
 1654     {
 1655             (yyval.unit) = ut_raise((yyvsp[-1].unit), (yyvsp[0].ival));
 1656             ut_free((yyvsp[-1].unit));
 1657             if ((yyval.unit) == NULL)
 1658             YYERROR;
 1659         }
 1660 #line 1661 "parser.c" /* yacc.c:1646  */
 1661     break;
 1662 
 1663   case 20:
 1664 #line 343 "parser.y" /* yacc.c:1646  */
 1665     {
 1666             ut_status   prev = ut_get_status();
 1667             ut_free((yyvsp[-1].unit));
 1668             ut_set_status(prev);
 1669             YYERROR;
 1670         }
 1671 #line 1672 "parser.c" /* yacc.c:1646  */
 1672     break;
 1673 
 1674   case 21:
 1675 #line 351 "parser.y" /* yacc.c:1646  */
 1676     {
 1677             double  prefix = 1;
 1678             ut_unit*    unit = NULL;
 1679             char*   cp = (yyvsp[0].id);
 1680             int     symbolPrefixSeen = 0;
 1681 
 1682             while (*cp) {
 1683             size_t  nchar;
 1684             double  value;
 1685 
 1686             unit = ut_get_unit_by_name(_unitSystem, cp);
 1687 
 1688             if (unit != NULL)
 1689                 break;
 1690 
 1691             unit = ut_get_unit_by_symbol(_unitSystem, cp);
 1692 
 1693             if (unit != NULL)
 1694                 break;
 1695 
 1696             if (utGetPrefixByName(_unitSystem, cp, &value, &nchar)
 1697                 == UT_SUCCESS) {
 1698                 prefix *= value;
 1699                 cp += nchar;
 1700             }
 1701             else {
 1702                 if (!symbolPrefixSeen &&
 1703                     utGetPrefixBySymbol(_unitSystem, cp, &value,
 1704                     &nchar) == UT_SUCCESS) {
 1705                 symbolPrefixSeen = 1;
 1706                 prefix *= value;
 1707                 cp += nchar;
 1708                 }
 1709                 else {
 1710                 break;
 1711                 }
 1712             }
 1713             }
 1714 
 1715             free((yyvsp[0].id));
 1716 
 1717             if (unit == NULL) {
 1718             ut_set_status(UT_UNKNOWN);
 1719             YYERROR;
 1720             }
 1721 
 1722             (yyval.unit) = ut_scale(prefix, unit);
 1723 
 1724             ut_free(unit);
 1725 
 1726             if ((yyval.unit) == NULL)
 1727             YYERROR;
 1728         }
 1729 #line 1730 "parser.c" /* yacc.c:1646  */
 1730     break;
 1731 
 1732   case 22:
 1733 #line 404 "parser.y" /* yacc.c:1646  */
 1734     {
 1735             (yyval.unit) = (yyvsp[-1].unit);
 1736         }
 1737 #line 1738 "parser.c" /* yacc.c:1646  */
 1738     break;
 1739 
 1740   case 23:
 1741 #line 407 "parser.y" /* yacc.c:1646  */
 1742     {
 1743             ut_status   status = ut_get_status();
 1744             ut_free((yyvsp[-1].unit));
 1745             ut_set_status(status);
 1746             YYERROR;
 1747         }
 1748 #line 1749 "parser.c" /* yacc.c:1646  */
 1749     break;
 1750 
 1751   case 24:
 1752 #line 413 "parser.y" /* yacc.c:1646  */
 1753     {
 1754             (yyval.unit) = ut_log((yyvsp[-2].rval), (yyvsp[-1].unit));
 1755             ut_free((yyvsp[-1].unit));
 1756             if ((yyval.unit) == NULL)
 1757             YYERROR;
 1758         }
 1759 #line 1760 "parser.c" /* yacc.c:1646  */
 1760     break;
 1761 
 1762   case 25:
 1763 #line 419 "parser.y" /* yacc.c:1646  */
 1764     {
 1765             ut_status   status = ut_get_status();
 1766             ut_free((yyvsp[-1].unit));
 1767             ut_set_status(status);
 1768             YYERROR;
 1769         }
 1770 #line 1771 "parser.c" /* yacc.c:1646  */
 1771     break;
 1772 
 1773   case 26:
 1774 #line 425 "parser.y" /* yacc.c:1646  */
 1775     {
 1776             (yyval.unit) = ut_scale((yyvsp[0].rval),
 1777                         ut_get_dimensionless_unit_one(_unitSystem));
 1778         }
 1779 #line 1780 "parser.c" /* yacc.c:1646  */
 1780     break;
 1781 
 1782   case 27:
 1783 #line 431 "parser.y" /* yacc.c:1646  */
 1784     {
 1785             (yyval.rval) = (yyvsp[0].ival);
 1786         }
 1787 #line 1788 "parser.c" /* yacc.c:1646  */
 1788     break;
 1789 
 1790   case 28:
 1791 #line 434 "parser.y" /* yacc.c:1646  */
 1792     {
 1793             (yyval.rval) = (yyvsp[0].rval);
 1794         }
 1795 #line 1796 "parser.c" /* yacc.c:1646  */
 1796     break;
 1797 
 1798   case 29:
 1799 #line 439 "parser.y" /* yacc.c:1646  */
 1800     {
 1801             (yyval.rval) = (yyvsp[0].rval);
 1802         }
 1803 #line 1804 "parser.c" /* yacc.c:1646  */
 1804     break;
 1805 
 1806   case 30:
 1807 #line 442 "parser.y" /* yacc.c:1646  */
 1808     {
 1809             (yyval.rval) = (yyvsp[-1].rval) + (yyvsp[0].rval);
 1810         }
 1811 #line 1812 "parser.c" /* yacc.c:1646  */
 1812     break;
 1813 
 1814   case 31:
 1815 #line 445 "parser.y" /* yacc.c:1646  */
 1816     {
 1817             (yyval.rval) = (yyvsp[-2].rval) + ((yyvsp[-1].rval) - (yyvsp[0].rval));
 1818         }
 1819 #line 1820 "parser.c" /* yacc.c:1646  */
 1820     break;
 1821 
 1822   case 32:
 1823 #line 448 "parser.y" /* yacc.c:1646  */
 1824     {
 1825             int error = 0;
 1826 
 1827             if (strcasecmp((yyvsp[0].id), "UTC") != 0 &&
 1828                 strcasecmp((yyvsp[0].id), "GMT") != 0 &&
 1829                 strcasecmp((yyvsp[0].id), "Z") != 0) {
 1830             ut_set_status(UT_UNKNOWN);
 1831             error = 1;
 1832             }
 1833 
 1834             free((yyvsp[0].id));
 1835 
 1836             if (!error) {
 1837             (yyval.rval) = (yyvsp[-2].rval) + (yyvsp[-1].rval);
 1838             }
 1839             else {
 1840             YYERROR;
 1841             }
 1842         }
 1843 #line 1844 "parser.c" /* yacc.c:1646  */
 1844     break;
 1845 
 1846   case 33:
 1847 #line 467 "parser.y" /* yacc.c:1646  */
 1848     {
 1849             (yyval.rval) = (yyvsp[0].rval);
 1850         }
 1851 #line 1852 "parser.c" /* yacc.c:1646  */
 1852     break;
 1853 
 1854   case 34:
 1855 #line 470 "parser.y" /* yacc.c:1646  */
 1856     {
 1857             (yyval.rval) = (yyvsp[-1].rval) - (yyvsp[0].rval);
 1858         }
 1859 #line 1860 "parser.c" /* yacc.c:1646  */
 1860     break;
 1861 
 1862   case 35:
 1863 #line 473 "parser.y" /* yacc.c:1646  */
 1864     {
 1865             int error = 0;
 1866 
 1867             if (strcasecmp((yyvsp[0].id), "UTC") != 0 &&
 1868                 strcasecmp((yyvsp[0].id), "GMT") != 0 &&
 1869                 strcasecmp((yyvsp[0].id), "Z") != 0) {
 1870             ut_set_status(UT_UNKNOWN);
 1871             error = 1;
 1872             }
 1873 
 1874             free((yyvsp[0].id));
 1875 
 1876             if (!error) {
 1877             (yyval.rval) = (yyvsp[-1].rval);
 1878             }
 1879             else {
 1880             YYERROR;
 1881             }
 1882         }
 1883 #line 1884 "parser.c" /* yacc.c:1646  */
 1884     break;
 1885 
 1886 
 1887 #line 1888 "parser.c" /* yacc.c:1646  */
 1888       default: break;
 1889     }
 1890   /* User semantic actions sometimes alter yychar, and that requires
 1891      that yytoken be updated with the new translation.  We take the
 1892      approach of translating immediately before every use of yytoken.
 1893      One alternative is translating here after every semantic action,
 1894      but that translation would be missed if the semantic action invokes
 1895      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
 1896      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
 1897      incorrect destructor might then be invoked immediately.  In the
 1898      case of YYERROR or YYBACKUP, subsequent parser actions might lead
 1899      to an incorrect destructor call or verbose syntax error message
 1900      before the lookahead is translated.  */
 1901   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
 1902 
 1903   YYPOPSTACK (yylen);
 1904   yylen = 0;
 1905   YY_STACK_PRINT (yyss, yyssp);
 1906 
 1907   *++yyvsp = yyval;
 1908 
 1909   /* Now 'shift' the result of the reduction.  Determine what state
 1910      that goes to, based on the state we popped back to and the rule
 1911      number reduced by.  */
 1912 
 1913   yyn = yyr1[yyn];
 1914 
 1915   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
 1916   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
 1917     yystate = yytable[yystate];
 1918   else
 1919     yystate = yydefgoto[yyn - YYNTOKENS];
 1920 
 1921   goto yynewstate;
 1922 
 1923 
 1924 /*--------------------------------------.
 1925 | yyerrlab -- here on detecting error.  |
 1926 `--------------------------------------*/
 1927 yyerrlab:
 1928   /* Make sure we have latest lookahead translation.  See comments at
 1929      user semantic actions for why this is necessary.  */
 1930   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
 1931 
 1932   /* If not already recovering from an error, report this error.  */
 1933   if (!yyerrstatus)
 1934     {
 1935       ++yynerrs;
 1936 #if ! YYERROR_VERBOSE
 1937       yyerror (YY_("syntax error"));
 1938 #else
 1939 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
 1940                                         yyssp, yytoken)
 1941       {
 1942         char const *yymsgp = YY_("syntax error");
 1943         int yysyntax_error_status;
 1944         yysyntax_error_status = YYSYNTAX_ERROR;
 1945         if (yysyntax_error_status == 0)
 1946           yymsgp = yymsg;
 1947         else if (yysyntax_error_status == 1)
 1948           {
 1949             if (yymsg != yymsgbuf)
 1950               YYSTACK_FREE (yymsg);
 1951             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
 1952             if (!yymsg)
 1953               {
 1954                 yymsg = yymsgbuf;
 1955                 yymsg_alloc = sizeof yymsgbuf;
 1956                 yysyntax_error_status = 2;
 1957               }
 1958             else
 1959               {
 1960                 yysyntax_error_status = YYSYNTAX_ERROR;
 1961                 yymsgp = yymsg;
 1962               }
 1963           }
 1964         yyerror (yymsgp);
 1965         if (yysyntax_error_status == 2)
 1966           goto yyexhaustedlab;
 1967       }
 1968 # undef YYSYNTAX_ERROR
 1969 #endif
 1970     }
 1971 
 1972 
 1973 
 1974   if (yyerrstatus == 3)
 1975     {
 1976       /* If just tried and failed to reuse lookahead token after an
 1977          error, discard it.  */
 1978 
 1979       if (yychar <= YYEOF)
 1980         {
 1981           /* Return failure if at end of input.  */
 1982           if (yychar == YYEOF)
 1983             YYABORT;
 1984         }
 1985       else
 1986         {
 1987           yydestruct ("Error: discarding",
 1988                       yytoken, &yylval);
 1989           yychar = YYEMPTY;
 1990         }
 1991     }
 1992 
 1993   /* Else will try to reuse lookahead token after shifting the error
 1994      token.  */
 1995   goto yyerrlab1;
 1996 
 1997 
 1998 /*---------------------------------------------------.
 1999 | yyerrorlab -- error raised explicitly by YYERROR.  |
 2000 `---------------------------------------------------*/
 2001 yyerrorlab:
 2002 
 2003   /* Pacify compilers like GCC when the user code never invokes
 2004      YYERROR and the label yyerrorlab therefore never appears in user
 2005      code.  */
 2006   if (/*CONSTCOND*/ 0)
 2007      goto yyerrorlab;
 2008 
 2009   /* Do not reclaim the symbols of the rule whose action triggered
 2010      this YYERROR.  */
 2011   YYPOPSTACK (yylen);
 2012   yylen = 0;
 2013   YY_STACK_PRINT (yyss, yyssp);
 2014   yystate = *yyssp;
 2015   goto yyerrlab1;
 2016 
 2017 
 2018 /*-------------------------------------------------------------.
 2019 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
 2020 `-------------------------------------------------------------*/
 2021 yyerrlab1:
 2022   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
 2023 
 2024   for (;;)
 2025     {
 2026       yyn = yypact[yystate];
 2027       if (!yypact_value_is_default (yyn))
 2028         {
 2029           yyn += YYTERROR;
 2030           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
 2031             {
 2032               yyn = yytable[yyn];
 2033               if (0 < yyn)
 2034                 break;
 2035             }
 2036         }
 2037 
 2038       /* Pop the current state because it cannot handle the error token.  */
 2039       if (yyssp == yyss)
 2040         YYABORT;
 2041 
 2042 
 2043       yydestruct ("Error: popping",
 2044                   yystos[yystate], yyvsp);
 2045       YYPOPSTACK (1);
 2046       yystate = *yyssp;
 2047       YY_STACK_PRINT (yyss, yyssp);
 2048     }
 2049 
 2050   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
 2051   *++yyvsp = yylval;
 2052   YY_IGNORE_MAYBE_UNINITIALIZED_END
 2053 
 2054 
 2055   /* Shift the error token.  */
 2056   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
 2057 
 2058   yystate = yyn;
 2059   goto yynewstate;
 2060 
 2061 
 2062 /*-------------------------------------.
 2063 | yyacceptlab -- YYACCEPT comes here.  |
 2064 `-------------------------------------*/
 2065 yyacceptlab:
 2066   yyresult = 0;
 2067   goto yyreturn;
 2068 
 2069 /*-----------------------------------.
 2070 | yyabortlab -- YYABORT comes here.  |
 2071 `-----------------------------------*/
 2072 yyabortlab:
 2073   yyresult = 1;
 2074   goto yyreturn;
 2075 
 2076 #if !defined yyoverflow || YYERROR_VERBOSE
 2077 /*-------------------------------------------------.
 2078 | yyexhaustedlab -- memory exhaustion comes here.  |
 2079 `-------------------------------------------------*/
 2080 yyexhaustedlab:
 2081   yyerror (YY_("memory exhausted"));
 2082   yyresult = 2;
 2083   /* Fall through.  */
 2084 #endif
 2085 
 2086 yyreturn:
 2087   if (yychar != YYEMPTY)
 2088     {
 2089       /* Make sure we have latest lookahead translation.  See comments at
 2090          user semantic actions for why this is necessary.  */
 2091       yytoken = YYTRANSLATE (yychar);
 2092       yydestruct ("Cleanup: discarding lookahead",
 2093                   yytoken, &yylval);
 2094     }
 2095   /* Do not reclaim the symbols of the rule whose action triggered
 2096      this YYABORT or YYACCEPT.  */
 2097   YYPOPSTACK (yylen);
 2098   YY_STACK_PRINT (yyss, yyssp);
 2099   while (yyssp != yyss)
 2100     {
 2101       yydestruct ("Cleanup: popping",
 2102                   yystos[*yyssp], yyvsp);
 2103       YYPOPSTACK (1);
 2104     }
 2105 #ifndef yyoverflow
 2106   if (yyss != yyssa)
 2107     YYSTACK_FREE (yyss);
 2108 #endif
 2109 #if YYERROR_VERBOSE
 2110   if (yymsg != yymsgbuf)
 2111     YYSTACK_FREE (yymsg);
 2112 #endif
 2113   return yyresult;
 2114 }
 2115 #line 494 "parser.y" /* yacc.c:1906  */
 2116 
 2117 
 2118 #define yymaxdepth  utmaxdepth
 2119 #define yylval      utlval
 2120 #define yychar      utchar
 2121 #define yypact      utpact
 2122 #define yyr1        utr1
 2123 #define yyr2        utr2
 2124 #define yydef       utdef
 2125 #define yychk       utchk
 2126 #define yypgo       utpgo
 2127 #define yyact       utact
 2128 #define yyexca      utexca
 2129 #define yyerrflag   uterrflag
 2130 #define yynerrs     utnerrs
 2131 #define yyps        utps
 2132 #define yypv        utpv
 2133 #define yys     uts
 2134 #define yy_yys      utyys
 2135 #define yystate     utstate
 2136 #define yytmp       uttmp
 2137 #define yyv     utv
 2138 #define yy_yyv      utyyv
 2139 #define yyval       utval
 2140 #define yylloc      utlloc
 2141 #define yyreds      utreds
 2142 #define yytoks      uttoks
 2143 #define yylhs       utyylhs
 2144 #define yydefred    utyydefred
 2145 #define yydgoto     utyydgoto
 2146 #define yysindex    utyysindex
 2147 #define yyrindex    utyyrindex
 2148 #define yygindex    utyygindex
 2149 #define yytable     utyytable
 2150 #define yycheck     utyycheck
 2151 #define yyname      utyyname
 2152 #define yyrule      utyyrule
 2153 
 2154 #include "scanner.c"
 2155 
 2156 
 2157 /*
 2158  * Converts a string in the Latin-1 character set (ISO 8859-1) to the UTF-8
 2159  * character set.
 2160  *
 2161  * Arguments:
 2162  *      latin1String    Pointer to the string to be converted.  May be freed
 2163  *                      upon return.
 2164  * Returns:
 2165  *      NULL            Failure.  ut_handle_error_message() was called.
 2166  *      else            Pointer to UTF-8 representation of "string".  Must not
 2167  *                      be freed.  Subsequent calls may overwrite.
 2168  */
 2169 static const char*
 2170 latin1ToUtf8(
 2171     const char* const   latin1String)
 2172 {
 2173     static char*                utf8String = NULL;
 2174     static size_t               bufSize = 0;
 2175     size_t                      size;
 2176     const unsigned char*        in;
 2177     unsigned char*              out;
 2178 
 2179     assert(latin1String != NULL);
 2180 
 2181     size = 2 * strlen(latin1String) + 1;
 2182 
 2183     if (size > bufSize) {
 2184         char*   buf = realloc(utf8String, size);
 2185 
 2186         if (buf != NULL) {
 2187             utf8String = buf;
 2188             bufSize = size;
 2189         }
 2190         else {
 2191             ut_handle_error_message("Couldn't allocate %ld-byte buffer: %s",
 2192                 (unsigned long)size, strerror(errno));
 2193             return NULL;
 2194         }
 2195     }
 2196 
 2197     if (utf8String) {
 2198         for (in = (const unsigned char*)latin1String,
 2199                 out = (unsigned char*)utf8String; *in; ++in) {
 2200 #           define IS_ASCII(c) (((c) & 0x80) == 0)
 2201 
 2202             if (IS_ASCII(*in)) {
 2203                 *out++ = *in;
 2204             }
 2205             else {
 2206                 *out++ = 0xC0 | ((0xC0 & *in) >> 6);
 2207                 *out++ = 0x80 | (0x3F & *in);
 2208             }
 2209         }
 2210 
 2211         *out = 0;
 2212     }
 2213 
 2214     return utf8String;
 2215 }
 2216 
 2217 
 2218 /*
 2219  * Returns the binary representation of a unit corresponding to a string
 2220  * representation.
 2221  *
 2222  * Arguments:
 2223  *  system      Pointer to the unit-system in which the parsing will
 2224  *          occur.
 2225  *  string      The string to be parsed (e.g., "millimeters").  There
 2226  *          should be no leading or trailing whitespace in the
 2227  *          string.  See ut_trim().
 2228  *  encoding    The encoding of "string".
 2229  * Returns:
 2230  *  NULL        Failure.  "ut_get_status()" will be one of
 2231  *              UT_BAD_ARG      "system" or "string" is NULL.
 2232  *              UT_SYNTAX       "string" contained a syntax
 2233  *                      error.
 2234  *              UT_UNKNOWN      "string" contained an unknown
 2235  *                      identifier.
 2236  *              UT_OS       Operating-system failure.  See
 2237  *                      "errno".
 2238  *  else        Pointer to the unit corresponding to "string".
 2239  */
 2240 ut_unit*
 2241 ut_parse(
 2242     const ut_system* const  system,
 2243     const char* const       string,
 2244     ut_encoding         encoding)
 2245 {
 2246     ut_unit*    unit = NULL;        /* failure */
 2247 
 2248     if (system == NULL || string == NULL) {
 2249     ut_set_status(UT_BAD_ARG);
 2250     }
 2251     else {
 2252         const char*     utf8String;
 2253 
 2254         if (encoding != UT_LATIN1) {
 2255             utf8String = string;
 2256         }
 2257         else {
 2258             utf8String = latin1ToUtf8(string);
 2259             encoding = UT_UTF8;
 2260 
 2261             if (utf8String == NULL)
 2262                 ut_set_status(UT_OS);
 2263         }
 2264 
 2265         if (utf8String != NULL) {
 2266             YY_BUFFER_STATE buf = ut_scan_string(utf8String);
 2267 
 2268             _unitSystem = (ut_system*)system;
 2269             _encoding = encoding;
 2270             _restartScanner = 1;
 2271 
 2272 #if YYDEBUG
 2273             utdebug = 0;
 2274             ut_flex_debug = 0;
 2275 #endif
 2276 
 2277             _finalUnit = NULL;
 2278 
 2279             if (utparse() == 0) {
 2280                 int       status;
 2281                 ptrdiff_t n = yy_c_buf_p  - buf->yy_ch_buf;
 2282 
 2283                 if (n >= strlen(utf8String)) {
 2284                     unit = _finalUnit;  /* success */
 2285                     status = UT_SUCCESS;
 2286                 }
 2287                 else {
 2288                     /*
 2289                      * Parsing terminated before the end of the string.
 2290                      */
 2291                     ut_free(_finalUnit);
 2292                     status = UT_SYNTAX;
 2293                 }
 2294 
 2295                 ut_set_status(status);
 2296             }
 2297 
 2298             ut_delete_buffer(buf);
 2299         }                               /* utf8String != NULL */
 2300     }                                   /* valid arguments */
 2301 
 2302     return unit;
 2303 }