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