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