this repo has no description
at develop 48 kB view raw
1/* A Bison parser, made by GNU Bison 3.7.6. */ 2 3/* Bison implementation for Yacc-like parsers in C 4 5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, 6 Inc. 7 8 This program is free software: you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <https://www.gnu.org/licenses/>. */ 20 21/* As a special exception, you may create a larger work that contains 22 part or all of the Bison parser skeleton and distribute that work 23 under terms of your choice, so long as that work isn't itself a 24 parser generator using the skeleton or a modified version thereof 25 as a parser skeleton. Alternatively, if you modify or redistribute 26 the parser skeleton itself, you may (at your option) remove this 27 special exception, which will cause the skeleton and the resulting 28 Bison output files to be licensed under the GNU General Public 29 License without this special exception. 30 31 This special exception was added by the Free Software Foundation in 32 version 2.2 of Bison. */ 33 34/* C LALR(1) parser skeleton written by Richard Stallman, by 35 simplifying the original so-called "semantic" parser. */ 36 37/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, 38 especially those whose name start with YY_ or yy_. They are 39 private implementation details that can be changed or removed. */ 40 41/* All symbols defined below should begin with yy or YY, to avoid 42 infringing on user name space. This should be done even for local 43 variables, as they might otherwise be expanded by user macros. 44 There are some unavoidable exceptions within include files to 45 define necessary library symbols; they are noted "INFRINGES ON 46 USER NAME SPACE" below. */ 47 48/* Identify Bison output, and Bison version. */ 49#define YYBISON 30706 50 51/* Bison version string. */ 52#define YYBISON_VERSION "3.7.6" 53 54/* Skeleton name. */ 55#define YYSKELETON_NAME "yacc.c" 56 57/* Pure parsers. */ 58#define YYPURE 0 59 60/* Push parsers. */ 61#define YYPUSH 0 62 63/* Pull parsers. */ 64#define YYPULL 1 65 66 67/* Substitute the variable and function names. */ 68#define yyparse regex_yyparse 69#define yylex regex_yylex 70#define yyerror regex_yyerror 71#define yydebug regex_yydebug 72#define yynerrs regex_yynerrs 73#define yylval regex_yylval 74#define yychar regex_yychar 75 76/* First part of user prologue. */ 77 78#include <cstdlib> 79#include <cstdio> 80#include <memory> 81#include <unordered_set> 82#include <unordered_map> 83 84#include <gecode/minimodel.hh> 85#include <minizinc/values.hh> 86using namespace Gecode; 87using namespace MiniZinc; 88 89typedef struct yy_buffer_state *YY_BUFFER_STATE; 90YY_BUFFER_STATE regex_yy_scan_string ( const char* yy_str ); 91 92extern int yylex(); 93extern FILE* yyin; 94 95typedef struct REContext{ 96 REG* expr; 97 const IntSetVal& dom; 98 const std::unordered_map<std::string, int>& idMap; 99} REContext; 100 101void yyerror(REContext& ctx, const char* s); 102 103 104# ifndef YY_CAST 105# ifdef __cplusplus 106# define YY_CAST(Type, Val) static_cast<Type> (Val) 107# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val) 108# else 109# define YY_CAST(Type, Val) ((Type) (Val)) 110# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) 111# endif 112# endif 113# ifndef YY_NULLPTR 114# if defined __cplusplus 115# if 201103L <= __cplusplus 116# define YY_NULLPTR nullptr 117# else 118# define YY_NULLPTR 0 119# endif 120# else 121# define YY_NULLPTR ((void*)0) 122# endif 123# endif 124 125#include <minizinc/support/regex_parser.tab.hh> 126/* Symbol kind. */ 127enum yysymbol_kind_t 128{ 129 YYSYMBOL_YYEMPTY = -2, 130 YYSYMBOL_YYEOF = 0, /* "end of file" */ 131 YYSYMBOL_YYerror = 1, /* error */ 132 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ 133 YYSYMBOL_R_INTEGER = 3, /* R_INTEGER */ 134 YYSYMBOL_R_GROUP_OPEN = 4, /* "(" */ 135 YYSYMBOL_R_GROUP_CLOSE = 5, /* ")" */ 136 YYSYMBOL_R_STAR = 6, /* "*" */ 137 YYSYMBOL_R_PLUS = 7, /* "+" */ 138 YYSYMBOL_R_ANY = 8, /* "." */ 139 YYSYMBOL_R_UNION = 9, /* "|" */ 140 YYSYMBOL_R_OPTIONAL = 10, /* "?" */ 141 YYSYMBOL_R_QUANT_OPEN = 11, /* "{" */ 142 YYSYMBOL_R_QUANT_CLOSE = 12, /* "}" */ 143 YYSYMBOL_R_COMMA = 13, /* "," */ 144 YYSYMBOL_R_CLASS_OPEN = 14, /* "[" */ 145 YYSYMBOL_R_CLASS_CLOSE = 15, /* "]" */ 146 YYSYMBOL_R_CLASS_RANGE = 16, /* "-" */ 147 YYSYMBOL_R_CLASS_NEG = 17, /* "^" */ 148 YYSYMBOL_R_IDENTIFIER = 18, /* R_IDENTIFIER */ 149 YYSYMBOL_YYACCEPT = 19, /* $accept */ 150 YYSYMBOL_regex = 20, /* regex */ 151 YYSYMBOL_expression = 21, /* expression */ 152 YYSYMBOL_term = 22, /* term */ 153 YYSYMBOL_factor = 23, /* factor */ 154 YYSYMBOL_atom = 24, /* atom */ 155 YYSYMBOL_set_items = 25, /* set_items */ 156 YYSYMBOL_set_item = 26, /* set_item */ 157 YYSYMBOL_literal = 27 /* literal */ 158}; 159typedef enum yysymbol_kind_t yysymbol_kind_t; 160 161 162 163 164#ifdef short 165# undef short 166#endif 167 168/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure 169 <limits.h> and (if available) <stdint.h> are included 170 so that the code can choose integer types of a good width. */ 171 172#ifndef __PTRDIFF_MAX__ 173# include <limits.h> /* INFRINGES ON USER NAME SPACE */ 174# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 175# include <stdint.h> /* INFRINGES ON USER NAME SPACE */ 176# define YY_STDINT_H 177# endif 178#endif 179 180/* Narrow types that promote to a signed type and that can represent a 181 signed or unsigned integer of at least N bits. In tables they can 182 save space and decrease cache pressure. Promoting to a signed type 183 helps avoid bugs in integer arithmetic. */ 184 185#ifdef __INT_LEAST8_MAX__ 186typedef __INT_LEAST8_TYPE__ yytype_int8; 187#elif defined YY_STDINT_H 188typedef int_least8_t yytype_int8; 189#else 190typedef signed char yytype_int8; 191#endif 192 193#ifdef __INT_LEAST16_MAX__ 194typedef __INT_LEAST16_TYPE__ yytype_int16; 195#elif defined YY_STDINT_H 196typedef int_least16_t yytype_int16; 197#else 198typedef short yytype_int16; 199#endif 200 201/* Work around bug in HP-UX 11.23, which defines these macros 202 incorrectly for preprocessor constants. This workaround can likely 203 be removed in 2023, as HPE has promised support for HP-UX 11.23 204 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of 205 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */ 206#ifdef __hpux 207# undef UINT_LEAST8_MAX 208# undef UINT_LEAST16_MAX 209# define UINT_LEAST8_MAX 255 210# define UINT_LEAST16_MAX 65535 211#endif 212 213#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ 214typedef __UINT_LEAST8_TYPE__ yytype_uint8; 215#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ 216 && UINT_LEAST8_MAX <= INT_MAX) 217typedef uint_least8_t yytype_uint8; 218#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX 219typedef unsigned char yytype_uint8; 220#else 221typedef short yytype_uint8; 222#endif 223 224#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ 225typedef __UINT_LEAST16_TYPE__ yytype_uint16; 226#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ 227 && UINT_LEAST16_MAX <= INT_MAX) 228typedef uint_least16_t yytype_uint16; 229#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX 230typedef unsigned short yytype_uint16; 231#else 232typedef int yytype_uint16; 233#endif 234 235#ifndef YYPTRDIFF_T 236# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ 237# define YYPTRDIFF_T __PTRDIFF_TYPE__ 238# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ 239# elif defined PTRDIFF_MAX 240# ifndef ptrdiff_t 241# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ 242# endif 243# define YYPTRDIFF_T ptrdiff_t 244# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX 245# else 246# define YYPTRDIFF_T long 247# define YYPTRDIFF_MAXIMUM LONG_MAX 248# endif 249#endif 250 251#ifndef YYSIZE_T 252# ifdef __SIZE_TYPE__ 253# define YYSIZE_T __SIZE_TYPE__ 254# elif defined size_t 255# define YYSIZE_T size_t 256# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 257# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ 258# define YYSIZE_T size_t 259# else 260# define YYSIZE_T unsigned 261# endif 262#endif 263 264#define YYSIZE_MAXIMUM \ 265 YY_CAST (YYPTRDIFF_T, \ 266 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ 267 ? YYPTRDIFF_MAXIMUM \ 268 : YY_CAST (YYSIZE_T, -1))) 269 270#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) 271 272 273/* Stored state numbers (used for stacks). */ 274typedef yytype_int8 yy_state_t; 275 276/* State numbers in computations. */ 277typedef int yy_state_fast_t; 278 279#ifndef YY_ 280# if defined YYENABLE_NLS && YYENABLE_NLS 281# if ENABLE_NLS 282# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ 283# define YY_(Msgid) dgettext ("bison-runtime", Msgid) 284# endif 285# endif 286# ifndef YY_ 287# define YY_(Msgid) Msgid 288# endif 289#endif 290 291 292#ifndef YY_ATTRIBUTE_PURE 293# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) 294# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) 295# else 296# define YY_ATTRIBUTE_PURE 297# endif 298#endif 299 300#ifndef YY_ATTRIBUTE_UNUSED 301# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) 302# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 303# else 304# define YY_ATTRIBUTE_UNUSED 305# endif 306#endif 307 308/* Suppress unused-variable warnings by "using" E. */ 309#if ! defined lint || defined __GNUC__ 310# define YY_USE(E) ((void) (E)) 311#else 312# define YY_USE(E) /* empty */ 313#endif 314 315#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ 316/* Suppress an incorrect diagnostic about yylval being uninitialized. */ 317# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 318 _Pragma ("GCC diagnostic push") \ 319 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ 320 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") 321# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ 322 _Pragma ("GCC diagnostic pop") 323#else 324# define YY_INITIAL_VALUE(Value) Value 325#endif 326#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 327# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 328# define YY_IGNORE_MAYBE_UNINITIALIZED_END 329#endif 330#ifndef YY_INITIAL_VALUE 331# define YY_INITIAL_VALUE(Value) /* Nothing. */ 332#endif 333 334#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ 335# define YY_IGNORE_USELESS_CAST_BEGIN \ 336 _Pragma ("GCC diagnostic push") \ 337 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") 338# define YY_IGNORE_USELESS_CAST_END \ 339 _Pragma ("GCC diagnostic pop") 340#endif 341#ifndef YY_IGNORE_USELESS_CAST_BEGIN 342# define YY_IGNORE_USELESS_CAST_BEGIN 343# define YY_IGNORE_USELESS_CAST_END 344#endif 345 346 347#define YY_ASSERT(E) ((void) (0 && (E))) 348 349#if !defined yyoverflow 350 351/* The parser invokes alloca or malloc; define the necessary symbols. */ 352 353# ifdef YYSTACK_USE_ALLOCA 354# if YYSTACK_USE_ALLOCA 355# ifdef __GNUC__ 356# define YYSTACK_ALLOC __builtin_alloca 357# elif defined __BUILTIN_VA_ARG_INCR 358# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ 359# elif defined _AIX 360# define YYSTACK_ALLOC __alloca 361# elif defined _MSC_VER 362# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ 363# define alloca _alloca 364# else 365# define YYSTACK_ALLOC alloca 366# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS 367# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 368 /* Use EXIT_SUCCESS as a witness for stdlib.h. */ 369# ifndef EXIT_SUCCESS 370# define EXIT_SUCCESS 0 371# endif 372# endif 373# endif 374# endif 375# endif 376 377# ifdef YYSTACK_ALLOC 378 /* Pacify GCC's 'empty if-body' warning. */ 379# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) 380# ifndef YYSTACK_ALLOC_MAXIMUM 381 /* The OS might guarantee only one guard page at the bottom of the stack, 382 and a page size can be as small as 4096 bytes. So we cannot safely 383 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 384 to allow for a few compiler-allocated temporary stack slots. */ 385# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 386# endif 387# else 388# define YYSTACK_ALLOC YYMALLOC 389# define YYSTACK_FREE YYFREE 390# ifndef YYSTACK_ALLOC_MAXIMUM 391# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 392# endif 393# if (defined __cplusplus && ! defined EXIT_SUCCESS \ 394 && ! ((defined YYMALLOC || defined malloc) \ 395 && (defined YYFREE || defined free))) 396# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 397# ifndef EXIT_SUCCESS 398# define EXIT_SUCCESS 0 399# endif 400# endif 401# ifndef YYMALLOC 402# define YYMALLOC malloc 403# if ! defined malloc && ! defined EXIT_SUCCESS 404void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 405# endif 406# endif 407# ifndef YYFREE 408# define YYFREE free 409# if ! defined free && ! defined EXIT_SUCCESS 410void free (void *); /* INFRINGES ON USER NAME SPACE */ 411# endif 412# endif 413# endif 414#endif /* !defined yyoverflow */ 415 416#if (! defined yyoverflow \ 417 && (! defined __cplusplus \ 418 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 419 420/* A type that is properly aligned for any stack member. */ 421union yyalloc 422{ 423 yy_state_t yyss_alloc; 424 YYSTYPE yyvs_alloc; 425}; 426 427/* The size of the maximum gap between one aligned stack and the next. */ 428# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) 429 430/* The size of an array large to enough to hold all stacks, each with 431 N elements. */ 432# define YYSTACK_BYTES(N) \ 433 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ 434 + YYSTACK_GAP_MAXIMUM) 435 436# define YYCOPY_NEEDED 1 437 438/* Relocate STACK from its old location to the new one. The 439 local variables YYSIZE and YYSTACKSIZE give the old and new number of 440 elements in the stack, and YYPTR gives the new location of the 441 stack. Advance YYPTR to a properly aligned location for the next 442 stack. */ 443# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ 444 do \ 445 { \ 446 YYPTRDIFF_T yynewbytes; \ 447 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ 448 Stack = &yyptr->Stack_alloc; \ 449 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ 450 yyptr += yynewbytes / YYSIZEOF (*yyptr); \ 451 } \ 452 while (0) 453 454#endif 455 456#if defined YYCOPY_NEEDED && YYCOPY_NEEDED 457/* Copy COUNT objects from SRC to DST. The source and destination do 458 not overlap. */ 459# ifndef YYCOPY 460# if defined __GNUC__ && 1 < __GNUC__ 461# define YYCOPY(Dst, Src, Count) \ 462 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) 463# else 464# define YYCOPY(Dst, Src, Count) \ 465 do \ 466 { \ 467 YYPTRDIFF_T yyi; \ 468 for (yyi = 0; yyi < (Count); yyi++) \ 469 (Dst)[yyi] = (Src)[yyi]; \ 470 } \ 471 while (0) 472# endif 473# endif 474#endif /* !YYCOPY_NEEDED */ 475 476/* YYFINAL -- State number of the termination state. */ 477#define YYFINAL 17 478/* YYLAST -- Last index in YYTABLE. */ 479#define YYLAST 34 480 481/* YYNTOKENS -- Number of terminals. */ 482#define YYNTOKENS 19 483/* YYNNTS -- Number of nonterminals. */ 484#define YYNNTS 9 485/* YYNRULES -- Number of rules. */ 486#define YYNRULES 24 487/* YYNSTATES -- Number of states. */ 488#define YYNSTATES 38 489 490/* YYMAXUTOK -- Last valid token kind. */ 491#define YYMAXUTOK 273 492 493 494/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM 495 as returned by yylex, with out-of-bounds checking. */ 496#define YYTRANSLATE(YYX) \ 497 (0 <= (YYX) && (YYX) <= YYMAXUTOK \ 498 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ 499 : YYSYMBOL_YYUNDEF) 500 501/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM 502 as returned by yylex. */ 503static const yytype_int8 yytranslate[] = 504{ 505 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 506 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 507 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 508 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 509 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 510 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 511 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 512 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 513 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 514 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 515 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 516 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 517 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 518 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 519 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 520 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 521 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 522 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 523 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 524 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 525 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 526 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 527 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 528 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 529 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 530 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 531 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 532 15, 16, 17, 18 533}; 534 535#if YYDEBUG 536 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ 537static const yytype_uint8 yyrline[] = 538{ 539 0, 75, 75, 82, 83, 91, 92, 100, 101, 106, 540 111, 116, 121, 126, 133, 135, 140, 150, 165, 169, 541 170, 180, 184, 198, 199 542}; 543#endif 544 545/** Accessing symbol of state STATE. */ 546#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) 547 548#if YYDEBUG || 0 549/* The user-facing name of the symbol whose (internal) number is 550 YYSYMBOL. No bounds checking. */ 551static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; 552 553/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 554 First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 555static const char *const yytname[] = 556{ 557 "\"end of file\"", "error", "\"invalid token\"", "R_INTEGER", "\"(\"", 558 "\")\"", "\"*\"", "\"+\"", "\".\"", "\"|\"", "\"?\"", "\"{\"", "\"}\"", 559 "\",\"", "\"[\"", "\"]\"", "\"-\"", "\"^\"", "R_IDENTIFIER", "$accept", 560 "regex", "expression", "term", "factor", "atom", "set_items", "set_item", 561 "literal", YY_NULLPTR 562}; 563 564static const char * 565yysymbol_name (yysymbol_kind_t yysymbol) 566{ 567 return yytname[yysymbol]; 568} 569#endif 570 571#ifdef YYPRINT 572/* YYTOKNUM[NUM] -- (External) token number corresponding to the 573 (internal) symbol number NUM (which must be that of a token). */ 574static const yytype_int16 yytoknum[] = 575{ 576 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 577 265, 266, 267, 268, 269, 270, 271, 272, 273 578}; 579#endif 580 581#define YYPACT_NINF (-8) 582 583#define yypact_value_is_default(Yyn) \ 584 ((Yyn) == YYPACT_NINF) 585 586#define YYTABLE_NINF (-1) 587 588#define yytable_value_is_error(Yyn) \ 589 0 590 591 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 592 STATE-NUM. */ 593static const yytype_int8 yypact[] = 594{ 595 0, -8, 0, -8, 2, -8, 13, -8, -7, 0, 596 16, -8, 10, 3, 18, 3, 9, -8, 0, -8, 597 -8, -8, -8, 25, -8, 19, -8, -8, 3, -8, 598 17, -8, -8, -8, 4, 20, -8, -8 599}; 600 601 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. 602 Performed when YYTABLE does not specify something else to do. Zero 603 means the default is an error. */ 604static const yytype_int8 yydefact[] = 605{ 606 0, 23, 0, 15, 0, 24, 0, 2, 3, 5, 607 7, 14, 0, 0, 0, 19, 21, 1, 0, 6, 608 8, 9, 10, 0, 18, 0, 16, 20, 0, 4, 609 0, 17, 22, 11, 0, 0, 12, 13 610}; 611 612 /* YYPGOTO[NTERM-NUM]. */ 613static const yytype_int8 yypgoto[] = 614{ 615 -8, -8, -1, 22, -8, -8, -3, -8, -4 616}; 617 618 /* YYDEFGOTO[NTERM-NUM]. */ 619static const yytype_int8 yydefgoto[] = 620{ 621 0, 6, 7, 8, 9, 10, 14, 15, 11 622}; 623 624 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If 625 positive, shift that token. If negative, reduce the rule whose 626 number is the opposite. If YYTABLE_NINF, syntax error. */ 627static const yytype_int8 yytable[] = 628{ 629 16, 12, 18, 1, 2, 1, 1, 35, 3, 16, 630 25, 16, 27, 17, 4, 24, 36, 29, 5, 13, 631 5, 5, 20, 21, 32, 28, 22, 23, 30, 33, 632 34, 19, 37, 26, 31 633}; 634 635static const yytype_int8 yycheck[] = 636{ 637 4, 2, 9, 3, 4, 3, 3, 3, 8, 13, 638 13, 15, 15, 0, 14, 5, 12, 18, 18, 17, 639 18, 18, 6, 7, 28, 16, 10, 11, 3, 12, 640 13, 9, 12, 15, 15 641}; 642 643 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 644 symbol of state STATE-NUM. */ 645static const yytype_int8 yystos[] = 646{ 647 0, 3, 4, 8, 14, 18, 20, 21, 22, 23, 648 24, 27, 21, 17, 25, 26, 27, 0, 9, 22, 649 6, 7, 10, 11, 5, 25, 15, 25, 16, 21, 650 3, 15, 27, 12, 13, 3, 12, 12 651}; 652 653 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 654static const yytype_int8 yyr1[] = 655{ 656 0, 19, 20, 21, 21, 22, 22, 23, 23, 23, 657 23, 23, 23, 23, 24, 24, 24, 24, 24, 25, 658 25, 26, 26, 27, 27 659}; 660 661 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ 662static const yytype_int8 yyr2[] = 663{ 664 0, 2, 1, 1, 3, 1, 2, 1, 2, 2, 665 2, 4, 5, 6, 1, 1, 3, 4, 3, 1, 666 2, 1, 3, 1, 1 667}; 668 669 670enum { YYENOMEM = -2 }; 671 672#define yyerrok (yyerrstatus = 0) 673#define yyclearin (yychar = YYEMPTY) 674 675#define YYACCEPT goto yyacceptlab 676#define YYABORT goto yyabortlab 677#define YYERROR goto yyerrorlab 678 679 680#define YYRECOVERING() (!!yyerrstatus) 681 682#define YYBACKUP(Token, Value) \ 683 do \ 684 if (yychar == YYEMPTY) \ 685 { \ 686 yychar = (Token); \ 687 yylval = (Value); \ 688 YYPOPSTACK (yylen); \ 689 yystate = *yyssp; \ 690 goto yybackup; \ 691 } \ 692 else \ 693 { \ 694 yyerror (ctx, YY_("syntax error: cannot back up")); \ 695 YYERROR; \ 696 } \ 697 while (0) 698 699/* Backward compatibility with an undocumented macro. 700 Use YYerror or YYUNDEF. */ 701#define YYERRCODE YYUNDEF 702 703 704/* Enable debugging if requested. */ 705#if YYDEBUG 706 707# ifndef YYFPRINTF 708# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ 709# define YYFPRINTF fprintf 710# endif 711 712# define YYDPRINTF(Args) \ 713do { \ 714 if (yydebug) \ 715 YYFPRINTF Args; \ 716} while (0) 717 718/* This macro is provided for backward compatibility. */ 719# ifndef YY_LOCATION_PRINT 720# define YY_LOCATION_PRINT(File, Loc) ((void) 0) 721# endif 722 723 724# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ 725do { \ 726 if (yydebug) \ 727 { \ 728 YYFPRINTF (stderr, "%s ", Title); \ 729 yy_symbol_print (stderr, \ 730 Kind, Value, ctx); \ 731 YYFPRINTF (stderr, "\n"); \ 732 } \ 733} while (0) 734 735 736/*-----------------------------------. 737| Print this symbol's value on YYO. | 738`-----------------------------------*/ 739 740static void 741yy_symbol_value_print (FILE *yyo, 742 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, REContext& ctx) 743{ 744 FILE *yyoutput = yyo; 745 YY_USE (yyoutput); 746 YY_USE (ctx); 747 if (!yyvaluep) 748 return; 749# ifdef YYPRINT 750 if (yykind < YYNTOKENS) 751 YYPRINT (yyo, yytoknum[yykind], *yyvaluep); 752# endif 753 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 754 YY_USE (yykind); 755 YY_IGNORE_MAYBE_UNINITIALIZED_END 756} 757 758 759/*---------------------------. 760| Print this symbol on YYO. | 761`---------------------------*/ 762 763static void 764yy_symbol_print (FILE *yyo, 765 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, REContext& ctx) 766{ 767 YYFPRINTF (yyo, "%s %s (", 768 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); 769 770 yy_symbol_value_print (yyo, yykind, yyvaluep, ctx); 771 YYFPRINTF (yyo, ")"); 772} 773 774/*------------------------------------------------------------------. 775| yy_stack_print -- Print the state stack from its BOTTOM up to its | 776| TOP (included). | 777`------------------------------------------------------------------*/ 778 779static void 780yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) 781{ 782 YYFPRINTF (stderr, "Stack now"); 783 for (; yybottom <= yytop; yybottom++) 784 { 785 int yybot = *yybottom; 786 YYFPRINTF (stderr, " %d", yybot); 787 } 788 YYFPRINTF (stderr, "\n"); 789} 790 791# define YY_STACK_PRINT(Bottom, Top) \ 792do { \ 793 if (yydebug) \ 794 yy_stack_print ((Bottom), (Top)); \ 795} while (0) 796 797 798/*------------------------------------------------. 799| Report that the YYRULE is going to be reduced. | 800`------------------------------------------------*/ 801 802static void 803yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, 804 int yyrule, REContext& ctx) 805{ 806 int yylno = yyrline[yyrule]; 807 int yynrhs = yyr2[yyrule]; 808 int yyi; 809 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", 810 yyrule - 1, yylno); 811 /* The symbols being reduced. */ 812 for (yyi = 0; yyi < yynrhs; yyi++) 813 { 814 YYFPRINTF (stderr, " $%d = ", yyi + 1); 815 yy_symbol_print (stderr, 816 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), 817 &yyvsp[(yyi + 1) - (yynrhs)], ctx); 818 YYFPRINTF (stderr, "\n"); 819 } 820} 821 822# define YY_REDUCE_PRINT(Rule) \ 823do { \ 824 if (yydebug) \ 825 yy_reduce_print (yyssp, yyvsp, Rule, ctx); \ 826} while (0) 827 828/* Nonzero means print parse trace. It is left uninitialized so that 829 multiple parsers can coexist. */ 830int yydebug; 831#else /* !YYDEBUG */ 832# define YYDPRINTF(Args) ((void) 0) 833# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) 834# define YY_STACK_PRINT(Bottom, Top) 835# define YY_REDUCE_PRINT(Rule) 836#endif /* !YYDEBUG */ 837 838 839/* YYINITDEPTH -- initial size of the parser's stacks. */ 840#ifndef YYINITDEPTH 841# define YYINITDEPTH 200 842#endif 843 844/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 845 if the built-in stack extension method is used). 846 847 Do not make this value too large; the results are undefined if 848 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 849 evaluated with infinite-precision integer arithmetic. */ 850 851#ifndef YYMAXDEPTH 852# define YYMAXDEPTH 10000 853#endif 854 855 856 857 858 859 860/*-----------------------------------------------. 861| Release the memory associated to this symbol. | 862`-----------------------------------------------*/ 863 864static void 865yydestruct (const char *yymsg, 866 yysymbol_kind_t yykind, YYSTYPE *yyvaluep, REContext& ctx) 867{ 868 YY_USE (yyvaluep); 869 YY_USE (ctx); 870 if (!yymsg) 871 yymsg = "Deleting"; 872 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); 873 874 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 875 YY_USE (yykind); 876 YY_IGNORE_MAYBE_UNINITIALIZED_END 877} 878 879 880/* Lookahead token kind. */ 881int yychar; 882 883/* The semantic value of the lookahead symbol. */ 884YYSTYPE yylval; 885/* Number of syntax errors so far. */ 886int yynerrs; 887 888 889 890 891/*----------. 892| yyparse. | 893`----------*/ 894 895int 896yyparse (REContext& ctx) 897{ 898 yy_state_fast_t yystate = 0; 899 /* Number of tokens to shift before error messages enabled. */ 900 int yyerrstatus = 0; 901 902 /* Refer to the stacks through separate pointers, to allow yyoverflow 903 to reallocate them elsewhere. */ 904 905 /* Their size. */ 906 YYPTRDIFF_T yystacksize = YYINITDEPTH; 907 908 /* The state stack: array, bottom, top. */ 909 yy_state_t yyssa[YYINITDEPTH]; 910 yy_state_t *yyss = yyssa; 911 yy_state_t *yyssp = yyss; 912 913 /* The semantic value stack: array, bottom, top. */ 914 YYSTYPE yyvsa[YYINITDEPTH]; 915 YYSTYPE *yyvs = yyvsa; 916 YYSTYPE *yyvsp = yyvs; 917 918 int yyn; 919 /* The return value of yyparse. */ 920 int yyresult; 921 /* Lookahead symbol kind. */ 922 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; 923 /* The variables used to return semantic value and location from the 924 action routines. */ 925 YYSTYPE yyval; 926 927 928 929#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) 930 931 /* The number of symbols on the RHS of the reduced rule. 932 Keep to zero when no symbol should be popped. */ 933 int yylen = 0; 934 935 YYDPRINTF ((stderr, "Starting parse\n")); 936 937 yychar = YYEMPTY; /* Cause a token to be read. */ 938 goto yysetstate; 939 940 941/*------------------------------------------------------------. 942| yynewstate -- push a new state, which is found in yystate. | 943`------------------------------------------------------------*/ 944yynewstate: 945 /* In all cases, when you get here, the value and location stacks 946 have just been pushed. So pushing a state here evens the stacks. */ 947 yyssp++; 948 949 950/*--------------------------------------------------------------------. 951| yysetstate -- set current state (the top of the stack) to yystate. | 952`--------------------------------------------------------------------*/ 953yysetstate: 954 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 955 YY_ASSERT (0 <= yystate && yystate < YYNSTATES); 956 YY_IGNORE_USELESS_CAST_BEGIN 957 *yyssp = YY_CAST (yy_state_t, yystate); 958 YY_IGNORE_USELESS_CAST_END 959 YY_STACK_PRINT (yyss, yyssp); 960 961 if (yyss + yystacksize - 1 <= yyssp) 962#if !defined yyoverflow && !defined YYSTACK_RELOCATE 963 goto yyexhaustedlab; 964#else 965 { 966 /* Get the current used size of the three stacks, in elements. */ 967 YYPTRDIFF_T yysize = yyssp - yyss + 1; 968 969# if defined yyoverflow 970 { 971 /* Give user a chance to reallocate the stack. Use copies of 972 these so that the &'s don't force the real ones into 973 memory. */ 974 yy_state_t *yyss1 = yyss; 975 YYSTYPE *yyvs1 = yyvs; 976 977 /* Each stack pointer address is followed by the size of the 978 data in use in that stack, in bytes. This used to be a 979 conditional around just the two extra args, but that might 980 be undefined if yyoverflow is a macro. */ 981 yyoverflow (YY_("memory exhausted"), 982 &yyss1, yysize * YYSIZEOF (*yyssp), 983 &yyvs1, yysize * YYSIZEOF (*yyvsp), 984 &yystacksize); 985 yyss = yyss1; 986 yyvs = yyvs1; 987 } 988# else /* defined YYSTACK_RELOCATE */ 989 /* Extend the stack our own way. */ 990 if (YYMAXDEPTH <= yystacksize) 991 goto yyexhaustedlab; 992 yystacksize *= 2; 993 if (YYMAXDEPTH < yystacksize) 994 yystacksize = YYMAXDEPTH; 995 996 { 997 yy_state_t *yyss1 = yyss; 998 union yyalloc *yyptr = 999 YY_CAST (union yyalloc *, 1000 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); 1001 if (! yyptr) 1002 goto yyexhaustedlab; 1003 YYSTACK_RELOCATE (yyss_alloc, yyss); 1004 YYSTACK_RELOCATE (yyvs_alloc, yyvs); 1005# undef YYSTACK_RELOCATE 1006 if (yyss1 != yyssa) 1007 YYSTACK_FREE (yyss1); 1008 } 1009# endif 1010 1011 yyssp = yyss + yysize - 1; 1012 yyvsp = yyvs + yysize - 1; 1013 1014 YY_IGNORE_USELESS_CAST_BEGIN 1015 YYDPRINTF ((stderr, "Stack size increased to %ld\n", 1016 YY_CAST (long, yystacksize))); 1017 YY_IGNORE_USELESS_CAST_END 1018 1019 if (yyss + yystacksize - 1 <= yyssp) 1020 YYABORT; 1021 } 1022#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ 1023 1024 if (yystate == YYFINAL) 1025 YYACCEPT; 1026 1027 goto yybackup; 1028 1029 1030/*-----------. 1031| yybackup. | 1032`-----------*/ 1033yybackup: 1034 /* Do appropriate processing given the current state. Read a 1035 lookahead token if we need one and don't already have one. */ 1036 1037 /* First try to decide what to do without reference to lookahead token. */ 1038 yyn = yypact[yystate]; 1039 if (yypact_value_is_default (yyn)) 1040 goto yydefault; 1041 1042 /* Not known => get a lookahead token if don't already have one. */ 1043 1044 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ 1045 if (yychar == YYEMPTY) 1046 { 1047 YYDPRINTF ((stderr, "Reading a token\n")); 1048 yychar = yylex (); 1049 } 1050 1051 if (yychar <= YYEOF) 1052 { 1053 yychar = YYEOF; 1054 yytoken = YYSYMBOL_YYEOF; 1055 YYDPRINTF ((stderr, "Now at end of input.\n")); 1056 } 1057 else if (yychar == YYerror) 1058 { 1059 /* The scanner already issued an error message, process directly 1060 to error recovery. But do not keep the error token as 1061 lookahead, it is too special and may lead us to an endless 1062 loop in error recovery. */ 1063 yychar = YYUNDEF; 1064 yytoken = YYSYMBOL_YYerror; 1065 goto yyerrlab1; 1066 } 1067 else 1068 { 1069 yytoken = YYTRANSLATE (yychar); 1070 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 1071 } 1072 1073 /* If the proper action on seeing token YYTOKEN is to reduce or to 1074 detect an error, take that action. */ 1075 yyn += yytoken; 1076 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1077 goto yydefault; 1078 yyn = yytable[yyn]; 1079 if (yyn <= 0) 1080 { 1081 if (yytable_value_is_error (yyn)) 1082 goto yyerrlab; 1083 yyn = -yyn; 1084 goto yyreduce; 1085 } 1086 1087 /* Count tokens shifted since error; after three, turn off error 1088 status. */ 1089 if (yyerrstatus) 1090 yyerrstatus--; 1091 1092 /* Shift the lookahead token. */ 1093 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1094 yystate = yyn; 1095 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1096 *++yyvsp = yylval; 1097 YY_IGNORE_MAYBE_UNINITIALIZED_END 1098 1099 /* Discard the shifted token. */ 1100 yychar = YYEMPTY; 1101 goto yynewstate; 1102 1103 1104/*-----------------------------------------------------------. 1105| yydefault -- do the default action for the current state. | 1106`-----------------------------------------------------------*/ 1107yydefault: 1108 yyn = yydefact[yystate]; 1109 if (yyn == 0) 1110 goto yyerrlab; 1111 goto yyreduce; 1112 1113 1114/*-----------------------------. 1115| yyreduce -- do a reduction. | 1116`-----------------------------*/ 1117yyreduce: 1118 /* yyn is the number of a rule to reduce with. */ 1119 yylen = yyr2[yyn]; 1120 1121 /* If YYLEN is nonzero, implement the default value of the action: 1122 '$$ = $1'. 1123 1124 Otherwise, the following line sets YYVAL to garbage. 1125 This behavior is undocumented and Bison 1126 users should not rely upon it. Assigning to YYVAL 1127 unconditionally makes the parser a bit smaller, and it avoids a 1128 GCC warning that YYVAL may be used uninitialized. */ 1129 yyval = yyvsp[1-yylen]; 1130 1131 1132 YY_REDUCE_PRINT (yyn); 1133 switch (yyn) 1134 { 1135 case 2: /* regex: expression */ 1136 { 1137 *ctx.expr = (*(yyvsp[0].rValue)); 1138 delete (yyvsp[0].rValue); 1139 } 1140 break; 1141 1142 case 4: /* expression: term "|" expression */ 1143 { 1144 *(yyvsp[-2].rValue) = *(yyvsp[-2].rValue) | *(yyvsp[0].rValue); 1145 delete (yyvsp[0].rValue); 1146 (yyval.rValue) = (yyvsp[-2].rValue); 1147 } 1148 break; 1149 1150 case 6: /* term: factor term */ 1151 { 1152 *(yyvsp[-1].rValue) = *(yyvsp[-1].rValue) + *(yyvsp[0].rValue); 1153 delete (yyvsp[0].rValue); 1154 (yyval.rValue) = (yyvsp[-1].rValue); 1155 } 1156 break; 1157 1158 case 8: /* factor: atom "*" */ 1159 { 1160 *(yyvsp[-1].rValue) = *(*(yyvsp[-1].rValue)); 1161 (yyval.rValue) = (yyvsp[-1].rValue); 1162 } 1163 break; 1164 1165 case 9: /* factor: atom "+" */ 1166 { 1167 *(yyvsp[-1].rValue) = +(*(yyvsp[-1].rValue)); 1168 (yyval.rValue) = (yyvsp[-1].rValue); 1169 } 1170 break; 1171 1172 case 10: /* factor: atom "?" */ 1173 { 1174 *(yyvsp[-1].rValue) = (*(yyvsp[-1].rValue))(0, 1); 1175 (yyval.rValue) = (yyvsp[-1].rValue); 1176 } 1177 break; 1178 1179 case 11: /* factor: atom "{" R_INTEGER "}" */ 1180 { 1181 *(yyvsp[-3].rValue) = (*(yyvsp[-3].rValue))((yyvsp[-1].iValue), (yyvsp[-1].iValue)); 1182 (yyval.rValue) = (yyvsp[-3].rValue); 1183 } 1184 break; 1185 1186 case 12: /* factor: atom "{" R_INTEGER "," "}" */ 1187 { 1188 *(yyvsp[-4].rValue) = (*(yyvsp[-4].rValue))((yyvsp[-2].iValue)); 1189 (yyval.rValue) = (yyvsp[-4].rValue); 1190 } 1191 break; 1192 1193 case 13: /* factor: atom "{" R_INTEGER "," R_INTEGER "}" */ 1194 { 1195 *(yyvsp[-5].rValue) = (*(yyvsp[-5].rValue))((yyvsp[-3].iValue), (yyvsp[-1].iValue)); 1196 (yyval.rValue) = (yyvsp[-5].rValue); 1197 } 1198 break; 1199 1200 case 14: /* atom: literal */ 1201 { (yyval.rValue) = new REG((yyvsp[0].iValue)); } 1202 break; 1203 1204 case 15: /* atom: "." */ 1205 { 1206 IntArgs range = IntArgs::create(ctx.dom.max().toInt() - ctx.dom.min().toInt() + 1, ctx.dom.min().toInt()); 1207 (yyval.rValue) = new REG(range); 1208 } 1209 break; 1210 1211 case 16: /* atom: "[" set_items "]" */ 1212 { 1213 std::vector<int> v; 1214 v.reserve((yyvsp[-1].setValue)->size()); 1215 for(auto i : *(yyvsp[-1].setValue)) { 1216 v.push_back(i); 1217 } 1218 delete (yyvsp[-1].setValue); 1219 (yyval.rValue) = new REG(IntArgs(v)); 1220 } 1221 break; 1222 1223 case 17: /* atom: "[" "^" set_items "]" */ 1224 { 1225 std::vector<int> diff; 1226 std::unordered_set<int> domain; 1227 for(int i = ctx.dom.min().toInt(); i<=ctx.dom.max().toInt(); ++i) { 1228 domain.insert(i); 1229 } 1230 std::set_difference( 1231 domain.begin(), domain.end(), 1232 (yyvsp[-1].setValue)->begin(), (yyvsp[-1].setValue)->end(), 1233 std::inserter(diff, diff.begin()) 1234 ); 1235 delete (yyvsp[-1].setValue); 1236 (yyval.rValue) = new REG(IntArgs(diff)); 1237 } 1238 break; 1239 1240 case 18: /* atom: "(" expression ")" */ 1241 { (yyval.rValue) = (yyvsp[-1].rValue); } 1242 break; 1243 1244 case 20: /* set_items: set_item set_items */ 1245 { 1246 (yyval.setValue) = (yyvsp[-1].setValue); 1247 for (auto i : *(yyvsp[0].setValue)) { 1248 (yyvsp[-1].setValue)->insert(i); 1249 } 1250 delete (yyvsp[0].setValue); 1251 } 1252 break; 1253 1254 case 21: /* set_item: literal */ 1255 { 1256 (yyval.setValue) = new std::unordered_set<int>({(yyvsp[0].iValue)}); 1257 } 1258 break; 1259 1260 case 22: /* set_item: literal "-" literal */ 1261 { 1262 int from = (yyvsp[-2].iValue); 1263 int to = (yyvsp[0].iValue); 1264 if (to < from) { 1265 std::swap(from,to); 1266 } 1267 (yyval.setValue) = new std::unordered_set<int>; 1268 for(int i = from; i<=to; ++i) { 1269 (yyval.setValue)->insert(i); 1270 } 1271 } 1272 break; 1273 1274 case 24: /* literal: R_IDENTIFIER */ 1275 { 1276 std::string s((yyvsp[0].sValue)); 1277 auto find = ctx.idMap.find(s); 1278 if (find == ctx.idMap.end()) { 1279 throw std::runtime_error("Unknown identifier: " + s); 1280 } 1281 (yyval.iValue) = find->second; 1282 } 1283 break; 1284 1285 1286 1287 default: break; 1288 } 1289 /* User semantic actions sometimes alter yychar, and that requires 1290 that yytoken be updated with the new translation. We take the 1291 approach of translating immediately before every use of yytoken. 1292 One alternative is translating here after every semantic action, 1293 but that translation would be missed if the semantic action invokes 1294 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or 1295 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an 1296 incorrect destructor might then be invoked immediately. In the 1297 case of YYERROR or YYBACKUP, subsequent parser actions might lead 1298 to an incorrect destructor call or verbose syntax error message 1299 before the lookahead is translated. */ 1300 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); 1301 1302 YYPOPSTACK (yylen); 1303 yylen = 0; 1304 1305 *++yyvsp = yyval; 1306 1307 /* Now 'shift' the result of the reduction. Determine what state 1308 that goes to, based on the state we popped back to and the rule 1309 number reduced by. */ 1310 { 1311 const int yylhs = yyr1[yyn] - YYNTOKENS; 1312 const int yyi = yypgoto[yylhs] + *yyssp; 1313 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp 1314 ? yytable[yyi] 1315 : yydefgoto[yylhs]); 1316 } 1317 1318 goto yynewstate; 1319 1320 1321/*--------------------------------------. 1322| yyerrlab -- here on detecting error. | 1323`--------------------------------------*/ 1324yyerrlab: 1325 /* Make sure we have latest lookahead translation. See comments at 1326 user semantic actions for why this is necessary. */ 1327 yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); 1328 /* If not already recovering from an error, report this error. */ 1329 if (!yyerrstatus) 1330 { 1331 ++yynerrs; 1332 yyerror (ctx, YY_("syntax error")); 1333 } 1334 1335 if (yyerrstatus == 3) 1336 { 1337 /* If just tried and failed to reuse lookahead token after an 1338 error, discard it. */ 1339 1340 if (yychar <= YYEOF) 1341 { 1342 /* Return failure if at end of input. */ 1343 if (yychar == YYEOF) 1344 YYABORT; 1345 } 1346 else 1347 { 1348 yydestruct ("Error: discarding", 1349 yytoken, &yylval, ctx); 1350 yychar = YYEMPTY; 1351 } 1352 } 1353 1354 /* Else will try to reuse lookahead token after shifting the error 1355 token. */ 1356 goto yyerrlab1; 1357 1358 1359/*---------------------------------------------------. 1360| yyerrorlab -- error raised explicitly by YYERROR. | 1361`---------------------------------------------------*/ 1362yyerrorlab: 1363 /* Pacify compilers when the user code never invokes YYERROR and the 1364 label yyerrorlab therefore never appears in user code. */ 1365 if (0) 1366 YYERROR; 1367 1368 /* Do not reclaim the symbols of the rule whose action triggered 1369 this YYERROR. */ 1370 YYPOPSTACK (yylen); 1371 yylen = 0; 1372 YY_STACK_PRINT (yyss, yyssp); 1373 yystate = *yyssp; 1374 goto yyerrlab1; 1375 1376 1377/*-------------------------------------------------------------. 1378| yyerrlab1 -- common code for both syntax error and YYERROR. | 1379`-------------------------------------------------------------*/ 1380yyerrlab1: 1381 yyerrstatus = 3; /* Each real token shifted decrements this. */ 1382 1383 /* Pop stack until we find a state that shifts the error token. */ 1384 for (;;) 1385 { 1386 yyn = yypact[yystate]; 1387 if (!yypact_value_is_default (yyn)) 1388 { 1389 yyn += YYSYMBOL_YYerror; 1390 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) 1391 { 1392 yyn = yytable[yyn]; 1393 if (0 < yyn) 1394 break; 1395 } 1396 } 1397 1398 /* Pop the current state because it cannot handle the error token. */ 1399 if (yyssp == yyss) 1400 YYABORT; 1401 1402 1403 yydestruct ("Error: popping", 1404 YY_ACCESSING_SYMBOL (yystate), yyvsp, ctx); 1405 YYPOPSTACK (1); 1406 yystate = *yyssp; 1407 YY_STACK_PRINT (yyss, yyssp); 1408 } 1409 1410 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1411 *++yyvsp = yylval; 1412 YY_IGNORE_MAYBE_UNINITIALIZED_END 1413 1414 1415 /* Shift the error token. */ 1416 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); 1417 1418 yystate = yyn; 1419 goto yynewstate; 1420 1421 1422/*-------------------------------------. 1423| yyacceptlab -- YYACCEPT comes here. | 1424`-------------------------------------*/ 1425yyacceptlab: 1426 yyresult = 0; 1427 goto yyreturn; 1428 1429 1430/*-----------------------------------. 1431| yyabortlab -- YYABORT comes here. | 1432`-----------------------------------*/ 1433yyabortlab: 1434 yyresult = 1; 1435 goto yyreturn; 1436 1437 1438#if !defined yyoverflow 1439/*-------------------------------------------------. 1440| yyexhaustedlab -- memory exhaustion comes here. | 1441`-------------------------------------------------*/ 1442yyexhaustedlab: 1443 yyerror (ctx, YY_("memory exhausted")); 1444 yyresult = 2; 1445 goto yyreturn; 1446#endif 1447 1448 1449/*-------------------------------------------------------. 1450| yyreturn -- parsing is finished, clean up and return. | 1451`-------------------------------------------------------*/ 1452yyreturn: 1453 if (yychar != YYEMPTY) 1454 { 1455 /* Make sure we have latest lookahead translation. See comments at 1456 user semantic actions for why this is necessary. */ 1457 yytoken = YYTRANSLATE (yychar); 1458 yydestruct ("Cleanup: discarding lookahead", 1459 yytoken, &yylval, ctx); 1460 } 1461 /* Do not reclaim the symbols of the rule whose action triggered 1462 this YYABORT or YYACCEPT. */ 1463 YYPOPSTACK (yylen); 1464 YY_STACK_PRINT (yyss, yyssp); 1465 while (yyssp != yyss) 1466 { 1467 yydestruct ("Cleanup: popping", 1468 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, ctx); 1469 YYPOPSTACK (1); 1470 } 1471#ifndef yyoverflow 1472 if (yyss != yyssa) 1473 YYSTACK_FREE (yyss); 1474#endif 1475 1476 return yyresult; 1477} 1478 1479 1480 1481void yyerror(REContext& ctx, const char* s) { 1482 // TODO: Add error location 1483 throw std::runtime_error("Cannot parse regular expression: " + std::string(s)); 1484} 1485 1486std::unique_ptr<REG> regex_from_string(const std::string& regex_str, const IntSetVal& domain, const std::unordered_map<std::string, int>& identifiers) { 1487 REG* expr = new REG(); 1488 regex_yy_scan_string(regex_str.c_str()); 1489 REContext rctx = REContext{expr, domain, identifiers}; 1490 int err = yyparse(rctx); 1491 if (err != 0) { 1492 throw std::runtime_error("Cannot parse regular expression, error code " + std::to_string(err)); 1493 } 1494 return std::unique_ptr<REG>(expr); 1495}