blob: 19944dc719d0b3b59988f83eb8763f8081a32b38 [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>
102
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000103#include "DiagnosticsBase.h"
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000104#include "Lexer.h"
105#include "Token.h"
106
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000107#if defined(_MSC_VER)
108typedef __int64 YYSTYPE;
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000109#else
110#include <stdint.h>
111typedef intmax_t YYSTYPE;
112#endif // _MSC_VER
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000113#define YYENABLE_NLS 0
114#define YYLTYPE_IS_TRIVIAL 1
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000115#define YYSTYPE_IS_TRIVIAL 1
116#define YYSTYPE_IS_DECLARED 1
117
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000118namespace {
119struct Context
120{
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000121 pp::Diagnostics* diagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000122 pp::Lexer* lexer;
123 pp::Token* token;
124 int* result;
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300125
126 void startIgnoreErrors() { ++ignoreErrors; }
127 void endIgnoreErrors() { --ignoreErrors; }
128
129 bool isIgnoringErrors() { return ignoreErrors > 0; }
130
131 int ignoreErrors;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000132};
133} // namespace
134
135
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000136static int yylex(YYSTYPE* lvalp, Context* context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000137static void yyerror(Context* context, const char* reason);
138
139
140
Jamie Madill185de882014-12-22 15:17:52 -0500141# ifndef YY_NULLPTR
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000142# if defined __cplusplus && 201103L <= __cplusplus
Jamie Madill185de882014-12-22 15:17:52 -0500143# define YY_NULLPTR nullptr
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000144# else
Jamie Madill185de882014-12-22 15:17:52 -0500145# define YY_NULLPTR 0
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000146# endif
147# endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000148
149/* Enabling verbose error messages. */
150#ifdef YYERROR_VERBOSE
151# undef YYERROR_VERBOSE
152# define YYERROR_VERBOSE 1
153#else
154# define YYERROR_VERBOSE 0
155#endif
156
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000157
Jamie Madill185de882014-12-22 15:17:52 -0500158/* Debug traces. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000159#ifndef YYDEBUG
160# define YYDEBUG 0
161#endif
162#if YYDEBUG
163extern int ppdebug;
164#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000165
Jamie Madill185de882014-12-22 15:17:52 -0500166/* Token type. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000167#ifndef YYTOKENTYPE
168# define YYTOKENTYPE
Jamie Madill185de882014-12-22 15:17:52 -0500169 enum yytokentype
170 {
171 TOK_CONST_INT = 258,
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300172 TOK_IDENTIFIER = 259,
173 TOK_OP_OR = 260,
174 TOK_OP_AND = 261,
175 TOK_OP_EQ = 262,
176 TOK_OP_NE = 263,
177 TOK_OP_LE = 264,
178 TOK_OP_GE = 265,
179 TOK_OP_LEFT = 266,
180 TOK_OP_RIGHT = 267,
181 TOK_UNARY = 268
Jamie Madill185de882014-12-22 15:17:52 -0500182 };
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000183#endif
184
Jamie Madill185de882014-12-22 15:17:52 -0500185/* Value type. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000186#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
187typedef int YYSTYPE;
188# define YYSTYPE_IS_TRIVIAL 1
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000189# define YYSTYPE_IS_DECLARED 1
190#endif
191
192
Jamie Madill185de882014-12-22 15:17:52 -0500193
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000194int ppparse (Context *context);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000195
196
197
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000198/* Copy the second part of user declarations. */
199
200
201
202#ifdef short
203# undef short
204#endif
205
206#ifdef YYTYPE_UINT8
207typedef YYTYPE_UINT8 yytype_uint8;
208#else
209typedef unsigned char yytype_uint8;
210#endif
211
212#ifdef YYTYPE_INT8
213typedef YYTYPE_INT8 yytype_int8;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000214#else
Jamie Madill185de882014-12-22 15:17:52 -0500215typedef signed char yytype_int8;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000216#endif
217
218#ifdef YYTYPE_UINT16
219typedef YYTYPE_UINT16 yytype_uint16;
220#else
221typedef unsigned short int yytype_uint16;
222#endif
223
224#ifdef YYTYPE_INT16
225typedef YYTYPE_INT16 yytype_int16;
226#else
227typedef short int yytype_int16;
228#endif
229
230#ifndef YYSIZE_T
231# ifdef __SIZE_TYPE__
232# define YYSIZE_T __SIZE_TYPE__
233# elif defined size_t
234# define YYSIZE_T size_t
Jamie Madill185de882014-12-22 15:17:52 -0500235# elif ! defined YYSIZE_T
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000236# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
237# define YYSIZE_T size_t
238# else
239# define YYSIZE_T unsigned int
240# endif
241#endif
242
243#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
244
245#ifndef YY_
246# if defined YYENABLE_NLS && YYENABLE_NLS
247# if ENABLE_NLS
248# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000249# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000250# endif
251# endif
252# ifndef YY_
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000253# define YY_(Msgid) Msgid
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000254# endif
255#endif
256
Jamie Madill185de882014-12-22 15:17:52 -0500257#ifndef YY_ATTRIBUTE
258# if (defined __GNUC__ \
259 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
260 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
261# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
262# else
263# define YY_ATTRIBUTE(Spec) /* empty */
264# endif
265#endif
266
267#ifndef YY_ATTRIBUTE_PURE
268# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
269#endif
270
271#ifndef YY_ATTRIBUTE_UNUSED
272# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
273#endif
274
275#if !defined _Noreturn \
276 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
277# if defined _MSC_VER && 1200 <= _MSC_VER
278# define _Noreturn __declspec (noreturn)
279# else
280# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400281# endif
282#endif
283
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000284/* Suppress unused-variable warnings by "using" E. */
285#if ! defined lint || defined __GNUC__
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000286# define YYUSE(E) ((void) (E))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000287#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000288# define YYUSE(E) /* empty */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000289#endif
290
Jamie Madill185de882014-12-22 15:17:52 -0500291#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
292/* Suppress an incorrect diagnostic about yylval being uninitialized. */
293# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
294 _Pragma ("GCC diagnostic push") \
295 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
296 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
297# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
298 _Pragma ("GCC diagnostic pop")
299#else
300# define YY_INITIAL_VALUE(Value) Value
301#endif
302#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
303# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
304# define YY_IGNORE_MAYBE_UNINITIALIZED_END
305#endif
306#ifndef YY_INITIAL_VALUE
307# define YY_INITIAL_VALUE(Value) /* Nothing. */
308#endif
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400309
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000310
311#if ! defined yyoverflow || YYERROR_VERBOSE
312
313/* The parser invokes alloca or malloc; define the necessary symbols. */
314
315# ifdef YYSTACK_USE_ALLOCA
316# if YYSTACK_USE_ALLOCA
317# ifdef __GNUC__
318# define YYSTACK_ALLOC __builtin_alloca
319# elif defined __BUILTIN_VA_ARG_INCR
320# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
321# elif defined _AIX
322# define YYSTACK_ALLOC __alloca
323# elif defined _MSC_VER
324# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
325# define alloca _alloca
326# else
327# define YYSTACK_ALLOC alloca
Jamie Madill185de882014-12-22 15:17:52 -0500328# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000329# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000330 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
331# ifndef EXIT_SUCCESS
332# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000333# endif
334# endif
335# endif
336# endif
337# endif
338
339# ifdef YYSTACK_ALLOC
Jamie Madill185de882014-12-22 15:17:52 -0500340 /* Pacify GCC's 'empty if-body' warning. */
341# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000342# ifndef YYSTACK_ALLOC_MAXIMUM
343 /* The OS might guarantee only one guard page at the bottom of the stack,
344 and a page size can be as small as 4096 bytes. So we cannot safely
345 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
346 to allow for a few compiler-allocated temporary stack slots. */
347# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
348# endif
349# else
350# define YYSTACK_ALLOC YYMALLOC
351# define YYSTACK_FREE YYFREE
352# ifndef YYSTACK_ALLOC_MAXIMUM
353# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
354# endif
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000355# if (defined __cplusplus && ! defined EXIT_SUCCESS \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000356 && ! ((defined YYMALLOC || defined malloc) \
Jamie Madill185de882014-12-22 15:17:52 -0500357 && (defined YYFREE || defined free)))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000358# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000359# ifndef EXIT_SUCCESS
360# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000361# endif
362# endif
363# ifndef YYMALLOC
364# define YYMALLOC malloc
Jamie Madill185de882014-12-22 15:17:52 -0500365# if ! defined malloc && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000366void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
367# endif
368# endif
369# ifndef YYFREE
370# define YYFREE free
Jamie Madill185de882014-12-22 15:17:52 -0500371# if ! defined free && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000372void free (void *); /* INFRINGES ON USER NAME SPACE */
373# endif
374# endif
375# endif
376#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
377
378
379#if (! defined yyoverflow \
380 && (! defined __cplusplus \
Jamie Madill185de882014-12-22 15:17:52 -0500381 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000382
383/* A type that is properly aligned for any stack member. */
384union yyalloc
385{
386 yytype_int16 yyss_alloc;
387 YYSTYPE yyvs_alloc;
388};
389
390/* The size of the maximum gap between one aligned stack and the next. */
391# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
392
393/* The size of an array large to enough to hold all stacks, each with
394 N elements. */
395# define YYSTACK_BYTES(N) \
396 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
397 + YYSTACK_GAP_MAXIMUM)
398
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000399# define YYCOPY_NEEDED 1
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000400
401/* Relocate STACK from its old location to the new one. The
402 local variables YYSIZE and YYSTACKSIZE give the old and new number of
403 elements in the stack, and YYPTR gives the new location of the
404 stack. Advance YYPTR to a properly aligned location for the next
405 stack. */
Jamie Madill185de882014-12-22 15:17:52 -0500406# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
407 do \
408 { \
409 YYSIZE_T yynewbytes; \
410 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
411 Stack = &yyptr->Stack_alloc; \
412 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
413 yyptr += yynewbytes / sizeof (*yyptr); \
414 } \
415 while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000416
417#endif
418
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000419#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
420/* Copy COUNT objects from SRC to DST. The source and destination do
421 not overlap. */
422# ifndef YYCOPY
423# if defined __GNUC__ && 1 < __GNUC__
424# define YYCOPY(Dst, Src, Count) \
425 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
426# else
427# define YYCOPY(Dst, Src, Count) \
428 do \
429 { \
430 YYSIZE_T yyi; \
431 for (yyi = 0; yyi < (Count); yyi++) \
432 (Dst)[yyi] = (Src)[yyi]; \
433 } \
Jamie Madill185de882014-12-22 15:17:52 -0500434 while (0)
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000435# endif
436# endif
437#endif /* !YYCOPY_NEEDED */
438
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000439/* YYFINAL -- State number of the termination state. */
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300440#define YYFINAL 15
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000441/* YYLAST -- Last index in YYTABLE. */
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300442#define YYLAST 176
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000443
444/* YYNTOKENS -- Number of terminals. */
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300445#define YYNTOKENS 28
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000446/* YYNNTS -- Number of nonterminals. */
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300447#define YYNNTS 5
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000448/* YYNRULES -- Number of rules. */
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300449#define YYNRULES 29
Jamie Madill185de882014-12-22 15:17:52 -0500450/* YYNSTATES -- Number of states. */
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300451#define YYNSTATES 55
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000452
Jamie Madill185de882014-12-22 15:17:52 -0500453/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
454 by yylex, with out-of-bounds checking. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000455#define YYUNDEFTOK 2
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300456#define YYMAXUTOK 268
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000457
Jamie Madill185de882014-12-22 15:17:52 -0500458#define YYTRANSLATE(YYX) \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000459 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
460
Jamie Madill185de882014-12-22 15:17:52 -0500461/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
462 as returned by yylex, without out-of-bounds checking. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000463static const yytype_uint8 yytranslate[] =
464{
465 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
466 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
467 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300468 2, 2, 2, 24, 2, 2, 2, 22, 9, 2,
469 26, 27, 20, 18, 2, 19, 2, 21, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000470 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300471 12, 2, 13, 2, 2, 2, 2, 2, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000472 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
473 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300474 2, 2, 2, 2, 8, 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 Etuaho6ffe6132015-08-26 14:30:57 +0300477 2, 2, 2, 2, 7, 2, 25, 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,
480 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
481 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, 1, 2, 3, 4,
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300491 5, 6, 10, 11, 14, 15, 16, 17, 23
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000492};
493
494#if YYDEBUG
Jamie Madill185de882014-12-22 15:17:52 -0500495 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300496static const yytype_uint16 yyrline[] =
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000497{
Olli Etuaho6ffe6132015-08-26 14:30:57 +0300498 0, 105, 105, 111, 112, 118, 118, 141, 141, 164,
499 167, 170, 173, 176, 179, 182, 185, 188, 191, 194,
500 197, 200, 203, 226, 249, 252, 255, 258, 261, 264
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000501};
502#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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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 Etuaho6ffe6132015-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]));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001333 }
Jamie Madill185de882014-12-22 15:17:52 -05001334
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001335 break;
1336
1337 case 4:
1338
1339 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001340 if (!context->isIgnoringErrors())
1341 {
1342 YYABORT;
1343 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001344 }
Jamie Madill185de882014-12-22 15:17:52 -05001345
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001346 break;
1347
1348 case 5:
1349
1350 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001351 if ((yyvsp[-1]) != 0)
1352 {
1353 // Ignore errors in the short-circuited part of the expression.
1354 // ESSL3.00 section 3.4:
1355 // If an operand is not evaluated, the presence of undefined identifiers
1356 // in the operand will not cause an error.
1357 // Unevaluated division by zero should not cause an error either.
1358 context->startIgnoreErrors();
1359 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001360 }
Jamie Madill185de882014-12-22 15:17:52 -05001361
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001362 break;
1363
1364 case 6:
1365
1366 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001367 if ((yyvsp[-3]) != 0)
1368 {
1369 context->endIgnoreErrors();
1370 // Make sure that short-circuited version of || works consistently
1371 // with the normal version even for values other than 0 and 1.
1372 (yyval) = (yyvsp[-3]) || 0;
1373 }
1374 else
1375 {
1376 (yyval) = (yyvsp[-3]) || (yyvsp[0]);
1377 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001378 }
Jamie Madill185de882014-12-22 15:17:52 -05001379
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001380 break;
1381
1382 case 7:
1383
1384 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001385 if ((yyvsp[-1]) == 0)
1386 {
1387 // Ignore errors in the short-circuited part of the expression.
1388 // ESSL3.00 section 3.4:
1389 // If an operand is not evaluated, the presence of undefined identifiers
1390 // in the operand will not cause an error.
1391 // Unevaluated division by zero should not cause an error either.
1392 context->startIgnoreErrors();
1393 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001394 }
Jamie Madill185de882014-12-22 15:17:52 -05001395
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001396 break;
1397
1398 case 8:
1399
1400 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001401 if ((yyvsp[-3]) == 0)
1402 {
1403 context->endIgnoreErrors();
1404 // Make sure that short-circuited version of && works consistently
1405 // with the normal version even for values other than 0 and 1.
1406 (yyval) = (yyvsp[-3]) && 0;
1407 }
1408 else
1409 {
1410 (yyval) = (yyvsp[-3]) && (yyvsp[0]);
1411 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001412 }
Jamie Madill185de882014-12-22 15:17:52 -05001413
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001414 break;
1415
1416 case 9:
1417
1418 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001419 (yyval) = (yyvsp[-2]) | (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001420 }
Jamie Madill185de882014-12-22 15:17:52 -05001421
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001422 break;
1423
1424 case 10:
1425
1426 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001427 (yyval) = (yyvsp[-2]) ^ (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001428 }
Jamie Madill185de882014-12-22 15:17:52 -05001429
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001430 break;
1431
1432 case 11:
1433
1434 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001435 (yyval) = (yyvsp[-2]) & (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001436 }
Jamie Madill185de882014-12-22 15:17:52 -05001437
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001438 break;
1439
1440 case 12:
1441
1442 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001443 (yyval) = (yyvsp[-2]) != (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001444 }
Jamie Madill185de882014-12-22 15:17:52 -05001445
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001446 break;
1447
1448 case 13:
1449
1450 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001451 (yyval) = (yyvsp[-2]) == (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001452 }
Jamie Madill185de882014-12-22 15:17:52 -05001453
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001454 break;
1455
1456 case 14:
1457
1458 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001459 (yyval) = (yyvsp[-2]) >= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001460 }
Jamie Madill185de882014-12-22 15:17:52 -05001461
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001462 break;
1463
1464 case 15:
1465
1466 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001467 (yyval) = (yyvsp[-2]) <= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001468 }
Jamie Madill185de882014-12-22 15:17:52 -05001469
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001470 break;
1471
1472 case 16:
1473
1474 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001475 (yyval) = (yyvsp[-2]) > (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001476 }
Jamie Madill185de882014-12-22 15:17:52 -05001477
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001478 break;
1479
1480 case 17:
1481
1482 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001483 (yyval) = (yyvsp[-2]) < (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001484 }
Jamie Madill185de882014-12-22 15:17:52 -05001485
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001486 break;
1487
1488 case 18:
1489
1490 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001491 (yyval) = (yyvsp[-2]) >> (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001492 }
Jamie Madill185de882014-12-22 15:17:52 -05001493
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001494 break;
1495
1496 case 19:
1497
1498 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001499 (yyval) = (yyvsp[-2]) << (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001500 }
Jamie Madill185de882014-12-22 15:17:52 -05001501
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001502 break;
1503
1504 case 20:
1505
1506 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001507 (yyval) = (yyvsp[-2]) - (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001508 }
Jamie Madill185de882014-12-22 15:17:52 -05001509
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001510 break;
1511
1512 case 21:
1513
1514 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001515 (yyval) = (yyvsp[-2]) + (yyvsp[0]);
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 22:
1521
1522 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001523 if ((yyvsp[0]) == 0)
1524 {
1525 if (context->isIgnoringErrors())
1526 {
1527 (yyval) = static_cast<YYSTYPE>(0);
1528 }
1529 else
1530 {
1531 std::ostringstream stream;
1532 stream << (yyvsp[-2]) << " % " << (yyvsp[0]);
1533 std::string text = stream.str();
1534 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1535 context->token->location,
1536 text.c_str());
1537 YYABORT;
1538 }
1539 }
1540 else
1541 {
1542 (yyval) = (yyvsp[-2]) % (yyvsp[0]);
1543 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001544 }
Jamie Madill185de882014-12-22 15:17:52 -05001545
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001546 break;
1547
1548 case 23:
1549
1550 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001551 if ((yyvsp[0]) == 0)
1552 {
1553 if (context->isIgnoringErrors())
1554 {
1555 (yyval) = static_cast<YYSTYPE>(0);
1556 }
1557 else
1558 {
1559 std::ostringstream stream;
1560 stream << (yyvsp[-2]) << " / " << (yyvsp[0]);
1561 std::string text = stream.str();
1562 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1563 context->token->location,
1564 text.c_str());
1565 YYABORT;
1566 }
1567 }
1568 else
1569 {
1570 (yyval) = (yyvsp[-2]) / (yyvsp[0]);
1571 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001572 }
Jamie Madill185de882014-12-22 15:17:52 -05001573
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001574 break;
1575
1576 case 24:
1577
1578 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001579 (yyval) = (yyvsp[-2]) * (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001580 }
Jamie Madill185de882014-12-22 15:17:52 -05001581
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001582 break;
1583
1584 case 25:
1585
1586 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001587 (yyval) = ! (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001588 }
Jamie Madill185de882014-12-22 15:17:52 -05001589
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001590 break;
1591
1592 case 26:
1593
1594 {
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001595 (yyval) = ~ (yyvsp[0]);
1596 }
1597
1598 break;
1599
1600 case 27:
1601
1602 {
1603 (yyval) = - (yyvsp[0]);
1604 }
1605
1606 break;
1607
1608 case 28:
1609
1610 {
1611 (yyval) = + (yyvsp[0]);
1612 }
1613
1614 break;
1615
1616 case 29:
1617
1618 {
Jamie Madill185de882014-12-22 15:17:52 -05001619 (yyval) = (yyvsp[-1]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001620 }
Jamie Madill185de882014-12-22 15:17:52 -05001621
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001622 break;
1623
1624
1625
1626 default: break;
1627 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001628 /* User semantic actions sometimes alter yychar, and that requires
1629 that yytoken be updated with the new translation. We take the
1630 approach of translating immediately before every use of yytoken.
1631 One alternative is translating here after every semantic action,
1632 but that translation would be missed if the semantic action invokes
1633 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1634 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1635 incorrect destructor might then be invoked immediately. In the
1636 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1637 to an incorrect destructor call or verbose syntax error message
1638 before the lookahead is translated. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001639 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1640
1641 YYPOPSTACK (yylen);
1642 yylen = 0;
1643 YY_STACK_PRINT (yyss, yyssp);
1644
1645 *++yyvsp = yyval;
1646
Jamie Madill185de882014-12-22 15:17:52 -05001647 /* Now 'shift' the result of the reduction. Determine what state
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001648 that goes to, based on the state we popped back to and the rule
1649 number reduced by. */
1650
1651 yyn = yyr1[yyn];
1652
1653 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1654 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1655 yystate = yytable[yystate];
1656 else
1657 yystate = yydefgoto[yyn - YYNTOKENS];
1658
1659 goto yynewstate;
1660
1661
Jamie Madill185de882014-12-22 15:17:52 -05001662/*--------------------------------------.
1663| yyerrlab -- here on detecting error. |
1664`--------------------------------------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001665yyerrlab:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001666 /* Make sure we have latest lookahead translation. See comments at
1667 user semantic actions for why this is necessary. */
1668 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1669
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001670 /* If not already recovering from an error, report this error. */
1671 if (!yyerrstatus)
1672 {
1673 ++yynerrs;
1674#if ! YYERROR_VERBOSE
1675 yyerror (context, YY_("syntax error"));
1676#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001677# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1678 yyssp, yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001679 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001680 char const *yymsgp = YY_("syntax error");
1681 int yysyntax_error_status;
1682 yysyntax_error_status = YYSYNTAX_ERROR;
1683 if (yysyntax_error_status == 0)
1684 yymsgp = yymsg;
1685 else if (yysyntax_error_status == 1)
1686 {
1687 if (yymsg != yymsgbuf)
1688 YYSTACK_FREE (yymsg);
1689 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1690 if (!yymsg)
1691 {
1692 yymsg = yymsgbuf;
1693 yymsg_alloc = sizeof yymsgbuf;
1694 yysyntax_error_status = 2;
1695 }
1696 else
1697 {
1698 yysyntax_error_status = YYSYNTAX_ERROR;
1699 yymsgp = yymsg;
1700 }
1701 }
1702 yyerror (context, yymsgp);
1703 if (yysyntax_error_status == 2)
1704 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001705 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001706# undef YYSYNTAX_ERROR
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001707#endif
1708 }
1709
1710
1711
1712 if (yyerrstatus == 3)
1713 {
1714 /* If just tried and failed to reuse lookahead token after an
Jamie Madill185de882014-12-22 15:17:52 -05001715 error, discard it. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001716
1717 if (yychar <= YYEOF)
Jamie Madill185de882014-12-22 15:17:52 -05001718 {
1719 /* Return failure if at end of input. */
1720 if (yychar == YYEOF)
1721 YYABORT;
1722 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001723 else
Jamie Madill185de882014-12-22 15:17:52 -05001724 {
1725 yydestruct ("Error: discarding",
1726 yytoken, &yylval, context);
1727 yychar = YYEMPTY;
1728 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001729 }
1730
1731 /* Else will try to reuse lookahead token after shifting the error
1732 token. */
1733 goto yyerrlab1;
1734
1735
1736/*---------------------------------------------------.
1737| yyerrorlab -- error raised explicitly by YYERROR. |
1738`---------------------------------------------------*/
1739yyerrorlab:
1740
1741 /* Pacify compilers like GCC when the user code never invokes
1742 YYERROR and the label yyerrorlab therefore never appears in user
1743 code. */
1744 if (/*CONSTCOND*/ 0)
1745 goto yyerrorlab;
1746
Jamie Madill185de882014-12-22 15:17:52 -05001747 /* Do not reclaim the symbols of the rule whose action triggered
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001748 this YYERROR. */
1749 YYPOPSTACK (yylen);
1750 yylen = 0;
1751 YY_STACK_PRINT (yyss, yyssp);
1752 yystate = *yyssp;
1753 goto yyerrlab1;
1754
1755
1756/*-------------------------------------------------------------.
1757| yyerrlab1 -- common code for both syntax error and YYERROR. |
1758`-------------------------------------------------------------*/
1759yyerrlab1:
Jamie Madill185de882014-12-22 15:17:52 -05001760 yyerrstatus = 3; /* Each real token shifted decrements this. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001761
1762 for (;;)
1763 {
1764 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001765 if (!yypact_value_is_default (yyn))
Jamie Madill185de882014-12-22 15:17:52 -05001766 {
1767 yyn += YYTERROR;
1768 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1769 {
1770 yyn = yytable[yyn];
1771 if (0 < yyn)
1772 break;
1773 }
1774 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001775
1776 /* Pop the current state because it cannot handle the error token. */
1777 if (yyssp == yyss)
Jamie Madill185de882014-12-22 15:17:52 -05001778 YYABORT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001779
1780
1781 yydestruct ("Error: popping",
Jamie Madill185de882014-12-22 15:17:52 -05001782 yystos[yystate], yyvsp, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001783 YYPOPSTACK (1);
1784 yystate = *yyssp;
1785 YY_STACK_PRINT (yyss, yyssp);
1786 }
1787
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001788 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001789 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001790 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001791
1792
1793 /* Shift the error token. */
1794 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1795
1796 yystate = yyn;
1797 goto yynewstate;
1798
1799
1800/*-------------------------------------.
1801| yyacceptlab -- YYACCEPT comes here. |
1802`-------------------------------------*/
1803yyacceptlab:
1804 yyresult = 0;
1805 goto yyreturn;
1806
1807/*-----------------------------------.
1808| yyabortlab -- YYABORT comes here. |
1809`-----------------------------------*/
1810yyabortlab:
1811 yyresult = 1;
1812 goto yyreturn;
1813
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001814#if !defined yyoverflow || YYERROR_VERBOSE
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001815/*-------------------------------------------------.
1816| yyexhaustedlab -- memory exhaustion comes here. |
1817`-------------------------------------------------*/
1818yyexhaustedlab:
1819 yyerror (context, YY_("memory exhausted"));
1820 yyresult = 2;
1821 /* Fall through. */
1822#endif
1823
1824yyreturn:
1825 if (yychar != YYEMPTY)
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001826 {
1827 /* Make sure we have latest lookahead translation. See comments at
1828 user semantic actions for why this is necessary. */
1829 yytoken = YYTRANSLATE (yychar);
1830 yydestruct ("Cleanup: discarding lookahead",
1831 yytoken, &yylval, context);
1832 }
Jamie Madill185de882014-12-22 15:17:52 -05001833 /* Do not reclaim the symbols of the rule whose action triggered
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001834 this YYABORT or YYACCEPT. */
1835 YYPOPSTACK (yylen);
1836 YY_STACK_PRINT (yyss, yyssp);
1837 while (yyssp != yyss)
1838 {
1839 yydestruct ("Cleanup: popping",
Jamie Madill185de882014-12-22 15:17:52 -05001840 yystos[*yyssp], yyvsp, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001841 YYPOPSTACK (1);
1842 }
1843#ifndef yyoverflow
1844 if (yyss != yyssa)
1845 YYSTACK_FREE (yyss);
1846#endif
1847#if YYERROR_VERBOSE
1848 if (yymsg != yymsgbuf)
1849 YYSTACK_FREE (yymsg);
1850#endif
Jamie Madill185de882014-12-22 15:17:52 -05001851 return yyresult;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001852}
1853
1854
1855
Zhenyao Mod526f982014-05-13 14:51:19 -07001856int yylex(YYSTYPE *lvalp, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001857{
1858 int type = 0;
1859
Zhenyao Mod526f982014-05-13 14:51:19 -07001860 pp::Token *token = context->token;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001861 switch (token->type)
1862 {
Zhenyao Mod526f982014-05-13 14:51:19 -07001863 case pp::Token::CONST_INT: {
alokp@chromium.org2e818912012-06-29 21:26:03 +00001864 unsigned int val = 0;
1865 if (!token->uValue(&val))
1866 {
Shannon Woods7f2d7942013-11-19 15:07:58 -05001867 context->diagnostics->report(pp::Diagnostics::PP_INTEGER_OVERFLOW,
alokp@chromium.org2e818912012-06-29 21:26:03 +00001868 token->location, token->text);
1869 }
1870 *lvalp = static_cast<YYSTYPE>(val);
maxvujovic@gmail.come640ef82012-07-13 18:42:40 +00001871 type = TOK_CONST_INT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001872 break;
alokp@chromium.org2e818912012-06-29 21:26:03 +00001873 }
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001874 case pp::Token::IDENTIFIER:
1875 if (!context->isIgnoringErrors())
1876 {
1877 context->diagnostics->report(pp::Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
1878 token->location, token->text);
1879 }
1880 *lvalp = static_cast<YYSTYPE>(-1);
1881 type = TOK_IDENTIFIER;
1882 break;
Zhenyao Mod526f982014-05-13 14:51:19 -07001883 case pp::Token::OP_OR:
1884 type = TOK_OP_OR;
1885 break;
1886 case pp::Token::OP_AND:
1887 type = TOK_OP_AND;
1888 break;
1889 case pp::Token::OP_NE:
1890 type = TOK_OP_NE;
1891 break;
1892 case pp::Token::OP_EQ:
1893 type = TOK_OP_EQ;
1894 break;
1895 case pp::Token::OP_GE:
1896 type = TOK_OP_GE;
1897 break;
1898 case pp::Token::OP_LE:
1899 type = TOK_OP_LE;
1900 break;
1901 case pp::Token::OP_RIGHT:
1902 type = TOK_OP_RIGHT;
1903 break;
1904 case pp::Token::OP_LEFT:
1905 type = TOK_OP_LEFT;
1906 break;
1907 case '|':
1908 case '^':
1909 case '&':
1910 case '>':
1911 case '<':
1912 case '-':
1913 case '+':
1914 case '%':
1915 case '/':
1916 case '*':
1917 case '!':
1918 case '~':
1919 case '(':
1920 case ')':
1921 type = token->type;
1922 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001923
Zhenyao Mod526f982014-05-13 14:51:19 -07001924 default:
1925 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001926 }
1927
1928 // Advance to the next token if the current one is valid.
Zhenyao Mod526f982014-05-13 14:51:19 -07001929 if (type != 0)
1930 context->lexer->lex(token);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001931
1932 return type;
1933}
1934
Zhenyao Mod526f982014-05-13 14:51:19 -07001935void yyerror(Context *context, const char *reason)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001936{
Shannon Woods7f2d7942013-11-19 15:07:58 -05001937 context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION,
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001938 context->token->location,
1939 reason);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001940}
1941
1942namespace pp {
1943
Zhenyao Mod526f982014-05-13 14:51:19 -07001944ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
1945 : mLexer(lexer),
1946 mDiagnostics(diagnostics)
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001947{
1948}
1949
Zhenyao Mod526f982014-05-13 14:51:19 -07001950bool ExpressionParser::parse(Token *token, int *result)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001951{
1952 Context context;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001953 context.diagnostics = mDiagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001954 context.lexer = mLexer;
1955 context.token = token;
1956 context.result = result;
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001957 context.ignoreErrors = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001958 int ret = yyparse(&context);
1959 switch (ret)
1960 {
1961 case 0:
1962 case 1:
1963 break;
1964
1965 case 2:
Shannon Woods7f2d7942013-11-19 15:07:58 -05001966 mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001967 break;
1968
1969 default:
1970 assert(false);
Shannon Woods7f2d7942013-11-19 15:07:58 -05001971 mDiagnostics->report(Diagnostics::PP_INTERNAL_ERROR, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001972 break;
1973 }
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001974
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001975 return ret == 0;
1976}
1977
1978} // namespace pp