1/* A Bison parser, made by GNU Bison 2.7.  */
2
3/* Bison implementation for Yacc-like parsers in C
4
5      Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
6
7   This program is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20/* As a special exception, you may create a larger work that contains
21   part or all of the Bison parser skeleton and distribute that work
22   under terms of your choice, so long as that work isn't itself a
23   parser generator using the skeleton or a modified version thereof
24   as a parser skeleton.  Alternatively, if you modify or redistribute
25   the parser skeleton itself, you may (at your option) remove this
26   special exception, which will cause the skeleton and the resulting
27   Bison output files to be licensed under the GNU General Public
28   License without this special exception.
29
30   This special exception was added by the Free Software Foundation in
31   version 2.2 of Bison.  */
32
33/* C LALR(1) parser skeleton written by Richard Stallman, by
34   simplifying the original so-called "semantic" parser.  */
35
36/* All symbols defined below should begin with yy or YY, to avoid
37   infringing on user name space.  This should be done even for local
38   variables, as they might otherwise be expanded by user macros.
39   There are some unavoidable exceptions within include files to
40   define necessary library symbols; they are noted "INFRINGES ON
41   USER NAME SPACE" below.  */
42
43/* Identify Bison output.  */
44#define YYBISON 1
45
46/* Bison version.  */
47#define YYBISON_VERSION "2.7"
48
49/* Skeleton name.  */
50#define YYSKELETON_NAME "yacc.c"
51
52/* Pure parsers.  */
53#define YYPURE 1
54
55/* Push parsers.  */
56#define YYPUSH 0
57
58/* Pull parsers.  */
59#define YYPULL 1
60
61
62/* Substitute the variable and function names.  */
63#define yyparse         ppparse
64#define yylex           pplex
65#define yyerror         pperror
66#define yylval          pplval
67#define yychar          ppchar
68#define yydebug         ppdebug
69#define yynerrs         ppnerrs
70
71/* Copy the first part of user declarations.  */
72
73
74//
75// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
76// Use of this source code is governed by a BSD-style license that can be
77// found in the LICENSE file.
78//
79
80// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
81
82#if defined(__GNUC__)
83// Triggered by the auto-generated pplval variable.
84#if !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
85#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
86#else
87#pragma GCC diagnostic ignored "-Wuninitialized"
88#endif
89#elif defined(_MSC_VER)
90#pragma warning(disable: 4065 4701)
91#endif
92
93#include "ExpressionParser.h"
94
95#if defined(_MSC_VER)
96#include <malloc.h>
97#else
98#include <stdlib.h>
99#endif
100
101#include <cassert>
102#include <sstream>
103
104#include "DiagnosticsBase.h"
105#include "Lexer.h"
106#include "Token.h"
107
108#if defined(_MSC_VER)
109typedef __int64 YYSTYPE;
110#else
111#include <stdint.h>
112typedef intmax_t YYSTYPE;
113#endif  // _MSC_VER
114#define YYENABLE_NLS 0
115#define YYLTYPE_IS_TRIVIAL 1
116#define YYSTYPE_IS_TRIVIAL 1
117#define YYSTYPE_IS_DECLARED 1
118
119namespace {
120struct Context
121{
122    pp::Diagnostics* diagnostics;
123    pp::Lexer* lexer;
124    pp::Token* token;
125    int* result;
126};
127}  // namespace
128
129
130static int yylex(YYSTYPE* lvalp, Context* context);
131static void yyerror(Context* context, const char* reason);
132
133
134
135# ifndef YY_NULL
136#  if defined __cplusplus && 201103L <= __cplusplus
137#   define YY_NULL nullptr
138#  else
139#   define YY_NULL 0
140#  endif
141# endif
142
143/* Enabling verbose error messages.  */
144#ifdef YYERROR_VERBOSE
145# undef YYERROR_VERBOSE
146# define YYERROR_VERBOSE 1
147#else
148# define YYERROR_VERBOSE 0
149#endif
150
151
152/* Enabling traces.  */
153#ifndef YYDEBUG
154# define YYDEBUG 0
155#endif
156#if YYDEBUG
157extern int ppdebug;
158#endif
159
160/* Tokens.  */
161#ifndef YYTOKENTYPE
162# define YYTOKENTYPE
163   /* Put the tokens into the symbol table, so that GDB and other debuggers
164      know about them.  */
165   enum yytokentype {
166     TOK_CONST_INT = 258,
167     TOK_OP_OR = 259,
168     TOK_OP_AND = 260,
169     TOK_OP_NE = 261,
170     TOK_OP_EQ = 262,
171     TOK_OP_GE = 263,
172     TOK_OP_LE = 264,
173     TOK_OP_RIGHT = 265,
174     TOK_OP_LEFT = 266,
175     TOK_UNARY = 267
176   };
177#endif
178
179
180#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
181typedef int YYSTYPE;
182# define YYSTYPE_IS_TRIVIAL 1
183# define yystype YYSTYPE /* obsolescent; will be withdrawn */
184# define YYSTYPE_IS_DECLARED 1
185#endif
186
187
188#ifdef YYPARSE_PARAM
189#if defined __STDC__ || defined __cplusplus
190int ppparse (void *YYPARSE_PARAM);
191#else
192int ppparse ();
193#endif
194#else /* ! YYPARSE_PARAM */
195#if defined __STDC__ || defined __cplusplus
196int ppparse (Context *context);
197#else
198int ppparse ();
199#endif
200#endif /* ! YYPARSE_PARAM */
201
202
203
204/* Copy the second part of user declarations.  */
205
206
207
208#ifdef short
209# undef short
210#endif
211
212#ifdef YYTYPE_UINT8
213typedef YYTYPE_UINT8 yytype_uint8;
214#else
215typedef unsigned char yytype_uint8;
216#endif
217
218#ifdef YYTYPE_INT8
219typedef YYTYPE_INT8 yytype_int8;
220#elif (defined __STDC__ || defined __C99__FUNC__ \
221     || defined __cplusplus || defined _MSC_VER)
222typedef signed char yytype_int8;
223#else
224typedef short int yytype_int8;
225#endif
226
227#ifdef YYTYPE_UINT16
228typedef YYTYPE_UINT16 yytype_uint16;
229#else
230typedef unsigned short int yytype_uint16;
231#endif
232
233#ifdef YYTYPE_INT16
234typedef YYTYPE_INT16 yytype_int16;
235#else
236typedef short int yytype_int16;
237#endif
238
239#ifndef YYSIZE_T
240# ifdef __SIZE_TYPE__
241#  define YYSIZE_T __SIZE_TYPE__
242# elif defined size_t
243#  define YYSIZE_T size_t
244# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
245     || defined __cplusplus || defined _MSC_VER)
246#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
247#  define YYSIZE_T size_t
248# else
249#  define YYSIZE_T unsigned int
250# endif
251#endif
252
253#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
254
255#ifndef YY_
256# if defined YYENABLE_NLS && YYENABLE_NLS
257#  if ENABLE_NLS
258#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
259#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
260#  endif
261# endif
262# ifndef YY_
263#  define YY_(Msgid) Msgid
264# endif
265#endif
266
267/* Suppress unused-variable warnings by "using" E.  */
268#if ! defined lint || defined __GNUC__
269# define YYUSE(E) ((void) (E))
270#else
271# define YYUSE(E) /* empty */
272#endif
273
274/* Identity function, used to suppress warnings about constant conditions.  */
275#ifndef lint
276# define YYID(N) (N)
277#else
278#if (defined __STDC__ || defined __C99__FUNC__ \
279     || defined __cplusplus || defined _MSC_VER)
280static int
281YYID (int yyi)
282#else
283static int
284YYID (yyi)
285    int yyi;
286#endif
287{
288  return yyi;
289}
290#endif
291
292#if ! defined yyoverflow || YYERROR_VERBOSE
293
294/* The parser invokes alloca or malloc; define the necessary symbols.  */
295
296# ifdef YYSTACK_USE_ALLOCA
297#  if YYSTACK_USE_ALLOCA
298#   ifdef __GNUC__
299#    define YYSTACK_ALLOC __builtin_alloca
300#   elif defined __BUILTIN_VA_ARG_INCR
301#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
302#   elif defined _AIX
303#    define YYSTACK_ALLOC __alloca
304#   elif defined _MSC_VER
305#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
306#    define alloca _alloca
307#   else
308#    define YYSTACK_ALLOC alloca
309#    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
310     || defined __cplusplus || defined _MSC_VER)
311#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
312      /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
313#     ifndef EXIT_SUCCESS
314#      define EXIT_SUCCESS 0
315#     endif
316#    endif
317#   endif
318#  endif
319# endif
320
321# ifdef YYSTACK_ALLOC
322   /* Pacify GCC's `empty if-body' warning.  */
323#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
324#  ifndef YYSTACK_ALLOC_MAXIMUM
325    /* The OS might guarantee only one guard page at the bottom of the stack,
326       and a page size can be as small as 4096 bytes.  So we cannot safely
327       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
328       to allow for a few compiler-allocated temporary stack slots.  */
329#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
330#  endif
331# else
332#  define YYSTACK_ALLOC YYMALLOC
333#  define YYSTACK_FREE YYFREE
334#  ifndef YYSTACK_ALLOC_MAXIMUM
335#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
336#  endif
337#  if (defined __cplusplus && ! defined EXIT_SUCCESS \
338       && ! ((defined YYMALLOC || defined malloc) \
339	     && (defined YYFREE || defined free)))
340#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
341#   ifndef EXIT_SUCCESS
342#    define EXIT_SUCCESS 0
343#   endif
344#  endif
345#  ifndef YYMALLOC
346#   define YYMALLOC malloc
347#   if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
348     || defined __cplusplus || defined _MSC_VER)
349void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
350#   endif
351#  endif
352#  ifndef YYFREE
353#   define YYFREE free
354#   if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
355     || defined __cplusplus || defined _MSC_VER)
356void free (void *); /* INFRINGES ON USER NAME SPACE */
357#   endif
358#  endif
359# endif
360#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
361
362
363#if (! defined yyoverflow \
364     && (! defined __cplusplus \
365	 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
366
367/* A type that is properly aligned for any stack member.  */
368union yyalloc
369{
370  yytype_int16 yyss_alloc;
371  YYSTYPE yyvs_alloc;
372};
373
374/* The size of the maximum gap between one aligned stack and the next.  */
375# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
376
377/* The size of an array large to enough to hold all stacks, each with
378   N elements.  */
379# define YYSTACK_BYTES(N) \
380     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
381      + YYSTACK_GAP_MAXIMUM)
382
383# define YYCOPY_NEEDED 1
384
385/* Relocate STACK from its old location to the new one.  The
386   local variables YYSIZE and YYSTACKSIZE give the old and new number of
387   elements in the stack, and YYPTR gives the new location of the
388   stack.  Advance YYPTR to a properly aligned location for the next
389   stack.  */
390# define YYSTACK_RELOCATE(Stack_alloc, Stack)				\
391    do									\
392      {									\
393	YYSIZE_T yynewbytes;						\
394	YYCOPY (&yyptr->Stack_alloc, Stack, yysize);			\
395	Stack = &yyptr->Stack_alloc;					\
396	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
397	yyptr += yynewbytes / sizeof (*yyptr);				\
398      }									\
399    while (YYID (0))
400
401#endif
402
403#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
404/* Copy COUNT objects from SRC to DST.  The source and destination do
405   not overlap.  */
406# ifndef YYCOPY
407#  if defined __GNUC__ && 1 < __GNUC__
408#   define YYCOPY(Dst, Src, Count) \
409      __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
410#  else
411#   define YYCOPY(Dst, Src, Count)              \
412      do                                        \
413        {                                       \
414          YYSIZE_T yyi;                         \
415          for (yyi = 0; yyi < (Count); yyi++)   \
416            (Dst)[yyi] = (Src)[yyi];            \
417        }                                       \
418      while (YYID (0))
419#  endif
420# endif
421#endif /* !YYCOPY_NEEDED */
422
423/* YYFINAL -- State number of the termination state.  */
424#define YYFINAL  14
425/* YYLAST -- Last index in YYTABLE.  */
426#define YYLAST   175
427
428/* YYNTOKENS -- Number of terminals.  */
429#define YYNTOKENS  27
430/* YYNNTS -- Number of nonterminals.  */
431#define YYNNTS  3
432/* YYNRULES -- Number of rules.  */
433#define YYNRULES  26
434/* YYNRULES -- Number of states.  */
435#define YYNSTATES  52
436
437/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
438#define YYUNDEFTOK  2
439#define YYMAXUTOK   267
440
441#define YYTRANSLATE(YYX)						\
442  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
443
444/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
445static const yytype_uint8 yytranslate[] =
446{
447       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
448       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
449       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
450       2,     2,     2,    23,     2,     2,     2,    21,     8,     2,
451      25,    26,    19,    17,     2,    18,     2,    20,     2,     2,
452       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
453      11,     2,    12,     2,     2,     2,     2,     2,     2,     2,
454       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
455       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
456       2,     2,     2,     2,     7,     2,     2,     2,     2,     2,
457       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
458       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
459       2,     2,     2,     2,     6,     2,    24,     2,     2,     2,
460       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
461       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
462       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
463       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
464       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
465       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
466       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
467       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
468       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
469       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
470       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
471       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
472       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
473       5,     9,    10,    13,    14,    15,    16,    22
474};
475
476#if YYDEBUG
477/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
478   YYRHS.  */
479static const yytype_uint8 yyprhs[] =
480{
481       0,     0,     3,     5,     7,    11,    15,    19,    23,    27,
482      31,    35,    39,    43,    47,    51,    55,    59,    63,    67,
483      71,    75,    79,    82,    85,    88,    91
484};
485
486/* YYRHS -- A `-1'-separated list of the rules' RHS.  */
487static const yytype_int8 yyrhs[] =
488{
489      28,     0,    -1,    29,    -1,     3,    -1,    29,     4,    29,
490      -1,    29,     5,    29,    -1,    29,     6,    29,    -1,    29,
491       7,    29,    -1,    29,     8,    29,    -1,    29,     9,    29,
492      -1,    29,    10,    29,    -1,    29,    13,    29,    -1,    29,
493      14,    29,    -1,    29,    12,    29,    -1,    29,    11,    29,
494      -1,    29,    15,    29,    -1,    29,    16,    29,    -1,    29,
495      18,    29,    -1,    29,    17,    29,    -1,    29,    21,    29,
496      -1,    29,    20,    29,    -1,    29,    19,    29,    -1,    23,
497      29,    -1,    24,    29,    -1,    18,    29,    -1,    17,    29,
498      -1,    25,    29,    26,    -1
499};
500
501/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
502static const yytype_uint8 yyrline[] =
503{
504       0,    91,    91,    98,    99,   102,   105,   108,   111,   114,
505     117,   120,   123,   126,   129,   132,   135,   138,   141,   144,
506     157,   170,   173,   176,   179,   182,   185
507};
508#endif
509
510#if YYDEBUG || YYERROR_VERBOSE || 0
511/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
512   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
513static const char *const yytname[] =
514{
515  "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_OP_OR",
516  "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_NE", "TOK_OP_EQ", "'<'",
517  "'>'", "TOK_OP_GE", "TOK_OP_LE", "TOK_OP_RIGHT", "TOK_OP_LEFT", "'+'",
518  "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('", "')'",
519  "$accept", "input", "expression", YY_NULL
520};
521#endif
522
523# ifdef YYPRINT
524/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
525   token YYLEX-NUM.  */
526static const yytype_uint16 yytoknum[] =
527{
528       0,   256,   257,   258,   259,   260,   124,    94,    38,   261,
529     262,    60,    62,   263,   264,   265,   266,    43,    45,    42,
530      47,    37,   267,    33,   126,    40,    41
531};
532# endif
533
534/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
535static const yytype_uint8 yyr1[] =
536{
537       0,    27,    28,    29,    29,    29,    29,    29,    29,    29,
538      29,    29,    29,    29,    29,    29,    29,    29,    29,    29,
539      29,    29,    29,    29,    29,    29,    29
540};
541
542/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
543static const yytype_uint8 yyr2[] =
544{
545       0,     2,     1,     1,     3,     3,     3,     3,     3,     3,
546       3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
547       3,     3,     2,     2,     2,     2,     3
548};
549
550/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
551   Performed when YYTABLE doesn't specify something else to do.  Zero
552   means the default is an error.  */
553static const yytype_uint8 yydefact[] =
554{
555       0,     3,     0,     0,     0,     0,     0,     0,     2,    25,
556      24,    22,    23,     0,     1,     0,     0,     0,     0,     0,
557       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
558       0,     0,     0,    26,     4,     5,     6,     7,     8,     9,
559      10,    14,    13,    11,    12,    15,    16,    18,    17,    21,
560      20,    19
561};
562
563/* YYDEFGOTO[NTERM-NUM].  */
564static const yytype_int8 yydefgoto[] =
565{
566      -1,     7,     8
567};
568
569/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
570   STATE-NUM.  */
571#define YYPACT_NINF -11
572static const yytype_int16 yypact[] =
573{
574      46,   -11,    46,    46,    46,    46,    46,    12,    68,   -11,
575     -11,   -11,   -11,    27,   -11,    46,    46,    46,    46,    46,
576      46,    46,    46,    46,    46,    46,    46,    46,    46,    46,
577      46,    46,    46,   -11,    85,   101,   116,   130,   143,   154,
578     154,   -10,   -10,   -10,   -10,    37,    37,    31,    31,   -11,
579     -11,   -11
580};
581
582/* YYPGOTO[NTERM-NUM].  */
583static const yytype_int8 yypgoto[] =
584{
585     -11,   -11,    -2
586};
587
588/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
589   positive, shift that token.  If negative, reduce the rule which
590   number is the opposite.  If YYTABLE_NINF, syntax error.  */
591#define YYTABLE_NINF -1
592static const yytype_uint8 yytable[] =
593{
594       9,    10,    11,    12,    13,    26,    27,    28,    29,    30,
595      31,    32,    14,    34,    35,    36,    37,    38,    39,    40,
596      41,    42,    43,    44,    45,    46,    47,    48,    49,    50,
597      51,    15,    16,    17,    18,    19,    20,    21,    22,    23,
598      24,    25,    26,    27,    28,    29,    30,    31,    32,     1,
599      30,    31,    32,    33,    28,    29,    30,    31,    32,     0,
600       0,     0,     0,     2,     3,     0,     0,     0,     0,     4,
601       5,     6,    15,    16,    17,    18,    19,    20,    21,    22,
602      23,    24,    25,    26,    27,    28,    29,    30,    31,    32,
603      16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
604      26,    27,    28,    29,    30,    31,    32,    17,    18,    19,
605      20,    21,    22,    23,    24,    25,    26,    27,    28,    29,
606      30,    31,    32,    18,    19,    20,    21,    22,    23,    24,
607      25,    26,    27,    28,    29,    30,    31,    32,    19,    20,
608      21,    22,    23,    24,    25,    26,    27,    28,    29,    30,
609      31,    32,    20,    21,    22,    23,    24,    25,    26,    27,
610      28,    29,    30,    31,    32,    22,    23,    24,    25,    26,
611      27,    28,    29,    30,    31,    32
612};
613
614#define yypact_value_is_default(Yystate) \
615  (!!((Yystate) == (-11)))
616
617#define yytable_value_is_error(Yytable_value) \
618  YYID (0)
619
620static const yytype_int8 yycheck[] =
621{
622       2,     3,     4,     5,     6,    15,    16,    17,    18,    19,
623      20,    21,     0,    15,    16,    17,    18,    19,    20,    21,
624      22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
625      32,     4,     5,     6,     7,     8,     9,    10,    11,    12,
626      13,    14,    15,    16,    17,    18,    19,    20,    21,     3,
627      19,    20,    21,    26,    17,    18,    19,    20,    21,    -1,
628      -1,    -1,    -1,    17,    18,    -1,    -1,    -1,    -1,    23,
629      24,    25,     4,     5,     6,     7,     8,     9,    10,    11,
630      12,    13,    14,    15,    16,    17,    18,    19,    20,    21,
631       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
632      15,    16,    17,    18,    19,    20,    21,     6,     7,     8,
633       9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
634      19,    20,    21,     7,     8,     9,    10,    11,    12,    13,
635      14,    15,    16,    17,    18,    19,    20,    21,     8,     9,
636      10,    11,    12,    13,    14,    15,    16,    17,    18,    19,
637      20,    21,     9,    10,    11,    12,    13,    14,    15,    16,
638      17,    18,    19,    20,    21,    11,    12,    13,    14,    15,
639      16,    17,    18,    19,    20,    21
640};
641
642/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
643   symbol of state STATE-NUM.  */
644static const yytype_uint8 yystos[] =
645{
646       0,     3,    17,    18,    23,    24,    25,    28,    29,    29,
647      29,    29,    29,    29,     0,     4,     5,     6,     7,     8,
648       9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
649      19,    20,    21,    26,    29,    29,    29,    29,    29,    29,
650      29,    29,    29,    29,    29,    29,    29,    29,    29,    29,
651      29,    29
652};
653
654#define yyerrok		(yyerrstatus = 0)
655#define yyclearin	(yychar = YYEMPTY)
656#define YYEMPTY		(-2)
657#define YYEOF		0
658
659#define YYACCEPT	goto yyacceptlab
660#define YYABORT		goto yyabortlab
661#define YYERROR		goto yyerrorlab
662
663
664/* Like YYERROR except do call yyerror.  This remains here temporarily
665   to ease the transition to the new meaning of YYERROR, for GCC.
666   Once GCC version 2 has supplanted version 1, this can go.  However,
667   YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
668   in Bison 2.4.2's NEWS entry, where a plan to phase it out is
669   discussed.  */
670
671#define YYFAIL		goto yyerrlab
672#if defined YYFAIL
673  /* This is here to suppress warnings from the GCC cpp's
674     -Wunused-macros.  Normally we don't worry about that warning, but
675     some users do, and we want to make it easy for users to remove
676     YYFAIL uses, which will produce warnings from Bison 2.5.  */
677#endif
678
679#define YYRECOVERING()  (!!yyerrstatus)
680
681#define YYBACKUP(Token, Value)                                  \
682do                                                              \
683  if (yychar == YYEMPTY)                                        \
684    {                                                           \
685      yychar = (Token);                                         \
686      yylval = (Value);                                         \
687      YYPOPSTACK (yylen);                                       \
688      yystate = *yyssp;                                         \
689      goto yybackup;                                            \
690    }                                                           \
691  else                                                          \
692    {                                                           \
693      yyerror (context, YY_("syntax error: cannot back up")); \
694      YYERROR;							\
695    }								\
696while (YYID (0))
697
698/* Error token number */
699#define YYTERROR	1
700#define YYERRCODE	256
701
702
703/* This macro is provided for backward compatibility. */
704#ifndef YY_LOCATION_PRINT
705# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
706#endif
707
708
709/* YYLEX -- calling `yylex' with the right arguments.  */
710#ifdef YYLEX_PARAM
711# define YYLEX yylex (&yylval, YYLEX_PARAM)
712#else
713# define YYLEX yylex (&yylval, context)
714#endif
715
716/* Enable debugging if requested.  */
717#if YYDEBUG
718
719# ifndef YYFPRINTF
720#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
721#  define YYFPRINTF fprintf
722# endif
723
724# define YYDPRINTF(Args)			\
725do {						\
726  if (yydebug)					\
727    YYFPRINTF Args;				\
728} while (YYID (0))
729
730# define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \
731do {									  \
732  if (yydebug)								  \
733    {									  \
734      YYFPRINTF (stderr, "%s ", Title);					  \
735      yy_symbol_print (stderr,						  \
736		  Type, Value, context); \
737      YYFPRINTF (stderr, "\n");						  \
738    }									  \
739} while (YYID (0))
740
741
742/*--------------------------------.
743| Print this symbol on YYOUTPUT.  |
744`--------------------------------*/
745
746/*ARGSUSED*/
747#if (defined __STDC__ || defined __C99__FUNC__ \
748     || defined __cplusplus || defined _MSC_VER)
749static void
750yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
751#else
752static void
753yy_symbol_value_print (yyoutput, yytype, yyvaluep, context)
754    FILE *yyoutput;
755    int yytype;
756    YYSTYPE const * const yyvaluep;
757    Context *context;
758#endif
759{
760  FILE *yyo = yyoutput;
761  YYUSE (yyo);
762  if (!yyvaluep)
763    return;
764  YYUSE (context);
765# ifdef YYPRINT
766  if (yytype < YYNTOKENS)
767    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
768# else
769  YYUSE (yyoutput);
770# endif
771  switch (yytype)
772    {
773      default:
774        break;
775    }
776}
777
778
779/*--------------------------------.
780| Print this symbol on YYOUTPUT.  |
781`--------------------------------*/
782
783#if (defined __STDC__ || defined __C99__FUNC__ \
784     || defined __cplusplus || defined _MSC_VER)
785static void
786yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
787#else
788static void
789yy_symbol_print (yyoutput, yytype, yyvaluep, context)
790    FILE *yyoutput;
791    int yytype;
792    YYSTYPE const * const yyvaluep;
793    Context *context;
794#endif
795{
796  if (yytype < YYNTOKENS)
797    YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
798  else
799    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
800
801  yy_symbol_value_print (yyoutput, yytype, yyvaluep, context);
802  YYFPRINTF (yyoutput, ")");
803}
804
805/*------------------------------------------------------------------.
806| yy_stack_print -- Print the state stack from its BOTTOM up to its |
807| TOP (included).                                                   |
808`------------------------------------------------------------------*/
809
810#if (defined __STDC__ || defined __C99__FUNC__ \
811     || defined __cplusplus || defined _MSC_VER)
812static void
813yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
814#else
815static void
816yy_stack_print (yybottom, yytop)
817    yytype_int16 *yybottom;
818    yytype_int16 *yytop;
819#endif
820{
821  YYFPRINTF (stderr, "Stack now");
822  for (; yybottom <= yytop; yybottom++)
823    {
824      int yybot = *yybottom;
825      YYFPRINTF (stderr, " %d", yybot);
826    }
827  YYFPRINTF (stderr, "\n");
828}
829
830# define YY_STACK_PRINT(Bottom, Top)				\
831do {								\
832  if (yydebug)							\
833    yy_stack_print ((Bottom), (Top));				\
834} while (YYID (0))
835
836
837/*------------------------------------------------.
838| Report that the YYRULE is going to be reduced.  |
839`------------------------------------------------*/
840
841#if (defined __STDC__ || defined __C99__FUNC__ \
842     || defined __cplusplus || defined _MSC_VER)
843static void
844yy_reduce_print (YYSTYPE *yyvsp, int yyrule, Context *context)
845#else
846static void
847yy_reduce_print (yyvsp, yyrule, context)
848    YYSTYPE *yyvsp;
849    int yyrule;
850    Context *context;
851#endif
852{
853  int yynrhs = yyr2[yyrule];
854  int yyi;
855  unsigned long int yylno = yyrline[yyrule];
856  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
857	     yyrule - 1, yylno);
858  /* The symbols being reduced.  */
859  for (yyi = 0; yyi < yynrhs; yyi++)
860    {
861      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
862      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
863		       &(yyvsp[(yyi + 1) - (yynrhs)])
864		       		       , context);
865      YYFPRINTF (stderr, "\n");
866    }
867}
868
869# define YY_REDUCE_PRINT(Rule)		\
870do {					\
871  if (yydebug)				\
872    yy_reduce_print (yyvsp, Rule, context); \
873} while (YYID (0))
874
875/* Nonzero means print parse trace.  It is left uninitialized so that
876   multiple parsers can coexist.  */
877int yydebug;
878#else /* !YYDEBUG */
879# define YYDPRINTF(Args)
880# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
881# define YY_STACK_PRINT(Bottom, Top)
882# define YY_REDUCE_PRINT(Rule)
883#endif /* !YYDEBUG */
884
885
886/* YYINITDEPTH -- initial size of the parser's stacks.  */
887#ifndef	YYINITDEPTH
888# define YYINITDEPTH 200
889#endif
890
891/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
892   if the built-in stack extension method is used).
893
894   Do not make this value too large; the results are undefined if
895   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
896   evaluated with infinite-precision integer arithmetic.  */
897
898#ifndef YYMAXDEPTH
899# define YYMAXDEPTH 10000
900#endif
901
902
903#if YYERROR_VERBOSE
904
905# ifndef yystrlen
906#  if defined __GLIBC__ && defined _STRING_H
907#   define yystrlen strlen
908#  else
909/* Return the length of YYSTR.  */
910#if (defined __STDC__ || defined __C99__FUNC__ \
911     || defined __cplusplus || defined _MSC_VER)
912static YYSIZE_T
913yystrlen (const char *yystr)
914#else
915static YYSIZE_T
916yystrlen (yystr)
917    const char *yystr;
918#endif
919{
920  YYSIZE_T yylen;
921  for (yylen = 0; yystr[yylen]; yylen++)
922    continue;
923  return yylen;
924}
925#  endif
926# endif
927
928# ifndef yystpcpy
929#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
930#   define yystpcpy stpcpy
931#  else
932/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
933   YYDEST.  */
934#if (defined __STDC__ || defined __C99__FUNC__ \
935     || defined __cplusplus || defined _MSC_VER)
936static char *
937yystpcpy (char *yydest, const char *yysrc)
938#else
939static char *
940yystpcpy (yydest, yysrc)
941    char *yydest;
942    const char *yysrc;
943#endif
944{
945  char *yyd = yydest;
946  const char *yys = yysrc;
947
948  while ((*yyd++ = *yys++) != '\0')
949    continue;
950
951  return yyd - 1;
952}
953#  endif
954# endif
955
956# ifndef yytnamerr
957/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
958   quotes and backslashes, so that it's suitable for yyerror.  The
959   heuristic is that double-quoting is unnecessary unless the string
960   contains an apostrophe, a comma, or backslash (other than
961   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
962   null, do not copy; instead, return the length of what the result
963   would have been.  */
964static YYSIZE_T
965yytnamerr (char *yyres, const char *yystr)
966{
967  if (*yystr == '"')
968    {
969      YYSIZE_T yyn = 0;
970      char const *yyp = yystr;
971
972      for (;;)
973	switch (*++yyp)
974	  {
975	  case '\'':
976	  case ',':
977	    goto do_not_strip_quotes;
978
979	  case '\\':
980	    if (*++yyp != '\\')
981	      goto do_not_strip_quotes;
982	    /* Fall through.  */
983	  default:
984	    if (yyres)
985	      yyres[yyn] = *yyp;
986	    yyn++;
987	    break;
988
989	  case '"':
990	    if (yyres)
991	      yyres[yyn] = '\0';
992	    return yyn;
993	  }
994    do_not_strip_quotes: ;
995    }
996
997  if (! yyres)
998    return yystrlen (yystr);
999
1000  return yystpcpy (yyres, yystr) - yyres;
1001}
1002# endif
1003
1004/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1005   about the unexpected token YYTOKEN for the state stack whose top is
1006   YYSSP.
1007
1008   Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1009   not large enough to hold the message.  In that case, also set
1010   *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1011   required number of bytes is too large to store.  */
1012static int
1013yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1014                yytype_int16 *yyssp, int yytoken)
1015{
1016  YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1017  YYSIZE_T yysize = yysize0;
1018  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1019  /* Internationalized format string. */
1020  const char *yyformat = YY_NULL;
1021  /* Arguments of yyformat. */
1022  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1023  /* Number of reported tokens (one for the "unexpected", one per
1024     "expected"). */
1025  int yycount = 0;
1026
1027  /* There are many possibilities here to consider:
1028     - Assume YYFAIL is not used.  It's too flawed to consider.  See
1029       <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1030       for details.  YYERROR is fine as it does not invoke this
1031       function.
1032     - If this state is a consistent state with a default action, then
1033       the only way this function was invoked is if the default action
1034       is an error action.  In that case, don't check for expected
1035       tokens because there are none.
1036     - The only way there can be no lookahead present (in yychar) is if
1037       this state is a consistent state with a default action.  Thus,
1038       detecting the absence of a lookahead is sufficient to determine
1039       that there is no unexpected or expected token to report.  In that
1040       case, just report a simple "syntax error".
1041     - Don't assume there isn't a lookahead just because this state is a
1042       consistent state with a default action.  There might have been a
1043       previous inconsistent state, consistent state with a non-default
1044       action, or user semantic action that manipulated yychar.
1045     - Of course, the expected token list depends on states to have
1046       correct lookahead information, and it depends on the parser not
1047       to perform extra reductions after fetching a lookahead from the
1048       scanner and before detecting a syntax error.  Thus, state merging
1049       (from LALR or IELR) and default reductions corrupt the expected
1050       token list.  However, the list is correct for canonical LR with
1051       one exception: it will still contain any token that will not be
1052       accepted due to an error action in a later state.
1053  */
1054  if (yytoken != YYEMPTY)
1055    {
1056      int yyn = yypact[*yyssp];
1057      yyarg[yycount++] = yytname[yytoken];
1058      if (!yypact_value_is_default (yyn))
1059        {
1060          /* Start YYX at -YYN if negative to avoid negative indexes in
1061             YYCHECK.  In other words, skip the first -YYN actions for
1062             this state because they are default actions.  */
1063          int yyxbegin = yyn < 0 ? -yyn : 0;
1064          /* Stay within bounds of both yycheck and yytname.  */
1065          int yychecklim = YYLAST - yyn + 1;
1066          int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1067          int yyx;
1068
1069          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1070            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1071                && !yytable_value_is_error (yytable[yyx + yyn]))
1072              {
1073                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1074                  {
1075                    yycount = 1;
1076                    yysize = yysize0;
1077                    break;
1078                  }
1079                yyarg[yycount++] = yytname[yyx];
1080                {
1081                  YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1082                  if (! (yysize <= yysize1
1083                         && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1084                    return 2;
1085                  yysize = yysize1;
1086                }
1087              }
1088        }
1089    }
1090
1091  switch (yycount)
1092    {
1093# define YYCASE_(N, S)                      \
1094      case N:                               \
1095        yyformat = S;                       \
1096      break
1097      YYCASE_(0, YY_("syntax error"));
1098      YYCASE_(1, YY_("syntax error, unexpected %s"));
1099      YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1100      YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1101      YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1102      YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1103# undef YYCASE_
1104    }
1105
1106  {
1107    YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1108    if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1109      return 2;
1110    yysize = yysize1;
1111  }
1112
1113  if (*yymsg_alloc < yysize)
1114    {
1115      *yymsg_alloc = 2 * yysize;
1116      if (! (yysize <= *yymsg_alloc
1117             && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1118        *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1119      return 1;
1120    }
1121
1122  /* Avoid sprintf, as that infringes on the user's name space.
1123     Don't have undefined behavior even if the translation
1124     produced a string with the wrong number of "%s"s.  */
1125  {
1126    char *yyp = *yymsg;
1127    int yyi = 0;
1128    while ((*yyp = *yyformat) != '\0')
1129      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1130        {
1131          yyp += yytnamerr (yyp, yyarg[yyi++]);
1132          yyformat += 2;
1133        }
1134      else
1135        {
1136          yyp++;
1137          yyformat++;
1138        }
1139  }
1140  return 0;
1141}
1142#endif /* YYERROR_VERBOSE */
1143
1144/*-----------------------------------------------.
1145| Release the memory associated to this symbol.  |
1146`-----------------------------------------------*/
1147
1148/*ARGSUSED*/
1149#if (defined __STDC__ || defined __C99__FUNC__ \
1150     || defined __cplusplus || defined _MSC_VER)
1151static void
1152yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)
1153#else
1154static void
1155yydestruct (yymsg, yytype, yyvaluep, context)
1156    const char *yymsg;
1157    int yytype;
1158    YYSTYPE *yyvaluep;
1159    Context *context;
1160#endif
1161{
1162  YYUSE (yyvaluep);
1163  YYUSE (context);
1164
1165  if (!yymsg)
1166    yymsg = "Deleting";
1167  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1168
1169  switch (yytype)
1170    {
1171
1172      default:
1173        break;
1174    }
1175}
1176
1177
1178
1179
1180/*----------.
1181| yyparse.  |
1182`----------*/
1183
1184#ifdef YYPARSE_PARAM
1185#if (defined __STDC__ || defined __C99__FUNC__ \
1186     || defined __cplusplus || defined _MSC_VER)
1187int
1188yyparse (void *YYPARSE_PARAM)
1189#else
1190int
1191yyparse (YYPARSE_PARAM)
1192    void *YYPARSE_PARAM;
1193#endif
1194#else /* ! YYPARSE_PARAM */
1195#if (defined __STDC__ || defined __C99__FUNC__ \
1196     || defined __cplusplus || defined _MSC_VER)
1197int
1198yyparse (Context *context)
1199#else
1200int
1201yyparse (context)
1202    Context *context;
1203#endif
1204#endif
1205{
1206/* The lookahead symbol.  */
1207int yychar;
1208
1209
1210#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
1211/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
1212# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
1213    _Pragma ("GCC diagnostic push") \
1214    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
1215    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
1216# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
1217    _Pragma ("GCC diagnostic pop")
1218#else
1219/* Default value used for initialization, for pacifying older GCCs
1220   or non-GCC compilers.  */
1221static YYSTYPE yyval_default;
1222# define YY_INITIAL_VALUE(Value) = Value
1223#endif
1224#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1225# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1226# define YY_IGNORE_MAYBE_UNINITIALIZED_END
1227#endif
1228#ifndef YY_INITIAL_VALUE
1229# define YY_INITIAL_VALUE(Value) /* Nothing. */
1230#endif
1231
1232/* The semantic value of the lookahead symbol.  */
1233YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
1234
1235    /* Number of syntax errors so far.  */
1236    int yynerrs;
1237
1238    int yystate;
1239    /* Number of tokens to shift before error messages enabled.  */
1240    int yyerrstatus;
1241
1242    /* The stacks and their tools:
1243       `yyss': related to states.
1244       `yyvs': related to semantic values.
1245
1246       Refer to the stacks through separate pointers, to allow yyoverflow
1247       to reallocate them elsewhere.  */
1248
1249    /* The state stack.  */
1250    yytype_int16 yyssa[YYINITDEPTH];
1251    yytype_int16 *yyss;
1252    yytype_int16 *yyssp;
1253
1254    /* The semantic value stack.  */
1255    YYSTYPE yyvsa[YYINITDEPTH];
1256    YYSTYPE *yyvs;
1257    YYSTYPE *yyvsp;
1258
1259    YYSIZE_T yystacksize;
1260
1261  int yyn;
1262  int yyresult;
1263  /* Lookahead token as an internal (translated) token number.  */
1264  int yytoken = 0;
1265  /* The variables used to return semantic value and location from the
1266     action routines.  */
1267  YYSTYPE yyval;
1268
1269#if YYERROR_VERBOSE
1270  /* Buffer for error messages, and its allocated size.  */
1271  char yymsgbuf[128];
1272  char *yymsg = yymsgbuf;
1273  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1274#endif
1275
1276#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1277
1278  /* The number of symbols on the RHS of the reduced rule.
1279     Keep to zero when no symbol should be popped.  */
1280  int yylen = 0;
1281
1282  yyssp = yyss = yyssa;
1283  yyvsp = yyvs = yyvsa;
1284  yystacksize = YYINITDEPTH;
1285
1286  YYDPRINTF ((stderr, "Starting parse\n"));
1287
1288  yystate = 0;
1289  yyerrstatus = 0;
1290  yynerrs = 0;
1291  yychar = YYEMPTY; /* Cause a token to be read.  */
1292  goto yysetstate;
1293
1294/*------------------------------------------------------------.
1295| yynewstate -- Push a new state, which is found in yystate.  |
1296`------------------------------------------------------------*/
1297 yynewstate:
1298  /* In all cases, when you get here, the value and location stacks
1299     have just been pushed.  So pushing a state here evens the stacks.  */
1300  yyssp++;
1301
1302 yysetstate:
1303  *yyssp = yystate;
1304
1305  if (yyss + yystacksize - 1 <= yyssp)
1306    {
1307      /* Get the current used size of the three stacks, in elements.  */
1308      YYSIZE_T yysize = yyssp - yyss + 1;
1309
1310#ifdef yyoverflow
1311      {
1312	/* Give user a chance to reallocate the stack.  Use copies of
1313	   these so that the &'s don't force the real ones into
1314	   memory.  */
1315	YYSTYPE *yyvs1 = yyvs;
1316	yytype_int16 *yyss1 = yyss;
1317
1318	/* Each stack pointer address is followed by the size of the
1319	   data in use in that stack, in bytes.  This used to be a
1320	   conditional around just the two extra args, but that might
1321	   be undefined if yyoverflow is a macro.  */
1322	yyoverflow (YY_("memory exhausted"),
1323		    &yyss1, yysize * sizeof (*yyssp),
1324		    &yyvs1, yysize * sizeof (*yyvsp),
1325		    &yystacksize);
1326
1327	yyss = yyss1;
1328	yyvs = yyvs1;
1329      }
1330#else /* no yyoverflow */
1331# ifndef YYSTACK_RELOCATE
1332      goto yyexhaustedlab;
1333# else
1334      /* Extend the stack our own way.  */
1335      if (YYMAXDEPTH <= yystacksize)
1336	goto yyexhaustedlab;
1337      yystacksize *= 2;
1338      if (YYMAXDEPTH < yystacksize)
1339	yystacksize = YYMAXDEPTH;
1340
1341      {
1342	yytype_int16 *yyss1 = yyss;
1343	union yyalloc *yyptr =
1344	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1345	if (! yyptr)
1346	  goto yyexhaustedlab;
1347	YYSTACK_RELOCATE (yyss_alloc, yyss);
1348	YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1349#  undef YYSTACK_RELOCATE
1350	if (yyss1 != yyssa)
1351	  YYSTACK_FREE (yyss1);
1352      }
1353# endif
1354#endif /* no yyoverflow */
1355
1356      yyssp = yyss + yysize - 1;
1357      yyvsp = yyvs + yysize - 1;
1358
1359      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1360		  (unsigned long int) yystacksize));
1361
1362      if (yyss + yystacksize - 1 <= yyssp)
1363	YYABORT;
1364    }
1365
1366  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1367
1368  if (yystate == YYFINAL)
1369    YYACCEPT;
1370
1371  goto yybackup;
1372
1373/*-----------.
1374| yybackup.  |
1375`-----------*/
1376yybackup:
1377
1378  /* Do appropriate processing given the current state.  Read a
1379     lookahead token if we need one and don't already have one.  */
1380
1381  /* First try to decide what to do without reference to lookahead token.  */
1382  yyn = yypact[yystate];
1383  if (yypact_value_is_default (yyn))
1384    goto yydefault;
1385
1386  /* Not known => get a lookahead token if don't already have one.  */
1387
1388  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1389  if (yychar == YYEMPTY)
1390    {
1391      YYDPRINTF ((stderr, "Reading a token: "));
1392      yychar = YYLEX;
1393    }
1394
1395  if (yychar <= YYEOF)
1396    {
1397      yychar = yytoken = YYEOF;
1398      YYDPRINTF ((stderr, "Now at end of input.\n"));
1399    }
1400  else
1401    {
1402      yytoken = YYTRANSLATE (yychar);
1403      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1404    }
1405
1406  /* If the proper action on seeing token YYTOKEN is to reduce or to
1407     detect an error, take that action.  */
1408  yyn += yytoken;
1409  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1410    goto yydefault;
1411  yyn = yytable[yyn];
1412  if (yyn <= 0)
1413    {
1414      if (yytable_value_is_error (yyn))
1415        goto yyerrlab;
1416      yyn = -yyn;
1417      goto yyreduce;
1418    }
1419
1420  /* Count tokens shifted since error; after three, turn off error
1421     status.  */
1422  if (yyerrstatus)
1423    yyerrstatus--;
1424
1425  /* Shift the lookahead token.  */
1426  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1427
1428  /* Discard the shifted token.  */
1429  yychar = YYEMPTY;
1430
1431  yystate = yyn;
1432  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1433  *++yyvsp = yylval;
1434  YY_IGNORE_MAYBE_UNINITIALIZED_END
1435
1436  goto yynewstate;
1437
1438
1439/*-----------------------------------------------------------.
1440| yydefault -- do the default action for the current state.  |
1441`-----------------------------------------------------------*/
1442yydefault:
1443  yyn = yydefact[yystate];
1444  if (yyn == 0)
1445    goto yyerrlab;
1446  goto yyreduce;
1447
1448
1449/*-----------------------------.
1450| yyreduce -- Do a reduction.  |
1451`-----------------------------*/
1452yyreduce:
1453  /* yyn is the number of a rule to reduce with.  */
1454  yylen = yyr2[yyn];
1455
1456  /* If YYLEN is nonzero, implement the default value of the action:
1457     `$$ = $1'.
1458
1459     Otherwise, the following line sets YYVAL to garbage.
1460     This behavior is undocumented and Bison
1461     users should not rely upon it.  Assigning to YYVAL
1462     unconditionally makes the parser a bit smaller, and it avoids a
1463     GCC warning that YYVAL may be used uninitialized.  */
1464  yyval = yyvsp[1-yylen];
1465
1466
1467  YY_REDUCE_PRINT (yyn);
1468  switch (yyn)
1469    {
1470        case 2:
1471
1472    {
1473        *(context->result) = static_cast<int>((yyvsp[(1) - (1)]));
1474        YYACCEPT;
1475    }
1476    break;
1477
1478  case 4:
1479
1480    {
1481        (yyval) = (yyvsp[(1) - (3)]) || (yyvsp[(3) - (3)]);
1482    }
1483    break;
1484
1485  case 5:
1486
1487    {
1488        (yyval) = (yyvsp[(1) - (3)]) && (yyvsp[(3) - (3)]);
1489    }
1490    break;
1491
1492  case 6:
1493
1494    {
1495        (yyval) = (yyvsp[(1) - (3)]) | (yyvsp[(3) - (3)]);
1496    }
1497    break;
1498
1499  case 7:
1500
1501    {
1502        (yyval) = (yyvsp[(1) - (3)]) ^ (yyvsp[(3) - (3)]);
1503    }
1504    break;
1505
1506  case 8:
1507
1508    {
1509        (yyval) = (yyvsp[(1) - (3)]) & (yyvsp[(3) - (3)]);
1510    }
1511    break;
1512
1513  case 9:
1514
1515    {
1516        (yyval) = (yyvsp[(1) - (3)]) != (yyvsp[(3) - (3)]);
1517    }
1518    break;
1519
1520  case 10:
1521
1522    {
1523        (yyval) = (yyvsp[(1) - (3)]) == (yyvsp[(3) - (3)]);
1524    }
1525    break;
1526
1527  case 11:
1528
1529    {
1530        (yyval) = (yyvsp[(1) - (3)]) >= (yyvsp[(3) - (3)]);
1531    }
1532    break;
1533
1534  case 12:
1535
1536    {
1537        (yyval) = (yyvsp[(1) - (3)]) <= (yyvsp[(3) - (3)]);
1538    }
1539    break;
1540
1541  case 13:
1542
1543    {
1544        (yyval) = (yyvsp[(1) - (3)]) > (yyvsp[(3) - (3)]);
1545    }
1546    break;
1547
1548  case 14:
1549
1550    {
1551        (yyval) = (yyvsp[(1) - (3)]) < (yyvsp[(3) - (3)]);
1552    }
1553    break;
1554
1555  case 15:
1556
1557    {
1558        (yyval) = (yyvsp[(1) - (3)]) >> (yyvsp[(3) - (3)]);
1559    }
1560    break;
1561
1562  case 16:
1563
1564    {
1565        (yyval) = (yyvsp[(1) - (3)]) << (yyvsp[(3) - (3)]);
1566    }
1567    break;
1568
1569  case 17:
1570
1571    {
1572        (yyval) = (yyvsp[(1) - (3)]) - (yyvsp[(3) - (3)]);
1573    }
1574    break;
1575
1576  case 18:
1577
1578    {
1579        (yyval) = (yyvsp[(1) - (3)]) + (yyvsp[(3) - (3)]);
1580    }
1581    break;
1582
1583  case 19:
1584
1585    {
1586        if ((yyvsp[(3) - (3)]) == 0) {
1587            std::ostringstream stream;
1588            stream << (yyvsp[(1) - (3)]) << " % " << (yyvsp[(3) - (3)]);
1589            std::string text = stream.str();
1590            context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1591                                         context->token->location,
1592                                         text.c_str());
1593            YYABORT;
1594        } else {
1595            (yyval) = (yyvsp[(1) - (3)]) % (yyvsp[(3) - (3)]);
1596        }
1597    }
1598    break;
1599
1600  case 20:
1601
1602    {
1603        if ((yyvsp[(3) - (3)]) == 0) {
1604            std::ostringstream stream;
1605            stream << (yyvsp[(1) - (3)]) << " / " << (yyvsp[(3) - (3)]);
1606            std::string text = stream.str();
1607            context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1608                                         context->token->location,
1609                                         text.c_str());
1610            YYABORT;
1611        } else {
1612            (yyval) = (yyvsp[(1) - (3)]) / (yyvsp[(3) - (3)]);
1613        }
1614    }
1615    break;
1616
1617  case 21:
1618
1619    {
1620        (yyval) = (yyvsp[(1) - (3)]) * (yyvsp[(3) - (3)]);
1621    }
1622    break;
1623
1624  case 22:
1625
1626    {
1627        (yyval) = ! (yyvsp[(2) - (2)]);
1628    }
1629    break;
1630
1631  case 23:
1632
1633    {
1634        (yyval) = ~ (yyvsp[(2) - (2)]);
1635    }
1636    break;
1637
1638  case 24:
1639
1640    {
1641        (yyval) = - (yyvsp[(2) - (2)]);
1642    }
1643    break;
1644
1645  case 25:
1646
1647    {
1648        (yyval) = + (yyvsp[(2) - (2)]);
1649    }
1650    break;
1651
1652  case 26:
1653
1654    {
1655        (yyval) = (yyvsp[(2) - (3)]);
1656    }
1657    break;
1658
1659
1660
1661      default: break;
1662    }
1663  /* User semantic actions sometimes alter yychar, and that requires
1664     that yytoken be updated with the new translation.  We take the
1665     approach of translating immediately before every use of yytoken.
1666     One alternative is translating here after every semantic action,
1667     but that translation would be missed if the semantic action invokes
1668     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1669     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
1670     incorrect destructor might then be invoked immediately.  In the
1671     case of YYERROR or YYBACKUP, subsequent parser actions might lead
1672     to an incorrect destructor call or verbose syntax error message
1673     before the lookahead is translated.  */
1674  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1675
1676  YYPOPSTACK (yylen);
1677  yylen = 0;
1678  YY_STACK_PRINT (yyss, yyssp);
1679
1680  *++yyvsp = yyval;
1681
1682  /* Now `shift' the result of the reduction.  Determine what state
1683     that goes to, based on the state we popped back to and the rule
1684     number reduced by.  */
1685
1686  yyn = yyr1[yyn];
1687
1688  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1689  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1690    yystate = yytable[yystate];
1691  else
1692    yystate = yydefgoto[yyn - YYNTOKENS];
1693
1694  goto yynewstate;
1695
1696
1697/*------------------------------------.
1698| yyerrlab -- here on detecting error |
1699`------------------------------------*/
1700yyerrlab:
1701  /* Make sure we have latest lookahead translation.  See comments at
1702     user semantic actions for why this is necessary.  */
1703  yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1704
1705  /* If not already recovering from an error, report this error.  */
1706  if (!yyerrstatus)
1707    {
1708      ++yynerrs;
1709#if ! YYERROR_VERBOSE
1710      yyerror (context, YY_("syntax error"));
1711#else
1712# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1713                                        yyssp, yytoken)
1714      {
1715        char const *yymsgp = YY_("syntax error");
1716        int yysyntax_error_status;
1717        yysyntax_error_status = YYSYNTAX_ERROR;
1718        if (yysyntax_error_status == 0)
1719          yymsgp = yymsg;
1720        else if (yysyntax_error_status == 1)
1721          {
1722            if (yymsg != yymsgbuf)
1723              YYSTACK_FREE (yymsg);
1724            yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1725            if (!yymsg)
1726              {
1727                yymsg = yymsgbuf;
1728                yymsg_alloc = sizeof yymsgbuf;
1729                yysyntax_error_status = 2;
1730              }
1731            else
1732              {
1733                yysyntax_error_status = YYSYNTAX_ERROR;
1734                yymsgp = yymsg;
1735              }
1736          }
1737        yyerror (context, yymsgp);
1738        if (yysyntax_error_status == 2)
1739          goto yyexhaustedlab;
1740      }
1741# undef YYSYNTAX_ERROR
1742#endif
1743    }
1744
1745
1746
1747  if (yyerrstatus == 3)
1748    {
1749      /* If just tried and failed to reuse lookahead token after an
1750	 error, discard it.  */
1751
1752      if (yychar <= YYEOF)
1753	{
1754	  /* Return failure if at end of input.  */
1755	  if (yychar == YYEOF)
1756	    YYABORT;
1757	}
1758      else
1759	{
1760	  yydestruct ("Error: discarding",
1761		      yytoken, &yylval, context);
1762	  yychar = YYEMPTY;
1763	}
1764    }
1765
1766  /* Else will try to reuse lookahead token after shifting the error
1767     token.  */
1768  goto yyerrlab1;
1769
1770
1771/*---------------------------------------------------.
1772| yyerrorlab -- error raised explicitly by YYERROR.  |
1773`---------------------------------------------------*/
1774yyerrorlab:
1775
1776  /* Pacify compilers like GCC when the user code never invokes
1777     YYERROR and the label yyerrorlab therefore never appears in user
1778     code.  */
1779  if (/*CONSTCOND*/ 0)
1780     goto yyerrorlab;
1781
1782  /* Do not reclaim the symbols of the rule which action triggered
1783     this YYERROR.  */
1784  YYPOPSTACK (yylen);
1785  yylen = 0;
1786  YY_STACK_PRINT (yyss, yyssp);
1787  yystate = *yyssp;
1788  goto yyerrlab1;
1789
1790
1791/*-------------------------------------------------------------.
1792| yyerrlab1 -- common code for both syntax error and YYERROR.  |
1793`-------------------------------------------------------------*/
1794yyerrlab1:
1795  yyerrstatus = 3;	/* Each real token shifted decrements this.  */
1796
1797  for (;;)
1798    {
1799      yyn = yypact[yystate];
1800      if (!yypact_value_is_default (yyn))
1801	{
1802	  yyn += YYTERROR;
1803	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1804	    {
1805	      yyn = yytable[yyn];
1806	      if (0 < yyn)
1807		break;
1808	    }
1809	}
1810
1811      /* Pop the current state because it cannot handle the error token.  */
1812      if (yyssp == yyss)
1813	YYABORT;
1814
1815
1816      yydestruct ("Error: popping",
1817		  yystos[yystate], yyvsp, context);
1818      YYPOPSTACK (1);
1819      yystate = *yyssp;
1820      YY_STACK_PRINT (yyss, yyssp);
1821    }
1822
1823  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1824  *++yyvsp = yylval;
1825  YY_IGNORE_MAYBE_UNINITIALIZED_END
1826
1827
1828  /* Shift the error token.  */
1829  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1830
1831  yystate = yyn;
1832  goto yynewstate;
1833
1834
1835/*-------------------------------------.
1836| yyacceptlab -- YYACCEPT comes here.  |
1837`-------------------------------------*/
1838yyacceptlab:
1839  yyresult = 0;
1840  goto yyreturn;
1841
1842/*-----------------------------------.
1843| yyabortlab -- YYABORT comes here.  |
1844`-----------------------------------*/
1845yyabortlab:
1846  yyresult = 1;
1847  goto yyreturn;
1848
1849#if !defined yyoverflow || YYERROR_VERBOSE
1850/*-------------------------------------------------.
1851| yyexhaustedlab -- memory exhaustion comes here.  |
1852`-------------------------------------------------*/
1853yyexhaustedlab:
1854  yyerror (context, YY_("memory exhausted"));
1855  yyresult = 2;
1856  /* Fall through.  */
1857#endif
1858
1859yyreturn:
1860  if (yychar != YYEMPTY)
1861    {
1862      /* Make sure we have latest lookahead translation.  See comments at
1863         user semantic actions for why this is necessary.  */
1864      yytoken = YYTRANSLATE (yychar);
1865      yydestruct ("Cleanup: discarding lookahead",
1866                  yytoken, &yylval, context);
1867    }
1868  /* Do not reclaim the symbols of the rule which action triggered
1869     this YYABORT or YYACCEPT.  */
1870  YYPOPSTACK (yylen);
1871  YY_STACK_PRINT (yyss, yyssp);
1872  while (yyssp != yyss)
1873    {
1874      yydestruct ("Cleanup: popping",
1875		  yystos[*yyssp], yyvsp, context);
1876      YYPOPSTACK (1);
1877    }
1878#ifndef yyoverflow
1879  if (yyss != yyssa)
1880    YYSTACK_FREE (yyss);
1881#endif
1882#if YYERROR_VERBOSE
1883  if (yymsg != yymsgbuf)
1884    YYSTACK_FREE (yymsg);
1885#endif
1886  /* Make sure YYID is used.  */
1887  return YYID (yyresult);
1888}
1889
1890
1891
1892
1893
1894int yylex(YYSTYPE* lvalp, Context* context)
1895{
1896    int type = 0;
1897
1898    pp::Token* token = context->token;
1899    switch (token->type)
1900    {
1901      case pp::Token::CONST_INT:
1902      {
1903        unsigned int val = 0;
1904        if (!token->uValue(&val))
1905        {
1906            context->diagnostics->report(pp::Diagnostics::PP_INTEGER_OVERFLOW,
1907                                         token->location, token->text);
1908        }
1909        *lvalp = static_cast<YYSTYPE>(val);
1910        type = TOK_CONST_INT;
1911        break;
1912      }
1913      case pp::Token::OP_OR: type = TOK_OP_OR; break;
1914      case pp::Token::OP_AND: type = TOK_OP_AND; break;
1915      case pp::Token::OP_NE: type = TOK_OP_NE; break;
1916      case pp::Token::OP_EQ: type = TOK_OP_EQ; break;
1917      case pp::Token::OP_GE: type = TOK_OP_GE; break;
1918      case pp::Token::OP_LE: type = TOK_OP_LE; break;
1919      case pp::Token::OP_RIGHT: type = TOK_OP_RIGHT; break;
1920      case pp::Token::OP_LEFT: type = TOK_OP_LEFT; break;
1921      case '|': type = '|'; break;
1922      case '^': type = '^'; break;
1923      case '&': type = '&'; break;
1924      case '>': type = '>'; break;
1925      case '<': type = '<'; break;
1926      case '-': type = '-'; break;
1927      case '+': type = '+'; break;
1928      case '%': type = '%'; break;
1929      case '/': type = '/'; break;
1930      case '*': type = '*'; break;
1931      case '!': type = '!'; break;
1932      case '~': type = '~'; break;
1933      case '(': type = '('; break;
1934      case ')': type = ')'; break;
1935
1936      default: break;
1937    }
1938
1939    // Advance to the next token if the current one is valid.
1940    if (type != 0) context->lexer->lex(token);
1941
1942    return type;
1943}
1944
1945void yyerror(Context* context, const char* reason)
1946{
1947    context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION,
1948                                 context->token->location,
1949                                 reason);
1950}
1951
1952namespace pp {
1953
1954ExpressionParser::ExpressionParser(Lexer* lexer, Diagnostics* diagnostics) :
1955    mLexer(lexer),
1956    mDiagnostics(diagnostics)
1957{
1958}
1959
1960bool ExpressionParser::parse(Token* token, int* result)
1961{
1962    Context context;
1963    context.diagnostics = mDiagnostics;
1964    context.lexer = mLexer;
1965    context.token = token;
1966    context.result = result;
1967    int ret = yyparse(&context);
1968    switch (ret)
1969    {
1970      case 0:
1971      case 1:
1972        break;
1973
1974      case 2:
1975        mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token->location, "");
1976        break;
1977
1978      default:
1979        assert(false);
1980        mDiagnostics->report(Diagnostics::PP_INTERNAL_ERROR, token->location, "");
1981        break;
1982    }
1983
1984    return ret == 0;
1985}
1986
1987}  // namespace pp
1988