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