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