blob: ede3346194b96632c91d87da2d54a7d17d94cc91 [file] [log] [blame]
Jamie Madillb96687d2015-04-30 15:56:51 -04001/* A Bison parser, made by GNU Bison 3.0.4. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00003/* Bison implementation for Yacc-like parsers in C
Jamie Madill185de882014-12-22 15:17:52 -05004
Jamie Madillb96687d2015-04-30 15:56:51 -04005 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
Jamie Madill185de882014-12-22 15:17:52 -05006
alokp@chromium.org04d7d222012-05-16 19:24:07 +00007 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.
Jamie Madill185de882014-12-22 15:17:52 -050011
alokp@chromium.org04d7d222012-05-16 19:24:07 +000012 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.
Jamie Madill185de882014-12-22 15:17:52 -050016
alokp@chromium.org04d7d222012-05-16 19:24:07 +000017 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.
Jamie Madill185de882014-12-22 15:17:52 -050029
alokp@chromium.org04d7d222012-05-16 19:24:07 +000030 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. */
Jamie Madillb96687d2015-04-30 15:56:51 -040047#define YYBISON_VERSION "3.0.4"
alokp@chromium.org04d7d222012-05-16 19:24:07 +000048
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
alokp@chromium.org04d7d222012-05-16 19:24:07 +000061
62/* Substitute the variable and function names. */
63#define yyparse ppparse
64#define yylex pplex
65#define yyerror pperror
alokp@chromium.org04d7d222012-05-16 19:24:07 +000066#define yydebug ppdebug
67#define yynerrs ppnerrs
68
Jamie Madill185de882014-12-22 15:17:52 -050069
alokp@chromium.org04d7d222012-05-16 19:24:07 +000070/* Copy the first part of user declarations. */
71
72
73//
74// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
75// Use of this source code is governed by a BSD-style license that can be
76// found in the LICENSE file.
77//
78
79// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
80
81#if defined(__GNUC__)
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000082// Triggered by the auto-generated pplval variable.
shannon.woods@transgaming.comeb68fd02013-02-28 23:20:01 +000083#if !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
daniel@transgaming.comb3077d02013-01-11 04:12:09 +000084#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
shannon.woods@transgaming.comeb68fd02013-02-28 23:20:01 +000085#else
86#pragma GCC diagnostic ignored "-Wuninitialized"
shannon.woods@transgaming.come36fddf2013-01-25 21:57:50 +000087#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +000088#elif defined(_MSC_VER)
Minmin Gong794e0002015-04-07 18:31:54 -070089#pragma warning(disable: 4065 4244 4701 4702)
alokp@chromium.org04d7d222012-05-16 19:24:07 +000090#endif
91
92#include "ExpressionParser.h"
93
Jamie Madilla738f082013-11-01 17:45:04 -040094#if defined(_MSC_VER)
Jamie Madilld7f21352013-10-30 17:53:15 -040095#include <malloc.h>
Jamie Madilla738f082013-11-01 17:45:04 -040096#else
97#include <stdlib.h>
98#endif
99
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000100#include <cassert>
101#include <sstream>
Olli Etuaho7f9a55f2016-10-03 14:32:08 +0100102#include <stdint.h>
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000103
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000104#include "DiagnosticsBase.h"
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000105#include "Lexer.h"
106#include "Token.h"
Olli Etuaho7f9a55f2016-10-03 14:32:08 +0100107#include "common/mathutil.h"
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000108
Olli Etuaho7f9a55f2016-10-03 14:32:08 +0100109typedef int32_t YYSTYPE;
110typedef uint32_t UNSIGNED_TYPE;
Olli Etuaho3187a382015-09-09 12:00:12 +0300111
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000112#define YYENABLE_NLS 0
113#define YYLTYPE_IS_TRIVIAL 1
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000114#define YYSTYPE_IS_TRIVIAL 1
115#define YYSTYPE_IS_DECLARED 1
116
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000117namespace {
118struct Context
119{
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000120 pp::Diagnostics* diagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000121 pp::Lexer* lexer;
122 pp::Token* token;
123 int* result;
Olli Etuaho247374c2015-09-09 15:07:24 +0300124 bool parsePresetToken;
125
126 pp::ExpressionParser::ErrorSettings errorSettings;
127 bool *valid;
Olli Etuaho809ec542015-08-26 14:30:57 +0300128
129 void startIgnoreErrors() { ++ignoreErrors; }
130 void endIgnoreErrors() { --ignoreErrors; }
131
132 bool isIgnoringErrors() { return ignoreErrors > 0; }
133
134 int ignoreErrors;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000135};
136} // namespace
137
138
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000139static int yylex(YYSTYPE* lvalp, Context* context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000140static void yyerror(Context* context, const char* reason);
141
142
143
Jamie Madill185de882014-12-22 15:17:52 -0500144# ifndef YY_NULLPTR
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000145# if defined __cplusplus && 201103L <= __cplusplus
Jamie Madill185de882014-12-22 15:17:52 -0500146# define YY_NULLPTR nullptr
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000147# else
Jamie Madill185de882014-12-22 15:17:52 -0500148# define YY_NULLPTR 0
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000149# endif
150# endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000151
152/* Enabling verbose error messages. */
153#ifdef YYERROR_VERBOSE
154# undef YYERROR_VERBOSE
155# define YYERROR_VERBOSE 1
156#else
157# define YYERROR_VERBOSE 0
158#endif
159
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000160
Jamie Madill185de882014-12-22 15:17:52 -0500161/* Debug traces. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000162#ifndef YYDEBUG
163# define YYDEBUG 0
164#endif
165#if YYDEBUG
166extern int ppdebug;
167#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000168
Jamie Madill185de882014-12-22 15:17:52 -0500169/* Token type. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000170#ifndef YYTOKENTYPE
171# define YYTOKENTYPE
Jamie Madill185de882014-12-22 15:17:52 -0500172 enum yytokentype
173 {
174 TOK_CONST_INT = 258,
Olli Etuaho809ec542015-08-26 14:30:57 +0300175 TOK_IDENTIFIER = 259,
176 TOK_OP_OR = 260,
177 TOK_OP_AND = 261,
178 TOK_OP_EQ = 262,
179 TOK_OP_NE = 263,
180 TOK_OP_LE = 264,
181 TOK_OP_GE = 265,
182 TOK_OP_LEFT = 266,
183 TOK_OP_RIGHT = 267,
184 TOK_UNARY = 268
Jamie Madill185de882014-12-22 15:17:52 -0500185 };
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000186#endif
187
Jamie Madill185de882014-12-22 15:17:52 -0500188/* Value type. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000189#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
190typedef int YYSTYPE;
191# define YYSTYPE_IS_TRIVIAL 1
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000192# define YYSTYPE_IS_DECLARED 1
193#endif
194
195
Jamie Madill185de882014-12-22 15:17:52 -0500196
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000197int ppparse (Context *context);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000198
199
200
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000201/* Copy the second part of user declarations. */
202
203
204
205#ifdef short
206# undef short
207#endif
208
209#ifdef YYTYPE_UINT8
210typedef YYTYPE_UINT8 yytype_uint8;
211#else
212typedef unsigned char yytype_uint8;
213#endif
214
215#ifdef YYTYPE_INT8
216typedef YYTYPE_INT8 yytype_int8;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000217#else
Jamie Madill185de882014-12-22 15:17:52 -0500218typedef signed char yytype_int8;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000219#endif
220
221#ifdef YYTYPE_UINT16
222typedef YYTYPE_UINT16 yytype_uint16;
223#else
224typedef unsigned short int yytype_uint16;
225#endif
226
227#ifdef YYTYPE_INT16
228typedef YYTYPE_INT16 yytype_int16;
229#else
230typedef short int yytype_int16;
231#endif
232
233#ifndef YYSIZE_T
234# ifdef __SIZE_TYPE__
235# define YYSIZE_T __SIZE_TYPE__
236# elif defined size_t
237# define YYSIZE_T size_t
Jamie Madill185de882014-12-22 15:17:52 -0500238# elif ! defined YYSIZE_T
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000239# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
240# define YYSIZE_T size_t
241# else
242# define YYSIZE_T unsigned int
243# endif
244#endif
245
246#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
247
248#ifndef YY_
249# if defined YYENABLE_NLS && YYENABLE_NLS
250# if ENABLE_NLS
251# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000252# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000253# endif
254# endif
255# ifndef YY_
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000256# define YY_(Msgid) Msgid
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000257# endif
258#endif
259
Jamie Madill185de882014-12-22 15:17:52 -0500260#ifndef YY_ATTRIBUTE
261# if (defined __GNUC__ \
262 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
263 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
264# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
265# else
266# define YY_ATTRIBUTE(Spec) /* empty */
267# endif
268#endif
269
270#ifndef YY_ATTRIBUTE_PURE
271# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
272#endif
273
274#ifndef YY_ATTRIBUTE_UNUSED
275# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
276#endif
277
278#if !defined _Noreturn \
279 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
280# if defined _MSC_VER && 1200 <= _MSC_VER
281# define _Noreturn __declspec (noreturn)
282# else
283# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400284# endif
285#endif
286
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000287/* Suppress unused-variable warnings by "using" E. */
288#if ! defined lint || defined __GNUC__
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000289# define YYUSE(E) ((void) (E))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000290#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000291# define YYUSE(E) /* empty */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000292#endif
293
Jamie Madill185de882014-12-22 15:17:52 -0500294#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
295/* Suppress an incorrect diagnostic about yylval being uninitialized. */
296# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
297 _Pragma ("GCC diagnostic push") \
298 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
299 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
300# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
301 _Pragma ("GCC diagnostic pop")
302#else
303# define YY_INITIAL_VALUE(Value) Value
304#endif
305#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
306# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
307# define YY_IGNORE_MAYBE_UNINITIALIZED_END
308#endif
309#ifndef YY_INITIAL_VALUE
310# define YY_INITIAL_VALUE(Value) /* Nothing. */
311#endif
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400312
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000313
314#if ! defined yyoverflow || YYERROR_VERBOSE
315
316/* The parser invokes alloca or malloc; define the necessary symbols. */
317
318# ifdef YYSTACK_USE_ALLOCA
319# if YYSTACK_USE_ALLOCA
320# ifdef __GNUC__
321# define YYSTACK_ALLOC __builtin_alloca
322# elif defined __BUILTIN_VA_ARG_INCR
323# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
324# elif defined _AIX
325# define YYSTACK_ALLOC __alloca
326# elif defined _MSC_VER
327# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
328# define alloca _alloca
329# else
330# define YYSTACK_ALLOC alloca
Jamie Madill185de882014-12-22 15:17:52 -0500331# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000332# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000333 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
334# ifndef EXIT_SUCCESS
335# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000336# endif
337# endif
338# endif
339# endif
340# endif
341
342# ifdef YYSTACK_ALLOC
Jamie Madill185de882014-12-22 15:17:52 -0500343 /* Pacify GCC's 'empty if-body' warning. */
344# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000345# ifndef YYSTACK_ALLOC_MAXIMUM
346 /* The OS might guarantee only one guard page at the bottom of the stack,
347 and a page size can be as small as 4096 bytes. So we cannot safely
348 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
349 to allow for a few compiler-allocated temporary stack slots. */
350# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
351# endif
352# else
353# define YYSTACK_ALLOC YYMALLOC
354# define YYSTACK_FREE YYFREE
355# ifndef YYSTACK_ALLOC_MAXIMUM
356# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
357# endif
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000358# if (defined __cplusplus && ! defined EXIT_SUCCESS \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000359 && ! ((defined YYMALLOC || defined malloc) \
Jamie Madill185de882014-12-22 15:17:52 -0500360 && (defined YYFREE || defined free)))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000361# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000362# ifndef EXIT_SUCCESS
363# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000364# endif
365# endif
366# ifndef YYMALLOC
367# define YYMALLOC malloc
Jamie Madill185de882014-12-22 15:17:52 -0500368# if ! defined malloc && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000369void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
370# endif
371# endif
372# ifndef YYFREE
373# define YYFREE free
Jamie Madill185de882014-12-22 15:17:52 -0500374# if ! defined free && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000375void free (void *); /* INFRINGES ON USER NAME SPACE */
376# endif
377# endif
378# endif
379#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
380
381
382#if (! defined yyoverflow \
383 && (! defined __cplusplus \
Jamie Madill185de882014-12-22 15:17:52 -0500384 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000385
386/* A type that is properly aligned for any stack member. */
387union yyalloc
388{
389 yytype_int16 yyss_alloc;
390 YYSTYPE yyvs_alloc;
391};
392
393/* The size of the maximum gap between one aligned stack and the next. */
394# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
395
396/* The size of an array large to enough to hold all stacks, each with
397 N elements. */
398# define YYSTACK_BYTES(N) \
399 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
400 + YYSTACK_GAP_MAXIMUM)
401
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000402# define YYCOPY_NEEDED 1
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000403
404/* Relocate STACK from its old location to the new one. The
405 local variables YYSIZE and YYSTACKSIZE give the old and new number of
406 elements in the stack, and YYPTR gives the new location of the
407 stack. Advance YYPTR to a properly aligned location for the next
408 stack. */
Jamie Madill185de882014-12-22 15:17:52 -0500409# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
410 do \
411 { \
412 YYSIZE_T yynewbytes; \
413 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
414 Stack = &yyptr->Stack_alloc; \
415 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
416 yyptr += yynewbytes / sizeof (*yyptr); \
417 } \
418 while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000419
420#endif
421
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000422#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
423/* Copy COUNT objects from SRC to DST. The source and destination do
424 not overlap. */
425# ifndef YYCOPY
426# if defined __GNUC__ && 1 < __GNUC__
427# define YYCOPY(Dst, Src, Count) \
428 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
429# else
430# define YYCOPY(Dst, Src, Count) \
431 do \
432 { \
433 YYSIZE_T yyi; \
434 for (yyi = 0; yyi < (Count); yyi++) \
435 (Dst)[yyi] = (Src)[yyi]; \
436 } \
Jamie Madill185de882014-12-22 15:17:52 -0500437 while (0)
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000438# endif
439# endif
440#endif /* !YYCOPY_NEEDED */
441
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000442/* YYFINAL -- State number of the termination state. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300443#define YYFINAL 15
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000444/* YYLAST -- Last index in YYTABLE. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300445#define YYLAST 176
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000446
447/* YYNTOKENS -- Number of terminals. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300448#define YYNTOKENS 28
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000449/* YYNNTS -- Number of nonterminals. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300450#define YYNNTS 5
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000451/* YYNRULES -- Number of rules. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300452#define YYNRULES 29
Jamie Madill185de882014-12-22 15:17:52 -0500453/* YYNSTATES -- Number of states. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300454#define YYNSTATES 55
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000455
Jamie Madill185de882014-12-22 15:17:52 -0500456/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
457 by yylex, with out-of-bounds checking. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000458#define YYUNDEFTOK 2
Olli Etuaho809ec542015-08-26 14:30:57 +0300459#define YYMAXUTOK 268
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000460
Jamie Madill185de882014-12-22 15:17:52 -0500461#define YYTRANSLATE(YYX) \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000462 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
463
Jamie Madill185de882014-12-22 15:17:52 -0500464/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
465 as returned by yylex, without out-of-bounds checking. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000466static const yytype_uint8 yytranslate[] =
467{
468 0, 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,
Olli Etuaho809ec542015-08-26 14:30:57 +0300471 2, 2, 2, 24, 2, 2, 2, 22, 9, 2,
472 26, 27, 20, 18, 2, 19, 2, 21, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000473 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho809ec542015-08-26 14:30:57 +0300474 12, 2, 13, 2, 2, 2, 2, 2, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000475 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
476 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho809ec542015-08-26 14:30:57 +0300477 2, 2, 2, 2, 8, 2, 2, 2, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000478 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
479 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho809ec542015-08-26 14:30:57 +0300480 2, 2, 2, 2, 7, 2, 25, 2, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000481 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
482 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
483 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
484 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
485 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
486 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
487 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
488 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
489 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
490 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
491 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
492 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
493 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
Olli Etuaho809ec542015-08-26 14:30:57 +0300494 5, 6, 10, 11, 14, 15, 16, 17, 23
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000495};
496
497#if YYDEBUG
Jamie Madill185de882014-12-22 15:17:52 -0500498 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
Olli Etuahoa3d384a2017-10-06 16:12:50 +0300499static const yytype_uint16 yyrline[] = {0, 108, 108, 115, 116, 127, 127, 148, 148, 169,
500 172, 175, 178, 181, 184, 187, 190, 193, 196, 221,
501 243, 246, 249, 275, 302, 305, 308, 311, 323, 326};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000502#endif
503
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000504#if YYDEBUG || YYERROR_VERBOSE || 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000505/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
506 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
507static const char *const yytname[] =
508{
Olli Etuaho809ec542015-08-26 14:30:57 +0300509 "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_IDENTIFIER",
510 "TOK_OP_OR", "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_EQ", "TOK_OP_NE",
511 "'<'", "'>'", "TOK_OP_LE", "TOK_OP_GE", "TOK_OP_LEFT", "TOK_OP_RIGHT",
512 "'+'", "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('",
513 "')'", "$accept", "input", "expression", "$@1", "$@2", YY_NULLPTR
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000514};
515#endif
516
517# ifdef YYPRINT
Jamie Madill185de882014-12-22 15:17:52 -0500518/* YYTOKNUM[NUM] -- (External) token number corresponding to the
519 (internal) symbol number NUM (which must be that of a token). */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000520static const yytype_uint16 yytoknum[] =
521{
Olli Etuaho809ec542015-08-26 14:30:57 +0300522 0, 256, 257, 258, 259, 260, 261, 124, 94, 38,
523 262, 263, 60, 62, 264, 265, 266, 267, 43, 45,
524 42, 47, 37, 268, 33, 126, 40, 41
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000525};
526# endif
527
Olli Etuaho809ec542015-08-26 14:30:57 +0300528#define YYPACT_NINF -12
Jamie Madill185de882014-12-22 15:17:52 -0500529
530#define yypact_value_is_default(Yystate) \
Olli Etuaho809ec542015-08-26 14:30:57 +0300531 (!!((Yystate) == (-12)))
Jamie Madill185de882014-12-22 15:17:52 -0500532
533#define YYTABLE_NINF -1
534
535#define yytable_value_is_error(Yytable_value) \
536 0
537
538 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
539 STATE-NUM. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000540static const yytype_int16 yypact[] =
541{
Olli Etuaho809ec542015-08-26 14:30:57 +0300542 31, -12, -12, 31, 31, 31, 31, 31, 51, 76,
543 -12, -12, -12, -12, 53, -12, -12, -12, 31, 31,
544 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
545 31, 31, 31, 31, -12, 31, 31, 124, 138, 26,
546 149, 149, -11, -11, -11, -11, 154, 154, -8, -8,
547 -12, -12, -12, 93, 109
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000548};
549
Jamie Madill185de882014-12-22 15:17:52 -0500550 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
551 Performed when YYTABLE does not specify something else to do. Zero
552 means the default is an error. */
553static const yytype_uint8 yydefact[] =
554{
Olli Etuaho809ec542015-08-26 14:30:57 +0300555 0, 3, 4, 0, 0, 0, 0, 0, 0, 2,
556 28, 27, 25, 26, 0, 1, 5, 7, 0, 0,
Jamie Madill185de882014-12-22 15:17:52 -0500557 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Olli Etuaho809ec542015-08-26 14:30:57 +0300558 0, 0, 0, 0, 29, 0, 0, 9, 10, 11,
559 13, 12, 17, 16, 15, 14, 19, 18, 21, 20,
560 24, 23, 22, 6, 8
Jamie Madill185de882014-12-22 15:17:52 -0500561};
562
563 /* YYPGOTO[NTERM-NUM]. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000564static const yytype_int8 yypgoto[] =
565{
Olli Etuaho809ec542015-08-26 14:30:57 +0300566 -12, -12, -3, -12, -12
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000567};
568
Jamie Madill185de882014-12-22 15:17:52 -0500569 /* YYDEFGOTO[NTERM-NUM]. */
570static const yytype_int8 yydefgoto[] =
571{
Olli Etuaho809ec542015-08-26 14:30:57 +0300572 -1, 8, 9, 35, 36
Jamie Madill185de882014-12-22 15:17:52 -0500573};
574
575 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
576 positive, shift that token. If negative, reduce the rule whose
577 number is the opposite. If YYTABLE_NINF, syntax error. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000578static const yytype_uint8 yytable[] =
579{
Olli Etuaho809ec542015-08-26 14:30:57 +0300580 10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
581 32, 33, 31, 32, 33, 37, 38, 39, 40, 41,
582 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
583 52, 0, 53, 54, 1, 2, 21, 22, 23, 24,
584 25, 26, 27, 28, 29, 30, 31, 32, 33, 3,
585 4, 15, 0, 0, 0, 5, 6, 7, 16, 17,
586 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
587 28, 29, 30, 31, 32, 33, 0, 0, 0, 0,
588 34, 16, 17, 18, 19, 20, 21, 22, 23, 24,
589 25, 26, 27, 28, 29, 30, 31, 32, 33, 17,
590 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
591 28, 29, 30, 31, 32, 33, 18, 19, 20, 21,
592 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
593 32, 33, 19, 20, 21, 22, 23, 24, 25, 26,
594 27, 28, 29, 30, 31, 32, 33, 20, 21, 22,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000595 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
Olli Etuaho809ec542015-08-26 14:30:57 +0300596 33, 23, 24, 25, 26, 27, 28, 29, 30, 31,
597 32, 33, 29, 30, 31, 32, 33
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000598};
599
600static const yytype_int8 yycheck[] =
601{
Olli Etuaho809ec542015-08-26 14:30:57 +0300602 3, 4, 5, 6, 7, 16, 17, 18, 19, 20,
603 21, 22, 20, 21, 22, 18, 19, 20, 21, 22,
604 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
605 33, -1, 35, 36, 3, 4, 10, 11, 12, 13,
606 14, 15, 16, 17, 18, 19, 20, 21, 22, 18,
607 19, 0, -1, -1, -1, 24, 25, 26, 5, 6,
608 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
609 17, 18, 19, 20, 21, 22, -1, -1, -1, -1,
610 27, 5, 6, 7, 8, 9, 10, 11, 12, 13,
611 14, 15, 16, 17, 18, 19, 20, 21, 22, 6,
612 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
613 17, 18, 19, 20, 21, 22, 7, 8, 9, 10,
614 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
615 21, 22, 8, 9, 10, 11, 12, 13, 14, 15,
616 16, 17, 18, 19, 20, 21, 22, 9, 10, 11,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000617 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
Olli Etuaho809ec542015-08-26 14:30:57 +0300618 22, 12, 13, 14, 15, 16, 17, 18, 19, 20,
619 21, 22, 18, 19, 20, 21, 22
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000620};
621
Jamie Madill185de882014-12-22 15:17:52 -0500622 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
623 symbol of state STATE-NUM. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000624static const yytype_uint8 yystos[] =
625{
Olli Etuaho809ec542015-08-26 14:30:57 +0300626 0, 3, 4, 18, 19, 24, 25, 26, 29, 30,
627 30, 30, 30, 30, 30, 0, 5, 6, 7, 8,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000628 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
Olli Etuaho809ec542015-08-26 14:30:57 +0300629 19, 20, 21, 22, 27, 31, 32, 30, 30, 30,
630 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
631 30, 30, 30, 30, 30
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000632};
633
Jamie Madill185de882014-12-22 15:17:52 -0500634 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
635static const yytype_uint8 yyr1[] =
636{
Olli Etuaho809ec542015-08-26 14:30:57 +0300637 0, 28, 29, 30, 30, 31, 30, 32, 30, 30,
638 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
639 30, 30, 30, 30, 30, 30, 30, 30, 30, 30
Jamie Madill185de882014-12-22 15:17:52 -0500640};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000641
Jamie Madill185de882014-12-22 15:17:52 -0500642 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
643static const yytype_uint8 yyr2[] =
644{
Olli Etuaho809ec542015-08-26 14:30:57 +0300645 0, 2, 1, 1, 1, 0, 4, 0, 4, 3,
Jamie Madill185de882014-12-22 15:17:52 -0500646 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
Olli Etuaho809ec542015-08-26 14:30:57 +0300647 3, 3, 3, 3, 3, 2, 2, 2, 2, 3
Jamie Madill185de882014-12-22 15:17:52 -0500648};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000649
650
Jamie Madill185de882014-12-22 15:17:52 -0500651#define yyerrok (yyerrstatus = 0)
652#define yyclearin (yychar = YYEMPTY)
653#define YYEMPTY (-2)
654#define YYEOF 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000655
Jamie Madill185de882014-12-22 15:17:52 -0500656#define YYACCEPT goto yyacceptlab
657#define YYABORT goto yyabortlab
658#define YYERROR goto yyerrorlab
659
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000660
661#define YYRECOVERING() (!!yyerrstatus)
662
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000663#define YYBACKUP(Token, Value) \
664do \
665 if (yychar == YYEMPTY) \
666 { \
667 yychar = (Token); \
668 yylval = (Value); \
669 YYPOPSTACK (yylen); \
670 yystate = *yyssp; \
671 goto yybackup; \
672 } \
673 else \
674 { \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000675 yyerror (context, YY_("syntax error: cannot back up")); \
Jamie Madill185de882014-12-22 15:17:52 -0500676 YYERROR; \
677 } \
678while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000679
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000680/* Error token number */
Jamie Madill185de882014-12-22 15:17:52 -0500681#define YYTERROR 1
682#define YYERRCODE 256
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000683
684
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000685
686/* Enable debugging if requested. */
687#if YYDEBUG
688
689# ifndef YYFPRINTF
690# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
691# define YYFPRINTF fprintf
692# endif
693
Jamie Madill185de882014-12-22 15:17:52 -0500694# define YYDPRINTF(Args) \
695do { \
696 if (yydebug) \
697 YYFPRINTF Args; \
698} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000699
Jamie Madill185de882014-12-22 15:17:52 -0500700/* This macro is provided for backward compatibility. */
701#ifndef YY_LOCATION_PRINT
702# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
703#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000704
705
Jamie Madill185de882014-12-22 15:17:52 -0500706# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
707do { \
708 if (yydebug) \
709 { \
710 YYFPRINTF (stderr, "%s ", Title); \
711 yy_symbol_print (stderr, \
712 Type, Value, context); \
713 YYFPRINTF (stderr, "\n"); \
714 } \
715} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000716
Jamie Madill185de882014-12-22 15:17:52 -0500717
718/*----------------------------------------.
719| Print this symbol's value on YYOUTPUT. |
720`----------------------------------------*/
721
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000722static void
723yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000724{
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000725 FILE *yyo = yyoutput;
726 YYUSE (yyo);
Jamie Madill185de882014-12-22 15:17:52 -0500727 YYUSE (context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000728 if (!yyvaluep)
729 return;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000730# ifdef YYPRINT
731 if (yytype < YYNTOKENS)
732 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000733# endif
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400734 YYUSE (yytype);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000735}
736
737
738/*--------------------------------.
739| Print this symbol on YYOUTPUT. |
740`--------------------------------*/
741
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000742static void
743yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000744{
Jamie Madill185de882014-12-22 15:17:52 -0500745 YYFPRINTF (yyoutput, "%s %s (",
746 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000747
748 yy_symbol_value_print (yyoutput, yytype, yyvaluep, context);
749 YYFPRINTF (yyoutput, ")");
750}
751
752/*------------------------------------------------------------------.
753| yy_stack_print -- Print the state stack from its BOTTOM up to its |
754| TOP (included). |
755`------------------------------------------------------------------*/
756
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000757static void
758yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000759{
760 YYFPRINTF (stderr, "Stack now");
761 for (; yybottom <= yytop; yybottom++)
762 {
763 int yybot = *yybottom;
764 YYFPRINTF (stderr, " %d", yybot);
765 }
766 YYFPRINTF (stderr, "\n");
767}
768
Jamie Madill185de882014-12-22 15:17:52 -0500769# define YY_STACK_PRINT(Bottom, Top) \
770do { \
771 if (yydebug) \
772 yy_stack_print ((Bottom), (Top)); \
773} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000774
775
776/*------------------------------------------------.
777| Report that the YYRULE is going to be reduced. |
778`------------------------------------------------*/
779
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000780static void
Jamie Madill185de882014-12-22 15:17:52 -0500781yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000782{
Jamie Madill185de882014-12-22 15:17:52 -0500783 unsigned long int yylno = yyrline[yyrule];
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000784 int yynrhs = yyr2[yyrule];
785 int yyi;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000786 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
Jamie Madill185de882014-12-22 15:17:52 -0500787 yyrule - 1, yylno);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000788 /* The symbols being reduced. */
789 for (yyi = 0; yyi < yynrhs; yyi++)
790 {
791 YYFPRINTF (stderr, " $%d = ", yyi + 1);
Jamie Madill185de882014-12-22 15:17:52 -0500792 yy_symbol_print (stderr,
793 yystos[yyssp[yyi + 1 - yynrhs]],
794 &(yyvsp[(yyi + 1) - (yynrhs)])
795 , context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000796 YYFPRINTF (stderr, "\n");
797 }
798}
799
Jamie Madill185de882014-12-22 15:17:52 -0500800# define YY_REDUCE_PRINT(Rule) \
801do { \
802 if (yydebug) \
803 yy_reduce_print (yyssp, yyvsp, Rule, context); \
804} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000805
806/* Nonzero means print parse trace. It is left uninitialized so that
807 multiple parsers can coexist. */
808int yydebug;
809#else /* !YYDEBUG */
810# define YYDPRINTF(Args)
811# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
812# define YY_STACK_PRINT(Bottom, Top)
813# define YY_REDUCE_PRINT(Rule)
814#endif /* !YYDEBUG */
815
816
817/* YYINITDEPTH -- initial size of the parser's stacks. */
Jamie Madill185de882014-12-22 15:17:52 -0500818#ifndef YYINITDEPTH
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000819# define YYINITDEPTH 200
820#endif
821
822/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
823 if the built-in stack extension method is used).
824
825 Do not make this value too large; the results are undefined if
826 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
827 evaluated with infinite-precision integer arithmetic. */
828
829#ifndef YYMAXDEPTH
830# define YYMAXDEPTH 10000
831#endif
832
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000833
834#if YYERROR_VERBOSE
835
836# ifndef yystrlen
837# if defined __GLIBC__ && defined _STRING_H
838# define yystrlen strlen
839# else
840/* Return the length of YYSTR. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000841static YYSIZE_T
842yystrlen (const char *yystr)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000843{
844 YYSIZE_T yylen;
845 for (yylen = 0; yystr[yylen]; yylen++)
846 continue;
847 return yylen;
848}
849# endif
850# endif
851
852# ifndef yystpcpy
853# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
854# define yystpcpy stpcpy
855# else
856/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
857 YYDEST. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000858static char *
859yystpcpy (char *yydest, const char *yysrc)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000860{
861 char *yyd = yydest;
862 const char *yys = yysrc;
863
864 while ((*yyd++ = *yys++) != '\0')
865 continue;
866
867 return yyd - 1;
868}
869# endif
870# endif
871
872# ifndef yytnamerr
873/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
874 quotes and backslashes, so that it's suitable for yyerror. The
875 heuristic is that double-quoting is unnecessary unless the string
876 contains an apostrophe, a comma, or backslash (other than
877 backslash-backslash). YYSTR is taken from yytname. If YYRES is
878 null, do not copy; instead, return the length of what the result
879 would have been. */
880static YYSIZE_T
881yytnamerr (char *yyres, const char *yystr)
882{
883 if (*yystr == '"')
884 {
885 YYSIZE_T yyn = 0;
886 char const *yyp = yystr;
887
888 for (;;)
Jamie Madill185de882014-12-22 15:17:52 -0500889 switch (*++yyp)
890 {
891 case '\'':
892 case ',':
893 goto do_not_strip_quotes;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000894
Jamie Madill185de882014-12-22 15:17:52 -0500895 case '\\':
896 if (*++yyp != '\\')
897 goto do_not_strip_quotes;
898 /* Fall through. */
899 default:
900 if (yyres)
901 yyres[yyn] = *yyp;
902 yyn++;
903 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000904
Jamie Madill185de882014-12-22 15:17:52 -0500905 case '"':
906 if (yyres)
907 yyres[yyn] = '\0';
908 return yyn;
909 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000910 do_not_strip_quotes: ;
911 }
912
913 if (! yyres)
914 return yystrlen (yystr);
915
916 return yystpcpy (yyres, yystr) - yyres;
917}
918# endif
919
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000920/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
921 about the unexpected token YYTOKEN for the state stack whose top is
922 YYSSP.
923
924 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
925 not large enough to hold the message. In that case, also set
926 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
927 required number of bytes is too large to store. */
928static int
929yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
930 yytype_int16 *yyssp, int yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000931{
Jamie Madill185de882014-12-22 15:17:52 -0500932 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000933 YYSIZE_T yysize = yysize0;
934 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
935 /* Internationalized format string. */
Jamie Madill185de882014-12-22 15:17:52 -0500936 const char *yyformat = YY_NULLPTR;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000937 /* Arguments of yyformat. */
938 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
939 /* Number of reported tokens (one for the "unexpected", one per
940 "expected"). */
941 int yycount = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000942
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000943 /* There are many possibilities here to consider:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000944 - If this state is a consistent state with a default action, then
945 the only way this function was invoked is if the default action
946 is an error action. In that case, don't check for expected
947 tokens because there are none.
948 - The only way there can be no lookahead present (in yychar) is if
949 this state is a consistent state with a default action. Thus,
950 detecting the absence of a lookahead is sufficient to determine
951 that there is no unexpected or expected token to report. In that
952 case, just report a simple "syntax error".
953 - Don't assume there isn't a lookahead just because this state is a
954 consistent state with a default action. There might have been a
955 previous inconsistent state, consistent state with a non-default
956 action, or user semantic action that manipulated yychar.
957 - Of course, the expected token list depends on states to have
958 correct lookahead information, and it depends on the parser not
959 to perform extra reductions after fetching a lookahead from the
960 scanner and before detecting a syntax error. Thus, state merging
961 (from LALR or IELR) and default reductions corrupt the expected
962 token list. However, the list is correct for canonical LR with
963 one exception: it will still contain any token that will not be
964 accepted due to an error action in a later state.
965 */
966 if (yytoken != YYEMPTY)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000967 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000968 int yyn = yypact[*yyssp];
969 yyarg[yycount++] = yytname[yytoken];
970 if (!yypact_value_is_default (yyn))
971 {
972 /* Start YYX at -YYN if negative to avoid negative indexes in
973 YYCHECK. In other words, skip the first -YYN actions for
974 this state because they are default actions. */
975 int yyxbegin = yyn < 0 ? -yyn : 0;
976 /* Stay within bounds of both yycheck and yytname. */
977 int yychecklim = YYLAST - yyn + 1;
978 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
979 int yyx;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000980
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000981 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
982 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
983 && !yytable_value_is_error (yytable[yyx + yyn]))
984 {
985 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
986 {
987 yycount = 1;
988 yysize = yysize0;
989 break;
990 }
991 yyarg[yycount++] = yytname[yyx];
992 {
Jamie Madill185de882014-12-22 15:17:52 -0500993 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000994 if (! (yysize <= yysize1
995 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
996 return 2;
997 yysize = yysize1;
998 }
999 }
1000 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001001 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001002
1003 switch (yycount)
1004 {
1005# define YYCASE_(N, S) \
1006 case N: \
1007 yyformat = S; \
1008 break
1009 YYCASE_(0, YY_("syntax error"));
1010 YYCASE_(1, YY_("syntax error, unexpected %s"));
1011 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1012 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1013 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1014 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1015# undef YYCASE_
1016 }
1017
1018 {
1019 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1020 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1021 return 2;
1022 yysize = yysize1;
1023 }
1024
1025 if (*yymsg_alloc < yysize)
1026 {
1027 *yymsg_alloc = 2 * yysize;
1028 if (! (yysize <= *yymsg_alloc
1029 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1030 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1031 return 1;
1032 }
1033
1034 /* Avoid sprintf, as that infringes on the user's name space.
1035 Don't have undefined behavior even if the translation
1036 produced a string with the wrong number of "%s"s. */
1037 {
1038 char *yyp = *yymsg;
1039 int yyi = 0;
1040 while ((*yyp = *yyformat) != '\0')
1041 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1042 {
1043 yyp += yytnamerr (yyp, yyarg[yyi++]);
1044 yyformat += 2;
1045 }
1046 else
1047 {
1048 yyp++;
1049 yyformat++;
1050 }
1051 }
1052 return 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001053}
1054#endif /* YYERROR_VERBOSE */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001055
1056/*-----------------------------------------------.
1057| Release the memory associated to this symbol. |
1058`-----------------------------------------------*/
1059
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001060static void
1061yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001062{
1063 YYUSE (yyvaluep);
1064 YYUSE (context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001065 if (!yymsg)
1066 yymsg = "Deleting";
1067 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1068
Jamie Madill185de882014-12-22 15:17:52 -05001069 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Zhenyao Mof1d723c2013-09-23 14:57:07 -04001070 YYUSE (yytype);
Jamie Madill185de882014-12-22 15:17:52 -05001071 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001072}
1073
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001074
1075
1076
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001077/*----------.
1078| yyparse. |
1079`----------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001080
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001081int
1082yyparse (Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001083{
1084/* The lookahead symbol. */
1085int yychar;
1086
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001087
Jamie Madill185de882014-12-22 15:17:52 -05001088/* The semantic value of the lookahead symbol. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001089/* Default value used for initialization, for pacifying older GCCs
1090 or non-GCC compilers. */
Jamie Madill185de882014-12-22 15:17:52 -05001091YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1092YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001093
1094 /* Number of syntax errors so far. */
1095 int yynerrs;
1096
1097 int yystate;
1098 /* Number of tokens to shift before error messages enabled. */
1099 int yyerrstatus;
1100
1101 /* The stacks and their tools:
Jamie Madill185de882014-12-22 15:17:52 -05001102 'yyss': related to states.
1103 'yyvs': related to semantic values.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001104
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001105 Refer to the stacks through separate pointers, to allow yyoverflow
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001106 to reallocate them elsewhere. */
1107
1108 /* The state stack. */
1109 yytype_int16 yyssa[YYINITDEPTH];
1110 yytype_int16 *yyss;
1111 yytype_int16 *yyssp;
1112
1113 /* The semantic value stack. */
1114 YYSTYPE yyvsa[YYINITDEPTH];
1115 YYSTYPE *yyvs;
1116 YYSTYPE *yyvsp;
1117
1118 YYSIZE_T yystacksize;
1119
1120 int yyn;
1121 int yyresult;
1122 /* Lookahead token as an internal (translated) token number. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001123 int yytoken = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001124 /* The variables used to return semantic value and location from the
1125 action routines. */
1126 YYSTYPE yyval;
1127
1128#if YYERROR_VERBOSE
1129 /* Buffer for error messages, and its allocated size. */
1130 char yymsgbuf[128];
1131 char *yymsg = yymsgbuf;
1132 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1133#endif
1134
1135#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1136
1137 /* The number of symbols on the RHS of the reduced rule.
1138 Keep to zero when no symbol should be popped. */
1139 int yylen = 0;
1140
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001141 yyssp = yyss = yyssa;
1142 yyvsp = yyvs = yyvsa;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001143 yystacksize = YYINITDEPTH;
1144
1145 YYDPRINTF ((stderr, "Starting parse\n"));
1146
1147 yystate = 0;
1148 yyerrstatus = 0;
1149 yynerrs = 0;
1150 yychar = YYEMPTY; /* Cause a token to be read. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001151 goto yysetstate;
1152
1153/*------------------------------------------------------------.
1154| yynewstate -- Push a new state, which is found in yystate. |
1155`------------------------------------------------------------*/
1156 yynewstate:
1157 /* In all cases, when you get here, the value and location stacks
1158 have just been pushed. So pushing a state here evens the stacks. */
1159 yyssp++;
1160
1161 yysetstate:
1162 *yyssp = yystate;
1163
1164 if (yyss + yystacksize - 1 <= yyssp)
1165 {
1166 /* Get the current used size of the three stacks, in elements. */
1167 YYSIZE_T yysize = yyssp - yyss + 1;
1168
1169#ifdef yyoverflow
1170 {
Jamie Madill185de882014-12-22 15:17:52 -05001171 /* Give user a chance to reallocate the stack. Use copies of
1172 these so that the &'s don't force the real ones into
1173 memory. */
1174 YYSTYPE *yyvs1 = yyvs;
1175 yytype_int16 *yyss1 = yyss;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001176
Jamie Madill185de882014-12-22 15:17:52 -05001177 /* Each stack pointer address is followed by the size of the
1178 data in use in that stack, in bytes. This used to be a
1179 conditional around just the two extra args, but that might
1180 be undefined if yyoverflow is a macro. */
1181 yyoverflow (YY_("memory exhausted"),
1182 &yyss1, yysize * sizeof (*yyssp),
1183 &yyvs1, yysize * sizeof (*yyvsp),
1184 &yystacksize);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001185
Jamie Madill185de882014-12-22 15:17:52 -05001186 yyss = yyss1;
1187 yyvs = yyvs1;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001188 }
1189#else /* no yyoverflow */
1190# ifndef YYSTACK_RELOCATE
1191 goto yyexhaustedlab;
1192# else
1193 /* Extend the stack our own way. */
1194 if (YYMAXDEPTH <= yystacksize)
Jamie Madill185de882014-12-22 15:17:52 -05001195 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001196 yystacksize *= 2;
1197 if (YYMAXDEPTH < yystacksize)
Jamie Madill185de882014-12-22 15:17:52 -05001198 yystacksize = YYMAXDEPTH;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001199
1200 {
Jamie Madill185de882014-12-22 15:17:52 -05001201 yytype_int16 *yyss1 = yyss;
1202 union yyalloc *yyptr =
1203 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1204 if (! yyptr)
1205 goto yyexhaustedlab;
1206 YYSTACK_RELOCATE (yyss_alloc, yyss);
1207 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001208# undef YYSTACK_RELOCATE
Jamie Madill185de882014-12-22 15:17:52 -05001209 if (yyss1 != yyssa)
1210 YYSTACK_FREE (yyss1);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001211 }
1212# endif
1213#endif /* no yyoverflow */
1214
1215 yyssp = yyss + yysize - 1;
1216 yyvsp = yyvs + yysize - 1;
1217
1218 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
Jamie Madill185de882014-12-22 15:17:52 -05001219 (unsigned long int) yystacksize));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001220
1221 if (yyss + yystacksize - 1 <= yyssp)
Jamie Madill185de882014-12-22 15:17:52 -05001222 YYABORT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001223 }
1224
1225 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1226
1227 if (yystate == YYFINAL)
1228 YYACCEPT;
1229
1230 goto yybackup;
1231
1232/*-----------.
1233| yybackup. |
1234`-----------*/
1235yybackup:
1236
1237 /* Do appropriate processing given the current state. Read a
1238 lookahead token if we need one and don't already have one. */
1239
1240 /* First try to decide what to do without reference to lookahead token. */
1241 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001242 if (yypact_value_is_default (yyn))
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001243 goto yydefault;
1244
1245 /* Not known => get a lookahead token if don't already have one. */
1246
1247 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1248 if (yychar == YYEMPTY)
1249 {
1250 YYDPRINTF ((stderr, "Reading a token: "));
Jamie Madill185de882014-12-22 15:17:52 -05001251 yychar = yylex (&yylval, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001252 }
1253
1254 if (yychar <= YYEOF)
1255 {
1256 yychar = yytoken = YYEOF;
1257 YYDPRINTF ((stderr, "Now at end of input.\n"));
1258 }
1259 else
1260 {
1261 yytoken = YYTRANSLATE (yychar);
1262 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1263 }
1264
1265 /* If the proper action on seeing token YYTOKEN is to reduce or to
1266 detect an error, take that action. */
1267 yyn += yytoken;
1268 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1269 goto yydefault;
1270 yyn = yytable[yyn];
1271 if (yyn <= 0)
1272 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001273 if (yytable_value_is_error (yyn))
1274 goto yyerrlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001275 yyn = -yyn;
1276 goto yyreduce;
1277 }
1278
1279 /* Count tokens shifted since error; after three, turn off error
1280 status. */
1281 if (yyerrstatus)
1282 yyerrstatus--;
1283
1284 /* Shift the lookahead token. */
1285 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1286
1287 /* Discard the shifted token. */
1288 yychar = YYEMPTY;
1289
1290 yystate = yyn;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001291 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001292 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001293 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001294
1295 goto yynewstate;
1296
1297
1298/*-----------------------------------------------------------.
1299| yydefault -- do the default action for the current state. |
1300`-----------------------------------------------------------*/
1301yydefault:
1302 yyn = yydefact[yystate];
1303 if (yyn == 0)
1304 goto yyerrlab;
1305 goto yyreduce;
1306
1307
1308/*-----------------------------.
1309| yyreduce -- Do a reduction. |
1310`-----------------------------*/
1311yyreduce:
1312 /* yyn is the number of a rule to reduce with. */
1313 yylen = yyr2[yyn];
1314
1315 /* If YYLEN is nonzero, implement the default value of the action:
Jamie Madill185de882014-12-22 15:17:52 -05001316 '$$ = $1'.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001317
1318 Otherwise, the following line sets YYVAL to garbage.
1319 This behavior is undocumented and Bison
1320 users should not rely upon it. Assigning to YYVAL
1321 unconditionally makes the parser a bit smaller, and it avoids a
1322 GCC warning that YYVAL may be used uninitialized. */
1323 yyval = yyvsp[1-yylen];
1324
1325
1326 YY_REDUCE_PRINT (yyn);
1327 switch (yyn)
1328 {
1329 case 2:
1330
1331 {
Jamie Madill185de882014-12-22 15:17:52 -05001332 *(context->result) = static_cast<int>((yyvsp[0]));
Olli Etuaho3187a382015-09-09 12:00:12 +03001333 YYACCEPT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001334 }
Jamie Madill185de882014-12-22 15:17:52 -05001335
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001336 break;
1337
1338 case 4:
1339
1340 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001341 if (!context->isIgnoringErrors())
1342 {
Olli Etuaho3187a382015-09-09 12:00:12 +03001343 // This rule should be applied right after the token is lexed, so we can
1344 // refer to context->token in the error message.
Olli Etuaho247374c2015-09-09 15:07:24 +03001345 context->diagnostics->report(context->errorSettings.unexpectedIdentifier,
Olli Etuaho3187a382015-09-09 12:00:12 +03001346 context->token->location, context->token->text);
Olli Etuaho247374c2015-09-09 15:07:24 +03001347 *(context->valid) = false;
Olli Etuaho809ec542015-08-26 14:30:57 +03001348 }
Olli Etuaho3187a382015-09-09 12:00:12 +03001349 (yyval) = (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001350 }
Jamie Madill185de882014-12-22 15:17:52 -05001351
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001352 break;
1353
1354 case 5:
1355
1356 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001357 if ((yyvsp[-1]) != 0)
1358 {
1359 // Ignore errors in the short-circuited part of the expression.
1360 // ESSL3.00 section 3.4:
1361 // If an operand is not evaluated, the presence of undefined identifiers
1362 // in the operand will not cause an error.
1363 // Unevaluated division by zero should not cause an error either.
1364 context->startIgnoreErrors();
1365 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001366 }
Jamie Madill185de882014-12-22 15:17:52 -05001367
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001368 break;
1369
1370 case 6:
1371
1372 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001373 if ((yyvsp[-3]) != 0)
1374 {
1375 context->endIgnoreErrors();
1376 (yyval) = static_cast<YYSTYPE>(1);
1377 }
1378 else
1379 {
1380 (yyval) = (yyvsp[-3]) || (yyvsp[0]);
1381 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001382 }
Jamie Madill185de882014-12-22 15:17:52 -05001383
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001384 break;
1385
1386 case 7:
1387
1388 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001389 if ((yyvsp[-1]) == 0)
1390 {
1391 // Ignore errors in the short-circuited part of the expression.
1392 // ESSL3.00 section 3.4:
1393 // If an operand is not evaluated, the presence of undefined identifiers
1394 // in the operand will not cause an error.
1395 // Unevaluated division by zero should not cause an error either.
1396 context->startIgnoreErrors();
1397 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001398 }
Jamie Madill185de882014-12-22 15:17:52 -05001399
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001400 break;
1401
1402 case 8:
1403
1404 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001405 if ((yyvsp[-3]) == 0)
1406 {
1407 context->endIgnoreErrors();
1408 (yyval) = static_cast<YYSTYPE>(0);
1409 }
1410 else
1411 {
1412 (yyval) = (yyvsp[-3]) && (yyvsp[0]);
1413 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001414 }
Jamie Madill185de882014-12-22 15:17:52 -05001415
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001416 break;
1417
1418 case 9:
1419
1420 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001421 (yyval) = (yyvsp[-2]) | (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001422 }
Jamie Madill185de882014-12-22 15:17:52 -05001423
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001424 break;
1425
1426 case 10:
1427
1428 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001429 (yyval) = (yyvsp[-2]) ^ (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001430 }
Jamie Madill185de882014-12-22 15:17:52 -05001431
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001432 break;
1433
1434 case 11:
1435
1436 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001437 (yyval) = (yyvsp[-2]) & (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001438 }
Jamie Madill185de882014-12-22 15:17:52 -05001439
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001440 break;
1441
1442 case 12:
1443
1444 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001445 (yyval) = (yyvsp[-2]) != (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001446 }
Jamie Madill185de882014-12-22 15:17:52 -05001447
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001448 break;
1449
1450 case 13:
1451
1452 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001453 (yyval) = (yyvsp[-2]) == (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001454 }
Jamie Madill185de882014-12-22 15:17:52 -05001455
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001456 break;
1457
1458 case 14:
1459
1460 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001461 (yyval) = (yyvsp[-2]) >= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001462 }
Jamie Madill185de882014-12-22 15:17:52 -05001463
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001464 break;
1465
1466 case 15:
1467
1468 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001469 (yyval) = (yyvsp[-2]) <= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001470 }
Jamie Madill185de882014-12-22 15:17:52 -05001471
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001472 break;
1473
1474 case 16:
1475
1476 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001477 (yyval) = (yyvsp[-2]) > (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001478 }
Jamie Madill185de882014-12-22 15:17:52 -05001479
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001480 break;
1481
1482 case 17:
1483
1484 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001485 (yyval) = (yyvsp[-2]) < (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001486 }
Jamie Madill185de882014-12-22 15:17:52 -05001487
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001488 break;
1489
1490 case 18:
1491
1492 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001493 if ((yyvsp[0]) < 0 || (yyvsp[0]) > 31)
Jamie Madill461e3af2016-07-21 18:15:34 -04001494 {
1495 if (!context->isIgnoringErrors())
1496 {
1497 std::ostringstream stream;
1498 stream << (yyvsp[-2]) << " >> " << (yyvsp[0]);
1499 std::string text = stream.str();
1500 context->diagnostics->report(pp::Diagnostics::PP_UNDEFINED_SHIFT,
Geoff Lang93561c32016-09-20 10:22:55 -04001501 context->token->location,
1502 text.c_str());
Jamie Madill461e3af2016-07-21 18:15:34 -04001503 *(context->valid) = false;
1504 }
1505 (yyval) = static_cast<YYSTYPE>(0);
1506 }
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001507 else if ((yyvsp[-2]) < 0)
1508 {
1509 // Logical shift right.
1510 (yyval) = static_cast<YYSTYPE>(static_cast<UNSIGNED_TYPE>((yyvsp[-2])) >> (yyvsp[0]));
1511 }
Jamie Madill461e3af2016-07-21 18:15:34 -04001512 else
1513 {
1514 (yyval) = (yyvsp[-2]) >> (yyvsp[0]);
1515 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001516 }
Jamie Madill185de882014-12-22 15:17:52 -05001517
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001518 break;
1519
1520 case 19:
1521
1522 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001523 if ((yyvsp[0]) < 0 || (yyvsp[0]) > 31)
Jamie Madill461e3af2016-07-21 18:15:34 -04001524 {
1525 if (!context->isIgnoringErrors())
1526 {
1527 std::ostringstream stream;
1528 stream << (yyvsp[-2]) << " << " << (yyvsp[0]);
1529 std::string text = stream.str();
1530 context->diagnostics->report(pp::Diagnostics::PP_UNDEFINED_SHIFT,
Geoff Lang93561c32016-09-20 10:22:55 -04001531 context->token->location,
1532 text.c_str());
Jamie Madill461e3af2016-07-21 18:15:34 -04001533 *(context->valid) = false;
1534 }
1535 (yyval) = static_cast<YYSTYPE>(0);
1536 }
1537 else
1538 {
Olli Etuahoa3d384a2017-10-06 16:12:50 +03001539 // Logical shift left. Casting to unsigned is needed to ensure there's no signed integer
1540 // overflow, which some tools treat as an error.
1541 (yyval) = static_cast<YYSTYPE>(static_cast<UNSIGNED_TYPE>((yyvsp[-2])) << (yyvsp[0]));
Jamie Madill461e3af2016-07-21 18:15:34 -04001542 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001543 }
Jamie Madill185de882014-12-22 15:17:52 -05001544
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001545 break;
1546
1547 case 20:
1548
1549 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001550 (yyval) = gl::WrappingDiff<YYSTYPE>((yyvsp[-2]), (yyvsp[0]));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001551 }
Jamie Madill185de882014-12-22 15:17:52 -05001552
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001553 break;
1554
1555 case 21:
1556
1557 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001558 (yyval) = gl::WrappingSum<YYSTYPE>((yyvsp[-2]), (yyvsp[0]));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001559 }
Jamie Madill185de882014-12-22 15:17:52 -05001560
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001561 break;
1562
1563 case 22:
1564
1565 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001566 if ((yyvsp[0]) == 0)
1567 {
Olli Etuaho3187a382015-09-09 12:00:12 +03001568 if (!context->isIgnoringErrors())
Olli Etuaho809ec542015-08-26 14:30:57 +03001569 {
1570 std::ostringstream stream;
1571 stream << (yyvsp[-2]) << " % " << (yyvsp[0]);
1572 std::string text = stream.str();
1573 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1574 context->token->location,
1575 text.c_str());
Olli Etuaho247374c2015-09-09 15:07:24 +03001576 *(context->valid) = false;
Olli Etuaho809ec542015-08-26 14:30:57 +03001577 }
Olli Etuaho3187a382015-09-09 12:00:12 +03001578 (yyval) = static_cast<YYSTYPE>(0);
Olli Etuaho809ec542015-08-26 14:30:57 +03001579 }
Olli Etuahod1d1dff2016-11-03 14:56:14 +00001580 else if (((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min()) && ((yyvsp[0]) == -1))
1581 {
1582 // Check for the special case where the minimum representable number is
1583 // divided by -1. If left alone this has undefined results.
1584 (yyval) = 0;
1585 }
Olli Etuaho809ec542015-08-26 14:30:57 +03001586 else
1587 {
1588 (yyval) = (yyvsp[-2]) % (yyvsp[0]);
1589 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001590 }
Jamie Madill185de882014-12-22 15:17:52 -05001591
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001592 break;
1593
1594 case 23:
1595
1596 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001597 if ((yyvsp[0]) == 0)
1598 {
Olli Etuaho3187a382015-09-09 12:00:12 +03001599 if (!context->isIgnoringErrors())
Olli Etuaho809ec542015-08-26 14:30:57 +03001600 {
1601 std::ostringstream stream;
1602 stream << (yyvsp[-2]) << " / " << (yyvsp[0]);
1603 std::string text = stream.str();
1604 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1605 context->token->location,
1606 text.c_str());
Olli Etuaho247374c2015-09-09 15:07:24 +03001607 *(context->valid) = false;
Olli Etuaho809ec542015-08-26 14:30:57 +03001608 }
Olli Etuaho3187a382015-09-09 12:00:12 +03001609 (yyval) = static_cast<YYSTYPE>(0);
Olli Etuaho809ec542015-08-26 14:30:57 +03001610 }
Olli Etuahod1d1dff2016-11-03 14:56:14 +00001611 else if (((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min()) && ((yyvsp[0]) == -1))
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001612 {
1613 // Check for the special case where the minimum representable number is
1614 // divided by -1. If left alone this leads to integer overflow in C++, which
1615 // has undefined results.
1616 (yyval) = std::numeric_limits<YYSTYPE>::max();
1617 }
Olli Etuaho809ec542015-08-26 14:30:57 +03001618 else
1619 {
1620 (yyval) = (yyvsp[-2]) / (yyvsp[0]);
1621 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001622 }
Jamie Madill185de882014-12-22 15:17:52 -05001623
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001624 break;
1625
1626 case 24:
1627
1628 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001629 (yyval) = gl::WrappingMul((yyvsp[-2]), (yyvsp[0]));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001630 }
Jamie Madill185de882014-12-22 15:17:52 -05001631
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001632 break;
1633
1634 case 25:
1635
1636 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001637 (yyval) = ! (yyvsp[0]);
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001638 }
1639
1640 break;
1641
Jamie Madill9a1b49f2015-09-08 14:32:26 +00001642 case 26:
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001643
1644 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001645 (yyval) = ~ (yyvsp[0]);
1646 }
1647
1648 break;
1649
1650 case 27:
1651
1652 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001653 // Check for negation of minimum representable integer to prevent undefined signed int
1654 // overflow.
1655 if ((yyvsp[0]) == std::numeric_limits<YYSTYPE>::min())
1656 {
1657 (yyval) = std::numeric_limits<YYSTYPE>::min();
1658 }
1659 else
1660 {
1661 (yyval) = -(yyvsp[0]);
1662 }
Olli Etuaho809ec542015-08-26 14:30:57 +03001663 }
1664
1665 break;
1666
1667 case 28:
1668
1669 {
1670 (yyval) = + (yyvsp[0]);
1671 }
1672
1673 break;
1674
1675 case 29:
1676
1677 {
Jamie Madill185de882014-12-22 15:17:52 -05001678 (yyval) = (yyvsp[-1]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001679 }
Jamie Madill185de882014-12-22 15:17:52 -05001680
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001681 break;
1682
1683
1684
1685 default: break;
1686 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001687 /* User semantic actions sometimes alter yychar, and that requires
1688 that yytoken be updated with the new translation. We take the
1689 approach of translating immediately before every use of yytoken.
1690 One alternative is translating here after every semantic action,
1691 but that translation would be missed if the semantic action invokes
1692 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1693 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1694 incorrect destructor might then be invoked immediately. In the
1695 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1696 to an incorrect destructor call or verbose syntax error message
1697 before the lookahead is translated. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001698 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1699
1700 YYPOPSTACK (yylen);
1701 yylen = 0;
1702 YY_STACK_PRINT (yyss, yyssp);
1703
1704 *++yyvsp = yyval;
1705
Jamie Madill185de882014-12-22 15:17:52 -05001706 /* Now 'shift' the result of the reduction. Determine what state
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001707 that goes to, based on the state we popped back to and the rule
1708 number reduced by. */
1709
1710 yyn = yyr1[yyn];
1711
1712 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1713 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1714 yystate = yytable[yystate];
1715 else
1716 yystate = yydefgoto[yyn - YYNTOKENS];
1717
1718 goto yynewstate;
1719
1720
Jamie Madill185de882014-12-22 15:17:52 -05001721/*--------------------------------------.
1722| yyerrlab -- here on detecting error. |
1723`--------------------------------------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001724yyerrlab:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001725 /* Make sure we have latest lookahead translation. See comments at
1726 user semantic actions for why this is necessary. */
1727 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1728
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001729 /* If not already recovering from an error, report this error. */
1730 if (!yyerrstatus)
1731 {
1732 ++yynerrs;
1733#if ! YYERROR_VERBOSE
1734 yyerror (context, YY_("syntax error"));
1735#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001736# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1737 yyssp, yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001738 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001739 char const *yymsgp = YY_("syntax error");
1740 int yysyntax_error_status;
1741 yysyntax_error_status = YYSYNTAX_ERROR;
1742 if (yysyntax_error_status == 0)
1743 yymsgp = yymsg;
1744 else if (yysyntax_error_status == 1)
1745 {
1746 if (yymsg != yymsgbuf)
1747 YYSTACK_FREE (yymsg);
1748 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1749 if (!yymsg)
1750 {
1751 yymsg = yymsgbuf;
1752 yymsg_alloc = sizeof yymsgbuf;
1753 yysyntax_error_status = 2;
1754 }
1755 else
1756 {
1757 yysyntax_error_status = YYSYNTAX_ERROR;
1758 yymsgp = yymsg;
1759 }
1760 }
1761 yyerror (context, yymsgp);
1762 if (yysyntax_error_status == 2)
1763 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001764 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001765# undef YYSYNTAX_ERROR
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001766#endif
1767 }
1768
1769
1770
1771 if (yyerrstatus == 3)
1772 {
1773 /* If just tried and failed to reuse lookahead token after an
Jamie Madill185de882014-12-22 15:17:52 -05001774 error, discard it. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001775
1776 if (yychar <= YYEOF)
Jamie Madill185de882014-12-22 15:17:52 -05001777 {
1778 /* Return failure if at end of input. */
1779 if (yychar == YYEOF)
1780 YYABORT;
1781 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001782 else
Jamie Madill185de882014-12-22 15:17:52 -05001783 {
1784 yydestruct ("Error: discarding",
1785 yytoken, &yylval, context);
1786 yychar = YYEMPTY;
1787 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001788 }
1789
1790 /* Else will try to reuse lookahead token after shifting the error
1791 token. */
1792 goto yyerrlab1;
1793
1794
1795/*---------------------------------------------------.
1796| yyerrorlab -- error raised explicitly by YYERROR. |
1797`---------------------------------------------------*/
1798yyerrorlab:
1799
1800 /* Pacify compilers like GCC when the user code never invokes
1801 YYERROR and the label yyerrorlab therefore never appears in user
1802 code. */
1803 if (/*CONSTCOND*/ 0)
1804 goto yyerrorlab;
1805
Jamie Madill185de882014-12-22 15:17:52 -05001806 /* Do not reclaim the symbols of the rule whose action triggered
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001807 this YYERROR. */
1808 YYPOPSTACK (yylen);
1809 yylen = 0;
1810 YY_STACK_PRINT (yyss, yyssp);
1811 yystate = *yyssp;
1812 goto yyerrlab1;
1813
1814
1815/*-------------------------------------------------------------.
1816| yyerrlab1 -- common code for both syntax error and YYERROR. |
1817`-------------------------------------------------------------*/
1818yyerrlab1:
Jamie Madill185de882014-12-22 15:17:52 -05001819 yyerrstatus = 3; /* Each real token shifted decrements this. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001820
1821 for (;;)
1822 {
1823 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001824 if (!yypact_value_is_default (yyn))
Jamie Madill185de882014-12-22 15:17:52 -05001825 {
1826 yyn += YYTERROR;
1827 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1828 {
1829 yyn = yytable[yyn];
1830 if (0 < yyn)
1831 break;
1832 }
1833 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001834
1835 /* Pop the current state because it cannot handle the error token. */
1836 if (yyssp == yyss)
Jamie Madill185de882014-12-22 15:17:52 -05001837 YYABORT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001838
1839
1840 yydestruct ("Error: popping",
Jamie Madill185de882014-12-22 15:17:52 -05001841 yystos[yystate], yyvsp, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001842 YYPOPSTACK (1);
1843 yystate = *yyssp;
1844 YY_STACK_PRINT (yyss, yyssp);
1845 }
1846
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001847 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001848 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001849 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001850
1851
1852 /* Shift the error token. */
1853 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1854
1855 yystate = yyn;
1856 goto yynewstate;
1857
1858
1859/*-------------------------------------.
1860| yyacceptlab -- YYACCEPT comes here. |
1861`-------------------------------------*/
1862yyacceptlab:
1863 yyresult = 0;
1864 goto yyreturn;
1865
1866/*-----------------------------------.
1867| yyabortlab -- YYABORT comes here. |
1868`-----------------------------------*/
1869yyabortlab:
1870 yyresult = 1;
1871 goto yyreturn;
1872
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001873#if !defined yyoverflow || YYERROR_VERBOSE
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001874/*-------------------------------------------------.
1875| yyexhaustedlab -- memory exhaustion comes here. |
1876`-------------------------------------------------*/
1877yyexhaustedlab:
1878 yyerror (context, YY_("memory exhausted"));
1879 yyresult = 2;
1880 /* Fall through. */
1881#endif
1882
1883yyreturn:
1884 if (yychar != YYEMPTY)
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001885 {
1886 /* Make sure we have latest lookahead translation. See comments at
1887 user semantic actions for why this is necessary. */
1888 yytoken = YYTRANSLATE (yychar);
1889 yydestruct ("Cleanup: discarding lookahead",
1890 yytoken, &yylval, context);
1891 }
Jamie Madill185de882014-12-22 15:17:52 -05001892 /* Do not reclaim the symbols of the rule whose action triggered
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001893 this YYABORT or YYACCEPT. */
1894 YYPOPSTACK (yylen);
1895 YY_STACK_PRINT (yyss, yyssp);
1896 while (yyssp != yyss)
1897 {
1898 yydestruct ("Cleanup: popping",
Jamie Madill185de882014-12-22 15:17:52 -05001899 yystos[*yyssp], yyvsp, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001900 YYPOPSTACK (1);
1901 }
1902#ifndef yyoverflow
1903 if (yyss != yyssa)
1904 YYSTACK_FREE (yyss);
1905#endif
1906#if YYERROR_VERBOSE
1907 if (yymsg != yymsgbuf)
1908 YYSTACK_FREE (yymsg);
1909#endif
Jamie Madill185de882014-12-22 15:17:52 -05001910 return yyresult;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001911}
1912
1913
1914
Zhenyao Mod526f982014-05-13 14:51:19 -07001915int yylex(YYSTYPE *lvalp, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001916{
Olli Etuaho3187a382015-09-09 12:00:12 +03001917 pp::Token *token = context->token;
Olli Etuaho247374c2015-09-09 15:07:24 +03001918 if (!context->parsePresetToken)
1919 {
1920 context->lexer->lex(token);
1921 }
1922 context->parsePresetToken = false;
Olli Etuaho3187a382015-09-09 12:00:12 +03001923
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001924 int type = 0;
1925
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001926 switch (token->type)
1927 {
Zhenyao Mod526f982014-05-13 14:51:19 -07001928 case pp::Token::CONST_INT: {
alokp@chromium.org2e818912012-06-29 21:26:03 +00001929 unsigned int val = 0;
Olli Etuaho247374c2015-09-09 15:07:24 +03001930 int testVal = 0;
1931 if (!token->uValue(&val) || (!token->iValue(&testVal) &&
1932 context->errorSettings.integerLiteralsMustFit32BitSignedRange))
alokp@chromium.org2e818912012-06-29 21:26:03 +00001933 {
Shannon Woods7f2d7942013-11-19 15:07:58 -05001934 context->diagnostics->report(pp::Diagnostics::PP_INTEGER_OVERFLOW,
alokp@chromium.org2e818912012-06-29 21:26:03 +00001935 token->location, token->text);
Olli Etuaho247374c2015-09-09 15:07:24 +03001936 *(context->valid) = false;
alokp@chromium.org2e818912012-06-29 21:26:03 +00001937 }
1938 *lvalp = static_cast<YYSTYPE>(val);
maxvujovic@gmail.come640ef82012-07-13 18:42:40 +00001939 type = TOK_CONST_INT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001940 break;
alokp@chromium.org2e818912012-06-29 21:26:03 +00001941 }
Olli Etuaho809ec542015-08-26 14:30:57 +03001942 case pp::Token::IDENTIFIER:
Olli Etuaho809ec542015-08-26 14:30:57 +03001943 *lvalp = static_cast<YYSTYPE>(-1);
1944 type = TOK_IDENTIFIER;
1945 break;
Zhenyao Mod526f982014-05-13 14:51:19 -07001946 case pp::Token::OP_OR:
1947 type = TOK_OP_OR;
1948 break;
1949 case pp::Token::OP_AND:
1950 type = TOK_OP_AND;
1951 break;
1952 case pp::Token::OP_NE:
1953 type = TOK_OP_NE;
1954 break;
1955 case pp::Token::OP_EQ:
1956 type = TOK_OP_EQ;
1957 break;
1958 case pp::Token::OP_GE:
1959 type = TOK_OP_GE;
1960 break;
1961 case pp::Token::OP_LE:
1962 type = TOK_OP_LE;
1963 break;
1964 case pp::Token::OP_RIGHT:
1965 type = TOK_OP_RIGHT;
1966 break;
1967 case pp::Token::OP_LEFT:
1968 type = TOK_OP_LEFT;
1969 break;
1970 case '|':
1971 case '^':
1972 case '&':
1973 case '>':
1974 case '<':
1975 case '-':
1976 case '+':
1977 case '%':
1978 case '/':
1979 case '*':
1980 case '!':
1981 case '~':
1982 case '(':
1983 case ')':
1984 type = token->type;
1985 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001986
Zhenyao Mod526f982014-05-13 14:51:19 -07001987 default:
1988 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001989 }
1990
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001991 return type;
1992}
1993
Zhenyao Mod526f982014-05-13 14:51:19 -07001994void yyerror(Context *context, const char *reason)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001995{
Shannon Woods7f2d7942013-11-19 15:07:58 -05001996 context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION,
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001997 context->token->location,
1998 reason);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001999}
2000
2001namespace pp {
2002
Zhenyao Mod526f982014-05-13 14:51:19 -07002003ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
2004 : mLexer(lexer),
2005 mDiagnostics(diagnostics)
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00002006{
2007}
2008
Olli Etuaho247374c2015-09-09 15:07:24 +03002009bool ExpressionParser::parse(Token *token,
2010 int *result,
2011 bool parsePresetToken,
2012 const ErrorSettings &errorSettings,
2013 bool *valid)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002014{
2015 Context context;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00002016 context.diagnostics = mDiagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002017 context.lexer = mLexer;
2018 context.token = token;
2019 context.result = result;
Olli Etuaho809ec542015-08-26 14:30:57 +03002020 context.ignoreErrors = 0;
Olli Etuaho247374c2015-09-09 15:07:24 +03002021 context.parsePresetToken = parsePresetToken;
2022 context.errorSettings = errorSettings;
2023 context.valid = valid;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002024 int ret = yyparse(&context);
2025 switch (ret)
2026 {
2027 case 0:
2028 case 1:
2029 break;
2030
2031 case 2:
Shannon Woods7f2d7942013-11-19 15:07:58 -05002032 mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002033 break;
2034
2035 default:
2036 assert(false);
Shannon Woods7f2d7942013-11-19 15:07:58 -05002037 mDiagnostics->report(Diagnostics::PP_INTERNAL_ERROR, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002038 break;
2039 }
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00002040
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002041 return ret == 0;
2042}
2043
2044} // namespace pp