this repo has no description
at develop 78 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 1 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 mza_yyparse 69#define yylex mza_yylex 70#define yyerror mza_yyerror 71#define yydebug mza_yydebug 72#define yynerrs mza_yynerrs 73 74/* First part of user prologue. */ 75 76#include <cstdio> 77#include <list> 78 79#include <minizinc/interpreter.hh> 80 81//Anonymous struct for when yyparse is exported 82typedef struct MZAContext MZAContext; 83#include <minizinc/support/mza_parser.tab.hh> 84 85using namespace MiniZinc; 86 87typedef struct yy_buffer_state *YY_BUFFER_STATE; 88YY_BUFFER_STATE mza_yy_scan_string ( const char* yy_str ); 89 90extern int yylex(YYSTYPE*, YYLTYPE*); 91extern FILE* yyin; 92 93struct ProcPatch { 94 int code; 95 BytecodeProc::Mode mode; 96 std::vector<std::pair<int, std::pair<std::string, int>>> patch; 97 ProcPatch(int code0, BytecodeProc::Mode mode0, std::vector<std::pair<int, std::pair<std::string, int>>> patch0) 98 : code(code0), mode(mode0), patch(std::move(patch0)) {} 99}; 100 101typedef struct MZAContext { 102 std::vector<BytecodeProc>& procs; 103 std::unordered_map<std::string, int>& proc_map; 104 int& max_glob; 105 std::vector<ProcPatch> to_patch; 106 BytecodeStream proc_body; 107 std::unordered_map<std::string, int> labels; 108 std::vector<std::pair<int, std::string>> patch_labels; 109 std::vector<std::pair<int, std::pair<std::string, int>>> patch_procs; 110} MZAContext; 111 112void yyerror(YYLTYPE* location, MZAContext& ctx, const char* s); 113 114 115# ifndef YY_CAST 116# ifdef __cplusplus 117# define YY_CAST(Type, Val) static_cast<Type> (Val) 118# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val) 119# else 120# define YY_CAST(Type, Val) ((Type) (Val)) 121# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) 122# endif 123# endif 124# ifndef YY_NULLPTR 125# if defined __cplusplus 126# if 201103L <= __cplusplus 127# define YY_NULLPTR nullptr 128# else 129# define YY_NULLPTR 0 130# endif 131# else 132# define YY_NULLPTR ((void*)0) 133# endif 134# endif 135 136#include <minizinc/support/mza_parser.tab.hh> 137/* Symbol kind. */ 138enum yysymbol_kind_t 139{ 140 YYSYMBOL_YYEMPTY = -2, 141 YYSYMBOL_YYEOF = 0, /* "end of file" */ 142 YYSYMBOL_YYerror = 1, /* error */ 143 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ 144 YYSYMBOL_MZA_INT = 3, /* MZA_INT */ 145 YYSYMBOL_MZA_REG = 4, /* MZA_REG */ 146 YYSYMBOL_MZA_MODE = 5, /* MZA_MODE */ 147 YYSYMBOL_MZA_CTX = 6, /* MZA_CTX */ 148 YYSYMBOL_MZA_ID = 7, /* MZA_ID */ 149 YYSYMBOL_MZA_COLON = 8, /* ":" */ 150 YYSYMBOL_MZA_DELAY = 9, /* "D" */ 151 YYSYMBOL_MZA_GLOBAL = 10, /* "GLOBAL" */ 152 YYSYMBOL_MZA_ADDI = 11, /* MZA_ADDI */ 153 YYSYMBOL_MZA_SUBI = 12, /* MZA_SUBI */ 154 YYSYMBOL_MZA_MULI = 13, /* MZA_MULI */ 155 YYSYMBOL_MZA_DIVI = 14, /* MZA_DIVI */ 156 YYSYMBOL_MZA_MODI = 15, /* MZA_MODI */ 157 YYSYMBOL_MZA_INCI = 16, /* MZA_INCI */ 158 YYSYMBOL_MZA_DECI = 17, /* MZA_DECI */ 159 YYSYMBOL_MZA_IMMI = 18, /* MZA_IMMI */ 160 YYSYMBOL_MZA_CLEAR = 19, /* MZA_CLEAR */ 161 YYSYMBOL_MZA_LOAD_GLOBAL = 20, /* MZA_LOAD_GLOBAL */ 162 YYSYMBOL_MZA_STORE_GLOBAL = 21, /* MZA_STORE_GLOBAL */ 163 YYSYMBOL_MZA_MOV = 22, /* MZA_MOV */ 164 YYSYMBOL_MZA_JMP = 23, /* MZA_JMP */ 165 YYSYMBOL_MZA_JMPIF = 24, /* MZA_JMPIF */ 166 YYSYMBOL_MZA_JMPIFNOT = 25, /* MZA_JMPIFNOT */ 167 YYSYMBOL_MZA_EQI = 26, /* MZA_EQI */ 168 YYSYMBOL_MZA_LTI = 27, /* MZA_LTI */ 169 YYSYMBOL_MZA_LEI = 28, /* MZA_LEI */ 170 YYSYMBOL_MZA_AND = 29, /* MZA_AND */ 171 YYSYMBOL_MZA_OR = 30, /* MZA_OR */ 172 YYSYMBOL_MZA_NOT = 31, /* MZA_NOT */ 173 YYSYMBOL_MZA_XOR = 32, /* MZA_XOR */ 174 YYSYMBOL_MZA_ISPAR = 33, /* MZA_ISPAR */ 175 YYSYMBOL_MZA_ISEMPTY = 34, /* MZA_ISEMPTY */ 176 YYSYMBOL_MZA_LENGTH = 35, /* MZA_LENGTH */ 177 YYSYMBOL_MZA_GET_VEC = 36, /* MZA_GET_VEC */ 178 YYSYMBOL_MZA_GET_ARRAY = 37, /* MZA_GET_ARRAY */ 179 YYSYMBOL_MZA_LB = 38, /* MZA_LB */ 180 YYSYMBOL_MZA_UB = 39, /* MZA_UB */ 181 YYSYMBOL_MZA_DOM = 40, /* MZA_DOM */ 182 YYSYMBOL_MZA_MAKE_SET = 41, /* MZA_MAKE_SET */ 183 YYSYMBOL_MZA_DIFF = 42, /* MZA_DIFF */ 184 YYSYMBOL_MZA_INTERSECTION = 43, /* MZA_INTERSECTION */ 185 YYSYMBOL_MZA_UNION = 44, /* MZA_UNION */ 186 YYSYMBOL_MZA_INTERSECT_DOMAIN = 45, /* MZA_INTERSECT_DOMAIN */ 187 YYSYMBOL_MZA_OPEN_AGGREGATION = 46, /* MZA_OPEN_AGGREGATION */ 188 YYSYMBOL_MZA_CLOSE_AGGREGATION = 47, /* MZA_CLOSE_AGGREGATION */ 189 YYSYMBOL_MZA_SIMPLIFY_LIN = 48, /* MZA_SIMPLIFY_LIN */ 190 YYSYMBOL_MZA_PUSH = 49, /* MZA_PUSH */ 191 YYSYMBOL_MZA_POP = 50, /* MZA_POP */ 192 YYSYMBOL_MZA_POST = 51, /* MZA_POST */ 193 YYSYMBOL_MZA_RET = 52, /* MZA_RET */ 194 YYSYMBOL_MZA_CALL = 53, /* MZA_CALL */ 195 YYSYMBOL_MZA_BUILTIN = 54, /* MZA_BUILTIN */ 196 YYSYMBOL_MZA_TCALL = 55, /* MZA_TCALL */ 197 YYSYMBOL_MZA_ITER_ARRAY = 56, /* MZA_ITER_ARRAY */ 198 YYSYMBOL_MZA_ITER_VEC = 57, /* MZA_ITER_VEC */ 199 YYSYMBOL_MZA_ITER_RANGE = 58, /* MZA_ITER_RANGE */ 200 YYSYMBOL_MZA_ITER_NEXT = 59, /* MZA_ITER_NEXT */ 201 YYSYMBOL_MZA_ITER_BREAK = 60, /* MZA_ITER_BREAK */ 202 YYSYMBOL_MZA_TRACE = 61, /* MZA_TRACE */ 203 YYSYMBOL_MZA_ABORT = 62, /* MZA_ABORT */ 204 YYSYMBOL_YYACCEPT = 63, /* $accept */ 205 YYSYMBOL_procedures = 64, /* procedures */ 206 YYSYMBOL_procedure = 65, /* procedure */ 207 YYSYMBOL_mode = 66, /* mode */ 208 YYSYMBOL_delay = 67, /* delay */ 209 YYSYMBOL_instructions = 68, /* instructions */ 210 YYSYMBOL_labeled_instr = 69, /* labeled_instr */ 211 YYSYMBOL_labels = 70, /* labels */ 212 YYSYMBOL_label = 71, /* label */ 213 YYSYMBOL_instruction = 72, /* instruction */ 214 YYSYMBOL_instrIR = 73, /* instrIR */ 215 YYSYMBOL_instrI = 74, /* instrI */ 216 YYSYMBOL_instrR = 75, /* instrR */ 217 YYSYMBOL_instrRR = 76, /* instrRR */ 218 YYSYMBOL_instrRS = 77, /* instrRS */ 219 YYSYMBOL_instrRRR = 78, /* instrRRR */ 220 YYSYMBOL_instrRRS = 79, /* instrRRS */ 221 YYSYMBOL_instrRRIRRR = 80, /* instrRRIRRR */ 222 YYSYMBOL_instrS = 81, /* instrS */ 223 YYSYMBOL_instr = 82, /* instr */ 224 YYSYMBOL_registers = 83 /* registers */ 225}; 226typedef enum yysymbol_kind_t yysymbol_kind_t; 227 228 229 230 231#ifdef short 232# undef short 233#endif 234 235/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure 236 <limits.h> and (if available) <stdint.h> are included 237 so that the code can choose integer types of a good width. */ 238 239#ifndef __PTRDIFF_MAX__ 240# include <limits.h> /* INFRINGES ON USER NAME SPACE */ 241# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 242# include <stdint.h> /* INFRINGES ON USER NAME SPACE */ 243# define YY_STDINT_H 244# endif 245#endif 246 247/* Narrow types that promote to a signed type and that can represent a 248 signed or unsigned integer of at least N bits. In tables they can 249 save space and decrease cache pressure. Promoting to a signed type 250 helps avoid bugs in integer arithmetic. */ 251 252#ifdef __INT_LEAST8_MAX__ 253typedef __INT_LEAST8_TYPE__ yytype_int8; 254#elif defined YY_STDINT_H 255typedef int_least8_t yytype_int8; 256#else 257typedef signed char yytype_int8; 258#endif 259 260#ifdef __INT_LEAST16_MAX__ 261typedef __INT_LEAST16_TYPE__ yytype_int16; 262#elif defined YY_STDINT_H 263typedef int_least16_t yytype_int16; 264#else 265typedef short yytype_int16; 266#endif 267 268/* Work around bug in HP-UX 11.23, which defines these macros 269 incorrectly for preprocessor constants. This workaround can likely 270 be removed in 2023, as HPE has promised support for HP-UX 11.23 271 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of 272 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */ 273#ifdef __hpux 274# undef UINT_LEAST8_MAX 275# undef UINT_LEAST16_MAX 276# define UINT_LEAST8_MAX 255 277# define UINT_LEAST16_MAX 65535 278#endif 279 280#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ 281typedef __UINT_LEAST8_TYPE__ yytype_uint8; 282#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ 283 && UINT_LEAST8_MAX <= INT_MAX) 284typedef uint_least8_t yytype_uint8; 285#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX 286typedef unsigned char yytype_uint8; 287#else 288typedef short yytype_uint8; 289#endif 290 291#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ 292typedef __UINT_LEAST16_TYPE__ yytype_uint16; 293#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ 294 && UINT_LEAST16_MAX <= INT_MAX) 295typedef uint_least16_t yytype_uint16; 296#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX 297typedef unsigned short yytype_uint16; 298#else 299typedef int yytype_uint16; 300#endif 301 302#ifndef YYPTRDIFF_T 303# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ 304# define YYPTRDIFF_T __PTRDIFF_TYPE__ 305# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ 306# elif defined PTRDIFF_MAX 307# ifndef ptrdiff_t 308# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ 309# endif 310# define YYPTRDIFF_T ptrdiff_t 311# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX 312# else 313# define YYPTRDIFF_T long 314# define YYPTRDIFF_MAXIMUM LONG_MAX 315# endif 316#endif 317 318#ifndef YYSIZE_T 319# ifdef __SIZE_TYPE__ 320# define YYSIZE_T __SIZE_TYPE__ 321# elif defined size_t 322# define YYSIZE_T size_t 323# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ 324# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ 325# define YYSIZE_T size_t 326# else 327# define YYSIZE_T unsigned 328# endif 329#endif 330 331#define YYSIZE_MAXIMUM \ 332 YY_CAST (YYPTRDIFF_T, \ 333 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ 334 ? YYPTRDIFF_MAXIMUM \ 335 : YY_CAST (YYSIZE_T, -1))) 336 337#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) 338 339 340/* Stored state numbers (used for stacks). */ 341typedef yytype_int8 yy_state_t; 342 343/* State numbers in computations. */ 344typedef int yy_state_fast_t; 345 346#ifndef YY_ 347# if defined YYENABLE_NLS && YYENABLE_NLS 348# if ENABLE_NLS 349# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ 350# define YY_(Msgid) dgettext ("bison-runtime", Msgid) 351# endif 352# endif 353# ifndef YY_ 354# define YY_(Msgid) Msgid 355# endif 356#endif 357 358 359#ifndef YY_ATTRIBUTE_PURE 360# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) 361# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) 362# else 363# define YY_ATTRIBUTE_PURE 364# endif 365#endif 366 367#ifndef YY_ATTRIBUTE_UNUSED 368# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) 369# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 370# else 371# define YY_ATTRIBUTE_UNUSED 372# endif 373#endif 374 375/* Suppress unused-variable warnings by "using" E. */ 376#if ! defined lint || defined __GNUC__ 377# define YY_USE(E) ((void) (E)) 378#else 379# define YY_USE(E) /* empty */ 380#endif 381 382#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ 383/* Suppress an incorrect diagnostic about yylval being uninitialized. */ 384# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 385 _Pragma ("GCC diagnostic push") \ 386 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ 387 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") 388# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ 389 _Pragma ("GCC diagnostic pop") 390#else 391# define YY_INITIAL_VALUE(Value) Value 392#endif 393#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 394# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 395# define YY_IGNORE_MAYBE_UNINITIALIZED_END 396#endif 397#ifndef YY_INITIAL_VALUE 398# define YY_INITIAL_VALUE(Value) /* Nothing. */ 399#endif 400 401#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ 402# define YY_IGNORE_USELESS_CAST_BEGIN \ 403 _Pragma ("GCC diagnostic push") \ 404 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") 405# define YY_IGNORE_USELESS_CAST_END \ 406 _Pragma ("GCC diagnostic pop") 407#endif 408#ifndef YY_IGNORE_USELESS_CAST_BEGIN 409# define YY_IGNORE_USELESS_CAST_BEGIN 410# define YY_IGNORE_USELESS_CAST_END 411#endif 412 413 414#define YY_ASSERT(E) ((void) (0 && (E))) 415 416#if 1 417 418/* The parser invokes alloca or malloc; define the necessary symbols. */ 419 420# ifdef YYSTACK_USE_ALLOCA 421# if YYSTACK_USE_ALLOCA 422# ifdef __GNUC__ 423# define YYSTACK_ALLOC __builtin_alloca 424# elif defined __BUILTIN_VA_ARG_INCR 425# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ 426# elif defined _AIX 427# define YYSTACK_ALLOC __alloca 428# elif defined _MSC_VER 429# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ 430# define alloca _alloca 431# else 432# define YYSTACK_ALLOC alloca 433# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS 434# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 435 /* Use EXIT_SUCCESS as a witness for stdlib.h. */ 436# ifndef EXIT_SUCCESS 437# define EXIT_SUCCESS 0 438# endif 439# endif 440# endif 441# endif 442# endif 443 444# ifdef YYSTACK_ALLOC 445 /* Pacify GCC's 'empty if-body' warning. */ 446# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) 447# ifndef YYSTACK_ALLOC_MAXIMUM 448 /* The OS might guarantee only one guard page at the bottom of the stack, 449 and a page size can be as small as 4096 bytes. So we cannot safely 450 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number 451 to allow for a few compiler-allocated temporary stack slots. */ 452# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ 453# endif 454# else 455# define YYSTACK_ALLOC YYMALLOC 456# define YYSTACK_FREE YYFREE 457# ifndef YYSTACK_ALLOC_MAXIMUM 458# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM 459# endif 460# if (defined __cplusplus && ! defined EXIT_SUCCESS \ 461 && ! ((defined YYMALLOC || defined malloc) \ 462 && (defined YYFREE || defined free))) 463# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ 464# ifndef EXIT_SUCCESS 465# define EXIT_SUCCESS 0 466# endif 467# endif 468# ifndef YYMALLOC 469# define YYMALLOC malloc 470# if ! defined malloc && ! defined EXIT_SUCCESS 471void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ 472# endif 473# endif 474# ifndef YYFREE 475# define YYFREE free 476# if ! defined free && ! defined EXIT_SUCCESS 477void free (void *); /* INFRINGES ON USER NAME SPACE */ 478# endif 479# endif 480# endif 481#endif /* 1 */ 482 483#if (! defined yyoverflow \ 484 && (! defined __cplusplus \ 485 || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ 486 && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) 487 488/* A type that is properly aligned for any stack member. */ 489union yyalloc 490{ 491 yy_state_t yyss_alloc; 492 YYSTYPE yyvs_alloc; 493 YYLTYPE yyls_alloc; 494}; 495 496/* The size of the maximum gap between one aligned stack and the next. */ 497# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) 498 499/* The size of an array large to enough to hold all stacks, each with 500 N elements. */ 501# define YYSTACK_BYTES(N) \ 502 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \ 503 + YYSIZEOF (YYLTYPE)) \ 504 + 2 * YYSTACK_GAP_MAXIMUM) 505 506# define YYCOPY_NEEDED 1 507 508/* Relocate STACK from its old location to the new one. The 509 local variables YYSIZE and YYSTACKSIZE give the old and new number of 510 elements in the stack, and YYPTR gives the new location of the 511 stack. Advance YYPTR to a properly aligned location for the next 512 stack. */ 513# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ 514 do \ 515 { \ 516 YYPTRDIFF_T yynewbytes; \ 517 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ 518 Stack = &yyptr->Stack_alloc; \ 519 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ 520 yyptr += yynewbytes / YYSIZEOF (*yyptr); \ 521 } \ 522 while (0) 523 524#endif 525 526#if defined YYCOPY_NEEDED && YYCOPY_NEEDED 527/* Copy COUNT objects from SRC to DST. The source and destination do 528 not overlap. */ 529# ifndef YYCOPY 530# if defined __GNUC__ && 1 < __GNUC__ 531# define YYCOPY(Dst, Src, Count) \ 532 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) 533# else 534# define YYCOPY(Dst, Src, Count) \ 535 do \ 536 { \ 537 YYPTRDIFF_T yyi; \ 538 for (yyi = 0; yyi < (Count); yyi++) \ 539 (Dst)[yyi] = (Src)[yyi]; \ 540 } \ 541 while (0) 542# endif 543# endif 544#endif /* !YYCOPY_NEEDED */ 545 546/* YYFINAL -- State number of the termination state. */ 547#define YYFINAL 2 548/* YYLAST -- Last index in YYTABLE. */ 549#define YYLAST 105 550 551/* YYNTOKENS -- Number of terminals. */ 552#define YYNTOKENS 63 553/* YYNNTS -- Number of nonterminals. */ 554#define YYNNTS 21 555/* YYNRULES -- Number of rules. */ 556#define YYNRULES 80 557/* YYNSTATES -- Number of states. */ 558#define YYNSTATES 121 559 560/* YYMAXUTOK -- Last valid token kind. */ 561#define YYMAXUTOK 317 562 563 564/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM 565 as returned by yylex, with out-of-bounds checking. */ 566#define YYTRANSLATE(YYX) \ 567 (0 <= (YYX) && (YYX) <= YYMAXUTOK \ 568 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ 569 : YYSYMBOL_YYUNDEF) 570 571/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM 572 as returned by yylex. */ 573static const yytype_int8 yytranslate[] = 574{ 575 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 576 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 577 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 578 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 579 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 580 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 581 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 582 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 583 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 584 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 585 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 586 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 587 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 588 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 589 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 590 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 591 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 592 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 593 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 594 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 595 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 596 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 597 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 598 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 599 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 600 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 601 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 602 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 603 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 604 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 605 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 606 55, 56, 57, 58, 59, 60, 61, 62 607}; 608 609#if YYDEBUG 610 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ 611static const yytype_int16 yyrline[] = 612{ 613 0, 154, 154, 156, 159, 205, 206, 209, 210, 212, 614 214, 217, 226, 227, 230, 233, 238, 244, 251, 257, 615 264, 272, 281, 289, 300, 307, 320, 331, 340, 347, 616 353, 360, 368, 376, 388, 391, 394, 395, 396, 397, 617 398, 399, 400, 403, 404, 405, 406, 407, 408, 409, 618 410, 411, 412, 415, 416, 417, 418, 421, 422, 423, 619 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 620 434, 435, 436, 439, 442, 445, 448, 449, 450, 454, 621 455 622}; 623#endif 624 625/** Accessing symbol of state STATE. */ 626#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) 627 628#if 1 629/* The user-facing name of the symbol whose (internal) number is 630 YYSYMBOL. No bounds checking. */ 631static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; 632 633/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 634 First, the terminals, then, starting at YYNTOKENS, nonterminals. */ 635static const char *const yytname[] = 636{ 637 "\"end of file\"", "error", "\"invalid token\"", "MZA_INT", "MZA_REG", 638 "MZA_MODE", "MZA_CTX", "MZA_ID", "\":\"", "\"D\"", "\"GLOBAL\"", 639 "MZA_ADDI", "MZA_SUBI", "MZA_MULI", "MZA_DIVI", "MZA_MODI", "MZA_INCI", 640 "MZA_DECI", "MZA_IMMI", "MZA_CLEAR", "MZA_LOAD_GLOBAL", 641 "MZA_STORE_GLOBAL", "MZA_MOV", "MZA_JMP", "MZA_JMPIF", "MZA_JMPIFNOT", 642 "MZA_EQI", "MZA_LTI", "MZA_LEI", "MZA_AND", "MZA_OR", "MZA_NOT", 643 "MZA_XOR", "MZA_ISPAR", "MZA_ISEMPTY", "MZA_LENGTH", "MZA_GET_VEC", 644 "MZA_GET_ARRAY", "MZA_LB", "MZA_UB", "MZA_DOM", "MZA_MAKE_SET", 645 "MZA_DIFF", "MZA_INTERSECTION", "MZA_UNION", "MZA_INTERSECT_DOMAIN", 646 "MZA_OPEN_AGGREGATION", "MZA_CLOSE_AGGREGATION", "MZA_SIMPLIFY_LIN", 647 "MZA_PUSH", "MZA_POP", "MZA_POST", "MZA_RET", "MZA_CALL", "MZA_BUILTIN", 648 "MZA_TCALL", "MZA_ITER_ARRAY", "MZA_ITER_VEC", "MZA_ITER_RANGE", 649 "MZA_ITER_NEXT", "MZA_ITER_BREAK", "MZA_TRACE", "MZA_ABORT", "$accept", 650 "procedures", "procedure", "mode", "delay", "instructions", 651 "labeled_instr", "labels", "label", "instruction", "instrIR", "instrI", 652 "instrR", "instrRR", "instrRS", "instrRRR", "instrRRS", "instrRRIRRR", 653 "instrS", "instr", "registers", YY_NULLPTR 654}; 655 656static const char * 657yysymbol_name (yysymbol_kind_t yysymbol) 658{ 659 return yytname[yysymbol]; 660} 661#endif 662 663#ifdef YYPRINT 664/* YYTOKNUM[NUM] -- (External) token number corresponding to the 665 (internal) symbol number NUM (which must be that of a token). */ 666static const yytype_int16 yytoknum[] = 667{ 668 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 669 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 670 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 671 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 672 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 673 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 674 315, 316, 317 675}; 676#endif 677 678#define YYPACT_NINF (-32) 679 680#define yypact_value_is_default(Yyn) \ 681 ((Yyn) == YYPACT_NINF) 682 683#define YYTABLE_NINF (-5) 684 685#define yytable_value_is_error(Yyn) \ 686 0 687 688 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 689 STATE-NUM. */ 690static const yytype_int8 yypact[] = 691{ 692 -32, 58, -32, -6, -32, -5, -3, -32, 57, 52, 693 -32, -32, 59, -32, -7, 54, -32, -32, -32, -32, 694 -32, -32, -32, -32, -32, 60, 61, -32, -32, -32, 695 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 696 -32, -32, 65, -32, -32, -32, -32, -32, -32, -32, 697 -32, 50, -32, -32, -32, -32, -32, -32, 64, 63, 698 66, -32, -32, -32, -32, -32, -32, -32, -32, -32, 699 69, 70, 71, 72, 73, 74, 78, 79, 67, -32, 700 -32, 80, 82, -32, -32, -32, -32, 81, -32, 83, 701 85, -32, -32, 87, 86, 88, 90, 91, -32, -32, 702 -32, 92, 84, 92, 94, -32, -32, -32, 95, 93, 703 98, -32, -32, -32, -32, -32, 99, 92, 100, 101, 704 -32 705}; 706 707 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. 708 Performed when YYTABLE does not specify something else to do. Zero 709 means the default is an error. */ 710static const yytype_int8 yydefact[] = 711{ 712 2, 0, 1, 0, 3, 0, 5, 6, 0, 7, 713 8, 9, 12, 10, 0, 0, 57, 58, 59, 60, 714 61, 36, 37, 34, 52, 0, 0, 43, 75, 53, 715 54, 62, 63, 64, 65, 66, 44, 67, 45, 46, 716 47, 68, 0, 50, 49, 51, 48, 69, 70, 71, 717 72, 0, 77, 74, 38, 39, 40, 76, 0, 0, 718 0, 55, 56, 73, 41, 35, 42, 78, 13, 11, 719 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 720 14, 0, 0, 79, 28, 29, 30, 0, 79, 0, 721 0, 16, 18, 0, 0, 0, 0, 0, 24, 31, 722 32, 33, 0, 26, 0, 17, 19, 20, 0, 0, 723 0, 80, 79, 27, 22, 21, 0, 25, 0, 0, 724 23 725}; 726 727 /* YYPGOTO[NTERM-NUM]. */ 728static const yytype_int8 yypgoto[] = 729{ 730 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 731 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 732 -31 733}; 734 735 /* YYDEFGOTO[NTERM-NUM]. */ 736static const yytype_int8 yydefgoto[] = 737{ 738 0, 1, 4, 8, 11, 12, 13, 14, 68, 69, 739 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 740 101 741}; 742 743 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If 744 positive, shift that token. If negative, reduce the rule whose 745 number is the opposite. If YYTABLE_NINF, syntax error. */ 746static const yytype_int8 yytable[] = 747{ 748 15, 5, 7, 6, 16, 17, 18, 19, 20, 21, 749 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 750 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 751 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 752 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 753 62, 63, 64, 65, 66, 67, 84, 103, 2, -4, 754 9, 10, 80, 81, 0, 82, 3, -4, 83, 87, 755 88, 89, 90, 91, 98, 92, 93, 94, 95, 85, 756 86, 117, 96, 97, 99, 100, 0, 112, 102, 105, 757 104, 106, 108, 107, 109, 110, 111, 113, 0, 114, 758 115, 116, 0, 118, 119, 120 759}; 760 761static const yytype_int8 yycheck[] = 762{ 763 7, 7, 5, 8, 11, 12, 13, 14, 15, 16, 764 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 765 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 766 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 767 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 768 57, 58, 59, 60, 61, 62, 6, 88, 0, 0, 769 3, 9, 8, 3, -1, 4, 8, 8, 3, 5, 770 7, 5, 3, 3, 7, 4, 4, 4, 4, 29, 771 30, 112, 4, 4, 4, 3, -1, 3, 7, 4, 772 7, 4, 4, 7, 4, 4, 4, 3, -1, 4, 773 7, 3, -1, 4, 4, 4 774}; 775 776 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing 777 symbol of state STATE-NUM. */ 778static const yytype_int8 yystos[] = 779{ 780 0, 64, 0, 8, 65, 7, 8, 5, 66, 3, 781 9, 67, 68, 69, 70, 7, 11, 12, 13, 14, 782 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 783 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 784 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 785 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 786 55, 56, 57, 58, 59, 60, 61, 62, 71, 72, 787 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 788 8, 3, 4, 3, 6, 29, 30, 5, 7, 5, 789 3, 3, 4, 4, 4, 4, 4, 4, 7, 4, 790 3, 83, 7, 83, 7, 4, 4, 7, 4, 4, 791 4, 4, 3, 3, 4, 7, 3, 83, 4, 4, 792 4 793}; 794 795 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ 796static const yytype_int8 yyr1[] = 797{ 798 0, 63, 64, 64, 65, 66, 66, 67, 67, 68, 799 68, 69, 70, 70, 71, 72, 72, 72, 72, 72, 800 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 801 72, 72, 72, 72, 73, 74, 75, 75, 75, 75, 802 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 803 76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 804 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 805 78, 78, 78, 79, 80, 81, 82, 82, 82, 83, 806 83 807}; 808 809 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ 810static const yytype_int8 yyr2[] = 811{ 812 0, 2, 0, 2, 7, 0, 1, 0, 1, 0, 813 2, 2, 0, 2, 2, 1, 2, 3, 2, 3, 814 3, 4, 4, 7, 2, 5, 3, 4, 2, 2, 815 2, 3, 3, 3, 1, 1, 1, 1, 1, 1, 816 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 817 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 818 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 819 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 820 2 821}; 822 823 824enum { YYENOMEM = -2 }; 825 826#define yyerrok (yyerrstatus = 0) 827#define yyclearin (yychar = YYEMPTY) 828 829#define YYACCEPT goto yyacceptlab 830#define YYABORT goto yyabortlab 831#define YYERROR goto yyerrorlab 832 833 834#define YYRECOVERING() (!!yyerrstatus) 835 836#define YYBACKUP(Token, Value) \ 837 do \ 838 if (yychar == YYEMPTY) \ 839 { \ 840 yychar = (Token); \ 841 yylval = (Value); \ 842 YYPOPSTACK (yylen); \ 843 yystate = *yyssp; \ 844 goto yybackup; \ 845 } \ 846 else \ 847 { \ 848 yyerror (&yylloc, ctx, YY_("syntax error: cannot back up")); \ 849 YYERROR; \ 850 } \ 851 while (0) 852 853/* Backward compatibility with an undocumented macro. 854 Use YYerror or YYUNDEF. */ 855#define YYERRCODE YYUNDEF 856 857/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. 858 If N is 0, then set CURRENT to the empty location which ends 859 the previous symbol: RHS[0] (always defined). */ 860 861#ifndef YYLLOC_DEFAULT 862# define YYLLOC_DEFAULT(Current, Rhs, N) \ 863 do \ 864 if (N) \ 865 { \ 866 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ 867 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ 868 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ 869 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ 870 } \ 871 else \ 872 { \ 873 (Current).first_line = (Current).last_line = \ 874 YYRHSLOC (Rhs, 0).last_line; \ 875 (Current).first_column = (Current).last_column = \ 876 YYRHSLOC (Rhs, 0).last_column; \ 877 } \ 878 while (0) 879#endif 880 881#define YYRHSLOC(Rhs, K) ((Rhs)[K]) 882 883 884/* Enable debugging if requested. */ 885#if YYDEBUG 886 887# ifndef YYFPRINTF 888# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ 889# define YYFPRINTF fprintf 890# endif 891 892# define YYDPRINTF(Args) \ 893do { \ 894 if (yydebug) \ 895 YYFPRINTF Args; \ 896} while (0) 897 898 899/* YY_LOCATION_PRINT -- Print the location on the stream. 900 This macro was not mandated originally: define only if we know 901 we won't break user code: when these are the locations we know. */ 902 903# ifndef YY_LOCATION_PRINT 904# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL 905 906/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ 907 908YY_ATTRIBUTE_UNUSED 909static int 910yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) 911{ 912 int res = 0; 913 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; 914 if (0 <= yylocp->first_line) 915 { 916 res += YYFPRINTF (yyo, "%d", yylocp->first_line); 917 if (0 <= yylocp->first_column) 918 res += YYFPRINTF (yyo, ".%d", yylocp->first_column); 919 } 920 if (0 <= yylocp->last_line) 921 { 922 if (yylocp->first_line < yylocp->last_line) 923 { 924 res += YYFPRINTF (yyo, "-%d", yylocp->last_line); 925 if (0 <= end_col) 926 res += YYFPRINTF (yyo, ".%d", end_col); 927 } 928 else if (0 <= end_col && yylocp->first_column < end_col) 929 res += YYFPRINTF (yyo, "-%d", end_col); 930 } 931 return res; 932 } 933 934# define YY_LOCATION_PRINT(File, Loc) \ 935 yy_location_print_ (File, &(Loc)) 936 937# else 938# define YY_LOCATION_PRINT(File, Loc) ((void) 0) 939# endif 940# endif /* !defined YY_LOCATION_PRINT */ 941 942 943# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ 944do { \ 945 if (yydebug) \ 946 { \ 947 YYFPRINTF (stderr, "%s ", Title); \ 948 yy_symbol_print (stderr, \ 949 Kind, Value, Location, ctx); \ 950 YYFPRINTF (stderr, "\n"); \ 951 } \ 952} while (0) 953 954 955/*-----------------------------------. 956| Print this symbol's value on YYO. | 957`-----------------------------------*/ 958 959static void 960yy_symbol_value_print (FILE *yyo, 961 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, MZAContext& ctx) 962{ 963 FILE *yyoutput = yyo; 964 YY_USE (yyoutput); 965 YY_USE (yylocationp); 966 YY_USE (ctx); 967 if (!yyvaluep) 968 return; 969# ifdef YYPRINT 970 if (yykind < YYNTOKENS) 971 YYPRINT (yyo, yytoknum[yykind], *yyvaluep); 972# endif 973 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 974 YY_USE (yykind); 975 YY_IGNORE_MAYBE_UNINITIALIZED_END 976} 977 978 979/*---------------------------. 980| Print this symbol on YYO. | 981`---------------------------*/ 982 983static void 984yy_symbol_print (FILE *yyo, 985 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, MZAContext& ctx) 986{ 987 YYFPRINTF (yyo, "%s %s (", 988 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); 989 990 YY_LOCATION_PRINT (yyo, *yylocationp); 991 YYFPRINTF (yyo, ": "); 992 yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, ctx); 993 YYFPRINTF (yyo, ")"); 994} 995 996/*------------------------------------------------------------------. 997| yy_stack_print -- Print the state stack from its BOTTOM up to its | 998| TOP (included). | 999`------------------------------------------------------------------*/ 1000 1001static void 1002yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) 1003{ 1004 YYFPRINTF (stderr, "Stack now"); 1005 for (; yybottom <= yytop; yybottom++) 1006 { 1007 int yybot = *yybottom; 1008 YYFPRINTF (stderr, " %d", yybot); 1009 } 1010 YYFPRINTF (stderr, "\n"); 1011} 1012 1013# define YY_STACK_PRINT(Bottom, Top) \ 1014do { \ 1015 if (yydebug) \ 1016 yy_stack_print ((Bottom), (Top)); \ 1017} while (0) 1018 1019 1020/*------------------------------------------------. 1021| Report that the YYRULE is going to be reduced. | 1022`------------------------------------------------*/ 1023 1024static void 1025yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, 1026 int yyrule, MZAContext& ctx) 1027{ 1028 int yylno = yyrline[yyrule]; 1029 int yynrhs = yyr2[yyrule]; 1030 int yyi; 1031 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", 1032 yyrule - 1, yylno); 1033 /* The symbols being reduced. */ 1034 for (yyi = 0; yyi < yynrhs; yyi++) 1035 { 1036 YYFPRINTF (stderr, " $%d = ", yyi + 1); 1037 yy_symbol_print (stderr, 1038 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), 1039 &yyvsp[(yyi + 1) - (yynrhs)], 1040 &(yylsp[(yyi + 1) - (yynrhs)]), ctx); 1041 YYFPRINTF (stderr, "\n"); 1042 } 1043} 1044 1045# define YY_REDUCE_PRINT(Rule) \ 1046do { \ 1047 if (yydebug) \ 1048 yy_reduce_print (yyssp, yyvsp, yylsp, Rule, ctx); \ 1049} while (0) 1050 1051/* Nonzero means print parse trace. It is left uninitialized so that 1052 multiple parsers can coexist. */ 1053int yydebug; 1054#else /* !YYDEBUG */ 1055# define YYDPRINTF(Args) ((void) 0) 1056# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) 1057# define YY_STACK_PRINT(Bottom, Top) 1058# define YY_REDUCE_PRINT(Rule) 1059#endif /* !YYDEBUG */ 1060 1061 1062/* YYINITDEPTH -- initial size of the parser's stacks. */ 1063#ifndef YYINITDEPTH 1064# define YYINITDEPTH 200 1065#endif 1066 1067/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 1068 if the built-in stack extension method is used). 1069 1070 Do not make this value too large; the results are undefined if 1071 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) 1072 evaluated with infinite-precision integer arithmetic. */ 1073 1074#ifndef YYMAXDEPTH 1075# define YYMAXDEPTH 10000 1076#endif 1077 1078 1079/* Context of a parse error. */ 1080typedef struct 1081{ 1082 yy_state_t *yyssp; 1083 yysymbol_kind_t yytoken; 1084 YYLTYPE *yylloc; 1085} yypcontext_t; 1086 1087/* Put in YYARG at most YYARGN of the expected tokens given the 1088 current YYCTX, and return the number of tokens stored in YYARG. If 1089 YYARG is null, return the number of expected tokens (guaranteed to 1090 be less than YYNTOKENS). Return YYENOMEM on memory exhaustion. 1091 Return 0 if there are more than YYARGN expected tokens, yet fill 1092 YYARG up to YYARGN. */ 1093static int 1094yypcontext_expected_tokens (const yypcontext_t *yyctx, 1095 yysymbol_kind_t yyarg[], int yyargn) 1096{ 1097 /* Actual size of YYARG. */ 1098 int yycount = 0; 1099 int yyn = yypact[+*yyctx->yyssp]; 1100 if (!yypact_value_is_default (yyn)) 1101 { 1102 /* Start YYX at -YYN if negative to avoid negative indexes in 1103 YYCHECK. In other words, skip the first -YYN actions for 1104 this state because they are default actions. */ 1105 int yyxbegin = yyn < 0 ? -yyn : 0; 1106 /* Stay within bounds of both yycheck and yytname. */ 1107 int yychecklim = YYLAST - yyn + 1; 1108 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 1109 int yyx; 1110 for (yyx = yyxbegin; yyx < yyxend; ++yyx) 1111 if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYerror 1112 && !yytable_value_is_error (yytable[yyx + yyn])) 1113 { 1114 if (!yyarg) 1115 ++yycount; 1116 else if (yycount == yyargn) 1117 return 0; 1118 else 1119 yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); 1120 } 1121 } 1122 if (yyarg && yycount == 0 && 0 < yyargn) 1123 yyarg[0] = YYSYMBOL_YYEMPTY; 1124 return yycount; 1125} 1126 1127 1128 1129 1130#ifndef yystrlen 1131# if defined __GLIBC__ && defined _STRING_H 1132# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) 1133# else 1134/* Return the length of YYSTR. */ 1135static YYPTRDIFF_T 1136yystrlen (const char *yystr) 1137{ 1138 YYPTRDIFF_T yylen; 1139 for (yylen = 0; yystr[yylen]; yylen++) 1140 continue; 1141 return yylen; 1142} 1143# endif 1144#endif 1145 1146#ifndef yystpcpy 1147# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE 1148# define yystpcpy stpcpy 1149# else 1150/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in 1151 YYDEST. */ 1152static char * 1153yystpcpy (char *yydest, const char *yysrc) 1154{ 1155 char *yyd = yydest; 1156 const char *yys = yysrc; 1157 1158 while ((*yyd++ = *yys++) != '\0') 1159 continue; 1160 1161 return yyd - 1; 1162} 1163# endif 1164#endif 1165 1166#ifndef yytnamerr 1167/* Copy to YYRES the contents of YYSTR after stripping away unnecessary 1168 quotes and backslashes, so that it's suitable for yyerror. The 1169 heuristic is that double-quoting is unnecessary unless the string 1170 contains an apostrophe, a comma, or backslash (other than 1171 backslash-backslash). YYSTR is taken from yytname. If YYRES is 1172 null, do not copy; instead, return the length of what the result 1173 would have been. */ 1174static YYPTRDIFF_T 1175yytnamerr (char *yyres, const char *yystr) 1176{ 1177 if (*yystr == '"') 1178 { 1179 YYPTRDIFF_T yyn = 0; 1180 char const *yyp = yystr; 1181 for (;;) 1182 switch (*++yyp) 1183 { 1184 case '\'': 1185 case ',': 1186 goto do_not_strip_quotes; 1187 1188 case '\\': 1189 if (*++yyp != '\\') 1190 goto do_not_strip_quotes; 1191 else 1192 goto append; 1193 1194 append: 1195 default: 1196 if (yyres) 1197 yyres[yyn] = *yyp; 1198 yyn++; 1199 break; 1200 1201 case '"': 1202 if (yyres) 1203 yyres[yyn] = '\0'; 1204 return yyn; 1205 } 1206 do_not_strip_quotes: ; 1207 } 1208 1209 if (yyres) 1210 return yystpcpy (yyres, yystr) - yyres; 1211 else 1212 return yystrlen (yystr); 1213} 1214#endif 1215 1216 1217static int 1218yy_syntax_error_arguments (const yypcontext_t *yyctx, 1219 yysymbol_kind_t yyarg[], int yyargn) 1220{ 1221 /* Actual size of YYARG. */ 1222 int yycount = 0; 1223 /* There are many possibilities here to consider: 1224 - If this state is a consistent state with a default action, then 1225 the only way this function was invoked is if the default action 1226 is an error action. In that case, don't check for expected 1227 tokens because there are none. 1228 - The only way there can be no lookahead present (in yychar) is if 1229 this state is a consistent state with a default action. Thus, 1230 detecting the absence of a lookahead is sufficient to determine 1231 that there is no unexpected or expected token to report. In that 1232 case, just report a simple "syntax error". 1233 - Don't assume there isn't a lookahead just because this state is a 1234 consistent state with a default action. There might have been a 1235 previous inconsistent state, consistent state with a non-default 1236 action, or user semantic action that manipulated yychar. 1237 - Of course, the expected token list depends on states to have 1238 correct lookahead information, and it depends on the parser not 1239 to perform extra reductions after fetching a lookahead from the 1240 scanner and before detecting a syntax error. Thus, state merging 1241 (from LALR or IELR) and default reductions corrupt the expected 1242 token list. However, the list is correct for canonical LR with 1243 one exception: it will still contain any token that will not be 1244 accepted due to an error action in a later state. 1245 */ 1246 if (yyctx->yytoken != YYSYMBOL_YYEMPTY) 1247 { 1248 int yyn; 1249 if (yyarg) 1250 yyarg[yycount] = yyctx->yytoken; 1251 ++yycount; 1252 yyn = yypcontext_expected_tokens (yyctx, 1253 yyarg ? yyarg + 1 : yyarg, yyargn - 1); 1254 if (yyn == YYENOMEM) 1255 return YYENOMEM; 1256 else 1257 yycount += yyn; 1258 } 1259 return yycount; 1260} 1261 1262/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message 1263 about the unexpected token YYTOKEN for the state stack whose top is 1264 YYSSP. 1265 1266 Return 0 if *YYMSG was successfully written. Return -1 if *YYMSG is 1267 not large enough to hold the message. In that case, also set 1268 *YYMSG_ALLOC to the required number of bytes. Return YYENOMEM if the 1269 required number of bytes is too large to store. */ 1270static int 1271yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, 1272 const yypcontext_t *yyctx) 1273{ 1274 enum { YYARGS_MAX = 5 }; 1275 /* Internationalized format string. */ 1276 const char *yyformat = YY_NULLPTR; 1277 /* Arguments of yyformat: reported tokens (one for the "unexpected", 1278 one per "expected"). */ 1279 yysymbol_kind_t yyarg[YYARGS_MAX]; 1280 /* Cumulated lengths of YYARG. */ 1281 YYPTRDIFF_T yysize = 0; 1282 1283 /* Actual size of YYARG. */ 1284 int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX); 1285 if (yycount == YYENOMEM) 1286 return YYENOMEM; 1287 1288 switch (yycount) 1289 { 1290#define YYCASE_(N, S) \ 1291 case N: \ 1292 yyformat = S; \ 1293 break 1294 default: /* Avoid compiler warnings. */ 1295 YYCASE_(0, YY_("syntax error")); 1296 YYCASE_(1, YY_("syntax error, unexpected %s")); 1297 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); 1298 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); 1299 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); 1300 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); 1301#undef YYCASE_ 1302 } 1303 1304 /* Compute error message size. Don't count the "%s"s, but reserve 1305 room for the terminator. */ 1306 yysize = yystrlen (yyformat) - 2 * yycount + 1; 1307 { 1308 int yyi; 1309 for (yyi = 0; yyi < yycount; ++yyi) 1310 { 1311 YYPTRDIFF_T yysize1 1312 = yysize + yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]]); 1313 if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) 1314 yysize = yysize1; 1315 else 1316 return YYENOMEM; 1317 } 1318 } 1319 1320 if (*yymsg_alloc < yysize) 1321 { 1322 *yymsg_alloc = 2 * yysize; 1323 if (! (yysize <= *yymsg_alloc 1324 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) 1325 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; 1326 return -1; 1327 } 1328 1329 /* Avoid sprintf, as that infringes on the user's name space. 1330 Don't have undefined behavior even if the translation 1331 produced a string with the wrong number of "%s"s. */ 1332 { 1333 char *yyp = *yymsg; 1334 int yyi = 0; 1335 while ((*yyp = *yyformat) != '\0') 1336 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) 1337 { 1338 yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]); 1339 yyformat += 2; 1340 } 1341 else 1342 { 1343 ++yyp; 1344 ++yyformat; 1345 } 1346 } 1347 return 0; 1348} 1349 1350 1351/*-----------------------------------------------. 1352| Release the memory associated to this symbol. | 1353`-----------------------------------------------*/ 1354 1355static void 1356yydestruct (const char *yymsg, 1357 yysymbol_kind_t yykind, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, MZAContext& ctx) 1358{ 1359 YY_USE (yyvaluep); 1360 YY_USE (yylocationp); 1361 YY_USE (ctx); 1362 if (!yymsg) 1363 yymsg = "Deleting"; 1364 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); 1365 1366 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1367 YY_USE (yykind); 1368 YY_IGNORE_MAYBE_UNINITIALIZED_END 1369} 1370 1371 1372 1373 1374 1375 1376/*----------. 1377| yyparse. | 1378`----------*/ 1379 1380int 1381yyparse (MZAContext& ctx) 1382{ 1383/* Lookahead token kind. */ 1384int yychar; 1385 1386 1387/* The semantic value of the lookahead symbol. */ 1388/* Default value used for initialization, for pacifying older GCCs 1389 or non-GCC compilers. */ 1390YY_INITIAL_VALUE (static YYSTYPE yyval_default;) 1391YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); 1392 1393/* Location data for the lookahead symbol. */ 1394static YYLTYPE yyloc_default 1395# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL 1396 = { 1, 1, 1, 1 } 1397# endif 1398; 1399YYLTYPE yylloc = yyloc_default; 1400 1401 /* Number of syntax errors so far. */ 1402 int yynerrs = 0; 1403 1404 yy_state_fast_t yystate = 0; 1405 /* Number of tokens to shift before error messages enabled. */ 1406 int yyerrstatus = 0; 1407 1408 /* Refer to the stacks through separate pointers, to allow yyoverflow 1409 to reallocate them elsewhere. */ 1410 1411 /* Their size. */ 1412 YYPTRDIFF_T yystacksize = YYINITDEPTH; 1413 1414 /* The state stack: array, bottom, top. */ 1415 yy_state_t yyssa[YYINITDEPTH]; 1416 yy_state_t *yyss = yyssa; 1417 yy_state_t *yyssp = yyss; 1418 1419 /* The semantic value stack: array, bottom, top. */ 1420 YYSTYPE yyvsa[YYINITDEPTH]; 1421 YYSTYPE *yyvs = yyvsa; 1422 YYSTYPE *yyvsp = yyvs; 1423 1424 /* The location stack: array, bottom, top. */ 1425 YYLTYPE yylsa[YYINITDEPTH]; 1426 YYLTYPE *yyls = yylsa; 1427 YYLTYPE *yylsp = yyls; 1428 1429 int yyn; 1430 /* The return value of yyparse. */ 1431 int yyresult; 1432 /* Lookahead symbol kind. */ 1433 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; 1434 /* The variables used to return semantic value and location from the 1435 action routines. */ 1436 YYSTYPE yyval; 1437 YYLTYPE yyloc; 1438 1439 /* The locations where the error started and ended. */ 1440 YYLTYPE yyerror_range[3]; 1441 1442 /* Buffer for error messages, and its allocated size. */ 1443 char yymsgbuf[128]; 1444 char *yymsg = yymsgbuf; 1445 YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; 1446 1447#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) 1448 1449 /* The number of symbols on the RHS of the reduced rule. 1450 Keep to zero when no symbol should be popped. */ 1451 int yylen = 0; 1452 1453 YYDPRINTF ((stderr, "Starting parse\n")); 1454 1455 yychar = YYEMPTY; /* Cause a token to be read. */ 1456 yylsp[0] = yylloc; 1457 goto yysetstate; 1458 1459 1460/*------------------------------------------------------------. 1461| yynewstate -- push a new state, which is found in yystate. | 1462`------------------------------------------------------------*/ 1463yynewstate: 1464 /* In all cases, when you get here, the value and location stacks 1465 have just been pushed. So pushing a state here evens the stacks. */ 1466 yyssp++; 1467 1468 1469/*--------------------------------------------------------------------. 1470| yysetstate -- set current state (the top of the stack) to yystate. | 1471`--------------------------------------------------------------------*/ 1472yysetstate: 1473 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 1474 YY_ASSERT (0 <= yystate && yystate < YYNSTATES); 1475 YY_IGNORE_USELESS_CAST_BEGIN 1476 *yyssp = YY_CAST (yy_state_t, yystate); 1477 YY_IGNORE_USELESS_CAST_END 1478 YY_STACK_PRINT (yyss, yyssp); 1479 1480 if (yyss + yystacksize - 1 <= yyssp) 1481#if !defined yyoverflow && !defined YYSTACK_RELOCATE 1482 goto yyexhaustedlab; 1483#else 1484 { 1485 /* Get the current used size of the three stacks, in elements. */ 1486 YYPTRDIFF_T yysize = yyssp - yyss + 1; 1487 1488# if defined yyoverflow 1489 { 1490 /* Give user a chance to reallocate the stack. Use copies of 1491 these so that the &'s don't force the real ones into 1492 memory. */ 1493 yy_state_t *yyss1 = yyss; 1494 YYSTYPE *yyvs1 = yyvs; 1495 YYLTYPE *yyls1 = yyls; 1496 1497 /* Each stack pointer address is followed by the size of the 1498 data in use in that stack, in bytes. This used to be a 1499 conditional around just the two extra args, but that might 1500 be undefined if yyoverflow is a macro. */ 1501 yyoverflow (YY_("memory exhausted"), 1502 &yyss1, yysize * YYSIZEOF (*yyssp), 1503 &yyvs1, yysize * YYSIZEOF (*yyvsp), 1504 &yyls1, yysize * YYSIZEOF (*yylsp), 1505 &yystacksize); 1506 yyss = yyss1; 1507 yyvs = yyvs1; 1508 yyls = yyls1; 1509 } 1510# else /* defined YYSTACK_RELOCATE */ 1511 /* Extend the stack our own way. */ 1512 if (YYMAXDEPTH <= yystacksize) 1513 goto yyexhaustedlab; 1514 yystacksize *= 2; 1515 if (YYMAXDEPTH < yystacksize) 1516 yystacksize = YYMAXDEPTH; 1517 1518 { 1519 yy_state_t *yyss1 = yyss; 1520 union yyalloc *yyptr = 1521 YY_CAST (union yyalloc *, 1522 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); 1523 if (! yyptr) 1524 goto yyexhaustedlab; 1525 YYSTACK_RELOCATE (yyss_alloc, yyss); 1526 YYSTACK_RELOCATE (yyvs_alloc, yyvs); 1527 YYSTACK_RELOCATE (yyls_alloc, yyls); 1528# undef YYSTACK_RELOCATE 1529 if (yyss1 != yyssa) 1530 YYSTACK_FREE (yyss1); 1531 } 1532# endif 1533 1534 yyssp = yyss + yysize - 1; 1535 yyvsp = yyvs + yysize - 1; 1536 yylsp = yyls + yysize - 1; 1537 1538 YY_IGNORE_USELESS_CAST_BEGIN 1539 YYDPRINTF ((stderr, "Stack size increased to %ld\n", 1540 YY_CAST (long, yystacksize))); 1541 YY_IGNORE_USELESS_CAST_END 1542 1543 if (yyss + yystacksize - 1 <= yyssp) 1544 YYABORT; 1545 } 1546#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ 1547 1548 if (yystate == YYFINAL) 1549 YYACCEPT; 1550 1551 goto yybackup; 1552 1553 1554/*-----------. 1555| yybackup. | 1556`-----------*/ 1557yybackup: 1558 /* Do appropriate processing given the current state. Read a 1559 lookahead token if we need one and don't already have one. */ 1560 1561 /* First try to decide what to do without reference to lookahead token. */ 1562 yyn = yypact[yystate]; 1563 if (yypact_value_is_default (yyn)) 1564 goto yydefault; 1565 1566 /* Not known => get a lookahead token if don't already have one. */ 1567 1568 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ 1569 if (yychar == YYEMPTY) 1570 { 1571 YYDPRINTF ((stderr, "Reading a token\n")); 1572 yychar = yylex (&yylval, &yylloc); 1573 } 1574 1575 if (yychar <= YYEOF) 1576 { 1577 yychar = YYEOF; 1578 yytoken = YYSYMBOL_YYEOF; 1579 YYDPRINTF ((stderr, "Now at end of input.\n")); 1580 } 1581 else if (yychar == YYerror) 1582 { 1583 /* The scanner already issued an error message, process directly 1584 to error recovery. But do not keep the error token as 1585 lookahead, it is too special and may lead us to an endless 1586 loop in error recovery. */ 1587 yychar = YYUNDEF; 1588 yytoken = YYSYMBOL_YYerror; 1589 yyerror_range[1] = yylloc; 1590 goto yyerrlab1; 1591 } 1592 else 1593 { 1594 yytoken = YYTRANSLATE (yychar); 1595 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); 1596 } 1597 1598 /* If the proper action on seeing token YYTOKEN is to reduce or to 1599 detect an error, take that action. */ 1600 yyn += yytoken; 1601 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) 1602 goto yydefault; 1603 yyn = yytable[yyn]; 1604 if (yyn <= 0) 1605 { 1606 if (yytable_value_is_error (yyn)) 1607 goto yyerrlab; 1608 yyn = -yyn; 1609 goto yyreduce; 1610 } 1611 1612 /* Count tokens shifted since error; after three, turn off error 1613 status. */ 1614 if (yyerrstatus) 1615 yyerrstatus--; 1616 1617 /* Shift the lookahead token. */ 1618 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); 1619 yystate = yyn; 1620 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 1621 *++yyvsp = yylval; 1622 YY_IGNORE_MAYBE_UNINITIALIZED_END 1623 *++yylsp = yylloc; 1624 1625 /* Discard the shifted token. */ 1626 yychar = YYEMPTY; 1627 goto yynewstate; 1628 1629 1630/*-----------------------------------------------------------. 1631| yydefault -- do the default action for the current state. | 1632`-----------------------------------------------------------*/ 1633yydefault: 1634 yyn = yydefact[yystate]; 1635 if (yyn == 0) 1636 goto yyerrlab; 1637 goto yyreduce; 1638 1639 1640/*-----------------------------. 1641| yyreduce -- do a reduction. | 1642`-----------------------------*/ 1643yyreduce: 1644 /* yyn is the number of a rule to reduce with. */ 1645 yylen = yyr2[yyn]; 1646 1647 /* If YYLEN is nonzero, implement the default value of the action: 1648 '$$ = $1'. 1649 1650 Otherwise, the following line sets YYVAL to garbage. 1651 This behavior is undocumented and Bison 1652 users should not rely upon it. Assigning to YYVAL 1653 unconditionally makes the parser a bit smaller, and it avoids a 1654 GCC warning that YYVAL may be used uninitialized. */ 1655 yyval = yyvsp[1-yylen]; 1656 1657 /* Default location. */ 1658 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); 1659 yyerror_range[1] = yyloc; 1660 YY_REDUCE_PRINT (yyn); 1661 switch (yyn) 1662 { 1663 case 4: /* procedure: ":" MZA_ID ":" mode MZA_INT delay instructions */ 1664 { 1665 // Patch jumps with recorded labels 1666 for (auto& cl : ctx.patch_labels) { 1667 if (ctx.labels.find(cl.second) == ctx.labels.end()) { 1668 throw Error("Error: label " + cl.second + " not found\n"); 1669 } 1670 ctx.proc_body.patchAddress(cl.first, ctx.labels[cl.second]); 1671 } 1672 ctx.labels.clear(); 1673 ctx.patch_labels.clear(); 1674 1675 ctx.proc_body.setNArgs((yyvsp[-2].iValue)); 1676 1677 // Add ABORT instruction for error management 1678 if (ctx.proc_body.size() > 0) { 1679 ctx.proc_body.addInstr(BytecodeStream::ABORT); 1680 } 1681 // Store procedure in the correct place 1682 auto mode = static_cast<BytecodeProc::Mode>((yyvsp[-3].iValue)); 1683 auto it = ctx.proc_map.find((yyvsp[-5].sValue)); 1684 if (it != ctx.proc_map.end()) { 1685 BytecodeProc& bcp = ctx.procs[it->second]; 1686 if (bcp.mode[mode].size() > 0) { 1687 throw Error("Error: procedure " + std::string((yyvsp[-5].sValue)) + " already defined before with the same mode\n"); 1688 } 1689 if (bcp.nargs != (yyvsp[-2].iValue) ) { 1690 throw Error("Error: procedure " + std::string((yyvsp[-5].sValue)) + " already defined before with different number of arguments\n"); 1691 } 1692 bcp.mode[(yyvsp[-3].iValue)] = ctx.proc_body; 1693 ctx.to_patch.emplace_back(it->second, mode, ctx.patch_procs); 1694 } else { 1695 BytecodeProc bcp; 1696 bcp.name = (yyvsp[-5].sValue); 1697 bcp.mode[mode] = ctx.proc_body; 1698 bcp.nargs = (yyvsp[-2].iValue); 1699 bcp.delay = (yyvsp[-1].iValue); 1700 ctx.proc_map.emplace((yyvsp[-5].sValue), ctx.procs.size()); 1701 ctx.to_patch.emplace_back(ctx.procs.size(), mode, ctx.patch_procs); 1702 ctx.procs.push_back(bcp); 1703 } 1704 ctx.proc_body = BytecodeStream(); 1705 ctx.patch_procs.clear(); 1706 } 1707 break; 1708 1709 case 5: /* mode: %empty */ 1710 { (yyval.iValue) = BytecodeProc::FUN; } 1711 break; 1712 1713 case 7: /* delay: %empty */ 1714 { (yyval.iValue) = 0; } 1715 break; 1716 1717 case 8: /* delay: "D" */ 1718 { (yyval.iValue) = 1; } 1719 break; 1720 1721 case 11: /* labeled_instr: labels instruction */ 1722 { 1723 for (auto l : *(yyvsp[-1].sliValue)) { 1724 ctx.labels.emplace(l, (yyvsp[0].iValue)); 1725 } 1726 delete (yyvsp[-1].sliValue); 1727 } 1728 break; 1729 1730 case 12: /* labels: %empty */ 1731 { (yyval.sliValue) = new std::list<std::string>(); } 1732 break; 1733 1734 case 13: /* labels: labels label */ 1735 { (yyvsp[-1].sliValue)->push_back((yyvsp[0].sValue)); (yyval.sliValue) = (yyvsp[-1].sliValue); } 1736 break; 1737 1738 case 15: /* instruction: instr */ 1739 { 1740 (yyval.iValue) = ctx.proc_body.size(); 1741 ctx.proc_body.addInstr((yyvsp[0].bValue)); 1742 } 1743 break; 1744 1745 case 16: /* instruction: instrI MZA_INT */ 1746 { 1747 (yyval.iValue) = ctx.proc_body.size(); 1748 ctx.proc_body.addInstr((yyvsp[-1].bValue)); 1749 ctx.proc_body.addIntVal((yyvsp[0].iValue)); 1750 } 1751 break; 1752 1753 case 17: /* instruction: instrIR MZA_INT MZA_REG */ 1754 { 1755 (yyval.iValue) = ctx.proc_body.size(); 1756 ctx.proc_body.addInstr((yyvsp[-2].bValue)); 1757 ctx.proc_body.addIntVal((yyvsp[-1].iValue)); 1758 ctx.proc_body.addReg((yyvsp[0].iValue)); 1759 } 1760 break; 1761 1762 case 18: /* instruction: instrR MZA_REG */ 1763 { 1764 (yyval.iValue) = ctx.proc_body.size(); 1765 ctx.proc_body.addInstr((yyvsp[-1].bValue)); 1766 ctx.proc_body.addReg((yyvsp[0].iValue)); 1767 } 1768 break; 1769 1770 case 19: /* instruction: instrRR MZA_REG MZA_REG */ 1771 { 1772 (yyval.iValue) = ctx.proc_body.size(); 1773 ctx.proc_body.addInstr((yyvsp[-2].bValue)); 1774 ctx.proc_body.addReg((yyvsp[-1].iValue)); 1775 ctx.proc_body.addReg((yyvsp[0].iValue)); 1776 } 1777 break; 1778 1779 case 20: /* instruction: instrRS MZA_REG MZA_ID */ 1780 { 1781 (yyval.iValue) = ctx.proc_body.size(); 1782 ctx.proc_body.addInstr((yyvsp[-2].bValue)); 1783 ctx.proc_body.addReg((yyvsp[-1].iValue)); 1784 ctx.patch_labels.emplace_back(ctx.proc_body.size(), (yyvsp[0].sValue)); 1785 ctx.proc_body.addSmallInt(0); 1786 } 1787 break; 1788 1789 case 21: /* instruction: instrRRS MZA_REG MZA_REG MZA_ID */ 1790 { 1791 (yyval.iValue) = ctx.proc_body.size(); 1792 ctx.proc_body.addInstr((yyvsp[-3].bValue)); 1793 ctx.proc_body.addReg((yyvsp[-2].iValue)); 1794 ctx.proc_body.addReg((yyvsp[-1].iValue)); 1795 ctx.patch_labels.emplace_back(ctx.proc_body.size(), (yyvsp[0].sValue)); 1796 ctx.proc_body.addSmallInt(0); 1797 } 1798 break; 1799 1800 case 22: /* instruction: instrRRR MZA_REG MZA_REG MZA_REG */ 1801 { 1802 (yyval.iValue) = ctx.proc_body.size(); 1803 ctx.proc_body.addInstr((yyvsp[-3].bValue)); 1804 ctx.proc_body.addReg((yyvsp[-2].iValue)); 1805 ctx.proc_body.addReg((yyvsp[-1].iValue)); 1806 ctx.proc_body.addReg((yyvsp[0].iValue)); 1807 } 1808 break; 1809 1810 case 23: /* instruction: instrRRIRRR MZA_REG MZA_REG MZA_INT MZA_REG MZA_REG MZA_REG */ 1811 { 1812 (yyval.iValue) = ctx.proc_body.size(); 1813 ctx.proc_body.addInstr((yyvsp[-6].bValue)); 1814 ctx.proc_body.addReg((yyvsp[-5].iValue)); 1815 ctx.proc_body.addReg((yyvsp[-4].iValue)); 1816 ctx.proc_body.addIntVal((yyvsp[-3].iValue)); 1817 ctx.proc_body.addReg((yyvsp[-2].iValue)); 1818 ctx.proc_body.addReg((yyvsp[-1].iValue)); 1819 ctx.proc_body.addReg((yyvsp[0].iValue)); 1820 } 1821 break; 1822 1823 case 24: /* instruction: instrS MZA_ID */ 1824 { 1825 (yyval.iValue) = ctx.proc_body.size(); 1826 ctx.proc_body.addInstr((yyvsp[-1].bValue)); 1827 ctx.patch_labels.emplace_back(ctx.proc_body.size(), (yyvsp[0].sValue)); 1828 ctx.proc_body.addSmallInt(0); 1829 } 1830 break; 1831 1832 case 25: /* instruction: MZA_CALL MZA_MODE MZA_ID MZA_INT registers */ 1833 { 1834 (yyval.iValue) = ctx.proc_body.size(); 1835 ctx.proc_body.addInstr((yyvsp[-4].bValue)); 1836 ctx.proc_body.addCharVal((yyvsp[-3].iValue)); 1837 ctx.patch_procs.emplace_back(ctx.proc_body.size(), std::make_pair((yyvsp[-2].sValue), (yyvsp[0].liValue)->size())); 1838 ctx.proc_body.addSmallInt(0); 1839 ctx.proc_body.addCharVal((yyvsp[-1].iValue)); 1840 for (auto arg : *(yyvsp[0].liValue)) { 1841 ctx.proc_body.addReg(arg); 1842 } 1843 delete (yyvsp[0].liValue); 1844 } 1845 break; 1846 1847 case 26: /* instruction: MZA_BUILTIN MZA_ID registers */ 1848 { 1849 (yyval.iValue) = ctx.proc_body.size(); 1850 ctx.proc_body.addInstr((yyvsp[-2].bValue)); 1851 ctx.patch_procs.emplace_back(ctx.proc_body.size(), std::make_pair((yyvsp[-1].sValue), (yyvsp[0].liValue)->size())); 1852 ctx.proc_body.addSmallInt(0); 1853 for (auto arg : *(yyvsp[0].liValue)) { 1854 ctx.proc_body.addReg(arg); 1855 } 1856 delete (yyvsp[0].liValue); 1857 } 1858 break; 1859 1860 case 27: /* instruction: MZA_TCALL MZA_MODE MZA_ID MZA_INT */ 1861 { 1862 (yyval.iValue) = ctx.proc_body.size(); 1863 ctx.proc_body.addInstr((yyvsp[-3].bValue)); 1864 ctx.proc_body.addCharVal((yyvsp[-2].iValue)); 1865 ctx.patch_procs.emplace_back(ctx.proc_body.size(), std::make_pair((yyvsp[-1].sValue), -1)); 1866 ctx.proc_body.addSmallInt(0); 1867 ctx.proc_body.addCharVal((yyvsp[0].iValue)); 1868 } 1869 break; 1870 1871 case 28: /* instruction: MZA_OPEN_AGGREGATION MZA_CTX */ 1872 { 1873 (yyval.iValue) = ctx.proc_body.size(); 1874 ctx.proc_body.addInstr((yyvsp[-1].bValue)); 1875 ctx.proc_body.addCharVal((yyvsp[0].iValue)); 1876 } 1877 break; 1878 1879 case 29: /* instruction: MZA_OPEN_AGGREGATION MZA_AND */ 1880 { 1881 (yyval.iValue) = ctx.proc_body.size(); 1882 ctx.proc_body.addInstr((yyvsp[-1].bValue)); 1883 ctx.proc_body.addCharVal(AggregationCtx::VCTX_AND); 1884 } 1885 break; 1886 1887 case 30: /* instruction: MZA_OPEN_AGGREGATION MZA_OR */ 1888 { 1889 (yyval.iValue) = ctx.proc_body.size(); 1890 ctx.proc_body.addInstr((yyvsp[-1].bValue)); 1891 ctx.proc_body.addCharVal(AggregationCtx::VCTX_OR); 1892 } 1893 break; 1894 1895 case 31: /* instruction: MZA_LOAD_GLOBAL MZA_INT MZA_REG */ 1896 { 1897 (yyval.iValue) = ctx.proc_body.size(); 1898 ctx.proc_body.addInstr((yyvsp[-2].bValue)); 1899 ctx.proc_body.addReg((yyvsp[-1].iValue), true); 1900 ctx.max_glob = std::max(ctx.max_glob, (yyvsp[-1].iValue)); 1901 ctx.proc_body.addReg((yyvsp[0].iValue)); 1902 } 1903 break; 1904 1905 case 32: /* instruction: MZA_STORE_GLOBAL MZA_REG MZA_INT */ 1906 { 1907 (yyval.iValue) = ctx.proc_body.size(); 1908 ctx.proc_body.addInstr((yyvsp[-2].bValue)); 1909 ctx.proc_body.addReg((yyvsp[-1].iValue)); 1910 ctx.proc_body.addReg((yyvsp[0].iValue), true); 1911 ctx.max_glob = std::max(ctx.max_glob, (yyvsp[0].iValue)); 1912 } 1913 break; 1914 1915 case 33: /* instruction: MZA_GET_ARRAY MZA_INT registers */ 1916 { 1917 (yyval.iValue) = ctx.proc_body.size(); 1918 ctx.proc_body.addInstr((yyvsp[-2].bValue)); 1919 ctx.proc_body.addIntVal((yyvsp[-1].iValue)); 1920 for (auto arg : *(yyvsp[0].liValue)) { 1921 ctx.proc_body.addReg(arg); 1922 } 1923 delete (yyvsp[0].liValue); 1924 } 1925 break; 1926 1927 case 79: /* registers: %empty */ 1928 { (yyval.liValue) = new std::list<int>(); } 1929 break; 1930 1931 case 80: /* registers: registers MZA_REG */ 1932 { (yyvsp[-1].liValue)->push_back((yyvsp[0].iValue)); (yyval.liValue) = (yyvsp[-1].liValue); } 1933 break; 1934 1935 1936 1937 default: break; 1938 } 1939 /* User semantic actions sometimes alter yychar, and that requires 1940 that yytoken be updated with the new translation. We take the 1941 approach of translating immediately before every use of yytoken. 1942 One alternative is translating here after every semantic action, 1943 but that translation would be missed if the semantic action invokes 1944 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or 1945 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an 1946 incorrect destructor might then be invoked immediately. In the 1947 case of YYERROR or YYBACKUP, subsequent parser actions might lead 1948 to an incorrect destructor call or verbose syntax error message 1949 before the lookahead is translated. */ 1950 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); 1951 1952 YYPOPSTACK (yylen); 1953 yylen = 0; 1954 1955 *++yyvsp = yyval; 1956 *++yylsp = yyloc; 1957 1958 /* Now 'shift' the result of the reduction. Determine what state 1959 that goes to, based on the state we popped back to and the rule 1960 number reduced by. */ 1961 { 1962 const int yylhs = yyr1[yyn] - YYNTOKENS; 1963 const int yyi = yypgoto[yylhs] + *yyssp; 1964 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp 1965 ? yytable[yyi] 1966 : yydefgoto[yylhs]); 1967 } 1968 1969 goto yynewstate; 1970 1971 1972/*--------------------------------------. 1973| yyerrlab -- here on detecting error. | 1974`--------------------------------------*/ 1975yyerrlab: 1976 /* Make sure we have latest lookahead translation. See comments at 1977 user semantic actions for why this is necessary. */ 1978 yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); 1979 /* If not already recovering from an error, report this error. */ 1980 if (!yyerrstatus) 1981 { 1982 ++yynerrs; 1983 { 1984 yypcontext_t yyctx 1985 = {yyssp, yytoken, &yylloc}; 1986 char const *yymsgp = YY_("syntax error"); 1987 int yysyntax_error_status; 1988 yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); 1989 if (yysyntax_error_status == 0) 1990 yymsgp = yymsg; 1991 else if (yysyntax_error_status == -1) 1992 { 1993 if (yymsg != yymsgbuf) 1994 YYSTACK_FREE (yymsg); 1995 yymsg = YY_CAST (char *, 1996 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); 1997 if (yymsg) 1998 { 1999 yysyntax_error_status 2000 = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); 2001 yymsgp = yymsg; 2002 } 2003 else 2004 { 2005 yymsg = yymsgbuf; 2006 yymsg_alloc = sizeof yymsgbuf; 2007 yysyntax_error_status = YYENOMEM; 2008 } 2009 } 2010 yyerror (&yylloc, ctx, yymsgp); 2011 if (yysyntax_error_status == YYENOMEM) 2012 goto yyexhaustedlab; 2013 } 2014 } 2015 2016 yyerror_range[1] = yylloc; 2017 if (yyerrstatus == 3) 2018 { 2019 /* If just tried and failed to reuse lookahead token after an 2020 error, discard it. */ 2021 2022 if (yychar <= YYEOF) 2023 { 2024 /* Return failure if at end of input. */ 2025 if (yychar == YYEOF) 2026 YYABORT; 2027 } 2028 else 2029 { 2030 yydestruct ("Error: discarding", 2031 yytoken, &yylval, &yylloc, ctx); 2032 yychar = YYEMPTY; 2033 } 2034 } 2035 2036 /* Else will try to reuse lookahead token after shifting the error 2037 token. */ 2038 goto yyerrlab1; 2039 2040 2041/*---------------------------------------------------. 2042| yyerrorlab -- error raised explicitly by YYERROR. | 2043`---------------------------------------------------*/ 2044yyerrorlab: 2045 /* Pacify compilers when the user code never invokes YYERROR and the 2046 label yyerrorlab therefore never appears in user code. */ 2047 if (0) 2048 YYERROR; 2049 2050 /* Do not reclaim the symbols of the rule whose action triggered 2051 this YYERROR. */ 2052 YYPOPSTACK (yylen); 2053 yylen = 0; 2054 YY_STACK_PRINT (yyss, yyssp); 2055 yystate = *yyssp; 2056 goto yyerrlab1; 2057 2058 2059/*-------------------------------------------------------------. 2060| yyerrlab1 -- common code for both syntax error and YYERROR. | 2061`-------------------------------------------------------------*/ 2062yyerrlab1: 2063 yyerrstatus = 3; /* Each real token shifted decrements this. */ 2064 2065 /* Pop stack until we find a state that shifts the error token. */ 2066 for (;;) 2067 { 2068 yyn = yypact[yystate]; 2069 if (!yypact_value_is_default (yyn)) 2070 { 2071 yyn += YYSYMBOL_YYerror; 2072 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) 2073 { 2074 yyn = yytable[yyn]; 2075 if (0 < yyn) 2076 break; 2077 } 2078 } 2079 2080 /* Pop the current state because it cannot handle the error token. */ 2081 if (yyssp == yyss) 2082 YYABORT; 2083 2084 yyerror_range[1] = *yylsp; 2085 yydestruct ("Error: popping", 2086 YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp, ctx); 2087 YYPOPSTACK (1); 2088 yystate = *yyssp; 2089 YY_STACK_PRINT (yyss, yyssp); 2090 } 2091 2092 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 2093 *++yyvsp = yylval; 2094 YY_IGNORE_MAYBE_UNINITIALIZED_END 2095 2096 yyerror_range[2] = yylloc; 2097 ++yylsp; 2098 YYLLOC_DEFAULT (*yylsp, yyerror_range, 2); 2099 2100 /* Shift the error token. */ 2101 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); 2102 2103 yystate = yyn; 2104 goto yynewstate; 2105 2106 2107/*-------------------------------------. 2108| yyacceptlab -- YYACCEPT comes here. | 2109`-------------------------------------*/ 2110yyacceptlab: 2111 yyresult = 0; 2112 goto yyreturn; 2113 2114 2115/*-----------------------------------. 2116| yyabortlab -- YYABORT comes here. | 2117`-----------------------------------*/ 2118yyabortlab: 2119 yyresult = 1; 2120 goto yyreturn; 2121 2122 2123#if 1 2124/*-------------------------------------------------. 2125| yyexhaustedlab -- memory exhaustion comes here. | 2126`-------------------------------------------------*/ 2127yyexhaustedlab: 2128 yyerror (&yylloc, ctx, YY_("memory exhausted")); 2129 yyresult = 2; 2130 goto yyreturn; 2131#endif 2132 2133 2134/*-------------------------------------------------------. 2135| yyreturn -- parsing is finished, clean up and return. | 2136`-------------------------------------------------------*/ 2137yyreturn: 2138 if (yychar != YYEMPTY) 2139 { 2140 /* Make sure we have latest lookahead translation. See comments at 2141 user semantic actions for why this is necessary. */ 2142 yytoken = YYTRANSLATE (yychar); 2143 yydestruct ("Cleanup: discarding lookahead", 2144 yytoken, &yylval, &yylloc, ctx); 2145 } 2146 /* Do not reclaim the symbols of the rule whose action triggered 2147 this YYABORT or YYACCEPT. */ 2148 YYPOPSTACK (yylen); 2149 YY_STACK_PRINT (yyss, yyssp); 2150 while (yyssp != yyss) 2151 { 2152 yydestruct ("Cleanup: popping", 2153 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yylsp, ctx); 2154 YYPOPSTACK (1); 2155 } 2156#ifndef yyoverflow 2157 if (yyss != yyssa) 2158 YYSTACK_FREE (yyss); 2159#endif 2160 if (yymsg != yymsgbuf) 2161 YYSTACK_FREE (yymsg); 2162 return yyresult; 2163} 2164 2165 2166 2167#include <minizinc/interpreter/primitives.hh> 2168#include <minizinc/interpreter.hh> 2169 2170void yyerror(YYLTYPE* location, MZAContext& ctx, const char* s) { 2171 std::ostringstream oss; 2172 oss << "Cannot parse MiniZinc assembly in line " << location->first_line << ": " << std::string(s); 2173 throw Error(oss.str()); 2174} 2175 2176std::pair<int, std::vector<BytecodeProc>> parse_mza(const std::string& assembly_str) { 2177 std::vector<BytecodeProc> procs; 2178 std::unordered_map<std::string, int> proc_map; 2179 int max_glob; 2180 // Initialise first slots with 2181 for (PrimitiveMap::Primitive* p : primitiveMap()) { 2182 BytecodeProc bcp; 2183 bcp.name = p->name(); 2184 bcp.nargs = p->n_args(); 2185 bcp.delay = false; 2186 procs.push_back(bcp); 2187 proc_map.emplace(bcp.name, p->ident()); 2188 } 2189 mza_yy_scan_string(assembly_str.c_str()); 2190 MZAContext ctx = MZAContext{procs, proc_map, max_glob}; 2191 int err = yyparse(ctx); 2192 if (err != 0) { 2193 throw std::runtime_error("Cannot parse MiniZinc assembly: " + std::to_string(err)); 2194 } 2195 for (auto& p : ctx.to_patch) { 2196 int code = p.code; 2197 BytecodeProc::Mode mode = p.mode; 2198 for (auto& patch : p.patch) { 2199 int& nargs = patch.second.second; 2200 std::string& name = patch.second.first; 2201 2202 if (nargs >= 0 && nargs != procs[proc_map[name]].nargs) { 2203 throw Error("Error: number of arguments in call to " + patch.second.first + " at position " 2204 + std::to_string(patch.second.second) + " has an invalid number of arguments.\n"); 2205 } 2206 procs[code].mode[mode].patchAddress(patch.first, proc_map[patch.second.first]); 2207 } 2208 } 2209 return {max_glob, procs}; 2210}