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