/* A Bison parser, made by GNU Bison 3.8.2.  */

/* Bison implementation for Yacc-like parsers in C

   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
   Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */

/* As a special exception, you may create a larger work that contains
   part or all of the Bison parser skeleton and distribute that work
   under terms of your choice, so long as that work isn't itself a
   parser generator using the skeleton or a modified version thereof
   as a parser skeleton.  Alternatively, if you modify or redistribute
   the parser skeleton itself, you may (at your option) remove this
   special exception, which will cause the skeleton and the resulting
   Bison output files to be licensed under the GNU General Public
   License without this special exception.

   This special exception was added by the Free Software Foundation in
   version 2.2 of Bison.  */

/* C LALR(1) parser skeleton written by Richard Stallman, by
   simplifying the original so-called "semantic" parser.  */

/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
   especially those whose name start with YY_ or yy_.  They are
   private implementation details that can be changed or removed.  */

/* All symbols defined below should begin with yy or YY, to avoid
   infringing on user name space.  This should be done even for local
   variables, as they might otherwise be expanded by user macros.
   There are some unavoidable exceptions within include files to
   define necessary library symbols; they are noted "INFRINGES ON
   USER NAME SPACE" below.  */

/* Identify Bison output, and Bison version.  */
#define YYBISON 30802

/* Bison version string.  */
#define YYBISON_VERSION "3.8.2"

/* Skeleton name.  */
#define YYSKELETON_NAME "yacc.c"

/* Pure parsers.  */
#define YYPURE 2

/* Push parsers.  */
#define YYPUSH 0

/* Pull parsers.  */
#define YYPULL 1




/* First part of user prologue.  */
#line 8 "query_parser.y"

/*
 * query_parser.y - yacc/bison grammar for the PCP time series language
 *
 * Copyright (c) 2017-2022 Red Hat.
 * Copyright (c) 2020 Yushan ZHANG.
 * Copyright (c) 2022 Shiyao CHEN.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 */

#include <ctype.h>
#include "query.h"
#include "load.h"
#include "schema.h"
#include "util.h"
#include "libpcp.h"

typedef struct PARSER {
    char	*yy_input;
    char	*yy_lexicon;
    int		yy_lexpeek;
    int		yy_error;
    sds		yy_errstr;
    char	*yy_tokbuf;
    int 	yy_tokbuflen;
    meta_t	yy_meta;
    sds		yy_base;
    node_t	*yy_np;
    series_t	yy_series;
} PARSER;

typedef union {
    sds		s;
    node_t	*n;
    meta_t	m;
} YYSTYPE;

#define YYSTYPE_IS_DECLARED 1
static int yylex(YYSTYPE *, PARSER *);
static int yyerror(PARSER *, const char *);

static int series_lex(YYSTYPE *, PARSER *);
static int series_error(PARSER *, const char *);
static void gramerr(PARSER *, const char *, const char *, char *);

static node_t *newnode(int);
static node_t *newmetric(sds);
static node_t *newmetricquery(sds, node_t *);
static node_t *newtree(int, node_t *, node_t *);
static int newaligntime(PARSER *, sds);
static int newstarttime(PARSER *, sds);
static int newinterval(PARSER *, sds);
static int newendtime(PARSER *, sds);
static int newrange(PARSER *, sds);
static int newtimezone(PARSER *, sds);
static int newsamples(PARSER *, sds);
static int newoffset(PARSER *, sds);
static char *n_type_str(int);
static char *n_type_c(int);
static char *l_type_str(int);

#line 142 "query_parser.tab.c"

# ifndef YY_CAST
#  ifdef __cplusplus
#   define YY_CAST(Type, Val) static_cast<Type> (Val)
#   define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
#  else
#   define YY_CAST(Type, Val) ((Type) (Val))
#   define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
#  endif
# endif
# ifndef YY_NULLPTR
#  if defined __cplusplus
#   if 201103L <= __cplusplus
#    define YY_NULLPTR nullptr
#   else
#    define YY_NULLPTR 0
#   endif
#  else
#   define YY_NULLPTR ((void*)0)
#  endif
# endif

#include "query_parser.tab.h"
/* Symbol kind.  */
enum yysymbol_kind_t
{
  YYSYMBOL_YYEMPTY = -2,
  YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
  YYSYMBOL_YYerror = 1,                    /* error  */
  YYSYMBOL_YYUNDEF = 2,                    /* "invalid token"  */
  YYSYMBOL_L_UNDEF = 3,                    /* L_UNDEF  */
  YYSYMBOL_L_ERROR = 4,                    /* L_ERROR  */
  YYSYMBOL_L_EOS = 5,                      /* L_EOS  */
  YYSYMBOL_L_PLUS = 6,                     /* L_PLUS  */
  YYSYMBOL_L_MINUS = 7,                    /* L_MINUS  */
  YYSYMBOL_L_STAR = 8,                     /* L_STAR  */
  YYSYMBOL_L_SLASH = 9,                    /* L_SLASH  */
  YYSYMBOL_L_COLON = 10,                   /* L_COLON  */
  YYSYMBOL_L_LPAREN = 11,                  /* L_LPAREN  */
  YYSYMBOL_L_RPAREN = 12,                  /* L_RPAREN  */
  YYSYMBOL_L_LBRACE = 13,                  /* L_LBRACE  */
  YYSYMBOL_L_RBRACE = 14,                  /* L_RBRACE  */
  YYSYMBOL_L_LSQUARE = 15,                 /* L_LSQUARE  */
  YYSYMBOL_L_RSQUARE = 16,                 /* L_RSQUARE  */
  YYSYMBOL_L_ABS = 17,                     /* L_ABS  */
  YYSYMBOL_L_FLOOR = 18,                   /* L_FLOOR  */
  YYSYMBOL_L_LOG = 19,                     /* L_LOG  */
  YYSYMBOL_L_SQRT = 20,                    /* L_SQRT  */
  YYSYMBOL_L_ROUND = 21,                   /* L_ROUND  */
  YYSYMBOL_L_AVG = 22,                     /* L_AVG  */
  YYSYMBOL_L_AVG_INST = 23,                /* L_AVG_INST  */
  YYSYMBOL_L_AVG_SAMPLE = 24,              /* L_AVG_SAMPLE  */
  YYSYMBOL_L_COUNT = 25,                   /* L_COUNT  */
  YYSYMBOL_L_DELTA = 26,                   /* L_DELTA  */
  YYSYMBOL_L_MAX = 27,                     /* L_MAX  */
  YYSYMBOL_L_MAX_INST = 28,                /* L_MAX_INST  */
  YYSYMBOL_L_MAX_SAMPLE = 29,              /* L_MAX_SAMPLE  */
  YYSYMBOL_L_MIN = 30,                     /* L_MIN  */
  YYSYMBOL_L_MIN_INST = 31,                /* L_MIN_INST  */
  YYSYMBOL_L_MIN_SAMPLE = 32,              /* L_MIN_SAMPLE  */
  YYSYMBOL_L_SUM = 33,                     /* L_SUM  */
  YYSYMBOL_L_SUM_INST = 34,                /* L_SUM_INST  */
  YYSYMBOL_L_SUM_SAMPLE = 35,              /* L_SUM_SAMPLE  */
  YYSYMBOL_L_STDEV_INST = 36,              /* L_STDEV_INST  */
  YYSYMBOL_L_STDEV_SAMPLE = 37,            /* L_STDEV_SAMPLE  */
  YYSYMBOL_L_TOPK_INST = 38,               /* L_TOPK_INST  */
  YYSYMBOL_L_TOPK_SAMPLE = 39,             /* L_TOPK_SAMPLE  */
  YYSYMBOL_L_NTH_PERCENTILE_INST = 40,     /* L_NTH_PERCENTILE_INST  */
  YYSYMBOL_L_NTH_PERCENTILE_SAMPLE = 41,   /* L_NTH_PERCENTILE_SAMPLE  */
  YYSYMBOL_L_ANON = 42,                    /* L_ANON  */
  YYSYMBOL_L_RATE = 43,                    /* L_RATE  */
  YYSYMBOL_L_INSTANT = 44,                 /* L_INSTANT  */
  YYSYMBOL_L_LT = 45,                      /* L_LT  */
  YYSYMBOL_L_LEQ = 46,                     /* L_LEQ  */
  YYSYMBOL_L_EQ = 47,                      /* L_EQ  */
  YYSYMBOL_L_GLOB = 48,                    /* L_GLOB  */
  YYSYMBOL_L_GEQ = 49,                     /* L_GEQ  */
  YYSYMBOL_L_GT = 50,                      /* L_GT  */
  YYSYMBOL_L_NEQ = 51,                     /* L_NEQ  */
  YYSYMBOL_L_REQ = 52,                     /* L_REQ  */
  YYSYMBOL_L_RNE = 53,                     /* L_RNE  */
  YYSYMBOL_L_AND = 54,                     /* L_AND  */
  YYSYMBOL_L_OR = 55,                      /* L_OR  */
  YYSYMBOL_L_MKCONST = 56,                 /* L_MKCONST  */
  YYSYMBOL_L_RESCALE = 57,                 /* L_RESCALE  */
  YYSYMBOL_L_DEFINED = 58,                 /* L_DEFINED  */
  YYSYMBOL_L_TYPE = 59,                    /* L_TYPE  */
  YYSYMBOL_L_SEMANTICS = 60,               /* L_SEMANTICS  */
  YYSYMBOL_L_UNITS = 61,                   /* L_UNITS  */
  YYSYMBOL_L_ASSIGN = 62,                  /* L_ASSIGN  */
  YYSYMBOL_L_COMMA = 63,                   /* L_COMMA  */
  YYSYMBOL_L_INTERVAL = 64,                /* L_INTERVAL  */
  YYSYMBOL_L_TIMEZONE = 65,                /* L_TIMEZONE  */
  YYSYMBOL_L_ALIGN = 66,                   /* L_ALIGN  */
  YYSYMBOL_L_START = 67,                   /* L_START  */
  YYSYMBOL_L_FINISH = 68,                  /* L_FINISH  */
  YYSYMBOL_L_SAMPLES = 69,                 /* L_SAMPLES  */
  YYSYMBOL_L_OFFSET = 70,                  /* L_OFFSET  */
  YYSYMBOL_EVENT_UNIT = 71,                /* EVENT_UNIT  */
  YYSYMBOL_TIME_UNIT = 72,                 /* TIME_UNIT  */
  YYSYMBOL_SPACE_UNIT = 73,                /* SPACE_UNIT  */
  YYSYMBOL_L_INTEGER = 74,                 /* L_INTEGER  */
  YYSYMBOL_L_DOUBLE = 75,                  /* L_DOUBLE  */
  YYSYMBOL_L_NAME = 76,                    /* L_NAME  */
  YYSYMBOL_L_STRING = 77,                  /* L_STRING  */
  YYSYMBOL_L_RANGE = 78,                   /* L_RANGE  */
  YYSYMBOL_YYACCEPT = 79,                  /* $accept  */
  YYSYMBOL_query = 80,                     /* query  */
  YYSYMBOL_vector = 81,                    /* vector  */
  YYSYMBOL_exprlist = 82,                  /* exprlist  */
  YYSYMBOL_exprval = 83,                   /* exprval  */
  YYSYMBOL_string = 84,                    /* string  */
  YYSYMBOL_number = 85,                    /* number  */
  YYSYMBOL_integer = 86,                   /* integer  */
  YYSYMBOL_timelist = 87,                  /* timelist  */
  YYSYMBOL_timespec = 88,                  /* timespec  */
  YYSYMBOL_timeexpr = 89,                  /* timeexpr  */
  YYSYMBOL_expr = 90,                      /* expr  */
  YYSYMBOL_val_vec = 91,                   /* val_vec  */
  YYSYMBOL_sid_vec = 92,                   /* sid_vec  */
  YYSYMBOL_func_sid = 93,                  /* func_sid  */
  YYSYMBOL_arithmetic_expr_sid = 94,       /* arithmetic_expr_sid  */
  YYSYMBOL_func = 95,                      /* func  */
  YYSYMBOL_arithmetic_expression = 96      /* arithmetic_expression  */
};
typedef enum yysymbol_kind_t yysymbol_kind_t;




#ifdef short
# undef short
#endif

/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
   <limits.h> and (if available) <stdint.h> are included
   so that the code can choose integer types of a good width.  */

#ifndef __PTRDIFF_MAX__
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
#  include <stdint.h> /* INFRINGES ON USER NAME SPACE */
#  define YY_STDINT_H
# endif
#endif

/* Narrow types that promote to a signed type and that can represent a
   signed or unsigned integer of at least N bits.  In tables they can
   save space and decrease cache pressure.  Promoting to a signed type
   helps avoid bugs in integer arithmetic.  */

#ifdef __INT_LEAST8_MAX__
typedef __INT_LEAST8_TYPE__ yytype_int8;
#elif defined YY_STDINT_H
typedef int_least8_t yytype_int8;
#else
typedef signed char yytype_int8;
#endif

#ifdef __INT_LEAST16_MAX__
typedef __INT_LEAST16_TYPE__ yytype_int16;
#elif defined YY_STDINT_H
typedef int_least16_t yytype_int16;
#else
typedef short yytype_int16;
#endif

/* Work around bug in HP-UX 11.23, which defines these macros
   incorrectly for preprocessor constants.  This workaround can likely
   be removed in 2023, as HPE has promised support for HP-UX 11.23
   (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
   <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>.  */
#ifdef __hpux
# undef UINT_LEAST8_MAX
# undef UINT_LEAST16_MAX
# define UINT_LEAST8_MAX 255
# define UINT_LEAST16_MAX 65535
#endif

#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
       && UINT_LEAST8_MAX <= INT_MAX)
typedef uint_least8_t yytype_uint8;
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
typedef unsigned char yytype_uint8;
#else
typedef short yytype_uint8;
#endif

#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
       && UINT_LEAST16_MAX <= INT_MAX)
typedef uint_least16_t yytype_uint16;
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
typedef unsigned short yytype_uint16;
#else
typedef int yytype_uint16;
#endif

#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
#  define YYPTRDIFF_T __PTRDIFF_TYPE__
#  define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
#  ifndef ptrdiff_t
#   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
#  endif
#  define YYPTRDIFF_T ptrdiff_t
#  define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
#  define YYPTRDIFF_T long
#  define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif

#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
#  define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
#  define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
#  define YYSIZE_T size_t
# else
#  define YYSIZE_T unsigned
# endif
#endif

#define YYSIZE_MAXIMUM                                  \
  YY_CAST (YYPTRDIFF_T,                                 \
           (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1)  \
            ? YYPTRDIFF_MAXIMUM                         \
            : YY_CAST (YYSIZE_T, -1)))

#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))


/* Stored state numbers (used for stacks). */
typedef yytype_int16 yy_state_t;

/* State numbers in computations.  */
typedef int yy_state_fast_t;

#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
#  if ENABLE_NLS
#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
#  endif
# endif
# ifndef YY_
#  define YY_(Msgid) Msgid
# endif
#endif


#ifndef YY_ATTRIBUTE_PURE
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
#  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
#  define YY_ATTRIBUTE_PURE
# endif
#endif

#ifndef YY_ATTRIBUTE_UNUSED
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
#  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# else
#  define YY_ATTRIBUTE_UNUSED
# endif
#endif

/* Suppress unused-variable warnings by "using" E.  */
#if ! defined lint || defined __GNUC__
# define YY_USE(E) ((void) (E))
#else
# define YY_USE(E) /* empty */
#endif

/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
#  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
    _Pragma ("GCC diagnostic push")                                     \
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
# else
#  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
    _Pragma ("GCC diagnostic push")                                     \
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")              \
    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# endif
# define YY_IGNORE_MAYBE_UNINITIALIZED_END      \
    _Pragma ("GCC diagnostic pop")
#else
# define YY_INITIAL_VALUE(Value) Value
#endif
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
#endif
#ifndef YY_INITIAL_VALUE
# define YY_INITIAL_VALUE(Value) /* Nothing. */
#endif

#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
# define YY_IGNORE_USELESS_CAST_BEGIN                          \
    _Pragma ("GCC diagnostic push")                            \
    _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
# define YY_IGNORE_USELESS_CAST_END            \
    _Pragma ("GCC diagnostic pop")
#endif
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_END
#endif


#define YY_ASSERT(E) ((void) (0 && (E)))

#if !defined yyoverflow

/* The parser invokes alloca or malloc; define the necessary symbols.  */

# ifdef YYSTACK_USE_ALLOCA
#  if YYSTACK_USE_ALLOCA
#   ifdef __GNUC__
#    define YYSTACK_ALLOC __builtin_alloca
#   elif defined __BUILTIN_VA_ARG_INCR
#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
#   elif defined _AIX
#    define YYSTACK_ALLOC __alloca
#   elif defined _MSC_VER
#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
#    define alloca _alloca
#   else
#    define YYSTACK_ALLOC alloca
#    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
      /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
#     ifndef EXIT_SUCCESS
#      define EXIT_SUCCESS 0
#     endif
#    endif
#   endif
#  endif
# endif

# ifdef YYSTACK_ALLOC
   /* Pacify GCC's 'empty if-body' warning.  */
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
#  ifndef YYSTACK_ALLOC_MAXIMUM
    /* The OS might guarantee only one guard page at the bottom of the stack,
       and a page size can be as small as 4096 bytes.  So we cannot safely
       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
       to allow for a few compiler-allocated temporary stack slots.  */
#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
#  endif
# else
#  define YYSTACK_ALLOC YYMALLOC
#  define YYSTACK_FREE YYFREE
#  ifndef YYSTACK_ALLOC_MAXIMUM
#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
#  endif
#  if (defined __cplusplus && ! defined EXIT_SUCCESS \
       && ! ((defined YYMALLOC || defined malloc) \
             && (defined YYFREE || defined free)))
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
#   ifndef EXIT_SUCCESS
#    define EXIT_SUCCESS 0
#   endif
#  endif
#  ifndef YYMALLOC
#   define YYMALLOC malloc
#   if ! defined malloc && ! defined EXIT_SUCCESS
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
#   endif
#  endif
#  ifndef YYFREE
#   define YYFREE free
#   if ! defined free && ! defined EXIT_SUCCESS
void free (void *); /* INFRINGES ON USER NAME SPACE */
#   endif
#  endif
# endif
#endif /* !defined yyoverflow */

#if (! defined yyoverflow \
     && (! defined __cplusplus \
         || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))

/* A type that is properly aligned for any stack member.  */
union yyalloc
{
  yy_state_t yyss_alloc;
  YYSTYPE yyvs_alloc;
};

/* The size of the maximum gap between one aligned stack and the next.  */
# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)

/* The size of an array large to enough to hold all stacks, each with
   N elements.  */
# define YYSTACK_BYTES(N) \
     ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
      + YYSTACK_GAP_MAXIMUM)

# define YYCOPY_NEEDED 1

/* Relocate STACK from its old location to the new one.  The
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
   elements in the stack, and YYPTR gives the new location of the
   stack.  Advance YYPTR to a properly aligned location for the next
   stack.  */
# define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
    do                                                                  \
      {                                                                 \
        YYPTRDIFF_T yynewbytes;                                         \
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
        Stack = &yyptr->Stack_alloc;                                    \
        yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
        yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
      }                                                                 \
    while (0)

#endif

#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
/* Copy COUNT objects from SRC to DST.  The source and destination do
   not overlap.  */
# ifndef YYCOPY
#  if defined __GNUC__ && 1 < __GNUC__
#   define YYCOPY(Dst, Src, Count) \
      __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
#  else
#   define YYCOPY(Dst, Src, Count)              \
      do                                        \
        {                                       \
          YYPTRDIFF_T yyi;                      \
          for (yyi = 0; yyi < (Count); yyi++)   \
            (Dst)[yyi] = (Src)[yyi];            \
        }                                       \
      while (0)
#  endif
# endif
#endif /* !YYCOPY_NEEDED */

/* YYFINAL -- State number of the termination state.  */
#define YYFINAL  85
/* YYLAST -- Last index in YYTABLE.  */
#define YYLAST   1313

/* YYNTOKENS -- Number of terminals.  */
#define YYNTOKENS  79
/* YYNNTS -- Number of nonterminals.  */
#define YYNNTS  18
/* YYNRULES -- Number of rules.  */
#define YYNRULES  196
/* YYNSTATES -- Number of states.  */
#define YYNSTATES  586

/* YYMAXUTOK -- Last valid token kind.  */
#define YYMAXUTOK   333


/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
   as returned by yylex, with out-of-bounds checking.  */
#define YYTRANSLATE(YYX)                                \
  (0 <= (YYX) && (YYX) <= YYMAXUTOK                     \
   ? YY_CAST (yysymbol_kind_t, yytranslate[YYX])        \
   : YYSYMBOL_YYUNDEF)

/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
   as returned by yylex.  */
static const yytype_int8 yytranslate[] =
{
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
      45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
      55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
      65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
      75,    76,    77,    78
};

#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
static const yytype_int16 yyrline[] =
{
       0,   196,   196,   197,   204,   210,   217,   219,   221,   228,
     231,   237,   242,   249,   256,   259,   260,   263,   269,   277,
     278,   286,   294,   295,   299,   300,   301,   305,   309,   313,
     317,   321,   325,   329,   333,   340,   344,   348,   352,   356,
     360,   366,   370,   374,   378,   384,   388,   395,   401,   410,
     415,   423,   429,   435,   441,   447,   453,   459,   465,   471,
     477,   484,   491,   497,   503,   509,   529,   549,   555,   561,
     567,   573,   579,   585,   591,   597,   603,   609,   616,   623,
     630,   637,   651,   665,   679,   693,   699,   705,   711,   717,
     723,   729,   735,   741,   747,   753,   760,   767,   773,   779,
     785,   791,   797,   803,   810,   817,   824,   831,   838,   845,
     852,   859,   866,   873,   880,   887,   894,   901,   908,   915,
     922,   929,   936,   943,   952,   958,   964,   970,   976,   983,
     989,   995,  1001,  1007,  1013,  1019,  1025,  1031,  1037,  1057,
    1077,  1083,  1089,  1095,  1101,  1108,  1115,  1121,  1127,  1133,
    1139,  1145,  1151,  1157,  1163,  1169,  1175,  1181,  1187,  1193,
    1199,  1205,  1211,  1218,  1225,  1232,  1239,  1253,  1267,  1281,
    1295,  1301,  1307,  1313,  1319,  1325,  1331,  1338,  1345,  1352,
    1359,  1366,  1373,  1380,  1387,  1394,  1401,  1408,  1415,  1422,
    1429,  1436,  1443,  1450,  1457,  1464,  1471
};
#endif

/** Accessing symbol of state STATE.  */
#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])

#if YYDEBUG || 0
/* The user-facing name of the symbol whose (internal) number is
   YYSYMBOL.  No bounds checking.  */
static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;

/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
static const char *const yytname[] =
{
  "\"end of file\"", "error", "\"invalid token\"", "L_UNDEF", "L_ERROR",
  "L_EOS", "L_PLUS", "L_MINUS", "L_STAR", "L_SLASH", "L_COLON", "L_LPAREN",
  "L_RPAREN", "L_LBRACE", "L_RBRACE", "L_LSQUARE", "L_RSQUARE", "L_ABS",
  "L_FLOOR", "L_LOG", "L_SQRT", "L_ROUND", "L_AVG", "L_AVG_INST",
  "L_AVG_SAMPLE", "L_COUNT", "L_DELTA", "L_MAX", "L_MAX_INST",
  "L_MAX_SAMPLE", "L_MIN", "L_MIN_INST", "L_MIN_SAMPLE", "L_SUM",
  "L_SUM_INST", "L_SUM_SAMPLE", "L_STDEV_INST", "L_STDEV_SAMPLE",
  "L_TOPK_INST", "L_TOPK_SAMPLE", "L_NTH_PERCENTILE_INST",
  "L_NTH_PERCENTILE_SAMPLE", "L_ANON", "L_RATE", "L_INSTANT", "L_LT",
  "L_LEQ", "L_EQ", "L_GLOB", "L_GEQ", "L_GT", "L_NEQ", "L_REQ", "L_RNE",
  "L_AND", "L_OR", "L_MKCONST", "L_RESCALE", "L_DEFINED", "L_TYPE",
  "L_SEMANTICS", "L_UNITS", "L_ASSIGN", "L_COMMA", "L_INTERVAL",
  "L_TIMEZONE", "L_ALIGN", "L_START", "L_FINISH", "L_SAMPLES", "L_OFFSET",
  "EVENT_UNIT", "TIME_UNIT", "SPACE_UNIT", "L_INTEGER", "L_DOUBLE",
  "L_NAME", "L_STRING", "L_RANGE", "$accept", "query", "vector",
  "exprlist", "exprval", "string", "number", "integer", "timelist",
  "timespec", "timeexpr", "expr", "val_vec", "sid_vec", "func_sid",
  "arithmetic_expr_sid", "func", "arithmetic_expression", YY_NULLPTR
};

static const char *
yysymbol_name (yysymbol_kind_t yysymbol)
{
  return yytname[yysymbol];
}
#endif

#define YYPACT_NINF (-92)

#define yypact_value_is_default(Yyn) \
  ((Yyn) == YYPACT_NINF)

#define YYTABLE_NINF (-1)

#define yytable_value_is_error(Yyn) \
  0

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
   STATE-NUM.  */
static const yytype_int16 yypact[] =
{
     300,    24,   -57,    11,    31,   129,   143,   177,   179,   182,
     193,   229,   331,   344,   355,   357,   359,   361,   367,   369,
     403,   407,   409,   424,   426,   439,   449,   467,   -92,   -92,
     515,   304,   -92,   428,   -92,   203,  1300,   248,   -92,   339,
     -92,   -92,   -92,   -13,   406,   236,   469,   472,   473,   475,
     476,   477,   479,   -92,   -14,   -92,   682,   682,   682,   682,
     682,   682,   682,   682,   682,   682,   682,   682,   682,   682,
     682,   682,   682,   682,   682,   682,   682,   682,   682,   682,
     682,   -92,    24,   -57,   364,   -92,   682,   742,   742,   742,
     742,   802,   802,   802,   802,   -92,   802,   802,   802,   802,
     -92,   742,   742,   742,   742,   237,    24,  1236,   233,   233,
    1236,  1236,   233,   233,  1236,    24,    24,    24,    24,   371,
     340,   371,   371,   371,   416,   445,   516,   -57,     1,   435,
     572,   579,   720,   728,   735,   743,   780,    18,    25,    32,
      39,   788,   795,   803,   840,   848,   855,   862,   873,   880,
     887,   894,   901,   908,   915,   922,   929,   936,   943,   950,
     957,   964,   971,   978,   985,   992,   999,  1006,  1013,  1020,
    1027,  1034,  1041,  1048,  1055,  1062,  1069,  1076,  1083,  1090,
    1097,  1104,  1111,  1118,  1125,  1132,  1139,  1146,  1153,  1160,
    1167,  1174,  1181,  1188,  1195,  1202,  1209,  1216,  1223,  1230,
    1237,  1244,  1251,  1258,  1265,   135,   140,   178,   199,   242,
     293,   343,   352,   356,   402,   417,   421,   425,   455,   460,
     464,  1272,  1279,  1286,  1293,   468,   526,   530,   644,   -11,
      19,   301,   -92,   -92,   -92,   -92,   -92,   511,   513,   514,
     518,   531,   534,   535,   564,   571,   581,   608,   635,   637,
     638,   659,   660,   686,   697,   713,   719,   722,   727,   734,
     737,   756,    72,   533,   317,   345,   317,   345,   -92,   -92,
     -92,   -92,   -92,   757,   773,   779,   782,   787,   794,   797,
     816,   817,   833,   839,   842,   847,   854,   861,   864,   872,
     879,   886,   893,   900,   907,   914,   921,   928,   570,   582,
     381,   404,   381,   404,   -92,   -92,   -92,   -92,   -92,   381,
     404,   381,   404,   -92,   -92,   -92,   -92,   -92,   317,   345,
     317,   345,   -92,   -92,   -92,   -92,   -92,   -92,   -57,   236,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,    24,   -57,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   233,   -92,   233,
     -92,   233,   -92,   233,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   452,   452,
     452,   452,   452,   452,   452,   452,   452,   452,   452,   452,
     452,   452,   452,   452,   -92,   -92,   -92,   -92,   654,   669,
     676,   677,   288,   786,   742,   742,   742,   742,   742,   742,
     742,   742,   742,   742,   742,   742,   742,   742,   742,   742,
     742,   742,   742,   742,   742,   742,   742,   742,   742,    24,
     742,   802,   802,   802,   802,   802,   802,   802,   802,   802,
     802,   802,   802,   802,   802,   802,   802,   802,   802,   802,
     802,   802,   802,   802,   802,   802,    24,   802,    20,   -10,
      27,   801,   934,   935,   941,   942,   948,   949,   955,   956,
     962,   963,   969,   970,   976,   977,   983,   984,   990,   991,
     997,   998,  1004,  1005,  1011,   -92,   -57,   -92,    -9,    -8,
     809,   791,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,   -92,
     -92,   -92,   -92,   -92,   -92,   -92,   -92,   175,   791,   -92,
     -92,   -57,   846,   176,   -92,   -92
};

/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
   Performed when YYTABLE does not specify something else to do.  Zero
   means the default is an error.  */
static const yytype_uint8 yydefact[] =
{
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,    21,    20,
      50,     0,     2,     0,    19,     0,     0,     0,   103,     0,
     176,    18,    17,     0,     0,    14,     0,     0,     0,     0,
       0,     0,     0,    34,     0,    23,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,    10,     0,     0,     0,     1,     0,     0,     0,     0,
       0,     0,     0,     0,     0,    12,     0,     0,     0,     0,
      11,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,    50,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,    50,     3,   189,   116,   118,   191,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,   177,   178,   181,   182,   190,   185,
     186,   193,   194,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,    50,     0,
     104,   105,   108,   109,   117,   112,   113,   120,   121,   106,
     107,   110,   111,   119,   114,   115,   122,   123,   179,   180,
     183,   184,   192,   187,   188,   195,   196,     7,     0,    13,
      43,    15,    16,    35,    36,    37,    44,    38,    39,    40,
      41,    42,    45,    46,    25,    26,    24,    27,    28,    31,
      32,    33,    29,    30,     9,    22,     0,     0,   140,    91,
      92,   141,   142,    93,    94,   143,   146,     0,    97,     0,
      98,     0,   147,     0,   148,    99,   100,   149,   150,   101,
     102,   151,   170,    85,    86,   171,   172,    87,    88,   173,
     174,    89,    90,   175,   126,    53,    54,   127,   128,    55,
      56,   129,   130,    57,    58,   131,   132,    59,    60,   133,
     134,    61,    62,   135,   136,    63,    64,   137,   152,    67,
      68,   153,   154,    69,    70,   155,   156,    71,    72,   157,
     158,    73,    74,   159,   160,    75,    76,   161,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,   124,    51,    52,   125,     0,     0,
       0,     0,    49,    48,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     4,     0,     8,     0,     0,
       0,    49,    48,   144,    95,    96,   145,   162,    77,    78,
     163,   164,    79,    80,   165,   166,    81,    82,   167,   168,
      83,    84,   169,   138,    65,    66,   139,     0,     0,    49,
       6,     0,    47,     0,     5,    47
};

/* YYPGOTO[NTERM-NUM].  */
static const yytype_int16 yypgoto[] =
{
     -92,   -92,   789,   -67,   -91,   433,     0,   216,   -65,   -17,
     739,   -89,   157,    59,   103,   -92,   208,   -92
};

/* YYDEFGOTO[NTERM-NUM].  */
static const yytype_int16 yydefgoto[] =
{
       0,    31,    32,    43,   330,    44,   263,    34,    54,   347,
      55,    45,    35,    36,    37,    38,    39,    40
};

/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
   positive, shift that token.  If negative, reduce the rule whose
   number is the opposite.  If YYTABLE_NINF, syntax error.  */
static const yytype_int16 yytable[] =
{
      33,   105,   126,   462,   551,   578,   579,    46,    47,    48,
      49,    50,    51,    52,   356,   229,   357,   329,   230,   335,
     336,    53,    56,   339,    87,    88,    89,    90,   342,   343,
     366,    91,    92,    93,    94,   463,   550,   368,    96,    97,
      98,    99,    57,   552,   370,   101,   102,   103,   104,   127,
     106,   372,   106,   106,   106,   106,    33,    33,    33,    33,
      33,    33,    33,    33,    33,    33,    33,    33,    33,    33,
      33,    33,    33,    33,    33,    33,    33,    33,    33,    33,
      33,   367,   127,   127,    33,   489,    33,   357,   369,   268,
     127,   299,   299,   304,   299,   371,   299,   299,   313,   299,
      41,    42,   373,   322,   349,   350,   351,   332,   333,   334,
     332,   332,   337,   338,   332,   130,   134,   138,   142,   146,
     150,   154,   158,   162,   166,   170,   174,   178,   182,   186,
     190,   194,   198,   202,   206,   210,   214,   218,   222,   226,
      58,    87,    88,    89,    90,   234,    91,    92,    93,    94,
     300,   302,   305,   307,    59,   309,   311,   314,   316,   131,
     135,   139,   143,   147,   151,   155,   159,   163,   167,   171,
     175,   179,   183,   187,   191,   195,   199,   203,   207,   211,
     215,   219,   223,   227,    96,    97,    98,    99,    60,   235,
      61,   582,   585,    62,   301,   303,   306,   308,   438,   310,
     312,   315,   317,   439,    63,   101,   102,   103,   104,    87,
      88,    89,    90,   129,   133,   137,   141,   145,   149,   153,
     157,   161,   165,   169,   173,   177,   181,   185,   189,   193,
     197,   201,   205,   209,   213,   217,   221,   225,   127,   127,
      64,   440,   327,   233,   264,   266,   269,   271,    87,    88,
      89,    90,   328,    95,    96,    97,    98,    99,   318,   320,
     323,   325,   441,   518,   132,   136,   140,   144,   148,   152,
     156,   160,   164,   168,   172,   176,   180,   184,   188,   192,
     196,   200,   204,   208,   212,   216,   220,   224,   228,   519,
     117,   118,   520,   545,   236,   265,   267,   270,   272,    91,
      92,    93,    94,   546,    85,   442,    81,    28,    29,   319,
     321,   324,   326,     1,    82,     2,    83,     3,     4,     5,
       6,     7,     8,     9,    10,    89,    90,    11,    12,    13,
      14,    15,    16,    17,    18,    19,    20,    21,    22,    23,
      24,    25,    65,    26,   100,   101,   102,   103,   104,    96,
      97,    98,    99,   103,   104,    66,   443,    27,   101,   102,
     103,   104,    87,    88,    89,    90,    67,   521,    68,   522,
      69,   523,    70,   524,    28,    29,    30,     1,    71,     2,
      72,     3,     4,     5,     6,     7,     8,     9,    10,    93,
      94,    11,    12,    13,    14,    15,    16,    17,    18,    19,
      20,    21,    22,    23,    24,    25,   444,    26,    91,    92,
      93,    94,    98,    99,    73,   445,   107,   348,    74,   446,
      75,    27,   548,    96,    97,    98,    99,   101,   102,   103,
     104,    87,    88,    89,    90,    76,    86,    77,    28,    29,
     231,    87,    88,    89,    90,   344,   345,   358,   346,   549,
      78,   108,   109,   110,   111,   112,   113,   114,   115,   116,
      79,    91,    92,    93,    94,   447,    96,    97,    98,    99,
     101,   102,   103,   104,    87,    88,    89,    90,    80,   119,
     448,   577,   120,   121,   449,   122,   123,   124,   450,   125,
     352,   299,   299,   299,   299,   299,   299,   299,   299,   299,
     299,   299,   299,   299,   299,   299,   299,   299,   299,   299,
     299,   299,   299,   299,   299,   299,   583,   299,   451,   353,
      81,   354,   464,   452,   465,   466,    28,   453,    82,   467,
      83,   458,    91,    92,    93,    94,    96,    97,    98,    99,
     331,   490,   468,   331,   331,   469,   470,   331,   340,   341,
     130,   134,   138,   142,   146,   150,   154,   158,   162,   166,
     170,   174,   178,   182,   186,   190,   194,   198,   202,   206,
     210,   214,   218,   222,   226,   471,   234,    84,    91,    92,
      93,    94,   472,   516,   359,    96,    97,    98,    99,   459,
     517,   360,   473,   460,   131,   135,   139,   143,   147,   151,
     155,   159,   163,   167,   171,   175,   179,   183,   187,   191,
     195,   199,   203,   207,   211,   215,   219,   223,   227,   474,
     235,   129,   133,   137,   141,   145,   149,   153,   157,   161,
     165,   169,   173,   177,   181,   185,   189,   193,   197,   201,
     205,   209,   213,   217,   221,   225,   475,   233,   476,   477,
     101,   102,   103,   104,   525,   526,   527,   528,   529,   530,
     531,   532,   533,   534,   535,   536,   537,   538,   539,   540,
     478,   479,   132,   136,   140,   144,   148,   152,   156,   160,
     164,   168,   172,   176,   180,   184,   188,   192,   196,   200,
     204,   208,   212,   216,   220,   224,   228,   480,   236,     3,
       4,     5,     6,     7,     8,     9,    10,   461,   481,    11,
      12,    13,    14,    15,    16,    17,    18,    19,    20,    21,
      22,    23,    24,    25,   482,    26,   101,   102,   103,   104,
     483,   541,   361,   484,    87,    88,    89,    90,   485,    27,
     362,    91,    92,    93,    94,   486,   542,   363,   487,    96,
      97,    98,    99,   543,   544,   364,    28,    29,   128,   237,
     238,   239,   240,   241,   242,   243,   244,   488,   491,   245,
     246,   247,   248,   249,   250,   251,   252,   253,   254,   255,
     256,   257,   258,   259,   492,   260,   101,   102,   103,   104,
     493,   547,   365,   494,    87,    88,    89,    90,   495,   261,
     374,    91,    92,    93,    94,   496,   581,   375,   497,    96,
      97,    98,    99,   553,   580,   376,    28,    29,   262,   273,
     274,   275,   276,   277,   278,   279,   280,   498,   499,   281,
     282,   283,   284,   285,   286,   287,   288,   289,   290,   291,
     292,   293,   294,   295,   500,   296,   101,   102,   103,   104,
     501,   584,   377,   502,    87,    88,    89,    90,   503,   297,
     378,    91,    92,    93,    94,   504,   355,   379,    96,    97,
      98,    99,   505,   232,   380,   506,    28,    29,   298,   101,
     102,   103,   104,   507,     0,   381,    87,    88,    89,    90,
     508,     0,   382,    91,    92,    93,    94,   509,     0,   383,
      96,    97,    98,    99,   510,     0,   384,   101,   102,   103,
     104,   511,     0,   385,    87,    88,    89,    90,   512,     0,
     386,    91,    92,    93,    94,   513,     0,   387,    96,    97,
      98,    99,   514,     0,   388,   101,   102,   103,   104,   515,
       0,   389,    87,    88,    89,    90,   554,   555,   390,    91,
      92,    93,    94,   556,   557,   391,    96,    97,    98,    99,
     558,   559,   392,   101,   102,   103,   104,   560,   561,   393,
      87,    88,    89,    90,   562,   563,   394,    91,    92,    93,
      94,   564,   565,   395,    96,    97,    98,    99,   566,   567,
     396,   101,   102,   103,   104,   568,   569,   397,    87,    88,
      89,    90,   570,   571,   398,    91,    92,    93,    94,   572,
     573,   399,    96,    97,    98,    99,   574,   575,   400,   101,
     102,   103,   104,   576,     0,   401,    87,    88,    89,    90,
       0,     0,   402,    91,    92,    93,    94,     0,     0,   403,
      96,    97,    98,    99,     0,     0,   404,   101,   102,   103,
     104,     0,     0,   405,    87,    88,    89,    90,     0,     0,
     406,    91,    92,    93,    94,     0,     0,   407,    96,    97,
      98,    99,     0,     0,   408,   101,   102,   103,   104,     0,
       0,   409,    87,    88,    89,    90,     0,     0,   410,    91,
      92,    93,    94,     0,     0,   411,    96,    97,    98,    99,
       0,     0,   412,   101,   102,   103,   104,     0,     0,   413,
      87,    88,    89,    90,     0,     0,   414,    91,    92,    93,
      94,     0,     0,   415,    96,    97,    98,    99,     0,     0,
     416,   101,   102,   103,   104,     0,     0,   417,    87,    88,
      89,    90,     0,     0,   418,    91,    92,    93,    94,     0,
       0,   419,    96,    97,    98,    99,     0,     0,   420,   101,
     102,   103,   104,     0,     0,   421,    87,    88,    89,    90,
       0,     0,   422,    91,    92,    93,    94,     0,     0,   423,
      96,    97,    98,    99,     0,     0,   424,   101,   102,   103,
     104,     0,     0,   425,    87,    88,    89,    90,     0,     0,
     426,    91,    92,    93,    94,     0,     0,   427,    96,    97,
      98,    99,     0,     0,   428,   101,   102,   103,   104,     0,
       0,   429,    87,    88,    89,    90,     0,     0,   430,    91,
      92,    93,    94,     0,     0,   431,    96,    97,    98,    99,
       0,     0,   432,   101,   102,   103,   104,     0,     0,   433,
      87,    88,    89,    90,     0,     0,   434,    91,    92,    93,
      94,     0,     0,   435,    96,    97,    98,    99,     0,     0,
     436,   101,   102,   103,   104,     0,     0,   437,    87,    88,
      89,    90,     0,     0,   454,    91,    92,    93,    94,     0,
       0,   455,    96,    97,    98,    99,     0,     0,   456,   101,
     102,   103,   104,     0,     0,   457,    91,    92,    93,    94,
      28,    29,    41,    42
};

static const yytype_int16 yycheck[] =
{
       0,    14,    16,    14,    14,    14,    14,    64,    65,    66,
      67,    68,    69,    70,    13,    82,    15,   106,    83,   110,
     111,    78,    11,   114,     6,     7,     8,     9,   117,   118,
      12,     6,     7,     8,     9,    16,    16,    12,     6,     7,
       8,     9,    11,    16,    12,     6,     7,     8,     9,    63,
      63,    12,    63,    63,    63,    63,    56,    57,    58,    59,
      60,    61,    62,    63,    64,    65,    66,    67,    68,    69,
      70,    71,    72,    73,    74,    75,    76,    77,    78,    79,
      80,    63,    63,    63,    84,    13,    86,    15,    63,    89,
      63,    91,    92,    93,    94,    63,    96,    97,    98,    99,
      76,    77,    63,   103,   121,   122,   123,   107,   108,   109,
     110,   111,   112,   113,   114,    56,    57,    58,    59,    60,
      61,    62,    63,    64,    65,    66,    67,    68,    69,    70,
      71,    72,    73,    74,    75,    76,    77,    78,    79,    80,
      11,     6,     7,     8,     9,    86,     6,     7,     8,     9,
      91,    92,    93,    94,    11,    96,    97,    98,    99,    56,
      57,    58,    59,    60,    61,    62,    63,    64,    65,    66,
      67,    68,    69,    70,    71,    72,    73,    74,    75,    76,
      77,    78,    79,    80,     6,     7,     8,     9,    11,    86,
      11,    16,    16,    11,    91,    92,    93,    94,    63,    96,
      97,    98,    99,    63,    11,     6,     7,     8,     9,     6,
       7,     8,     9,    56,    57,    58,    59,    60,    61,    62,
      63,    64,    65,    66,    67,    68,    69,    70,    71,    72,
      73,    74,    75,    76,    77,    78,    79,    80,    63,    63,
      11,    63,     5,    86,    87,    88,    89,    90,     6,     7,
       8,     9,    15,     5,     6,     7,     8,     9,   101,   102,
     103,   104,    63,   328,    56,    57,    58,    59,    60,    61,
      62,    63,    64,    65,    66,    67,    68,    69,    70,    71,
      72,    73,    74,    75,    76,    77,    78,    79,    80,   356,
      54,    55,   357,     5,    86,    87,    88,    89,    90,     6,
       7,     8,     9,    15,     0,    63,     5,    74,    75,   101,
     102,   103,   104,    13,    13,    15,    15,    17,    18,    19,
      20,    21,    22,    23,    24,     8,     9,    27,    28,    29,
      30,    31,    32,    33,    34,    35,    36,    37,    38,    39,
      40,    41,    11,    43,     5,     6,     7,     8,     9,     6,
       7,     8,     9,     8,     9,    11,    63,    57,     6,     7,
       8,     9,     6,     7,     8,     9,    11,   367,    11,   369,
      11,   371,    11,   373,    74,    75,    76,    13,    11,    15,
      11,    17,    18,    19,    20,    21,    22,    23,    24,     8,
       9,    27,    28,    29,    30,    31,    32,    33,    34,    35,
      36,    37,    38,    39,    40,    41,    63,    43,     6,     7,
       8,     9,     8,     9,    11,    63,    10,    77,    11,    63,
      11,    57,   489,     6,     7,     8,     9,     6,     7,     8,
       9,     6,     7,     8,     9,    11,     8,    11,    74,    75,
      76,     6,     7,     8,     9,    74,    75,    12,    77,   516,
      11,    45,    46,    47,    48,    49,    50,    51,    52,    53,
      11,     6,     7,     8,     9,    63,     6,     7,     8,     9,
       6,     7,     8,     9,     6,     7,     8,     9,    11,    10,
      63,   546,    10,    10,    63,    10,    10,    10,    63,    10,
      74,   491,   492,   493,   494,   495,   496,   497,   498,   499,
     500,   501,   502,   503,   504,   505,   506,   507,   508,   509,
     510,   511,   512,   513,   514,   515,   581,   517,    63,    74,
       5,     5,    11,    63,    11,    11,    74,    63,    13,    11,
      15,    63,     6,     7,     8,     9,     6,     7,     8,     9,
     107,     8,    11,   110,   111,    11,    11,   114,   115,   116,
     491,   492,   493,   494,   495,   496,   497,   498,   499,   500,
     501,   502,   503,   504,   505,   506,   507,   508,   509,   510,
     511,   512,   513,   514,   515,    11,   517,    62,     6,     7,
       8,     9,    11,    13,    12,     6,     7,     8,     9,    63,
       8,    12,    11,    63,   491,   492,   493,   494,   495,   496,
     497,   498,   499,   500,   501,   502,   503,   504,   505,   506,
     507,   508,   509,   510,   511,   512,   513,   514,   515,    11,
     517,   464,   465,   466,   467,   468,   469,   470,   471,   472,
     473,   474,   475,   476,   477,   478,   479,   480,   481,   482,
     483,   484,   485,   486,   487,   488,    11,   490,    11,    11,
       6,     7,     8,     9,   438,   439,   440,   441,   442,   443,
     444,   445,   446,   447,   448,   449,   450,   451,   452,   453,
      11,    11,   464,   465,   466,   467,   468,   469,   470,   471,
     472,   473,   474,   475,   476,   477,   478,   479,   480,   481,
     482,   483,   484,   485,   486,   487,   488,    11,   490,    17,
      18,    19,    20,    21,    22,    23,    24,    63,    11,    27,
      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
      38,    39,    40,    41,    11,    43,     6,     7,     8,     9,
      11,    77,    12,    11,     6,     7,     8,     9,    11,    57,
      12,     6,     7,     8,     9,    11,    77,    12,    11,     6,
       7,     8,     9,    77,    77,    12,    74,    75,    76,    17,
      18,    19,    20,    21,    22,    23,    24,    11,    11,    27,
      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
      38,    39,    40,    41,    11,    43,     6,     7,     8,     9,
      11,     5,    12,    11,     6,     7,     8,     9,    11,    57,
      12,     6,     7,     8,     9,    11,    15,    12,    11,     6,
       7,     8,     9,    12,     5,    12,    74,    75,    76,    17,
      18,    19,    20,    21,    22,    23,    24,    11,    11,    27,
      28,    29,    30,    31,    32,    33,    34,    35,    36,    37,
      38,    39,    40,    41,    11,    43,     6,     7,     8,     9,
      11,     5,    12,    11,     6,     7,     8,     9,    11,    57,
      12,     6,     7,     8,     9,    11,   127,    12,     6,     7,
       8,     9,    11,    84,    12,    11,    74,    75,    76,     6,
       7,     8,     9,    11,    -1,    12,     6,     7,     8,     9,
      11,    -1,    12,     6,     7,     8,     9,    11,    -1,    12,
       6,     7,     8,     9,    11,    -1,    12,     6,     7,     8,
       9,    11,    -1,    12,     6,     7,     8,     9,    11,    -1,
      12,     6,     7,     8,     9,    11,    -1,    12,     6,     7,
       8,     9,    11,    -1,    12,     6,     7,     8,     9,    11,
      -1,    12,     6,     7,     8,     9,    12,    12,    12,     6,
       7,     8,     9,    12,    12,    12,     6,     7,     8,     9,
      12,    12,    12,     6,     7,     8,     9,    12,    12,    12,
       6,     7,     8,     9,    12,    12,    12,     6,     7,     8,
       9,    12,    12,    12,     6,     7,     8,     9,    12,    12,
      12,     6,     7,     8,     9,    12,    12,    12,     6,     7,
       8,     9,    12,    12,    12,     6,     7,     8,     9,    12,
      12,    12,     6,     7,     8,     9,    12,    12,    12,     6,
       7,     8,     9,    12,    -1,    12,     6,     7,     8,     9,
      -1,    -1,    12,     6,     7,     8,     9,    -1,    -1,    12,
       6,     7,     8,     9,    -1,    -1,    12,     6,     7,     8,
       9,    -1,    -1,    12,     6,     7,     8,     9,    -1,    -1,
      12,     6,     7,     8,     9,    -1,    -1,    12,     6,     7,
       8,     9,    -1,    -1,    12,     6,     7,     8,     9,    -1,
      -1,    12,     6,     7,     8,     9,    -1,    -1,    12,     6,
       7,     8,     9,    -1,    -1,    12,     6,     7,     8,     9,
      -1,    -1,    12,     6,     7,     8,     9,    -1,    -1,    12,
       6,     7,     8,     9,    -1,    -1,    12,     6,     7,     8,
       9,    -1,    -1,    12,     6,     7,     8,     9,    -1,    -1,
      12,     6,     7,     8,     9,    -1,    -1,    12,     6,     7,
       8,     9,    -1,    -1,    12,     6,     7,     8,     9,    -1,
      -1,    12,     6,     7,     8,     9,    -1,    -1,    12,     6,
       7,     8,     9,    -1,    -1,    12,     6,     7,     8,     9,
      -1,    -1,    12,     6,     7,     8,     9,    -1,    -1,    12,
       6,     7,     8,     9,    -1,    -1,    12,     6,     7,     8,
       9,    -1,    -1,    12,     6,     7,     8,     9,    -1,    -1,
      12,     6,     7,     8,     9,    -1,    -1,    12,     6,     7,
       8,     9,    -1,    -1,    12,     6,     7,     8,     9,    -1,
      -1,    12,     6,     7,     8,     9,    -1,    -1,    12,     6,
       7,     8,     9,    -1,    -1,    12,     6,     7,     8,     9,
      -1,    -1,    12,     6,     7,     8,     9,    -1,    -1,    12,
       6,     7,     8,     9,    -1,    -1,    12,     6,     7,     8,
       9,    -1,    -1,    12,     6,     7,     8,     9,    -1,    -1,
      12,     6,     7,     8,     9,    -1,    -1,    12,     6,     7,
       8,     9,    -1,    -1,    12,     6,     7,     8,     9,    -1,
      -1,    12,     6,     7,     8,     9,    -1,    -1,    12,     6,
       7,     8,     9,    -1,    -1,    12,     6,     7,     8,     9,
      74,    75,    76,    77
};

/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
   state STATE-NUM.  */
static const yytype_int8 yystos[] =
{
       0,    13,    15,    17,    18,    19,    20,    21,    22,    23,
      24,    27,    28,    29,    30,    31,    32,    33,    34,    35,
      36,    37,    38,    39,    40,    41,    43,    57,    74,    75,
      76,    80,    81,    85,    86,    91,    92,    93,    94,    95,
      96,    76,    77,    82,    84,    90,    64,    65,    66,    67,
      68,    69,    70,    78,    87,    89,    11,    11,    11,    11,
      11,    11,    11,    11,    11,    11,    11,    11,    11,    11,
      11,    11,    11,    11,    11,    11,    11,    11,    11,    11,
      11,     5,    13,    15,    62,     0,     8,     6,     7,     8,
       9,     6,     7,     8,     9,     5,     6,     7,     8,     9,
       5,     6,     7,     8,     9,    14,    63,    10,    45,    46,
      47,    48,    49,    50,    51,    52,    53,    54,    55,    10,
      10,    10,    10,    10,    10,    10,    16,    63,    76,    91,
      92,    93,    95,    91,    92,    93,    95,    91,    92,    93,
      95,    91,    92,    93,    95,    91,    92,    93,    95,    91,
      92,    93,    95,    91,    92,    93,    95,    91,    92,    93,
      95,    91,    92,    93,    95,    91,    92,    93,    95,    91,
      92,    93,    95,    91,    92,    93,    95,    91,    92,    93,
      95,    91,    92,    93,    95,    91,    92,    93,    95,    91,
      92,    93,    95,    91,    92,    93,    95,    91,    92,    93,
      95,    91,    92,    93,    95,    91,    92,    93,    95,    91,
      92,    93,    95,    91,    92,    93,    95,    91,    92,    93,
      95,    91,    92,    93,    95,    91,    92,    93,    95,    82,
      87,    76,    81,    91,    92,    93,    95,    17,    18,    19,
      20,    21,    22,    23,    24,    27,    28,    29,    30,    31,
      32,    33,    34,    35,    36,    37,    38,    39,    40,    41,
      43,    57,    76,    85,    91,    95,    91,    95,    85,    91,
      95,    91,    95,    17,    18,    19,    20,    21,    22,    23,
      24,    27,    28,    29,    30,    31,    32,    33,    34,    35,
      36,    37,    38,    39,    40,    41,    43,    57,    76,    85,
      92,    93,    92,    93,    85,    92,    93,    92,    93,    92,
      93,    92,    93,    85,    92,    93,    92,    93,    91,    95,
      91,    95,    85,    91,    95,    91,    95,     5,    15,    90,
      83,    84,    85,    85,    85,    83,    83,    85,    85,    83,
      84,    84,    90,    90,    74,    75,    77,    88,    77,    88,
      88,    88,    74,    74,     5,    89,    13,    15,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    63,    12,    63,
      12,    63,    12,    63,    12,    12,    12,    12,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    12,    63,    63,
      63,    63,    63,    63,    63,    63,    63,    63,    63,    63,
      63,    63,    63,    63,    12,    12,    12,    12,    63,    63,
      63,    63,    14,    16,    11,    11,    11,    11,    11,    11,
      11,    11,    11,    11,    11,    11,    11,    11,    11,    11,
      11,    11,    11,    11,    11,    11,    11,    11,    11,    13,
       8,    11,    11,    11,    11,    11,    11,    11,    11,    11,
      11,    11,    11,    11,    11,    11,    11,    11,    11,    11,
      11,    11,    11,    11,    11,    11,    13,     8,    87,    82,
      87,    85,    85,    85,    85,    86,    86,    86,    86,    86,
      86,    86,    86,    86,    86,    86,    86,    86,    86,    86,
      86,    77,    77,    77,    77,     5,    15,     5,    82,    82,
      16,    14,    16,    12,    12,    12,    12,    12,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
      12,    12,    12,    12,    12,    12,    12,    87,    14,    14,
       5,    15,    16,    87,     5,    16
};

/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.  */
static const yytype_int8 yyr1[] =
{
       0,    79,    80,    80,    81,    81,    81,    81,    81,    81,
      81,    81,    81,    82,    82,    83,    83,    84,    84,    85,
      85,    86,    87,    87,    88,    88,    88,    89,    89,    89,
      89,    89,    89,    89,    89,    90,    90,    90,    90,    90,
      90,    90,    90,    90,    90,    90,    90,    91,    91,    92,
      92,    93,    93,    93,    93,    93,    93,    93,    93,    93,
      93,    93,    93,    93,    93,    93,    93,    93,    93,    93,
      93,    93,    93,    93,    93,    93,    93,    93,    93,    93,
      93,    93,    93,    93,    93,    93,    93,    93,    93,    93,
      93,    93,    93,    93,    93,    93,    93,    93,    93,    93,
      93,    93,    93,    93,    94,    94,    94,    94,    94,    94,
      94,    94,    94,    94,    94,    94,    94,    94,    94,    94,
      94,    94,    94,    94,    95,    95,    95,    95,    95,    95,
      95,    95,    95,    95,    95,    95,    95,    95,    95,    95,
      95,    95,    95,    95,    95,    95,    95,    95,    95,    95,
      95,    95,    95,    95,    95,    95,    95,    95,    95,    95,
      95,    95,    95,    95,    95,    95,    95,    95,    95,    95,
      95,    95,    95,    95,    95,    95,    95,    96,    96,    96,
      96,    96,    96,    96,    96,    96,    96,    96,    96,    96,
      96,    96,    96,    96,    96,    96,    96
};

/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.  */
static const yytype_int8 yyr2[] =
{
       0,     2,     1,     3,     5,     8,     7,     4,     5,     4,
       2,     2,     2,     3,     1,     1,     1,     1,     1,     1,
       1,     1,     3,     1,     1,     1,     1,     3,     3,     3,
       3,     3,     3,     3,     1,     3,     3,     3,     3,     3,
       3,     3,     3,     3,     3,     3,     3,     7,     4,     4,
       1,     4,     4,     4,     4,     4,     4,     4,     4,     4,
       4,     4,     4,     4,     4,     6,     6,     4,     4,     4,
       4,     4,     4,     4,     4,     4,     4,     6,     6,     6,
       6,     6,     6,     6,     6,     4,     4,     4,     4,     4,
       4,     4,     4,     4,     4,     6,     6,     4,     4,     4,
       4,     4,     4,     1,     3,     3,     3,     3,     3,     3,
       3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
       3,     3,     3,     3,     4,     4,     4,     4,     4,     4,
       4,     4,     4,     4,     4,     4,     4,     4,     6,     6,
       4,     4,     4,     4,     6,     6,     4,     4,     4,     4,
       4,     4,     4,     4,     4,     4,     4,     4,     4,     4,
       4,     4,     6,     6,     6,     6,     6,     6,     6,     6,
       4,     4,     4,     4,     4,     4,     1,     3,     3,     3,
       3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
       3,     3,     3,     3,     3,     3,     3
};


enum { YYENOMEM = -2 };

#define yyerrok         (yyerrstatus = 0)
#define yyclearin       (yychar = YYEMPTY)

#define YYACCEPT        goto yyacceptlab
#define YYABORT         goto yyabortlab
#define YYERROR         goto yyerrorlab
#define YYNOMEM         goto yyexhaustedlab


#define YYRECOVERING()  (!!yyerrstatus)

#define YYBACKUP(Token, Value)                                    \
  do                                                              \
    if (yychar == YYEMPTY)                                        \
      {                                                           \
        yychar = (Token);                                         \
        yylval = (Value);                                         \
        YYPOPSTACK (yylen);                                       \
        yystate = *yyssp;                                         \
        goto yybackup;                                            \
      }                                                           \
    else                                                          \
      {                                                           \
        yyerror (lp, YY_("syntax error: cannot back up")); \
        YYERROR;                                                  \
      }                                                           \
  while (0)

/* Backward compatibility with an undocumented macro.
   Use YYerror or YYUNDEF. */
#define YYERRCODE YYUNDEF


/* Enable debugging if requested.  */
#if YYDEBUG

# ifndef YYFPRINTF
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
#  define YYFPRINTF fprintf
# endif

# define YYDPRINTF(Args)                        \
do {                                            \
  if (yydebug)                                  \
    YYFPRINTF Args;                             \
} while (0)




# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                    \
do {                                                                      \
  if (yydebug)                                                            \
    {                                                                     \
      YYFPRINTF (stderr, "%s ", Title);                                   \
      yy_symbol_print (stderr,                                            \
                  Kind, Value, lp); \
      YYFPRINTF (stderr, "\n");                                           \
    }                                                                     \
} while (0)


/*-----------------------------------.
| Print this symbol's value on YYO.  |
`-----------------------------------*/

static void
yy_symbol_value_print (FILE *yyo,
                       yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, PARSER *lp)
{
  FILE *yyoutput = yyo;
  YY_USE (yyoutput);
  YY_USE (lp);
  if (!yyvaluep)
    return;
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  YY_USE (yykind);
  YY_IGNORE_MAYBE_UNINITIALIZED_END
}


/*---------------------------.
| Print this symbol on YYO.  |
`---------------------------*/

static void
yy_symbol_print (FILE *yyo,
                 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, PARSER *lp)
{
  YYFPRINTF (yyo, "%s %s (",
             yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));

  yy_symbol_value_print (yyo, yykind, yyvaluep, lp);
  YYFPRINTF (yyo, ")");
}

/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included).                                                   |
`------------------------------------------------------------------*/

static void
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
{
  YYFPRINTF (stderr, "Stack now");
  for (; yybottom <= yytop; yybottom++)
    {
      int yybot = *yybottom;
      YYFPRINTF (stderr, " %d", yybot);
    }
  YYFPRINTF (stderr, "\n");
}

# define YY_STACK_PRINT(Bottom, Top)                            \
do {                                                            \
  if (yydebug)                                                  \
    yy_stack_print ((Bottom), (Top));                           \
} while (0)


/*------------------------------------------------.
| Report that the YYRULE is going to be reduced.  |
`------------------------------------------------*/

static void
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
                 int yyrule, PARSER *lp)
{
  int yylno = yyrline[yyrule];
  int yynrhs = yyr2[yyrule];
  int yyi;
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
             yyrule - 1, yylno);
  /* The symbols being reduced.  */
  for (yyi = 0; yyi < yynrhs; yyi++)
    {
      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
      yy_symbol_print (stderr,
                       YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
                       &yyvsp[(yyi + 1) - (yynrhs)], lp);
      YYFPRINTF (stderr, "\n");
    }
}

# define YY_REDUCE_PRINT(Rule)          \
do {                                    \
  if (yydebug)                          \
    yy_reduce_print (yyssp, yyvsp, Rule, lp); \
} while (0)

/* Nonzero means print parse trace.  It is left uninitialized so that
   multiple parsers can coexist.  */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args) ((void) 0)
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */


/* YYINITDEPTH -- initial size of the parser's stacks.  */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif

/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
   if the built-in stack extension method is used).

   Do not make this value too large; the results are undefined if
   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
   evaluated with infinite-precision integer arithmetic.  */

#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif






/*-----------------------------------------------.
| Release the memory associated to this symbol.  |
`-----------------------------------------------*/

static void
yydestruct (const char *yymsg,
            yysymbol_kind_t yykind, YYSTYPE *yyvaluep, PARSER *lp)
{
  YY_USE (yyvaluep);
  YY_USE (lp);
  if (!yymsg)
    yymsg = "Deleting";
  YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);

  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  YY_USE (yykind);
  YY_IGNORE_MAYBE_UNINITIALIZED_END
}






/*----------.
| yyparse.  |
`----------*/

int
yyparse (PARSER *lp)
{
/* Lookahead token kind.  */
int yychar;


/* The semantic value of the lookahead symbol.  */
/* Default value used for initialization, for pacifying older GCCs
   or non-GCC compilers.  */
YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);

    /* Number of syntax errors so far.  */
    int yynerrs = 0;

    yy_state_fast_t yystate = 0;
    /* Number of tokens to shift before error messages enabled.  */
    int yyerrstatus = 0;

    /* Refer to the stacks through separate pointers, to allow yyoverflow
       to reallocate them elsewhere.  */

    /* Their size.  */
    YYPTRDIFF_T yystacksize = YYINITDEPTH;

    /* The state stack: array, bottom, top.  */
    yy_state_t yyssa[YYINITDEPTH];
    yy_state_t *yyss = yyssa;
    yy_state_t *yyssp = yyss;

    /* The semantic value stack: array, bottom, top.  */
    YYSTYPE yyvsa[YYINITDEPTH];
    YYSTYPE *yyvs = yyvsa;
    YYSTYPE *yyvsp = yyvs;

  int yyn;
  /* The return value of yyparse.  */
  int yyresult;
  /* Lookahead symbol kind.  */
  yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
  /* The variables used to return semantic value and location from the
     action routines.  */
  YYSTYPE yyval;



#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))

  /* The number of symbols on the RHS of the reduced rule.
     Keep to zero when no symbol should be popped.  */
  int yylen = 0;

  YYDPRINTF ((stderr, "Starting parse\n"));

  yychar = YYEMPTY; /* Cause a token to be read.  */

  goto yysetstate;


/*------------------------------------------------------------.
| yynewstate -- push a new state, which is found in yystate.  |
`------------------------------------------------------------*/
yynewstate:
  /* In all cases, when you get here, the value and location stacks
     have just been pushed.  So pushing a state here evens the stacks.  */
  yyssp++;


/*--------------------------------------------------------------------.
| yysetstate -- set current state (the top of the stack) to yystate.  |
`--------------------------------------------------------------------*/
yysetstate:
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
  YY_IGNORE_USELESS_CAST_BEGIN
  *yyssp = YY_CAST (yy_state_t, yystate);
  YY_IGNORE_USELESS_CAST_END
  YY_STACK_PRINT (yyss, yyssp);

  if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
    YYNOMEM;
#else
    {
      /* Get the current used size of the three stacks, in elements.  */
      YYPTRDIFF_T yysize = yyssp - yyss + 1;

# if defined yyoverflow
      {
        /* Give user a chance to reallocate the stack.  Use copies of
           these so that the &'s don't force the real ones into
           memory.  */
        yy_state_t *yyss1 = yyss;
        YYSTYPE *yyvs1 = yyvs;

        /* Each stack pointer address is followed by the size of the
           data in use in that stack, in bytes.  This used to be a
           conditional around just the two extra args, but that might
           be undefined if yyoverflow is a macro.  */
        yyoverflow (YY_("memory exhausted"),
                    &yyss1, yysize * YYSIZEOF (*yyssp),
                    &yyvs1, yysize * YYSIZEOF (*yyvsp),
                    &yystacksize);
        yyss = yyss1;
        yyvs = yyvs1;
      }
# else /* defined YYSTACK_RELOCATE */
      /* Extend the stack our own way.  */
      if (YYMAXDEPTH <= yystacksize)
        YYNOMEM;
      yystacksize *= 2;
      if (YYMAXDEPTH < yystacksize)
        yystacksize = YYMAXDEPTH;

      {
        yy_state_t *yyss1 = yyss;
        union yyalloc *yyptr =
          YY_CAST (union yyalloc *,
                   YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
        if (! yyptr)
          YYNOMEM;
        YYSTACK_RELOCATE (yyss_alloc, yyss);
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
#  undef YYSTACK_RELOCATE
        if (yyss1 != yyssa)
          YYSTACK_FREE (yyss1);
      }
# endif

      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;

      YY_IGNORE_USELESS_CAST_BEGIN
      YYDPRINTF ((stderr, "Stack size increased to %ld\n",
                  YY_CAST (long, yystacksize)));
      YY_IGNORE_USELESS_CAST_END

      if (yyss + yystacksize - 1 <= yyssp)
        YYABORT;
    }
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */


  if (yystate == YYFINAL)
    YYACCEPT;

  goto yybackup;


/*-----------.
| yybackup.  |
`-----------*/
yybackup:
  /* Do appropriate processing given the current state.  Read a
     lookahead token if we need one and don't already have one.  */

  /* First try to decide what to do without reference to lookahead token.  */
  yyn = yypact[yystate];
  if (yypact_value_is_default (yyn))
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* YYCHAR is either empty, or end-of-input, or a valid lookahead.  */
  if (yychar == YYEMPTY)
    {
      YYDPRINTF ((stderr, "Reading a token\n"));
      yychar = yylex (&yylval, lp);
    }

  if (yychar <= YYEOF)
    {
      yychar = YYEOF;
      yytoken = YYSYMBOL_YYEOF;
      YYDPRINTF ((stderr, "Now at end of input.\n"));
    }
  else if (yychar == YYerror)
    {
      /* The scanner already issued an error message, process directly
         to error recovery.  But do not keep the error token as
         lookahead, it is too special and may lead us to an endless
         loop in error recovery. */
      yychar = YYUNDEF;
      yytoken = YYSYMBOL_YYerror;
      goto yyerrlab1;
    }
  else
    {
      yytoken = YYTRANSLATE (yychar);
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    }

  /* If the proper action on seeing token YYTOKEN is to reduce or to
     detect an error, take that action.  */
  yyn += yytoken;
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (yytable_value_is_error (yyn))
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }

  /* Count tokens shifted since error; after three, turn off error
     status.  */
  if (yyerrstatus)
    yyerrstatus--;

  /* Shift the lookahead token.  */
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  yystate = yyn;
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  *++yyvsp = yylval;
  YY_IGNORE_MAYBE_UNINITIALIZED_END

  /* Discard the shifted token.  */
  yychar = YYEMPTY;
  goto yynewstate;


/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state.  |
`-----------------------------------------------------------*/
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;


/*-----------------------------.
| yyreduce -- do a reduction.  |
`-----------------------------*/
yyreduce:
  /* yyn is the number of a rule to reduce with.  */
  yylen = yyr2[yyn];

  /* If YYLEN is nonzero, implement the default value of the action:
     '$$ = $1'.

     Otherwise, the following line sets YYVAL to garbage.
     This behavior is undocumented and Bison
     users should not rely upon it.  Assigning to YYVAL
     unconditionally makes the parser a bit smaller, and it avoids a
     GCC warning that YYVAL may be used uninitialized.  */
  yyval = yyvsp[1-yylen];


  YY_REDUCE_PRINT (yyn);
  switch (yyn)
    {
  case 3: /* query: L_NAME L_ASSIGN vector  */
#line 198 "query_parser.y"
                { lp->yy_series.name = (yyvsp[-2].s);
		  (yyval.n) = lp->yy_series.expr;
		  YYACCEPT;
		}
#line 1741 "query_parser.tab.c"
    break;

  case 4: /* vector: L_NAME L_LBRACE exprlist L_RBRACE L_EOS  */
#line 205 "query_parser.y"
                { if ((lp->yy_np = newmetricquery((yyvsp[-4].s), (yyvsp[-2].n))) == NULL)
		      return -1;
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		  YYACCEPT;
		}
#line 1751 "query_parser.tab.c"
    break;

  case 5: /* vector: L_NAME L_LBRACE exprlist L_RBRACE L_LSQUARE timelist L_RSQUARE L_EOS  */
#line 211 "query_parser.y"
                { if ((lp->yy_np = newmetricquery((yyvsp[-7].s), (yyvsp[-5].n))) == NULL)
		      return -1;
		  lp->yy_np->time = lp->yy_series.time;
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		  YYACCEPT;
		}
#line 1762 "query_parser.tab.c"
    break;

  case 6: /* vector: L_LBRACE exprlist L_RBRACE L_LSQUARE timelist L_RSQUARE L_EOS  */
#line 218 "query_parser.y"
                { lp->yy_np = lp->yy_series.expr = (yyvsp[-5].n); YYACCEPT; }
#line 1768 "query_parser.tab.c"
    break;

  case 7: /* vector: L_LBRACE exprlist L_RBRACE L_EOS  */
#line 220 "query_parser.y"
                { lp->yy_np = lp->yy_series.expr = (yyvsp[-2].n); YYACCEPT; }
#line 1774 "query_parser.tab.c"
    break;

  case 8: /* vector: L_NAME L_LSQUARE timelist L_RSQUARE L_EOS  */
#line 222 "query_parser.y"
                { if ((lp->yy_np = newmetric((yyvsp[-4].s))) == NULL)
		      return -1;
		  lp->yy_np->time = lp->yy_series.time;
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		  YYACCEPT;
		}
#line 1785 "query_parser.tab.c"
    break;

  case 9: /* vector: L_LSQUARE timelist L_RSQUARE L_EOS  */
#line 229 "query_parser.y"
                { YYACCEPT;
		}
#line 1792 "query_parser.tab.c"
    break;

  case 10: /* vector: L_NAME L_EOS  */
#line 232 "query_parser.y"
                { if ((lp->yy_np = newmetric((yyvsp[-1].s))) == NULL)
		      return -1;
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		  YYACCEPT;
		}
#line 1802 "query_parser.tab.c"
    break;

  case 11: /* vector: func L_EOS  */
#line 238 "query_parser.y"
                { lp->yy_np = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		  YYACCEPT;
		}
#line 1811 "query_parser.tab.c"
    break;

  case 12: /* vector: func_sid L_EOS  */
#line 243 "query_parser.y"
                { lp->yy_np = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		  YYACCEPT;
		}
#line 1820 "query_parser.tab.c"
    break;

  case 13: /* exprlist: exprlist L_COMMA expr  */
#line 250 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AND)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_np;
		}
#line 1831 "query_parser.tab.c"
    break;

  case 17: /* string: L_STRING  */
#line 264 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STRING)) == NULL)
		      return -1;
		  lp->yy_np->value = (yyvsp[0].s);
		  (yyval.n) = lp->yy_np;
		}
#line 1841 "query_parser.tab.c"
    break;

  case 18: /* string: L_NAME  */
#line 270 "query_parser.y"
                { if ((lp->yy_np = newnode(N_NAME)) == NULL)
		      return -1;
		  lp->yy_np->value = (yyvsp[0].s);
		  (yyval.n) = lp->yy_np;
		}
#line 1851 "query_parser.tab.c"
    break;

  case 20: /* number: L_DOUBLE  */
#line 279 "query_parser.y"
                { if ((lp->yy_np = newnode(N_DOUBLE)) == NULL)
		      return -1;
		  lp->yy_np->value = (yyvsp[0].s);
		  (yyval.n) = lp->yy_np;
		}
#line 1861 "query_parser.tab.c"
    break;

  case 21: /* integer: L_INTEGER  */
#line 287 "query_parser.y"
                { if ((lp->yy_np = newnode(N_INTEGER)) == NULL)
		      return -1;
		  lp->yy_np->value = (yyvsp[0].s);
		  (yyval.n) = lp->yy_np;
		}
#line 1871 "query_parser.tab.c"
    break;

  case 27: /* timeexpr: L_INTERVAL L_COLON timespec  */
#line 306 "query_parser.y"
                { if (newinterval(lp, (yyvsp[0].s)) < 0)
		      return -1;
		}
#line 1879 "query_parser.tab.c"
    break;

  case 28: /* timeexpr: L_TIMEZONE L_COLON L_STRING  */
#line 310 "query_parser.y"
                { if (newtimezone(lp, (yyvsp[0].s)) < 0)
		      return -1;
		}
#line 1887 "query_parser.tab.c"
    break;

  case 29: /* timeexpr: L_SAMPLES L_COLON L_INTEGER  */
#line 314 "query_parser.y"
                { if (newsamples(lp, (yyvsp[0].s)) < 0)
		      return -1;
		}
#line 1895 "query_parser.tab.c"
    break;

  case 30: /* timeexpr: L_OFFSET L_COLON L_INTEGER  */
#line 318 "query_parser.y"
                { if (newoffset(lp, (yyvsp[0].s)) < 0)
		      return -1;
		}
#line 1903 "query_parser.tab.c"
    break;

  case 31: /* timeexpr: L_ALIGN L_COLON timespec  */
#line 322 "query_parser.y"
                { if (newaligntime(lp, (yyvsp[0].s)) < 0)
		      return -1;
		}
#line 1911 "query_parser.tab.c"
    break;

  case 32: /* timeexpr: L_START L_COLON timespec  */
#line 326 "query_parser.y"
                { if (newstarttime(lp, (yyvsp[0].s)) < 0)
		      return -1;
		}
#line 1919 "query_parser.tab.c"
    break;

  case 33: /* timeexpr: L_FINISH L_COLON timespec  */
#line 330 "query_parser.y"
                { if (newendtime(lp, (yyvsp[0].s)) < 0)
		      return -1;
		}
#line 1927 "query_parser.tab.c"
    break;

  case 34: /* timeexpr: L_RANGE  */
#line 334 "query_parser.y"
                { if (newrange(lp, (yyvsp[0].s)) < 0)
		      return -1;
		}
#line 1935 "query_parser.tab.c"
    break;

  case 35: /* expr: string L_LT number  */
#line 341 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_LT, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		    return -1;
		}
#line 1943 "query_parser.tab.c"
    break;

  case 36: /* expr: string L_LEQ number  */
#line 345 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_LEQ, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		    return -1;
		}
#line 1951 "query_parser.tab.c"
    break;

  case 37: /* expr: string L_EQ exprval  */
#line 349 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_EQ, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		    return -1;
		}
#line 1959 "query_parser.tab.c"
    break;

  case 38: /* expr: string L_GEQ number  */
#line 353 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_GEQ, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		    return -1;
		}
#line 1967 "query_parser.tab.c"
    break;

  case 39: /* expr: string L_GT number  */
#line 357 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_GT, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		    return -1;
		}
#line 1975 "query_parser.tab.c"
    break;

  case 40: /* expr: string L_NEQ exprval  */
#line 361 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_NEQ, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		    return -1;
		}
#line 1983 "query_parser.tab.c"
    break;

  case 41: /* expr: string L_REQ string  */
#line 367 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_REQ, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		     return -1;
		}
#line 1991 "query_parser.tab.c"
    break;

  case 42: /* expr: string L_RNE string  */
#line 371 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_RNE, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		     return -1;
		}
#line 1999 "query_parser.tab.c"
    break;

  case 43: /* expr: string L_COLON exprval  */
#line 375 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_GLOB, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		     return -1;
		}
#line 2007 "query_parser.tab.c"
    break;

  case 44: /* expr: string L_GLOB exprval  */
#line 379 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_GLOB, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		     return -1;
		}
#line 2015 "query_parser.tab.c"
    break;

  case 45: /* expr: expr L_AND expr  */
#line 385 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_AND, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		      return -1;
		}
#line 2023 "query_parser.tab.c"
    break;

  case 46: /* expr: expr L_OR expr  */
#line 389 "query_parser.y"
                { if (((yyval.n) = lp->yy_np = newtree(N_OR, (yyvsp[-2].n), (yyvsp[0].n))) == NULL)
		      return -1;
		}
#line 2031 "query_parser.tab.c"
    break;

  case 47: /* val_vec: L_NAME L_LBRACE exprlist L_RBRACE L_LSQUARE timelist L_RSQUARE  */
#line 396 "query_parser.y"
                { if ((lp->yy_np = newmetricquery((yyvsp[-6].s), (yyvsp[-4].n))) == NULL)
		      return -1;
		  lp->yy_np->time = lp->yy_series.time;
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2041 "query_parser.tab.c"
    break;

  case 48: /* val_vec: L_NAME L_LSQUARE timelist L_RSQUARE  */
#line 402 "query_parser.y"
                { if ((lp->yy_np = newmetric((yyvsp[-3].s))) == NULL)
		      return -1;
		  lp->yy_np->time = lp->yy_series.time;
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2051 "query_parser.tab.c"
    break;

  case 49: /* sid_vec: L_NAME L_LBRACE exprlist L_RBRACE  */
#line 411 "query_parser.y"
                { if ((lp->yy_np = newmetricquery((yyvsp[-3].s), (yyvsp[-1].n))) == NULL)
		      return -1;
                  (yyval.n) = lp->yy_series.expr = lp->yy_np;
                }
#line 2060 "query_parser.tab.c"
    break;

  case 50: /* sid_vec: L_NAME  */
#line 416 "query_parser.y"
                { if ((lp->yy_np = newmetric((yyvsp[0].s))) == NULL)
		      return -1;
                  (yyval.n) = lp->yy_series.expr = lp->yy_np;
                }
#line 2069 "query_parser.tab.c"
    break;

  case 51: /* func_sid: L_RATE L_LPAREN sid_vec L_RPAREN  */
#line 424 "query_parser.y"
                { if ((lp->yy_np = newnode(N_RATE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2079 "query_parser.tab.c"
    break;

  case 52: /* func_sid: L_RATE L_LPAREN func_sid L_RPAREN  */
#line 430 "query_parser.y"
                { if ((lp->yy_np = newnode(N_RATE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2089 "query_parser.tab.c"
    break;

  case 53: /* func_sid: L_MAX L_LPAREN sid_vec L_RPAREN  */
#line 436 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2099 "query_parser.tab.c"
    break;

  case 54: /* func_sid: L_MAX L_LPAREN func_sid L_RPAREN  */
#line 442 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2109 "query_parser.tab.c"
    break;

  case 55: /* func_sid: L_MAX_INST L_LPAREN sid_vec L_RPAREN  */
#line 448 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2119 "query_parser.tab.c"
    break;

  case 56: /* func_sid: L_MAX_INST L_LPAREN func_sid L_RPAREN  */
#line 454 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2129 "query_parser.tab.c"
    break;

  case 57: /* func_sid: L_MAX_SAMPLE L_LPAREN sid_vec L_RPAREN  */
#line 460 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2139 "query_parser.tab.c"
    break;

  case 58: /* func_sid: L_MAX_SAMPLE L_LPAREN func_sid L_RPAREN  */
#line 466 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2149 "query_parser.tab.c"
    break;

  case 59: /* func_sid: L_MIN L_LPAREN sid_vec L_RPAREN  */
#line 472 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2159 "query_parser.tab.c"
    break;

  case 60: /* func_sid: L_MIN L_LPAREN func_sid L_RPAREN  */
#line 478 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2170 "query_parser.tab.c"
    break;

  case 61: /* func_sid: L_MIN_INST L_LPAREN sid_vec L_RPAREN  */
#line 485 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2181 "query_parser.tab.c"
    break;

  case 62: /* func_sid: L_MIN_INST L_LPAREN func_sid L_RPAREN  */
#line 492 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2191 "query_parser.tab.c"
    break;

  case 63: /* func_sid: L_MIN_SAMPLE L_LPAREN sid_vec L_RPAREN  */
#line 498 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2201 "query_parser.tab.c"
    break;

  case 64: /* func_sid: L_MIN_SAMPLE L_LPAREN func_sid L_RPAREN  */
#line 504 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2211 "query_parser.tab.c"
    break;

  case 65: /* func_sid: L_RESCALE L_LPAREN sid_vec L_COMMA L_STRING L_RPAREN  */
#line 510 "query_parser.y"
                { double		mult;
		  struct pmUnits	units;
		  char			*errmsg;
		
		  if ((lp->yy_np = newnode(N_RESCALE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  if (pmParseUnitsStr((yyvsp[-1].s), &units, &mult, &errmsg) < 0) {
		      gramerr(lp, "Illegal units:", NULL, errmsg);
		      free(errmsg);
		      series_error(lp, NULL);
		      return -1;
		  }
		  if ((lp->yy_np->right = newnode(N_SCALE)) == NULL)
		      return -1;
		  lp->yy_np->right->meta.units = units;	/* struct assign */
		  lp->yy_np->right->value = (yyvsp[-1].s);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2235 "query_parser.tab.c"
    break;

  case 66: /* func_sid: L_RESCALE L_LPAREN func_sid L_COMMA L_STRING L_RPAREN  */
#line 530 "query_parser.y"
                { double		mult;
		  struct pmUnits	units;
		  char			*errmsg;
		
		  if ((lp->yy_np = newnode(N_RESCALE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  if (pmParseUnitsStr((yyvsp[-1].s), &units, &mult, &errmsg) < 0) {
		      gramerr(lp, "Illegal units:", NULL, errmsg);
		      free(errmsg);
		      series_error(lp, NULL);
		      return -1;
		  }
		  if ((lp->yy_np->right = newnode(N_SCALE)) == NULL)
		      return -1;
		  lp->yy_np->right->meta.units = units;	/* struct assign */
		  lp->yy_np->right->value = (yyvsp[-1].s);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2259 "query_parser.tab.c"
    break;

  case 67: /* func_sid: L_SUM L_LPAREN sid_vec L_RPAREN  */
#line 550 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2269 "query_parser.tab.c"
    break;

  case 68: /* func_sid: L_SUM L_LPAREN func_sid L_RPAREN  */
#line 556 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2279 "query_parser.tab.c"
    break;

  case 69: /* func_sid: L_SUM_INST L_LPAREN sid_vec L_RPAREN  */
#line 562 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2289 "query_parser.tab.c"
    break;

  case 70: /* func_sid: L_SUM_INST L_LPAREN func_sid L_RPAREN  */
#line 568 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2299 "query_parser.tab.c"
    break;

  case 71: /* func_sid: L_SUM_SAMPLE L_LPAREN sid_vec L_RPAREN  */
#line 574 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2309 "query_parser.tab.c"
    break;

  case 72: /* func_sid: L_SUM_SAMPLE L_LPAREN func_sid L_RPAREN  */
#line 580 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2319 "query_parser.tab.c"
    break;

  case 73: /* func_sid: L_STDEV_INST L_LPAREN sid_vec L_RPAREN  */
#line 586 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STDEV_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2329 "query_parser.tab.c"
    break;

  case 74: /* func_sid: L_STDEV_INST L_LPAREN func_sid L_RPAREN  */
#line 592 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STDEV_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2339 "query_parser.tab.c"
    break;

  case 75: /* func_sid: L_STDEV_SAMPLE L_LPAREN sid_vec L_RPAREN  */
#line 598 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STDEV_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2349 "query_parser.tab.c"
    break;

  case 76: /* func_sid: L_STDEV_SAMPLE L_LPAREN func_sid L_RPAREN  */
#line 604 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STDEV_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2359 "query_parser.tab.c"
    break;

  case 77: /* func_sid: L_TOPK_INST L_LPAREN sid_vec L_COMMA integer L_RPAREN  */
#line 610 "query_parser.y"
                { if ((lp->yy_np = newnode(N_TOPK_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2370 "query_parser.tab.c"
    break;

  case 78: /* func_sid: L_TOPK_INST L_LPAREN func_sid L_COMMA integer L_RPAREN  */
#line 617 "query_parser.y"
                { if ((lp->yy_np = newnode(N_TOPK_INST)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2381 "query_parser.tab.c"
    break;

  case 79: /* func_sid: L_TOPK_SAMPLE L_LPAREN sid_vec L_COMMA integer L_RPAREN  */
#line 624 "query_parser.y"
                { if ((lp->yy_np = newnode(N_TOPK_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2392 "query_parser.tab.c"
    break;

  case 80: /* func_sid: L_TOPK_SAMPLE L_LPAREN func_sid L_COMMA integer L_RPAREN  */
#line 631 "query_parser.y"
                { if ((lp->yy_np = newnode(N_TOPK_SAMPLE)) == NULL)
		      return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2403 "query_parser.tab.c"
    break;

  case 81: /* func_sid: L_NTH_PERCENTILE_INST L_LPAREN sid_vec L_COMMA integer L_RPAREN  */
#line 638 "query_parser.y"
                { char *ptr;
		  long ret;
		  ret = strtoul((yyvsp[-1].n)->value, &ptr, 10);
		  if (*ptr != '\0' || ret < 0 || ret > 100){
			series_error(lp, NULL);
			return -1;
		  }
		  if ((lp->yy_np = newnode(N_NTH_PERCENTILE_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2421 "query_parser.tab.c"
    break;

  case 82: /* func_sid: L_NTH_PERCENTILE_INST L_LPAREN func_sid L_COMMA integer L_RPAREN  */
#line 652 "query_parser.y"
                { char *ptr;
		  long ret;
		  ret = strtoul((yyvsp[-1].n)->value, &ptr, 10);
		  if (*ptr != '\0' || ret < 0 || ret > 100){
			series_error(lp, NULL);
			return -1;
		  }
		  if ((lp->yy_np = newnode(N_NTH_PERCENTILE_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2439 "query_parser.tab.c"
    break;

  case 83: /* func_sid: L_NTH_PERCENTILE_SAMPLE L_LPAREN sid_vec L_COMMA integer L_RPAREN  */
#line 666 "query_parser.y"
                { char *ptr;
		  long ret;
		  ret = strtoul((yyvsp[-1].n)->value, &ptr, 10);
		  if (*ptr != '\0' || ret < 0 || ret > 100){
			series_error(lp, NULL);
			return -1;
		  }
		  if ((lp->yy_np = newnode(N_NTH_PERCENTILE_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2457 "query_parser.tab.c"
    break;

  case 84: /* func_sid: L_NTH_PERCENTILE_SAMPLE L_LPAREN func_sid L_COMMA integer L_RPAREN  */
#line 680 "query_parser.y"
                { char *ptr;
		  long ret;
		  ret = strtoul((yyvsp[-1].n)->value, &ptr, 10);
		  if (*ptr != '\0' || ret < 0 || ret > 100){
			series_error(lp, NULL);
			return -1;
		  }
		  if ((lp->yy_np = newnode(N_NTH_PERCENTILE_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2475 "query_parser.tab.c"
    break;

  case 85: /* func_sid: L_AVG L_LPAREN sid_vec L_RPAREN  */
#line 694 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2485 "query_parser.tab.c"
    break;

  case 86: /* func_sid: L_AVG L_LPAREN func_sid L_RPAREN  */
#line 700 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2495 "query_parser.tab.c"
    break;

  case 87: /* func_sid: L_AVG_INST L_LPAREN sid_vec L_RPAREN  */
#line 706 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2505 "query_parser.tab.c"
    break;

  case 88: /* func_sid: L_AVG_INST L_LPAREN func_sid L_RPAREN  */
#line 712 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2515 "query_parser.tab.c"
    break;

  case 89: /* func_sid: L_AVG_SAMPLE L_LPAREN sid_vec L_RPAREN  */
#line 718 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2525 "query_parser.tab.c"
    break;

  case 90: /* func_sid: L_AVG_SAMPLE L_LPAREN func_sid L_RPAREN  */
#line 724 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2535 "query_parser.tab.c"
    break;

  case 91: /* func_sid: L_ABS L_LPAREN sid_vec L_RPAREN  */
#line 730 "query_parser.y"
                { if ((lp->yy_np = newnode(N_ABS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2545 "query_parser.tab.c"
    break;

  case 92: /* func_sid: L_ABS L_LPAREN func_sid L_RPAREN  */
#line 736 "query_parser.y"
                { if ((lp->yy_np = newnode(N_ABS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2555 "query_parser.tab.c"
    break;

  case 93: /* func_sid: L_FLOOR L_LPAREN sid_vec L_RPAREN  */
#line 742 "query_parser.y"
                { if ((lp->yy_np = newnode(N_FLOOR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2565 "query_parser.tab.c"
    break;

  case 94: /* func_sid: L_FLOOR L_LPAREN func_sid L_RPAREN  */
#line 748 "query_parser.y"
                { if ((lp->yy_np = newnode(N_FLOOR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2575 "query_parser.tab.c"
    break;

  case 95: /* func_sid: L_LOG L_LPAREN sid_vec L_COMMA number L_RPAREN  */
#line 754 "query_parser.y"
                { if ((lp->yy_np = newnode(N_LOG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2586 "query_parser.tab.c"
    break;

  case 96: /* func_sid: L_LOG L_LPAREN func_sid L_COMMA number L_RPAREN  */
#line 761 "query_parser.y"
                { if ((lp->yy_np = newnode(N_LOG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2597 "query_parser.tab.c"
    break;

  case 97: /* func_sid: L_LOG L_LPAREN sid_vec L_RPAREN  */
#line 768 "query_parser.y"
                { if ((lp->yy_np = newnode(N_LOG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2607 "query_parser.tab.c"
    break;

  case 98: /* func_sid: L_LOG L_LPAREN func_sid L_RPAREN  */
#line 774 "query_parser.y"
                { if ((lp->yy_np = newnode(N_LOG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2617 "query_parser.tab.c"
    break;

  case 99: /* func_sid: L_SQRT L_LPAREN sid_vec L_RPAREN  */
#line 780 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SQRT)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2627 "query_parser.tab.c"
    break;

  case 100: /* func_sid: L_SQRT L_LPAREN func_sid L_RPAREN  */
#line 786 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SQRT)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2637 "query_parser.tab.c"
    break;

  case 101: /* func_sid: L_ROUND L_LPAREN sid_vec L_RPAREN  */
#line 792 "query_parser.y"
                { if ((lp->yy_np = newnode(N_ROUND)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2647 "query_parser.tab.c"
    break;

  case 102: /* func_sid: L_ROUND L_LPAREN func_sid L_RPAREN  */
#line 798 "query_parser.y"
                { if ((lp->yy_np = newnode(N_ROUND)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2657 "query_parser.tab.c"
    break;

  case 103: /* func_sid: arithmetic_expr_sid  */
#line 804 "query_parser.y"
                { lp->yy_np = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2665 "query_parser.tab.c"
    break;

  case 104: /* arithmetic_expr_sid: sid_vec L_PLUS sid_vec  */
#line 811 "query_parser.y"
                { if ((lp->yy_np = newnode(N_PLUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2676 "query_parser.tab.c"
    break;

  case 105: /* arithmetic_expr_sid: sid_vec L_PLUS func_sid  */
#line 818 "query_parser.y"
                { if ((lp->yy_np = newnode(N_PLUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2687 "query_parser.tab.c"
    break;

  case 106: /* arithmetic_expr_sid: func_sid L_PLUS sid_vec  */
#line 825 "query_parser.y"
                { if ((lp->yy_np = newnode(N_PLUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2698 "query_parser.tab.c"
    break;

  case 107: /* arithmetic_expr_sid: func_sid L_PLUS func_sid  */
#line 832 "query_parser.y"
                { if ((lp->yy_np = newnode(N_PLUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2709 "query_parser.tab.c"
    break;

  case 108: /* arithmetic_expr_sid: sid_vec L_MINUS sid_vec  */
#line 839 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MINUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2720 "query_parser.tab.c"
    break;

  case 109: /* arithmetic_expr_sid: sid_vec L_MINUS func_sid  */
#line 846 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MINUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2731 "query_parser.tab.c"
    break;

  case 110: /* arithmetic_expr_sid: func_sid L_MINUS sid_vec  */
#line 853 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MINUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2742 "query_parser.tab.c"
    break;

  case 111: /* arithmetic_expr_sid: func_sid L_MINUS func_sid  */
#line 860 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MINUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2753 "query_parser.tab.c"
    break;

  case 112: /* arithmetic_expr_sid: sid_vec L_STAR sid_vec  */
#line 867 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2764 "query_parser.tab.c"
    break;

  case 113: /* arithmetic_expr_sid: sid_vec L_STAR func_sid  */
#line 874 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2775 "query_parser.tab.c"
    break;

  case 114: /* arithmetic_expr_sid: func_sid L_STAR sid_vec  */
#line 881 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2786 "query_parser.tab.c"
    break;

  case 115: /* arithmetic_expr_sid: func_sid L_STAR func_sid  */
#line 888 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2797 "query_parser.tab.c"
    break;

  case 116: /* arithmetic_expr_sid: number L_STAR sid_vec  */
#line 895 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2808 "query_parser.tab.c"
    break;

  case 117: /* arithmetic_expr_sid: sid_vec L_STAR number  */
#line 902 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2819 "query_parser.tab.c"
    break;

  case 118: /* arithmetic_expr_sid: number L_STAR func_sid  */
#line 909 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2830 "query_parser.tab.c"
    break;

  case 119: /* arithmetic_expr_sid: func_sid L_STAR number  */
#line 916 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2841 "query_parser.tab.c"
    break;

  case 120: /* arithmetic_expr_sid: sid_vec L_SLASH sid_vec  */
#line 923 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SLASH)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2852 "query_parser.tab.c"
    break;

  case 121: /* arithmetic_expr_sid: sid_vec L_SLASH func_sid  */
#line 930 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SLASH)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2863 "query_parser.tab.c"
    break;

  case 122: /* arithmetic_expr_sid: func_sid L_SLASH sid_vec  */
#line 937 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SLASH)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2874 "query_parser.tab.c"
    break;

  case 123: /* arithmetic_expr_sid: func_sid L_SLASH func_sid  */
#line 944 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SLASH)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2885 "query_parser.tab.c"
    break;

  case 124: /* func: L_RATE L_LPAREN val_vec L_RPAREN  */
#line 953 "query_parser.y"
                { if ((lp->yy_np = newnode(N_RATE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2895 "query_parser.tab.c"
    break;

  case 125: /* func: L_RATE L_LPAREN func L_RPAREN  */
#line 959 "query_parser.y"
                { if ((lp->yy_np = newnode(N_RATE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2905 "query_parser.tab.c"
    break;

  case 126: /* func: L_MAX L_LPAREN val_vec L_RPAREN  */
#line 965 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2915 "query_parser.tab.c"
    break;

  case 127: /* func: L_MAX L_LPAREN func L_RPAREN  */
#line 971 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2925 "query_parser.tab.c"
    break;

  case 128: /* func: L_MAX_INST L_LPAREN val_vec L_RPAREN  */
#line 977 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2936 "query_parser.tab.c"
    break;

  case 129: /* func: L_MAX_INST L_LPAREN func L_RPAREN  */
#line 984 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2946 "query_parser.tab.c"
    break;

  case 130: /* func: L_MAX_SAMPLE L_LPAREN val_vec L_RPAREN  */
#line 990 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2956 "query_parser.tab.c"
    break;

  case 131: /* func: L_MAX_SAMPLE L_LPAREN func L_RPAREN  */
#line 996 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MAX_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2966 "query_parser.tab.c"
    break;

  case 132: /* func: L_MIN L_LPAREN val_vec L_RPAREN  */
#line 1002 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2976 "query_parser.tab.c"
    break;

  case 133: /* func: L_MIN L_LPAREN func L_RPAREN  */
#line 1008 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2986 "query_parser.tab.c"
    break;

  case 134: /* func: L_MIN_INST L_LPAREN val_vec L_RPAREN  */
#line 1014 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 2996 "query_parser.tab.c"
    break;

  case 135: /* func: L_MIN_INST L_LPAREN func L_RPAREN  */
#line 1020 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3006 "query_parser.tab.c"
    break;

  case 136: /* func: L_MIN_SAMPLE L_LPAREN val_vec L_RPAREN  */
#line 1026 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3016 "query_parser.tab.c"
    break;

  case 137: /* func: L_MIN_SAMPLE L_LPAREN func L_RPAREN  */
#line 1032 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MIN_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3026 "query_parser.tab.c"
    break;

  case 138: /* func: L_RESCALE L_LPAREN val_vec L_COMMA L_STRING L_RPAREN  */
#line 1038 "query_parser.y"
                { double		mult;
		  struct pmUnits	units;
		  char			*errmsg;
		
		  if ((lp->yy_np = newnode(N_RESCALE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  if (pmParseUnitsStr((yyvsp[-1].s), &units, &mult, &errmsg) < 0) {
		      gramerr(lp, "Illegal units:", NULL, errmsg);
		      free(errmsg);
		      series_error(lp, NULL);
		      return -1;
		  }
		  if ((lp->yy_np->right = newnode(N_SCALE)) == NULL)
			return -1;
		  lp->yy_np->right->meta.units = units;	/* struct assign */
		  lp->yy_np->right->value = (yyvsp[-1].s);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3050 "query_parser.tab.c"
    break;

  case 139: /* func: L_RESCALE L_LPAREN func L_COMMA L_STRING L_RPAREN  */
#line 1058 "query_parser.y"
                { double		mult;
		  struct pmUnits	units;
		  char			*errmsg;
		
		  if ((lp->yy_np = newnode(N_RESCALE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  if (pmParseUnitsStr((yyvsp[-1].s), &units, &mult, &errmsg) < 0) {
		      gramerr(lp, "Illegal units:", NULL, errmsg);
		      free(errmsg);
		      series_error(lp, NULL);
		      return -1;
		  }
		  if ((lp->yy_np->right = newnode(N_SCALE)) == NULL)
			return -1;
		  lp->yy_np->right->meta.units = units;	/* struct assign */
		  lp->yy_np->right->value = (yyvsp[-1].s);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3074 "query_parser.tab.c"
    break;

  case 140: /* func: L_ABS L_LPAREN val_vec L_RPAREN  */
#line 1078 "query_parser.y"
                { if ((lp->yy_np = newnode(N_ABS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3084 "query_parser.tab.c"
    break;

  case 141: /* func: L_ABS L_LPAREN func L_RPAREN  */
#line 1084 "query_parser.y"
                { if ((lp->yy_np = newnode(N_ABS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3094 "query_parser.tab.c"
    break;

  case 142: /* func: L_FLOOR L_LPAREN val_vec L_RPAREN  */
#line 1090 "query_parser.y"
                { if ((lp->yy_np = newnode(N_FLOOR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3104 "query_parser.tab.c"
    break;

  case 143: /* func: L_FLOOR L_LPAREN func L_RPAREN  */
#line 1096 "query_parser.y"
                { if ((lp->yy_np = newnode(N_FLOOR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3114 "query_parser.tab.c"
    break;

  case 144: /* func: L_LOG L_LPAREN val_vec L_COMMA number L_RPAREN  */
#line 1102 "query_parser.y"
                { if ((lp->yy_np = newnode(N_LOG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3125 "query_parser.tab.c"
    break;

  case 145: /* func: L_LOG L_LPAREN func L_COMMA number L_RPAREN  */
#line 1109 "query_parser.y"
                { if ((lp->yy_np = newnode(N_LOG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3136 "query_parser.tab.c"
    break;

  case 146: /* func: L_LOG L_LPAREN val_vec L_RPAREN  */
#line 1116 "query_parser.y"
                { if ((lp->yy_np = newnode(N_LOG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3146 "query_parser.tab.c"
    break;

  case 147: /* func: L_LOG L_LPAREN func L_RPAREN  */
#line 1122 "query_parser.y"
                { if ((lp->yy_np = newnode(N_LOG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3156 "query_parser.tab.c"
    break;

  case 148: /* func: L_SQRT L_LPAREN val_vec L_RPAREN  */
#line 1128 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SQRT)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3166 "query_parser.tab.c"
    break;

  case 149: /* func: L_SQRT L_LPAREN func L_RPAREN  */
#line 1134 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SQRT)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3176 "query_parser.tab.c"
    break;

  case 150: /* func: L_ROUND L_LPAREN val_vec L_RPAREN  */
#line 1140 "query_parser.y"
                { if ((lp->yy_np = newnode(N_ROUND)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3186 "query_parser.tab.c"
    break;

  case 151: /* func: L_ROUND L_LPAREN func L_RPAREN  */
#line 1146 "query_parser.y"
                { if ((lp->yy_np = newnode(N_ROUND)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3196 "query_parser.tab.c"
    break;

  case 152: /* func: L_SUM L_LPAREN val_vec L_RPAREN  */
#line 1152 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3206 "query_parser.tab.c"
    break;

  case 153: /* func: L_SUM L_LPAREN func L_RPAREN  */
#line 1158 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3216 "query_parser.tab.c"
    break;

  case 154: /* func: L_SUM_INST L_LPAREN val_vec L_RPAREN  */
#line 1164 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3226 "query_parser.tab.c"
    break;

  case 155: /* func: L_SUM_INST L_LPAREN func L_RPAREN  */
#line 1170 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3236 "query_parser.tab.c"
    break;

  case 156: /* func: L_SUM_SAMPLE L_LPAREN val_vec L_RPAREN  */
#line 1176 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3246 "query_parser.tab.c"
    break;

  case 157: /* func: L_SUM_SAMPLE L_LPAREN func L_RPAREN  */
#line 1182 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SUM_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3256 "query_parser.tab.c"
    break;

  case 158: /* func: L_STDEV_INST L_LPAREN val_vec L_RPAREN  */
#line 1188 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STDEV_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3266 "query_parser.tab.c"
    break;

  case 159: /* func: L_STDEV_INST L_LPAREN func L_RPAREN  */
#line 1194 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STDEV_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3276 "query_parser.tab.c"
    break;

  case 160: /* func: L_STDEV_SAMPLE L_LPAREN val_vec L_RPAREN  */
#line 1200 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STDEV_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3286 "query_parser.tab.c"
    break;

  case 161: /* func: L_STDEV_SAMPLE L_LPAREN func L_RPAREN  */
#line 1206 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STDEV_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3296 "query_parser.tab.c"
    break;

  case 162: /* func: L_TOPK_INST L_LPAREN val_vec L_COMMA integer L_RPAREN  */
#line 1212 "query_parser.y"
                { if ((lp->yy_np = newnode(N_TOPK_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3307 "query_parser.tab.c"
    break;

  case 163: /* func: L_TOPK_INST L_LPAREN func L_COMMA integer L_RPAREN  */
#line 1219 "query_parser.y"
                { if ((lp->yy_np = newnode(N_TOPK_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3318 "query_parser.tab.c"
    break;

  case 164: /* func: L_TOPK_SAMPLE L_LPAREN val_vec L_COMMA integer L_RPAREN  */
#line 1226 "query_parser.y"
                { if ((lp->yy_np = newnode(N_TOPK_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3329 "query_parser.tab.c"
    break;

  case 165: /* func: L_TOPK_SAMPLE L_LPAREN func L_COMMA integer L_RPAREN  */
#line 1233 "query_parser.y"
                { if ((lp->yy_np = newnode(N_TOPK_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3340 "query_parser.tab.c"
    break;

  case 166: /* func: L_NTH_PERCENTILE_INST L_LPAREN val_vec L_COMMA integer L_RPAREN  */
#line 1240 "query_parser.y"
                { char *ptr;
		  long ret;
		  ret = strtoul((yyvsp[-1].n)->value, &ptr, 10);
		  if (*ptr != '\0' || ret < 0 || ret > 100){
			series_error(lp, NULL);
			return -1;
		  }
		  if ((lp->yy_np = newnode(N_NTH_PERCENTILE_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3358 "query_parser.tab.c"
    break;

  case 167: /* func: L_NTH_PERCENTILE_INST L_LPAREN func L_COMMA integer L_RPAREN  */
#line 1254 "query_parser.y"
                { char *ptr;
		  long ret;
		  ret = strtoul((yyvsp[-1].n)->value, &ptr, 10);
		  if (*ptr != '\0' || ret < 0 || ret > 100){
			series_error(lp, NULL);
			return -1;
		  }
		  if ((lp->yy_np = newnode(N_NTH_PERCENTILE_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3376 "query_parser.tab.c"
    break;

  case 168: /* func: L_NTH_PERCENTILE_SAMPLE L_LPAREN val_vec L_COMMA integer L_RPAREN  */
#line 1268 "query_parser.y"
                { char *ptr;
		  long ret;
		  ret = strtoul((yyvsp[-1].n)->value, &ptr, 10);
		  if (*ptr != '\0' || ret < 0 || ret > 100){
			series_error(lp, NULL);
			return -1;
		  }
		  if ((lp->yy_np = newnode(N_NTH_PERCENTILE_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3394 "query_parser.tab.c"
    break;

  case 169: /* func: L_NTH_PERCENTILE_SAMPLE L_LPAREN func L_COMMA integer L_RPAREN  */
#line 1282 "query_parser.y"
                { char *ptr;
		  long ret;
		  ret = strtoul((yyvsp[-1].n)->value, &ptr, 10);
		  if (*ptr != '\0' || ret < 0 || ret > 100){
			series_error(lp, NULL);
			return -1;
		  }
		  if ((lp->yy_np = newnode(N_NTH_PERCENTILE_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-3].n);
		  lp->yy_np->right = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3412 "query_parser.tab.c"
    break;

  case 170: /* func: L_AVG L_LPAREN val_vec L_RPAREN  */
#line 1296 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3422 "query_parser.tab.c"
    break;

  case 171: /* func: L_AVG L_LPAREN func L_RPAREN  */
#line 1302 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3432 "query_parser.tab.c"
    break;

  case 172: /* func: L_AVG_INST L_LPAREN val_vec L_RPAREN  */
#line 1308 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3442 "query_parser.tab.c"
    break;

  case 173: /* func: L_AVG_INST L_LPAREN func L_RPAREN  */
#line 1314 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG_INST)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3452 "query_parser.tab.c"
    break;

  case 174: /* func: L_AVG_SAMPLE L_LPAREN val_vec L_RPAREN  */
#line 1320 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3462 "query_parser.tab.c"
    break;

  case 175: /* func: L_AVG_SAMPLE L_LPAREN func L_RPAREN  */
#line 1326 "query_parser.y"
                { if ((lp->yy_np = newnode(N_AVG_SAMPLE)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-1].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3472 "query_parser.tab.c"
    break;

  case 176: /* func: arithmetic_expression  */
#line 1332 "query_parser.y"
                { lp->yy_np = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3480 "query_parser.tab.c"
    break;

  case 177: /* arithmetic_expression: val_vec L_PLUS val_vec  */
#line 1339 "query_parser.y"
                { if ((lp->yy_np = newnode(N_PLUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3491 "query_parser.tab.c"
    break;

  case 178: /* arithmetic_expression: val_vec L_PLUS func  */
#line 1346 "query_parser.y"
                { if ((lp->yy_np = newnode(N_PLUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3502 "query_parser.tab.c"
    break;

  case 179: /* arithmetic_expression: func L_PLUS val_vec  */
#line 1353 "query_parser.y"
                { if ((lp->yy_np = newnode(N_PLUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3513 "query_parser.tab.c"
    break;

  case 180: /* arithmetic_expression: func L_PLUS func  */
#line 1360 "query_parser.y"
                { if ((lp->yy_np = newnode(N_PLUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3524 "query_parser.tab.c"
    break;

  case 181: /* arithmetic_expression: val_vec L_MINUS val_vec  */
#line 1367 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MINUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3535 "query_parser.tab.c"
    break;

  case 182: /* arithmetic_expression: val_vec L_MINUS func  */
#line 1374 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MINUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3546 "query_parser.tab.c"
    break;

  case 183: /* arithmetic_expression: func L_MINUS val_vec  */
#line 1381 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MINUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3557 "query_parser.tab.c"
    break;

  case 184: /* arithmetic_expression: func L_MINUS func  */
#line 1388 "query_parser.y"
                { if ((lp->yy_np = newnode(N_MINUS)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3568 "query_parser.tab.c"
    break;

  case 185: /* arithmetic_expression: val_vec L_STAR val_vec  */
#line 1395 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3579 "query_parser.tab.c"
    break;

  case 186: /* arithmetic_expression: val_vec L_STAR func  */
#line 1402 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3590 "query_parser.tab.c"
    break;

  case 187: /* arithmetic_expression: func L_STAR val_vec  */
#line 1409 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3601 "query_parser.tab.c"
    break;

  case 188: /* arithmetic_expression: func L_STAR func  */
#line 1416 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3612 "query_parser.tab.c"
    break;

  case 189: /* arithmetic_expression: number L_STAR val_vec  */
#line 1423 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3623 "query_parser.tab.c"
    break;

  case 190: /* arithmetic_expression: val_vec L_STAR number  */
#line 1430 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3634 "query_parser.tab.c"
    break;

  case 191: /* arithmetic_expression: number L_STAR func  */
#line 1437 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3645 "query_parser.tab.c"
    break;

  case 192: /* arithmetic_expression: func L_STAR number  */
#line 1444 "query_parser.y"
                { if ((lp->yy_np = newnode(N_STAR)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3656 "query_parser.tab.c"
    break;

  case 193: /* arithmetic_expression: val_vec L_SLASH val_vec  */
#line 1451 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SLASH)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3667 "query_parser.tab.c"
    break;

  case 194: /* arithmetic_expression: val_vec L_SLASH func  */
#line 1458 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SLASH)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3678 "query_parser.tab.c"
    break;

  case 195: /* arithmetic_expression: func L_SLASH val_vec  */
#line 1465 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SLASH)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3689 "query_parser.tab.c"
    break;

  case 196: /* arithmetic_expression: func L_SLASH func  */
#line 1472 "query_parser.y"
                { if ((lp->yy_np = newnode(N_SLASH)) == NULL)
			return -1;
		  lp->yy_np->left = (yyvsp[-2].n);
		  lp->yy_np->right = (yyvsp[0].n);
		  (yyval.n) = lp->yy_series.expr = lp->yy_np;
		}
#line 3700 "query_parser.tab.c"
    break;


#line 3704 "query_parser.tab.c"

      default: break;
    }
  /* User semantic actions sometimes alter yychar, and that requires
     that yytoken be updated with the new translation.  We take the
     approach of translating immediately before every use of yytoken.
     One alternative is translating here after every semantic action,
     but that translation would be missed if the semantic action invokes
     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
     incorrect destructor might then be invoked immediately.  In the
     case of YYERROR or YYBACKUP, subsequent parser actions might lead
     to an incorrect destructor call or verbose syntax error message
     before the lookahead is translated.  */
  YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);

  YYPOPSTACK (yylen);
  yylen = 0;

  *++yyvsp = yyval;

  /* Now 'shift' the result of the reduction.  Determine what state
     that goes to, based on the state we popped back to and the rule
     number reduced by.  */
  {
    const int yylhs = yyr1[yyn] - YYNTOKENS;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }

  goto yynewstate;


/*--------------------------------------.
| yyerrlab -- here on detecting error.  |
`--------------------------------------*/
yyerrlab:
  /* Make sure we have latest lookahead translation.  See comments at
     user semantic actions for why this is necessary.  */
  yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror (lp, YY_("syntax error"));
    }

  if (yyerrstatus == 3)
    {
      /* If just tried and failed to reuse lookahead token after an
         error, discard it.  */

      if (yychar <= YYEOF)
        {
          /* Return failure if at end of input.  */
          if (yychar == YYEOF)
            YYABORT;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval, lp);
          yychar = YYEMPTY;
        }
    }

  /* Else will try to reuse lookahead token after shifting the error
     token.  */
  goto yyerrlab1;


/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR.  |
`---------------------------------------------------*/
yyerrorlab:
  /* Pacify compilers when the user code never invokes YYERROR and the
     label yyerrorlab therefore never appears in user code.  */
  if (0)
    YYERROR;
  ++yynerrs;

  /* Do not reclaim the symbols of the rule whose action triggered
     this YYERROR.  */
  YYPOPSTACK (yylen);
  yylen = 0;
  YY_STACK_PRINT (yyss, yyssp);
  yystate = *yyssp;
  goto yyerrlab1;


/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
`-------------------------------------------------------------*/
yyerrlab1:
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */

  /* Pop stack until we find a state that shifts the error token.  */
  for (;;)
    {
      yyn = yypact[yystate];
      if (!yypact_value_is_default (yyn))
        {
          yyn += YYSYMBOL_YYerror;
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }

      /* Pop the current state because it cannot handle the error token.  */
      if (yyssp == yyss)
        YYABORT;


      yydestruct ("Error: popping",
                  YY_ACCESSING_SYMBOL (yystate), yyvsp, lp);
      YYPOPSTACK (1);
      yystate = *yyssp;
      YY_STACK_PRINT (yyss, yyssp);
    }

  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  *++yyvsp = yylval;
  YY_IGNORE_MAYBE_UNINITIALIZED_END


  /* Shift the error token.  */
  YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);

  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturnlab;


/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturnlab;


/*-----------------------------------------------------------.
| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here.  |
`-----------------------------------------------------------*/
yyexhaustedlab:
  yyerror (lp, YY_("memory exhausted"));
  yyresult = 2;
  goto yyreturnlab;


/*----------------------------------------------------------.
| yyreturnlab -- parsing is finished, clean up and return.  |
`----------------------------------------------------------*/
yyreturnlab:
  if (yychar != YYEMPTY)
    {
      /* Make sure we have latest lookahead translation.  See comments at
         user semantic actions for why this is necessary.  */
      yytoken = YYTRANSLATE (yychar);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval, lp);
    }
  /* Do not reclaim the symbols of the rule whose action triggered
     this YYABORT or YYACCEPT.  */
  YYPOPSTACK (yylen);
  YY_STACK_PRINT (yyss, yyssp);
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, lp);
      YYPOPSTACK (1);
    }
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif

  return yyresult;
}

#line 1480 "query_parser.y"


/* function table for lexer */
static const struct {
    int		f_type;
    int		f_namelen;
    char	*f_name;
} func[] = {
    { L_AVG,		sizeof("avg")-1,	"avg" },
    { L_AVG_INST,	sizeof("avg_inst")-1,	"avg_inst" },
    { L_AVG_SAMPLE,	sizeof("avg_sample")-1,	"avg_sample" },
    { L_COUNT,		sizeof("count")-1,	"count" },
    { L_MAX,		sizeof("max")-1,	"max" },
    { L_MAX_INST,	sizeof("max_inst")-1,	"max_inst" },
    { L_MAX_SAMPLE,	sizeof("max_sample")-1,	"max_sample" },
    { L_MIN,		sizeof("min")-1,	"min" },
    { L_MIN_INST,	sizeof("min_inst")-1,	"min_inst" },
    { L_MIN_SAMPLE,	sizeof("min_sample")-1,	"min_sample" },
    { L_SUM,		sizeof("sum")-1,	"sum" },
    { L_SUM_INST,	sizeof("sum_inst")-1,	"sum_inst" },
    { L_SUM_SAMPLE,	sizeof("sum_sample")-1,	"sum_sample" },
    { L_STDEV_INST,	sizeof("stdev_inst")-1,	"stdev_inst" },
    { L_STDEV_SAMPLE,	sizeof("stdev_sample")-1,	"stdev_sample" },
    { L_TOPK_INST,	sizeof("topk_inst")-1,	"topk_inst" },
    { L_TOPK_SAMPLE,	sizeof("topk_sample")-1,	"topk_sample" },
    { L_NTH_PERCENTILE_INST,	sizeof("nth_percentile_inst")-1,	"nth_percentile_inst" },
    { L_NTH_PERCENTILE_SAMPLE,	sizeof("nth_percentile_sample")-1,	"nth_percentile_sample" },
    { L_RATE,		sizeof("rate")-1,	"rate" },
    { L_ABS,		sizeof("abs")-1,	"abs" },
    { L_FLOOR,		sizeof("floor")-1,	"floor" },
    { L_LOG,		sizeof("log")-1,	"log" },
    { L_SQRT,		sizeof("sqrt")-1,	"sqrt" },
    { L_ROUND,		sizeof("round")-1,	"round" },
    { L_RESCALE,	sizeof("rescale")-1,	"rescale" },
    { L_UNDEF,		0,			NULL }
};

static struct {
    int         ltype;
    int         ntype;
    char        *long_name;
    char        *short_name;
} typetab[] = {
    { L_UNDEF,		0,		"UNDEF",	NULL },
    { L_ERROR,		0,		"ERROR",	NULL },
    { L_EOS,		0,		"EOS",		NULL },
    { L_INTEGER,	N_INTEGER,	"INTEGER",	NULL },
    { L_DOUBLE,		N_DOUBLE,	"DOUBLE",	NULL },
    { L_NAME,		N_NAME,		"NAME",		NULL },
    { L_NAME,		N_METRIC,	"METRIC",	NULL },
    { L_NAME,		N_QUERY,	"QUERY",	NULL },
    { L_PLUS,		N_PLUS,		"PLUS",		"+" },
    { L_MINUS,		N_MINUS,	"MINUS",	"-" },
    { L_STAR,		N_STAR,		"STAR",		"*" },
    { L_SLASH,		N_SLASH,	"SLASH",	"/" },
    { L_LPAREN,		0,		"LPAREN",	"(" },
    { L_RPAREN,		0,		"RPAREN",	")" },
    { L_LBRACE,		0,		"LBRACE",	"{" },
    { L_RBRACE,		0,		"RBRACE",	"}" },
    { L_TYPE,		0,		"TYPE",		NULL },
    { L_SEMANTICS,	0,		"SEMANTICS",	NULL },
    { L_UNITS,		0,		"UNITS",	NULL },
    { L_ASSIGN,		0,		"ASSIGN",	"=" },
    { L_COMMA,		0,		"COMMA",	"," },
    { L_STRING,		0,		"STRING",	"\"" },
    { L_ABS,		N_ABS,		"ABS",		NULL },
    { L_FLOOR,		N_FLOOR,	"FLOOR",	NULL },
    { N_LOG,		N_LOG,		"LOG",		NULL },
    { N_SQRT,		N_SQRT,		"SQRT",		NULL },
    { N_ROUND,		N_ROUND,	"ROUND",	NULL },
    { L_AVG,		N_AVG,		"AVG",		NULL },
    { L_AVG_INST,	N_AVG_INST,	"AVG_INST",	NULL },
    { L_AVG_SAMPLE,	N_AVG_SAMPLE,	"AVG_SAMPLE",	NULL },
    { L_COUNT,		N_COUNT,	"COUNT",	NULL },
    { L_DELTA,		N_DELTA,	"DELTA",	NULL },
    { L_MAX,		N_MAX,		"MAX",		NULL },
    { L_MAX_INST,	N_MAX_INST,	"MAX_INST",	NULL },
    { L_MAX_SAMPLE,	N_MAX_SAMPLE,	"MAX_SAMPLE",	NULL },
    { L_MIN,		N_MIN,		"MIN",		NULL },
    { L_MIN_INST,	N_MIN_INST,	"MIN_INST",	NULL },
    { L_MIN_SAMPLE,	N_MIN_SAMPLE,	"MIN_SAMPLE",	NULL },
    { L_SUM,		N_SUM,		"SUM",		NULL },
    { L_SUM_INST,	N_SUM_INST,	"SUM_INST",	NULL },
    { L_SUM_SAMPLE,	N_SUM_SAMPLE,	"SUM_SAMPLE",	NULL },
    { L_STDEV_INST,	N_STDEV_INST,	"STDEV_INST",	NULL },
    { L_STDEV_SAMPLE,	N_STDEV_SAMPLE,	"STDEV_SAMPLE",	NULL },
    { L_TOPK_INST,	N_TOPK_INST,	"TOPK_INST",	NULL },
    { L_TOPK_SAMPLE,	N_TOPK_SAMPLE,	"TOPK_SAMPLE",	NULL },
    { L_NTH_PERCENTILE_INST,	N_NTH_PERCENTILE_INST,	"NTH_PERCENTILE_INST",	NULL },
    { L_NTH_PERCENTILE_SAMPLE, N_NTH_PERCENTILE_SAMPLE, "NTH_PERCENTILE_SAMPLE", NULL },
    { L_ANON,		N_ANON,		"ANON",		NULL },
    { L_RATE,		N_RATE,		"RATE",		NULL },
    { L_INSTANT,	N_INSTANT,	"INSTANT",	NULL },
    { L_MKCONST,	0,		"MKCONST",	NULL },
    { L_RESCALE,	N_RESCALE,	"RESCALE",	NULL },
    { 0,		N_SCALE,	"SCALE",	NULL },
    { L_DEFINED,	N_DEFINED,	"DEFINED",	NULL },
    { L_INTERVAL,	N_INTERVAL,	"INTERVAL",	NULL },
    { L_START,		N_START,	"START",	NULL },
    { L_FINISH,		N_FINISH,	"FINISH",	NULL },
    { L_TIMEZONE,	N_TIMEZONE,	"TIMEZONE",	"TZ" },
    { L_SAMPLES,	N_SAMPLES,	"SAMPLES",	NULL },
    { L_OFFSET,		N_OFFSET,	"OFFSET",	NULL },
    { L_LT,		N_LT,		"LT",		"<" },
    { L_LEQ,		N_LEQ,		"LEQ",		"<=" },
    { L_EQ,		N_EQ,		"EQ",		"==" },
    { L_GLOB,		N_GLOB,		"GLOB",		"~~" },
    { L_GEQ,		N_GEQ,		"GEQ",		">=" },
    { L_GT,		N_GT,		"GT",		">" },
    { L_NEQ,		N_NEQ,		"NEQ",		"!=" },
    { L_REQ,		N_REQ,		"REQ",		"=~" },
    { L_RNE,		N_RNE,		"RNE",		"!~" },
    { L_AND,		N_AND,		"AND",		"&&" },
    { L_OR,		N_OR,		"OR",		"||" },
    { 0,		N_NEG,		"NEG",		"-" },
    { -1,		-1,		NULL,		NULL }
};

/* full name for all node types */
static char *
n_type_str(int type)
{
    int		i;
    static char n_eh_str[32];	/* big enough for "unknown type XXXXXXXXXXX!" */

    for (i = 0; typetab[i].ntype != -1; i++)
	if (type == typetab[i].ntype)
	    return typetab[i].long_name;
    pmsprintf(n_eh_str, sizeof(n_eh_str), "unknown type %d!", type);
    return n_eh_str;
}

/* short string for the operator node types */
static char *
n_type_c(int type)
{
    int		i;
    static char n_eh_c[20]; /* big enough for "op XXXXXXXXXXX!" */

    for (i = 0; typetab[i].ntype != -1; i++)
	if (type == typetab[i].ntype)
	    return typetab[i].short_name;
    pmsprintf(n_eh_c, sizeof(n_eh_c), "op %d!", type);
    return n_eh_c;
}

/* full name for all lex types */
static char *
l_type_str(int type)
{
    int		i;
    static char l_eh_str[32];	/* big enough for "unknown type XXXXXXXXXXX!" */

    for (i = 0; typetab[i].ltype != -1; i++)
	if (type == typetab[i].ltype)
	    return typetab[i].long_name;
    pmsprintf(l_eh_str, sizeof(l_eh_str), "unknown type %d!", type);
    return l_eh_str;
}

static node_t *
newnode(int type)
{
    node_t	*np;

    if ((np = (node_t *)calloc(1, sizeof(node_t))) == NULL) {
	pmNoMem("pmSeries: newnode", sizeof(node_t), PM_RECOV_ERR);
	return NULL;
    }
    np->type = type;
    return np;
}

static node_t *
newtree(int type, node_t *left, node_t *right)
{
    node_t	*tree = newnode(type);

    if (tree) {
	tree->left = left;
	tree->right = right;
    }
    return tree;
}

static node_t *
newmetric(sds name)
{
    node_t	*node;
    char	*re;

    /* enable globbing if string contains a non-escaped '*' */
    if ((re = strchr(name, '*')) != NULL &&
	(re == name || (re[-1] != '%' && re[-1] != '\\')))
	node = newnode(N_GLOB);
    else
	node = newnode(N_EQ);

    if (node) {
	if ((node->left = newnode(N_NAME)) == NULL) {
	    sdsfree(name);
	    free(node);
	    return NULL;
	}
	if ((node->right = newnode(N_STRING)) == NULL) {
	    sdsfree(name);
	    free(node->left);
	    free(node);
	    return NULL;
	}
	node->left->value = sdsnew("metric.name");
	node->right->value = name;
    } else {
	sdsfree(name);
    }
    return node;
}

static node_t *
newmetricquery(sds name, node_t *query)
{
    node_t	*root, *metric;

    if ((root = newnode(N_AND)) == NULL)
	return NULL;
    if ((metric = newmetric(name)) == NULL) {
	free(root);
	return NULL;
    }
    root->left = metric;
    root->right = query;
    return root;
}

static int
newinterval(PARSER *lp, sds string)
{
    timing_t	*tp = &lp->yy_series.time;
    char	*error;
    int		sts;

    if ((sts = pmParseInterval(string, &tp->delta, &error)) < 0) {
	lp->yy_error = sts;
	lp->yy_errstr = sdscatfmt(sdsempty(),
		"Cannot parse time delta with %s:\n%s", "pmParseInterval", error);
	sdsfree(string);
	free(error);
	return -1;
    } else if (tp->window.delta) {
	if (sdscmp(string, tp->window.delta) != 0) {
	    lp->yy_error = -EINVAL;
	    lp->yy_errstr = sdscatfmt(sdsempty(),
		    "Invalid second time delta requested - \"%S\" vs \"%S\"",
		    tp->window.delta, string);
	    sdsfree(string);
	    return -1;
	}
	sdsfree(tp->window.delta);
    }
    tp->window.delta = string;
    return 0;
}

static int
parsetime(PARSER *lp, struct timespec *result, sds string)
{
    struct timespec start = { 0, 0 };
    struct timespec end = { PM_MAX_TIME_T, 0 };
    char	*error;
    int		sts;

    if ((sts = __pmtimespecParse(string, &start, &end, result, &error)) < 0) {
	lp->yy_error = sts;
	lp->yy_errstr = sdscatfmt(sdsempty(),
		"Cannot parse time with %s:\n%s",
		"__pmtimespecParse", error);
	sdsfree(string);
	free(error);
	return -1;
    }
    return 0;
}

static int
newstarttime(PARSER *lp, sds string)
{
    timing_t	*tp = &lp->yy_series.time;

    if (parsetime(lp, &tp->start, string) != 0)
	return -1;

    if (tp->window.start) {
	if (sdscmp(tp->window.start, string) != 0) {
	    lp->yy_error = -EINVAL;
	    lp->yy_errstr = sdscatfmt(sdsempty(),
		    "Invalid second start time requested - \"%S\" vs \"%S\"",
		    tp->window.start, string);
	    sdsfree(string);
	    return -1;
	}
	sdsfree(tp->window.start);
    }
    tp->window.start = string;
    return 0;
}

static int
newendtime(PARSER *lp, sds string)
{
    timing_t	*tp = &lp->yy_series.time;

    if (parsetime(lp, &tp->end, string) != 0)
	return -1;

    if (tp->window.end) {
	if (sdscmp(tp->window.end, string) != 0) {
	    lp->yy_error = -EINVAL;
	    lp->yy_errstr = sdscatfmt(sdsempty(),
		    "Invalid second end time requested - \"%S\" vs \"%S\"",
		    tp->window.end, string);
	    sdsfree(string);
	    return -1;
	}
	sdsfree(tp->window.end);
    }
    tp->window.end = string;
    return 0;
}

static int
newrange(PARSER *lp, sds string)
{
    struct timespec offset;
    timing_t	*tp = &lp->yy_series.time;
    char	*error;
    int		sts;

    if ((sts = pmParseInterval(string, &tp->start, &error)) < 0) {
	lp->yy_error = sts;
	lp->yy_errstr = sdscatfmt(sdsempty(),
		"Cannot parse range with %s:\n%s", "pmParseInterval", error);
	lp->yy_error = sts;
	sdsfree(string);
	free(error);
	return -1;
    }
    if (tp->window.range) {
	if (sdscmp(tp->window.range, string) != 0) {
	    lp->yy_error = -EINVAL;
	    lp->yy_errstr = sdscatfmt(sdsempty(),
		    "Invalid second time range requested - \"%S\" vs \"%S\"",
		    tp->window.range, string);
	    sdsfree(string);
	    return -1;
	}
	sdsfree(tp->window.range);
    }
    pmtimespecNow(&offset);
    pmtimespecDec(&offset, &tp->start);
    tp->start = offset;
    tp->end.tv_sec = PM_MAX_TIME_T;
    tp->window.range = string;
    return 0;
}

static int
newaligntime(PARSER *lp, sds string)
{
    timing_t	*tp = &lp->yy_series.time;

    if (parsetime(lp, &tp->align, string) != 0)
	return -1;

    if (tp->window.align) {
	if (sdscmp(tp->window.align, string) != 0) {
	    lp->yy_error = -EINVAL;
	    lp->yy_errstr = sdscatfmt(sdsempty(),
		    "Invalid second alignment requested - \"%S\" vs \"%S\"",
		    tp->window.align, string);
	    sdsfree(string);
	    return -1;
	}
	sdsfree(tp->window.align);
    }
    tp->window.align = string;
    return 0;
}

static int
newtimezone(PARSER *lp, sds string)
{
    timing_t	*tp = &lp->yy_series.time;
    char	e[PM_MAXERRMSGLEN];
    int		sts;

    if ((sts = pmNewZone(string)) < 0) {
	lp->yy_error = sts;
	lp->yy_errstr = sdscatfmt(sdsempty(),
		"Cannot parse timezone with pmNewZone:\n\"%S\" - %s",
		string, pmErrStr_r(sts, e, sizeof(e)));
	sdsfree(string);
	return -1;
    } else if (tp->window.zone) {
	if (sdscmp(tp->window.zone, string) != 0) {
	    lp->yy_error = -EINVAL;
	    lp->yy_errstr = sdscatfmt(sdsempty(),
		    "Invalid second timezone requested - \"%S\" vs \"%S\"",
		    tp->window.zone, string);
	    sdsfree(string);
	    return -1;
	}
	sdsfree(tp->window.zone);
    }
    tp->zone = sts;
    tp->window.zone = string;
    return 0;
}

static int
newsamples(PARSER *lp, sds string)
{
    timing_t	*tp = &lp->yy_series.time;
    int		sts;

    if ((sts = atoi(string)) < 0) {
	lp->yy_error = -EINVAL;
	lp->yy_errstr = sdscatfmt(sdsempty(),
		"Invalid sample count requested - \"%S\"", string);
	sdsfree(string);
	return -1;
    } else if (tp->window.count) {
	if (sdscmp(string, tp->window.count) != 0) {
	    lp->yy_error = -EINVAL;
	    lp->yy_errstr = sdscatfmt(sdsempty(),
		"Invalid second sample count requested - \"%S\" vs \"%S\"",
		string, tp->window.count);
	    sdsfree(string);
	    return -1;
	}
	sdsfree(tp->window.count);
    }
    tp->window.count = string;
    tp->count = sts;
    return 0;
}

static int
newoffset(PARSER *lp, sds string)
{
    timing_t	*tp = &lp->yy_series.time;
    int		sts;

    if ((sts = atoi(string)) < 0) {
	lp->yy_error = -EINVAL;
	lp->yy_errstr = sdscatfmt(sdsempty(),
		"Invalid sample offset requested - \"%S\"", string);
	sdsfree(string);
    } else if (tp->window.offset) {
	if (sdscmp(string, tp->window.offset) != 0) {
	    lp->yy_error = -EINVAL;
	    lp->yy_errstr = sdscatfmt(sdsempty(),
		"Invalid second time offset requested - \"%S\" vs \"%S\"",
		string, tp->window.offset);
	    sdsfree(string);
	    return -1;
	}
	sdsfree(tp->window.offset);
    }
    tp->offset = sts;
    tp->window.offset = string;
    return 0;
}

static void
gramerr(PARSER *lp, const char *phrase, const char *pos, char *arg)
{
   char errmsg[256];

   /* unless lexer has already found something amiss ... */
   if (lp->yy_errstr == NULL) {
	if (pos == NULL)
	    pmsprintf(errmsg, sizeof(errmsg), "%s '%s'", phrase, arg);
	else
	    pmsprintf(errmsg, sizeof(errmsg), "%s expected to %s %s", phrase, pos, arg);
	lp->yy_errstr = sdsnew(errmsg);
	if (lp->yy_error == 0)
	    lp->yy_error = -EINVAL;
   }
}

/* Construct error message buffer for syntactic error */
static char *
parseError(const char *spec, const char *point, const char *msg)
{
    size_t	need = 2 * strlen(spec) + strlen(msg) + 8;
    const char	*p;
    char	*q, *result;

    if ((result = malloc(need)) == NULL)
	return NULL;
    q = result;

    for (p = spec; *p != '\0'; p++)
	*q++ = *p;
    *q++ = '\n';
    for (p = spec; p != point; p++)
	*q++ = isgraph((int)*p) ? ' ' : *p;
    snprintf(q, need - (q - result), "^ -- ");
    q += 5;
    for (p = msg; *p != '\0'; p++)
	*q++ = *p;
    *q++ = '\n';
    *q = '\0';
    return result;
}

static int
series_error(PARSER *lp, const char *s)
{
    char	*msg;

    msg = parseError(lp->yy_base, lp->yy_lexicon, s ? s : "syntax error");
    lp->yy_errstr = sdscatfmt(sdsempty(), "cannot parse given string\n\n%s", msg);
    free(msg);

    lp->yy_series.expr = NULL;
    lp->yy_error = -EINVAL;
    return 0;
}

static int
yyerror(PARSER *lp, const char *s)
{
    return series_error(lp, s);
}

static void
unget(PARSER *lp, int c)
{
    lp->yy_lexpeek = c;
}

static int
get(PARSER *lp)
{
    int		c;

    if (lp->yy_lexpeek != 0) {
	c = lp->yy_lexpeek;
	lp->yy_lexpeek = 0;
	return c;
    }
    c = *lp->yy_input;
    if (c == '\0')
	return EOF;
    lp->yy_input++;
    return c;
}

static int
series_lex(YYSTYPE *lvalp, PARSER *lp)
{
    char	*p = lp->yy_tokbuf;
    int		ltype = L_UNDEF;
    int		c, i, len;
    int		firstch = 1;
    int		ret = L_UNDEF;

    for ( ; ret == L_UNDEF; ) {
	c = get(lp);
	if (firstch) {
	    if (isspace((int)c)) continue;
	    lp->yy_lexicon = &lp->yy_input[-1];
	    firstch = 0;
	}
	if (c == EOF) {
	    if (ltype != L_UNDEF) {
		/* force end of last token */
		c = 0;
	    }
	    else {
		/* really the end of the input buffer */
		ret = L_EOS;
		break;
	    }
	}
	if (p == NULL) {
	    lp->yy_tokbuflen = 128;
	    if ((p = (char *)malloc(lp->yy_tokbuflen+1)) == NULL) { /* CID287946 */
		lp->yy_errstr = sdscatfmt(sdsempty(),
				"cannot allocate token buffer (length=%lld)",
				(long long)lp->yy_tokbuflen);
		lp->yy_error = -ENOMEM;
		ret = L_ERROR;
		break;
	    }
	    lp->yy_tokbuf = p;
	}
	else if (p >= &lp->yy_tokbuf[lp->yy_tokbuflen]) {
	    len = p - lp->yy_tokbuf;
	    lp->yy_tokbuflen *= 2;
	    if (!(p = (char *)realloc(lp->yy_tokbuf, lp->yy_tokbuflen+1))) { /* CID287946 */
		lp->yy_errstr = sdscatfmt(sdsempty(),
				"cannot reallocate token buffer (length=%lld)",
				(long long)lp->yy_tokbuflen);
		lp->yy_error = -ENOMEM;
		ret = L_ERROR;
		break;
	    }
	    lp->yy_tokbuf = p;
	    p = &lp->yy_tokbuf[len];
	}

	*p++ = (char)c;

	if (ltype == L_UNDEF) {
	    if (isdigit((int)c))
		ltype = L_INTEGER;
	    else if (c == '.')
		ltype = L_DOUBLE;
	    else if (isalpha((int)c))
		ltype = L_NAME;
	    else {
		switch (c) {
		    case '+':
			*p = '\0';
			ret = L_PLUS;
			break;

		    case '-':
			*p = '\0';
			ret = L_MINUS;
			break;

		    case '*':
			*p = '\0';
			ret = L_STAR;
			break;

		    case '/':
			*p = '\0';
			ret = L_SLASH;
			break;

		    case '(':
			*p = '\0';
			ret = L_LPAREN;
			break;

		    case ')':
			*p = '\0';
			ret = L_RPAREN;
			break;

		    case '{':
			*p = '\0';
			ret = L_LBRACE;
			break;

		    case '}':
			*p = '\0';
			ret = L_RBRACE;
			break;

		    case '[':
			*p = '\0';
			ret = L_LSQUARE;
			break;

		    case ']':
			*p = '\0';
			ret = L_RSQUARE;
			break;

		    case '<':
			ltype = L_LT;
			break;

		    case '=':
			ltype = L_EQ;
			break;

		    case '~':
			ltype = L_GLOB;
			break;

		    case '>':
			ltype = L_GT;
			break;

		    case '!':
			ltype = L_NEQ;
			break;

		    case '&':
			ltype = L_AND;
			break;

		    case '|':
			ltype = L_OR;
			break;

		    case ':':
			*p = '\0';
			ret = L_COLON;
			break;

		    case ',':
			*p = '\0';
			ret = L_COMMA;
			break;

		    case '"':
			ltype = L_STRING;
			break;

		    default:
			*p = '\0';
			lp->yy_errstr = sdsnew("Illegal character");
			lp->yy_error = -EINVAL;
			ret = L_ERROR;
			break;
		}
	    }
	}
	else {
	    if (ltype == L_INTEGER) {
		if (c == '.') {
		    ltype = L_DOUBLE;
		}
		else if (isalpha((int)c)) {
		    ltype = L_RANGE;
		}
		else if (!isdigit((int)c)) {
		    char	*endptr;
		    __uint64_t	check;

		    unget(lp, c);
		    p[-1] = '\0';
		    check = strtoull(lp->yy_tokbuf, &endptr, 10);
		    if (*endptr != '\0' || check > 0xffffffffUL) {
			lp->yy_errstr = sdsnew("Constant value too large");
			lp->yy_error = -EINVAL;
			ret = L_ERROR;
			break;
		    }
		    if ((lvalp->s = sdsnew(lp->yy_tokbuf)) == NULL) {
			lp->yy_errstr = sdsnew("dup() for INTEGER failed");
			lp->yy_error = -ENOMEM;
			ret = L_ERROR;
			break;
		    }
		    ret = L_INTEGER;
		    break;
		}
	    }
	    else if (ltype == L_RANGE) {
		if (!isalpha((int)c)) {
		    unget(lp, c);
		    p[-1] = '\0';
		    if ((lvalp->s = sdsnew(lp->yy_tokbuf)) == NULL) {
			lp->yy_errstr = sdsnew("dup() for RANGE failed");
			lp->yy_error = -ENOMEM;
			ret = L_ERROR;
			break;
		    }
		    ret = L_RANGE;
		    break;
		}
	    }
	    else if (ltype == L_DOUBLE) {
		if (!isdigit((int)c)) {
		    unget(lp, c);
		    p[-1] = '\0';
		    if ((lvalp->s = sdsnew(lp->yy_tokbuf)) == NULL) {
			lp->yy_errstr = sdsnew("dup() for DOUBLE failed");
			lp->yy_error = -ENOMEM;
			ret = L_ERROR;
			break;
		    }
		    ret = L_DOUBLE;
		    break;
		}
	    }
	    else if (ltype == L_NAME) {
		if (isalpha((int)c) || isdigit((int)c) ||
		    c == '_' || c == '.' || c == '*' || c == '%' || c == '\\')
		    continue;
		if (c == '(') {
		    /* check for functions ... */
		    len = p - lp->yy_tokbuf - 1;
		    for (i = 0; func[i].f_name != NULL; i++) {
			if (len == func[i].f_namelen &&
			    strncmp(lp->yy_tokbuf, func[i].f_name, len) == 0) {
			    unget(lp, c);
			    p[-1] = '\0';
			    ret = func[i].f_type;
			    break;
			}
		    }
		    if (func[i].f_name != NULL) {
			/* match func name */
			break;
		    }
		}

		/* current character is end of name */
		unget(lp, c);
		p[-1] = '\0';
		if (strcmp(lp->yy_tokbuf, "type") == 0) {
		    ret = L_TYPE;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "semantics") == 0) {
		    ret = L_SEMANTICS;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "units") == 0) {
		    ret = L_UNITS;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "interval") == 0 ||
			 strcmp(lp->yy_tokbuf, "delta") == 0) {
		    ret = L_INTERVAL;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "timezone") == 0 ||
			 strcmp(lp->yy_tokbuf, "tz") == 0) {
		    ret = L_TIMEZONE;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "start") == 0 ||
			 strcmp(lp->yy_tokbuf, "begin") == 0) {
		    ret = L_START;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "finish") == 0 ||
			 strcmp(lp->yy_tokbuf, "end") == 0) {
		    ret = L_FINISH;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "samples") == 0 ||
			 strcmp(lp->yy_tokbuf, "count") == 0) {
		    ret = L_SAMPLES;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "offset") == 0 ||
			 strcmp(lp->yy_tokbuf, "from") == 0) {
		    ret = L_OFFSET;
		    break;
		}
		else if (strcmp(lp->yy_tokbuf, "align") == 0 ||
			 strcmp(lp->yy_tokbuf, "alignment") == 0) {
		    ret = L_ALIGN;
		    break;
		}
		if ((lvalp->s = sdsnew(lp->yy_tokbuf)) == NULL) {
		    lp->yy_errstr = sdsnew("dup() for NAME failed");
		    lp->yy_error = -ENOMEM;
		    ret = L_ERROR;
		    break;
		}
		ret = L_NAME;
		break;
	    }
	    else if (ltype == L_STRING) {
		if (c != '"')
		    continue;
		/* [-1] and [1] to strip quotes */
		p[-1] = '\0';
		if ((lvalp->s = sdsnew(&lp->yy_tokbuf[1])) == NULL) {
		    lp->yy_errstr = sdsnew("dup() for STRING failed");
		    lp->yy_error = -ENOMEM;
		    ret = L_ERROR;
		    break;
		}
		ret = L_STRING;
		break;
	    }
	    else if (ltype == L_LT) {
		if (c == '=') {
		    *p = '\0';
		    ret = L_LEQ;
		    break;
		}
		else {
		    unget(lp, c);
		    p[-1] = '\0';
		    ret = L_LT;
		    break;
		}
	    }
	    else if (ltype == L_GT) {
		if (c == '=') {
		    *p = '\0';
		    ret = L_GEQ;
		    break;
		}
		else {
		    unget(lp, c);
		    p[-1] = '\0';
		    ret = L_GT;
		    break;
		}
	    }
	    else if (ltype == L_GLOB) {
		if (c == '~') {
		    *p = '\0';
		    ret = L_GLOB;
		    break;
		}
		else {
		    unget(lp, c);
		    p[-1] = '\0';
		    lp->yy_errstr = sdsnew("Illegal character");
		    lp->yy_error = -EINVAL;
		    ret = L_ERROR;
		    break;
		}
	    }
	    else if (ltype == L_EQ) {
		if (c == '=') {
		    *p = '\0';
		    ret = L_EQ;
		    break;
		}
		else if (c == '~') {
		    *p = '\0';
		    ret = L_REQ;
		    break;
		}
		else {
		    unget(lp, c);
		    p[-1] = '\0';
		    ret = L_ASSIGN;
		    break;
		}
	    }
	    else if (ltype == L_NEQ) {
		if (c == '=') {
		    *p = '\0';
		    ret = L_NEQ;
		    break;
		}
		else if (c == '~') {
		    *p = '\0';
		    ret = L_RNE;
		    break;
		}
		else {
		    unget(lp, c);
		    p[-1] = '\0';
		    lp->yy_errstr = sdsnew("Illegal character");
		    lp->yy_error = -EINVAL;
		    ret = L_ERROR;
		    break;
		}
	    }
	    else if (ltype == L_AND) {
		if (c == '&') {
		    *p = '\0';
		    ret = L_AND;
		    break;
		}
		else {
		    unget(lp, c);
		    p[-1] = '\0';
		    lp->yy_errstr = sdsnew("Illegal character");
		    lp->yy_error = -EINVAL;
		    ret = L_ERROR;
		    break;
		}
	    }
	    else if (ltype == L_OR) {
		if (c == '|') {
		    *p = '\0';
		    ret = L_OR;
		    break;
		}
		else {
		    unget(lp, c);
		    p[-1] = '\0';
		    lp->yy_errstr = sdsnew("Illegal character");
		    lp->yy_error = -EINVAL;
		    ret = L_ERROR;
		    break;
		}
	    }
	}
    }

    if (pmDebugOptions.series && pmDebugOptions.appl0)
	fprintf(stderr, "series_lex() -> type=L_%s \"%s\"\n",
		l_type_str(ret), ret == L_EOS ? "" : lp->yy_tokbuf);

    return ret;
}

static int
yylex(YYSTYPE *lvalp, PARSER *lp)
{
    return series_lex(lvalp, lp);
}

static void
series_freetime(timing_t *tp)
{
    sdsfree(tp->window.delta);
    sdsfree(tp->window.align);
    sdsfree(tp->window.start);
    sdsfree(tp->window.end);
    sdsfree(tp->window.range);
    sdsfree(tp->window.count);
    sdsfree(tp->window.offset);
    sdsfree(tp->window.zone);
}

static void
series_dumpexpr(node_t *np, int level)
{
    if (np == NULL)
	return;

    series_dumpexpr(np->left, level+1);

    switch (np->type) {
    case N_NAME: case N_INTEGER: case N_DOUBLE:
	fprintf(stderr, "%*s%s", level*4, "", np->value);
	break;
    case N_STRING:
	fprintf(stderr, "%*s\"%s\"", level*4, "", np->value);
	break;
    case N_LT:  case N_LEQ: case N_EQ:  case N_GEQ: case N_GT:  case N_NEQ:
    case N_AND: case N_OR:  case N_RNE: case N_REQ: case N_NEG: case N_GLOB:
    case N_PLUS: case N_MINUS: case N_STAR: case N_SLASH:
	fprintf(stderr, "%*s%s", level*4, "", n_type_c(np->type));
	break;
    case N_AVG: case N_COUNT:   case N_DELTA:   case N_MAX:     case N_MIN:
    case N_SUM: case N_ANON:    case N_RATE:    case N_INSTANT: case N_RESCALE:
    case N_MAX_INST: case N_MAX_SAMPLE: case N_MIN_INST: case N_MIN_SAMPLE:
    case N_AVG_INST: case N_AVG_SAMPLE: case N_SUM_INST: case N_SUM_SAMPLE:
    case N_STDEV_INST: case N_STDEV_SAMPLE: case N_NTH_PERCENTILE_INST:
    case N_NTH_PERCENTILE_SAMPLE: case N_TOPK_INST: case N_TOPK_SAMPLE: 
	fprintf(stderr, "%*s%s()", level*4, "", n_type_str(np->type));
	break;
    case N_SCALE: {
	char	strbuf[60];

	if (pmUnitsStr_r(&np->meta.units, strbuf, sizeof(strbuf)) == NULL)
	    fprintf(stderr, " [bad units: %d %d %d %u %u %u %d %u]",
			np->meta.units.dimSpace,
			np->meta.units.dimTime,
			np->meta.units.dimCount,
			np->meta.units.scaleSpace,
			np->meta.units.scaleTime,
			np->meta.units.scaleCount,
			np->meta.units.extraUnit,
			np->meta.units.extraScale);
	else
	    fprintf(stderr, " [%s]", strbuf);
	break;
	}
    default:
	break;
    }
    fputc('\n', stderr);

    series_dumpexpr(np->right, level+1);
}

static void
series_freenode(node_t *np)
{
    if (np == NULL)
	return;

    series_freenode(np->left);
    series_freenode(np->right);
    sdsfree(np->value);
    free(np);
}

int
series_parse(sds query, series_t *sp, sds *err)
{
    PARSER	yp = { .yy_base = query, .yy_input = (char *)query };
    int		sts;

    sts = yyparse(&yp);
    if (yp.yy_tokbuf)
	free(yp.yy_tokbuf);

    if (sts != 0) {
	*err = yp.yy_errstr;
	return yp.yy_error;
    }
    if (yp.yy_series.expr == NULL) {	/* only a window? */
	*err = sdsnew("Invalid series query specification");
	return -EINVAL;
    }

    if (pmDebugOptions.query) {
	fprintf(stderr, "parsed query: %s\n", query);
	series_dumpexpr(yp.yy_series.expr, 0);
	fputc('\n', stderr);
    }

    *sp = yp.yy_series; /* struct copy */
    return sts;
}

int
pmSeriesQuery(pmSeriesSettings *settings, sds query, pmSeriesFlags flags, void *arg)
{
    series_t	sp = {0};
    sds		errstr;
    int		sts;

    series_stats_inc(settings, SERIES_QUERY_CALLS);

    if ((sts = series_parse(query, &sp, &errstr)) != 0) {
	moduleinfo(&settings->module, PMLOG_ERROR, errstr, arg);
	return sts;
    }

    sts = series_solve(settings, sp.expr, &sp.time, flags, arg);
    series_freetime(&sp.time);
    return sts;
}

int
pmSeriesLoad(pmSeriesSettings *settings, sds source, pmSeriesFlags flags, void *arg)
{
    series_t	sp = {0};
    sds		errstr;
    int		sts;

    series_stats_inc(settings, SERIES_LOAD_CALLS);

    if ((sts = series_parse(source, &sp, &errstr)) != 0) {
	moduleinfo(&settings->module, PMLOG_ERROR, errstr, arg);
	return sts;
    }

    sts = series_load(settings, sp.expr, &sp.time, flags, arg);
    series_freetime(&sp.time);
    series_freenode(sp.expr);
    return sts;
}

int
pmSeriesWindow(pmSeriesSettings *settings, sds window, pmSeriesTimeWindow *wp, void *arg)
{
    PARSER	yp = { .yy_base = window, .yy_input = (char *)window };
    timing_t	*tp = &yp.yy_series.time;
    sds		error;
    int		sts;

    sts = yyparse(&yp);
    if (yp.yy_tokbuf)
	free(yp.yy_tokbuf);

    if (sts != 0) {
	moduleinfo(&settings->module, PMLOG_ERROR, yp.yy_errstr, arg);
	series_freetime(tp);
	return yp.yy_error;
    }
    if (yp.yy_series.expr != NULL) {
	error = sdsnew("Invalid time window specification");
	moduleinfo(&settings->module, PMLOG_ERROR, error, arg);
	series_freetime(tp);
	return -EINVAL;
    }

    *wp = tp->window; /* struct copy */
    return sts;
}
