blob: f737a2e7a0d5a4a6a94a4e43b8332f667679e711 [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. */
Geoff Lang93561c32016-09-20 10:22:55 -0400499static const yytype_uint16 yyrline[] =
500{
Olli Etuaho7f9a55f2016-10-03 14:32:08 +0100501 0, 108, 108, 115, 116, 127, 127, 148, 148, 169,
502 172, 175, 178, 181, 184, 187, 190, 193, 196, 221,
503 246, 249, 252, 272, 299, 302, 305, 308, 320, 323
Geoff Lang93561c32016-09-20 10:22:55 -0400504};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000505#endif
506
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000507#if YYDEBUG || YYERROR_VERBOSE || 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000508/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
509 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
510static const char *const yytname[] =
511{
Olli Etuaho809ec542015-08-26 14:30:57 +0300512 "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_IDENTIFIER",
513 "TOK_OP_OR", "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_EQ", "TOK_OP_NE",
514 "'<'", "'>'", "TOK_OP_LE", "TOK_OP_GE", "TOK_OP_LEFT", "TOK_OP_RIGHT",
515 "'+'", "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('",
516 "')'", "$accept", "input", "expression", "$@1", "$@2", YY_NULLPTR
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000517};
518#endif
519
520# ifdef YYPRINT
Jamie Madill185de882014-12-22 15:17:52 -0500521/* YYTOKNUM[NUM] -- (External) token number corresponding to the
522 (internal) symbol number NUM (which must be that of a token). */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000523static const yytype_uint16 yytoknum[] =
524{
Olli Etuaho809ec542015-08-26 14:30:57 +0300525 0, 256, 257, 258, 259, 260, 261, 124, 94, 38,
526 262, 263, 60, 62, 264, 265, 266, 267, 43, 45,
527 42, 47, 37, 268, 33, 126, 40, 41
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000528};
529# endif
530
Olli Etuaho809ec542015-08-26 14:30:57 +0300531#define YYPACT_NINF -12
Jamie Madill185de882014-12-22 15:17:52 -0500532
533#define yypact_value_is_default(Yystate) \
Olli Etuaho809ec542015-08-26 14:30:57 +0300534 (!!((Yystate) == (-12)))
Jamie Madill185de882014-12-22 15:17:52 -0500535
536#define YYTABLE_NINF -1
537
538#define yytable_value_is_error(Yytable_value) \
539 0
540
541 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
542 STATE-NUM. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000543static const yytype_int16 yypact[] =
544{
Olli Etuaho809ec542015-08-26 14:30:57 +0300545 31, -12, -12, 31, 31, 31, 31, 31, 51, 76,
546 -12, -12, -12, -12, 53, -12, -12, -12, 31, 31,
547 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
548 31, 31, 31, 31, -12, 31, 31, 124, 138, 26,
549 149, 149, -11, -11, -11, -11, 154, 154, -8, -8,
550 -12, -12, -12, 93, 109
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000551};
552
Jamie Madill185de882014-12-22 15:17:52 -0500553 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
554 Performed when YYTABLE does not specify something else to do. Zero
555 means the default is an error. */
556static const yytype_uint8 yydefact[] =
557{
Olli Etuaho809ec542015-08-26 14:30:57 +0300558 0, 3, 4, 0, 0, 0, 0, 0, 0, 2,
559 28, 27, 25, 26, 0, 1, 5, 7, 0, 0,
Jamie Madill185de882014-12-22 15:17:52 -0500560 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Olli Etuaho809ec542015-08-26 14:30:57 +0300561 0, 0, 0, 0, 29, 0, 0, 9, 10, 11,
562 13, 12, 17, 16, 15, 14, 19, 18, 21, 20,
563 24, 23, 22, 6, 8
Jamie Madill185de882014-12-22 15:17:52 -0500564};
565
566 /* YYPGOTO[NTERM-NUM]. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000567static const yytype_int8 yypgoto[] =
568{
Olli Etuaho809ec542015-08-26 14:30:57 +0300569 -12, -12, -3, -12, -12
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000570};
571
Jamie Madill185de882014-12-22 15:17:52 -0500572 /* YYDEFGOTO[NTERM-NUM]. */
573static const yytype_int8 yydefgoto[] =
574{
Olli Etuaho809ec542015-08-26 14:30:57 +0300575 -1, 8, 9, 35, 36
Jamie Madill185de882014-12-22 15:17:52 -0500576};
577
578 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
579 positive, shift that token. If negative, reduce the rule whose
580 number is the opposite. If YYTABLE_NINF, syntax error. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000581static const yytype_uint8 yytable[] =
582{
Olli Etuaho809ec542015-08-26 14:30:57 +0300583 10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
584 32, 33, 31, 32, 33, 37, 38, 39, 40, 41,
585 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
586 52, 0, 53, 54, 1, 2, 21, 22, 23, 24,
587 25, 26, 27, 28, 29, 30, 31, 32, 33, 3,
588 4, 15, 0, 0, 0, 5, 6, 7, 16, 17,
589 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
590 28, 29, 30, 31, 32, 33, 0, 0, 0, 0,
591 34, 16, 17, 18, 19, 20, 21, 22, 23, 24,
592 25, 26, 27, 28, 29, 30, 31, 32, 33, 17,
593 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
594 28, 29, 30, 31, 32, 33, 18, 19, 20, 21,
595 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
596 32, 33, 19, 20, 21, 22, 23, 24, 25, 26,
597 27, 28, 29, 30, 31, 32, 33, 20, 21, 22,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000598 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
Olli Etuaho809ec542015-08-26 14:30:57 +0300599 33, 23, 24, 25, 26, 27, 28, 29, 30, 31,
600 32, 33, 29, 30, 31, 32, 33
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000601};
602
603static const yytype_int8 yycheck[] =
604{
Olli Etuaho809ec542015-08-26 14:30:57 +0300605 3, 4, 5, 6, 7, 16, 17, 18, 19, 20,
606 21, 22, 20, 21, 22, 18, 19, 20, 21, 22,
607 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
608 33, -1, 35, 36, 3, 4, 10, 11, 12, 13,
609 14, 15, 16, 17, 18, 19, 20, 21, 22, 18,
610 19, 0, -1, -1, -1, 24, 25, 26, 5, 6,
611 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
612 17, 18, 19, 20, 21, 22, -1, -1, -1, -1,
613 27, 5, 6, 7, 8, 9, 10, 11, 12, 13,
614 14, 15, 16, 17, 18, 19, 20, 21, 22, 6,
615 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
616 17, 18, 19, 20, 21, 22, 7, 8, 9, 10,
617 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
618 21, 22, 8, 9, 10, 11, 12, 13, 14, 15,
619 16, 17, 18, 19, 20, 21, 22, 9, 10, 11,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000620 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
Olli Etuaho809ec542015-08-26 14:30:57 +0300621 22, 12, 13, 14, 15, 16, 17, 18, 19, 20,
622 21, 22, 18, 19, 20, 21, 22
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000623};
624
Jamie Madill185de882014-12-22 15:17:52 -0500625 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
626 symbol of state STATE-NUM. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000627static const yytype_uint8 yystos[] =
628{
Olli Etuaho809ec542015-08-26 14:30:57 +0300629 0, 3, 4, 18, 19, 24, 25, 26, 29, 30,
630 30, 30, 30, 30, 30, 0, 5, 6, 7, 8,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000631 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
Olli Etuaho809ec542015-08-26 14:30:57 +0300632 19, 20, 21, 22, 27, 31, 32, 30, 30, 30,
633 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
634 30, 30, 30, 30, 30
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000635};
636
Jamie Madill185de882014-12-22 15:17:52 -0500637 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
638static const yytype_uint8 yyr1[] =
639{
Olli Etuaho809ec542015-08-26 14:30:57 +0300640 0, 28, 29, 30, 30, 31, 30, 32, 30, 30,
641 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
642 30, 30, 30, 30, 30, 30, 30, 30, 30, 30
Jamie Madill185de882014-12-22 15:17:52 -0500643};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000644
Jamie Madill185de882014-12-22 15:17:52 -0500645 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
646static const yytype_uint8 yyr2[] =
647{
Olli Etuaho809ec542015-08-26 14:30:57 +0300648 0, 2, 1, 1, 1, 0, 4, 0, 4, 3,
Jamie Madill185de882014-12-22 15:17:52 -0500649 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
Olli Etuaho809ec542015-08-26 14:30:57 +0300650 3, 3, 3, 3, 3, 2, 2, 2, 2, 3
Jamie Madill185de882014-12-22 15:17:52 -0500651};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000652
653
Jamie Madill185de882014-12-22 15:17:52 -0500654#define yyerrok (yyerrstatus = 0)
655#define yyclearin (yychar = YYEMPTY)
656#define YYEMPTY (-2)
657#define YYEOF 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000658
Jamie Madill185de882014-12-22 15:17:52 -0500659#define YYACCEPT goto yyacceptlab
660#define YYABORT goto yyabortlab
661#define YYERROR goto yyerrorlab
662
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000663
664#define YYRECOVERING() (!!yyerrstatus)
665
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000666#define YYBACKUP(Token, Value) \
667do \
668 if (yychar == YYEMPTY) \
669 { \
670 yychar = (Token); \
671 yylval = (Value); \
672 YYPOPSTACK (yylen); \
673 yystate = *yyssp; \
674 goto yybackup; \
675 } \
676 else \
677 { \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000678 yyerror (context, YY_("syntax error: cannot back up")); \
Jamie Madill185de882014-12-22 15:17:52 -0500679 YYERROR; \
680 } \
681while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000682
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000683/* Error token number */
Jamie Madill185de882014-12-22 15:17:52 -0500684#define YYTERROR 1
685#define YYERRCODE 256
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000686
687
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000688
689/* Enable debugging if requested. */
690#if YYDEBUG
691
692# ifndef YYFPRINTF
693# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
694# define YYFPRINTF fprintf
695# endif
696
Jamie Madill185de882014-12-22 15:17:52 -0500697# define YYDPRINTF(Args) \
698do { \
699 if (yydebug) \
700 YYFPRINTF Args; \
701} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000702
Jamie Madill185de882014-12-22 15:17:52 -0500703/* This macro is provided for backward compatibility. */
704#ifndef YY_LOCATION_PRINT
705# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
706#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000707
708
Jamie Madill185de882014-12-22 15:17:52 -0500709# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
710do { \
711 if (yydebug) \
712 { \
713 YYFPRINTF (stderr, "%s ", Title); \
714 yy_symbol_print (stderr, \
715 Type, Value, context); \
716 YYFPRINTF (stderr, "\n"); \
717 } \
718} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000719
Jamie Madill185de882014-12-22 15:17:52 -0500720
721/*----------------------------------------.
722| Print this symbol's value on YYOUTPUT. |
723`----------------------------------------*/
724
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000725static void
726yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000727{
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000728 FILE *yyo = yyoutput;
729 YYUSE (yyo);
Jamie Madill185de882014-12-22 15:17:52 -0500730 YYUSE (context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000731 if (!yyvaluep)
732 return;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000733# ifdef YYPRINT
734 if (yytype < YYNTOKENS)
735 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000736# endif
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400737 YYUSE (yytype);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000738}
739
740
741/*--------------------------------.
742| Print this symbol on YYOUTPUT. |
743`--------------------------------*/
744
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000745static void
746yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000747{
Jamie Madill185de882014-12-22 15:17:52 -0500748 YYFPRINTF (yyoutput, "%s %s (",
749 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000750
751 yy_symbol_value_print (yyoutput, yytype, yyvaluep, context);
752 YYFPRINTF (yyoutput, ")");
753}
754
755/*------------------------------------------------------------------.
756| yy_stack_print -- Print the state stack from its BOTTOM up to its |
757| TOP (included). |
758`------------------------------------------------------------------*/
759
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000760static void
761yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000762{
763 YYFPRINTF (stderr, "Stack now");
764 for (; yybottom <= yytop; yybottom++)
765 {
766 int yybot = *yybottom;
767 YYFPRINTF (stderr, " %d", yybot);
768 }
769 YYFPRINTF (stderr, "\n");
770}
771
Jamie Madill185de882014-12-22 15:17:52 -0500772# define YY_STACK_PRINT(Bottom, Top) \
773do { \
774 if (yydebug) \
775 yy_stack_print ((Bottom), (Top)); \
776} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000777
778
779/*------------------------------------------------.
780| Report that the YYRULE is going to be reduced. |
781`------------------------------------------------*/
782
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000783static void
Jamie Madill185de882014-12-22 15:17:52 -0500784yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000785{
Jamie Madill185de882014-12-22 15:17:52 -0500786 unsigned long int yylno = yyrline[yyrule];
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000787 int yynrhs = yyr2[yyrule];
788 int yyi;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000789 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
Jamie Madill185de882014-12-22 15:17:52 -0500790 yyrule - 1, yylno);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000791 /* The symbols being reduced. */
792 for (yyi = 0; yyi < yynrhs; yyi++)
793 {
794 YYFPRINTF (stderr, " $%d = ", yyi + 1);
Jamie Madill185de882014-12-22 15:17:52 -0500795 yy_symbol_print (stderr,
796 yystos[yyssp[yyi + 1 - yynrhs]],
797 &(yyvsp[(yyi + 1) - (yynrhs)])
798 , context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000799 YYFPRINTF (stderr, "\n");
800 }
801}
802
Jamie Madill185de882014-12-22 15:17:52 -0500803# define YY_REDUCE_PRINT(Rule) \
804do { \
805 if (yydebug) \
806 yy_reduce_print (yyssp, yyvsp, Rule, context); \
807} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000808
809/* Nonzero means print parse trace. It is left uninitialized so that
810 multiple parsers can coexist. */
811int yydebug;
812#else /* !YYDEBUG */
813# define YYDPRINTF(Args)
814# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
815# define YY_STACK_PRINT(Bottom, Top)
816# define YY_REDUCE_PRINT(Rule)
817#endif /* !YYDEBUG */
818
819
820/* YYINITDEPTH -- initial size of the parser's stacks. */
Jamie Madill185de882014-12-22 15:17:52 -0500821#ifndef YYINITDEPTH
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000822# define YYINITDEPTH 200
823#endif
824
825/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
826 if the built-in stack extension method is used).
827
828 Do not make this value too large; the results are undefined if
829 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
830 evaluated with infinite-precision integer arithmetic. */
831
832#ifndef YYMAXDEPTH
833# define YYMAXDEPTH 10000
834#endif
835
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000836
837#if YYERROR_VERBOSE
838
839# ifndef yystrlen
840# if defined __GLIBC__ && defined _STRING_H
841# define yystrlen strlen
842# else
843/* Return the length of YYSTR. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000844static YYSIZE_T
845yystrlen (const char *yystr)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000846{
847 YYSIZE_T yylen;
848 for (yylen = 0; yystr[yylen]; yylen++)
849 continue;
850 return yylen;
851}
852# endif
853# endif
854
855# ifndef yystpcpy
856# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
857# define yystpcpy stpcpy
858# else
859/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
860 YYDEST. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000861static char *
862yystpcpy (char *yydest, const char *yysrc)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000863{
864 char *yyd = yydest;
865 const char *yys = yysrc;
866
867 while ((*yyd++ = *yys++) != '\0')
868 continue;
869
870 return yyd - 1;
871}
872# endif
873# endif
874
875# ifndef yytnamerr
876/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
877 quotes and backslashes, so that it's suitable for yyerror. The
878 heuristic is that double-quoting is unnecessary unless the string
879 contains an apostrophe, a comma, or backslash (other than
880 backslash-backslash). YYSTR is taken from yytname. If YYRES is
881 null, do not copy; instead, return the length of what the result
882 would have been. */
883static YYSIZE_T
884yytnamerr (char *yyres, const char *yystr)
885{
886 if (*yystr == '"')
887 {
888 YYSIZE_T yyn = 0;
889 char const *yyp = yystr;
890
891 for (;;)
Jamie Madill185de882014-12-22 15:17:52 -0500892 switch (*++yyp)
893 {
894 case '\'':
895 case ',':
896 goto do_not_strip_quotes;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000897
Jamie Madill185de882014-12-22 15:17:52 -0500898 case '\\':
899 if (*++yyp != '\\')
900 goto do_not_strip_quotes;
901 /* Fall through. */
902 default:
903 if (yyres)
904 yyres[yyn] = *yyp;
905 yyn++;
906 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000907
Jamie Madill185de882014-12-22 15:17:52 -0500908 case '"':
909 if (yyres)
910 yyres[yyn] = '\0';
911 return yyn;
912 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000913 do_not_strip_quotes: ;
914 }
915
916 if (! yyres)
917 return yystrlen (yystr);
918
919 return yystpcpy (yyres, yystr) - yyres;
920}
921# endif
922
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000923/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
924 about the unexpected token YYTOKEN for the state stack whose top is
925 YYSSP.
926
927 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
928 not large enough to hold the message. In that case, also set
929 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
930 required number of bytes is too large to store. */
931static int
932yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
933 yytype_int16 *yyssp, int yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000934{
Jamie Madill185de882014-12-22 15:17:52 -0500935 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000936 YYSIZE_T yysize = yysize0;
937 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
938 /* Internationalized format string. */
Jamie Madill185de882014-12-22 15:17:52 -0500939 const char *yyformat = YY_NULLPTR;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000940 /* Arguments of yyformat. */
941 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
942 /* Number of reported tokens (one for the "unexpected", one per
943 "expected"). */
944 int yycount = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000945
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000946 /* There are many possibilities here to consider:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000947 - If this state is a consistent state with a default action, then
948 the only way this function was invoked is if the default action
949 is an error action. In that case, don't check for expected
950 tokens because there are none.
951 - The only way there can be no lookahead present (in yychar) is if
952 this state is a consistent state with a default action. Thus,
953 detecting the absence of a lookahead is sufficient to determine
954 that there is no unexpected or expected token to report. In that
955 case, just report a simple "syntax error".
956 - Don't assume there isn't a lookahead just because this state is a
957 consistent state with a default action. There might have been a
958 previous inconsistent state, consistent state with a non-default
959 action, or user semantic action that manipulated yychar.
960 - Of course, the expected token list depends on states to have
961 correct lookahead information, and it depends on the parser not
962 to perform extra reductions after fetching a lookahead from the
963 scanner and before detecting a syntax error. Thus, state merging
964 (from LALR or IELR) and default reductions corrupt the expected
965 token list. However, the list is correct for canonical LR with
966 one exception: it will still contain any token that will not be
967 accepted due to an error action in a later state.
968 */
969 if (yytoken != YYEMPTY)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000970 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000971 int yyn = yypact[*yyssp];
972 yyarg[yycount++] = yytname[yytoken];
973 if (!yypact_value_is_default (yyn))
974 {
975 /* Start YYX at -YYN if negative to avoid negative indexes in
976 YYCHECK. In other words, skip the first -YYN actions for
977 this state because they are default actions. */
978 int yyxbegin = yyn < 0 ? -yyn : 0;
979 /* Stay within bounds of both yycheck and yytname. */
980 int yychecklim = YYLAST - yyn + 1;
981 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
982 int yyx;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000983
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000984 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
985 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
986 && !yytable_value_is_error (yytable[yyx + yyn]))
987 {
988 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
989 {
990 yycount = 1;
991 yysize = yysize0;
992 break;
993 }
994 yyarg[yycount++] = yytname[yyx];
995 {
Jamie Madill185de882014-12-22 15:17:52 -0500996 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000997 if (! (yysize <= yysize1
998 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
999 return 2;
1000 yysize = yysize1;
1001 }
1002 }
1003 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001004 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001005
1006 switch (yycount)
1007 {
1008# define YYCASE_(N, S) \
1009 case N: \
1010 yyformat = S; \
1011 break
1012 YYCASE_(0, YY_("syntax error"));
1013 YYCASE_(1, YY_("syntax error, unexpected %s"));
1014 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1015 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1016 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1017 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1018# undef YYCASE_
1019 }
1020
1021 {
1022 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1023 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1024 return 2;
1025 yysize = yysize1;
1026 }
1027
1028 if (*yymsg_alloc < yysize)
1029 {
1030 *yymsg_alloc = 2 * yysize;
1031 if (! (yysize <= *yymsg_alloc
1032 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1033 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1034 return 1;
1035 }
1036
1037 /* Avoid sprintf, as that infringes on the user's name space.
1038 Don't have undefined behavior even if the translation
1039 produced a string with the wrong number of "%s"s. */
1040 {
1041 char *yyp = *yymsg;
1042 int yyi = 0;
1043 while ((*yyp = *yyformat) != '\0')
1044 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1045 {
1046 yyp += yytnamerr (yyp, yyarg[yyi++]);
1047 yyformat += 2;
1048 }
1049 else
1050 {
1051 yyp++;
1052 yyformat++;
1053 }
1054 }
1055 return 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001056}
1057#endif /* YYERROR_VERBOSE */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001058
1059/*-----------------------------------------------.
1060| Release the memory associated to this symbol. |
1061`-----------------------------------------------*/
1062
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001063static void
1064yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001065{
1066 YYUSE (yyvaluep);
1067 YYUSE (context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001068 if (!yymsg)
1069 yymsg = "Deleting";
1070 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1071
Jamie Madill185de882014-12-22 15:17:52 -05001072 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Zhenyao Mof1d723c2013-09-23 14:57:07 -04001073 YYUSE (yytype);
Jamie Madill185de882014-12-22 15:17:52 -05001074 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001075}
1076
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001077
1078
1079
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001080/*----------.
1081| yyparse. |
1082`----------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001083
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001084int
1085yyparse (Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001086{
1087/* The lookahead symbol. */
1088int yychar;
1089
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001090
Jamie Madill185de882014-12-22 15:17:52 -05001091/* The semantic value of the lookahead symbol. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001092/* Default value used for initialization, for pacifying older GCCs
1093 or non-GCC compilers. */
Jamie Madill185de882014-12-22 15:17:52 -05001094YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1095YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001096
1097 /* Number of syntax errors so far. */
1098 int yynerrs;
1099
1100 int yystate;
1101 /* Number of tokens to shift before error messages enabled. */
1102 int yyerrstatus;
1103
1104 /* The stacks and their tools:
Jamie Madill185de882014-12-22 15:17:52 -05001105 'yyss': related to states.
1106 'yyvs': related to semantic values.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001107
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001108 Refer to the stacks through separate pointers, to allow yyoverflow
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001109 to reallocate them elsewhere. */
1110
1111 /* The state stack. */
1112 yytype_int16 yyssa[YYINITDEPTH];
1113 yytype_int16 *yyss;
1114 yytype_int16 *yyssp;
1115
1116 /* The semantic value stack. */
1117 YYSTYPE yyvsa[YYINITDEPTH];
1118 YYSTYPE *yyvs;
1119 YYSTYPE *yyvsp;
1120
1121 YYSIZE_T yystacksize;
1122
1123 int yyn;
1124 int yyresult;
1125 /* Lookahead token as an internal (translated) token number. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001126 int yytoken = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001127 /* The variables used to return semantic value and location from the
1128 action routines. */
1129 YYSTYPE yyval;
1130
1131#if YYERROR_VERBOSE
1132 /* Buffer for error messages, and its allocated size. */
1133 char yymsgbuf[128];
1134 char *yymsg = yymsgbuf;
1135 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1136#endif
1137
1138#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1139
1140 /* The number of symbols on the RHS of the reduced rule.
1141 Keep to zero when no symbol should be popped. */
1142 int yylen = 0;
1143
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001144 yyssp = yyss = yyssa;
1145 yyvsp = yyvs = yyvsa;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001146 yystacksize = YYINITDEPTH;
1147
1148 YYDPRINTF ((stderr, "Starting parse\n"));
1149
1150 yystate = 0;
1151 yyerrstatus = 0;
1152 yynerrs = 0;
1153 yychar = YYEMPTY; /* Cause a token to be read. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001154 goto yysetstate;
1155
1156/*------------------------------------------------------------.
1157| yynewstate -- Push a new state, which is found in yystate. |
1158`------------------------------------------------------------*/
1159 yynewstate:
1160 /* In all cases, when you get here, the value and location stacks
1161 have just been pushed. So pushing a state here evens the stacks. */
1162 yyssp++;
1163
1164 yysetstate:
1165 *yyssp = yystate;
1166
1167 if (yyss + yystacksize - 1 <= yyssp)
1168 {
1169 /* Get the current used size of the three stacks, in elements. */
1170 YYSIZE_T yysize = yyssp - yyss + 1;
1171
1172#ifdef yyoverflow
1173 {
Jamie Madill185de882014-12-22 15:17:52 -05001174 /* Give user a chance to reallocate the stack. Use copies of
1175 these so that the &'s don't force the real ones into
1176 memory. */
1177 YYSTYPE *yyvs1 = yyvs;
1178 yytype_int16 *yyss1 = yyss;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001179
Jamie Madill185de882014-12-22 15:17:52 -05001180 /* Each stack pointer address is followed by the size of the
1181 data in use in that stack, in bytes. This used to be a
1182 conditional around just the two extra args, but that might
1183 be undefined if yyoverflow is a macro. */
1184 yyoverflow (YY_("memory exhausted"),
1185 &yyss1, yysize * sizeof (*yyssp),
1186 &yyvs1, yysize * sizeof (*yyvsp),
1187 &yystacksize);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001188
Jamie Madill185de882014-12-22 15:17:52 -05001189 yyss = yyss1;
1190 yyvs = yyvs1;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001191 }
1192#else /* no yyoverflow */
1193# ifndef YYSTACK_RELOCATE
1194 goto yyexhaustedlab;
1195# else
1196 /* Extend the stack our own way. */
1197 if (YYMAXDEPTH <= yystacksize)
Jamie Madill185de882014-12-22 15:17:52 -05001198 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001199 yystacksize *= 2;
1200 if (YYMAXDEPTH < yystacksize)
Jamie Madill185de882014-12-22 15:17:52 -05001201 yystacksize = YYMAXDEPTH;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001202
1203 {
Jamie Madill185de882014-12-22 15:17:52 -05001204 yytype_int16 *yyss1 = yyss;
1205 union yyalloc *yyptr =
1206 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1207 if (! yyptr)
1208 goto yyexhaustedlab;
1209 YYSTACK_RELOCATE (yyss_alloc, yyss);
1210 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001211# undef YYSTACK_RELOCATE
Jamie Madill185de882014-12-22 15:17:52 -05001212 if (yyss1 != yyssa)
1213 YYSTACK_FREE (yyss1);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001214 }
1215# endif
1216#endif /* no yyoverflow */
1217
1218 yyssp = yyss + yysize - 1;
1219 yyvsp = yyvs + yysize - 1;
1220
1221 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
Jamie Madill185de882014-12-22 15:17:52 -05001222 (unsigned long int) yystacksize));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001223
1224 if (yyss + yystacksize - 1 <= yyssp)
Jamie Madill185de882014-12-22 15:17:52 -05001225 YYABORT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001226 }
1227
1228 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1229
1230 if (yystate == YYFINAL)
1231 YYACCEPT;
1232
1233 goto yybackup;
1234
1235/*-----------.
1236| yybackup. |
1237`-----------*/
1238yybackup:
1239
1240 /* Do appropriate processing given the current state. Read a
1241 lookahead token if we need one and don't already have one. */
1242
1243 /* First try to decide what to do without reference to lookahead token. */
1244 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001245 if (yypact_value_is_default (yyn))
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001246 goto yydefault;
1247
1248 /* Not known => get a lookahead token if don't already have one. */
1249
1250 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1251 if (yychar == YYEMPTY)
1252 {
1253 YYDPRINTF ((stderr, "Reading a token: "));
Jamie Madill185de882014-12-22 15:17:52 -05001254 yychar = yylex (&yylval, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001255 }
1256
1257 if (yychar <= YYEOF)
1258 {
1259 yychar = yytoken = YYEOF;
1260 YYDPRINTF ((stderr, "Now at end of input.\n"));
1261 }
1262 else
1263 {
1264 yytoken = YYTRANSLATE (yychar);
1265 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1266 }
1267
1268 /* If the proper action on seeing token YYTOKEN is to reduce or to
1269 detect an error, take that action. */
1270 yyn += yytoken;
1271 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1272 goto yydefault;
1273 yyn = yytable[yyn];
1274 if (yyn <= 0)
1275 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001276 if (yytable_value_is_error (yyn))
1277 goto yyerrlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001278 yyn = -yyn;
1279 goto yyreduce;
1280 }
1281
1282 /* Count tokens shifted since error; after three, turn off error
1283 status. */
1284 if (yyerrstatus)
1285 yyerrstatus--;
1286
1287 /* Shift the lookahead token. */
1288 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1289
1290 /* Discard the shifted token. */
1291 yychar = YYEMPTY;
1292
1293 yystate = yyn;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001294 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001295 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001296 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001297
1298 goto yynewstate;
1299
1300
1301/*-----------------------------------------------------------.
1302| yydefault -- do the default action for the current state. |
1303`-----------------------------------------------------------*/
1304yydefault:
1305 yyn = yydefact[yystate];
1306 if (yyn == 0)
1307 goto yyerrlab;
1308 goto yyreduce;
1309
1310
1311/*-----------------------------.
1312| yyreduce -- Do a reduction. |
1313`-----------------------------*/
1314yyreduce:
1315 /* yyn is the number of a rule to reduce with. */
1316 yylen = yyr2[yyn];
1317
1318 /* If YYLEN is nonzero, implement the default value of the action:
Jamie Madill185de882014-12-22 15:17:52 -05001319 '$$ = $1'.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001320
1321 Otherwise, the following line sets YYVAL to garbage.
1322 This behavior is undocumented and Bison
1323 users should not rely upon it. Assigning to YYVAL
1324 unconditionally makes the parser a bit smaller, and it avoids a
1325 GCC warning that YYVAL may be used uninitialized. */
1326 yyval = yyvsp[1-yylen];
1327
1328
1329 YY_REDUCE_PRINT (yyn);
1330 switch (yyn)
1331 {
1332 case 2:
1333
1334 {
Jamie Madill185de882014-12-22 15:17:52 -05001335 *(context->result) = static_cast<int>((yyvsp[0]));
Olli Etuaho3187a382015-09-09 12:00:12 +03001336 YYACCEPT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001337 }
Jamie Madill185de882014-12-22 15:17:52 -05001338
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001339 break;
1340
1341 case 4:
1342
1343 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001344 if (!context->isIgnoringErrors())
1345 {
Olli Etuaho3187a382015-09-09 12:00:12 +03001346 // This rule should be applied right after the token is lexed, so we can
1347 // refer to context->token in the error message.
Olli Etuaho247374c2015-09-09 15:07:24 +03001348 context->diagnostics->report(context->errorSettings.unexpectedIdentifier,
Olli Etuaho3187a382015-09-09 12:00:12 +03001349 context->token->location, context->token->text);
Olli Etuaho247374c2015-09-09 15:07:24 +03001350 *(context->valid) = false;
Olli Etuaho809ec542015-08-26 14:30:57 +03001351 }
Olli Etuaho3187a382015-09-09 12:00:12 +03001352 (yyval) = (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001353 }
Jamie Madill185de882014-12-22 15:17:52 -05001354
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001355 break;
1356
1357 case 5:
1358
1359 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001360 if ((yyvsp[-1]) != 0)
1361 {
1362 // Ignore errors in the short-circuited part of the expression.
1363 // ESSL3.00 section 3.4:
1364 // If an operand is not evaluated, the presence of undefined identifiers
1365 // in the operand will not cause an error.
1366 // Unevaluated division by zero should not cause an error either.
1367 context->startIgnoreErrors();
1368 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001369 }
Jamie Madill185de882014-12-22 15:17:52 -05001370
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001371 break;
1372
1373 case 6:
1374
1375 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001376 if ((yyvsp[-3]) != 0)
1377 {
1378 context->endIgnoreErrors();
1379 (yyval) = static_cast<YYSTYPE>(1);
1380 }
1381 else
1382 {
1383 (yyval) = (yyvsp[-3]) || (yyvsp[0]);
1384 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001385 }
Jamie Madill185de882014-12-22 15:17:52 -05001386
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001387 break;
1388
1389 case 7:
1390
1391 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001392 if ((yyvsp[-1]) == 0)
1393 {
1394 // Ignore errors in the short-circuited part of the expression.
1395 // ESSL3.00 section 3.4:
1396 // If an operand is not evaluated, the presence of undefined identifiers
1397 // in the operand will not cause an error.
1398 // Unevaluated division by zero should not cause an error either.
1399 context->startIgnoreErrors();
1400 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001401 }
Jamie Madill185de882014-12-22 15:17:52 -05001402
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001403 break;
1404
1405 case 8:
1406
1407 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001408 if ((yyvsp[-3]) == 0)
1409 {
1410 context->endIgnoreErrors();
1411 (yyval) = static_cast<YYSTYPE>(0);
1412 }
1413 else
1414 {
1415 (yyval) = (yyvsp[-3]) && (yyvsp[0]);
1416 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001417 }
Jamie Madill185de882014-12-22 15:17:52 -05001418
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001419 break;
1420
1421 case 9:
1422
1423 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001424 (yyval) = (yyvsp[-2]) | (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001425 }
Jamie Madill185de882014-12-22 15:17:52 -05001426
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001427 break;
1428
1429 case 10:
1430
1431 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001432 (yyval) = (yyvsp[-2]) ^ (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001433 }
Jamie Madill185de882014-12-22 15:17:52 -05001434
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001435 break;
1436
1437 case 11:
1438
1439 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001440 (yyval) = (yyvsp[-2]) & (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001441 }
Jamie Madill185de882014-12-22 15:17:52 -05001442
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001443 break;
1444
1445 case 12:
1446
1447 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001448 (yyval) = (yyvsp[-2]) != (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001449 }
Jamie Madill185de882014-12-22 15:17:52 -05001450
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001451 break;
1452
1453 case 13:
1454
1455 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001456 (yyval) = (yyvsp[-2]) == (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001457 }
Jamie Madill185de882014-12-22 15:17:52 -05001458
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001459 break;
1460
1461 case 14:
1462
1463 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001464 (yyval) = (yyvsp[-2]) >= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001465 }
Jamie Madill185de882014-12-22 15:17:52 -05001466
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001467 break;
1468
1469 case 15:
1470
1471 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001472 (yyval) = (yyvsp[-2]) <= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001473 }
Jamie Madill185de882014-12-22 15:17:52 -05001474
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001475 break;
1476
1477 case 16:
1478
1479 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001480 (yyval) = (yyvsp[-2]) > (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001481 }
Jamie Madill185de882014-12-22 15:17:52 -05001482
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001483 break;
1484
1485 case 17:
1486
1487 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001488 (yyval) = (yyvsp[-2]) < (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001489 }
Jamie Madill185de882014-12-22 15:17:52 -05001490
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001491 break;
1492
1493 case 18:
1494
1495 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001496 if ((yyvsp[0]) < 0 || (yyvsp[0]) > 31)
Jamie Madill461e3af2016-07-21 18:15:34 -04001497 {
1498 if (!context->isIgnoringErrors())
1499 {
1500 std::ostringstream stream;
1501 stream << (yyvsp[-2]) << " >> " << (yyvsp[0]);
1502 std::string text = stream.str();
1503 context->diagnostics->report(pp::Diagnostics::PP_UNDEFINED_SHIFT,
Geoff Lang93561c32016-09-20 10:22:55 -04001504 context->token->location,
1505 text.c_str());
Jamie Madill461e3af2016-07-21 18:15:34 -04001506 *(context->valid) = false;
1507 }
1508 (yyval) = static_cast<YYSTYPE>(0);
1509 }
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001510 else if ((yyvsp[-2]) < 0)
1511 {
1512 // Logical shift right.
1513 (yyval) = static_cast<YYSTYPE>(static_cast<UNSIGNED_TYPE>((yyvsp[-2])) >> (yyvsp[0]));
1514 }
Jamie Madill461e3af2016-07-21 18:15:34 -04001515 else
1516 {
1517 (yyval) = (yyvsp[-2]) >> (yyvsp[0]);
1518 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001519 }
Jamie Madill185de882014-12-22 15:17:52 -05001520
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001521 break;
1522
1523 case 19:
1524
1525 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001526 if ((yyvsp[0]) < 0 || (yyvsp[0]) > 31)
Jamie Madill461e3af2016-07-21 18:15:34 -04001527 {
1528 if (!context->isIgnoringErrors())
1529 {
1530 std::ostringstream stream;
1531 stream << (yyvsp[-2]) << " << " << (yyvsp[0]);
1532 std::string text = stream.str();
1533 context->diagnostics->report(pp::Diagnostics::PP_UNDEFINED_SHIFT,
Geoff Lang93561c32016-09-20 10:22:55 -04001534 context->token->location,
1535 text.c_str());
Jamie Madill461e3af2016-07-21 18:15:34 -04001536 *(context->valid) = false;
1537 }
1538 (yyval) = static_cast<YYSTYPE>(0);
1539 }
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001540 else if ((yyvsp[-2]) < 0)
1541 {
1542 // Logical shift left.
1543 (yyval) = static_cast<YYSTYPE>(static_cast<UNSIGNED_TYPE>((yyvsp[-2])) << (yyvsp[0]));
1544 }
Jamie Madill461e3af2016-07-21 18:15:34 -04001545 else
1546 {
1547 (yyval) = (yyvsp[-2]) << (yyvsp[0]);
1548 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001549 }
Jamie Madill185de882014-12-22 15:17:52 -05001550
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001551 break;
1552
1553 case 20:
1554
1555 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001556 (yyval) = gl::WrappingDiff<YYSTYPE>((yyvsp[-2]), (yyvsp[0]));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001557 }
Jamie Madill185de882014-12-22 15:17:52 -05001558
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001559 break;
1560
1561 case 21:
1562
1563 {
Olli Etuaho7f9a55f2016-10-03 14:32:08 +01001564 (yyval) = gl::WrappingSum<YYSTYPE>((yyvsp[-2]), (yyvsp[0]));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001565 }
Jamie Madill185de882014-12-22 15:17:52 -05001566
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001567 break;
1568
1569 case 22:
1570
1571 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001572 if ((yyvsp[0]) == 0)
1573 {
Olli Etuaho3187a382015-09-09 12:00:12 +03001574 if (!context->isIgnoringErrors())
Olli Etuaho809ec542015-08-26 14:30:57 +03001575 {
1576 std::ostringstream stream;
1577 stream << (yyvsp[-2]) << " % " << (yyvsp[0]);
1578 std::string text = stream.str();
1579 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1580 context->token->location,
1581 text.c_str());
Olli Etuaho247374c2015-09-09 15:07:24 +03001582 *(context->valid) = false;
Olli Etuaho809ec542015-08-26 14:30:57 +03001583 }
Olli Etuaho3187a382015-09-09 12:00:12 +03001584 (yyval) = static_cast<YYSTYPE>(0);
Olli Etuaho809ec542015-08-26 14:30:57 +03001585 }
1586 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 Etuaho7f9a55f2016-10-03 14:32:08 +01001611 else if ((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min() && (yyvsp[0]) == -1)
1612 {
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