alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1 | /* A Bison parser, made by GNU Bison 2.4.2. */ |
| 2 | |
| 3 | /* Skeleton implementation for Bison's Yacc-like parsers in C |
| 4 | |
| 5 | Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software |
| 6 | Foundation, Inc. |
| 7 | |
| 8 | This program is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | /* As a special exception, you may create a larger work that contains |
| 22 | part or all of the Bison parser skeleton and distribute that work |
| 23 | under terms of your choice, so long as that work isn't itself a |
| 24 | parser generator using the skeleton or a modified version thereof |
| 25 | as a parser skeleton. Alternatively, if you modify or redistribute |
| 26 | the parser skeleton itself, you may (at your option) remove this |
| 27 | special exception, which will cause the skeleton and the resulting |
| 28 | Bison output files to be licensed under the GNU General Public |
| 29 | License without this special exception. |
| 30 | |
| 31 | This special exception was added by the Free Software Foundation in |
| 32 | version 2.2 of Bison. */ |
| 33 | |
| 34 | /* C LALR(1) parser skeleton written by Richard Stallman, by |
| 35 | simplifying the original so-called "semantic" parser. */ |
| 36 | |
| 37 | /* All symbols defined below should begin with yy or YY, to avoid |
| 38 | infringing on user name space. This should be done even for local |
| 39 | variables, as they might otherwise be expanded by user macros. |
| 40 | There are some unavoidable exceptions within include files to |
| 41 | define necessary library symbols; they are noted "INFRINGES ON |
| 42 | USER NAME SPACE" below. */ |
| 43 | |
| 44 | /* Identify Bison output. */ |
| 45 | #define YYBISON 1 |
| 46 | |
| 47 | /* Bison version. */ |
| 48 | #define YYBISON_VERSION "2.4.2" |
| 49 | |
| 50 | /* Skeleton name. */ |
| 51 | #define YYSKELETON_NAME "yacc.c" |
| 52 | |
| 53 | /* Pure parsers. */ |
| 54 | #define YYPURE 1 |
| 55 | |
| 56 | /* Push parsers. */ |
| 57 | #define YYPUSH 0 |
| 58 | |
| 59 | /* Pull parsers. */ |
| 60 | #define YYPULL 1 |
| 61 | |
| 62 | /* Using locations. */ |
| 63 | #define YYLSP_NEEDED 0 |
| 64 | |
| 65 | /* Substitute the variable and function names. */ |
| 66 | #define yyparse ppparse |
| 67 | #define yylex pplex |
| 68 | #define yyerror pperror |
| 69 | #define yylval pplval |
| 70 | #define yychar ppchar |
| 71 | #define yydebug ppdebug |
| 72 | #define yynerrs ppnerrs |
| 73 | |
| 74 | |
| 75 | /* Copy the first part of user declarations. */ |
| 76 | |
| 77 | |
| 78 | // |
| 79 | // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
| 80 | // Use of this source code is governed by a BSD-style license that can be |
| 81 | // found in the LICENSE file. |
| 82 | // |
| 83 | |
| 84 | // This file is auto-generated by generate_parser.sh. DO NOT EDIT! |
| 85 | |
| 86 | #if defined(__GNUC__) |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 87 | #pragma GCC diagnostic ignored "-Wunknown-pragmas" |
maxvujovic@gmail.com | c6b3b3c | 2012-06-27 22:49:39 +0000 | [diff] [blame] | 88 | // Triggered by the auto-generated pplval variable. |
| 89 | #pragma GCC diagnostic ignored "-Wuninitialized" |
shannon.woods@transgaming.com | e36fddf | 2013-01-25 21:57:50 +0000 | [diff] [blame] | 90 | #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 91 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" |
shannon.woods@transgaming.com | e36fddf | 2013-01-25 21:57:50 +0000 | [diff] [blame] | 92 | #endif |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 93 | #pragma GCC diagnostic warning "-Wunknown-pragmas" |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 94 | #elif defined(_MSC_VER) |
| 95 | #pragma warning(disable: 4065 4701) |
| 96 | #endif |
| 97 | |
| 98 | #include "ExpressionParser.h" |
| 99 | |
| 100 | #include <cassert> |
| 101 | #include <sstream> |
| 102 | |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 103 | #include "DiagnosticsBase.h" |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 104 | #include "Lexer.h" |
| 105 | #include "Token.h" |
| 106 | |
alokp@chromium.org | d39ec4c | 2012-06-26 04:37:55 +0000 | [diff] [blame] | 107 | #if defined(_MSC_VER) |
| 108 | typedef __int64 YYSTYPE; |
alokp@chromium.org | d39ec4c | 2012-06-26 04:37:55 +0000 | [diff] [blame] | 109 | #else |
| 110 | #include <stdint.h> |
| 111 | typedef intmax_t YYSTYPE; |
| 112 | #endif // _MSC_VER |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 113 | #define YYENABLE_NLS 0 |
| 114 | #define YYLTYPE_IS_TRIVIAL 1 |
alokp@chromium.org | d39ec4c | 2012-06-26 04:37:55 +0000 | [diff] [blame] | 115 | #define YYSTYPE_IS_TRIVIAL 1 |
| 116 | #define YYSTYPE_IS_DECLARED 1 |
| 117 | |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 118 | namespace { |
| 119 | struct Context |
| 120 | { |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 121 | pp::Diagnostics* diagnostics; |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 122 | pp::Lexer* lexer; |
| 123 | pp::Token* token; |
| 124 | int* result; |
| 125 | }; |
| 126 | } // namespace |
| 127 | |
| 128 | |
alokp@chromium.org | d39ec4c | 2012-06-26 04:37:55 +0000 | [diff] [blame] | 129 | static int yylex(YYSTYPE* lvalp, Context* context); |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 130 | static void yyerror(Context* context, const char* reason); |
| 131 | |
| 132 | |
| 133 | |
| 134 | /* Enabling traces. */ |
| 135 | #ifndef YYDEBUG |
| 136 | # define YYDEBUG 0 |
| 137 | #endif |
| 138 | |
| 139 | /* Enabling verbose error messages. */ |
| 140 | #ifdef YYERROR_VERBOSE |
| 141 | # undef YYERROR_VERBOSE |
| 142 | # define YYERROR_VERBOSE 1 |
| 143 | #else |
| 144 | # define YYERROR_VERBOSE 0 |
| 145 | #endif |
| 146 | |
| 147 | /* Enabling the token table. */ |
| 148 | #ifndef YYTOKEN_TABLE |
| 149 | # define YYTOKEN_TABLE 0 |
| 150 | #endif |
| 151 | |
| 152 | |
| 153 | /* Tokens. */ |
| 154 | #ifndef YYTOKENTYPE |
| 155 | # define YYTOKENTYPE |
| 156 | /* Put the tokens into the symbol table, so that GDB and other debuggers |
| 157 | know about them. */ |
| 158 | enum yytokentype { |
maxvujovic@gmail.com | e640ef8 | 2012-07-13 18:42:40 +0000 | [diff] [blame] | 159 | TOK_CONST_INT = 258, |
| 160 | TOK_OP_OR = 259, |
| 161 | TOK_OP_AND = 260, |
| 162 | TOK_OP_NE = 261, |
| 163 | TOK_OP_EQ = 262, |
| 164 | TOK_OP_GE = 263, |
| 165 | TOK_OP_LE = 264, |
| 166 | TOK_OP_RIGHT = 265, |
| 167 | TOK_OP_LEFT = 266, |
| 168 | TOK_UNARY = 267 |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 169 | }; |
| 170 | #endif |
| 171 | |
| 172 | |
| 173 | |
| 174 | #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED |
| 175 | typedef 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 | |
| 182 | /* Copy the second part of user declarations. */ |
| 183 | |
| 184 | |
| 185 | |
| 186 | #ifdef short |
| 187 | # undef short |
| 188 | #endif |
| 189 | |
| 190 | #ifdef YYTYPE_UINT8 |
| 191 | typedef YYTYPE_UINT8 yytype_uint8; |
| 192 | #else |
| 193 | typedef unsigned char yytype_uint8; |
| 194 | #endif |
| 195 | |
| 196 | #ifdef YYTYPE_INT8 |
| 197 | typedef YYTYPE_INT8 yytype_int8; |
| 198 | #elif (defined __STDC__ || defined __C99__FUNC__ \ |
| 199 | || defined __cplusplus || defined _MSC_VER) |
| 200 | typedef signed char yytype_int8; |
| 201 | #else |
| 202 | typedef short int yytype_int8; |
| 203 | #endif |
| 204 | |
| 205 | #ifdef YYTYPE_UINT16 |
| 206 | typedef YYTYPE_UINT16 yytype_uint16; |
| 207 | #else |
| 208 | typedef unsigned short int yytype_uint16; |
| 209 | #endif |
| 210 | |
| 211 | #ifdef YYTYPE_INT16 |
| 212 | typedef YYTYPE_INT16 yytype_int16; |
| 213 | #else |
| 214 | typedef short int yytype_int16; |
| 215 | #endif |
| 216 | |
| 217 | #ifndef YYSIZE_T |
| 218 | # ifdef __SIZE_TYPE__ |
| 219 | # define YYSIZE_T __SIZE_TYPE__ |
| 220 | # elif defined size_t |
| 221 | # define YYSIZE_T size_t |
| 222 | # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ |
| 223 | || defined __cplusplus || defined _MSC_VER) |
| 224 | # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ |
| 225 | # define YYSIZE_T size_t |
| 226 | # else |
| 227 | # define YYSIZE_T unsigned int |
| 228 | # endif |
| 229 | #endif |
| 230 | |
| 231 | #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) |
| 232 | |
| 233 | #ifndef YY_ |
| 234 | # if defined YYENABLE_NLS && YYENABLE_NLS |
| 235 | # if ENABLE_NLS |
| 236 | # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ |
| 237 | # define YY_(msgid) dgettext ("bison-runtime", msgid) |
| 238 | # endif |
| 239 | # endif |
| 240 | # ifndef YY_ |
| 241 | # define YY_(msgid) msgid |
| 242 | # endif |
| 243 | #endif |
| 244 | |
| 245 | /* Suppress unused-variable warnings by "using" E. */ |
| 246 | #if ! defined lint || defined __GNUC__ |
| 247 | # define YYUSE(e) ((void) (e)) |
| 248 | #else |
| 249 | # define YYUSE(e) /* empty */ |
| 250 | #endif |
| 251 | |
| 252 | /* Identity function, used to suppress warnings about constant conditions. */ |
| 253 | #ifndef lint |
| 254 | # define YYID(n) (n) |
| 255 | #else |
| 256 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 257 | || defined __cplusplus || defined _MSC_VER) |
| 258 | static int |
| 259 | YYID (int yyi) |
| 260 | #else |
| 261 | static int |
| 262 | YYID (yyi) |
| 263 | int yyi; |
| 264 | #endif |
| 265 | { |
| 266 | return yyi; |
| 267 | } |
| 268 | #endif |
| 269 | |
| 270 | #if ! defined yyoverflow || YYERROR_VERBOSE |
| 271 | |
| 272 | /* The parser invokes alloca or malloc; define the necessary symbols. */ |
| 273 | |
| 274 | # ifdef YYSTACK_USE_ALLOCA |
| 275 | # if YYSTACK_USE_ALLOCA |
| 276 | # ifdef __GNUC__ |
| 277 | # define YYSTACK_ALLOC __builtin_alloca |
| 278 | # elif defined __BUILTIN_VA_ARG_INCR |
| 279 | # include <alloca.h> /* INFRINGES ON USER NAME SPACE */ |
| 280 | # elif defined _AIX |
| 281 | # define YYSTACK_ALLOC __alloca |
| 282 | # elif defined _MSC_VER |
| 283 | # include <malloc.h> /* INFRINGES ON USER NAME SPACE */ |
| 284 | # define alloca _alloca |
| 285 | # else |
| 286 | # define YYSTACK_ALLOC alloca |
| 287 | # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ |
| 288 | || defined __cplusplus || defined _MSC_VER) |
| 289 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
| 290 | # ifndef _STDLIB_H |
| 291 | # define _STDLIB_H 1 |
| 292 | # endif |
| 293 | # endif |
| 294 | # endif |
| 295 | # endif |
| 296 | # endif |
| 297 | |
| 298 | # ifdef YYSTACK_ALLOC |
| 299 | /* Pacify GCC's `empty if-body' warning. */ |
| 300 | # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) |
| 301 | # ifndef YYSTACK_ALLOC_MAXIMUM |
| 302 | /* The OS might guarantee only one guard page at the bottom of the stack, |
| 303 | and a page size can be as small as 4096 bytes. So we cannot safely |
| 304 | invoke alloca (N) if N exceeds 4096. Use a slightly smaller number |
| 305 | to allow for a few compiler-allocated temporary stack slots. */ |
| 306 | # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ |
| 307 | # endif |
| 308 | # else |
| 309 | # define YYSTACK_ALLOC YYMALLOC |
| 310 | # define YYSTACK_FREE YYFREE |
| 311 | # ifndef YYSTACK_ALLOC_MAXIMUM |
| 312 | # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM |
| 313 | # endif |
| 314 | # if (defined __cplusplus && ! defined _STDLIB_H \ |
| 315 | && ! ((defined YYMALLOC || defined malloc) \ |
| 316 | && (defined YYFREE || defined free))) |
| 317 | # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ |
| 318 | # ifndef _STDLIB_H |
| 319 | # define _STDLIB_H 1 |
| 320 | # endif |
| 321 | # endif |
| 322 | # ifndef YYMALLOC |
| 323 | # define YYMALLOC malloc |
| 324 | # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ |
| 325 | || defined __cplusplus || defined _MSC_VER) |
| 326 | void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ |
| 327 | # endif |
| 328 | # endif |
| 329 | # ifndef YYFREE |
| 330 | # define YYFREE free |
| 331 | # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ |
| 332 | || defined __cplusplus || defined _MSC_VER) |
| 333 | void free (void *); /* INFRINGES ON USER NAME SPACE */ |
| 334 | # endif |
| 335 | # endif |
| 336 | # endif |
| 337 | #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ |
| 338 | |
| 339 | |
| 340 | #if (! defined yyoverflow \ |
| 341 | && (! defined __cplusplus \ |
| 342 | || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) |
| 343 | |
| 344 | /* A type that is properly aligned for any stack member. */ |
| 345 | union yyalloc |
| 346 | { |
| 347 | yytype_int16 yyss_alloc; |
| 348 | YYSTYPE yyvs_alloc; |
| 349 | }; |
| 350 | |
| 351 | /* The size of the maximum gap between one aligned stack and the next. */ |
| 352 | # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) |
| 353 | |
| 354 | /* The size of an array large to enough to hold all stacks, each with |
| 355 | N elements. */ |
| 356 | # define YYSTACK_BYTES(N) \ |
| 357 | ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ |
| 358 | + YYSTACK_GAP_MAXIMUM) |
| 359 | |
| 360 | /* Copy COUNT objects from FROM to TO. The source and destination do |
| 361 | not overlap. */ |
| 362 | # ifndef YYCOPY |
| 363 | # if defined __GNUC__ && 1 < __GNUC__ |
| 364 | # define YYCOPY(To, From, Count) \ |
| 365 | __builtin_memcpy (To, From, (Count) * sizeof (*(From))) |
| 366 | # else |
| 367 | # define YYCOPY(To, From, Count) \ |
| 368 | do \ |
| 369 | { \ |
| 370 | YYSIZE_T yyi; \ |
| 371 | for (yyi = 0; yyi < (Count); yyi++) \ |
| 372 | (To)[yyi] = (From)[yyi]; \ |
| 373 | } \ |
| 374 | while (YYID (0)) |
| 375 | # endif |
| 376 | # endif |
| 377 | |
| 378 | /* Relocate STACK from its old location to the new one. The |
| 379 | local variables YYSIZE and YYSTACKSIZE give the old and new number of |
| 380 | elements in the stack, and YYPTR gives the new location of the |
| 381 | stack. Advance YYPTR to a properly aligned location for the next |
| 382 | stack. */ |
| 383 | # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ |
| 384 | do \ |
| 385 | { \ |
| 386 | YYSIZE_T yynewbytes; \ |
| 387 | YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ |
| 388 | Stack = &yyptr->Stack_alloc; \ |
| 389 | yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ |
| 390 | yyptr += yynewbytes / sizeof (*yyptr); \ |
| 391 | } \ |
| 392 | while (YYID (0)) |
| 393 | |
| 394 | #endif |
| 395 | |
| 396 | /* YYFINAL -- State number of the termination state. */ |
| 397 | #define YYFINAL 14 |
| 398 | /* YYLAST -- Last index in YYTABLE. */ |
| 399 | #define YYLAST 175 |
| 400 | |
| 401 | /* YYNTOKENS -- Number of terminals. */ |
| 402 | #define YYNTOKENS 27 |
| 403 | /* YYNNTS -- Number of nonterminals. */ |
| 404 | #define YYNNTS 3 |
| 405 | /* YYNRULES -- Number of rules. */ |
| 406 | #define YYNRULES 26 |
| 407 | /* YYNRULES -- Number of states. */ |
| 408 | #define YYNSTATES 52 |
| 409 | |
| 410 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
| 411 | #define YYUNDEFTOK 2 |
| 412 | #define YYMAXUTOK 267 |
| 413 | |
| 414 | #define YYTRANSLATE(YYX) \ |
| 415 | ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) |
| 416 | |
| 417 | /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ |
| 418 | static const yytype_uint8 yytranslate[] = |
| 419 | { |
| 420 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 421 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 422 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 423 | 2, 2, 2, 23, 2, 2, 2, 21, 8, 2, |
| 424 | 25, 26, 19, 17, 2, 18, 2, 20, 2, 2, |
| 425 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 426 | 11, 2, 12, 2, 2, 2, 2, 2, 2, 2, |
| 427 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 428 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 429 | 2, 2, 2, 2, 7, 2, 2, 2, 2, 2, |
| 430 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 431 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 432 | 2, 2, 2, 2, 6, 2, 24, 2, 2, 2, |
| 433 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 434 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 435 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 436 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 437 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 438 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 439 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 440 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 441 | 2, 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, 2, 2, 2, 2, 2, 2, 2, |
| 445 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
| 446 | 5, 9, 10, 13, 14, 15, 16, 22 |
| 447 | }; |
| 448 | |
| 449 | #if YYDEBUG |
| 450 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in |
| 451 | YYRHS. */ |
| 452 | static const yytype_uint8 yyprhs[] = |
| 453 | { |
| 454 | 0, 0, 3, 5, 7, 11, 15, 19, 23, 27, |
| 455 | 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, |
| 456 | 71, 75, 79, 82, 85, 88, 91 |
| 457 | }; |
| 458 | |
| 459 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
| 460 | static const yytype_int8 yyrhs[] = |
| 461 | { |
| 462 | 28, 0, -1, 29, -1, 3, -1, 29, 4, 29, |
| 463 | -1, 29, 5, 29, -1, 29, 6, 29, -1, 29, |
| 464 | 7, 29, -1, 29, 8, 29, -1, 29, 9, 29, |
| 465 | -1, 29, 10, 29, -1, 29, 13, 29, -1, 29, |
| 466 | 14, 29, -1, 29, 12, 29, -1, 29, 11, 29, |
| 467 | -1, 29, 15, 29, -1, 29, 16, 29, -1, 29, |
| 468 | 18, 29, -1, 29, 17, 29, -1, 29, 21, 29, |
| 469 | -1, 29, 20, 29, -1, 29, 19, 29, -1, 23, |
| 470 | 29, -1, 24, 29, -1, 18, 29, -1, 17, 29, |
| 471 | -1, 25, 29, 26, -1 |
| 472 | }; |
| 473 | |
| 474 | /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ |
| 475 | static const yytype_uint8 yyrline[] = |
| 476 | { |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 477 | 0, 90, 90, 97, 98, 101, 104, 107, 110, 113, |
| 478 | 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, |
| 479 | 156, 169, 172, 175, 178, 181, 184 |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 480 | }; |
| 481 | #endif |
| 482 | |
| 483 | #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE |
| 484 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
| 485 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
| 486 | static const char *const yytname[] = |
| 487 | { |
maxvujovic@gmail.com | e640ef8 | 2012-07-13 18:42:40 +0000 | [diff] [blame] | 488 | "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_OP_OR", |
| 489 | "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_NE", "TOK_OP_EQ", "'<'", |
| 490 | "'>'", "TOK_OP_GE", "TOK_OP_LE", "TOK_OP_RIGHT", "TOK_OP_LEFT", "'+'", |
| 491 | "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('", "')'", |
| 492 | "$accept", "input", "expression", 0 |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 493 | }; |
| 494 | #endif |
| 495 | |
| 496 | # ifdef YYPRINT |
| 497 | /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to |
| 498 | token YYLEX-NUM. */ |
| 499 | static const yytype_uint16 yytoknum[] = |
| 500 | { |
| 501 | 0, 256, 257, 258, 259, 260, 124, 94, 38, 261, |
| 502 | 262, 60, 62, 263, 264, 265, 266, 43, 45, 42, |
| 503 | 47, 37, 267, 33, 126, 40, 41 |
| 504 | }; |
| 505 | # endif |
| 506 | |
| 507 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ |
| 508 | static const yytype_uint8 yyr1[] = |
| 509 | { |
| 510 | 0, 27, 28, 29, 29, 29, 29, 29, 29, 29, |
| 511 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, |
| 512 | 29, 29, 29, 29, 29, 29, 29 |
| 513 | }; |
| 514 | |
| 515 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ |
| 516 | static const yytype_uint8 yyr2[] = |
| 517 | { |
| 518 | 0, 2, 1, 1, 3, 3, 3, 3, 3, 3, |
| 519 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
| 520 | 3, 3, 2, 2, 2, 2, 3 |
| 521 | }; |
| 522 | |
| 523 | /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state |
| 524 | STATE-NUM when YYTABLE doesn't specify something else to do. Zero |
| 525 | means the default is an error. */ |
| 526 | static const yytype_uint8 yydefact[] = |
| 527 | { |
| 528 | 0, 3, 0, 0, 0, 0, 0, 0, 2, 25, |
| 529 | 24, 22, 23, 0, 1, 0, 0, 0, 0, 0, |
| 530 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 531 | 0, 0, 0, 26, 4, 5, 6, 7, 8, 9, |
| 532 | 10, 14, 13, 11, 12, 15, 16, 18, 17, 21, |
| 533 | 20, 19 |
| 534 | }; |
| 535 | |
| 536 | /* YYDEFGOTO[NTERM-NUM]. */ |
| 537 | static const yytype_int8 yydefgoto[] = |
| 538 | { |
| 539 | -1, 7, 8 |
| 540 | }; |
| 541 | |
| 542 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
| 543 | STATE-NUM. */ |
| 544 | #define YYPACT_NINF -11 |
| 545 | static const yytype_int16 yypact[] = |
| 546 | { |
| 547 | 46, -11, 46, 46, 46, 46, 46, 12, 68, -11, |
| 548 | -11, -11, -11, 27, -11, 46, 46, 46, 46, 46, |
| 549 | 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, |
| 550 | 46, 46, 46, -11, 85, 101, 116, 130, 143, 154, |
| 551 | 154, -10, -10, -10, -10, 37, 37, 31, 31, -11, |
| 552 | -11, -11 |
| 553 | }; |
| 554 | |
| 555 | /* YYPGOTO[NTERM-NUM]. */ |
| 556 | static const yytype_int8 yypgoto[] = |
| 557 | { |
| 558 | -11, -11, -2 |
| 559 | }; |
| 560 | |
| 561 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If |
| 562 | positive, shift that token. If negative, reduce the rule which |
| 563 | number is the opposite. If zero, do what YYDEFACT says. |
| 564 | If YYTABLE_NINF, syntax error. */ |
| 565 | #define YYTABLE_NINF -1 |
| 566 | static const yytype_uint8 yytable[] = |
| 567 | { |
| 568 | 9, 10, 11, 12, 13, 26, 27, 28, 29, 30, |
| 569 | 31, 32, 14, 34, 35, 36, 37, 38, 39, 40, |
| 570 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, |
| 571 | 51, 15, 16, 17, 18, 19, 20, 21, 22, 23, |
| 572 | 24, 25, 26, 27, 28, 29, 30, 31, 32, 1, |
| 573 | 30, 31, 32, 33, 28, 29, 30, 31, 32, 0, |
| 574 | 0, 0, 0, 2, 3, 0, 0, 0, 0, 4, |
| 575 | 5, 6, 15, 16, 17, 18, 19, 20, 21, 22, |
| 576 | 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, |
| 577 | 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, |
| 578 | 26, 27, 28, 29, 30, 31, 32, 17, 18, 19, |
| 579 | 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 580 | 30, 31, 32, 18, 19, 20, 21, 22, 23, 24, |
| 581 | 25, 26, 27, 28, 29, 30, 31, 32, 19, 20, |
| 582 | 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, |
| 583 | 31, 32, 20, 21, 22, 23, 24, 25, 26, 27, |
| 584 | 28, 29, 30, 31, 32, 22, 23, 24, 25, 26, |
| 585 | 27, 28, 29, 30, 31, 32 |
| 586 | }; |
| 587 | |
| 588 | static const yytype_int8 yycheck[] = |
| 589 | { |
| 590 | 2, 3, 4, 5, 6, 15, 16, 17, 18, 19, |
| 591 | 20, 21, 0, 15, 16, 17, 18, 19, 20, 21, |
| 592 | 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
| 593 | 32, 4, 5, 6, 7, 8, 9, 10, 11, 12, |
| 594 | 13, 14, 15, 16, 17, 18, 19, 20, 21, 3, |
| 595 | 19, 20, 21, 26, 17, 18, 19, 20, 21, -1, |
| 596 | -1, -1, -1, 17, 18, -1, -1, -1, -1, 23, |
| 597 | 24, 25, 4, 5, 6, 7, 8, 9, 10, 11, |
| 598 | 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
| 599 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
| 600 | 15, 16, 17, 18, 19, 20, 21, 6, 7, 8, |
| 601 | 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
| 602 | 19, 20, 21, 7, 8, 9, 10, 11, 12, 13, |
| 603 | 14, 15, 16, 17, 18, 19, 20, 21, 8, 9, |
| 604 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, |
| 605 | 20, 21, 9, 10, 11, 12, 13, 14, 15, 16, |
| 606 | 17, 18, 19, 20, 21, 11, 12, 13, 14, 15, |
| 607 | 16, 17, 18, 19, 20, 21 |
| 608 | }; |
| 609 | |
| 610 | /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing |
| 611 | symbol of state STATE-NUM. */ |
| 612 | static const yytype_uint8 yystos[] = |
| 613 | { |
| 614 | 0, 3, 17, 18, 23, 24, 25, 28, 29, 29, |
| 615 | 29, 29, 29, 29, 0, 4, 5, 6, 7, 8, |
| 616 | 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
| 617 | 19, 20, 21, 26, 29, 29, 29, 29, 29, 29, |
| 618 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, |
| 619 | 29, 29 |
| 620 | }; |
| 621 | |
| 622 | #define yyerrok (yyerrstatus = 0) |
| 623 | #define yyclearin (yychar = YYEMPTY) |
| 624 | #define YYEMPTY (-2) |
| 625 | #define YYEOF 0 |
| 626 | |
| 627 | #define YYACCEPT goto yyacceptlab |
| 628 | #define YYABORT goto yyabortlab |
| 629 | #define YYERROR goto yyerrorlab |
| 630 | |
| 631 | |
| 632 | /* Like YYERROR except do call yyerror. This remains here temporarily |
| 633 | to ease the transition to the new meaning of YYERROR, for GCC. |
| 634 | Once GCC version 2 has supplanted version 1, this can go. However, |
| 635 | YYFAIL appears to be in use. Nevertheless, it is formally deprecated |
| 636 | in Bison 2.4.2's NEWS entry, where a plan to phase it out is |
| 637 | discussed. */ |
| 638 | |
| 639 | #define YYFAIL goto yyerrlab |
| 640 | #if defined YYFAIL |
| 641 | /* This is here to suppress warnings from the GCC cpp's |
| 642 | -Wunused-macros. Normally we don't worry about that warning, but |
| 643 | some users do, and we want to make it easy for users to remove |
| 644 | YYFAIL uses, which will produce warnings from Bison 2.5. */ |
| 645 | #endif |
| 646 | |
| 647 | #define YYRECOVERING() (!!yyerrstatus) |
| 648 | |
| 649 | #define YYBACKUP(Token, Value) \ |
| 650 | do \ |
| 651 | if (yychar == YYEMPTY && yylen == 1) \ |
| 652 | { \ |
| 653 | yychar = (Token); \ |
| 654 | yylval = (Value); \ |
| 655 | yytoken = YYTRANSLATE (yychar); \ |
| 656 | YYPOPSTACK (1); \ |
| 657 | goto yybackup; \ |
| 658 | } \ |
| 659 | else \ |
| 660 | { \ |
| 661 | yyerror (context, YY_("syntax error: cannot back up")); \ |
| 662 | YYERROR; \ |
| 663 | } \ |
| 664 | while (YYID (0)) |
| 665 | |
| 666 | |
| 667 | #define YYTERROR 1 |
| 668 | #define YYERRCODE 256 |
| 669 | |
| 670 | |
| 671 | /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. |
| 672 | If N is 0, then set CURRENT to the empty location which ends |
| 673 | the previous symbol: RHS[0] (always defined). */ |
| 674 | |
| 675 | #define YYRHSLOC(Rhs, K) ((Rhs)[K]) |
| 676 | #ifndef YYLLOC_DEFAULT |
| 677 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ |
| 678 | do \ |
| 679 | if (YYID (N)) \ |
| 680 | { \ |
| 681 | (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ |
| 682 | (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ |
| 683 | (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ |
| 684 | (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ |
| 685 | } \ |
| 686 | else \ |
| 687 | { \ |
| 688 | (Current).first_line = (Current).last_line = \ |
| 689 | YYRHSLOC (Rhs, 0).last_line; \ |
| 690 | (Current).first_column = (Current).last_column = \ |
| 691 | YYRHSLOC (Rhs, 0).last_column; \ |
| 692 | } \ |
| 693 | while (YYID (0)) |
| 694 | #endif |
| 695 | |
| 696 | |
| 697 | /* YY_LOCATION_PRINT -- Print the location on the stream. |
| 698 | This macro was not mandated originally: define only if we know |
| 699 | we won't break user code: when these are the locations we know. */ |
| 700 | |
| 701 | #ifndef YY_LOCATION_PRINT |
| 702 | # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL |
| 703 | # define YY_LOCATION_PRINT(File, Loc) \ |
| 704 | fprintf (File, "%d.%d-%d.%d", \ |
| 705 | (Loc).first_line, (Loc).first_column, \ |
| 706 | (Loc).last_line, (Loc).last_column) |
| 707 | # else |
| 708 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) |
| 709 | # endif |
| 710 | #endif |
| 711 | |
| 712 | |
| 713 | /* YYLEX -- calling `yylex' with the right arguments. */ |
| 714 | |
| 715 | #ifdef YYLEX_PARAM |
| 716 | # define YYLEX yylex (&yylval, YYLEX_PARAM) |
| 717 | #else |
| 718 | # define YYLEX yylex (&yylval, context) |
| 719 | #endif |
| 720 | |
| 721 | /* Enable debugging if requested. */ |
| 722 | #if YYDEBUG |
| 723 | |
| 724 | # ifndef YYFPRINTF |
| 725 | # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ |
| 726 | # define YYFPRINTF fprintf |
| 727 | # endif |
| 728 | |
| 729 | # define YYDPRINTF(Args) \ |
| 730 | do { \ |
| 731 | if (yydebug) \ |
| 732 | YYFPRINTF Args; \ |
| 733 | } while (YYID (0)) |
| 734 | |
| 735 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ |
| 736 | do { \ |
| 737 | if (yydebug) \ |
| 738 | { \ |
| 739 | YYFPRINTF (stderr, "%s ", Title); \ |
| 740 | yy_symbol_print (stderr, \ |
| 741 | Type, Value, context); \ |
| 742 | YYFPRINTF (stderr, "\n"); \ |
| 743 | } \ |
| 744 | } while (YYID (0)) |
| 745 | |
| 746 | |
| 747 | /*--------------------------------. |
| 748 | | Print this symbol on YYOUTPUT. | |
| 749 | `--------------------------------*/ |
| 750 | |
| 751 | /*ARGSUSED*/ |
| 752 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 753 | || defined __cplusplus || defined _MSC_VER) |
| 754 | static void |
| 755 | yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context) |
| 756 | #else |
| 757 | static void |
| 758 | yy_symbol_value_print (yyoutput, yytype, yyvaluep, context) |
| 759 | FILE *yyoutput; |
| 760 | int yytype; |
| 761 | YYSTYPE const * const yyvaluep; |
| 762 | Context *context; |
| 763 | #endif |
| 764 | { |
| 765 | 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 |
| 774 | switch (yytype) |
| 775 | { |
| 776 | default: |
| 777 | break; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | |
| 782 | /*--------------------------------. |
| 783 | | Print this symbol on YYOUTPUT. | |
| 784 | `--------------------------------*/ |
| 785 | |
| 786 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 787 | || defined __cplusplus || defined _MSC_VER) |
| 788 | static void |
| 789 | yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, Context *context) |
| 790 | #else |
| 791 | static void |
| 792 | yy_symbol_print (yyoutput, yytype, yyvaluep, context) |
| 793 | FILE *yyoutput; |
| 794 | int yytype; |
| 795 | YYSTYPE const * const yyvaluep; |
| 796 | Context *context; |
| 797 | #endif |
| 798 | { |
| 799 | if (yytype < YYNTOKENS) |
| 800 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); |
| 801 | else |
| 802 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); |
| 803 | |
| 804 | yy_symbol_value_print (yyoutput, yytype, yyvaluep, context); |
| 805 | YYFPRINTF (yyoutput, ")"); |
| 806 | } |
| 807 | |
| 808 | /*------------------------------------------------------------------. |
| 809 | | yy_stack_print -- Print the state stack from its BOTTOM up to its | |
| 810 | | TOP (included). | |
| 811 | `------------------------------------------------------------------*/ |
| 812 | |
| 813 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 814 | || defined __cplusplus || defined _MSC_VER) |
| 815 | static void |
| 816 | yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) |
| 817 | #else |
| 818 | static void |
| 819 | yy_stack_print (yybottom, yytop) |
| 820 | yytype_int16 *yybottom; |
| 821 | yytype_int16 *yytop; |
| 822 | #endif |
| 823 | { |
| 824 | YYFPRINTF (stderr, "Stack now"); |
| 825 | for (; yybottom <= yytop; yybottom++) |
| 826 | { |
| 827 | int yybot = *yybottom; |
| 828 | YYFPRINTF (stderr, " %d", yybot); |
| 829 | } |
| 830 | YYFPRINTF (stderr, "\n"); |
| 831 | } |
| 832 | |
| 833 | # define YY_STACK_PRINT(Bottom, Top) \ |
| 834 | do { \ |
| 835 | if (yydebug) \ |
| 836 | yy_stack_print ((Bottom), (Top)); \ |
| 837 | } while (YYID (0)) |
| 838 | |
| 839 | |
| 840 | /*------------------------------------------------. |
| 841 | | Report that the YYRULE is going to be reduced. | |
| 842 | `------------------------------------------------*/ |
| 843 | |
| 844 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 845 | || defined __cplusplus || defined _MSC_VER) |
| 846 | static void |
| 847 | yy_reduce_print (YYSTYPE *yyvsp, int yyrule, Context *context) |
| 848 | #else |
| 849 | static void |
| 850 | yy_reduce_print (yyvsp, yyrule, context) |
| 851 | YYSTYPE *yyvsp; |
| 852 | int yyrule; |
| 853 | Context *context; |
| 854 | #endif |
| 855 | { |
| 856 | int yynrhs = yyr2[yyrule]; |
| 857 | int yyi; |
| 858 | unsigned long int yylno = yyrline[yyrule]; |
| 859 | YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", |
| 860 | yyrule - 1, yylno); |
| 861 | /* The symbols being reduced. */ |
| 862 | for (yyi = 0; yyi < yynrhs; yyi++) |
| 863 | { |
| 864 | YYFPRINTF (stderr, " $%d = ", yyi + 1); |
| 865 | yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], |
| 866 | &(yyvsp[(yyi + 1) - (yynrhs)]) |
| 867 | , context); |
| 868 | YYFPRINTF (stderr, "\n"); |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | # define YY_REDUCE_PRINT(Rule) \ |
| 873 | do { \ |
| 874 | if (yydebug) \ |
| 875 | yy_reduce_print (yyvsp, Rule, context); \ |
| 876 | } while (YYID (0)) |
| 877 | |
| 878 | /* Nonzero means print parse trace. It is left uninitialized so that |
| 879 | multiple parsers can coexist. */ |
| 880 | int yydebug; |
| 881 | #else /* !YYDEBUG */ |
| 882 | # define YYDPRINTF(Args) |
| 883 | # define YY_SYMBOL_PRINT(Title, Type, Value, Location) |
| 884 | # define YY_STACK_PRINT(Bottom, Top) |
| 885 | # define YY_REDUCE_PRINT(Rule) |
| 886 | #endif /* !YYDEBUG */ |
| 887 | |
| 888 | |
| 889 | /* YYINITDEPTH -- initial size of the parser's stacks. */ |
| 890 | #ifndef YYINITDEPTH |
| 891 | # define YYINITDEPTH 200 |
| 892 | #endif |
| 893 | |
| 894 | /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only |
| 895 | if the built-in stack extension method is used). |
| 896 | |
| 897 | Do not make this value too large; the results are undefined if |
| 898 | YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) |
| 899 | evaluated with infinite-precision integer arithmetic. */ |
| 900 | |
| 901 | #ifndef YYMAXDEPTH |
| 902 | # define YYMAXDEPTH 10000 |
| 903 | #endif |
| 904 | |
| 905 | |
| 906 | |
| 907 | #if YYERROR_VERBOSE |
| 908 | |
| 909 | # ifndef yystrlen |
| 910 | # if defined __GLIBC__ && defined _STRING_H |
| 911 | # define yystrlen strlen |
| 912 | # else |
| 913 | /* Return the length of YYSTR. */ |
| 914 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 915 | || defined __cplusplus || defined _MSC_VER) |
| 916 | static YYSIZE_T |
| 917 | yystrlen (const char *yystr) |
| 918 | #else |
| 919 | static YYSIZE_T |
| 920 | yystrlen (yystr) |
| 921 | const char *yystr; |
| 922 | #endif |
| 923 | { |
| 924 | YYSIZE_T yylen; |
| 925 | for (yylen = 0; yystr[yylen]; yylen++) |
| 926 | continue; |
| 927 | return yylen; |
| 928 | } |
| 929 | # endif |
| 930 | # endif |
| 931 | |
| 932 | # ifndef yystpcpy |
| 933 | # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE |
| 934 | # define yystpcpy stpcpy |
| 935 | # else |
| 936 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in |
| 937 | YYDEST. */ |
| 938 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 939 | || defined __cplusplus || defined _MSC_VER) |
| 940 | static char * |
| 941 | yystpcpy (char *yydest, const char *yysrc) |
| 942 | #else |
| 943 | static char * |
| 944 | yystpcpy (yydest, yysrc) |
| 945 | char *yydest; |
| 946 | const char *yysrc; |
| 947 | #endif |
| 948 | { |
| 949 | char *yyd = yydest; |
| 950 | const char *yys = yysrc; |
| 951 | |
| 952 | while ((*yyd++ = *yys++) != '\0') |
| 953 | continue; |
| 954 | |
| 955 | return yyd - 1; |
| 956 | } |
| 957 | # endif |
| 958 | # endif |
| 959 | |
| 960 | # ifndef yytnamerr |
| 961 | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary |
| 962 | quotes and backslashes, so that it's suitable for yyerror. The |
| 963 | heuristic is that double-quoting is unnecessary unless the string |
| 964 | contains an apostrophe, a comma, or backslash (other than |
| 965 | backslash-backslash). YYSTR is taken from yytname. If YYRES is |
| 966 | null, do not copy; instead, return the length of what the result |
| 967 | would have been. */ |
| 968 | static YYSIZE_T |
| 969 | yytnamerr (char *yyres, const char *yystr) |
| 970 | { |
| 971 | if (*yystr == '"') |
| 972 | { |
| 973 | YYSIZE_T yyn = 0; |
| 974 | char const *yyp = yystr; |
| 975 | |
| 976 | for (;;) |
| 977 | switch (*++yyp) |
| 978 | { |
| 979 | case '\'': |
| 980 | case ',': |
| 981 | goto do_not_strip_quotes; |
| 982 | |
| 983 | case '\\': |
| 984 | if (*++yyp != '\\') |
| 985 | goto do_not_strip_quotes; |
| 986 | /* Fall through. */ |
| 987 | default: |
| 988 | if (yyres) |
| 989 | yyres[yyn] = *yyp; |
| 990 | yyn++; |
| 991 | break; |
| 992 | |
| 993 | case '"': |
| 994 | if (yyres) |
| 995 | yyres[yyn] = '\0'; |
| 996 | return yyn; |
| 997 | } |
| 998 | do_not_strip_quotes: ; |
| 999 | } |
| 1000 | |
| 1001 | if (! yyres) |
| 1002 | return yystrlen (yystr); |
| 1003 | |
| 1004 | return yystpcpy (yyres, yystr) - yyres; |
| 1005 | } |
| 1006 | # endif |
| 1007 | |
| 1008 | /* Copy into YYRESULT an error message about the unexpected token |
| 1009 | YYCHAR while in state YYSTATE. Return the number of bytes copied, |
| 1010 | including the terminating null byte. If YYRESULT is null, do not |
| 1011 | copy anything; just return the number of bytes that would be |
| 1012 | copied. As a special case, return 0 if an ordinary "syntax error" |
| 1013 | message will do. Return YYSIZE_MAXIMUM if overflow occurs during |
| 1014 | size calculation. */ |
| 1015 | static YYSIZE_T |
| 1016 | yysyntax_error (char *yyresult, int yystate, int yychar) |
| 1017 | { |
| 1018 | int yyn = yypact[yystate]; |
| 1019 | |
| 1020 | if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) |
| 1021 | return 0; |
| 1022 | else |
| 1023 | { |
| 1024 | int yytype = YYTRANSLATE (yychar); |
| 1025 | YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); |
| 1026 | YYSIZE_T yysize = yysize0; |
| 1027 | YYSIZE_T yysize1; |
| 1028 | int yysize_overflow = 0; |
| 1029 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; |
| 1030 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; |
| 1031 | int yyx; |
| 1032 | |
| 1033 | # if 0 |
| 1034 | /* This is so xgettext sees the translatable formats that are |
| 1035 | constructed on the fly. */ |
| 1036 | YY_("syntax error, unexpected %s"); |
| 1037 | YY_("syntax error, unexpected %s, expecting %s"); |
| 1038 | YY_("syntax error, unexpected %s, expecting %s or %s"); |
| 1039 | YY_("syntax error, unexpected %s, expecting %s or %s or %s"); |
| 1040 | YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); |
| 1041 | # endif |
| 1042 | char *yyfmt; |
| 1043 | char const *yyf; |
| 1044 | static char const yyunexpected[] = "syntax error, unexpected %s"; |
| 1045 | static char const yyexpecting[] = ", expecting %s"; |
| 1046 | static char const yyor[] = " or %s"; |
| 1047 | char yyformat[sizeof yyunexpected |
| 1048 | + sizeof yyexpecting - 1 |
| 1049 | + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) |
| 1050 | * (sizeof yyor - 1))]; |
| 1051 | char const *yyprefix = yyexpecting; |
| 1052 | |
| 1053 | /* Start YYX at -YYN if negative to avoid negative indexes in |
| 1054 | YYCHECK. */ |
| 1055 | int yyxbegin = yyn < 0 ? -yyn : 0; |
| 1056 | |
| 1057 | /* Stay within bounds of both yycheck and yytname. */ |
| 1058 | int yychecklim = YYLAST - yyn + 1; |
| 1059 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; |
| 1060 | int yycount = 1; |
| 1061 | |
| 1062 | yyarg[0] = yytname[yytype]; |
| 1063 | yyfmt = yystpcpy (yyformat, yyunexpected); |
| 1064 | |
| 1065 | for (yyx = yyxbegin; yyx < yyxend; ++yyx) |
| 1066 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) |
| 1067 | { |
| 1068 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) |
| 1069 | { |
| 1070 | yycount = 1; |
| 1071 | yysize = yysize0; |
| 1072 | yyformat[sizeof yyunexpected - 1] = '\0'; |
| 1073 | break; |
| 1074 | } |
| 1075 | yyarg[yycount++] = yytname[yyx]; |
| 1076 | yysize1 = yysize + yytnamerr (0, yytname[yyx]); |
| 1077 | yysize_overflow |= (yysize1 < yysize); |
| 1078 | yysize = yysize1; |
| 1079 | yyfmt = yystpcpy (yyfmt, yyprefix); |
| 1080 | yyprefix = yyor; |
| 1081 | } |
| 1082 | |
| 1083 | yyf = YY_(yyformat); |
| 1084 | yysize1 = yysize + yystrlen (yyf); |
| 1085 | yysize_overflow |= (yysize1 < yysize); |
| 1086 | yysize = yysize1; |
| 1087 | |
| 1088 | if (yysize_overflow) |
| 1089 | return YYSIZE_MAXIMUM; |
| 1090 | |
| 1091 | if (yyresult) |
| 1092 | { |
| 1093 | /* Avoid sprintf, as that infringes on the user's name space. |
| 1094 | Don't have undefined behavior even if the translation |
| 1095 | produced a string with the wrong number of "%s"s. */ |
| 1096 | char *yyp = yyresult; |
| 1097 | int yyi = 0; |
| 1098 | while ((*yyp = *yyf) != '\0') |
| 1099 | { |
| 1100 | if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) |
| 1101 | { |
| 1102 | yyp += yytnamerr (yyp, yyarg[yyi++]); |
| 1103 | yyf += 2; |
| 1104 | } |
| 1105 | else |
| 1106 | { |
| 1107 | yyp++; |
| 1108 | yyf++; |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | return yysize; |
| 1113 | } |
| 1114 | } |
| 1115 | #endif /* YYERROR_VERBOSE */ |
| 1116 | |
| 1117 | |
| 1118 | /*-----------------------------------------------. |
| 1119 | | Release the memory associated to this symbol. | |
| 1120 | `-----------------------------------------------*/ |
| 1121 | |
| 1122 | /*ARGSUSED*/ |
| 1123 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 1124 | || defined __cplusplus || defined _MSC_VER) |
| 1125 | static void |
| 1126 | yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context) |
| 1127 | #else |
| 1128 | static void |
| 1129 | yydestruct (yymsg, yytype, yyvaluep, context) |
| 1130 | const char *yymsg; |
| 1131 | int yytype; |
| 1132 | YYSTYPE *yyvaluep; |
| 1133 | Context *context; |
| 1134 | #endif |
| 1135 | { |
| 1136 | YYUSE (yyvaluep); |
| 1137 | YYUSE (context); |
| 1138 | |
| 1139 | if (!yymsg) |
| 1140 | yymsg = "Deleting"; |
| 1141 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); |
| 1142 | |
| 1143 | switch (yytype) |
| 1144 | { |
| 1145 | |
| 1146 | default: |
| 1147 | break; |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | /* Prevent warnings from -Wmissing-prototypes. */ |
| 1152 | #ifdef YYPARSE_PARAM |
| 1153 | #if defined __STDC__ || defined __cplusplus |
| 1154 | int yyparse (void *YYPARSE_PARAM); |
| 1155 | #else |
| 1156 | int yyparse (); |
| 1157 | #endif |
| 1158 | #else /* ! YYPARSE_PARAM */ |
| 1159 | #if defined __STDC__ || defined __cplusplus |
| 1160 | int yyparse (Context *context); |
| 1161 | #else |
| 1162 | int yyparse (); |
| 1163 | #endif |
| 1164 | #endif /* ! YYPARSE_PARAM */ |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | /*-------------------------. |
| 1171 | | yyparse or yypush_parse. | |
| 1172 | `-------------------------*/ |
| 1173 | |
| 1174 | #ifdef YYPARSE_PARAM |
| 1175 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 1176 | || defined __cplusplus || defined _MSC_VER) |
| 1177 | int |
| 1178 | yyparse (void *YYPARSE_PARAM) |
| 1179 | #else |
| 1180 | int |
| 1181 | yyparse (YYPARSE_PARAM) |
| 1182 | void *YYPARSE_PARAM; |
| 1183 | #endif |
| 1184 | #else /* ! YYPARSE_PARAM */ |
| 1185 | #if (defined __STDC__ || defined __C99__FUNC__ \ |
| 1186 | || defined __cplusplus || defined _MSC_VER) |
| 1187 | int |
| 1188 | yyparse (Context *context) |
| 1189 | #else |
| 1190 | int |
| 1191 | yyparse (context) |
| 1192 | Context *context; |
| 1193 | #endif |
| 1194 | #endif |
| 1195 | { |
| 1196 | /* The lookahead symbol. */ |
| 1197 | int yychar; |
| 1198 | |
| 1199 | /* The semantic value of the lookahead symbol. */ |
| 1200 | YYSTYPE yylval; |
| 1201 | |
| 1202 | /* Number of syntax errors so far. */ |
| 1203 | int yynerrs; |
| 1204 | |
| 1205 | int yystate; |
| 1206 | /* Number of tokens to shift before error messages enabled. */ |
| 1207 | int yyerrstatus; |
| 1208 | |
| 1209 | /* The stacks and their tools: |
| 1210 | `yyss': related to states. |
| 1211 | `yyvs': related to semantic values. |
| 1212 | |
| 1213 | Refer to the stacks thru separate pointers, to allow yyoverflow |
| 1214 | to reallocate them elsewhere. */ |
| 1215 | |
| 1216 | /* The state stack. */ |
| 1217 | yytype_int16 yyssa[YYINITDEPTH]; |
| 1218 | yytype_int16 *yyss; |
| 1219 | yytype_int16 *yyssp; |
| 1220 | |
| 1221 | /* The semantic value stack. */ |
| 1222 | YYSTYPE yyvsa[YYINITDEPTH]; |
| 1223 | YYSTYPE *yyvs; |
| 1224 | YYSTYPE *yyvsp; |
| 1225 | |
| 1226 | YYSIZE_T yystacksize; |
| 1227 | |
| 1228 | int yyn; |
| 1229 | int yyresult; |
| 1230 | /* Lookahead token as an internal (translated) token number. */ |
| 1231 | int yytoken; |
| 1232 | /* The variables used to return semantic value and location from the |
| 1233 | action routines. */ |
| 1234 | YYSTYPE yyval; |
| 1235 | |
| 1236 | #if YYERROR_VERBOSE |
| 1237 | /* Buffer for error messages, and its allocated size. */ |
| 1238 | char yymsgbuf[128]; |
| 1239 | char *yymsg = yymsgbuf; |
| 1240 | YYSIZE_T yymsg_alloc = sizeof yymsgbuf; |
| 1241 | #endif |
| 1242 | |
| 1243 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) |
| 1244 | |
| 1245 | /* The number of symbols on the RHS of the reduced rule. |
| 1246 | Keep to zero when no symbol should be popped. */ |
| 1247 | int yylen = 0; |
| 1248 | |
| 1249 | yytoken = 0; |
| 1250 | yyss = yyssa; |
| 1251 | yyvs = yyvsa; |
| 1252 | yystacksize = YYINITDEPTH; |
| 1253 | |
| 1254 | YYDPRINTF ((stderr, "Starting parse\n")); |
| 1255 | |
| 1256 | yystate = 0; |
| 1257 | yyerrstatus = 0; |
| 1258 | yynerrs = 0; |
| 1259 | yychar = YYEMPTY; /* Cause a token to be read. */ |
| 1260 | |
| 1261 | /* Initialize stack pointers. |
| 1262 | Waste one element of value and location stack |
| 1263 | so that they stay on the same level as the state stack. |
| 1264 | The wasted elements are never initialized. */ |
| 1265 | yyssp = yyss; |
| 1266 | yyvsp = yyvs; |
| 1267 | |
| 1268 | goto yysetstate; |
| 1269 | |
| 1270 | /*------------------------------------------------------------. |
| 1271 | | yynewstate -- Push a new state, which is found in yystate. | |
| 1272 | `------------------------------------------------------------*/ |
| 1273 | yynewstate: |
| 1274 | /* In all cases, when you get here, the value and location stacks |
| 1275 | have just been pushed. So pushing a state here evens the stacks. */ |
| 1276 | yyssp++; |
| 1277 | |
| 1278 | yysetstate: |
| 1279 | *yyssp = yystate; |
| 1280 | |
| 1281 | if (yyss + yystacksize - 1 <= yyssp) |
| 1282 | { |
| 1283 | /* Get the current used size of the three stacks, in elements. */ |
| 1284 | YYSIZE_T yysize = yyssp - yyss + 1; |
| 1285 | |
| 1286 | #ifdef yyoverflow |
| 1287 | { |
| 1288 | /* Give user a chance to reallocate the stack. Use copies of |
| 1289 | these so that the &'s don't force the real ones into |
| 1290 | memory. */ |
| 1291 | YYSTYPE *yyvs1 = yyvs; |
| 1292 | yytype_int16 *yyss1 = yyss; |
| 1293 | |
| 1294 | /* Each stack pointer address is followed by the size of the |
| 1295 | data in use in that stack, in bytes. This used to be a |
| 1296 | conditional around just the two extra args, but that might |
| 1297 | be undefined if yyoverflow is a macro. */ |
| 1298 | yyoverflow (YY_("memory exhausted"), |
| 1299 | &yyss1, yysize * sizeof (*yyssp), |
| 1300 | &yyvs1, yysize * sizeof (*yyvsp), |
| 1301 | &yystacksize); |
| 1302 | |
| 1303 | yyss = yyss1; |
| 1304 | yyvs = yyvs1; |
| 1305 | } |
| 1306 | #else /* no yyoverflow */ |
| 1307 | # ifndef YYSTACK_RELOCATE |
| 1308 | goto yyexhaustedlab; |
| 1309 | # else |
| 1310 | /* Extend the stack our own way. */ |
| 1311 | if (YYMAXDEPTH <= yystacksize) |
| 1312 | goto yyexhaustedlab; |
| 1313 | yystacksize *= 2; |
| 1314 | if (YYMAXDEPTH < yystacksize) |
| 1315 | yystacksize = YYMAXDEPTH; |
| 1316 | |
| 1317 | { |
| 1318 | yytype_int16 *yyss1 = yyss; |
| 1319 | union yyalloc *yyptr = |
| 1320 | (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); |
| 1321 | if (! yyptr) |
| 1322 | goto yyexhaustedlab; |
| 1323 | YYSTACK_RELOCATE (yyss_alloc, yyss); |
| 1324 | YYSTACK_RELOCATE (yyvs_alloc, yyvs); |
| 1325 | # undef YYSTACK_RELOCATE |
| 1326 | if (yyss1 != yyssa) |
| 1327 | YYSTACK_FREE (yyss1); |
| 1328 | } |
| 1329 | # endif |
| 1330 | #endif /* no yyoverflow */ |
| 1331 | |
| 1332 | yyssp = yyss + yysize - 1; |
| 1333 | yyvsp = yyvs + yysize - 1; |
| 1334 | |
| 1335 | YYDPRINTF ((stderr, "Stack size increased to %lu\n", |
| 1336 | (unsigned long int) yystacksize)); |
| 1337 | |
| 1338 | if (yyss + yystacksize - 1 <= yyssp) |
| 1339 | YYABORT; |
| 1340 | } |
| 1341 | |
| 1342 | YYDPRINTF ((stderr, "Entering state %d\n", yystate)); |
| 1343 | |
| 1344 | if (yystate == YYFINAL) |
| 1345 | YYACCEPT; |
| 1346 | |
| 1347 | goto yybackup; |
| 1348 | |
| 1349 | /*-----------. |
| 1350 | | yybackup. | |
| 1351 | `-----------*/ |
| 1352 | yybackup: |
| 1353 | |
| 1354 | /* Do appropriate processing given the current state. Read a |
| 1355 | lookahead token if we need one and don't already have one. */ |
| 1356 | |
| 1357 | /* First try to decide what to do without reference to lookahead token. */ |
| 1358 | yyn = yypact[yystate]; |
| 1359 | if (yyn == YYPACT_NINF) |
| 1360 | goto yydefault; |
| 1361 | |
| 1362 | /* Not known => get a lookahead token if don't already have one. */ |
| 1363 | |
| 1364 | /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ |
| 1365 | if (yychar == YYEMPTY) |
| 1366 | { |
| 1367 | YYDPRINTF ((stderr, "Reading a token: ")); |
| 1368 | yychar = YYLEX; |
| 1369 | } |
| 1370 | |
| 1371 | if (yychar <= YYEOF) |
| 1372 | { |
| 1373 | yychar = yytoken = YYEOF; |
| 1374 | YYDPRINTF ((stderr, "Now at end of input.\n")); |
| 1375 | } |
| 1376 | else |
| 1377 | { |
| 1378 | yytoken = YYTRANSLATE (yychar); |
| 1379 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); |
| 1380 | } |
| 1381 | |
| 1382 | /* If the proper action on seeing token YYTOKEN is to reduce or to |
| 1383 | detect an error, take that action. */ |
| 1384 | yyn += yytoken; |
| 1385 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) |
| 1386 | goto yydefault; |
| 1387 | yyn = yytable[yyn]; |
| 1388 | if (yyn <= 0) |
| 1389 | { |
| 1390 | if (yyn == 0 || yyn == YYTABLE_NINF) |
| 1391 | goto yyerrlab; |
| 1392 | yyn = -yyn; |
| 1393 | goto yyreduce; |
| 1394 | } |
| 1395 | |
| 1396 | /* Count tokens shifted since error; after three, turn off error |
| 1397 | status. */ |
| 1398 | if (yyerrstatus) |
| 1399 | yyerrstatus--; |
| 1400 | |
| 1401 | /* Shift the lookahead token. */ |
| 1402 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); |
| 1403 | |
| 1404 | /* Discard the shifted token. */ |
| 1405 | yychar = YYEMPTY; |
| 1406 | |
| 1407 | yystate = yyn; |
| 1408 | *++yyvsp = yylval; |
| 1409 | |
| 1410 | goto yynewstate; |
| 1411 | |
| 1412 | |
| 1413 | /*-----------------------------------------------------------. |
| 1414 | | yydefault -- do the default action for the current state. | |
| 1415 | `-----------------------------------------------------------*/ |
| 1416 | yydefault: |
| 1417 | yyn = yydefact[yystate]; |
| 1418 | if (yyn == 0) |
| 1419 | goto yyerrlab; |
| 1420 | goto yyreduce; |
| 1421 | |
| 1422 | |
| 1423 | /*-----------------------------. |
| 1424 | | yyreduce -- Do a reduction. | |
| 1425 | `-----------------------------*/ |
| 1426 | yyreduce: |
| 1427 | /* yyn is the number of a rule to reduce with. */ |
| 1428 | yylen = yyr2[yyn]; |
| 1429 | |
| 1430 | /* If YYLEN is nonzero, implement the default value of the action: |
| 1431 | `$$ = $1'. |
| 1432 | |
| 1433 | Otherwise, the following line sets YYVAL to garbage. |
| 1434 | This behavior is undocumented and Bison |
| 1435 | users should not rely upon it. Assigning to YYVAL |
| 1436 | unconditionally makes the parser a bit smaller, and it avoids a |
| 1437 | GCC warning that YYVAL may be used uninitialized. */ |
| 1438 | yyval = yyvsp[1-yylen]; |
| 1439 | |
| 1440 | |
| 1441 | YY_REDUCE_PRINT (yyn); |
| 1442 | switch (yyn) |
| 1443 | { |
| 1444 | case 2: |
| 1445 | |
| 1446 | { |
alokp@chromium.org | d39ec4c | 2012-06-26 04:37:55 +0000 | [diff] [blame] | 1447 | *(context->result) = static_cast<int>((yyvsp[(1) - (1)])); |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1448 | YYACCEPT; |
| 1449 | } |
| 1450 | break; |
| 1451 | |
| 1452 | case 4: |
| 1453 | |
| 1454 | { |
| 1455 | (yyval) = (yyvsp[(1) - (3)]) || (yyvsp[(3) - (3)]); |
| 1456 | } |
| 1457 | break; |
| 1458 | |
| 1459 | case 5: |
| 1460 | |
| 1461 | { |
| 1462 | (yyval) = (yyvsp[(1) - (3)]) && (yyvsp[(3) - (3)]); |
| 1463 | } |
| 1464 | break; |
| 1465 | |
| 1466 | case 6: |
| 1467 | |
| 1468 | { |
| 1469 | (yyval) = (yyvsp[(1) - (3)]) | (yyvsp[(3) - (3)]); |
| 1470 | } |
| 1471 | break; |
| 1472 | |
| 1473 | case 7: |
| 1474 | |
| 1475 | { |
| 1476 | (yyval) = (yyvsp[(1) - (3)]) ^ (yyvsp[(3) - (3)]); |
| 1477 | } |
| 1478 | break; |
| 1479 | |
| 1480 | case 8: |
| 1481 | |
| 1482 | { |
| 1483 | (yyval) = (yyvsp[(1) - (3)]) & (yyvsp[(3) - (3)]); |
| 1484 | } |
| 1485 | break; |
| 1486 | |
| 1487 | case 9: |
| 1488 | |
| 1489 | { |
| 1490 | (yyval) = (yyvsp[(1) - (3)]) != (yyvsp[(3) - (3)]); |
| 1491 | } |
| 1492 | break; |
| 1493 | |
| 1494 | case 10: |
| 1495 | |
| 1496 | { |
| 1497 | (yyval) = (yyvsp[(1) - (3)]) == (yyvsp[(3) - (3)]); |
| 1498 | } |
| 1499 | break; |
| 1500 | |
| 1501 | case 11: |
| 1502 | |
| 1503 | { |
| 1504 | (yyval) = (yyvsp[(1) - (3)]) >= (yyvsp[(3) - (3)]); |
| 1505 | } |
| 1506 | break; |
| 1507 | |
| 1508 | case 12: |
| 1509 | |
| 1510 | { |
| 1511 | (yyval) = (yyvsp[(1) - (3)]) <= (yyvsp[(3) - (3)]); |
| 1512 | } |
| 1513 | break; |
| 1514 | |
| 1515 | case 13: |
| 1516 | |
| 1517 | { |
| 1518 | (yyval) = (yyvsp[(1) - (3)]) > (yyvsp[(3) - (3)]); |
| 1519 | } |
| 1520 | break; |
| 1521 | |
| 1522 | case 14: |
| 1523 | |
| 1524 | { |
| 1525 | (yyval) = (yyvsp[(1) - (3)]) < (yyvsp[(3) - (3)]); |
| 1526 | } |
| 1527 | break; |
| 1528 | |
| 1529 | case 15: |
| 1530 | |
| 1531 | { |
| 1532 | (yyval) = (yyvsp[(1) - (3)]) >> (yyvsp[(3) - (3)]); |
| 1533 | } |
| 1534 | break; |
| 1535 | |
| 1536 | case 16: |
| 1537 | |
| 1538 | { |
| 1539 | (yyval) = (yyvsp[(1) - (3)]) << (yyvsp[(3) - (3)]); |
| 1540 | } |
| 1541 | break; |
| 1542 | |
| 1543 | case 17: |
| 1544 | |
| 1545 | { |
| 1546 | (yyval) = (yyvsp[(1) - (3)]) - (yyvsp[(3) - (3)]); |
| 1547 | } |
| 1548 | break; |
| 1549 | |
| 1550 | case 18: |
| 1551 | |
| 1552 | { |
| 1553 | (yyval) = (yyvsp[(1) - (3)]) + (yyvsp[(3) - (3)]); |
| 1554 | } |
| 1555 | break; |
| 1556 | |
| 1557 | case 19: |
| 1558 | |
| 1559 | { |
| 1560 | if ((yyvsp[(3) - (3)]) == 0) { |
alokp@chromium.org | 2e81891 | 2012-06-29 21:26:03 +0000 | [diff] [blame] | 1561 | std::ostringstream stream; |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1562 | stream << (yyvsp[(1) - (3)]) << " % " << (yyvsp[(3) - (3)]); |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 1563 | std::string text = stream.str(); |
| 1564 | context->diagnostics->report(pp::Diagnostics::DIVISION_BY_ZERO, |
| 1565 | context->token->location, |
| 1566 | text.c_str()); |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1567 | YYABORT; |
| 1568 | } else { |
| 1569 | (yyval) = (yyvsp[(1) - (3)]) % (yyvsp[(3) - (3)]); |
| 1570 | } |
| 1571 | } |
| 1572 | break; |
| 1573 | |
| 1574 | case 20: |
| 1575 | |
| 1576 | { |
| 1577 | if ((yyvsp[(3) - (3)]) == 0) { |
alokp@chromium.org | 2e81891 | 2012-06-29 21:26:03 +0000 | [diff] [blame] | 1578 | std::ostringstream stream; |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1579 | stream << (yyvsp[(1) - (3)]) << " / " << (yyvsp[(3) - (3)]); |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 1580 | std::string text = stream.str(); |
| 1581 | context->diagnostics->report(pp::Diagnostics::DIVISION_BY_ZERO, |
| 1582 | context->token->location, |
| 1583 | text.c_str()); |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1584 | YYABORT; |
| 1585 | } else { |
| 1586 | (yyval) = (yyvsp[(1) - (3)]) / (yyvsp[(3) - (3)]); |
| 1587 | } |
| 1588 | } |
| 1589 | break; |
| 1590 | |
| 1591 | case 21: |
| 1592 | |
| 1593 | { |
| 1594 | (yyval) = (yyvsp[(1) - (3)]) * (yyvsp[(3) - (3)]); |
| 1595 | } |
| 1596 | break; |
| 1597 | |
| 1598 | case 22: |
| 1599 | |
| 1600 | { |
| 1601 | (yyval) = ! (yyvsp[(2) - (2)]); |
| 1602 | } |
| 1603 | break; |
| 1604 | |
| 1605 | case 23: |
| 1606 | |
| 1607 | { |
| 1608 | (yyval) = ~ (yyvsp[(2) - (2)]); |
| 1609 | } |
| 1610 | break; |
| 1611 | |
| 1612 | case 24: |
| 1613 | |
| 1614 | { |
| 1615 | (yyval) = - (yyvsp[(2) - (2)]); |
| 1616 | } |
| 1617 | break; |
| 1618 | |
| 1619 | case 25: |
| 1620 | |
| 1621 | { |
| 1622 | (yyval) = + (yyvsp[(2) - (2)]); |
| 1623 | } |
| 1624 | break; |
| 1625 | |
| 1626 | case 26: |
| 1627 | |
| 1628 | { |
| 1629 | (yyval) = (yyvsp[(2) - (3)]); |
| 1630 | } |
| 1631 | break; |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | default: break; |
| 1636 | } |
| 1637 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); |
| 1638 | |
| 1639 | YYPOPSTACK (yylen); |
| 1640 | yylen = 0; |
| 1641 | YY_STACK_PRINT (yyss, yyssp); |
| 1642 | |
| 1643 | *++yyvsp = yyval; |
| 1644 | |
| 1645 | /* Now `shift' the result of the reduction. Determine what state |
| 1646 | that goes to, based on the state we popped back to and the rule |
| 1647 | number reduced by. */ |
| 1648 | |
| 1649 | yyn = yyr1[yyn]; |
| 1650 | |
| 1651 | yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; |
| 1652 | if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) |
| 1653 | yystate = yytable[yystate]; |
| 1654 | else |
| 1655 | yystate = yydefgoto[yyn - YYNTOKENS]; |
| 1656 | |
| 1657 | goto yynewstate; |
| 1658 | |
| 1659 | |
| 1660 | /*------------------------------------. |
| 1661 | | yyerrlab -- here on detecting error | |
| 1662 | `------------------------------------*/ |
| 1663 | yyerrlab: |
| 1664 | /* If not already recovering from an error, report this error. */ |
| 1665 | if (!yyerrstatus) |
| 1666 | { |
| 1667 | ++yynerrs; |
| 1668 | #if ! YYERROR_VERBOSE |
| 1669 | yyerror (context, YY_("syntax error")); |
| 1670 | #else |
| 1671 | { |
| 1672 | YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); |
| 1673 | if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) |
| 1674 | { |
| 1675 | YYSIZE_T yyalloc = 2 * yysize; |
| 1676 | if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) |
| 1677 | yyalloc = YYSTACK_ALLOC_MAXIMUM; |
| 1678 | if (yymsg != yymsgbuf) |
| 1679 | YYSTACK_FREE (yymsg); |
| 1680 | yymsg = (char *) YYSTACK_ALLOC (yyalloc); |
| 1681 | if (yymsg) |
| 1682 | yymsg_alloc = yyalloc; |
| 1683 | else |
| 1684 | { |
| 1685 | yymsg = yymsgbuf; |
| 1686 | yymsg_alloc = sizeof yymsgbuf; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | if (0 < yysize && yysize <= yymsg_alloc) |
| 1691 | { |
| 1692 | (void) yysyntax_error (yymsg, yystate, yychar); |
| 1693 | yyerror (context, yymsg); |
| 1694 | } |
| 1695 | else |
| 1696 | { |
| 1697 | yyerror (context, YY_("syntax error")); |
| 1698 | if (yysize != 0) |
| 1699 | goto yyexhaustedlab; |
| 1700 | } |
| 1701 | } |
| 1702 | #endif |
| 1703 | } |
| 1704 | |
| 1705 | |
| 1706 | |
| 1707 | if (yyerrstatus == 3) |
| 1708 | { |
| 1709 | /* If just tried and failed to reuse lookahead token after an |
| 1710 | error, discard it. */ |
| 1711 | |
| 1712 | if (yychar <= YYEOF) |
| 1713 | { |
| 1714 | /* Return failure if at end of input. */ |
| 1715 | if (yychar == YYEOF) |
| 1716 | YYABORT; |
| 1717 | } |
| 1718 | else |
| 1719 | { |
| 1720 | yydestruct ("Error: discarding", |
| 1721 | yytoken, &yylval, context); |
| 1722 | yychar = YYEMPTY; |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | /* Else will try to reuse lookahead token after shifting the error |
| 1727 | token. */ |
| 1728 | goto yyerrlab1; |
| 1729 | |
| 1730 | |
| 1731 | /*---------------------------------------------------. |
| 1732 | | yyerrorlab -- error raised explicitly by YYERROR. | |
| 1733 | `---------------------------------------------------*/ |
| 1734 | yyerrorlab: |
| 1735 | |
| 1736 | /* Pacify compilers like GCC when the user code never invokes |
| 1737 | YYERROR and the label yyerrorlab therefore never appears in user |
| 1738 | code. */ |
| 1739 | if (/*CONSTCOND*/ 0) |
| 1740 | goto yyerrorlab; |
| 1741 | |
| 1742 | /* Do not reclaim the symbols of the rule which action triggered |
| 1743 | this YYERROR. */ |
| 1744 | YYPOPSTACK (yylen); |
| 1745 | yylen = 0; |
| 1746 | YY_STACK_PRINT (yyss, yyssp); |
| 1747 | yystate = *yyssp; |
| 1748 | goto yyerrlab1; |
| 1749 | |
| 1750 | |
| 1751 | /*-------------------------------------------------------------. |
| 1752 | | yyerrlab1 -- common code for both syntax error and YYERROR. | |
| 1753 | `-------------------------------------------------------------*/ |
| 1754 | yyerrlab1: |
| 1755 | yyerrstatus = 3; /* Each real token shifted decrements this. */ |
| 1756 | |
| 1757 | for (;;) |
| 1758 | { |
| 1759 | yyn = yypact[yystate]; |
| 1760 | if (yyn != YYPACT_NINF) |
| 1761 | { |
| 1762 | yyn += YYTERROR; |
| 1763 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) |
| 1764 | { |
| 1765 | yyn = yytable[yyn]; |
| 1766 | if (0 < yyn) |
| 1767 | break; |
| 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | /* Pop the current state because it cannot handle the error token. */ |
| 1772 | if (yyssp == yyss) |
| 1773 | YYABORT; |
| 1774 | |
| 1775 | |
| 1776 | yydestruct ("Error: popping", |
| 1777 | yystos[yystate], yyvsp, context); |
| 1778 | YYPOPSTACK (1); |
| 1779 | yystate = *yyssp; |
| 1780 | YY_STACK_PRINT (yyss, yyssp); |
| 1781 | } |
| 1782 | |
| 1783 | *++yyvsp = yylval; |
| 1784 | |
| 1785 | |
| 1786 | /* Shift the error token. */ |
| 1787 | YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); |
| 1788 | |
| 1789 | yystate = yyn; |
| 1790 | goto yynewstate; |
| 1791 | |
| 1792 | |
| 1793 | /*-------------------------------------. |
| 1794 | | yyacceptlab -- YYACCEPT comes here. | |
| 1795 | `-------------------------------------*/ |
| 1796 | yyacceptlab: |
| 1797 | yyresult = 0; |
| 1798 | goto yyreturn; |
| 1799 | |
| 1800 | /*-----------------------------------. |
| 1801 | | yyabortlab -- YYABORT comes here. | |
| 1802 | `-----------------------------------*/ |
| 1803 | yyabortlab: |
| 1804 | yyresult = 1; |
| 1805 | goto yyreturn; |
| 1806 | |
| 1807 | #if !defined(yyoverflow) || YYERROR_VERBOSE |
| 1808 | /*-------------------------------------------------. |
| 1809 | | yyexhaustedlab -- memory exhaustion comes here. | |
| 1810 | `-------------------------------------------------*/ |
| 1811 | yyexhaustedlab: |
| 1812 | yyerror (context, YY_("memory exhausted")); |
| 1813 | yyresult = 2; |
| 1814 | /* Fall through. */ |
| 1815 | #endif |
| 1816 | |
| 1817 | yyreturn: |
| 1818 | if (yychar != YYEMPTY) |
| 1819 | yydestruct ("Cleanup: discarding lookahead", |
| 1820 | yytoken, &yylval, context); |
| 1821 | /* Do not reclaim the symbols of the rule which action triggered |
| 1822 | this YYABORT or YYACCEPT. */ |
| 1823 | YYPOPSTACK (yylen); |
| 1824 | YY_STACK_PRINT (yyss, yyssp); |
| 1825 | while (yyssp != yyss) |
| 1826 | { |
| 1827 | yydestruct ("Cleanup: popping", |
| 1828 | yystos[*yyssp], yyvsp, context); |
| 1829 | YYPOPSTACK (1); |
| 1830 | } |
| 1831 | #ifndef yyoverflow |
| 1832 | if (yyss != yyssa) |
| 1833 | YYSTACK_FREE (yyss); |
| 1834 | #endif |
| 1835 | #if YYERROR_VERBOSE |
| 1836 | if (yymsg != yymsgbuf) |
| 1837 | YYSTACK_FREE (yymsg); |
| 1838 | #endif |
| 1839 | /* Make sure YYID is used. */ |
| 1840 | return YYID (yyresult); |
| 1841 | } |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | |
| 1846 | |
alokp@chromium.org | d39ec4c | 2012-06-26 04:37:55 +0000 | [diff] [blame] | 1847 | int yylex(YYSTYPE* lvalp, Context* context) |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1848 | { |
| 1849 | int type = 0; |
| 1850 | |
| 1851 | pp::Token* token = context->token; |
| 1852 | switch (token->type) |
| 1853 | { |
| 1854 | case pp::Token::CONST_INT: |
alokp@chromium.org | 2e81891 | 2012-06-29 21:26:03 +0000 | [diff] [blame] | 1855 | { |
| 1856 | unsigned int val = 0; |
| 1857 | if (!token->uValue(&val)) |
| 1858 | { |
| 1859 | context->diagnostics->report(pp::Diagnostics::INTEGER_OVERFLOW, |
| 1860 | token->location, token->text); |
| 1861 | } |
| 1862 | *lvalp = static_cast<YYSTYPE>(val); |
maxvujovic@gmail.com | e640ef8 | 2012-07-13 18:42:40 +0000 | [diff] [blame] | 1863 | type = TOK_CONST_INT; |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1864 | break; |
alokp@chromium.org | 2e81891 | 2012-06-29 21:26:03 +0000 | [diff] [blame] | 1865 | } |
maxvujovic@gmail.com | e640ef8 | 2012-07-13 18:42:40 +0000 | [diff] [blame] | 1866 | case pp::Token::OP_OR: type = TOK_OP_OR; break; |
| 1867 | case pp::Token::OP_AND: type = TOK_OP_AND; break; |
| 1868 | case pp::Token::OP_NE: type = TOK_OP_NE; break; |
| 1869 | case pp::Token::OP_EQ: type = TOK_OP_EQ; break; |
| 1870 | case pp::Token::OP_GE: type = TOK_OP_GE; break; |
| 1871 | case pp::Token::OP_LE: type = TOK_OP_LE; break; |
| 1872 | case pp::Token::OP_RIGHT: type = TOK_OP_RIGHT; break; |
| 1873 | case pp::Token::OP_LEFT: type = TOK_OP_LEFT; break; |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1874 | case '|': type = '|'; break; |
| 1875 | case '^': type = '^'; break; |
| 1876 | case '&': type = '&'; break; |
| 1877 | case '>': type = '>'; break; |
| 1878 | case '<': type = '<'; break; |
| 1879 | case '-': type = '-'; break; |
| 1880 | case '+': type = '+'; break; |
| 1881 | case '%': type = '%'; break; |
| 1882 | case '/': type = '/'; break; |
| 1883 | case '*': type = '*'; break; |
| 1884 | case '!': type = '!'; break; |
| 1885 | case '~': type = '~'; break; |
| 1886 | case '(': type = '('; break; |
| 1887 | case ')': type = ')'; break; |
| 1888 | |
| 1889 | default: break; |
| 1890 | } |
| 1891 | |
| 1892 | // Advance to the next token if the current one is valid. |
| 1893 | if (type != 0) context->lexer->lex(token); |
| 1894 | |
| 1895 | return type; |
| 1896 | } |
| 1897 | |
| 1898 | void yyerror(Context* context, const char* reason) |
| 1899 | { |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 1900 | context->diagnostics->report(pp::Diagnostics::INVALID_EXPRESSION, |
| 1901 | context->token->location, |
| 1902 | reason); |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | namespace pp { |
| 1906 | |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 1907 | ExpressionParser::ExpressionParser(Lexer* lexer, Diagnostics* diagnostics) : |
| 1908 | mLexer(lexer), |
| 1909 | mDiagnostics(diagnostics) |
| 1910 | { |
| 1911 | } |
| 1912 | |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1913 | bool ExpressionParser::parse(Token* token, int* result) |
| 1914 | { |
| 1915 | Context context; |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 1916 | context.diagnostics = mDiagnostics; |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1917 | context.lexer = mLexer; |
| 1918 | context.token = token; |
| 1919 | context.result = result; |
| 1920 | int ret = yyparse(&context); |
| 1921 | switch (ret) |
| 1922 | { |
| 1923 | case 0: |
| 1924 | case 1: |
| 1925 | break; |
| 1926 | |
| 1927 | case 2: |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 1928 | mDiagnostics->report(Diagnostics::OUT_OF_MEMORY, token->location, ""); |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | |
| 1931 | default: |
| 1932 | assert(false); |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 1933 | mDiagnostics->report(Diagnostics::INTERNAL_ERROR, token->location, ""); |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1934 | break; |
| 1935 | } |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 1936 | |
alokp@chromium.org | 04d7d22 | 2012-05-16 19:24:07 +0000 | [diff] [blame] | 1937 | return ret == 0; |
| 1938 | } |
| 1939 | |
| 1940 | } // namespace pp |
| 1941 | |