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