blob: 27dc626fd2a5463d2641f59ba608abc6073905a3 [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 Etuaho809ec542015-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 Etuaho809ec542015-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 Etuaho809ec542015-08-26 14:30:57 +0300440#define YYFINAL 15
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000441/* YYLAST -- Last index in YYTABLE. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300442#define YYLAST 176
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000443
444/* YYNTOKENS -- Number of terminals. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300445#define YYNTOKENS 28
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000446/* YYNNTS -- Number of nonterminals. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300447#define YYNNTS 5
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000448/* YYNRULES -- Number of rules. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300449#define YYNRULES 29
Jamie Madill185de882014-12-22 15:17:52 -0500450/* YYNSTATES -- Number of states. */
Olli Etuaho809ec542015-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 Etuaho809ec542015-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 Etuaho809ec542015-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 Etuaho809ec542015-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 Etuaho809ec542015-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 Etuaho809ec542015-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 Etuaho809ec542015-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 Etuaho809ec542015-08-26 14:30:57 +0300496static const yytype_uint16 yyrline[] =
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000497{
Olli Etuaho809ec542015-08-26 14:30:57 +0300498 0, 105, 105, 111, 112, 118, 118, 139, 139, 160,
499 163, 166, 169, 172, 175, 178, 181, 184, 187, 190,
500 193, 196, 199, 222, 245, 248, 251, 254, 257, 260
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 Etuaho809ec542015-08-26 14:30:57 +0300509 "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_IDENTIFIER",
510 "TOK_OP_OR", "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_EQ", "TOK_OP_NE",
511 "'<'", "'>'", "TOK_OP_LE", "TOK_OP_GE", "TOK_OP_LEFT", "TOK_OP_RIGHT",
512 "'+'", "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('",
513 "')'", "$accept", "input", "expression", "$@1", "$@2", YY_NULLPTR
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000514};
515#endif
516
517# ifdef YYPRINT
Jamie Madill185de882014-12-22 15:17:52 -0500518/* YYTOKNUM[NUM] -- (External) token number corresponding to the
519 (internal) symbol number NUM (which must be that of a token). */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000520static const yytype_uint16 yytoknum[] =
521{
Olli Etuaho809ec542015-08-26 14:30:57 +0300522 0, 256, 257, 258, 259, 260, 261, 124, 94, 38,
523 262, 263, 60, 62, 264, 265, 266, 267, 43, 45,
524 42, 47, 37, 268, 33, 126, 40, 41
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000525};
526# endif
527
Olli Etuaho809ec542015-08-26 14:30:57 +0300528#define YYPACT_NINF -12
Jamie Madill185de882014-12-22 15:17:52 -0500529
530#define yypact_value_is_default(Yystate) \
Olli Etuaho809ec542015-08-26 14:30:57 +0300531 (!!((Yystate) == (-12)))
Jamie Madill185de882014-12-22 15:17:52 -0500532
533#define YYTABLE_NINF -1
534
535#define yytable_value_is_error(Yytable_value) \
536 0
537
538 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
539 STATE-NUM. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000540static const yytype_int16 yypact[] =
541{
Olli Etuaho809ec542015-08-26 14:30:57 +0300542 31, -12, -12, 31, 31, 31, 31, 31, 51, 76,
543 -12, -12, -12, -12, 53, -12, -12, -12, 31, 31,
544 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
545 31, 31, 31, 31, -12, 31, 31, 124, 138, 26,
546 149, 149, -11, -11, -11, -11, 154, 154, -8, -8,
547 -12, -12, -12, 93, 109
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000548};
549
Jamie Madill185de882014-12-22 15:17:52 -0500550 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
551 Performed when YYTABLE does not specify something else to do. Zero
552 means the default is an error. */
553static const yytype_uint8 yydefact[] =
554{
Olli Etuaho809ec542015-08-26 14:30:57 +0300555 0, 3, 4, 0, 0, 0, 0, 0, 0, 2,
556 28, 27, 25, 26, 0, 1, 5, 7, 0, 0,
Jamie Madill185de882014-12-22 15:17:52 -0500557 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Olli Etuaho809ec542015-08-26 14:30:57 +0300558 0, 0, 0, 0, 29, 0, 0, 9, 10, 11,
559 13, 12, 17, 16, 15, 14, 19, 18, 21, 20,
560 24, 23, 22, 6, 8
Jamie Madill185de882014-12-22 15:17:52 -0500561};
562
563 /* YYPGOTO[NTERM-NUM]. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000564static const yytype_int8 yypgoto[] =
565{
Olli Etuaho809ec542015-08-26 14:30:57 +0300566 -12, -12, -3, -12, -12
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000567};
568
Jamie Madill185de882014-12-22 15:17:52 -0500569 /* YYDEFGOTO[NTERM-NUM]. */
570static const yytype_int8 yydefgoto[] =
571{
Olli Etuaho809ec542015-08-26 14:30:57 +0300572 -1, 8, 9, 35, 36
Jamie Madill185de882014-12-22 15:17:52 -0500573};
574
575 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
576 positive, shift that token. If negative, reduce the rule whose
577 number is the opposite. If YYTABLE_NINF, syntax error. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000578static const yytype_uint8 yytable[] =
579{
Olli Etuaho809ec542015-08-26 14:30:57 +0300580 10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
581 32, 33, 31, 32, 33, 37, 38, 39, 40, 41,
582 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
583 52, 0, 53, 54, 1, 2, 21, 22, 23, 24,
584 25, 26, 27, 28, 29, 30, 31, 32, 33, 3,
585 4, 15, 0, 0, 0, 5, 6, 7, 16, 17,
586 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
587 28, 29, 30, 31, 32, 33, 0, 0, 0, 0,
588 34, 16, 17, 18, 19, 20, 21, 22, 23, 24,
589 25, 26, 27, 28, 29, 30, 31, 32, 33, 17,
590 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
591 28, 29, 30, 31, 32, 33, 18, 19, 20, 21,
592 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
593 32, 33, 19, 20, 21, 22, 23, 24, 25, 26,
594 27, 28, 29, 30, 31, 32, 33, 20, 21, 22,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000595 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
Olli Etuaho809ec542015-08-26 14:30:57 +0300596 33, 23, 24, 25, 26, 27, 28, 29, 30, 31,
597 32, 33, 29, 30, 31, 32, 33
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000598};
599
600static const yytype_int8 yycheck[] =
601{
Olli Etuaho809ec542015-08-26 14:30:57 +0300602 3, 4, 5, 6, 7, 16, 17, 18, 19, 20,
603 21, 22, 20, 21, 22, 18, 19, 20, 21, 22,
604 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
605 33, -1, 35, 36, 3, 4, 10, 11, 12, 13,
606 14, 15, 16, 17, 18, 19, 20, 21, 22, 18,
607 19, 0, -1, -1, -1, 24, 25, 26, 5, 6,
608 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
609 17, 18, 19, 20, 21, 22, -1, -1, -1, -1,
610 27, 5, 6, 7, 8, 9, 10, 11, 12, 13,
611 14, 15, 16, 17, 18, 19, 20, 21, 22, 6,
612 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
613 17, 18, 19, 20, 21, 22, 7, 8, 9, 10,
614 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
615 21, 22, 8, 9, 10, 11, 12, 13, 14, 15,
616 16, 17, 18, 19, 20, 21, 22, 9, 10, 11,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000617 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
Olli Etuaho809ec542015-08-26 14:30:57 +0300618 22, 12, 13, 14, 15, 16, 17, 18, 19, 20,
619 21, 22, 18, 19, 20, 21, 22
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000620};
621
Jamie Madill185de882014-12-22 15:17:52 -0500622 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
623 symbol of state STATE-NUM. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000624static const yytype_uint8 yystos[] =
625{
Olli Etuaho809ec542015-08-26 14:30:57 +0300626 0, 3, 4, 18, 19, 24, 25, 26, 29, 30,
627 30, 30, 30, 30, 30, 0, 5, 6, 7, 8,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000628 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
Olli Etuaho809ec542015-08-26 14:30:57 +0300629 19, 20, 21, 22, 27, 31, 32, 30, 30, 30,
630 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
631 30, 30, 30, 30, 30
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000632};
633
Jamie Madill185de882014-12-22 15:17:52 -0500634 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
635static const yytype_uint8 yyr1[] =
636{
Olli Etuaho809ec542015-08-26 14:30:57 +0300637 0, 28, 29, 30, 30, 31, 30, 32, 30, 30,
638 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
639 30, 30, 30, 30, 30, 30, 30, 30, 30, 30
Jamie Madill185de882014-12-22 15:17:52 -0500640};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000641
Jamie Madill185de882014-12-22 15:17:52 -0500642 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
643static const yytype_uint8 yyr2[] =
644{
Olli Etuaho809ec542015-08-26 14:30:57 +0300645 0, 2, 1, 1, 1, 0, 4, 0, 4, 3,
Jamie Madill185de882014-12-22 15:17:52 -0500646 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
Olli Etuaho809ec542015-08-26 14:30:57 +0300647 3, 3, 3, 3, 3, 2, 2, 2, 2, 3
Jamie Madill185de882014-12-22 15:17:52 -0500648};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000649
650
Jamie Madill185de882014-12-22 15:17:52 -0500651#define yyerrok (yyerrstatus = 0)
652#define yyclearin (yychar = YYEMPTY)
653#define YYEMPTY (-2)
654#define YYEOF 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000655
Jamie Madill185de882014-12-22 15:17:52 -0500656#define YYACCEPT goto yyacceptlab
657#define YYABORT goto yyabortlab
658#define YYERROR goto yyerrorlab
659
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000660
661#define YYRECOVERING() (!!yyerrstatus)
662
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000663#define YYBACKUP(Token, Value) \
664do \
665 if (yychar == YYEMPTY) \
666 { \
667 yychar = (Token); \
668 yylval = (Value); \
669 YYPOPSTACK (yylen); \
670 yystate = *yyssp; \
671 goto yybackup; \
672 } \
673 else \
674 { \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000675 yyerror (context, YY_("syntax error: cannot back up")); \
Jamie Madill185de882014-12-22 15:17:52 -0500676 YYERROR; \
677 } \
678while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000679
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000680/* Error token number */
Jamie Madill185de882014-12-22 15:17:52 -0500681#define YYTERROR 1
682#define YYERRCODE 256
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000683
684
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000685
686/* Enable debugging if requested. */
687#if YYDEBUG
688
689# ifndef YYFPRINTF
690# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
691# define YYFPRINTF fprintf
692# endif
693
Jamie Madill185de882014-12-22 15:17:52 -0500694# define YYDPRINTF(Args) \
695do { \
696 if (yydebug) \
697 YYFPRINTF Args; \
698} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000699
Jamie Madill185de882014-12-22 15:17:52 -0500700/* This macro is provided for backward compatibility. */
701#ifndef YY_LOCATION_PRINT
702# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
703#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000704
705
Jamie Madill185de882014-12-22 15:17:52 -0500706# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
707do { \
708 if (yydebug) \
709 { \
710 YYFPRINTF (stderr, "%s ", Title); \
711 yy_symbol_print (stderr, \
712 Type, Value, context); \
713 YYFPRINTF (stderr, "\n"); \
714 } \
715} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000716
Jamie Madill185de882014-12-22 15:17:52 -0500717
718/*----------------------------------------.
719| Print this symbol's value on YYOUTPUT. |
720`----------------------------------------*/
721
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000722static void
723yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000724{
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000725 FILE *yyo = yyoutput;
726 YYUSE (yyo);
Jamie Madill185de882014-12-22 15:17:52 -0500727 YYUSE (context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000728 if (!yyvaluep)
729 return;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000730# ifdef YYPRINT
731 if (yytype < YYNTOKENS)
732 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000733# endif
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400734 YYUSE (yytype);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000735}
736
737
738/*--------------------------------.
739| Print this symbol on YYOUTPUT. |
740`--------------------------------*/
741
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000742static void
743yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000744{
Jamie Madill185de882014-12-22 15:17:52 -0500745 YYFPRINTF (yyoutput, "%s %s (",
746 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000747
748 yy_symbol_value_print (yyoutput, yytype, yyvaluep, context);
749 YYFPRINTF (yyoutput, ")");
750}
751
752/*------------------------------------------------------------------.
753| yy_stack_print -- Print the state stack from its BOTTOM up to its |
754| TOP (included). |
755`------------------------------------------------------------------*/
756
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000757static void
758yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000759{
760 YYFPRINTF (stderr, "Stack now");
761 for (; yybottom <= yytop; yybottom++)
762 {
763 int yybot = *yybottom;
764 YYFPRINTF (stderr, " %d", yybot);
765 }
766 YYFPRINTF (stderr, "\n");
767}
768
Jamie Madill185de882014-12-22 15:17:52 -0500769# define YY_STACK_PRINT(Bottom, Top) \
770do { \
771 if (yydebug) \
772 yy_stack_print ((Bottom), (Top)); \
773} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000774
775
776/*------------------------------------------------.
777| Report that the YYRULE is going to be reduced. |
778`------------------------------------------------*/
779
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000780static void
Jamie Madill185de882014-12-22 15:17:52 -0500781yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000782{
Jamie Madill185de882014-12-22 15:17:52 -0500783 unsigned long int yylno = yyrline[yyrule];
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000784 int yynrhs = yyr2[yyrule];
785 int yyi;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000786 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
Jamie Madill185de882014-12-22 15:17:52 -0500787 yyrule - 1, yylno);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000788 /* The symbols being reduced. */
789 for (yyi = 0; yyi < yynrhs; yyi++)
790 {
791 YYFPRINTF (stderr, " $%d = ", yyi + 1);
Jamie Madill185de882014-12-22 15:17:52 -0500792 yy_symbol_print (stderr,
793 yystos[yyssp[yyi + 1 - yynrhs]],
794 &(yyvsp[(yyi + 1) - (yynrhs)])
795 , context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000796 YYFPRINTF (stderr, "\n");
797 }
798}
799
Jamie Madill185de882014-12-22 15:17:52 -0500800# define YY_REDUCE_PRINT(Rule) \
801do { \
802 if (yydebug) \
803 yy_reduce_print (yyssp, yyvsp, Rule, context); \
804} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000805
806/* Nonzero means print parse trace. It is left uninitialized so that
807 multiple parsers can coexist. */
808int yydebug;
809#else /* !YYDEBUG */
810# define YYDPRINTF(Args)
811# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
812# define YY_STACK_PRINT(Bottom, Top)
813# define YY_REDUCE_PRINT(Rule)
814#endif /* !YYDEBUG */
815
816
817/* YYINITDEPTH -- initial size of the parser's stacks. */
Jamie Madill185de882014-12-22 15:17:52 -0500818#ifndef YYINITDEPTH
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000819# define YYINITDEPTH 200
820#endif
821
822/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
823 if the built-in stack extension method is used).
824
825 Do not make this value too large; the results are undefined if
826 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
827 evaluated with infinite-precision integer arithmetic. */
828
829#ifndef YYMAXDEPTH
830# define YYMAXDEPTH 10000
831#endif
832
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000833
834#if YYERROR_VERBOSE
835
836# ifndef yystrlen
837# if defined __GLIBC__ && defined _STRING_H
838# define yystrlen strlen
839# else
840/* Return the length of YYSTR. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000841static YYSIZE_T
842yystrlen (const char *yystr)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000843{
844 YYSIZE_T yylen;
845 for (yylen = 0; yystr[yylen]; yylen++)
846 continue;
847 return yylen;
848}
849# endif
850# endif
851
852# ifndef yystpcpy
853# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
854# define yystpcpy stpcpy
855# else
856/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
857 YYDEST. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000858static char *
859yystpcpy (char *yydest, const char *yysrc)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000860{
861 char *yyd = yydest;
862 const char *yys = yysrc;
863
864 while ((*yyd++ = *yys++) != '\0')
865 continue;
866
867 return yyd - 1;
868}
869# endif
870# endif
871
872# ifndef yytnamerr
873/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
874 quotes and backslashes, so that it's suitable for yyerror. The
875 heuristic is that double-quoting is unnecessary unless the string
876 contains an apostrophe, a comma, or backslash (other than
877 backslash-backslash). YYSTR is taken from yytname. If YYRES is
878 null, do not copy; instead, return the length of what the result
879 would have been. */
880static YYSIZE_T
881yytnamerr (char *yyres, const char *yystr)
882{
883 if (*yystr == '"')
884 {
885 YYSIZE_T yyn = 0;
886 char const *yyp = yystr;
887
888 for (;;)
Jamie Madill185de882014-12-22 15:17:52 -0500889 switch (*++yyp)
890 {
891 case '\'':
892 case ',':
893 goto do_not_strip_quotes;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000894
Jamie Madill185de882014-12-22 15:17:52 -0500895 case '\\':
896 if (*++yyp != '\\')
897 goto do_not_strip_quotes;
898 /* Fall through. */
899 default:
900 if (yyres)
901 yyres[yyn] = *yyp;
902 yyn++;
903 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000904
Jamie Madill185de882014-12-22 15:17:52 -0500905 case '"':
906 if (yyres)
907 yyres[yyn] = '\0';
908 return yyn;
909 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000910 do_not_strip_quotes: ;
911 }
912
913 if (! yyres)
914 return yystrlen (yystr);
915
916 return yystpcpy (yyres, yystr) - yyres;
917}
918# endif
919
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000920/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
921 about the unexpected token YYTOKEN for the state stack whose top is
922 YYSSP.
923
924 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
925 not large enough to hold the message. In that case, also set
926 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
927 required number of bytes is too large to store. */
928static int
929yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
930 yytype_int16 *yyssp, int yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000931{
Jamie Madill185de882014-12-22 15:17:52 -0500932 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000933 YYSIZE_T yysize = yysize0;
934 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
935 /* Internationalized format string. */
Jamie Madill185de882014-12-22 15:17:52 -0500936 const char *yyformat = YY_NULLPTR;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000937 /* Arguments of yyformat. */
938 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
939 /* Number of reported tokens (one for the "unexpected", one per
940 "expected"). */
941 int yycount = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000942
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000943 /* There are many possibilities here to consider:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000944 - If this state is a consistent state with a default action, then
945 the only way this function was invoked is if the default action
946 is an error action. In that case, don't check for expected
947 tokens because there are none.
948 - The only way there can be no lookahead present (in yychar) is if
949 this state is a consistent state with a default action. Thus,
950 detecting the absence of a lookahead is sufficient to determine
951 that there is no unexpected or expected token to report. In that
952 case, just report a simple "syntax error".
953 - Don't assume there isn't a lookahead just because this state is a
954 consistent state with a default action. There might have been a
955 previous inconsistent state, consistent state with a non-default
956 action, or user semantic action that manipulated yychar.
957 - Of course, the expected token list depends on states to have
958 correct lookahead information, and it depends on the parser not
959 to perform extra reductions after fetching a lookahead from the
960 scanner and before detecting a syntax error. Thus, state merging
961 (from LALR or IELR) and default reductions corrupt the expected
962 token list. However, the list is correct for canonical LR with
963 one exception: it will still contain any token that will not be
964 accepted due to an error action in a later state.
965 */
966 if (yytoken != YYEMPTY)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000967 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000968 int yyn = yypact[*yyssp];
969 yyarg[yycount++] = yytname[yytoken];
970 if (!yypact_value_is_default (yyn))
971 {
972 /* Start YYX at -YYN if negative to avoid negative indexes in
973 YYCHECK. In other words, skip the first -YYN actions for
974 this state because they are default actions. */
975 int yyxbegin = yyn < 0 ? -yyn : 0;
976 /* Stay within bounds of both yycheck and yytname. */
977 int yychecklim = YYLAST - yyn + 1;
978 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
979 int yyx;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000980
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000981 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
982 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
983 && !yytable_value_is_error (yytable[yyx + yyn]))
984 {
985 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
986 {
987 yycount = 1;
988 yysize = yysize0;
989 break;
990 }
991 yyarg[yycount++] = yytname[yyx];
992 {
Jamie Madill185de882014-12-22 15:17:52 -0500993 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000994 if (! (yysize <= yysize1
995 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
996 return 2;
997 yysize = yysize1;
998 }
999 }
1000 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001001 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001002
1003 switch (yycount)
1004 {
1005# define YYCASE_(N, S) \
1006 case N: \
1007 yyformat = S; \
1008 break
1009 YYCASE_(0, YY_("syntax error"));
1010 YYCASE_(1, YY_("syntax error, unexpected %s"));
1011 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1012 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1013 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1014 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1015# undef YYCASE_
1016 }
1017
1018 {
1019 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1020 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1021 return 2;
1022 yysize = yysize1;
1023 }
1024
1025 if (*yymsg_alloc < yysize)
1026 {
1027 *yymsg_alloc = 2 * yysize;
1028 if (! (yysize <= *yymsg_alloc
1029 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1030 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1031 return 1;
1032 }
1033
1034 /* Avoid sprintf, as that infringes on the user's name space.
1035 Don't have undefined behavior even if the translation
1036 produced a string with the wrong number of "%s"s. */
1037 {
1038 char *yyp = *yymsg;
1039 int yyi = 0;
1040 while ((*yyp = *yyformat) != '\0')
1041 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1042 {
1043 yyp += yytnamerr (yyp, yyarg[yyi++]);
1044 yyformat += 2;
1045 }
1046 else
1047 {
1048 yyp++;
1049 yyformat++;
1050 }
1051 }
1052 return 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001053}
1054#endif /* YYERROR_VERBOSE */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001055
1056/*-----------------------------------------------.
1057| Release the memory associated to this symbol. |
1058`-----------------------------------------------*/
1059
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001060static void
1061yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001062{
1063 YYUSE (yyvaluep);
1064 YYUSE (context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001065 if (!yymsg)
1066 yymsg = "Deleting";
1067 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1068
Jamie Madill185de882014-12-22 15:17:52 -05001069 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Zhenyao Mof1d723c2013-09-23 14:57:07 -04001070 YYUSE (yytype);
Jamie Madill185de882014-12-22 15:17:52 -05001071 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001072}
1073
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001074
1075
1076
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001077/*----------.
1078| yyparse. |
1079`----------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001080
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001081int
1082yyparse (Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001083{
1084/* The lookahead symbol. */
1085int yychar;
1086
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001087
Jamie Madill185de882014-12-22 15:17:52 -05001088/* The semantic value of the lookahead symbol. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001089/* Default value used for initialization, for pacifying older GCCs
1090 or non-GCC compilers. */
Jamie Madill185de882014-12-22 15:17:52 -05001091YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1092YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001093
1094 /* Number of syntax errors so far. */
1095 int yynerrs;
1096
1097 int yystate;
1098 /* Number of tokens to shift before error messages enabled. */
1099 int yyerrstatus;
1100
1101 /* The stacks and their tools:
Jamie Madill185de882014-12-22 15:17:52 -05001102 'yyss': related to states.
1103 'yyvs': related to semantic values.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001104
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001105 Refer to the stacks through separate pointers, to allow yyoverflow
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001106 to reallocate them elsewhere. */
1107
1108 /* The state stack. */
1109 yytype_int16 yyssa[YYINITDEPTH];
1110 yytype_int16 *yyss;
1111 yytype_int16 *yyssp;
1112
1113 /* The semantic value stack. */
1114 YYSTYPE yyvsa[YYINITDEPTH];
1115 YYSTYPE *yyvs;
1116 YYSTYPE *yyvsp;
1117
1118 YYSIZE_T yystacksize;
1119
1120 int yyn;
1121 int yyresult;
1122 /* Lookahead token as an internal (translated) token number. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001123 int yytoken = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001124 /* The variables used to return semantic value and location from the
1125 action routines. */
1126 YYSTYPE yyval;
1127
1128#if YYERROR_VERBOSE
1129 /* Buffer for error messages, and its allocated size. */
1130 char yymsgbuf[128];
1131 char *yymsg = yymsgbuf;
1132 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1133#endif
1134
1135#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1136
1137 /* The number of symbols on the RHS of the reduced rule.
1138 Keep to zero when no symbol should be popped. */
1139 int yylen = 0;
1140
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001141 yyssp = yyss = yyssa;
1142 yyvsp = yyvs = yyvsa;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001143 yystacksize = YYINITDEPTH;
1144
1145 YYDPRINTF ((stderr, "Starting parse\n"));
1146
1147 yystate = 0;
1148 yyerrstatus = 0;
1149 yynerrs = 0;
1150 yychar = YYEMPTY; /* Cause a token to be read. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001151 goto yysetstate;
1152
1153/*------------------------------------------------------------.
1154| yynewstate -- Push a new state, which is found in yystate. |
1155`------------------------------------------------------------*/
1156 yynewstate:
1157 /* In all cases, when you get here, the value and location stacks
1158 have just been pushed. So pushing a state here evens the stacks. */
1159 yyssp++;
1160
1161 yysetstate:
1162 *yyssp = yystate;
1163
1164 if (yyss + yystacksize - 1 <= yyssp)
1165 {
1166 /* Get the current used size of the three stacks, in elements. */
1167 YYSIZE_T yysize = yyssp - yyss + 1;
1168
1169#ifdef yyoverflow
1170 {
Jamie Madill185de882014-12-22 15:17:52 -05001171 /* Give user a chance to reallocate the stack. Use copies of
1172 these so that the &'s don't force the real ones into
1173 memory. */
1174 YYSTYPE *yyvs1 = yyvs;
1175 yytype_int16 *yyss1 = yyss;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001176
Jamie Madill185de882014-12-22 15:17:52 -05001177 /* Each stack pointer address is followed by the size of the
1178 data in use in that stack, in bytes. This used to be a
1179 conditional around just the two extra args, but that might
1180 be undefined if yyoverflow is a macro. */
1181 yyoverflow (YY_("memory exhausted"),
1182 &yyss1, yysize * sizeof (*yyssp),
1183 &yyvs1, yysize * sizeof (*yyvsp),
1184 &yystacksize);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001185
Jamie Madill185de882014-12-22 15:17:52 -05001186 yyss = yyss1;
1187 yyvs = yyvs1;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001188 }
1189#else /* no yyoverflow */
1190# ifndef YYSTACK_RELOCATE
1191 goto yyexhaustedlab;
1192# else
1193 /* Extend the stack our own way. */
1194 if (YYMAXDEPTH <= yystacksize)
Jamie Madill185de882014-12-22 15:17:52 -05001195 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001196 yystacksize *= 2;
1197 if (YYMAXDEPTH < yystacksize)
Jamie Madill185de882014-12-22 15:17:52 -05001198 yystacksize = YYMAXDEPTH;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001199
1200 {
Jamie Madill185de882014-12-22 15:17:52 -05001201 yytype_int16 *yyss1 = yyss;
1202 union yyalloc *yyptr =
1203 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1204 if (! yyptr)
1205 goto yyexhaustedlab;
1206 YYSTACK_RELOCATE (yyss_alloc, yyss);
1207 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001208# undef YYSTACK_RELOCATE
Jamie Madill185de882014-12-22 15:17:52 -05001209 if (yyss1 != yyssa)
1210 YYSTACK_FREE (yyss1);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001211 }
1212# endif
1213#endif /* no yyoverflow */
1214
1215 yyssp = yyss + yysize - 1;
1216 yyvsp = yyvs + yysize - 1;
1217
1218 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
Jamie Madill185de882014-12-22 15:17:52 -05001219 (unsigned long int) yystacksize));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001220
1221 if (yyss + yystacksize - 1 <= yyssp)
Jamie Madill185de882014-12-22 15:17:52 -05001222 YYABORT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001223 }
1224
1225 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1226
1227 if (yystate == YYFINAL)
1228 YYACCEPT;
1229
1230 goto yybackup;
1231
1232/*-----------.
1233| yybackup. |
1234`-----------*/
1235yybackup:
1236
1237 /* Do appropriate processing given the current state. Read a
1238 lookahead token if we need one and don't already have one. */
1239
1240 /* First try to decide what to do without reference to lookahead token. */
1241 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001242 if (yypact_value_is_default (yyn))
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001243 goto yydefault;
1244
1245 /* Not known => get a lookahead token if don't already have one. */
1246
1247 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1248 if (yychar == YYEMPTY)
1249 {
1250 YYDPRINTF ((stderr, "Reading a token: "));
Jamie Madill185de882014-12-22 15:17:52 -05001251 yychar = yylex (&yylval, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001252 }
1253
1254 if (yychar <= YYEOF)
1255 {
1256 yychar = yytoken = YYEOF;
1257 YYDPRINTF ((stderr, "Now at end of input.\n"));
1258 }
1259 else
1260 {
1261 yytoken = YYTRANSLATE (yychar);
1262 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1263 }
1264
1265 /* If the proper action on seeing token YYTOKEN is to reduce or to
1266 detect an error, take that action. */
1267 yyn += yytoken;
1268 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1269 goto yydefault;
1270 yyn = yytable[yyn];
1271 if (yyn <= 0)
1272 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001273 if (yytable_value_is_error (yyn))
1274 goto yyerrlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001275 yyn = -yyn;
1276 goto yyreduce;
1277 }
1278
1279 /* Count tokens shifted since error; after three, turn off error
1280 status. */
1281 if (yyerrstatus)
1282 yyerrstatus--;
1283
1284 /* Shift the lookahead token. */
1285 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1286
1287 /* Discard the shifted token. */
1288 yychar = YYEMPTY;
1289
1290 yystate = yyn;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001291 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001292 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001293 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001294
1295 goto yynewstate;
1296
1297
1298/*-----------------------------------------------------------.
1299| yydefault -- do the default action for the current state. |
1300`-----------------------------------------------------------*/
1301yydefault:
1302 yyn = yydefact[yystate];
1303 if (yyn == 0)
1304 goto yyerrlab;
1305 goto yyreduce;
1306
1307
1308/*-----------------------------.
1309| yyreduce -- Do a reduction. |
1310`-----------------------------*/
1311yyreduce:
1312 /* yyn is the number of a rule to reduce with. */
1313 yylen = yyr2[yyn];
1314
1315 /* If YYLEN is nonzero, implement the default value of the action:
Jamie Madill185de882014-12-22 15:17:52 -05001316 '$$ = $1'.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001317
1318 Otherwise, the following line sets YYVAL to garbage.
1319 This behavior is undocumented and Bison
1320 users should not rely upon it. Assigning to YYVAL
1321 unconditionally makes the parser a bit smaller, and it avoids a
1322 GCC warning that YYVAL may be used uninitialized. */
1323 yyval = yyvsp[1-yylen];
1324
1325
1326 YY_REDUCE_PRINT (yyn);
1327 switch (yyn)
1328 {
1329 case 2:
1330
1331 {
Jamie Madill185de882014-12-22 15:17:52 -05001332 *(context->result) = static_cast<int>((yyvsp[0]));
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 Etuaho809ec542015-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 Etuaho809ec542015-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 Etuaho809ec542015-08-26 14:30:57 +03001367 if ((yyvsp[-3]) != 0)
1368 {
1369 context->endIgnoreErrors();
1370 (yyval) = static_cast<YYSTYPE>(1);
1371 }
1372 else
1373 {
1374 (yyval) = (yyvsp[-3]) || (yyvsp[0]);
1375 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001376 }
Jamie Madill185de882014-12-22 15:17:52 -05001377
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001378 break;
1379
1380 case 7:
1381
1382 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001383 if ((yyvsp[-1]) == 0)
1384 {
1385 // Ignore errors in the short-circuited part of the expression.
1386 // ESSL3.00 section 3.4:
1387 // If an operand is not evaluated, the presence of undefined identifiers
1388 // in the operand will not cause an error.
1389 // Unevaluated division by zero should not cause an error either.
1390 context->startIgnoreErrors();
1391 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001392 }
Jamie Madill185de882014-12-22 15:17:52 -05001393
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001394 break;
1395
1396 case 8:
1397
1398 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001399 if ((yyvsp[-3]) == 0)
1400 {
1401 context->endIgnoreErrors();
1402 (yyval) = static_cast<YYSTYPE>(0);
1403 }
1404 else
1405 {
1406 (yyval) = (yyvsp[-3]) && (yyvsp[0]);
1407 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001408 }
Jamie Madill185de882014-12-22 15:17:52 -05001409
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001410 break;
1411
1412 case 9:
1413
1414 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001415 (yyval) = (yyvsp[-2]) | (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001416 }
Jamie Madill185de882014-12-22 15:17:52 -05001417
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001418 break;
1419
1420 case 10:
1421
1422 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001423 (yyval) = (yyvsp[-2]) ^ (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001424 }
Jamie Madill185de882014-12-22 15:17:52 -05001425
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001426 break;
1427
1428 case 11:
1429
1430 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001431 (yyval) = (yyvsp[-2]) & (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001432 }
Jamie Madill185de882014-12-22 15:17:52 -05001433
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001434 break;
1435
1436 case 12:
1437
1438 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001439 (yyval) = (yyvsp[-2]) != (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001440 }
Jamie Madill185de882014-12-22 15:17:52 -05001441
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001442 break;
1443
1444 case 13:
1445
1446 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001447 (yyval) = (yyvsp[-2]) == (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001448 }
Jamie Madill185de882014-12-22 15:17:52 -05001449
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001450 break;
1451
1452 case 14:
1453
1454 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001455 (yyval) = (yyvsp[-2]) >= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001456 }
Jamie Madill185de882014-12-22 15:17:52 -05001457
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001458 break;
1459
1460 case 15:
1461
1462 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001463 (yyval) = (yyvsp[-2]) <= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001464 }
Jamie Madill185de882014-12-22 15:17:52 -05001465
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001466 break;
1467
1468 case 16:
1469
1470 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001471 (yyval) = (yyvsp[-2]) > (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001472 }
Jamie Madill185de882014-12-22 15:17:52 -05001473
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001474 break;
1475
1476 case 17:
1477
1478 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001479 (yyval) = (yyvsp[-2]) < (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001480 }
Jamie Madill185de882014-12-22 15:17:52 -05001481
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001482 break;
1483
1484 case 18:
1485
1486 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001487 (yyval) = (yyvsp[-2]) >> (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001488 }
Jamie Madill185de882014-12-22 15:17:52 -05001489
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001490 break;
1491
1492 case 19:
1493
1494 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001495 (yyval) = (yyvsp[-2]) << (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001496 }
Jamie Madill185de882014-12-22 15:17:52 -05001497
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001498 break;
1499
1500 case 20:
1501
1502 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001503 (yyval) = (yyvsp[-2]) - (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001504 }
Jamie Madill185de882014-12-22 15:17:52 -05001505
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001506 break;
1507
1508 case 21:
1509
1510 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001511 (yyval) = (yyvsp[-2]) + (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001512 }
Jamie Madill185de882014-12-22 15:17:52 -05001513
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001514 break;
1515
1516 case 22:
1517
1518 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001519 if ((yyvsp[0]) == 0)
1520 {
1521 if (context->isIgnoringErrors())
1522 {
1523 (yyval) = static_cast<YYSTYPE>(0);
1524 }
1525 else
1526 {
1527 std::ostringstream stream;
1528 stream << (yyvsp[-2]) << " % " << (yyvsp[0]);
1529 std::string text = stream.str();
1530 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1531 context->token->location,
1532 text.c_str());
1533 YYABORT;
1534 }
1535 }
1536 else
1537 {
1538 (yyval) = (yyvsp[-2]) % (yyvsp[0]);
1539 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001540 }
Jamie Madill185de882014-12-22 15:17:52 -05001541
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001542 break;
1543
1544 case 23:
1545
1546 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001547 if ((yyvsp[0]) == 0)
1548 {
1549 if (context->isIgnoringErrors())
1550 {
1551 (yyval) = static_cast<YYSTYPE>(0);
1552 }
1553 else
1554 {
1555 std::ostringstream stream;
1556 stream << (yyvsp[-2]) << " / " << (yyvsp[0]);
1557 std::string text = stream.str();
1558 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1559 context->token->location,
1560 text.c_str());
1561 YYABORT;
1562 }
1563 }
1564 else
1565 {
1566 (yyval) = (yyvsp[-2]) / (yyvsp[0]);
1567 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001568 }
Jamie Madill185de882014-12-22 15:17:52 -05001569
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001570 break;
1571
1572 case 24:
1573
1574 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001575 (yyval) = (yyvsp[-2]) * (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001576 }
Jamie Madill185de882014-12-22 15:17:52 -05001577
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001578 break;
1579
1580 case 25:
1581
1582 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001583 (yyval) = ! (yyvsp[0]);
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001584 }
1585
1586 break;
1587
Jamie Madill9a1b49f2015-09-08 14:32:26 +00001588 case 26:
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001589
1590 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001591 (yyval) = ~ (yyvsp[0]);
1592 }
1593
1594 break;
1595
1596 case 27:
1597
1598 {
1599 (yyval) = - (yyvsp[0]);
1600 }
1601
1602 break;
1603
1604 case 28:
1605
1606 {
1607 (yyval) = + (yyvsp[0]);
1608 }
1609
1610 break;
1611
1612 case 29:
1613
1614 {
Jamie Madill185de882014-12-22 15:17:52 -05001615 (yyval) = (yyvsp[-1]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001616 }
Jamie Madill185de882014-12-22 15:17:52 -05001617
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001618 break;
1619
1620
1621
1622 default: break;
1623 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001624 /* User semantic actions sometimes alter yychar, and that requires
1625 that yytoken be updated with the new translation. We take the
1626 approach of translating immediately before every use of yytoken.
1627 One alternative is translating here after every semantic action,
1628 but that translation would be missed if the semantic action invokes
1629 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1630 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1631 incorrect destructor might then be invoked immediately. In the
1632 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1633 to an incorrect destructor call or verbose syntax error message
1634 before the lookahead is translated. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001635 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1636
1637 YYPOPSTACK (yylen);
1638 yylen = 0;
1639 YY_STACK_PRINT (yyss, yyssp);
1640
1641 *++yyvsp = yyval;
1642
Jamie Madill185de882014-12-22 15:17:52 -05001643 /* Now 'shift' the result of the reduction. Determine what state
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001644 that goes to, based on the state we popped back to and the rule
1645 number reduced by. */
1646
1647 yyn = yyr1[yyn];
1648
1649 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1650 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1651 yystate = yytable[yystate];
1652 else
1653 yystate = yydefgoto[yyn - YYNTOKENS];
1654
1655 goto yynewstate;
1656
1657
Jamie Madill185de882014-12-22 15:17:52 -05001658/*--------------------------------------.
1659| yyerrlab -- here on detecting error. |
1660`--------------------------------------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001661yyerrlab:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001662 /* Make sure we have latest lookahead translation. See comments at
1663 user semantic actions for why this is necessary. */
1664 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1665
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001666 /* If not already recovering from an error, report this error. */
1667 if (!yyerrstatus)
1668 {
1669 ++yynerrs;
1670#if ! YYERROR_VERBOSE
1671 yyerror (context, YY_("syntax error"));
1672#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001673# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1674 yyssp, yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001675 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001676 char const *yymsgp = YY_("syntax error");
1677 int yysyntax_error_status;
1678 yysyntax_error_status = YYSYNTAX_ERROR;
1679 if (yysyntax_error_status == 0)
1680 yymsgp = yymsg;
1681 else if (yysyntax_error_status == 1)
1682 {
1683 if (yymsg != yymsgbuf)
1684 YYSTACK_FREE (yymsg);
1685 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1686 if (!yymsg)
1687 {
1688 yymsg = yymsgbuf;
1689 yymsg_alloc = sizeof yymsgbuf;
1690 yysyntax_error_status = 2;
1691 }
1692 else
1693 {
1694 yysyntax_error_status = YYSYNTAX_ERROR;
1695 yymsgp = yymsg;
1696 }
1697 }
1698 yyerror (context, yymsgp);
1699 if (yysyntax_error_status == 2)
1700 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001701 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001702# undef YYSYNTAX_ERROR
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001703#endif
1704 }
1705
1706
1707
1708 if (yyerrstatus == 3)
1709 {
1710 /* If just tried and failed to reuse lookahead token after an
Jamie Madill185de882014-12-22 15:17:52 -05001711 error, discard it. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001712
1713 if (yychar <= YYEOF)
Jamie Madill185de882014-12-22 15:17:52 -05001714 {
1715 /* Return failure if at end of input. */
1716 if (yychar == YYEOF)
1717 YYABORT;
1718 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001719 else
Jamie Madill185de882014-12-22 15:17:52 -05001720 {
1721 yydestruct ("Error: discarding",
1722 yytoken, &yylval, context);
1723 yychar = YYEMPTY;
1724 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001725 }
1726
1727 /* Else will try to reuse lookahead token after shifting the error
1728 token. */
1729 goto yyerrlab1;
1730
1731
1732/*---------------------------------------------------.
1733| yyerrorlab -- error raised explicitly by YYERROR. |
1734`---------------------------------------------------*/
1735yyerrorlab:
1736
1737 /* Pacify compilers like GCC when the user code never invokes
1738 YYERROR and the label yyerrorlab therefore never appears in user
1739 code. */
1740 if (/*CONSTCOND*/ 0)
1741 goto yyerrorlab;
1742
Jamie Madill185de882014-12-22 15:17:52 -05001743 /* Do not reclaim the symbols of the rule whose action triggered
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001744 this YYERROR. */
1745 YYPOPSTACK (yylen);
1746 yylen = 0;
1747 YY_STACK_PRINT (yyss, yyssp);
1748 yystate = *yyssp;
1749 goto yyerrlab1;
1750
1751
1752/*-------------------------------------------------------------.
1753| yyerrlab1 -- common code for both syntax error and YYERROR. |
1754`-------------------------------------------------------------*/
1755yyerrlab1:
Jamie Madill185de882014-12-22 15:17:52 -05001756 yyerrstatus = 3; /* Each real token shifted decrements this. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001757
1758 for (;;)
1759 {
1760 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001761 if (!yypact_value_is_default (yyn))
Jamie Madill185de882014-12-22 15:17:52 -05001762 {
1763 yyn += YYTERROR;
1764 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1765 {
1766 yyn = yytable[yyn];
1767 if (0 < yyn)
1768 break;
1769 }
1770 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001771
1772 /* Pop the current state because it cannot handle the error token. */
1773 if (yyssp == yyss)
Jamie Madill185de882014-12-22 15:17:52 -05001774 YYABORT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001775
1776
1777 yydestruct ("Error: popping",
Jamie Madill185de882014-12-22 15:17:52 -05001778 yystos[yystate], yyvsp, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001779 YYPOPSTACK (1);
1780 yystate = *yyssp;
1781 YY_STACK_PRINT (yyss, yyssp);
1782 }
1783
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001784 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001785 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001786 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001787
1788
1789 /* Shift the error token. */
1790 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1791
1792 yystate = yyn;
1793 goto yynewstate;
1794
1795
1796/*-------------------------------------.
1797| yyacceptlab -- YYACCEPT comes here. |
1798`-------------------------------------*/
1799yyacceptlab:
1800 yyresult = 0;
1801 goto yyreturn;
1802
1803/*-----------------------------------.
1804| yyabortlab -- YYABORT comes here. |
1805`-----------------------------------*/
1806yyabortlab:
1807 yyresult = 1;
1808 goto yyreturn;
1809
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001810#if !defined yyoverflow || YYERROR_VERBOSE
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001811/*-------------------------------------------------.
1812| yyexhaustedlab -- memory exhaustion comes here. |
1813`-------------------------------------------------*/
1814yyexhaustedlab:
1815 yyerror (context, YY_("memory exhausted"));
1816 yyresult = 2;
1817 /* Fall through. */
1818#endif
1819
1820yyreturn:
1821 if (yychar != YYEMPTY)
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001822 {
1823 /* Make sure we have latest lookahead translation. See comments at
1824 user semantic actions for why this is necessary. */
1825 yytoken = YYTRANSLATE (yychar);
1826 yydestruct ("Cleanup: discarding lookahead",
1827 yytoken, &yylval, context);
1828 }
Jamie Madill185de882014-12-22 15:17:52 -05001829 /* Do not reclaim the symbols of the rule whose action triggered
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001830 this YYABORT or YYACCEPT. */
1831 YYPOPSTACK (yylen);
1832 YY_STACK_PRINT (yyss, yyssp);
1833 while (yyssp != yyss)
1834 {
1835 yydestruct ("Cleanup: popping",
Jamie Madill185de882014-12-22 15:17:52 -05001836 yystos[*yyssp], yyvsp, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001837 YYPOPSTACK (1);
1838 }
1839#ifndef yyoverflow
1840 if (yyss != yyssa)
1841 YYSTACK_FREE (yyss);
1842#endif
1843#if YYERROR_VERBOSE
1844 if (yymsg != yymsgbuf)
1845 YYSTACK_FREE (yymsg);
1846#endif
Jamie Madill185de882014-12-22 15:17:52 -05001847 return yyresult;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001848}
1849
1850
1851
Zhenyao Mod526f982014-05-13 14:51:19 -07001852int yylex(YYSTYPE *lvalp, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001853{
1854 int type = 0;
1855
Zhenyao Mod526f982014-05-13 14:51:19 -07001856 pp::Token *token = context->token;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001857 switch (token->type)
1858 {
Zhenyao Mod526f982014-05-13 14:51:19 -07001859 case pp::Token::CONST_INT: {
alokp@chromium.org2e818912012-06-29 21:26:03 +00001860 unsigned int val = 0;
1861 if (!token->uValue(&val))
1862 {
Shannon Woods7f2d7942013-11-19 15:07:58 -05001863 context->diagnostics->report(pp::Diagnostics::PP_INTEGER_OVERFLOW,
alokp@chromium.org2e818912012-06-29 21:26:03 +00001864 token->location, token->text);
1865 }
1866 *lvalp = static_cast<YYSTYPE>(val);
maxvujovic@gmail.come640ef82012-07-13 18:42:40 +00001867 type = TOK_CONST_INT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001868 break;
alokp@chromium.org2e818912012-06-29 21:26:03 +00001869 }
Olli Etuaho809ec542015-08-26 14:30:57 +03001870 case pp::Token::IDENTIFIER:
1871 if (!context->isIgnoringErrors())
1872 {
1873 context->diagnostics->report(pp::Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
1874 token->location, token->text);
1875 }
1876 *lvalp = static_cast<YYSTYPE>(-1);
1877 type = TOK_IDENTIFIER;
1878 break;
Zhenyao Mod526f982014-05-13 14:51:19 -07001879 case pp::Token::OP_OR:
1880 type = TOK_OP_OR;
1881 break;
1882 case pp::Token::OP_AND:
1883 type = TOK_OP_AND;
1884 break;
1885 case pp::Token::OP_NE:
1886 type = TOK_OP_NE;
1887 break;
1888 case pp::Token::OP_EQ:
1889 type = TOK_OP_EQ;
1890 break;
1891 case pp::Token::OP_GE:
1892 type = TOK_OP_GE;
1893 break;
1894 case pp::Token::OP_LE:
1895 type = TOK_OP_LE;
1896 break;
1897 case pp::Token::OP_RIGHT:
1898 type = TOK_OP_RIGHT;
1899 break;
1900 case pp::Token::OP_LEFT:
1901 type = TOK_OP_LEFT;
1902 break;
1903 case '|':
1904 case '^':
1905 case '&':
1906 case '>':
1907 case '<':
1908 case '-':
1909 case '+':
1910 case '%':
1911 case '/':
1912 case '*':
1913 case '!':
1914 case '~':
1915 case '(':
1916 case ')':
1917 type = token->type;
1918 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001919
Zhenyao Mod526f982014-05-13 14:51:19 -07001920 default:
1921 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001922 }
1923
1924 // Advance to the next token if the current one is valid.
Zhenyao Mod526f982014-05-13 14:51:19 -07001925 if (type != 0)
1926 context->lexer->lex(token);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001927
1928 return type;
1929}
1930
Zhenyao Mod526f982014-05-13 14:51:19 -07001931void yyerror(Context *context, const char *reason)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001932{
Shannon Woods7f2d7942013-11-19 15:07:58 -05001933 context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION,
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001934 context->token->location,
1935 reason);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001936}
1937
1938namespace pp {
1939
Zhenyao Mod526f982014-05-13 14:51:19 -07001940ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
1941 : mLexer(lexer),
1942 mDiagnostics(diagnostics)
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001943{
1944}
1945
Zhenyao Mod526f982014-05-13 14:51:19 -07001946bool ExpressionParser::parse(Token *token, int *result)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001947{
1948 Context context;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001949 context.diagnostics = mDiagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001950 context.lexer = mLexer;
1951 context.token = token;
1952 context.result = result;
Olli Etuaho809ec542015-08-26 14:30:57 +03001953 context.ignoreErrors = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001954 int ret = yyparse(&context);
1955 switch (ret)
1956 {
1957 case 0:
1958 case 1:
1959 break;
1960
1961 case 2:
Shannon Woods7f2d7942013-11-19 15:07:58 -05001962 mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001963 break;
1964
1965 default:
1966 assert(false);
Shannon Woods7f2d7942013-11-19 15:07:58 -05001967 mDiagnostics->report(Diagnostics::PP_INTERNAL_ERROR, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001968 break;
1969 }
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001970
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001971 return ret == 0;
1972}
1973
1974} // namespace pp