blob: 9603274f147dcbb1852f204c433959a82fa9f315 [file] [log] [blame]
Zhenyao Mof1d723c2013-09-23 14:57:07 -04001/* A Bison parser, made by GNU Bison 2.7.1. */
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
alokp@chromium.org04d7d222012-05-16 19:24:07 +00004
Zhenyao Mof1d723c2013-09-23 14:57:07 -04005 Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
alokp@chromium.org04d7d222012-05-16 19:24:07 +00006
7 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.
11
12 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.
16
17 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.
29
30 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. */
Zhenyao Mof1d723c2013-09-23 14:57:07 -040047#define YYBISON_VERSION "2.7.1"
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
66#define yylval pplval
67#define yychar ppchar
68#define yydebug ppdebug
69#define yynerrs ppnerrs
70
alokp@chromium.org04d7d222012-05-16 19:24:07 +000071/* Copy the first part of user declarations. */
72
73
74//
75// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
76// Use of this source code is governed by a BSD-style license that can be
77// found in the LICENSE file.
78//
79
80// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
81
82#if defined(__GNUC__)
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000083// Triggered by the auto-generated pplval variable.
shannon.woods@transgaming.comeb68fd02013-02-28 23:20:01 +000084#if !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
daniel@transgaming.comb3077d02013-01-11 04:12:09 +000085#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
shannon.woods@transgaming.comeb68fd02013-02-28 23:20:01 +000086#else
87#pragma GCC diagnostic ignored "-Wuninitialized"
shannon.woods@transgaming.come36fddf2013-01-25 21:57:50 +000088#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +000089#elif defined(_MSC_VER)
90#pragma warning(disable: 4065 4701)
91#endif
92
93#include "ExpressionParser.h"
94
Jamie Madilld7f21352013-10-30 17:53:15 -040095#include <malloc.h>
alokp@chromium.org04d7d222012-05-16 19:24:07 +000096#include <cassert>
97#include <sstream>
98
daniel@transgaming.comb3077d02013-01-11 04:12:09 +000099#include "DiagnosticsBase.h"
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000100#include "Lexer.h"
101#include "Token.h"
102
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000103#if defined(_MSC_VER)
104typedef __int64 YYSTYPE;
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000105#else
106#include <stdint.h>
107typedef intmax_t YYSTYPE;
108#endif // _MSC_VER
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000109#define YYENABLE_NLS 0
110#define YYLTYPE_IS_TRIVIAL 1
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000111#define YYSTYPE_IS_TRIVIAL 1
112#define YYSTYPE_IS_DECLARED 1
113
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000114namespace {
115struct Context
116{
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000117 pp::Diagnostics* diagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000118 pp::Lexer* lexer;
119 pp::Token* token;
120 int* result;
121};
122} // namespace
123
124
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +0000125static int yylex(YYSTYPE* lvalp, Context* context);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000126static void yyerror(Context* context, const char* reason);
127
128
129
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000130# ifndef YY_NULL
131# if defined __cplusplus && 201103L <= __cplusplus
132# define YY_NULL nullptr
133# else
134# define YY_NULL 0
135# endif
136# endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000137
138/* Enabling verbose error messages. */
139#ifdef YYERROR_VERBOSE
140# undef YYERROR_VERBOSE
141# define YYERROR_VERBOSE 1
142#else
143# define YYERROR_VERBOSE 0
144#endif
145
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000146
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000147/* Enabling traces. */
148#ifndef YYDEBUG
149# define YYDEBUG 0
150#endif
151#if YYDEBUG
152extern int ppdebug;
153#endif
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000154
155/* Tokens. */
156#ifndef YYTOKENTYPE
157# define YYTOKENTYPE
158 /* Put the tokens into the symbol table, so that GDB and other debuggers
159 know about them. */
160 enum yytokentype {
maxvujovic@gmail.come640ef82012-07-13 18:42:40 +0000161 TOK_CONST_INT = 258,
162 TOK_OP_OR = 259,
163 TOK_OP_AND = 260,
164 TOK_OP_NE = 261,
165 TOK_OP_EQ = 262,
166 TOK_OP_GE = 263,
167 TOK_OP_LE = 264,
168 TOK_OP_RIGHT = 265,
169 TOK_OP_LEFT = 266,
170 TOK_UNARY = 267
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000171 };
172#endif
173
174
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000175#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
176typedef int YYSTYPE;
177# define YYSTYPE_IS_TRIVIAL 1
178# define yystype YYSTYPE /* obsolescent; will be withdrawn */
179# define YYSTYPE_IS_DECLARED 1
180#endif
181
182
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000183#ifdef YYPARSE_PARAM
184#if defined __STDC__ || defined __cplusplus
185int ppparse (void *YYPARSE_PARAM);
186#else
187int ppparse ();
188#endif
189#else /* ! YYPARSE_PARAM */
190#if defined __STDC__ || defined __cplusplus
191int ppparse (Context *context);
192#else
193int ppparse ();
194#endif
195#endif /* ! YYPARSE_PARAM */
196
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;
215#elif (defined __STDC__ || defined __C99__FUNC__ \
216 || defined __cplusplus || defined _MSC_VER)
217typedef signed char yytype_int8;
218#else
219typedef short int yytype_int8;
220#endif
221
222#ifdef YYTYPE_UINT16
223typedef YYTYPE_UINT16 yytype_uint16;
224#else
225typedef unsigned short int yytype_uint16;
226#endif
227
228#ifdef YYTYPE_INT16
229typedef YYTYPE_INT16 yytype_int16;
230#else
231typedef short int yytype_int16;
232#endif
233
234#ifndef YYSIZE_T
235# ifdef __SIZE_TYPE__
236# define YYSIZE_T __SIZE_TYPE__
237# elif defined size_t
238# define YYSIZE_T size_t
239# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
240 || defined __cplusplus || defined _MSC_VER)
241# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
242# define YYSIZE_T size_t
243# else
244# define YYSIZE_T unsigned int
245# endif
246#endif
247
248#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
249
250#ifndef YY_
251# if defined YYENABLE_NLS && YYENABLE_NLS
252# if ENABLE_NLS
253# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000254# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000255# endif
256# endif
257# ifndef YY_
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000258# define YY_(Msgid) Msgid
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000259# endif
260#endif
261
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400262#ifndef __attribute__
263/* This feature is available in gcc versions 2.5 and later. */
264# if (! defined __GNUC__ || __GNUC__ < 2 \
265 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
266# define __attribute__(Spec) /* empty */
267# endif
268#endif
269
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000270/* Suppress unused-variable warnings by "using" E. */
271#if ! defined lint || defined __GNUC__
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000272# define YYUSE(E) ((void) (E))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000273#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000274# define YYUSE(E) /* empty */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000275#endif
276
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400277
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000278/* Identity function, used to suppress warnings about constant conditions. */
279#ifndef lint
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000280# define YYID(N) (N)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000281#else
282#if (defined __STDC__ || defined __C99__FUNC__ \
283 || defined __cplusplus || defined _MSC_VER)
284static int
285YYID (int yyi)
286#else
287static int
288YYID (yyi)
289 int yyi;
290#endif
291{
292 return yyi;
293}
294#endif
295
296#if ! defined yyoverflow || YYERROR_VERBOSE
297
298/* The parser invokes alloca or malloc; define the necessary symbols. */
299
300# ifdef YYSTACK_USE_ALLOCA
301# if YYSTACK_USE_ALLOCA
302# ifdef __GNUC__
303# define YYSTACK_ALLOC __builtin_alloca
304# elif defined __BUILTIN_VA_ARG_INCR
305# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
306# elif defined _AIX
307# define YYSTACK_ALLOC __alloca
308# elif defined _MSC_VER
309# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
310# define alloca _alloca
311# else
312# define YYSTACK_ALLOC alloca
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000313# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000314 || defined __cplusplus || defined _MSC_VER)
315# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000316 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
317# ifndef EXIT_SUCCESS
318# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000319# endif
320# endif
321# endif
322# endif
323# endif
324
325# ifdef YYSTACK_ALLOC
326 /* Pacify GCC's `empty if-body' warning. */
327# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
328# ifndef YYSTACK_ALLOC_MAXIMUM
329 /* The OS might guarantee only one guard page at the bottom of the stack,
330 and a page size can be as small as 4096 bytes. So we cannot safely
331 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
332 to allow for a few compiler-allocated temporary stack slots. */
333# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
334# endif
335# else
336# define YYSTACK_ALLOC YYMALLOC
337# define YYSTACK_FREE YYFREE
338# ifndef YYSTACK_ALLOC_MAXIMUM
339# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
340# endif
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000341# if (defined __cplusplus && ! defined EXIT_SUCCESS \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000342 && ! ((defined YYMALLOC || defined malloc) \
343 && (defined YYFREE || defined free)))
344# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000345# ifndef EXIT_SUCCESS
346# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000347# endif
348# endif
349# ifndef YYMALLOC
350# define YYMALLOC malloc
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000351# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000352 || defined __cplusplus || defined _MSC_VER)
353void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
354# endif
355# endif
356# ifndef YYFREE
357# define YYFREE free
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000358# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000359 || defined __cplusplus || defined _MSC_VER)
360void free (void *); /* INFRINGES ON USER NAME SPACE */
361# endif
362# endif
363# endif
364#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
365
366
367#if (! defined yyoverflow \
368 && (! defined __cplusplus \
369 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
370
371/* A type that is properly aligned for any stack member. */
372union yyalloc
373{
374 yytype_int16 yyss_alloc;
375 YYSTYPE yyvs_alloc;
376};
377
378/* The size of the maximum gap between one aligned stack and the next. */
379# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
380
381/* The size of an array large to enough to hold all stacks, each with
382 N elements. */
383# define YYSTACK_BYTES(N) \
384 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
385 + YYSTACK_GAP_MAXIMUM)
386
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000387# define YYCOPY_NEEDED 1
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000388
389/* Relocate STACK from its old location to the new one. The
390 local variables YYSIZE and YYSTACKSIZE give the old and new number of
391 elements in the stack, and YYPTR gives the new location of the
392 stack. Advance YYPTR to a properly aligned location for the next
393 stack. */
394# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
395 do \
396 { \
397 YYSIZE_T yynewbytes; \
398 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
399 Stack = &yyptr->Stack_alloc; \
400 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
401 yyptr += yynewbytes / sizeof (*yyptr); \
402 } \
403 while (YYID (0))
404
405#endif
406
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000407#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
408/* Copy COUNT objects from SRC to DST. The source and destination do
409 not overlap. */
410# ifndef YYCOPY
411# if defined __GNUC__ && 1 < __GNUC__
412# define YYCOPY(Dst, Src, Count) \
413 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
414# else
415# define YYCOPY(Dst, Src, Count) \
416 do \
417 { \
418 YYSIZE_T yyi; \
419 for (yyi = 0; yyi < (Count); yyi++) \
420 (Dst)[yyi] = (Src)[yyi]; \
421 } \
422 while (YYID (0))
423# endif
424# endif
425#endif /* !YYCOPY_NEEDED */
426
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000427/* YYFINAL -- State number of the termination state. */
428#define YYFINAL 14
429/* YYLAST -- Last index in YYTABLE. */
430#define YYLAST 175
431
432/* YYNTOKENS -- Number of terminals. */
433#define YYNTOKENS 27
434/* YYNNTS -- Number of nonterminals. */
435#define YYNNTS 3
436/* YYNRULES -- Number of rules. */
437#define YYNRULES 26
438/* YYNRULES -- Number of states. */
439#define YYNSTATES 52
440
441/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
442#define YYUNDEFTOK 2
443#define YYMAXUTOK 267
444
445#define YYTRANSLATE(YYX) \
446 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
447
448/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
449static const yytype_uint8 yytranslate[] =
450{
451 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
452 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
453 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
454 2, 2, 2, 23, 2, 2, 2, 21, 8, 2,
455 25, 26, 19, 17, 2, 18, 2, 20, 2, 2,
456 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
457 11, 2, 12, 2, 2, 2, 2, 2, 2, 2,
458 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
459 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
460 2, 2, 2, 2, 7, 2, 2, 2, 2, 2,
461 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
462 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
463 2, 2, 2, 2, 6, 2, 24, 2, 2, 2,
464 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
465 2, 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,
468 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
469 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
470 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
471 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
472 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
473 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
474 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
475 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
476 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
477 5, 9, 10, 13, 14, 15, 16, 22
478};
479
480#if YYDEBUG
481/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
482 YYRHS. */
483static const yytype_uint8 yyprhs[] =
484{
485 0, 0, 3, 5, 7, 11, 15, 19, 23, 27,
486 31, 35, 39, 43, 47, 51, 55, 59, 63, 67,
487 71, 75, 79, 82, 85, 88, 91
488};
489
490/* YYRHS -- A `-1'-separated list of the rules' RHS. */
491static const yytype_int8 yyrhs[] =
492{
493 28, 0, -1, 29, -1, 3, -1, 29, 4, 29,
494 -1, 29, 5, 29, -1, 29, 6, 29, -1, 29,
495 7, 29, -1, 29, 8, 29, -1, 29, 9, 29,
496 -1, 29, 10, 29, -1, 29, 13, 29, -1, 29,
497 14, 29, -1, 29, 12, 29, -1, 29, 11, 29,
498 -1, 29, 15, 29, -1, 29, 16, 29, -1, 29,
499 18, 29, -1, 29, 17, 29, -1, 29, 21, 29,
500 -1, 29, 20, 29, -1, 29, 19, 29, -1, 23,
501 29, -1, 24, 29, -1, 18, 29, -1, 17, 29,
502 -1, 25, 29, 26, -1
503};
504
505/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
506static const yytype_uint8 yyrline[] =
507{
shannon.woods%transgaming.com@gtempaccount.combcde56f2013-04-13 03:32:12 +0000508 0, 91, 91, 98, 99, 102, 105, 108, 111, 114,
509 117, 120, 123, 126, 129, 132, 135, 138, 141, 144,
510 157, 170, 173, 176, 179, 182, 185
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000511};
512#endif
513
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000514#if YYDEBUG || YYERROR_VERBOSE || 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000515/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
516 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
517static const char *const yytname[] =
518{
maxvujovic@gmail.come640ef82012-07-13 18:42:40 +0000519 "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_OP_OR",
520 "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_NE", "TOK_OP_EQ", "'<'",
521 "'>'", "TOK_OP_GE", "TOK_OP_LE", "TOK_OP_RIGHT", "TOK_OP_LEFT", "'+'",
522 "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('", "')'",
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000523 "$accept", "input", "expression", YY_NULL
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000524};
525#endif
526
527# ifdef YYPRINT
528/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
529 token YYLEX-NUM. */
530static const yytype_uint16 yytoknum[] =
531{
532 0, 256, 257, 258, 259, 260, 124, 94, 38, 261,
533 262, 60, 62, 263, 264, 265, 266, 43, 45, 42,
534 47, 37, 267, 33, 126, 40, 41
535};
536# endif
537
538/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
539static const yytype_uint8 yyr1[] =
540{
541 0, 27, 28, 29, 29, 29, 29, 29, 29, 29,
542 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
543 29, 29, 29, 29, 29, 29, 29
544};
545
546/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
547static const yytype_uint8 yyr2[] =
548{
549 0, 2, 1, 1, 3, 3, 3, 3, 3, 3,
550 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
551 3, 3, 2, 2, 2, 2, 3
552};
553
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000554/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
555 Performed when YYTABLE doesn't specify something else to do. Zero
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000556 means the default is an error. */
557static const yytype_uint8 yydefact[] =
558{
559 0, 3, 0, 0, 0, 0, 0, 0, 2, 25,
560 24, 22, 23, 0, 1, 0, 0, 0, 0, 0,
561 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
562 0, 0, 0, 26, 4, 5, 6, 7, 8, 9,
563 10, 14, 13, 11, 12, 15, 16, 18, 17, 21,
564 20, 19
565};
566
567/* YYDEFGOTO[NTERM-NUM]. */
568static const yytype_int8 yydefgoto[] =
569{
570 -1, 7, 8
571};
572
573/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
574 STATE-NUM. */
575#define YYPACT_NINF -11
576static const yytype_int16 yypact[] =
577{
578 46, -11, 46, 46, 46, 46, 46, 12, 68, -11,
579 -11, -11, -11, 27, -11, 46, 46, 46, 46, 46,
580 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
581 46, 46, 46, -11, 85, 101, 116, 130, 143, 154,
582 154, -10, -10, -10, -10, 37, 37, 31, 31, -11,
583 -11, -11
584};
585
586/* YYPGOTO[NTERM-NUM]. */
587static const yytype_int8 yypgoto[] =
588{
589 -11, -11, -2
590};
591
592/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
593 positive, shift that token. If negative, reduce the rule which
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000594 number is the opposite. If YYTABLE_NINF, syntax error. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000595#define YYTABLE_NINF -1
596static const yytype_uint8 yytable[] =
597{
598 9, 10, 11, 12, 13, 26, 27, 28, 29, 30,
599 31, 32, 14, 34, 35, 36, 37, 38, 39, 40,
600 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
601 51, 15, 16, 17, 18, 19, 20, 21, 22, 23,
602 24, 25, 26, 27, 28, 29, 30, 31, 32, 1,
603 30, 31, 32, 33, 28, 29, 30, 31, 32, 0,
604 0, 0, 0, 2, 3, 0, 0, 0, 0, 4,
605 5, 6, 15, 16, 17, 18, 19, 20, 21, 22,
606 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
607 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
608 26, 27, 28, 29, 30, 31, 32, 17, 18, 19,
609 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
610 30, 31, 32, 18, 19, 20, 21, 22, 23, 24,
611 25, 26, 27, 28, 29, 30, 31, 32, 19, 20,
612 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
613 31, 32, 20, 21, 22, 23, 24, 25, 26, 27,
614 28, 29, 30, 31, 32, 22, 23, 24, 25, 26,
615 27, 28, 29, 30, 31, 32
616};
617
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000618#define yypact_value_is_default(Yystate) \
619 (!!((Yystate) == (-11)))
620
621#define yytable_value_is_error(Yytable_value) \
622 YYID (0)
623
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000624static const yytype_int8 yycheck[] =
625{
626 2, 3, 4, 5, 6, 15, 16, 17, 18, 19,
627 20, 21, 0, 15, 16, 17, 18, 19, 20, 21,
628 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
629 32, 4, 5, 6, 7, 8, 9, 10, 11, 12,
630 13, 14, 15, 16, 17, 18, 19, 20, 21, 3,
631 19, 20, 21, 26, 17, 18, 19, 20, 21, -1,
632 -1, -1, -1, 17, 18, -1, -1, -1, -1, 23,
633 24, 25, 4, 5, 6, 7, 8, 9, 10, 11,
634 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
635 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
636 15, 16, 17, 18, 19, 20, 21, 6, 7, 8,
637 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
638 19, 20, 21, 7, 8, 9, 10, 11, 12, 13,
639 14, 15, 16, 17, 18, 19, 20, 21, 8, 9,
640 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
641 20, 21, 9, 10, 11, 12, 13, 14, 15, 16,
642 17, 18, 19, 20, 21, 11, 12, 13, 14, 15,
643 16, 17, 18, 19, 20, 21
644};
645
646/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
647 symbol of state STATE-NUM. */
648static const yytype_uint8 yystos[] =
649{
650 0, 3, 17, 18, 23, 24, 25, 28, 29, 29,
651 29, 29, 29, 29, 0, 4, 5, 6, 7, 8,
652 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
653 19, 20, 21, 26, 29, 29, 29, 29, 29, 29,
654 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
655 29, 29
656};
657
658#define yyerrok (yyerrstatus = 0)
659#define yyclearin (yychar = YYEMPTY)
660#define YYEMPTY (-2)
661#define YYEOF 0
662
663#define YYACCEPT goto yyacceptlab
664#define YYABORT goto yyabortlab
665#define YYERROR goto yyerrorlab
666
667
668/* Like YYERROR except do call yyerror. This remains here temporarily
669 to ease the transition to the new meaning of YYERROR, for GCC.
670 Once GCC version 2 has supplanted version 1, this can go. However,
671 YYFAIL appears to be in use. Nevertheless, it is formally deprecated
672 in Bison 2.4.2's NEWS entry, where a plan to phase it out is
673 discussed. */
674
675#define YYFAIL goto yyerrlab
676#if defined YYFAIL
677 /* This is here to suppress warnings from the GCC cpp's
678 -Wunused-macros. Normally we don't worry about that warning, but
679 some users do, and we want to make it easy for users to remove
680 YYFAIL uses, which will produce warnings from Bison 2.5. */
681#endif
682
683#define YYRECOVERING() (!!yyerrstatus)
684
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000685#define YYBACKUP(Token, Value) \
686do \
687 if (yychar == YYEMPTY) \
688 { \
689 yychar = (Token); \
690 yylval = (Value); \
691 YYPOPSTACK (yylen); \
692 yystate = *yyssp; \
693 goto yybackup; \
694 } \
695 else \
696 { \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000697 yyerror (context, YY_("syntax error: cannot back up")); \
698 YYERROR; \
699 } \
700while (YYID (0))
701
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000702/* Error token number */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000703#define YYTERROR 1
704#define YYERRCODE 256
705
706
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000707/* This macro is provided for backward compatibility. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000708#ifndef YY_LOCATION_PRINT
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000709# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000710#endif
711
712
713/* YYLEX -- calling `yylex' with the right arguments. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000714#ifdef YYLEX_PARAM
715# define YYLEX yylex (&yylval, YYLEX_PARAM)
716#else
717# define YYLEX yylex (&yylval, context)
718#endif
719
720/* Enable debugging if requested. */
721#if YYDEBUG
722
723# ifndef YYFPRINTF
724# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
725# define YYFPRINTF fprintf
726# endif
727
728# define YYDPRINTF(Args) \
729do { \
730 if (yydebug) \
731 YYFPRINTF Args; \
732} while (YYID (0))
733
734# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
735do { \
736 if (yydebug) \
737 { \
738 YYFPRINTF (stderr, "%s ", Title); \
739 yy_symbol_print (stderr, \
740 Type, Value, context); \
741 YYFPRINTF (stderr, "\n"); \
742 } \
743} while (YYID (0))
744
745
746/*--------------------------------.
747| Print this symbol on YYOUTPUT. |
748`--------------------------------*/
749
750/*ARGSUSED*/
751#if (defined __STDC__ || defined __C99__FUNC__ \
752 || defined __cplusplus || defined _MSC_VER)
753static void
754yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
755#else
756static void
757yy_symbol_value_print (yyoutput, yytype, yyvaluep, context)
758 FILE *yyoutput;
759 int yytype;
760 YYSTYPE const * const yyvaluep;
761 Context *context;
762#endif
763{
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000764 FILE *yyo = yyoutput;
765 YYUSE (yyo);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000766 if (!yyvaluep)
767 return;
768 YYUSE (context);
769# ifdef YYPRINT
770 if (yytype < YYNTOKENS)
771 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
772# else
773 YYUSE (yyoutput);
774# endif
Zhenyao Mof1d723c2013-09-23 14:57:07 -0400775 YYUSE (yytype);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000776}
777
778
779/*--------------------------------.
780| Print this symbol on YYOUTPUT. |
781`--------------------------------*/
782
783#if (defined __STDC__ || defined __C99__FUNC__ \
784 || defined __cplusplus || defined _MSC_VER)
785static void
786yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
787#else
788static void
789yy_symbol_print (yyoutput, yytype, yyvaluep, context)
790 FILE *yyoutput;
791 int yytype;
792 YYSTYPE const * const yyvaluep;
793 Context *context;
794#endif
795{
796 if (yytype < YYNTOKENS)
797 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
798 else
799 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
800
801 yy_symbol_value_print (yyoutput, yytype, yyvaluep, context);
802 YYFPRINTF (yyoutput, ")");
803}
804
805/*------------------------------------------------------------------.
806| yy_stack_print -- Print the state stack from its BOTTOM up to its |
807| TOP (included). |
808`------------------------------------------------------------------*/
809
810#if (defined __STDC__ || defined __C99__FUNC__ \
811 || defined __cplusplus || defined _MSC_VER)
812static void
813yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
814#else
815static void
816yy_stack_print (yybottom, yytop)
817 yytype_int16 *yybottom;
818 yytype_int16 *yytop;
819#endif
820{
821 YYFPRINTF (stderr, "Stack now");
822 for (; yybottom <= yytop; yybottom++)
823 {
824 int yybot = *yybottom;
825 YYFPRINTF (stderr, " %d", yybot);
826 }
827 YYFPRINTF (stderr, "\n");
828}
829
830# define YY_STACK_PRINT(Bottom, Top) \
831do { \
832 if (yydebug) \
833 yy_stack_print ((Bottom), (Top)); \
834} while (YYID (0))
835
836
837/*------------------------------------------------.
838| Report that the YYRULE is going to be reduced. |
839`------------------------------------------------*/
840
841#if (defined __STDC__ || defined __C99__FUNC__ \
842 || defined __cplusplus || defined _MSC_VER)
843static void
844yy_reduce_print (YYSTYPE *yyvsp, int yyrule, Context *context)
845#else
846static void
847yy_reduce_print (yyvsp, yyrule, context)
848 YYSTYPE *yyvsp;
849 int yyrule;
850 Context *context;
851#endif
852{
853 int yynrhs = yyr2[yyrule];
854 int yyi;
855 unsigned long int yylno = yyrline[yyrule];
856 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
857 yyrule - 1, yylno);
858 /* The symbols being reduced. */
859 for (yyi = 0; yyi < yynrhs; yyi++)
860 {
861 YYFPRINTF (stderr, " $%d = ", yyi + 1);
862 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
863 &(yyvsp[(yyi + 1) - (yynrhs)])
864 , context);
865 YYFPRINTF (stderr, "\n");
866 }
867}
868
869# define YY_REDUCE_PRINT(Rule) \
870do { \
871 if (yydebug) \
872 yy_reduce_print (yyvsp, Rule, context); \
873} while (YYID (0))
874
875/* Nonzero means print parse trace. It is left uninitialized so that
876 multiple parsers can coexist. */
877int yydebug;
878#else /* !YYDEBUG */
879# define YYDPRINTF(Args)
880# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
881# define YY_STACK_PRINT(Bottom, Top)
882# define YY_REDUCE_PRINT(Rule)
883#endif /* !YYDEBUG */
884
885
886/* YYINITDEPTH -- initial size of the parser's stacks. */
887#ifndef YYINITDEPTH
888# define YYINITDEPTH 200
889#endif
890
891/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
892 if the built-in stack extension method is used).
893
894 Do not make this value too large; the results are undefined if
895 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
896 evaluated with infinite-precision integer arithmetic. */
897
898#ifndef YYMAXDEPTH
899# define YYMAXDEPTH 10000
900#endif
901
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000902
903#if YYERROR_VERBOSE
904
905# ifndef yystrlen
906# if defined __GLIBC__ && defined _STRING_H
907# define yystrlen strlen
908# else
909/* Return the length of YYSTR. */
910#if (defined __STDC__ || defined __C99__FUNC__ \
911 || defined __cplusplus || defined _MSC_VER)
912static YYSIZE_T
913yystrlen (const char *yystr)
914#else
915static YYSIZE_T
916yystrlen (yystr)
917 const char *yystr;
918#endif
919{
920 YYSIZE_T yylen;
921 for (yylen = 0; yystr[yylen]; yylen++)
922 continue;
923 return yylen;
924}
925# endif
926# endif
927
928# ifndef yystpcpy
929# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
930# define yystpcpy stpcpy
931# else
932/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
933 YYDEST. */
934#if (defined __STDC__ || defined __C99__FUNC__ \
935 || defined __cplusplus || defined _MSC_VER)
936static char *
937yystpcpy (char *yydest, const char *yysrc)
938#else
939static char *
940yystpcpy (yydest, yysrc)
941 char *yydest;
942 const char *yysrc;
943#endif
944{
945 char *yyd = yydest;
946 const char *yys = yysrc;
947
948 while ((*yyd++ = *yys++) != '\0')
949 continue;
950
951 return yyd - 1;
952}
953# endif
954# endif
955
956# ifndef yytnamerr
957/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
958 quotes and backslashes, so that it's suitable for yyerror. The
959 heuristic is that double-quoting is unnecessary unless the string
960 contains an apostrophe, a comma, or backslash (other than
961 backslash-backslash). YYSTR is taken from yytname. If YYRES is
962 null, do not copy; instead, return the length of what the result
963 would have been. */
964static YYSIZE_T
965yytnamerr (char *yyres, const char *yystr)
966{
967 if (*yystr == '"')
968 {
969 YYSIZE_T yyn = 0;
970 char const *yyp = yystr;
971
972 for (;;)
973 switch (*++yyp)
974 {
975 case '\'':
976 case ',':
977 goto do_not_strip_quotes;
978
979 case '\\':
980 if (*++yyp != '\\')
981 goto do_not_strip_quotes;
982 /* Fall through. */
983 default:
984 if (yyres)
985 yyres[yyn] = *yyp;
986 yyn++;
987 break;
988
989 case '"':
990 if (yyres)
991 yyres[yyn] = '\0';
992 return yyn;
993 }
994 do_not_strip_quotes: ;
995 }
996
997 if (! yyres)
998 return yystrlen (yystr);
999
1000 return yystpcpy (yyres, yystr) - yyres;
1001}
1002# endif
1003
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001004/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1005 about the unexpected token YYTOKEN for the state stack whose top is
1006 YYSSP.
1007
1008 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1009 not large enough to hold the message. In that case, also set
1010 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1011 required number of bytes is too large to store. */
1012static int
1013yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1014 yytype_int16 *yyssp, int yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001015{
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001016 YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1017 YYSIZE_T yysize = yysize0;
1018 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1019 /* Internationalized format string. */
1020 const char *yyformat = YY_NULL;
1021 /* Arguments of yyformat. */
1022 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1023 /* Number of reported tokens (one for the "unexpected", one per
1024 "expected"). */
1025 int yycount = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001026
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001027 /* There are many possibilities here to consider:
1028 - Assume YYFAIL is not used. It's too flawed to consider. See
1029 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1030 for details. YYERROR is fine as it does not invoke this
1031 function.
1032 - If this state is a consistent state with a default action, then
1033 the only way this function was invoked is if the default action
1034 is an error action. In that case, don't check for expected
1035 tokens because there are none.
1036 - The only way there can be no lookahead present (in yychar) is if
1037 this state is a consistent state with a default action. Thus,
1038 detecting the absence of a lookahead is sufficient to determine
1039 that there is no unexpected or expected token to report. In that
1040 case, just report a simple "syntax error".
1041 - Don't assume there isn't a lookahead just because this state is a
1042 consistent state with a default action. There might have been a
1043 previous inconsistent state, consistent state with a non-default
1044 action, or user semantic action that manipulated yychar.
1045 - Of course, the expected token list depends on states to have
1046 correct lookahead information, and it depends on the parser not
1047 to perform extra reductions after fetching a lookahead from the
1048 scanner and before detecting a syntax error. Thus, state merging
1049 (from LALR or IELR) and default reductions corrupt the expected
1050 token list. However, the list is correct for canonical LR with
1051 one exception: it will still contain any token that will not be
1052 accepted due to an error action in a later state.
1053 */
1054 if (yytoken != YYEMPTY)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001055 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001056 int yyn = yypact[*yyssp];
1057 yyarg[yycount++] = yytname[yytoken];
1058 if (!yypact_value_is_default (yyn))
1059 {
1060 /* Start YYX at -YYN if negative to avoid negative indexes in
1061 YYCHECK. In other words, skip the first -YYN actions for
1062 this state because they are default actions. */
1063 int yyxbegin = yyn < 0 ? -yyn : 0;
1064 /* Stay within bounds of both yycheck and yytname. */
1065 int yychecklim = YYLAST - yyn + 1;
1066 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1067 int yyx;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001068
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001069 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1070 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1071 && !yytable_value_is_error (yytable[yyx + yyn]))
1072 {
1073 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1074 {
1075 yycount = 1;
1076 yysize = yysize0;
1077 break;
1078 }
1079 yyarg[yycount++] = yytname[yyx];
1080 {
1081 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1082 if (! (yysize <= yysize1
1083 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1084 return 2;
1085 yysize = yysize1;
1086 }
1087 }
1088 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001089 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001090
1091 switch (yycount)
1092 {
1093# define YYCASE_(N, S) \
1094 case N: \
1095 yyformat = S; \
1096 break
1097 YYCASE_(0, YY_("syntax error"));
1098 YYCASE_(1, YY_("syntax error, unexpected %s"));
1099 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1100 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1101 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1102 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1103# undef YYCASE_
1104 }
1105
1106 {
1107 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1108 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1109 return 2;
1110 yysize = yysize1;
1111 }
1112
1113 if (*yymsg_alloc < yysize)
1114 {
1115 *yymsg_alloc = 2 * yysize;
1116 if (! (yysize <= *yymsg_alloc
1117 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1118 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1119 return 1;
1120 }
1121
1122 /* Avoid sprintf, as that infringes on the user's name space.
1123 Don't have undefined behavior even if the translation
1124 produced a string with the wrong number of "%s"s. */
1125 {
1126 char *yyp = *yymsg;
1127 int yyi = 0;
1128 while ((*yyp = *yyformat) != '\0')
1129 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1130 {
1131 yyp += yytnamerr (yyp, yyarg[yyi++]);
1132 yyformat += 2;
1133 }
1134 else
1135 {
1136 yyp++;
1137 yyformat++;
1138 }
1139 }
1140 return 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001141}
1142#endif /* YYERROR_VERBOSE */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001143
1144/*-----------------------------------------------.
1145| Release the memory associated to this symbol. |
1146`-----------------------------------------------*/
1147
1148/*ARGSUSED*/
1149#if (defined __STDC__ || defined __C99__FUNC__ \
1150 || defined __cplusplus || defined _MSC_VER)
1151static void
1152yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)
1153#else
1154static void
1155yydestruct (yymsg, yytype, yyvaluep, context)
1156 const char *yymsg;
1157 int yytype;
1158 YYSTYPE *yyvaluep;
1159 Context *context;
1160#endif
1161{
1162 YYUSE (yyvaluep);
1163 YYUSE (context);
1164
1165 if (!yymsg)
1166 yymsg = "Deleting";
1167 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1168
Zhenyao Mof1d723c2013-09-23 14:57:07 -04001169 YYUSE (yytype);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001170}
1171
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001172
1173
1174
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001175/*----------.
1176| yyparse. |
1177`----------*/
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001178
1179#ifdef YYPARSE_PARAM
1180#if (defined __STDC__ || defined __C99__FUNC__ \
1181 || defined __cplusplus || defined _MSC_VER)
1182int
1183yyparse (void *YYPARSE_PARAM)
1184#else
1185int
1186yyparse (YYPARSE_PARAM)
1187 void *YYPARSE_PARAM;
1188#endif
1189#else /* ! YYPARSE_PARAM */
1190#if (defined __STDC__ || defined __C99__FUNC__ \
1191 || defined __cplusplus || defined _MSC_VER)
1192int
1193yyparse (Context *context)
1194#else
1195int
1196yyparse (context)
1197 Context *context;
1198#endif
1199#endif
1200{
1201/* The lookahead symbol. */
1202int yychar;
1203
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001204
1205#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
1206/* Suppress an incorrect diagnostic about yylval being uninitialized. */
1207# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
1208 _Pragma ("GCC diagnostic push") \
1209 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
1210 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
1211# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
1212 _Pragma ("GCC diagnostic pop")
1213#else
1214/* Default value used for initialization, for pacifying older GCCs
1215 or non-GCC compilers. */
1216static YYSTYPE yyval_default;
1217# define YY_INITIAL_VALUE(Value) = Value
1218#endif
1219#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1220# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1221# define YY_IGNORE_MAYBE_UNINITIALIZED_END
1222#endif
1223#ifndef YY_INITIAL_VALUE
1224# define YY_INITIAL_VALUE(Value) /* Nothing. */
1225#endif
1226
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001227/* The semantic value of the lookahead symbol. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001228YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001229
1230 /* Number of syntax errors so far. */
1231 int yynerrs;
1232
1233 int yystate;
1234 /* Number of tokens to shift before error messages enabled. */
1235 int yyerrstatus;
1236
1237 /* The stacks and their tools:
1238 `yyss': related to states.
1239 `yyvs': related to semantic values.
1240
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001241 Refer to the stacks through separate pointers, to allow yyoverflow
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001242 to reallocate them elsewhere. */
1243
1244 /* The state stack. */
1245 yytype_int16 yyssa[YYINITDEPTH];
1246 yytype_int16 *yyss;
1247 yytype_int16 *yyssp;
1248
1249 /* The semantic value stack. */
1250 YYSTYPE yyvsa[YYINITDEPTH];
1251 YYSTYPE *yyvs;
1252 YYSTYPE *yyvsp;
1253
1254 YYSIZE_T yystacksize;
1255
1256 int yyn;
1257 int yyresult;
1258 /* Lookahead token as an internal (translated) token number. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001259 int yytoken = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001260 /* The variables used to return semantic value and location from the
1261 action routines. */
1262 YYSTYPE yyval;
1263
1264#if YYERROR_VERBOSE
1265 /* Buffer for error messages, and its allocated size. */
1266 char yymsgbuf[128];
1267 char *yymsg = yymsgbuf;
1268 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1269#endif
1270
1271#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1272
1273 /* The number of symbols on the RHS of the reduced rule.
1274 Keep to zero when no symbol should be popped. */
1275 int yylen = 0;
1276
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001277 yyssp = yyss = yyssa;
1278 yyvsp = yyvs = yyvsa;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001279 yystacksize = YYINITDEPTH;
1280
1281 YYDPRINTF ((stderr, "Starting parse\n"));
1282
1283 yystate = 0;
1284 yyerrstatus = 0;
1285 yynerrs = 0;
1286 yychar = YYEMPTY; /* Cause a token to be read. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001287 goto yysetstate;
1288
1289/*------------------------------------------------------------.
1290| yynewstate -- Push a new state, which is found in yystate. |
1291`------------------------------------------------------------*/
1292 yynewstate:
1293 /* In all cases, when you get here, the value and location stacks
1294 have just been pushed. So pushing a state here evens the stacks. */
1295 yyssp++;
1296
1297 yysetstate:
1298 *yyssp = yystate;
1299
1300 if (yyss + yystacksize - 1 <= yyssp)
1301 {
1302 /* Get the current used size of the three stacks, in elements. */
1303 YYSIZE_T yysize = yyssp - yyss + 1;
1304
1305#ifdef yyoverflow
1306 {
1307 /* Give user a chance to reallocate the stack. Use copies of
1308 these so that the &'s don't force the real ones into
1309 memory. */
1310 YYSTYPE *yyvs1 = yyvs;
1311 yytype_int16 *yyss1 = yyss;
1312
1313 /* Each stack pointer address is followed by the size of the
1314 data in use in that stack, in bytes. This used to be a
1315 conditional around just the two extra args, but that might
1316 be undefined if yyoverflow is a macro. */
1317 yyoverflow (YY_("memory exhausted"),
1318 &yyss1, yysize * sizeof (*yyssp),
1319 &yyvs1, yysize * sizeof (*yyvsp),
1320 &yystacksize);
1321
1322 yyss = yyss1;
1323 yyvs = yyvs1;
1324 }
1325#else /* no yyoverflow */
1326# ifndef YYSTACK_RELOCATE
1327 goto yyexhaustedlab;
1328# else
1329 /* Extend the stack our own way. */
1330 if (YYMAXDEPTH <= yystacksize)
1331 goto yyexhaustedlab;
1332 yystacksize *= 2;
1333 if (YYMAXDEPTH < yystacksize)
1334 yystacksize = YYMAXDEPTH;
1335
1336 {
1337 yytype_int16 *yyss1 = yyss;
1338 union yyalloc *yyptr =
1339 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1340 if (! yyptr)
1341 goto yyexhaustedlab;
1342 YYSTACK_RELOCATE (yyss_alloc, yyss);
1343 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1344# undef YYSTACK_RELOCATE
1345 if (yyss1 != yyssa)
1346 YYSTACK_FREE (yyss1);
1347 }
1348# endif
1349#endif /* no yyoverflow */
1350
1351 yyssp = yyss + yysize - 1;
1352 yyvsp = yyvs + yysize - 1;
1353
1354 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1355 (unsigned long int) yystacksize));
1356
1357 if (yyss + yystacksize - 1 <= yyssp)
1358 YYABORT;
1359 }
1360
1361 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1362
1363 if (yystate == YYFINAL)
1364 YYACCEPT;
1365
1366 goto yybackup;
1367
1368/*-----------.
1369| yybackup. |
1370`-----------*/
1371yybackup:
1372
1373 /* Do appropriate processing given the current state. Read a
1374 lookahead token if we need one and don't already have one. */
1375
1376 /* First try to decide what to do without reference to lookahead token. */
1377 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001378 if (yypact_value_is_default (yyn))
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001379 goto yydefault;
1380
1381 /* Not known => get a lookahead token if don't already have one. */
1382
1383 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1384 if (yychar == YYEMPTY)
1385 {
1386 YYDPRINTF ((stderr, "Reading a token: "));
1387 yychar = YYLEX;
1388 }
1389
1390 if (yychar <= YYEOF)
1391 {
1392 yychar = yytoken = YYEOF;
1393 YYDPRINTF ((stderr, "Now at end of input.\n"));
1394 }
1395 else
1396 {
1397 yytoken = YYTRANSLATE (yychar);
1398 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1399 }
1400
1401 /* If the proper action on seeing token YYTOKEN is to reduce or to
1402 detect an error, take that action. */
1403 yyn += yytoken;
1404 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1405 goto yydefault;
1406 yyn = yytable[yyn];
1407 if (yyn <= 0)
1408 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001409 if (yytable_value_is_error (yyn))
1410 goto yyerrlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001411 yyn = -yyn;
1412 goto yyreduce;
1413 }
1414
1415 /* Count tokens shifted since error; after three, turn off error
1416 status. */
1417 if (yyerrstatus)
1418 yyerrstatus--;
1419
1420 /* Shift the lookahead token. */
1421 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1422
1423 /* Discard the shifted token. */
1424 yychar = YYEMPTY;
1425
1426 yystate = yyn;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001427 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001428 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001429 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001430
1431 goto yynewstate;
1432
1433
1434/*-----------------------------------------------------------.
1435| yydefault -- do the default action for the current state. |
1436`-----------------------------------------------------------*/
1437yydefault:
1438 yyn = yydefact[yystate];
1439 if (yyn == 0)
1440 goto yyerrlab;
1441 goto yyreduce;
1442
1443
1444/*-----------------------------.
1445| yyreduce -- Do a reduction. |
1446`-----------------------------*/
1447yyreduce:
1448 /* yyn is the number of a rule to reduce with. */
1449 yylen = yyr2[yyn];
1450
1451 /* If YYLEN is nonzero, implement the default value of the action:
1452 `$$ = $1'.
1453
1454 Otherwise, the following line sets YYVAL to garbage.
1455 This behavior is undocumented and Bison
1456 users should not rely upon it. Assigning to YYVAL
1457 unconditionally makes the parser a bit smaller, and it avoids a
1458 GCC warning that YYVAL may be used uninitialized. */
1459 yyval = yyvsp[1-yylen];
1460
1461
1462 YY_REDUCE_PRINT (yyn);
1463 switch (yyn)
1464 {
1465 case 2:
1466
1467 {
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +00001468 *(context->result) = static_cast<int>((yyvsp[(1) - (1)]));
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001469 YYACCEPT;
1470 }
1471 break;
1472
1473 case 4:
1474
1475 {
1476 (yyval) = (yyvsp[(1) - (3)]) || (yyvsp[(3) - (3)]);
1477 }
1478 break;
1479
1480 case 5:
1481
1482 {
1483 (yyval) = (yyvsp[(1) - (3)]) && (yyvsp[(3) - (3)]);
1484 }
1485 break;
1486
1487 case 6:
1488
1489 {
1490 (yyval) = (yyvsp[(1) - (3)]) | (yyvsp[(3) - (3)]);
1491 }
1492 break;
1493
1494 case 7:
1495
1496 {
1497 (yyval) = (yyvsp[(1) - (3)]) ^ (yyvsp[(3) - (3)]);
1498 }
1499 break;
1500
1501 case 8:
1502
1503 {
1504 (yyval) = (yyvsp[(1) - (3)]) & (yyvsp[(3) - (3)]);
1505 }
1506 break;
1507
1508 case 9:
1509
1510 {
1511 (yyval) = (yyvsp[(1) - (3)]) != (yyvsp[(3) - (3)]);
1512 }
1513 break;
1514
1515 case 10:
1516
1517 {
1518 (yyval) = (yyvsp[(1) - (3)]) == (yyvsp[(3) - (3)]);
1519 }
1520 break;
1521
1522 case 11:
1523
1524 {
1525 (yyval) = (yyvsp[(1) - (3)]) >= (yyvsp[(3) - (3)]);
1526 }
1527 break;
1528
1529 case 12:
1530
1531 {
1532 (yyval) = (yyvsp[(1) - (3)]) <= (yyvsp[(3) - (3)]);
1533 }
1534 break;
1535
1536 case 13:
1537
1538 {
1539 (yyval) = (yyvsp[(1) - (3)]) > (yyvsp[(3) - (3)]);
1540 }
1541 break;
1542
1543 case 14:
1544
1545 {
1546 (yyval) = (yyvsp[(1) - (3)]) < (yyvsp[(3) - (3)]);
1547 }
1548 break;
1549
1550 case 15:
1551
1552 {
1553 (yyval) = (yyvsp[(1) - (3)]) >> (yyvsp[(3) - (3)]);
1554 }
1555 break;
1556
1557 case 16:
1558
1559 {
1560 (yyval) = (yyvsp[(1) - (3)]) << (yyvsp[(3) - (3)]);
1561 }
1562 break;
1563
1564 case 17:
1565
1566 {
1567 (yyval) = (yyvsp[(1) - (3)]) - (yyvsp[(3) - (3)]);
1568 }
1569 break;
1570
1571 case 18:
1572
1573 {
1574 (yyval) = (yyvsp[(1) - (3)]) + (yyvsp[(3) - (3)]);
1575 }
1576 break;
1577
1578 case 19:
1579
1580 {
1581 if ((yyvsp[(3) - (3)]) == 0) {
alokp@chromium.org2e818912012-06-29 21:26:03 +00001582 std::ostringstream stream;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001583 stream << (yyvsp[(1) - (3)]) << " % " << (yyvsp[(3) - (3)]);
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001584 std::string text = stream.str();
Shannon Woods7f2d7942013-11-19 15:07:58 -05001585 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001586 context->token->location,
1587 text.c_str());
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001588 YYABORT;
1589 } else {
1590 (yyval) = (yyvsp[(1) - (3)]) % (yyvsp[(3) - (3)]);
1591 }
1592 }
1593 break;
1594
1595 case 20:
1596
1597 {
1598 if ((yyvsp[(3) - (3)]) == 0) {
alokp@chromium.org2e818912012-06-29 21:26:03 +00001599 std::ostringstream stream;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001600 stream << (yyvsp[(1) - (3)]) << " / " << (yyvsp[(3) - (3)]);
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001601 std::string text = stream.str();
Shannon Woods7f2d7942013-11-19 15:07:58 -05001602 context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001603 context->token->location,
1604 text.c_str());
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001605 YYABORT;
1606 } else {
1607 (yyval) = (yyvsp[(1) - (3)]) / (yyvsp[(3) - (3)]);
1608 }
1609 }
1610 break;
1611
1612 case 21:
1613
1614 {
1615 (yyval) = (yyvsp[(1) - (3)]) * (yyvsp[(3) - (3)]);
1616 }
1617 break;
1618
1619 case 22:
1620
1621 {
1622 (yyval) = ! (yyvsp[(2) - (2)]);
1623 }
1624 break;
1625
1626 case 23:
1627
1628 {
1629 (yyval) = ~ (yyvsp[(2) - (2)]);
1630 }
1631 break;
1632
1633 case 24:
1634
1635 {
1636 (yyval) = - (yyvsp[(2) - (2)]);
1637 }
1638 break;
1639
1640 case 25:
1641
1642 {
1643 (yyval) = + (yyvsp[(2) - (2)]);
1644 }
1645 break;
1646
1647 case 26:
1648
1649 {
1650 (yyval) = (yyvsp[(2) - (3)]);
1651 }
1652 break;
1653
1654
1655
1656 default: break;
1657 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001658 /* User semantic actions sometimes alter yychar, and that requires
1659 that yytoken be updated with the new translation. We take the
1660 approach of translating immediately before every use of yytoken.
1661 One alternative is translating here after every semantic action,
1662 but that translation would be missed if the semantic action invokes
1663 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1664 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1665 incorrect destructor might then be invoked immediately. In the
1666 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1667 to an incorrect destructor call or verbose syntax error message
1668 before the lookahead is translated. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001669 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1670
1671 YYPOPSTACK (yylen);
1672 yylen = 0;
1673 YY_STACK_PRINT (yyss, yyssp);
1674
1675 *++yyvsp = yyval;
1676
1677 /* Now `shift' the result of the reduction. Determine what state
1678 that goes to, based on the state we popped back to and the rule
1679 number reduced by. */
1680
1681 yyn = yyr1[yyn];
1682
1683 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1684 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1685 yystate = yytable[yystate];
1686 else
1687 yystate = yydefgoto[yyn - YYNTOKENS];
1688
1689 goto yynewstate;
1690
1691
1692/*------------------------------------.
1693| yyerrlab -- here on detecting error |
1694`------------------------------------*/
1695yyerrlab:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001696 /* Make sure we have latest lookahead translation. See comments at
1697 user semantic actions for why this is necessary. */
1698 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1699
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001700 /* If not already recovering from an error, report this error. */
1701 if (!yyerrstatus)
1702 {
1703 ++yynerrs;
1704#if ! YYERROR_VERBOSE
1705 yyerror (context, YY_("syntax error"));
1706#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001707# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1708 yyssp, yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001709 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001710 char const *yymsgp = YY_("syntax error");
1711 int yysyntax_error_status;
1712 yysyntax_error_status = YYSYNTAX_ERROR;
1713 if (yysyntax_error_status == 0)
1714 yymsgp = yymsg;
1715 else if (yysyntax_error_status == 1)
1716 {
1717 if (yymsg != yymsgbuf)
1718 YYSTACK_FREE (yymsg);
1719 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1720 if (!yymsg)
1721 {
1722 yymsg = yymsgbuf;
1723 yymsg_alloc = sizeof yymsgbuf;
1724 yysyntax_error_status = 2;
1725 }
1726 else
1727 {
1728 yysyntax_error_status = YYSYNTAX_ERROR;
1729 yymsgp = yymsg;
1730 }
1731 }
1732 yyerror (context, yymsgp);
1733 if (yysyntax_error_status == 2)
1734 goto yyexhaustedlab;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001735 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001736# undef YYSYNTAX_ERROR
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001737#endif
1738 }
1739
1740
1741
1742 if (yyerrstatus == 3)
1743 {
1744 /* If just tried and failed to reuse lookahead token after an
1745 error, discard it. */
1746
1747 if (yychar <= YYEOF)
1748 {
1749 /* Return failure if at end of input. */
1750 if (yychar == YYEOF)
1751 YYABORT;
1752 }
1753 else
1754 {
1755 yydestruct ("Error: discarding",
1756 yytoken, &yylval, context);
1757 yychar = YYEMPTY;
1758 }
1759 }
1760
1761 /* Else will try to reuse lookahead token after shifting the error
1762 token. */
1763 goto yyerrlab1;
1764
1765
1766/*---------------------------------------------------.
1767| yyerrorlab -- error raised explicitly by YYERROR. |
1768`---------------------------------------------------*/
1769yyerrorlab:
1770
1771 /* Pacify compilers like GCC when the user code never invokes
1772 YYERROR and the label yyerrorlab therefore never appears in user
1773 code. */
1774 if (/*CONSTCOND*/ 0)
1775 goto yyerrorlab;
1776
1777 /* Do not reclaim the symbols of the rule which action triggered
1778 this YYERROR. */
1779 YYPOPSTACK (yylen);
1780 yylen = 0;
1781 YY_STACK_PRINT (yyss, yyssp);
1782 yystate = *yyssp;
1783 goto yyerrlab1;
1784
1785
1786/*-------------------------------------------------------------.
1787| yyerrlab1 -- common code for both syntax error and YYERROR. |
1788`-------------------------------------------------------------*/
1789yyerrlab1:
1790 yyerrstatus = 3; /* Each real token shifted decrements this. */
1791
1792 for (;;)
1793 {
1794 yyn = yypact[yystate];
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001795 if (!yypact_value_is_default (yyn))
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001796 {
1797 yyn += YYTERROR;
1798 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1799 {
1800 yyn = yytable[yyn];
1801 if (0 < yyn)
1802 break;
1803 }
1804 }
1805
1806 /* Pop the current state because it cannot handle the error token. */
1807 if (yyssp == yyss)
1808 YYABORT;
1809
1810
1811 yydestruct ("Error: popping",
1812 yystos[yystate], yyvsp, context);
1813 YYPOPSTACK (1);
1814 yystate = *yyssp;
1815 YY_STACK_PRINT (yyss, yyssp);
1816 }
1817
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001818 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001819 *++yyvsp = yylval;
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001820 YY_IGNORE_MAYBE_UNINITIALIZED_END
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001821
1822
1823 /* Shift the error token. */
1824 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1825
1826 yystate = yyn;
1827 goto yynewstate;
1828
1829
1830/*-------------------------------------.
1831| yyacceptlab -- YYACCEPT comes here. |
1832`-------------------------------------*/
1833yyacceptlab:
1834 yyresult = 0;
1835 goto yyreturn;
1836
1837/*-----------------------------------.
1838| yyabortlab -- YYABORT comes here. |
1839`-----------------------------------*/
1840yyabortlab:
1841 yyresult = 1;
1842 goto yyreturn;
1843
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001844#if !defined yyoverflow || YYERROR_VERBOSE
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001845/*-------------------------------------------------.
1846| yyexhaustedlab -- memory exhaustion comes here. |
1847`-------------------------------------------------*/
1848yyexhaustedlab:
1849 yyerror (context, YY_("memory exhausted"));
1850 yyresult = 2;
1851 /* Fall through. */
1852#endif
1853
1854yyreturn:
1855 if (yychar != YYEMPTY)
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001856 {
1857 /* Make sure we have latest lookahead translation. See comments at
1858 user semantic actions for why this is necessary. */
1859 yytoken = YYTRANSLATE (yychar);
1860 yydestruct ("Cleanup: discarding lookahead",
1861 yytoken, &yylval, context);
1862 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001863 /* Do not reclaim the symbols of the rule which action triggered
1864 this YYABORT or YYACCEPT. */
1865 YYPOPSTACK (yylen);
1866 YY_STACK_PRINT (yyss, yyssp);
1867 while (yyssp != yyss)
1868 {
1869 yydestruct ("Cleanup: popping",
1870 yystos[*yyssp], yyvsp, context);
1871 YYPOPSTACK (1);
1872 }
1873#ifndef yyoverflow
1874 if (yyss != yyssa)
1875 YYSTACK_FREE (yyss);
1876#endif
1877#if YYERROR_VERBOSE
1878 if (yymsg != yymsgbuf)
1879 YYSTACK_FREE (yymsg);
1880#endif
1881 /* Make sure YYID is used. */
1882 return YYID (yyresult);
1883}
1884
1885
1886
1887
1888
alokp@chromium.orgd39ec4c2012-06-26 04:37:55 +00001889int yylex(YYSTYPE* lvalp, Context* context)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001890{
1891 int type = 0;
1892
1893 pp::Token* token = context->token;
1894 switch (token->type)
1895 {
1896 case pp::Token::CONST_INT:
alokp@chromium.org2e818912012-06-29 21:26:03 +00001897 {
1898 unsigned int val = 0;
1899 if (!token->uValue(&val))
1900 {
Shannon Woods7f2d7942013-11-19 15:07:58 -05001901 context->diagnostics->report(pp::Diagnostics::PP_INTEGER_OVERFLOW,
alokp@chromium.org2e818912012-06-29 21:26:03 +00001902 token->location, token->text);
1903 }
1904 *lvalp = static_cast<YYSTYPE>(val);
maxvujovic@gmail.come640ef82012-07-13 18:42:40 +00001905 type = TOK_CONST_INT;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001906 break;
alokp@chromium.org2e818912012-06-29 21:26:03 +00001907 }
maxvujovic@gmail.come640ef82012-07-13 18:42:40 +00001908 case pp::Token::OP_OR: type = TOK_OP_OR; break;
1909 case pp::Token::OP_AND: type = TOK_OP_AND; break;
1910 case pp::Token::OP_NE: type = TOK_OP_NE; break;
1911 case pp::Token::OP_EQ: type = TOK_OP_EQ; break;
1912 case pp::Token::OP_GE: type = TOK_OP_GE; break;
1913 case pp::Token::OP_LE: type = TOK_OP_LE; break;
1914 case pp::Token::OP_RIGHT: type = TOK_OP_RIGHT; break;
1915 case pp::Token::OP_LEFT: type = TOK_OP_LEFT; break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001916 case '|': type = '|'; break;
1917 case '^': type = '^'; break;
1918 case '&': type = '&'; break;
1919 case '>': type = '>'; break;
1920 case '<': type = '<'; break;
1921 case '-': type = '-'; break;
1922 case '+': type = '+'; break;
1923 case '%': type = '%'; break;
1924 case '/': type = '/'; break;
1925 case '*': type = '*'; break;
1926 case '!': type = '!'; break;
1927 case '~': type = '~'; break;
1928 case '(': type = '('; break;
1929 case ')': type = ')'; break;
1930
1931 default: break;
1932 }
1933
1934 // Advance to the next token if the current one is valid.
1935 if (type != 0) context->lexer->lex(token);
1936
1937 return type;
1938}
1939
1940void yyerror(Context* context, const char* reason)
1941{
Shannon Woods7f2d7942013-11-19 15:07:58 -05001942 context->diagnostics->report(pp::Diagnostics::PP_INVALID_EXPRESSION,
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001943 context->token->location,
1944 reason);
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001945}
1946
1947namespace pp {
1948
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001949ExpressionParser::ExpressionParser(Lexer* lexer, Diagnostics* diagnostics) :
1950 mLexer(lexer),
1951 mDiagnostics(diagnostics)
1952{
1953}
1954
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001955bool ExpressionParser::parse(Token* token, int* result)
1956{
1957 Context context;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001958 context.diagnostics = mDiagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001959 context.lexer = mLexer;
1960 context.token = token;
1961 context.result = result;
1962 int ret = yyparse(&context);
1963 switch (ret)
1964 {
1965 case 0:
1966 case 1:
1967 break;
1968
1969 case 2:
Shannon Woods7f2d7942013-11-19 15:07:58 -05001970 mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001971 break;
1972
1973 default:
1974 assert(false);
Shannon Woods7f2d7942013-11-19 15:07:58 -05001975 mDiagnostics->report(Diagnostics::PP_INTERNAL_ERROR, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001976 break;
1977 }
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001978
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001979 return ret == 0;
1980}
1981
1982} // namespace pp