blob: 67966e95de624e0d571b25640ac7e1a44e2c85ab [file] [log] [blame]
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001/* A Bison parser, made by GNU Bison 2.7. */
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
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00005 Copyright (C) 1984, 1989-1990, 2000-2012 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. */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +000047#define YYBISON_VERSION "2.7"
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
261/* Suppress unused-variable warnings by "using" E. */
262#if ! defined lint || defined __GNUC__
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000263# define YYUSE(E) ((void) (E))
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000264#else
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000265# define YYUSE(E) /* empty */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000266#endif
267
268/* Identity function, used to suppress warnings about constant conditions. */
269#ifndef lint
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000270# define YYID(N) (N)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000271#else
272#if (defined __STDC__ || defined __C99__FUNC__ \
273 || defined __cplusplus || defined _MSC_VER)
274static int
275YYID (int yyi)
276#else
277static int
278YYID (yyi)
279 int yyi;
280#endif
281{
282 return yyi;
283}
284#endif
285
286#if ! defined yyoverflow || YYERROR_VERBOSE
287
288/* The parser invokes alloca or malloc; define the necessary symbols. */
289
290# ifdef YYSTACK_USE_ALLOCA
291# if YYSTACK_USE_ALLOCA
292# ifdef __GNUC__
293# define YYSTACK_ALLOC __builtin_alloca
294# elif defined __BUILTIN_VA_ARG_INCR
295# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
296# elif defined _AIX
297# define YYSTACK_ALLOC __alloca
298# elif defined _MSC_VER
299# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
300# define alloca _alloca
301# else
302# define YYSTACK_ALLOC alloca
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000303# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000304 || defined __cplusplus || defined _MSC_VER)
305# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000306 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
307# ifndef EXIT_SUCCESS
308# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000309# endif
310# endif
311# endif
312# endif
313# endif
314
315# ifdef YYSTACK_ALLOC
316 /* Pacify GCC's `empty if-body' warning. */
317# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
318# ifndef YYSTACK_ALLOC_MAXIMUM
319 /* The OS might guarantee only one guard page at the bottom of the stack,
320 and a page size can be as small as 4096 bytes. So we cannot safely
321 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
322 to allow for a few compiler-allocated temporary stack slots. */
323# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
324# endif
325# else
326# define YYSTACK_ALLOC YYMALLOC
327# define YYSTACK_FREE YYFREE
328# ifndef YYSTACK_ALLOC_MAXIMUM
329# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
330# endif
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000331# if (defined __cplusplus && ! defined EXIT_SUCCESS \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000332 && ! ((defined YYMALLOC || defined malloc) \
333 && (defined YYFREE || defined free)))
334# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000335# ifndef EXIT_SUCCESS
336# define EXIT_SUCCESS 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000337# endif
338# endif
339# ifndef YYMALLOC
340# define YYMALLOC malloc
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000341# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000342 || defined __cplusplus || defined _MSC_VER)
343void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
344# endif
345# endif
346# ifndef YYFREE
347# define YYFREE free
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000348# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000349 || defined __cplusplus || defined _MSC_VER)
350void free (void *); /* INFRINGES ON USER NAME SPACE */
351# endif
352# endif
353# endif
354#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
355
356
357#if (! defined yyoverflow \
358 && (! defined __cplusplus \
359 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
360
361/* A type that is properly aligned for any stack member. */
362union yyalloc
363{
364 yytype_int16 yyss_alloc;
365 YYSTYPE yyvs_alloc;
366};
367
368/* The size of the maximum gap between one aligned stack and the next. */
369# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
370
371/* The size of an array large to enough to hold all stacks, each with
372 N elements. */
373# define YYSTACK_BYTES(N) \
374 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
375 + YYSTACK_GAP_MAXIMUM)
376
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000377# define YYCOPY_NEEDED 1
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000378
379/* Relocate STACK from its old location to the new one. The
380 local variables YYSIZE and YYSTACKSIZE give the old and new number of
381 elements in the stack, and YYPTR gives the new location of the
382 stack. Advance YYPTR to a properly aligned location for the next
383 stack. */
384# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
385 do \
386 { \
387 YYSIZE_T yynewbytes; \
388 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
389 Stack = &yyptr->Stack_alloc; \
390 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
391 yyptr += yynewbytes / sizeof (*yyptr); \
392 } \
393 while (YYID (0))
394
395#endif
396
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000397#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
398/* Copy COUNT objects from SRC to DST. The source and destination do
399 not overlap. */
400# ifndef YYCOPY
401# if defined __GNUC__ && 1 < __GNUC__
402# define YYCOPY(Dst, Src, Count) \
403 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
404# else
405# define YYCOPY(Dst, Src, Count) \
406 do \
407 { \
408 YYSIZE_T yyi; \
409 for (yyi = 0; yyi < (Count); yyi++) \
410 (Dst)[yyi] = (Src)[yyi]; \
411 } \
412 while (YYID (0))
413# endif
414# endif
415#endif /* !YYCOPY_NEEDED */
416
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000417/* YYFINAL -- State number of the termination state. */
418#define YYFINAL 14
419/* YYLAST -- Last index in YYTABLE. */
420#define YYLAST 175
421
422/* YYNTOKENS -- Number of terminals. */
423#define YYNTOKENS 27
424/* YYNNTS -- Number of nonterminals. */
425#define YYNNTS 3
426/* YYNRULES -- Number of rules. */
427#define YYNRULES 26
428/* YYNRULES -- Number of states. */
429#define YYNSTATES 52
430
431/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
432#define YYUNDEFTOK 2
433#define YYMAXUTOK 267
434
435#define YYTRANSLATE(YYX) \
436 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
437
438/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
439static const yytype_uint8 yytranslate[] =
440{
441 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
442 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
443 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
444 2, 2, 2, 23, 2, 2, 2, 21, 8, 2,
445 25, 26, 19, 17, 2, 18, 2, 20, 2, 2,
446 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
447 11, 2, 12, 2, 2, 2, 2, 2, 2, 2,
448 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
449 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
450 2, 2, 2, 2, 7, 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, 2, 6, 2, 24, 2, 2, 2,
454 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
455 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
456 2, 2, 2, 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, 2, 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, 2, 2, 2, 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, 1, 2, 3, 4,
467 5, 9, 10, 13, 14, 15, 16, 22
468};
469
470#if YYDEBUG
471/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
472 YYRHS. */
473static const yytype_uint8 yyprhs[] =
474{
475 0, 0, 3, 5, 7, 11, 15, 19, 23, 27,
476 31, 35, 39, 43, 47, 51, 55, 59, 63, 67,
477 71, 75, 79, 82, 85, 88, 91
478};
479
480/* YYRHS -- A `-1'-separated list of the rules' RHS. */
481static const yytype_int8 yyrhs[] =
482{
483 28, 0, -1, 29, -1, 3, -1, 29, 4, 29,
484 -1, 29, 5, 29, -1, 29, 6, 29, -1, 29,
485 7, 29, -1, 29, 8, 29, -1, 29, 9, 29,
486 -1, 29, 10, 29, -1, 29, 13, 29, -1, 29,
487 14, 29, -1, 29, 12, 29, -1, 29, 11, 29,
488 -1, 29, 15, 29, -1, 29, 16, 29, -1, 29,
489 18, 29, -1, 29, 17, 29, -1, 29, 21, 29,
490 -1, 29, 20, 29, -1, 29, 19, 29, -1, 23,
491 29, -1, 24, 29, -1, 18, 29, -1, 17, 29,
492 -1, 25, 29, 26, -1
493};
494
495/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
496static const yytype_uint8 yyrline[] =
497{
shannon.woods%transgaming.com@gtempaccount.combcde56f2013-04-13 03:32:12 +0000498 0, 91, 91, 98, 99, 102, 105, 108, 111, 114,
499 117, 120, 123, 126, 129, 132, 135, 138, 141, 144,
500 157, 170, 173, 176, 179, 182, 185
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000501};
502#endif
503
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000504#if YYDEBUG || YYERROR_VERBOSE || 0
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000505/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
506 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
507static const char *const yytname[] =
508{
maxvujovic@gmail.come640ef82012-07-13 18:42:40 +0000509 "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_OP_OR",
510 "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_NE", "TOK_OP_EQ", "'<'",
511 "'>'", "TOK_OP_GE", "TOK_OP_LE", "TOK_OP_RIGHT", "TOK_OP_LEFT", "'+'",
512 "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('", "')'",
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000513 "$accept", "input", "expression", YY_NULL
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000514};
515#endif
516
517# ifdef YYPRINT
518/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
519 token YYLEX-NUM. */
520static const yytype_uint16 yytoknum[] =
521{
522 0, 256, 257, 258, 259, 260, 124, 94, 38, 261,
523 262, 60, 62, 263, 264, 265, 266, 43, 45, 42,
524 47, 37, 267, 33, 126, 40, 41
525};
526# endif
527
528/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
529static const yytype_uint8 yyr1[] =
530{
531 0, 27, 28, 29, 29, 29, 29, 29, 29, 29,
532 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
533 29, 29, 29, 29, 29, 29, 29
534};
535
536/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
537static const yytype_uint8 yyr2[] =
538{
539 0, 2, 1, 1, 3, 3, 3, 3, 3, 3,
540 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
541 3, 3, 2, 2, 2, 2, 3
542};
543
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000544/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
545 Performed when YYTABLE doesn't specify something else to do. Zero
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000546 means the default is an error. */
547static const yytype_uint8 yydefact[] =
548{
549 0, 3, 0, 0, 0, 0, 0, 0, 2, 25,
550 24, 22, 23, 0, 1, 0, 0, 0, 0, 0,
551 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
552 0, 0, 0, 26, 4, 5, 6, 7, 8, 9,
553 10, 14, 13, 11, 12, 15, 16, 18, 17, 21,
554 20, 19
555};
556
557/* YYDEFGOTO[NTERM-NUM]. */
558static const yytype_int8 yydefgoto[] =
559{
560 -1, 7, 8
561};
562
563/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
564 STATE-NUM. */
565#define YYPACT_NINF -11
566static const yytype_int16 yypact[] =
567{
568 46, -11, 46, 46, 46, 46, 46, 12, 68, -11,
569 -11, -11, -11, 27, -11, 46, 46, 46, 46, 46,
570 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
571 46, 46, 46, -11, 85, 101, 116, 130, 143, 154,
572 154, -10, -10, -10, -10, 37, 37, 31, 31, -11,
573 -11, -11
574};
575
576/* YYPGOTO[NTERM-NUM]. */
577static const yytype_int8 yypgoto[] =
578{
579 -11, -11, -2
580};
581
582/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
583 positive, shift that token. If negative, reduce the rule which
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000584 number is the opposite. If YYTABLE_NINF, syntax error. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000585#define YYTABLE_NINF -1
586static const yytype_uint8 yytable[] =
587{
588 9, 10, 11, 12, 13, 26, 27, 28, 29, 30,
589 31, 32, 14, 34, 35, 36, 37, 38, 39, 40,
590 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
591 51, 15, 16, 17, 18, 19, 20, 21, 22, 23,
592 24, 25, 26, 27, 28, 29, 30, 31, 32, 1,
593 30, 31, 32, 33, 28, 29, 30, 31, 32, 0,
594 0, 0, 0, 2, 3, 0, 0, 0, 0, 4,
595 5, 6, 15, 16, 17, 18, 19, 20, 21, 22,
596 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
597 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
598 26, 27, 28, 29, 30, 31, 32, 17, 18, 19,
599 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
600 30, 31, 32, 18, 19, 20, 21, 22, 23, 24,
601 25, 26, 27, 28, 29, 30, 31, 32, 19, 20,
602 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
603 31, 32, 20, 21, 22, 23, 24, 25, 26, 27,
604 28, 29, 30, 31, 32, 22, 23, 24, 25, 26,
605 27, 28, 29, 30, 31, 32
606};
607
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000608#define yypact_value_is_default(Yystate) \
609 (!!((Yystate) == (-11)))
610
611#define yytable_value_is_error(Yytable_value) \
612 YYID (0)
613
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000614static const yytype_int8 yycheck[] =
615{
616 2, 3, 4, 5, 6, 15, 16, 17, 18, 19,
617 20, 21, 0, 15, 16, 17, 18, 19, 20, 21,
618 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
619 32, 4, 5, 6, 7, 8, 9, 10, 11, 12,
620 13, 14, 15, 16, 17, 18, 19, 20, 21, 3,
621 19, 20, 21, 26, 17, 18, 19, 20, 21, -1,
622 -1, -1, -1, 17, 18, -1, -1, -1, -1, 23,
623 24, 25, 4, 5, 6, 7, 8, 9, 10, 11,
624 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
625 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
626 15, 16, 17, 18, 19, 20, 21, 6, 7, 8,
627 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
628 19, 20, 21, 7, 8, 9, 10, 11, 12, 13,
629 14, 15, 16, 17, 18, 19, 20, 21, 8, 9,
630 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
631 20, 21, 9, 10, 11, 12, 13, 14, 15, 16,
632 17, 18, 19, 20, 21, 11, 12, 13, 14, 15,
633 16, 17, 18, 19, 20, 21
634};
635
636/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
637 symbol of state STATE-NUM. */
638static const yytype_uint8 yystos[] =
639{
640 0, 3, 17, 18, 23, 24, 25, 28, 29, 29,
641 29, 29, 29, 29, 0, 4, 5, 6, 7, 8,
642 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
643 19, 20, 21, 26, 29, 29, 29, 29, 29, 29,
644 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
645 29, 29
646};
647
648#define yyerrok (yyerrstatus = 0)
649#define yyclearin (yychar = YYEMPTY)
650#define YYEMPTY (-2)
651#define YYEOF 0
652
653#define YYACCEPT goto yyacceptlab
654#define YYABORT goto yyabortlab
655#define YYERROR goto yyerrorlab
656
657
658/* Like YYERROR except do call yyerror. This remains here temporarily
659 to ease the transition to the new meaning of YYERROR, for GCC.
660 Once GCC version 2 has supplanted version 1, this can go. However,
661 YYFAIL appears to be in use. Nevertheless, it is formally deprecated
662 in Bison 2.4.2's NEWS entry, where a plan to phase it out is
663 discussed. */
664
665#define YYFAIL goto yyerrlab
666#if defined YYFAIL
667 /* This is here to suppress warnings from the GCC cpp's
668 -Wunused-macros. Normally we don't worry about that warning, but
669 some users do, and we want to make it easy for users to remove
670 YYFAIL uses, which will produce warnings from Bison 2.5. */
671#endif
672
673#define YYRECOVERING() (!!yyerrstatus)
674
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000675#define YYBACKUP(Token, Value) \
676do \
677 if (yychar == YYEMPTY) \
678 { \
679 yychar = (Token); \
680 yylval = (Value); \
681 YYPOPSTACK (yylen); \
682 yystate = *yyssp; \
683 goto yybackup; \
684 } \
685 else \
686 { \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000687 yyerror (context, YY_("syntax error: cannot back up")); \
688 YYERROR; \
689 } \
690while (YYID (0))
691
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000692/* Error token number */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000693#define YYTERROR 1
694#define YYERRCODE 256
695
696
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000697/* This macro is provided for backward compatibility. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000698#ifndef YY_LOCATION_PRINT
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000699# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000700#endif
701
702
703/* YYLEX -- calling `yylex' with the right arguments. */
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000704#ifdef YYLEX_PARAM
705# define YYLEX yylex (&yylval, YYLEX_PARAM)
706#else
707# define YYLEX yylex (&yylval, context)
708#endif
709
710/* Enable debugging if requested. */
711#if YYDEBUG
712
713# ifndef YYFPRINTF
714# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
715# define YYFPRINTF fprintf
716# endif
717
718# define YYDPRINTF(Args) \
719do { \
720 if (yydebug) \
721 YYFPRINTF Args; \
722} while (YYID (0))
723
724# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
725do { \
726 if (yydebug) \
727 { \
728 YYFPRINTF (stderr, "%s ", Title); \
729 yy_symbol_print (stderr, \
730 Type, Value, context); \
731 YYFPRINTF (stderr, "\n"); \
732 } \
733} while (YYID (0))
734
735
736/*--------------------------------.
737| Print this symbol on YYOUTPUT. |
738`--------------------------------*/
739
740/*ARGSUSED*/
741#if (defined __STDC__ || defined __C99__FUNC__ \
742 || defined __cplusplus || defined _MSC_VER)
743static void
744yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
745#else
746static void
747yy_symbol_value_print (yyoutput, yytype, yyvaluep, context)
748 FILE *yyoutput;
749 int yytype;
750 YYSTYPE const * const yyvaluep;
751 Context *context;
752#endif
753{
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000754 FILE *yyo = yyoutput;
755 YYUSE (yyo);
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000756 if (!yyvaluep)
757 return;
758 YYUSE (context);
759# ifdef YYPRINT
760 if (yytype < YYNTOKENS)
761 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
762# else
763 YYUSE (yyoutput);
764# endif
765 switch (yytype)
766 {
767 default:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000768 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000769 }
770}
771
772
773/*--------------------------------.
774| Print this symbol on YYOUTPUT. |
775`--------------------------------*/
776
777#if (defined __STDC__ || defined __C99__FUNC__ \
778 || defined __cplusplus || defined _MSC_VER)
779static void
780yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context)
781#else
782static void
783yy_symbol_print (yyoutput, yytype, yyvaluep, context)
784 FILE *yyoutput;
785 int yytype;
786 YYSTYPE const * const yyvaluep;
787 Context *context;
788#endif
789{
790 if (yytype < YYNTOKENS)
791 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
792 else
793 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
794
795 yy_symbol_value_print (yyoutput, yytype, yyvaluep, context);
796 YYFPRINTF (yyoutput, ")");
797}
798
799/*------------------------------------------------------------------.
800| yy_stack_print -- Print the state stack from its BOTTOM up to its |
801| TOP (included). |
802`------------------------------------------------------------------*/
803
804#if (defined __STDC__ || defined __C99__FUNC__ \
805 || defined __cplusplus || defined _MSC_VER)
806static void
807yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
808#else
809static void
810yy_stack_print (yybottom, yytop)
811 yytype_int16 *yybottom;
812 yytype_int16 *yytop;
813#endif
814{
815 YYFPRINTF (stderr, "Stack now");
816 for (; yybottom <= yytop; yybottom++)
817 {
818 int yybot = *yybottom;
819 YYFPRINTF (stderr, " %d", yybot);
820 }
821 YYFPRINTF (stderr, "\n");
822}
823
824# define YY_STACK_PRINT(Bottom, Top) \
825do { \
826 if (yydebug) \
827 yy_stack_print ((Bottom), (Top)); \
828} while (YYID (0))
829
830
831/*------------------------------------------------.
832| Report that the YYRULE is going to be reduced. |
833`------------------------------------------------*/
834
835#if (defined __STDC__ || defined __C99__FUNC__ \
836 || defined __cplusplus || defined _MSC_VER)
837static void
838yy_reduce_print (YYSTYPE *yyvsp, int yyrule, Context *context)
839#else
840static void
841yy_reduce_print (yyvsp, yyrule, context)
842 YYSTYPE *yyvsp;
843 int yyrule;
844 Context *context;
845#endif
846{
847 int yynrhs = yyr2[yyrule];
848 int yyi;
849 unsigned long int yylno = yyrline[yyrule];
850 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
851 yyrule - 1, yylno);
852 /* The symbols being reduced. */
853 for (yyi = 0; yyi < yynrhs; yyi++)
854 {
855 YYFPRINTF (stderr, " $%d = ", yyi + 1);
856 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
857 &(yyvsp[(yyi + 1) - (yynrhs)])
858 , context);
859 YYFPRINTF (stderr, "\n");
860 }
861}
862
863# define YY_REDUCE_PRINT(Rule) \
864do { \
865 if (yydebug) \
866 yy_reduce_print (yyvsp, Rule, context); \
867} while (YYID (0))
868
869/* Nonzero means print parse trace. It is left uninitialized so that
870 multiple parsers can coexist. */
871int yydebug;
872#else /* !YYDEBUG */
873# define YYDPRINTF(Args)
874# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
875# define YY_STACK_PRINT(Bottom, Top)
876# define YY_REDUCE_PRINT(Rule)
877#endif /* !YYDEBUG */
878
879
880/* YYINITDEPTH -- initial size of the parser's stacks. */
881#ifndef YYINITDEPTH
882# define YYINITDEPTH 200
883#endif
884
885/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
886 if the built-in stack extension method is used).
887
888 Do not make this value too large; the results are undefined if
889 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
890 evaluated with infinite-precision integer arithmetic. */
891
892#ifndef YYMAXDEPTH
893# define YYMAXDEPTH 10000
894#endif
895
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000896
897#if YYERROR_VERBOSE
898
899# ifndef yystrlen
900# if defined __GLIBC__ && defined _STRING_H
901# define yystrlen strlen
902# else
903/* Return the length of YYSTR. */
904#if (defined __STDC__ || defined __C99__FUNC__ \
905 || defined __cplusplus || defined _MSC_VER)
906static YYSIZE_T
907yystrlen (const char *yystr)
908#else
909static YYSIZE_T
910yystrlen (yystr)
911 const char *yystr;
912#endif
913{
914 YYSIZE_T yylen;
915 for (yylen = 0; yystr[yylen]; yylen++)
916 continue;
917 return yylen;
918}
919# endif
920# endif
921
922# ifndef yystpcpy
923# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
924# define yystpcpy stpcpy
925# else
926/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
927 YYDEST. */
928#if (defined __STDC__ || defined __C99__FUNC__ \
929 || defined __cplusplus || defined _MSC_VER)
930static char *
931yystpcpy (char *yydest, const char *yysrc)
932#else
933static char *
934yystpcpy (yydest, yysrc)
935 char *yydest;
936 const char *yysrc;
937#endif
938{
939 char *yyd = yydest;
940 const char *yys = yysrc;
941
942 while ((*yyd++ = *yys++) != '\0')
943 continue;
944
945 return yyd - 1;
946}
947# endif
948# endif
949
950# ifndef yytnamerr
951/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
952 quotes and backslashes, so that it's suitable for yyerror. The
953 heuristic is that double-quoting is unnecessary unless the string
954 contains an apostrophe, a comma, or backslash (other than
955 backslash-backslash). YYSTR is taken from yytname. If YYRES is
956 null, do not copy; instead, return the length of what the result
957 would have been. */
958static YYSIZE_T
959yytnamerr (char *yyres, const char *yystr)
960{
961 if (*yystr == '"')
962 {
963 YYSIZE_T yyn = 0;
964 char const *yyp = yystr;
965
966 for (;;)
967 switch (*++yyp)
968 {
969 case '\'':
970 case ',':
971 goto do_not_strip_quotes;
972
973 case '\\':
974 if (*++yyp != '\\')
975 goto do_not_strip_quotes;
976 /* Fall through. */
977 default:
978 if (yyres)
979 yyres[yyn] = *yyp;
980 yyn++;
981 break;
982
983 case '"':
984 if (yyres)
985 yyres[yyn] = '\0';
986 return yyn;
987 }
988 do_not_strip_quotes: ;
989 }
990
991 if (! yyres)
992 return yystrlen (yystr);
993
994 return yystpcpy (yyres, yystr) - yyres;
995}
996# endif
997
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +0000998/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
999 about the unexpected token YYTOKEN for the state stack whose top is
1000 YYSSP.
1001
1002 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1003 not large enough to hold the message. In that case, also set
1004 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1005 required number of bytes is too large to store. */
1006static int
1007yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1008 yytype_int16 *yyssp, int yytoken)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001009{
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001010 YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1011 YYSIZE_T yysize = yysize0;
1012 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1013 /* Internationalized format string. */
1014 const char *yyformat = YY_NULL;
1015 /* Arguments of yyformat. */
1016 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1017 /* Number of reported tokens (one for the "unexpected", one per
1018 "expected"). */
1019 int yycount = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001020
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001021 /* There are many possibilities here to consider:
1022 - Assume YYFAIL is not used. It's too flawed to consider. See
1023 <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1024 for details. YYERROR is fine as it does not invoke this
1025 function.
1026 - If this state is a consistent state with a default action, then
1027 the only way this function was invoked is if the default action
1028 is an error action. In that case, don't check for expected
1029 tokens because there are none.
1030 - The only way there can be no lookahead present (in yychar) is if
1031 this state is a consistent state with a default action. Thus,
1032 detecting the absence of a lookahead is sufficient to determine
1033 that there is no unexpected or expected token to report. In that
1034 case, just report a simple "syntax error".
1035 - Don't assume there isn't a lookahead just because this state is a
1036 consistent state with a default action. There might have been a
1037 previous inconsistent state, consistent state with a non-default
1038 action, or user semantic action that manipulated yychar.
1039 - Of course, the expected token list depends on states to have
1040 correct lookahead information, and it depends on the parser not
1041 to perform extra reductions after fetching a lookahead from the
1042 scanner and before detecting a syntax error. Thus, state merging
1043 (from LALR or IELR) and default reductions corrupt the expected
1044 token list. However, the list is correct for canonical LR with
1045 one exception: it will still contain any token that will not be
1046 accepted due to an error action in a later state.
1047 */
1048 if (yytoken != YYEMPTY)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001049 {
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001050 int yyn = yypact[*yyssp];
1051 yyarg[yycount++] = yytname[yytoken];
1052 if (!yypact_value_is_default (yyn))
1053 {
1054 /* Start YYX at -YYN if negative to avoid negative indexes in
1055 YYCHECK. In other words, skip the first -YYN actions for
1056 this state because they are default actions. */
1057 int yyxbegin = yyn < 0 ? -yyn : 0;
1058 /* Stay within bounds of both yycheck and yytname. */
1059 int yychecklim = YYLAST - yyn + 1;
1060 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1061 int yyx;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001062
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001063 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1064 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1065 && !yytable_value_is_error (yytable[yyx + yyn]))
1066 {
1067 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1068 {
1069 yycount = 1;
1070 yysize = yysize0;
1071 break;
1072 }
1073 yyarg[yycount++] = yytname[yyx];
1074 {
1075 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1076 if (! (yysize <= yysize1
1077 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1078 return 2;
1079 yysize = yysize1;
1080 }
1081 }
1082 }
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001083 }
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001084
1085 switch (yycount)
1086 {
1087# define YYCASE_(N, S) \
1088 case N: \
1089 yyformat = S; \
1090 break
1091 YYCASE_(0, YY_("syntax error"));
1092 YYCASE_(1, YY_("syntax error, unexpected %s"));
1093 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1094 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1095 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1096 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1097# undef YYCASE_
1098 }
1099
1100 {
1101 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1102 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1103 return 2;
1104 yysize = yysize1;
1105 }
1106
1107 if (*yymsg_alloc < yysize)
1108 {
1109 *yymsg_alloc = 2 * yysize;
1110 if (! (yysize <= *yymsg_alloc
1111 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1112 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1113 return 1;
1114 }
1115
1116 /* Avoid sprintf, as that infringes on the user's name space.
1117 Don't have undefined behavior even if the translation
1118 produced a string with the wrong number of "%s"s. */
1119 {
1120 char *yyp = *yymsg;
1121 int yyi = 0;
1122 while ((*yyp = *yyformat) != '\0')
1123 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1124 {
1125 yyp += yytnamerr (yyp, yyarg[yyi++]);
1126 yyformat += 2;
1127 }
1128 else
1129 {
1130 yyp++;
1131 yyformat++;
1132 }
1133 }
1134 return 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001135}
1136#endif /* YYERROR_VERBOSE */
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001137
1138/*-----------------------------------------------.
1139| Release the memory associated to this symbol. |
1140`-----------------------------------------------*/
1141
1142/*ARGSUSED*/
1143#if (defined __STDC__ || defined __C99__FUNC__ \
1144 || defined __cplusplus || defined _MSC_VER)
1145static void
1146yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)
1147#else
1148static void
1149yydestruct (yymsg, yytype, yyvaluep, context)
1150 const char *yymsg;
1151 int yytype;
1152 YYSTYPE *yyvaluep;
1153 Context *context;
1154#endif
1155{
1156 YYUSE (yyvaluep);
1157 YYUSE (context);
1158
1159 if (!yymsg)
1160 yymsg = "Deleting";
1161 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1162
1163 switch (yytype)
1164 {
1165
1166 default:
shannonwoods@chromium.org4b8a3112013-05-30 00:13:01 +00001167 break;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001168 }
1169}
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();
1584 context->diagnostics->report(pp::Diagnostics::DIVISION_BY_ZERO,
1585 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();
1601 context->diagnostics->report(pp::Diagnostics::DIVISION_BY_ZERO,
1602 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 {
1900 context->diagnostics->report(pp::Diagnostics::INTEGER_OVERFLOW,
1901 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{
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001941 context->diagnostics->report(pp::Diagnostics::INVALID_EXPRESSION,
1942 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:
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001969 mDiagnostics->report(Diagnostics::OUT_OF_MEMORY, token->location, "");
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001970 break;
1971
1972 default:
1973 assert(false);
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00001974 mDiagnostics->report(Diagnostics::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