blob: 21064b75ffc39eab0919bb85cdee2d04d9fc25d4 [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
Olli Etuaho3187a382015-09-09 12:00:12 +0300113
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000114#define YYENABLE_NLS 0
115#define YYLTYPE_IS_TRIVIAL 1
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000116#define YYSTYPE_IS_TRIVIAL 1
117#define YYSTYPE_IS_DECLARED 1
118
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000119namespace {
120struct Context
121{
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000122 pp::Diagnostics* diagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000123 pp::Lexer* lexer;
124 pp::Token* token;
125 int* result;
Olli Etuaho809ec542015-08-26 14:30:57 +0300126
127 void startIgnoreErrors() { ++ignoreErrors; }
128 void endIgnoreErrors() { --ignoreErrors; }
129
130 bool isIgnoringErrors() { return ignoreErrors > 0; }
131
132 int ignoreErrors;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000133};
134} // namespace
135
136
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000137static int yylex(YYSTYPE* lvalp, Context* context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000138static void yyerror(Context* context, const char* reason);
139
140
141
Jamie Madill185de882014-12-22 15:17:52 -0500142# ifndef YY_NULLPTR
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000143# if defined __cplusplus && 201103L <= __cplusplus
Jamie Madill185de882014-12-22 15:17:52 -0500144# define YY_NULLPTR nullptr
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000145# else
Jamie Madill185de882014-12-22 15:17:52 -0500146# define YY_NULLPTR 0
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000147# endif
148# endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000149
150/* Enabling verbose error messages. */
151#ifdef YYERROR_VERBOSE
152# undef YYERROR_VERBOSE
153# define YYERROR_VERBOSE 1
154#else
155# define YYERROR_VERBOSE 0
156#endif
157
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000158
Jamie Madill185de882014-12-22 15:17:52 -0500159/* Debug traces. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000160#ifndef YYDEBUG
161# define YYDEBUG 0
162#endif
163#if YYDEBUG
164extern int ppdebug;
165#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000166
Jamie Madill185de882014-12-22 15:17:52 -0500167/* Token type. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000168#ifndef YYTOKENTYPE
169# define YYTOKENTYPE
Jamie Madill185de882014-12-22 15:17:52 -0500170 enum yytokentype
171 {
172 TOK_CONST_INT = 258,
Olli Etuaho809ec542015-08-26 14:30:57 +0300173 TOK_IDENTIFIER = 259,
174 TOK_OP_OR = 260,
175 TOK_OP_AND = 261,
176 TOK_OP_EQ = 262,
177 TOK_OP_NE = 263,
178 TOK_OP_LE = 264,
179 TOK_OP_GE = 265,
180 TOK_OP_LEFT = 266,
181 TOK_OP_RIGHT = 267,
182 TOK_UNARY = 268
Jamie Madill185de882014-12-22 15:17:52 -0500183 };
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000184#endif
185
Jamie Madill185de882014-12-22 15:17:52 -0500186/* Value type. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000187#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
188typedef int YYSTYPE;
189# define YYSTYPE_IS_TRIVIAL 1
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000190# define YYSTYPE_IS_DECLARED 1
191#endif
192
193
Jamie Madill185de882014-12-22 15:17:52 -0500194
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000195int ppparse (Context *context);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000196
197
198
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000199/* Copy the second part of user declarations. */
200
201
202
203#ifdef short
204# undef short
205#endif
206
207#ifdef YYTYPE_UINT8
208typedef YYTYPE_UINT8 yytype_uint8;
209#else
210typedef unsigned char yytype_uint8;
211#endif
212
213#ifdef YYTYPE_INT8
214typedef YYTYPE_INT8 yytype_int8;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000215#else
Jamie Madill185de882014-12-22 15:17:52 -0500216typedef signed char yytype_int8;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000217#endif
218
219#ifdef YYTYPE_UINT16
220typedef YYTYPE_UINT16 yytype_uint16;
221#else
222typedef unsigned short int yytype_uint16;
223#endif
224
225#ifdef YYTYPE_INT16
226typedef YYTYPE_INT16 yytype_int16;
227#else
228typedef short int yytype_int16;
229#endif
230
231#ifndef YYSIZE_T
232# ifdef __SIZE_TYPE__
233# define YYSIZE_T __SIZE_TYPE__
234# elif defined size_t
235# define YYSIZE_T size_t
Jamie Madill185de882014-12-22 15:17:52 -0500236# elif ! defined YYSIZE_T
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000237# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
238# define YYSIZE_T size_t
239# else
240# define YYSIZE_T unsigned int
241# endif
242#endif
243
244#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
245
246#ifndef YY_
247# if defined YYENABLE_NLS && YYENABLE_NLS
248# if ENABLE_NLS
249# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000250# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000251# endif
252# endif
253# ifndef YY_
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000254# define YY_(Msgid) Msgid
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000255# endif
256#endif
257
Jamie Madill185de882014-12-22 15:17:52 -0500258#ifndef YY_ATTRIBUTE
259# if (defined __GNUC__ \
260 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
261 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
262# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
263# else
264# define YY_ATTRIBUTE(Spec) /* empty */
265# endif
266#endif
267
268#ifndef YY_ATTRIBUTE_PURE
269# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
270#endif
271
272#ifndef YY_ATTRIBUTE_UNUSED
273# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
274#endif
275
276#if !defined _Noreturn \
277 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
278# if defined _MSC_VER && 1200 <= _MSC_VER
279# define _Noreturn __declspec (noreturn)
280# else
281# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400282# endif
283#endif
284
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000285/* Suppress unused-variable warnings by "using" E. */
286#if ! defined lint || defined __GNUC__
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000287# define YYUSE(E) ((void) (E))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000288#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000289# define YYUSE(E) /* empty */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000290#endif
291
Jamie Madill185de882014-12-22 15:17:52 -0500292#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
293/* Suppress an incorrect diagnostic about yylval being uninitialized. */
294# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
295 _Pragma ("GCC diagnostic push") \
296 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
297 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
298# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
299 _Pragma ("GCC diagnostic pop")
300#else
301# define YY_INITIAL_VALUE(Value) Value
302#endif
303#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
304# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
305# define YY_IGNORE_MAYBE_UNINITIALIZED_END
306#endif
307#ifndef YY_INITIAL_VALUE
308# define YY_INITIAL_VALUE(Value) /* Nothing. */
309#endif
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400310
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000311
312#if ! defined yyoverflow || YYERROR_VERBOSE
313
314/* The parser invokes alloca or malloc; define the necessary symbols. */
315
316# ifdef YYSTACK_USE_ALLOCA
317# if YYSTACK_USE_ALLOCA
318# ifdef __GNUC__
319# define YYSTACK_ALLOC __builtin_alloca
320# elif defined __BUILTIN_VA_ARG_INCR
321# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
322# elif defined _AIX
323# define YYSTACK_ALLOC __alloca
324# elif defined _MSC_VER
325# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
326# define alloca _alloca
327# else
328# define YYSTACK_ALLOC alloca
Jamie Madill185de882014-12-22 15:17:52 -0500329# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000330# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000331 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
332# ifndef EXIT_SUCCESS
333# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000334# endif
335# endif
336# endif
337# endif
338# endif
339
340# ifdef YYSTACK_ALLOC
Jamie Madill185de882014-12-22 15:17:52 -0500341 /* Pacify GCC's 'empty if-body' warning. */
342# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000343# ifndef YYSTACK_ALLOC_MAXIMUM
344 /* The OS might guarantee only one guard page at the bottom of the stack,
345 and a page size can be as small as 4096 bytes. So we cannot safely
346 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
347 to allow for a few compiler-allocated temporary stack slots. */
348# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
349# endif
350# else
351# define YYSTACK_ALLOC YYMALLOC
352# define YYSTACK_FREE YYFREE
353# ifndef YYSTACK_ALLOC_MAXIMUM
354# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
355# endif
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000356# if (defined __cplusplus && ! defined EXIT_SUCCESS \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000357 && ! ((defined YYMALLOC || defined malloc) \
Jamie Madill185de882014-12-22 15:17:52 -0500358 && (defined YYFREE || defined free)))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000359# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000360# ifndef EXIT_SUCCESS
361# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000362# endif
363# endif
364# ifndef YYMALLOC
365# define YYMALLOC malloc
Jamie Madill185de882014-12-22 15:17:52 -0500366# if ! defined malloc && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000367void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
368# endif
369# endif
370# ifndef YYFREE
371# define YYFREE free
Jamie Madill185de882014-12-22 15:17:52 -0500372# if ! defined free && ! defined EXIT_SUCCESS
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000373void free (void *); /* INFRINGES ON USER NAME SPACE */
374# endif
375# endif
376# endif
377#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
378
379
380#if (! defined yyoverflow \
381 && (! defined __cplusplus \
Jamie Madill185de882014-12-22 15:17:52 -0500382 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000383
384/* A type that is properly aligned for any stack member. */
385union yyalloc
386{
387 yytype_int16 yyss_alloc;
388 YYSTYPE yyvs_alloc;
389};
390
391/* The size of the maximum gap between one aligned stack and the next. */
392# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
393
394/* The size of an array large to enough to hold all stacks, each with
395 N elements. */
396# define YYSTACK_BYTES(N) \
397 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
398 + YYSTACK_GAP_MAXIMUM)
399
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000400# define YYCOPY_NEEDED 1
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000401
402/* Relocate STACK from its old location to the new one. The
403 local variables YYSIZE and YYSTACKSIZE give the old and new number of
404 elements in the stack, and YYPTR gives the new location of the
405 stack. Advance YYPTR to a properly aligned location for the next
406 stack. */
Jamie Madill185de882014-12-22 15:17:52 -0500407# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
408 do \
409 { \
410 YYSIZE_T yynewbytes; \
411 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
412 Stack = &yyptr->Stack_alloc; \
413 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
414 yyptr += yynewbytes / sizeof (*yyptr); \
415 } \
416 while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000417
418#endif
419
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000420#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
421/* Copy COUNT objects from SRC to DST. The source and destination do
422 not overlap. */
423# ifndef YYCOPY
424# if defined __GNUC__ && 1 < __GNUC__
425# define YYCOPY(Dst, Src, Count) \
426 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
427# else
428# define YYCOPY(Dst, Src, Count) \
429 do \
430 { \
431 YYSIZE_T yyi; \
432 for (yyi = 0; yyi < (Count); yyi++) \
433 (Dst)[yyi] = (Src)[yyi]; \
434 } \
Jamie Madill185de882014-12-22 15:17:52 -0500435 while (0)
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000436# endif
437# endif
438#endif /* !YYCOPY_NEEDED */
439
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000440/* YYFINAL -- State number of the termination state. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300441#define YYFINAL 15
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000442/* YYLAST -- Last index in YYTABLE. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300443#define YYLAST 176
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000444
445/* YYNTOKENS -- Number of terminals. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300446#define YYNTOKENS 28
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000447/* YYNNTS -- Number of nonterminals. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300448#define YYNNTS 5
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000449/* YYNRULES -- Number of rules. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300450#define YYNRULES 29
Jamie Madill185de882014-12-22 15:17:52 -0500451/* YYNSTATES -- Number of states. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300452#define YYNSTATES 55
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000453
Jamie Madill185de882014-12-22 15:17:52 -0500454/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
455 by yylex, with out-of-bounds checking. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000456#define YYUNDEFTOK 2
Olli Etuaho809ec542015-08-26 14:30:57 +0300457#define YYMAXUTOK 268
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000458
Jamie Madill185de882014-12-22 15:17:52 -0500459#define YYTRANSLATE(YYX) \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000460 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
461
Jamie Madill185de882014-12-22 15:17:52 -0500462/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
463 as returned by yylex, without out-of-bounds checking. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000464static const yytype_uint8 yytranslate[] =
465{
466 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
467 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
468 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho809ec542015-08-26 14:30:57 +0300469 2, 2, 2, 24, 2, 2, 2, 22, 9, 2,
470 26, 27, 20, 18, 2, 19, 2, 21, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000471 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho809ec542015-08-26 14:30:57 +0300472 12, 2, 13, 2, 2, 2, 2, 2, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000473 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
474 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho809ec542015-08-26 14:30:57 +0300475 2, 2, 2, 2, 8, 2, 2, 2, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000476 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
477 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
Olli Etuaho809ec542015-08-26 14:30:57 +0300478 2, 2, 2, 2, 7, 2, 25, 2, 2, 2,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000479 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, 2, 2, 2, 2,
491 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
Olli Etuaho809ec542015-08-26 14:30:57 +0300492 5, 6, 10, 11, 14, 15, 16, 17, 23
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000493};
494
495#if YYDEBUG
Jamie Madill185de882014-12-22 15:17:52 -0500496 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
Olli Etuaho809ec542015-08-26 14:30:57 +0300497static const yytype_uint16 yyrline[] =
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000498{
Olli Etuaho3187a382015-09-09 12:00:12 +0300499 0, 106, 106, 113, 114, 124, 124, 145, 145, 166,
500 169, 172, 175, 178, 181, 184, 187, 190, 193, 196,
501 199, 202, 205, 224, 243, 246, 249, 252, 255, 258
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000502};
503#endif
504
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000505#if YYDEBUG || YYERROR_VERBOSE || 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000506/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
507 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
508static const char *const yytname[] =
509{
Olli Etuaho809ec542015-08-26 14:30:57 +0300510 "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_IDENTIFIER",
511 "TOK_OP_OR", "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_EQ", "TOK_OP_NE",
512 "'<'", "'>'", "TOK_OP_LE", "TOK_OP_GE", "TOK_OP_LEFT", "TOK_OP_RIGHT",
513 "'+'", "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('",
514 "')'", "$accept", "input", "expression", "$@1", "$@2", YY_NULLPTR
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000515};
516#endif
517
518# ifdef YYPRINT
Jamie Madill185de882014-12-22 15:17:52 -0500519/* YYTOKNUM[NUM] -- (External) token number corresponding to the
520 (internal) symbol number NUM (which must be that of a token). */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000521static const yytype_uint16 yytoknum[] =
522{
Olli Etuaho809ec542015-08-26 14:30:57 +0300523 0, 256, 257, 258, 259, 260, 261, 124, 94, 38,
524 262, 263, 60, 62, 264, 265, 266, 267, 43, 45,
525 42, 47, 37, 268, 33, 126, 40, 41
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000526};
527# endif
528
Olli Etuaho809ec542015-08-26 14:30:57 +0300529#define YYPACT_NINF -12
Jamie Madill185de882014-12-22 15:17:52 -0500530
531#define yypact_value_is_default(Yystate) \
Olli Etuaho809ec542015-08-26 14:30:57 +0300532 (!!((Yystate) == (-12)))
Jamie Madill185de882014-12-22 15:17:52 -0500533
534#define YYTABLE_NINF -1
535
536#define yytable_value_is_error(Yytable_value) \
537 0
538
539 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
540 STATE-NUM. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000541static const yytype_int16 yypact[] =
542{
Olli Etuaho809ec542015-08-26 14:30:57 +0300543 31, -12, -12, 31, 31, 31, 31, 31, 51, 76,
544 -12, -12, -12, -12, 53, -12, -12, -12, 31, 31,
545 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
546 31, 31, 31, 31, -12, 31, 31, 124, 138, 26,
547 149, 149, -11, -11, -11, -11, 154, 154, -8, -8,
548 -12, -12, -12, 93, 109
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000549};
550
Jamie Madill185de882014-12-22 15:17:52 -0500551 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
552 Performed when YYTABLE does not specify something else to do. Zero
553 means the default is an error. */
554static const yytype_uint8 yydefact[] =
555{
Olli Etuaho809ec542015-08-26 14:30:57 +0300556 0, 3, 4, 0, 0, 0, 0, 0, 0, 2,
557 28, 27, 25, 26, 0, 1, 5, 7, 0, 0,
Jamie Madill185de882014-12-22 15:17:52 -0500558 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Olli Etuaho809ec542015-08-26 14:30:57 +0300559 0, 0, 0, 0, 29, 0, 0, 9, 10, 11,
560 13, 12, 17, 16, 15, 14, 19, 18, 21, 20,
561 24, 23, 22, 6, 8
Jamie Madill185de882014-12-22 15:17:52 -0500562};
563
564 /* YYPGOTO[NTERM-NUM]. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000565static const yytype_int8 yypgoto[] =
566{
Olli Etuaho809ec542015-08-26 14:30:57 +0300567 -12, -12, -3, -12, -12
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000568};
569
Jamie Madill185de882014-12-22 15:17:52 -0500570 /* YYDEFGOTO[NTERM-NUM]. */
571static const yytype_int8 yydefgoto[] =
572{
Olli Etuaho809ec542015-08-26 14:30:57 +0300573 -1, 8, 9, 35, 36
Jamie Madill185de882014-12-22 15:17:52 -0500574};
575
576 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
577 positive, shift that token. If negative, reduce the rule whose
578 number is the opposite. If YYTABLE_NINF, syntax error. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000579static const yytype_uint8 yytable[] =
580{
Olli Etuaho809ec542015-08-26 14:30:57 +0300581 10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
582 32, 33, 31, 32, 33, 37, 38, 39, 40, 41,
583 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
584 52, 0, 53, 54, 1, 2, 21, 22, 23, 24,
585 25, 26, 27, 28, 29, 30, 31, 32, 33, 3,
586 4, 15, 0, 0, 0, 5, 6, 7, 16, 17,
587 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
588 28, 29, 30, 31, 32, 33, 0, 0, 0, 0,
589 34, 16, 17, 18, 19, 20, 21, 22, 23, 24,
590 25, 26, 27, 28, 29, 30, 31, 32, 33, 17,
591 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
592 28, 29, 30, 31, 32, 33, 18, 19, 20, 21,
593 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
594 32, 33, 19, 20, 21, 22, 23, 24, 25, 26,
595 27, 28, 29, 30, 31, 32, 33, 20, 21, 22,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000596 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
Olli Etuaho809ec542015-08-26 14:30:57 +0300597 33, 23, 24, 25, 26, 27, 28, 29, 30, 31,
598 32, 33, 29, 30, 31, 32, 33
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000599};
600
601static const yytype_int8 yycheck[] =
602{
Olli Etuaho809ec542015-08-26 14:30:57 +0300603 3, 4, 5, 6, 7, 16, 17, 18, 19, 20,
604 21, 22, 20, 21, 22, 18, 19, 20, 21, 22,
605 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
606 33, -1, 35, 36, 3, 4, 10, 11, 12, 13,
607 14, 15, 16, 17, 18, 19, 20, 21, 22, 18,
608 19, 0, -1, -1, -1, 24, 25, 26, 5, 6,
609 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
610 17, 18, 19, 20, 21, 22, -1, -1, -1, -1,
611 27, 5, 6, 7, 8, 9, 10, 11, 12, 13,
612 14, 15, 16, 17, 18, 19, 20, 21, 22, 6,
613 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
614 17, 18, 19, 20, 21, 22, 7, 8, 9, 10,
615 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
616 21, 22, 8, 9, 10, 11, 12, 13, 14, 15,
617 16, 17, 18, 19, 20, 21, 22, 9, 10, 11,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000618 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
Olli Etuaho809ec542015-08-26 14:30:57 +0300619 22, 12, 13, 14, 15, 16, 17, 18, 19, 20,
620 21, 22, 18, 19, 20, 21, 22
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000621};
622
Jamie Madill185de882014-12-22 15:17:52 -0500623 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
624 symbol of state STATE-NUM. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000625static const yytype_uint8 yystos[] =
626{
Olli Etuaho809ec542015-08-26 14:30:57 +0300627 0, 3, 4, 18, 19, 24, 25, 26, 29, 30,
628 30, 30, 30, 30, 30, 0, 5, 6, 7, 8,
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000629 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
Olli Etuaho809ec542015-08-26 14:30:57 +0300630 19, 20, 21, 22, 27, 31, 32, 30, 30, 30,
631 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
632 30, 30, 30, 30, 30
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000633};
634
Jamie Madill185de882014-12-22 15:17:52 -0500635 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
636static const yytype_uint8 yyr1[] =
637{
Olli Etuaho809ec542015-08-26 14:30:57 +0300638 0, 28, 29, 30, 30, 31, 30, 32, 30, 30,
639 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
640 30, 30, 30, 30, 30, 30, 30, 30, 30, 30
Jamie Madill185de882014-12-22 15:17:52 -0500641};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000642
Jamie Madill185de882014-12-22 15:17:52 -0500643 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
644static const yytype_uint8 yyr2[] =
645{
Olli Etuaho809ec542015-08-26 14:30:57 +0300646 0, 2, 1, 1, 1, 0, 4, 0, 4, 3,
Jamie Madill185de882014-12-22 15:17:52 -0500647 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
Olli Etuaho809ec542015-08-26 14:30:57 +0300648 3, 3, 3, 3, 3, 2, 2, 2, 2, 3
Jamie Madill185de882014-12-22 15:17:52 -0500649};
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000650
651
Jamie Madill185de882014-12-22 15:17:52 -0500652#define yyerrok (yyerrstatus = 0)
653#define yyclearin (yychar = YYEMPTY)
654#define YYEMPTY (-2)
655#define YYEOF 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000656
Jamie Madill185de882014-12-22 15:17:52 -0500657#define YYACCEPT goto yyacceptlab
658#define YYABORT goto yyabortlab
659#define YYERROR goto yyerrorlab
660
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000661
662#define YYRECOVERING() (!!yyerrstatus)
663
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000664#define YYBACKUP(Token, Value) \
665do \
666 if (yychar == YYEMPTY) \
667 { \
668 yychar = (Token); \
669 yylval = (Value); \
670 YYPOPSTACK (yylen); \
671 yystate = *yyssp; \
672 goto yybackup; \
673 } \
674 else \
675 { \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000676 yyerror (context, YY_("syntax error: cannot back up")); \
Jamie Madill185de882014-12-22 15:17:52 -0500677 YYERROR; \
678 } \
679while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000680
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000681/* Error token number */
Jamie Madill185de882014-12-22 15:17:52 -0500682#define YYTERROR 1
683#define YYERRCODE 256
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000684
685
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000686
687/* Enable debugging if requested. */
688#if YYDEBUG
689
690# ifndef YYFPRINTF
691# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
692# define YYFPRINTF fprintf
693# endif
694
Jamie Madill185de882014-12-22 15:17:52 -0500695# define YYDPRINTF(Args) \
696do { \
697 if (yydebug) \
698 YYFPRINTF Args; \
699} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000700
Jamie Madill185de882014-12-22 15:17:52 -0500701/* This macro is provided for backward compatibility. */
702#ifndef YY_LOCATION_PRINT
703# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
704#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000705
706
Jamie Madill185de882014-12-22 15:17:52 -0500707# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
708do { \
709 if (yydebug) \
710 { \
711 YYFPRINTF (stderr, "%s ", Title); \
712 yy_symbol_print (stderr, \
713 Type, Value, context); \
714 YYFPRINTF (stderr, "\n"); \
715 } \
716} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000717
Jamie Madill185de882014-12-22 15:17:52 -0500718
719/*----------------------------------------.
720| Print this symbol's value on YYOUTPUT. |
721`----------------------------------------*/
722
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000723static void
724yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000725{
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000726 FILE *yyo = yyoutput;
727 YYUSE (yyo);
Jamie Madill185de882014-12-22 15:17:52 -0500728 YYUSE (context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000729 if (!yyvaluep)
730 return;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000731# ifdef YYPRINT
732 if (yytype < YYNTOKENS)
733 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000734# endif
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400735 YYUSE (yytype);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000736}
737
738
739/*--------------------------------.
740| Print this symbol on YYOUTPUT. |
741`--------------------------------*/
742
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000743static void
744yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000745{
Jamie Madill185de882014-12-22 15:17:52 -0500746 YYFPRINTF (yyoutput, "%s %s (",
747 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000748
749 yy_symbol_value_print (yyoutput, yytype, yyvaluep, context);
750 YYFPRINTF (yyoutput, ")");
751}
752
753/*------------------------------------------------------------------.
754| yy_stack_print -- Print the state stack from its BOTTOM up to its |
755| TOP (included). |
756`------------------------------------------------------------------*/
757
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000758static void
759yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000760{
761 YYFPRINTF (stderr, "Stack now");
762 for (; yybottom <= yytop; yybottom++)
763 {
764 int yybot = *yybottom;
765 YYFPRINTF (stderr, " %d", yybot);
766 }
767 YYFPRINTF (stderr, "\n");
768}
769
Jamie Madill185de882014-12-22 15:17:52 -0500770# define YY_STACK_PRINT(Bottom, Top) \
771do { \
772 if (yydebug) \
773 yy_stack_print ((Bottom), (Top)); \
774} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000775
776
777/*------------------------------------------------.
778| Report that the YYRULE is going to be reduced. |
779`------------------------------------------------*/
780
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000781static void
Jamie Madill185de882014-12-22 15:17:52 -0500782yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000783{
Jamie Madill185de882014-12-22 15:17:52 -0500784 unsigned long int yylno = yyrline[yyrule];
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000785 int yynrhs = yyr2[yyrule];
786 int yyi;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000787 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
Jamie Madill185de882014-12-22 15:17:52 -0500788 yyrule - 1, yylno);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000789 /* The symbols being reduced. */
790 for (yyi = 0; yyi < yynrhs; yyi++)
791 {
792 YYFPRINTF (stderr, " $%d = ", yyi + 1);
Jamie Madill185de882014-12-22 15:17:52 -0500793 yy_symbol_print (stderr,
794 yystos[yyssp[yyi + 1 - yynrhs]],
795 &(yyvsp[(yyi + 1) - (yynrhs)])
796 , context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000797 YYFPRINTF (stderr, "\n");
798 }
799}
800
Jamie Madill185de882014-12-22 15:17:52 -0500801# define YY_REDUCE_PRINT(Rule) \
802do { \
803 if (yydebug) \
804 yy_reduce_print (yyssp, yyvsp, Rule, context); \
805} while (0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000806
807/* Nonzero means print parse trace. It is left uninitialized so that
808 multiple parsers can coexist. */
809int yydebug;
810#else /* !YYDEBUG */
811# define YYDPRINTF(Args)
812# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
813# define YY_STACK_PRINT(Bottom, Top)
814# define YY_REDUCE_PRINT(Rule)
815#endif /* !YYDEBUG */
816
817
818/* YYINITDEPTH -- initial size of the parser's stacks. */
Jamie Madill185de882014-12-22 15:17:52 -0500819#ifndef YYINITDEPTH
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000820# define YYINITDEPTH 200
821#endif
822
823/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
824 if the built-in stack extension method is used).
825
826 Do not make this value too large; the results are undefined if
827 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
828 evaluated with infinite-precision integer arithmetic. */
829
830#ifndef YYMAXDEPTH
831# define YYMAXDEPTH 10000
832#endif
833
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000834
835#if YYERROR_VERBOSE
836
837# ifndef yystrlen
838# if defined __GLIBC__ && defined _STRING_H
839# define yystrlen strlen
840# else
841/* Return the length of YYSTR. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000842static YYSIZE_T
843yystrlen (const char *yystr)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000844{
845 YYSIZE_T yylen;
846 for (yylen = 0; yystr[yylen]; yylen++)
847 continue;
848 return yylen;
849}
850# endif
851# endif
852
853# ifndef yystpcpy
854# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
855# define yystpcpy stpcpy
856# else
857/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
858 YYDEST. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000859static char *
860yystpcpy (char *yydest, const char *yysrc)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000861{
862 char *yyd = yydest;
863 const char *yys = yysrc;
864
865 while ((*yyd++ = *yys++) != '\0')
866 continue;
867
868 return yyd - 1;
869}
870# endif
871# endif
872
873# ifndef yytnamerr
874/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
875 quotes and backslashes, so that it's suitable for yyerror. The
876 heuristic is that double-quoting is unnecessary unless the string
877 contains an apostrophe, a comma, or backslash (other than
878 backslash-backslash). YYSTR is taken from yytname. If YYRES is
879 null, do not copy; instead, return the length of what the result
880 would have been. */
881static YYSIZE_T
882yytnamerr (char *yyres, const char *yystr)
883{
884 if (*yystr == '"')
885 {
886 YYSIZE_T yyn = 0;
887 char const *yyp = yystr;
888
889 for (;;)
Jamie Madill185de882014-12-22 15:17:52 -0500890 switch (*++yyp)
891 {
892 case '\'':
893 case ',':
894 goto do_not_strip_quotes;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000895
Jamie Madill185de882014-12-22 15:17:52 -0500896 case '\\':
897 if (*++yyp != '\\')
898 goto do_not_strip_quotes;
899 /* Fall through. */
900 default:
901 if (yyres)
902 yyres[yyn] = *yyp;
903 yyn++;
904 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000905
Jamie Madill185de882014-12-22 15:17:52 -0500906 case '"':
907 if (yyres)
908 yyres[yyn] = '\0';
909 return yyn;
910 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000911 do_not_strip_quotes: ;
912 }
913
914 if (! yyres)
915 return yystrlen (yystr);
916
917 return yystpcpy (yyres, yystr) - yyres;
918}
919# endif
920
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000921/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
922 about the unexpected token YYTOKEN for the state stack whose top is
923 YYSSP.
924
925 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
926 not large enough to hold the message. In that case, also set
927 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
928 required number of bytes is too large to store. */
929static int
930yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
931 yytype_int16 *yyssp, int yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000932{
Jamie Madill185de882014-12-22 15:17:52 -0500933 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000934 YYSIZE_T yysize = yysize0;
935 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
936 /* Internationalized format string. */
Jamie Madill185de882014-12-22 15:17:52 -0500937 const char *yyformat = YY_NULLPTR;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000938 /* Arguments of yyformat. */
939 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
940 /* Number of reported tokens (one for the "unexpected", one per
941 "expected"). */
942 int yycount = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000943
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000944 /* There are many possibilities here to consider:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000945 - If this state is a consistent state with a default action, then
946 the only way this function was invoked is if the default action
947 is an error action. In that case, don't check for expected
948 tokens because there are none.
949 - The only way there can be no lookahead present (in yychar) is if
950 this state is a consistent state with a default action. Thus,
951 detecting the absence of a lookahead is sufficient to determine
952 that there is no unexpected or expected token to report. In that
953 case, just report a simple "syntax error".
954 - Don't assume there isn't a lookahead just because this state is a
955 consistent state with a default action. There might have been a
956 previous inconsistent state, consistent state with a non-default
957 action, or user semantic action that manipulated yychar.
958 - Of course, the expected token list depends on states to have
959 correct lookahead information, and it depends on the parser not
960 to perform extra reductions after fetching a lookahead from the
961 scanner and before detecting a syntax error. Thus, state merging
962 (from LALR or IELR) and default reductions corrupt the expected
963 token list. However, the list is correct for canonical LR with
964 one exception: it will still contain any token that will not be
965 accepted due to an error action in a later state.
966 */
967 if (yytoken != YYEMPTY)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000968 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000969 int yyn = yypact[*yyssp];
970 yyarg[yycount++] = yytname[yytoken];
971 if (!yypact_value_is_default (yyn))
972 {
973 /* Start YYX at -YYN if negative to avoid negative indexes in
974 YYCHECK. In other words, skip the first -YYN actions for
975 this state because they are default actions. */
976 int yyxbegin = yyn < 0 ? -yyn : 0;
977 /* Stay within bounds of both yycheck and yytname. */
978 int yychecklim = YYLAST - yyn + 1;
979 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
980 int yyx;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000981
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000982 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
983 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
984 && !yytable_value_is_error (yytable[yyx + yyn]))
985 {
986 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
987 {
988 yycount = 1;
989 yysize = yysize0;
990 break;
991 }
992 yyarg[yycount++] = yytname[yyx];
993 {
Jamie Madill185de882014-12-22 15:17:52 -0500994 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000995 if (! (yysize <= yysize1
996 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
997 return 2;
998 yysize = yysize1;
999 }
1000 }
1001 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001002 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001003
1004 switch (yycount)
1005 {
1006# define YYCASE_(N, S) \
1007 case N: \
1008 yyformat = S; \
1009 break
1010 YYCASE_(0, YY_("syntax error"));
1011 YYCASE_(1, YY_("syntax error, unexpected %s"));
1012 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1013 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1014 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1015 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1016# undef YYCASE_
1017 }
1018
1019 {
1020 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1021 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1022 return 2;
1023 yysize = yysize1;
1024 }
1025
1026 if (*yymsg_alloc < yysize)
1027 {
1028 *yymsg_alloc = 2 * yysize;
1029 if (! (yysize <= *yymsg_alloc
1030 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1031 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1032 return 1;
1033 }
1034
1035 /* Avoid sprintf, as that infringes on the user's name space.
1036 Don't have undefined behavior even if the translation
1037 produced a string with the wrong number of "%s"s. */
1038 {
1039 char *yyp = *yymsg;
1040 int yyi = 0;
1041 while ((*yyp = *yyformat) != '\0')
1042 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1043 {
1044 yyp += yytnamerr (yyp, yyarg[yyi++]);
1045 yyformat += 2;
1046 }
1047 else
1048 {
1049 yyp++;
1050 yyformat++;
1051 }
1052 }
1053 return 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001054}
1055#endif /* YYERROR_VERBOSE */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001056
1057/*-----------------------------------------------.
1058| Release the memory associated to this symbol. |
1059`-----------------------------------------------*/
1060
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001061static void
1062yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001063{
1064 YYUSE (yyvaluep);
1065 YYUSE (context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001066 if (!yymsg)
1067 yymsg = "Deleting";
1068 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1069
Jamie Madill185de882014-12-22 15:17:52 -05001070 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Zhenyao Mof1d723c2013-09-23 14:57:07 -04001071 YYUSE (yytype);
Jamie Madill185de882014-12-22 15:17:52 -05001072 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001073}
1074
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001075
1076
1077
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001078/*----------.
1079| yyparse. |
1080`----------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001081
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001082int
1083yyparse (Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001084{
1085/* The lookahead symbol. */
1086int yychar;
1087
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001088
Jamie Madill185de882014-12-22 15:17:52 -05001089/* The semantic value of the lookahead symbol. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001090/* Default value used for initialization, for pacifying older GCCs
1091 or non-GCC compilers. */
Jamie Madill185de882014-12-22 15:17:52 -05001092YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1093YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001094
1095 /* Number of syntax errors so far. */
1096 int yynerrs;
1097
1098 int yystate;
1099 /* Number of tokens to shift before error messages enabled. */
1100 int yyerrstatus;
1101
1102 /* The stacks and their tools:
Jamie Madill185de882014-12-22 15:17:52 -05001103 'yyss': related to states.
1104 'yyvs': related to semantic values.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001105
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001106 Refer to the stacks through separate pointers, to allow yyoverflow
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001107 to reallocate them elsewhere. */
1108
1109 /* The state stack. */
1110 yytype_int16 yyssa[YYINITDEPTH];
1111 yytype_int16 *yyss;
1112 yytype_int16 *yyssp;
1113
1114 /* The semantic value stack. */
1115 YYSTYPE yyvsa[YYINITDEPTH];
1116 YYSTYPE *yyvs;
1117 YYSTYPE *yyvsp;
1118
1119 YYSIZE_T yystacksize;
1120
1121 int yyn;
1122 int yyresult;
1123 /* Lookahead token as an internal (translated) token number. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001124 int yytoken = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001125 /* The variables used to return semantic value and location from the
1126 action routines. */
1127 YYSTYPE yyval;
1128
1129#if YYERROR_VERBOSE
1130 /* Buffer for error messages, and its allocated size. */
1131 char yymsgbuf[128];
1132 char *yymsg = yymsgbuf;
1133 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1134#endif
1135
1136#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1137
1138 /* The number of symbols on the RHS of the reduced rule.
1139 Keep to zero when no symbol should be popped. */
1140 int yylen = 0;
1141
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001142 yyssp = yyss = yyssa;
1143 yyvsp = yyvs = yyvsa;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001144 yystacksize = YYINITDEPTH;
1145
1146 YYDPRINTF ((stderr, "Starting parse\n"));
1147
1148 yystate = 0;
1149 yyerrstatus = 0;
1150 yynerrs = 0;
1151 yychar = YYEMPTY; /* Cause a token to be read. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001152 goto yysetstate;
1153
1154/*------------------------------------------------------------.
1155| yynewstate -- Push a new state, which is found in yystate. |
1156`------------------------------------------------------------*/
1157 yynewstate:
1158 /* In all cases, when you get here, the value and location stacks
1159 have just been pushed. So pushing a state here evens the stacks. */
1160 yyssp++;
1161
1162 yysetstate:
1163 *yyssp = yystate;
1164
1165 if (yyss + yystacksize - 1 <= yyssp)
1166 {
1167 /* Get the current used size of the three stacks, in elements. */
1168 YYSIZE_T yysize = yyssp - yyss + 1;
1169
1170#ifdef yyoverflow
1171 {
Jamie Madill185de882014-12-22 15:17:52 -05001172 /* Give user a chance to reallocate the stack. Use copies of
1173 these so that the &'s don't force the real ones into
1174 memory. */
1175 YYSTYPE *yyvs1 = yyvs;
1176 yytype_int16 *yyss1 = yyss;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001177
Jamie Madill185de882014-12-22 15:17:52 -05001178 /* Each stack pointer address is followed by the size of the
1179 data in use in that stack, in bytes. This used to be a
1180 conditional around just the two extra args, but that might
1181 be undefined if yyoverflow is a macro. */
1182 yyoverflow (YY_("memory exhausted"),
1183 &yyss1, yysize * sizeof (*yyssp),
1184 &yyvs1, yysize * sizeof (*yyvsp),
1185 &yystacksize);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001186
Jamie Madill185de882014-12-22 15:17:52 -05001187 yyss = yyss1;
1188 yyvs = yyvs1;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001189 }
1190#else /* no yyoverflow */
1191# ifndef YYSTACK_RELOCATE
1192 goto yyexhaustedlab;
1193# else
1194 /* Extend the stack our own way. */
1195 if (YYMAXDEPTH <= yystacksize)
Jamie Madill185de882014-12-22 15:17:52 -05001196 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001197 yystacksize *= 2;
1198 if (YYMAXDEPTH < yystacksize)
Jamie Madill185de882014-12-22 15:17:52 -05001199 yystacksize = YYMAXDEPTH;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001200
1201 {
Jamie Madill185de882014-12-22 15:17:52 -05001202 yytype_int16 *yyss1 = yyss;
1203 union yyalloc *yyptr =
1204 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1205 if (! yyptr)
1206 goto yyexhaustedlab;
1207 YYSTACK_RELOCATE (yyss_alloc, yyss);
1208 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001209# undef YYSTACK_RELOCATE
Jamie Madill185de882014-12-22 15:17:52 -05001210 if (yyss1 != yyssa)
1211 YYSTACK_FREE (yyss1);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001212 }
1213# endif
1214#endif /* no yyoverflow */
1215
1216 yyssp = yyss + yysize - 1;
1217 yyvsp = yyvs + yysize - 1;
1218
1219 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
Jamie Madill185de882014-12-22 15:17:52 -05001220 (unsigned long int) yystacksize));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001221
1222 if (yyss + yystacksize - 1 <= yyssp)
Jamie Madill185de882014-12-22 15:17:52 -05001223 YYABORT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001224 }
1225
1226 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1227
1228 if (yystate == YYFINAL)
1229 YYACCEPT;
1230
1231 goto yybackup;
1232
1233/*-----------.
1234| yybackup. |
1235`-----------*/
1236yybackup:
1237
1238 /* Do appropriate processing given the current state. Read a
1239 lookahead token if we need one and don't already have one. */
1240
1241 /* First try to decide what to do without reference to lookahead token. */
1242 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001243 if (yypact_value_is_default (yyn))
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001244 goto yydefault;
1245
1246 /* Not known => get a lookahead token if don't already have one. */
1247
1248 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1249 if (yychar == YYEMPTY)
1250 {
1251 YYDPRINTF ((stderr, "Reading a token: "));
Jamie Madill185de882014-12-22 15:17:52 -05001252 yychar = yylex (&yylval, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001253 }
1254
1255 if (yychar <= YYEOF)
1256 {
1257 yychar = yytoken = YYEOF;
1258 YYDPRINTF ((stderr, "Now at end of input.\n"));
1259 }
1260 else
1261 {
1262 yytoken = YYTRANSLATE (yychar);
1263 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1264 }
1265
1266 /* If the proper action on seeing token YYTOKEN is to reduce or to
1267 detect an error, take that action. */
1268 yyn += yytoken;
1269 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1270 goto yydefault;
1271 yyn = yytable[yyn];
1272 if (yyn <= 0)
1273 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001274 if (yytable_value_is_error (yyn))
1275 goto yyerrlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001276 yyn = -yyn;
1277 goto yyreduce;
1278 }
1279
1280 /* Count tokens shifted since error; after three, turn off error
1281 status. */
1282 if (yyerrstatus)
1283 yyerrstatus--;
1284
1285 /* Shift the lookahead token. */
1286 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1287
1288 /* Discard the shifted token. */
1289 yychar = YYEMPTY;
1290
1291 yystate = yyn;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001292 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001293 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001294 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001295
1296 goto yynewstate;
1297
1298
1299/*-----------------------------------------------------------.
1300| yydefault -- do the default action for the current state. |
1301`-----------------------------------------------------------*/
1302yydefault:
1303 yyn = yydefact[yystate];
1304 if (yyn == 0)
1305 goto yyerrlab;
1306 goto yyreduce;
1307
1308
1309/*-----------------------------.
1310| yyreduce -- Do a reduction. |
1311`-----------------------------*/
1312yyreduce:
1313 /* yyn is the number of a rule to reduce with. */
1314 yylen = yyr2[yyn];
1315
1316 /* If YYLEN is nonzero, implement the default value of the action:
Jamie Madill185de882014-12-22 15:17:52 -05001317 '$$ = $1'.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001318
1319 Otherwise, the following line sets YYVAL to garbage.
1320 This behavior is undocumented and Bison
1321 users should not rely upon it. Assigning to YYVAL
1322 unconditionally makes the parser a bit smaller, and it avoids a
1323 GCC warning that YYVAL may be used uninitialized. */
1324 yyval = yyvsp[1-yylen];
1325
1326
1327 YY_REDUCE_PRINT (yyn);
1328 switch (yyn)
1329 {
1330 case 2:
1331
1332 {
Jamie Madill185de882014-12-22 15:17:52 -05001333 *(context->result) = static_cast<int>((yyvsp[0]));
Olli Etuaho3187a382015-09-09 12:00:12 +03001334 YYACCEPT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001335 }
Jamie Madill185de882014-12-22 15:17:52 -05001336
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001337 break;
1338
1339 case 4:
1340
1341 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001342 if (!context->isIgnoringErrors())
1343 {
Olli Etuaho3187a382015-09-09 12:00:12 +03001344 // This rule should be applied right after the token is lexed, so we can
1345 // refer to context->token in the error message.
1346 context->diagnostics->report(pp::Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
1347 context->token->location, context->token->text);
Olli Etuaho809ec542015-08-26 14:30:57 +03001348 }
Olli Etuaho3187a382015-09-09 12:00:12 +03001349 (yyval) = (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001350 }
Jamie Madill185de882014-12-22 15:17:52 -05001351
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001352 break;
1353
1354 case 5:
1355
1356 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001357 if ((yyvsp[-1]) != 0)
1358 {
1359 // Ignore errors in the short-circuited part of the expression.
1360 // ESSL3.00 section 3.4:
1361 // If an operand is not evaluated, the presence of undefined identifiers
1362 // in the operand will not cause an error.
1363 // Unevaluated division by zero should not cause an error either.
1364 context->startIgnoreErrors();
1365 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001366 }
Jamie Madill185de882014-12-22 15:17:52 -05001367
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001368 break;
1369
1370 case 6:
1371
1372 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001373 if ((yyvsp[-3]) != 0)
1374 {
1375 context->endIgnoreErrors();
1376 (yyval) = static_cast<YYSTYPE>(1);
1377 }
1378 else
1379 {
1380 (yyval) = (yyvsp[-3]) || (yyvsp[0]);
1381 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001382 }
Jamie Madill185de882014-12-22 15:17:52 -05001383
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001384 break;
1385
1386 case 7:
1387
1388 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001389 if ((yyvsp[-1]) == 0)
1390 {
1391 // Ignore errors in the short-circuited part of the expression.
1392 // ESSL3.00 section 3.4:
1393 // If an operand is not evaluated, the presence of undefined identifiers
1394 // in the operand will not cause an error.
1395 // Unevaluated division by zero should not cause an error either.
1396 context->startIgnoreErrors();
1397 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001398 }
Jamie Madill185de882014-12-22 15:17:52 -05001399
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001400 break;
1401
1402 case 8:
1403
1404 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001405 if ((yyvsp[-3]) == 0)
1406 {
1407 context->endIgnoreErrors();
1408 (yyval) = static_cast<YYSTYPE>(0);
1409 }
1410 else
1411 {
1412 (yyval) = (yyvsp[-3]) && (yyvsp[0]);
1413 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001414 }
Jamie Madill185de882014-12-22 15:17:52 -05001415
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001416 break;
1417
1418 case 9:
1419
1420 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001421 (yyval) = (yyvsp[-2]) | (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001422 }
Jamie Madill185de882014-12-22 15:17:52 -05001423
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001424 break;
1425
1426 case 10:
1427
1428 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001429 (yyval) = (yyvsp[-2]) ^ (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001430 }
Jamie Madill185de882014-12-22 15:17:52 -05001431
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001432 break;
1433
1434 case 11:
1435
1436 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001437 (yyval) = (yyvsp[-2]) & (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001438 }
Jamie Madill185de882014-12-22 15:17:52 -05001439
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001440 break;
1441
1442 case 12:
1443
1444 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001445 (yyval) = (yyvsp[-2]) != (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001446 }
Jamie Madill185de882014-12-22 15:17:52 -05001447
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001448 break;
1449
1450 case 13:
1451
1452 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001453 (yyval) = (yyvsp[-2]) == (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001454 }
Jamie Madill185de882014-12-22 15:17:52 -05001455
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001456 break;
1457
1458 case 14:
1459
1460 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001461 (yyval) = (yyvsp[-2]) >= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001462 }
Jamie Madill185de882014-12-22 15:17:52 -05001463
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001464 break;
1465
1466 case 15:
1467
1468 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001469 (yyval) = (yyvsp[-2]) <= (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001470 }
Jamie Madill185de882014-12-22 15:17:52 -05001471
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001472 break;
1473
1474 case 16:
1475
1476 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001477 (yyval) = (yyvsp[-2]) > (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001478 }
Jamie Madill185de882014-12-22 15:17:52 -05001479
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001480 break;
1481
1482 case 17:
1483
1484 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001485 (yyval) = (yyvsp[-2]) < (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001486 }
Jamie Madill185de882014-12-22 15:17:52 -05001487
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001488 break;
1489
1490 case 18:
1491
1492 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001493 (yyval) = (yyvsp[-2]) >> (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001494 }
Jamie Madill185de882014-12-22 15:17:52 -05001495
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001496 break;
1497
1498 case 19:
1499
1500 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001501 (yyval) = (yyvsp[-2]) << (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001502 }
Jamie Madill185de882014-12-22 15:17:52 -05001503
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001504 break;
1505
1506 case 20:
1507
1508 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001509 (yyval) = (yyvsp[-2]) - (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001510 }
Jamie Madill185de882014-12-22 15:17:52 -05001511
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001512 break;
1513
1514 case 21:
1515
1516 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001517 (yyval) = (yyvsp[-2]) + (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001518 }
Jamie Madill185de882014-12-22 15:17:52 -05001519
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001520 break;
1521
1522 case 22:
1523
1524 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001525 if ((yyvsp[0]) == 0)
1526 {
Olli Etuaho3187a382015-09-09 12:00:12 +03001527 if (!context->isIgnoringErrors())
Olli Etuaho809ec542015-08-26 14:30:57 +03001528 {
1529 std::ostringstream stream;
1530 stream << (yyvsp[-2]) << " % " << (yyvsp[0]);
1531 std::string text = stream.str();
1532 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1533 context->token->location,
1534 text.c_str());
Olli Etuaho809ec542015-08-26 14:30:57 +03001535 }
Olli Etuaho3187a382015-09-09 12:00:12 +03001536 (yyval) = static_cast<YYSTYPE>(0);
Olli Etuaho809ec542015-08-26 14:30:57 +03001537 }
1538 else
1539 {
1540 (yyval) = (yyvsp[-2]) % (yyvsp[0]);
1541 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001542 }
Jamie Madill185de882014-12-22 15:17:52 -05001543
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001544 break;
1545
1546 case 23:
1547
1548 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001549 if ((yyvsp[0]) == 0)
1550 {
Olli Etuaho3187a382015-09-09 12:00:12 +03001551 if (!context->isIgnoringErrors())
Olli Etuaho809ec542015-08-26 14:30:57 +03001552 {
1553 std::ostringstream stream;
1554 stream << (yyvsp[-2]) << " / " << (yyvsp[0]);
1555 std::string text = stream.str();
1556 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
1557 context->token->location,
1558 text.c_str());
Olli Etuaho809ec542015-08-26 14:30:57 +03001559 }
Olli Etuaho3187a382015-09-09 12:00:12 +03001560 (yyval) = static_cast<YYSTYPE>(0);
Olli Etuaho809ec542015-08-26 14:30:57 +03001561 }
1562 else
1563 {
1564 (yyval) = (yyvsp[-2]) / (yyvsp[0]);
1565 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001566 }
Jamie Madill185de882014-12-22 15:17:52 -05001567
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001568 break;
1569
1570 case 24:
1571
1572 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001573 (yyval) = (yyvsp[-2]) * (yyvsp[0]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001574 }
Jamie Madill185de882014-12-22 15:17:52 -05001575
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001576 break;
1577
1578 case 25:
1579
1580 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001581 (yyval) = ! (yyvsp[0]);
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001582 }
1583
1584 break;
1585
Jamie Madill9a1b49f2015-09-08 14:32:26 +00001586 case 26:
Olli Etuaho6ffe6132015-08-26 14:30:57 +03001587
1588 {
Olli Etuaho809ec542015-08-26 14:30:57 +03001589 (yyval) = ~ (yyvsp[0]);
1590 }
1591
1592 break;
1593
1594 case 27:
1595
1596 {
1597 (yyval) = - (yyvsp[0]);
1598 }
1599
1600 break;
1601
1602 case 28:
1603
1604 {
1605 (yyval) = + (yyvsp[0]);
1606 }
1607
1608 break;
1609
1610 case 29:
1611
1612 {
Jamie Madill185de882014-12-22 15:17:52 -05001613 (yyval) = (yyvsp[-1]);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001614 }
Jamie Madill185de882014-12-22 15:17:52 -05001615
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001616 break;
1617
1618
1619
1620 default: break;
1621 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001622 /* User semantic actions sometimes alter yychar, and that requires
1623 that yytoken be updated with the new translation. We take the
1624 approach of translating immediately before every use of yytoken.
1625 One alternative is translating here after every semantic action,
1626 but that translation would be missed if the semantic action invokes
1627 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1628 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1629 incorrect destructor might then be invoked immediately. In the
1630 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1631 to an incorrect destructor call or verbose syntax error message
1632 before the lookahead is translated. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001633 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1634
1635 YYPOPSTACK (yylen);
1636 yylen = 0;
1637 YY_STACK_PRINT (yyss, yyssp);
1638
1639 *++yyvsp = yyval;
1640
Jamie Madill185de882014-12-22 15:17:52 -05001641 /* Now 'shift' the result of the reduction. Determine what state
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001642 that goes to, based on the state we popped back to and the rule
1643 number reduced by. */
1644
1645 yyn = yyr1[yyn];
1646
1647 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1648 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1649 yystate = yytable[yystate];
1650 else
1651 yystate = yydefgoto[yyn - YYNTOKENS];
1652
1653 goto yynewstate;
1654
1655
Jamie Madill185de882014-12-22 15:17:52 -05001656/*--------------------------------------.
1657| yyerrlab -- here on detecting error. |
1658`--------------------------------------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001659yyerrlab:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001660 /* Make sure we have latest lookahead translation. See comments at
1661 user semantic actions for why this is necessary. */
1662 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1663
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001664 /* If not already recovering from an error, report this error. */
1665 if (!yyerrstatus)
1666 {
1667 ++yynerrs;
1668#if ! YYERROR_VERBOSE
1669 yyerror (context, YY_("syntax error"));
1670#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001671# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1672 yyssp, yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001673 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001674 char const *yymsgp = YY_("syntax error");
1675 int yysyntax_error_status;
1676 yysyntax_error_status = YYSYNTAX_ERROR;
1677 if (yysyntax_error_status == 0)
1678 yymsgp = yymsg;
1679 else if (yysyntax_error_status == 1)
1680 {
1681 if (yymsg != yymsgbuf)
1682 YYSTACK_FREE (yymsg);
1683 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1684 if (!yymsg)
1685 {
1686 yymsg = yymsgbuf;
1687 yymsg_alloc = sizeof yymsgbuf;
1688 yysyntax_error_status = 2;
1689 }
1690 else
1691 {
1692 yysyntax_error_status = YYSYNTAX_ERROR;
1693 yymsgp = yymsg;
1694 }
1695 }
1696 yyerror (context, yymsgp);
1697 if (yysyntax_error_status == 2)
1698 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001699 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001700# undef YYSYNTAX_ERROR
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001701#endif
1702 }
1703
1704
1705
1706 if (yyerrstatus == 3)
1707 {
1708 /* If just tried and failed to reuse lookahead token after an
Jamie Madill185de882014-12-22 15:17:52 -05001709 error, discard it. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001710
1711 if (yychar <= YYEOF)
Jamie Madill185de882014-12-22 15:17:52 -05001712 {
1713 /* Return failure if at end of input. */
1714 if (yychar == YYEOF)
1715 YYABORT;
1716 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001717 else
Jamie Madill185de882014-12-22 15:17:52 -05001718 {
1719 yydestruct ("Error: discarding",
1720 yytoken, &yylval, context);
1721 yychar = YYEMPTY;
1722 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001723 }
1724
1725 /* Else will try to reuse lookahead token after shifting the error
1726 token. */
1727 goto yyerrlab1;
1728
1729
1730/*---------------------------------------------------.
1731| yyerrorlab -- error raised explicitly by YYERROR. |
1732`---------------------------------------------------*/
1733yyerrorlab:
1734
1735 /* Pacify compilers like GCC when the user code never invokes
1736 YYERROR and the label yyerrorlab therefore never appears in user
1737 code. */
1738 if (/*CONSTCOND*/ 0)
1739 goto yyerrorlab;
1740
Jamie Madill185de882014-12-22 15:17:52 -05001741 /* Do not reclaim the symbols of the rule whose action triggered
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001742 this YYERROR. */
1743 YYPOPSTACK (yylen);
1744 yylen = 0;
1745 YY_STACK_PRINT (yyss, yyssp);
1746 yystate = *yyssp;
1747 goto yyerrlab1;
1748
1749
1750/*-------------------------------------------------------------.
1751| yyerrlab1 -- common code for both syntax error and YYERROR. |
1752`-------------------------------------------------------------*/
1753yyerrlab1:
Jamie Madill185de882014-12-22 15:17:52 -05001754 yyerrstatus = 3; /* Each real token shifted decrements this. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001755
1756 for (;;)
1757 {
1758 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001759 if (!yypact_value_is_default (yyn))
Jamie Madill185de882014-12-22 15:17:52 -05001760 {
1761 yyn += YYTERROR;
1762 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1763 {
1764 yyn = yytable[yyn];
1765 if (0 < yyn)
1766 break;
1767 }
1768 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001769
1770 /* Pop the current state because it cannot handle the error token. */
1771 if (yyssp == yyss)
Jamie Madill185de882014-12-22 15:17:52 -05001772 YYABORT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001773
1774
1775 yydestruct ("Error: popping",
Jamie Madill185de882014-12-22 15:17:52 -05001776 yystos[yystate], yyvsp, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001777 YYPOPSTACK (1);
1778 yystate = *yyssp;
1779 YY_STACK_PRINT (yyss, yyssp);
1780 }
1781
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001782 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001783 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001784 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001785
1786
1787 /* Shift the error token. */
1788 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1789
1790 yystate = yyn;
1791 goto yynewstate;
1792
1793
1794/*-------------------------------------.
1795| yyacceptlab -- YYACCEPT comes here. |
1796`-------------------------------------*/
1797yyacceptlab:
1798 yyresult = 0;
1799 goto yyreturn;
1800
1801/*-----------------------------------.
1802| yyabortlab -- YYABORT comes here. |
1803`-----------------------------------*/
1804yyabortlab:
1805 yyresult = 1;
1806 goto yyreturn;
1807
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001808#if !defined yyoverflow || YYERROR_VERBOSE
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001809/*-------------------------------------------------.
1810| yyexhaustedlab -- memory exhaustion comes here. |
1811`-------------------------------------------------*/
1812yyexhaustedlab:
1813 yyerror (context, YY_("memory exhausted"));
1814 yyresult = 2;
1815 /* Fall through. */
1816#endif
1817
1818yyreturn:
1819 if (yychar != YYEMPTY)
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001820 {
1821 /* Make sure we have latest lookahead translation. See comments at
1822 user semantic actions for why this is necessary. */
1823 yytoken = YYTRANSLATE (yychar);
1824 yydestruct ("Cleanup: discarding lookahead",
1825 yytoken, &yylval, context);
1826 }
Jamie Madill185de882014-12-22 15:17:52 -05001827 /* Do not reclaim the symbols of the rule whose action triggered
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001828 this YYABORT or YYACCEPT. */
1829 YYPOPSTACK (yylen);
1830 YY_STACK_PRINT (yyss, yyssp);
1831 while (yyssp != yyss)
1832 {
1833 yydestruct ("Cleanup: popping",
Jamie Madill185de882014-12-22 15:17:52 -05001834 yystos[*yyssp], yyvsp, context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001835 YYPOPSTACK (1);
1836 }
1837#ifndef yyoverflow
1838 if (yyss != yyssa)
1839 YYSTACK_FREE (yyss);
1840#endif
1841#if YYERROR_VERBOSE
1842 if (yymsg != yymsgbuf)
1843 YYSTACK_FREE (yymsg);
1844#endif
Jamie Madill185de882014-12-22 15:17:52 -05001845 return yyresult;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001846}
1847
1848
1849
Zhenyao Mod526f982014-05-13 14:51:19 -07001850int yylex(YYSTYPE *lvalp, Context *context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001851{
Olli Etuaho3187a382015-09-09 12:00:12 +03001852 pp::Token *token = context->token;
1853 context->lexer->lex(token);
1854
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001855 int type = 0;
1856
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:
Olli Etuaho809ec542015-08-26 14:30:57 +03001871 *lvalp = static_cast<YYSTYPE>(-1);
1872 type = TOK_IDENTIFIER;
1873 break;
Zhenyao Mod526f982014-05-13 14:51:19 -07001874 case pp::Token::OP_OR:
1875 type = TOK_OP_OR;
1876 break;
1877 case pp::Token::OP_AND:
1878 type = TOK_OP_AND;
1879 break;
1880 case pp::Token::OP_NE:
1881 type = TOK_OP_NE;
1882 break;
1883 case pp::Token::OP_EQ:
1884 type = TOK_OP_EQ;
1885 break;
1886 case pp::Token::OP_GE:
1887 type = TOK_OP_GE;
1888 break;
1889 case pp::Token::OP_LE:
1890 type = TOK_OP_LE;
1891 break;
1892 case pp::Token::OP_RIGHT:
1893 type = TOK_OP_RIGHT;
1894 break;
1895 case pp::Token::OP_LEFT:
1896 type = TOK_OP_LEFT;
1897 break;
1898 case '|':
1899 case '^':
1900 case '&':
1901 case '>':
1902 case '<':
1903 case '-':
1904 case '+':
1905 case '%':
1906 case '/':
1907 case '*':
1908 case '!':
1909 case '~':
1910 case '(':
1911 case ')':
1912 type = token->type;
1913 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001914
Zhenyao Mod526f982014-05-13 14:51:19 -07001915 default:
1916 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001917 }
1918
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001919 return type;
1920}
1921
Zhenyao Mod526f982014-05-13 14:51:19 -07001922void yyerror(Context *context, const char *reason)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001923{
Shannon Woods7f2d7942013-11-19 15:07:58 -05001924 context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION,
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001925 context->token->location,
1926 reason);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001927}
1928
1929namespace pp {
1930
Zhenyao Mod526f982014-05-13 14:51:19 -07001931ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)
1932 : mLexer(lexer),
1933 mDiagnostics(diagnostics)
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001934{
1935}
1936
Zhenyao Mod526f982014-05-13 14:51:19 -07001937bool ExpressionParser::parse(Token *token, int *result)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001938{
1939 Context context;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001940 context.diagnostics = mDiagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001941 context.lexer = mLexer;
1942 context.token = token;
1943 context.result = result;
Olli Etuaho809ec542015-08-26 14:30:57 +03001944 context.ignoreErrors = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001945 int ret = yyparse(&context);
1946 switch (ret)
1947 {
1948 case 0:
1949 case 1:
1950 break;
1951
1952 case 2:
Shannon Woods7f2d7942013-11-19 15:07:58 -05001953 mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001954 break;
1955
1956 default:
1957 assert(false);
Shannon Woods7f2d7942013-11-19 15:07:58 -05001958 mDiagnostics->report(Diagnostics::PP_INTERNAL_ERROR, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001959 break;
1960 }
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001961
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001962 return ret == 0;
1963}
1964
1965} // namespace pp