diff --git a/scripts/code_generation_hashes/ANGLE_shader_preprocessor.json b/scripts/code_generation_hashes/ANGLE_shader_preprocessor.json index b51b71371..99794eda4 100644 --- a/scripts/code_generation_hashes/ANGLE_shader_preprocessor.json +++ b/scripts/code_generation_hashes/ANGLE_shader_preprocessor.json @@ -6,25 +6,25 @@ "src/compiler/preprocessor/preprocessor.l": "31b4f8bc0bb8f713f5e4db8ae04925e2", "src/compiler/preprocessor/preprocessor.y": - "df988b6fbdf552ce94bed587679ca574", + "770be78579281bd332f2277dcd3be7d3", "src/compiler/preprocessor/preprocessor_lex_autogen.cpp": - "77b814881471bcb8c2720a3bc87110de", + "85aaf946bef9254abba2ca200a7a4006", "src/compiler/preprocessor/preprocessor_tab_autogen.cpp": - "efb77883a5683a8ecf23a7f3aac699c1", + "3f15f3cc604a1ac5668711728ddd8430", "tools/flex-bison/linux/bison.sha1": - "efa86001f00e7bcfdbe899dd15fc88e0", + "6eba651f1769883db395dd4e485ba838", "tools/flex-bison/linux/flex.sha1": "3e73ddbd801cf3e8ed759c49572c8bf2", "tools/flex-bison/windows/bison.exe.sha1": - "ad6345f2fbf1112bae67f0d54a92e574", + "fd6d2461a2c256179faca7f5f142e689", "tools/flex-bison/windows/flex.exe.sha1": - "45668fa0dafd4a7e68c2b0480e50e650", + "c0213d97938af52cc29960381c77e608", "tools/flex-bison/windows/m4.exe.sha1": - "0e0332c889b12576458bc481f34d6142", + "98b1183972580437dffe690b29915c09", "tools/flex-bison/windows/msys-2.0.dll.sha1": - "59854139bd445e5193812e2b910dc7b5", + "8f76dc025488db997861057d7283ce20", "tools/flex-bison/windows/msys-iconv-2.dll.sha1": - "5da154b537d340991bb4cd06eca6d523", + "3892b2095dbfca5a71a30ffc7c895dad", "tools/flex-bison/windows/msys-intl-8.dll.sha1": - "3b5cd216061b9dff4d2ae3956bc344a8" + "ff2f3d05584d43fbd77d6251988b83ac" } \ No newline at end of file diff --git a/scripts/code_generation_hashes/ANGLE_shader_translator.json b/scripts/code_generation_hashes/ANGLE_shader_translator.json index 0b092bba5..99170173f 100644 --- a/scripts/code_generation_hashes/ANGLE_shader_translator.json +++ b/scripts/code_generation_hashes/ANGLE_shader_translator.json @@ -10,23 +10,23 @@ "src/compiler/translator/glslang_lex_autogen.cpp": "a645db46c3218dda37e5391e187797a2", "src/compiler/translator/glslang_tab_autogen.cpp": - "3831458caec0f05cfb4948653ec74f94", + "9719a04ebc96f86619ef474678c6a878", "src/compiler/translator/glslang_tab_autogen.h": - "62ec4be0bf5b1e8d6a1653ab194d0bf4", + "028bdaebf359aefbcdaafae466993ebe", "tools/flex-bison/linux/bison.sha1": - "efa86001f00e7bcfdbe899dd15fc88e0", + "6eba651f1769883db395dd4e485ba838", "tools/flex-bison/linux/flex.sha1": "3e73ddbd801cf3e8ed759c49572c8bf2", "tools/flex-bison/windows/bison.exe.sha1": - "ad6345f2fbf1112bae67f0d54a92e574", + "fd6d2461a2c256179faca7f5f142e689", "tools/flex-bison/windows/flex.exe.sha1": - "45668fa0dafd4a7e68c2b0480e50e650", + "c0213d97938af52cc29960381c77e608", "tools/flex-bison/windows/m4.exe.sha1": - "0e0332c889b12576458bc481f34d6142", + "98b1183972580437dffe690b29915c09", "tools/flex-bison/windows/msys-2.0.dll.sha1": - "59854139bd445e5193812e2b910dc7b5", + "8f76dc025488db997861057d7283ce20", "tools/flex-bison/windows/msys-iconv-2.dll.sha1": - "5da154b537d340991bb4cd06eca6d523", + "3892b2095dbfca5a71a30ffc7c895dad", "tools/flex-bison/windows/msys-intl-8.dll.sha1": - "3b5cd216061b9dff4d2ae3956bc344a8" + "ff2f3d05584d43fbd77d6251988b83ac" } \ No newline at end of file diff --git a/src/compiler/preprocessor/preprocessor.y b/src/compiler/preprocessor/preprocessor.y index 5dade4841..500a76fcf 100644 --- a/src/compiler/preprocessor/preprocessor.y +++ b/src/compiler/preprocessor/preprocessor.y @@ -84,8 +84,8 @@ struct Context } // namespace %} -%pure-parser -%name-prefix "pp" +%define api.pure +%define api.prefix {pp} %parse-param {Context *context} %lex-param {Context *context} diff --git a/src/compiler/preprocessor/preprocessor_lex_autogen.cpp b/src/compiler/preprocessor/preprocessor_lex_autogen.cpp index 584abf0b0..190d53a47 100644 --- a/src/compiler/preprocessor/preprocessor_lex_autogen.cpp +++ b/src/compiler/preprocessor/preprocessor_lex_autogen.cpp @@ -902,8 +902,7 @@ static int input(yyscan_t yyscanner); do \ { \ if (fwrite(yytext, (size_t)yyleng, 1, yyout)) \ - { \ - } \ + {} \ } while (0) #endif @@ -1087,7 +1086,10 @@ YY_DECL /* Line breaks are just counted - not returned. */ /* The comment is replaced by a single space. */ case 2: - YY_RULE_SETUP { BEGIN(COMMENT); } + YY_RULE_SETUP + { + BEGIN(COMMENT); + } YY_BREAK case 3: YY_RULE_SETUP @@ -1310,7 +1312,10 @@ YY_DECL } YY_BREAK case 34: - YY_RULE_SETUP { yyextra->leadingSpace = true; } + YY_RULE_SETUP + { + yyextra->leadingSpace = true; + } YY_BREAK case 35: /* rule 35 can match eol */ diff --git a/src/compiler/preprocessor/preprocessor_tab_autogen.cpp b/src/compiler/preprocessor/preprocessor_tab_autogen.cpp index 50822f200..a7607c9e5 100644 --- a/src/compiler/preprocessor/preprocessor_tab_autogen.cpp +++ b/src/compiler/preprocessor/preprocessor_tab_autogen.cpp @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.3.2. */ +/* A Bison parser, made by GNU Bison 3.8.2. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -34,6 +34,10 @@ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -41,14 +45,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* Identify Bison output, and Bison version. */ +#define YYBISON 30802 -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "3.3.2" +/* Bison version string. */ +#define YYBISON_VERSION "3.8.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -62,6 +63,8 @@ /* Pull parsers. */ #define YYPULL 1 +/* Substitute the type names. */ +#define YYSTYPE PPSTYPE /* Substitute the variable and function names. */ #define yyparse ppparse #define yylex pplex @@ -146,6 +149,15 @@ struct Context static int yylex(YYSTYPE *lvalp, Context *context); static void yyerror(Context *context, const char *reason); +#ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast(Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast(Val) +# else +# define YY_CAST(Type, Val) ((Type)(Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type)(Val)) +# endif +#endif #ifndef YY_NULLPTR # if defined __cplusplus # if 201103L <= __cplusplus @@ -158,84 +170,186 @@ static void yyerror(Context *context, const char *reason); # endif #endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - /* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif -#if YYDEBUG +#ifndef PPDEBUG +# if defined YYDEBUG +# if YYDEBUG +# define PPDEBUG 1 +# else +# define PPDEBUG 0 +# endif +# else /* ! defined YYDEBUG */ +# define PPDEBUG 0 +# endif /* ! defined YYDEBUG */ +#endif /* ! defined PPDEBUG */ +#if PPDEBUG extern int ppdebug; #endif -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE -enum yytokentype +/* Token kinds. */ +#ifndef PPTOKENTYPE +# define PPTOKENTYPE +enum pptokentype { - TOK_CONST_INT = 258, - TOK_IDENTIFIER = 259, - TOK_OP_OR = 260, - TOK_OP_AND = 261, - TOK_OP_EQ = 262, - TOK_OP_NE = 263, - TOK_OP_LE = 264, - TOK_OP_GE = 265, - TOK_OP_LEFT = 266, - TOK_OP_RIGHT = 267, - TOK_UNARY = 268 + PPEMPTY = -2, + PPEOF = 0, /* "end of file" */ + PPerror = 256, /* error */ + PPUNDEF = 257, /* "invalid token" */ + TOK_CONST_INT = 258, /* TOK_CONST_INT */ + TOK_IDENTIFIER = 259, /* TOK_IDENTIFIER */ + TOK_OP_OR = 260, /* TOK_OP_OR */ + TOK_OP_AND = 261, /* TOK_OP_AND */ + TOK_OP_EQ = 262, /* TOK_OP_EQ */ + TOK_OP_NE = 263, /* TOK_OP_NE */ + TOK_OP_LE = 264, /* TOK_OP_LE */ + TOK_OP_GE = 265, /* TOK_OP_GE */ + TOK_OP_LEFT = 266, /* TOK_OP_LEFT */ + TOK_OP_RIGHT = 267, /* TOK_OP_RIGHT */ + TOK_UNARY = 268 /* TOK_UNARY */ }; +typedef enum pptokentype pptoken_kind_t; #endif /* Value type. */ -#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED -typedef int YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 +#if !defined PPSTYPE && !defined PPSTYPE_IS_DECLARED +typedef int PPSTYPE; +# define PPSTYPE_IS_TRIVIAL 1 +# define PPSTYPE_IS_DECLARED 1 #endif int ppparse(Context *context); +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_TOK_CONST_INT = 3, /* TOK_CONST_INT */ + YYSYMBOL_TOK_IDENTIFIER = 4, /* TOK_IDENTIFIER */ + YYSYMBOL_TOK_OP_OR = 5, /* TOK_OP_OR */ + YYSYMBOL_TOK_OP_AND = 6, /* TOK_OP_AND */ + YYSYMBOL_7_ = 7, /* '|' */ + YYSYMBOL_8_ = 8, /* '^' */ + YYSYMBOL_9_ = 9, /* '&' */ + YYSYMBOL_TOK_OP_EQ = 10, /* TOK_OP_EQ */ + YYSYMBOL_TOK_OP_NE = 11, /* TOK_OP_NE */ + YYSYMBOL_12_ = 12, /* '<' */ + YYSYMBOL_13_ = 13, /* '>' */ + YYSYMBOL_TOK_OP_LE = 14, /* TOK_OP_LE */ + YYSYMBOL_TOK_OP_GE = 15, /* TOK_OP_GE */ + YYSYMBOL_TOK_OP_LEFT = 16, /* TOK_OP_LEFT */ + YYSYMBOL_TOK_OP_RIGHT = 17, /* TOK_OP_RIGHT */ + YYSYMBOL_18_ = 18, /* '+' */ + YYSYMBOL_19_ = 19, /* '-' */ + YYSYMBOL_20_ = 20, /* '*' */ + YYSYMBOL_21_ = 21, /* '/' */ + YYSYMBOL_22_ = 22, /* '%' */ + YYSYMBOL_TOK_UNARY = 23, /* TOK_UNARY */ + YYSYMBOL_24_ = 24, /* '!' */ + YYSYMBOL_25_ = 25, /* '~' */ + YYSYMBOL_26_ = 26, /* '(' */ + YYSYMBOL_27_ = 27, /* ')' */ + YYSYMBOL_YYACCEPT = 28, /* $accept */ + YYSYMBOL_input = 29, /* input */ + YYSYMBOL_expression = 30, /* expression */ + YYSYMBOL_31_1 = 31, /* $@1 */ + YYSYMBOL_32_2 = 32 /* $@2 */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; + #ifdef short # undef short #endif -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif #endif -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; #else typedef signed char yytype_int8; #endif -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short yytype_uint16; -#endif - -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; #else typedef short yytype_int16; #endif +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + #ifndef YYSIZE_T # ifdef __SIZE_TYPE__ # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif !defined YYSIZE_T +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -243,7 +357,17 @@ typedef short yytype_int16; # endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T)-1) +#define YYSIZE_MAXIMUM \ + YY_CAST(YYPTRDIFF_T, (YYPTRDIFF_MAXIMUM < YY_CAST(YYSIZE_T, -1) ? YYPTRDIFF_MAXIMUM \ + : YY_CAST(YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST(YYPTRDIFF_T, sizeof(X)) + +/* Stored state numbers (used for stacks). */ +typedef yytype_int8 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -257,35 +381,39 @@ typedef short yytype_int16; # endif #endif -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) || \ - defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__((__pure__)) # else -# define YY_ATTRIBUTE(Spec) /* empty */ +# define YY_ATTRIBUTE_PURE # endif #endif -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE((__pure__)) -#endif - #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE((__unused__)) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif #endif /* Suppress unused-variable warnings by "using" E. */ #if !defined lint || defined __GNUC__ -# define YYUSE(E) ((void)(E)) +# define YY_USE(E) ((void)(E)) #else -# define YYUSE(E) /* empty */ +# define YY_USE(E) /* empty */ #endif -#if defined __GNUC__ && !defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ - _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +#if defined __GNUC__ && !defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# endif # define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -298,7 +426,19 @@ typedef short yytype_int16; # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif -#if !defined yyoverflow || YYERROR_VERBOSE +#if defined __cplusplus && defined __GNUC__ && !defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END _Pragma("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + +#define YY_ASSERT(E) ((void)(0 && (E))) + +#if !defined yyoverflow /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -366,24 +506,25 @@ void free(void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ +#endif /* !defined yyoverflow */ #if (!defined yyoverflow && \ - (!defined __cplusplus || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + (!defined __cplusplus || (defined PPSTYPE_IS_TRIVIAL && PPSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss_alloc; + yy_state_t yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof(union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF(union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ -# define YYSTACK_BYTES(N) ((N) * (sizeof(yytype_int16) + sizeof(YYSTYPE)) + YYSTACK_GAP_MAXIMUM) +# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF(yy_state_t) + YYSIZEOF(YYSTYPE)) + YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -392,14 +533,14 @@ union yyalloc elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof(*yyptr); \ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF(*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF(*yyptr); \ } while (0) #endif @@ -409,12 +550,13 @@ union yyalloc not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) __builtin_memcpy(Dst, Src, (Count) * sizeof(*(Src))) +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy(Dst, Src, YY_CAST(YYSIZE_T, (Count)) * sizeof(*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYSIZE_T yyi; \ + YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } while (0) @@ -436,16 +578,18 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 55 -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 268 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK ? YY_CAST(yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ -static const yytype_uint8 yytranslate[] = { +static const yytype_int8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 24, 2, 2, 2, 22, 9, 2, 26, 27, 20, 18, 2, 19, 2, 21, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 12, 2, 13, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -457,41 +601,71 @@ static const yytype_uint8 yytranslate[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 10, 11, 14, 15, 16, 17, 23}; -#if YYDEBUG +#if PPDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = {0, 114, 114, 121, 122, 133, 133, 154, 154, 175, - 178, 181, 184, 187, 190, 193, 196, 199, 202, 227, - 249, 252, 255, 281, 308, 311, 314, 317, 329, 332}; +static const yytype_int16 yyrline[] = {0, 114, 114, 121, 122, 133, 133, 154, 154, 175, + 178, 181, 184, 187, 190, 193, 196, 199, 202, 227, + 249, 252, 255, 281, 308, 311, 314, 317, 329, 332}; #endif -#if YYDEBUG || YYERROR_VERBOSE || 0 +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST(yysymbol_kind_t, yystos[State]) + +#if PPDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name(yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = { - "$end", "error", "$undefined", "TOK_CONST_INT", "TOK_IDENTIFIER", - "TOK_OP_OR", "TOK_OP_AND", "'|'", "'^'", "'&'", - "TOK_OP_EQ", "TOK_OP_NE", "'<'", "'>'", "TOK_OP_LE", - "TOK_OP_GE", "TOK_OP_LEFT", "TOK_OP_RIGHT", "'+'", "'-'", - "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", - "'~'", "'('", "')'", "$accept", "input", - "expression", "$@1", "$@2", YY_NULLPTR}; +static const char *const yytname[] = {"\"end of file\"", + "error", + "\"invalid token\"", + "TOK_CONST_INT", + "TOK_IDENTIFIER", + "TOK_OP_OR", + "TOK_OP_AND", + "'|'", + "'^'", + "'&'", + "TOK_OP_EQ", + "TOK_OP_NE", + "'<'", + "'>'", + "TOK_OP_LE", + "TOK_OP_GE", + "TOK_OP_LEFT", + "TOK_OP_RIGHT", + "'+'", + "'-'", + "'*'", + "'/'", + "'%'", + "TOK_UNARY", + "'!'", + "'~'", + "'('", + "')'", + "$accept", + "input", + "expression", + "$@1", + "$@2", + YY_NULLPTR}; + +static const char *yysymbol_name(yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} #endif -#ifdef YYPRINT -/* YYTOKNUM[NUM] -- (External) token number corresponding to the - (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = {0, 256, 257, 258, 259, 260, 261, 124, 94, 38, - 262, 263, 60, 62, 264, 265, 266, 267, 43, 45, - 42, 47, 37, 268, 33, 126, 40, 41}; -#endif +#define YYPACT_NINF (-12) -#define YYPACT_NINF -12 +#define yypact_value_is_default(Yyn) ((Yyn) == YYPACT_NINF) -#define yypact_value_is_default(Yystate) (!!((Yystate) == (-12))) +#define YYTABLE_NINF (-1) -#define YYTABLE_NINF -1 - -#define yytable_value_is_error(Yytable_value) 0 +#define yytable_value_is_error(Yyn) 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ @@ -503,21 +677,21 @@ static const yytype_int16 yypact[] = { /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. Performed when YYTABLE does not specify something else to do. Zero means the default is an error. */ -static const yytype_uint8 yydefact[] = {0, 3, 4, 0, 0, 0, 0, 0, 0, 2, 28, 27, 25, 26, - 0, 1, 5, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 29, 0, 0, 9, 10, 11, 13, 12, - 17, 16, 15, 14, 19, 18, 21, 20, 24, 23, 22, 6, 8}; +static const yytype_int8 yydefact[] = {0, 3, 4, 0, 0, 0, 0, 0, 0, 2, 28, 27, 25, 26, + 0, 1, 5, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 29, 0, 0, 9, 10, 11, 13, 12, + 17, 16, 15, 14, 19, 18, 21, 20, 24, 23, 22, 6, 8}; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = {-12, -12, -3, -12, -12}; /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int8 yydefgoto[] = {-1, 8, 9, 35, 36}; +static const yytype_int8 yydefgoto[] = {0, 8, 9, 35, 36}; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule whose number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_uint8 yytable[] = { +static const yytype_int8 yytable[] = { 10, 11, 12, 13, 14, 27, 28, 29, 30, 31, 32, 33, 31, 32, 33, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 0, 53, 54, 1, 2, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 3, 4, 15, 0, 0, 0, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, @@ -537,35 +711,39 @@ static const yytype_int8 yycheck[] = { 14, 15, 16, 17, 18, 19, 20, 21, 22, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 18, 19, 20, 21, 22}; -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = {0, 3, 4, 18, 19, 24, 25, 26, 29, 30, 30, 30, 30, 30, - 30, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 27, 31, 32, 30, 30, 30, 30, 30, - 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}; +/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of + state STATE-NUM. */ +static const yytype_int8 yystos[] = {0, 3, 4, 18, 19, 24, 25, 26, 29, 30, 30, 30, 30, 30, + 30, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 27, 31, 32, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}; -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = {0, 28, 29, 30, 30, 31, 30, 32, 30, 30, 30, 30, 30, 30, 30, - 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}; +/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr1[] = {0, 28, 29, 30, 30, 31, 30, 32, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30}; -/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = {0, 2, 1, 1, 1, 0, 4, 0, 4, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3}; +/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr2[] = {0, 2, 1, 1, 1, 0, 4, 0, 4, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3}; + +enum +{ + YYENOMEM = -2 +}; #define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 +#define yyclearin (yychar = PPEMPTY) #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ - if (yychar == YYEMPTY) \ + if (yychar == PPEMPTY) \ { \ yychar = (Token); \ yylval = (Value); \ @@ -580,12 +758,12 @@ static const yytype_uint8 yyr2[] = {0, 2, 1, 1, 1, 0, 4, 0, 4, 3, 3, 3, 3, 3, 3, } \ while (0) -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 +/* Backward compatibility with an undocumented macro. + Use PPerror or PPUNDEF. */ +#define YYERRCODE PPUNDEF /* Enable debugging if requested. */ -#if YYDEBUG +#if PPDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ @@ -599,18 +777,13 @@ static const yytype_uint8 yyr2[] = {0, 2, 1, 1, 1, 0, 4, 0, 4, 3, 3, 3, 3, 3, 3, YYFPRINTF Args; \ } while (0) -/* This macro is provided for backward compatibility. */ -# ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void)0) -# endif - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do \ { \ if (yydebug) \ { \ YYFPRINTF(stderr, "%s ", Title); \ - yy_symbol_print(stderr, Type, Value, context); \ + yy_symbol_print(stderr, Kind, Value, context); \ YYFPRINTF(stderr, "\n"); \ } \ } while (0) @@ -620,31 +793,32 @@ static const yytype_uint8 yyr2[] = {0, 2, 1, 1, 1, 0, 4, 0, 4, 3, 3, 3, 3, 3, 3, `-----------------------------------*/ static void yy_symbol_value_print(FILE *yyo, - int yytype, + yysymbol_kind_t yykind, YYSTYPE const *const yyvaluep, Context *context) { FILE *yyoutput = yyo; - YYUSE(yyoutput); - YYUSE(context); + YY_USE(yyoutput); + YY_USE(context); if (!yyvaluep) return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT(yyo, yytoknum[yytype], *yyvaluep); -# endif - YYUSE(yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE(yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } /*---------------------------. | Print this symbol on YYO. | `---------------------------*/ -static void yy_symbol_print(FILE *yyo, int yytype, YYSTYPE const *const yyvaluep, Context *context) +static void yy_symbol_print(FILE *yyo, + yysymbol_kind_t yykind, + YYSTYPE const *const yyvaluep, + Context *context) { - YYFPRINTF(yyo, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + YYFPRINTF(yyo, "%s %s (", yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name(yykind)); - yy_symbol_value_print(yyo, yytype, yyvaluep, context); + yy_symbol_value_print(yyo, yykind, yyvaluep, context); YYFPRINTF(yyo, ")"); } @@ -653,7 +827,7 @@ static void yy_symbol_print(FILE *yyo, int yytype, YYSTYPE const *const yyvaluep | TOP (included). | `------------------------------------------------------------------*/ -static void yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop) +static void yy_stack_print(yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF(stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -675,18 +849,18 @@ static void yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop) | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -static void yy_reduce_print(yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, Context *context) +static void yy_reduce_print(yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule, Context *context) { - unsigned long yylno = yyrline[yyrule]; - int yynrhs = yyr2[yyrule]; + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF(stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); + YYFPRINTF(stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF(stderr, " $%d = ", yyi + 1); - yy_symbol_print(stderr, yystos[yyssp[yyi + 1 - yynrhs]], &yyvsp[(yyi + 1) - (yynrhs)], - context); + yy_symbol_print(stderr, YY_ACCESSING_SYMBOL(+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)], context); YYFPRINTF(stderr, "\n"); } } @@ -701,12 +875,12 @@ static void yy_reduce_print(yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, Con /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +#else /* !PPDEBUG */ +# define YYDPRINTF(Args) ((void)0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ +#endif /* !PPDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH @@ -724,244 +898,23 @@ int yydebug; # define YYMAXDEPTH 10000 #endif -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T yystrlen(const char *yystr) -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif - -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char *yystpcpy(char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T yytnamerr(char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - else - goto append; - - append: - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes:; - } - - if (!yyres) - return yystrlen(yystr); - - return (YYSIZE_T)(yystpcpy(yyres, yystr) - yyres); -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int yysyntax_error(YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr(YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum - { - YYERROR_VERBOSE_ARGS_MAXIMUM = 5 - }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default(yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR && - !yytable_value_is_error(yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr(YY_NULLPTR, yytname[yyx]); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - default: /* Avoid compiler warnings. */ - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - YYSIZE_T yysize1 = yysize + yystrlen(yyformat); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (!(yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr(yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ -static void yydestruct(const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context) +static void yydestruct(const char *yymsg, + yysymbol_kind_t yykind, + YYSTYPE *yyvaluep, + Context *context) { - YYUSE(yyvaluep); - YYUSE(context); + YY_USE(yyvaluep); + YY_USE(context); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT(yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE(yytype); + YY_USE(yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } @@ -971,7 +924,7 @@ static void yydestruct(const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context int yyparse(Context *context) { - /* The lookahead symbol. */ + /* Lookahead token kind. */ int yychar; /* The semantic value of the lookahead symbol. */ @@ -981,62 +934,47 @@ int yyparse(Context *context) YYSTYPE yylval YY_INITIAL_VALUE(= yyval_default); /* Number of syntax errors so far. */ - int yynerrs; + int yynerrs = 0; - int yystate; + yy_state_fast_t yystate = 0; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yyerrstatus = 0; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - - Refer to the stacks through separate pointers, to allow yyoverflow + /* Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; - /* The semantic value stack. */ + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; + + /* The semantic value stack: array, bottom, top. */ YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; - - YYSIZE_T yystacksize; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; int yyn; + /* The return value of yyparse. */ int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif - #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; - YYDPRINTF((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ + yychar = PPEMPTY; /* Cause a token to be read. */ + goto yysetstate; /*------------------------------------------------------------. @@ -1048,49 +986,55 @@ yynewstate: yyssp++; /*--------------------------------------------------------------------. -| yynewstate -- set current state (the top of the stack) to yystate. | +| yysetstate -- set current state (the top of the stack) to yystate. | `--------------------------------------------------------------------*/ yysetstate: - *yyssp = (yytype_int16)yystate; + YYDPRINTF((stderr, "Entering state %d\n", yystate)); + YY_ASSERT(0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST(yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT(yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE - goto yyexhaustedlab; + YYNOMEM; #else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = (YYSIZE_T)(yyssp - yyss + 1); + YYPTRDIFF_T yysize = yyssp - yyss + 1; # if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ - yyoverflow(YY_("memory exhausted"), &yyss1, yysize * sizeof(*yyssp), &yyvs1, - yysize * sizeof(*yyvsp), &yystacksize); + yyoverflow(YY_("memory exhausted"), &yyss1, yysize * YYSIZEOF(*yyssp), &yyvs1, + yysize * YYSIZEOF(*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } # else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + YYNOMEM; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = (union yyalloc *)YYSTACK_ALLOC(YYSTACK_BYTES(yystacksize)); + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = YY_CAST( + union yyalloc *, YYSTACK_ALLOC(YY_CAST(YYSIZE_T, YYSTACK_BYTES(yystacksize)))); if (!yyptr) - goto yyexhaustedlab; + YYNOMEM; YYSTACK_RELOCATE(yyss_alloc, yyss); YYSTACK_RELOCATE(yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE @@ -1102,15 +1046,15 @@ yysetstate: yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; - YYDPRINTF((stderr, "Stack size increased to %lu\n", (unsigned long)yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF((stderr, "Stack size increased to %ld\n", YY_CAST(long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - YYDPRINTF((stderr, "Entering state %d\n", yystate)); - if (yystate == YYFINAL) YYACCEPT; @@ -1130,18 +1074,29 @@ yybackup: /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + if (yychar == PPEMPTY) { - YYDPRINTF((stderr, "Reading a token: ")); + YYDPRINTF((stderr, "Reading a token\n")); yychar = yylex(&yylval, context); } - if (yychar <= YYEOF) + if (yychar <= PPEOF) { - yychar = yytoken = YYEOF; + yychar = PPEOF; + yytoken = YYSYMBOL_YYEOF; YYDPRINTF((stderr, "Now at end of input.\n")); } + else if (yychar == PPerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = PPUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; + } else { yytoken = YYTRANSLATE(yychar); @@ -1169,15 +1124,13 @@ yybackup: /* Shift the lookahead token. */ YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END + /* Discard the shifted token. */ + yychar = PPEMPTY; goto yynewstate; /*-----------------------------------------------------------. @@ -1209,17 +1162,14 @@ yyreduce: YY_REDUCE_PRINT(yyn); switch (yyn) { - case 2: - + case 2: /* input: expression */ { *(context->result) = static_cast(yyvsp[0]); YYACCEPT; } - break; - case 4: - + case 4: /* expression: TOK_IDENTIFIER */ { if (!context->isIgnoringErrors()) { @@ -1231,11 +1181,9 @@ yyreduce: } yyval = yyvsp[0]; } - break; - case 5: - + case 5: /* $@1: %empty */ { if (yyvsp[-1] != 0) { @@ -1247,11 +1195,9 @@ yyreduce: context->startIgnoreErrors(); } } - break; - case 6: - + case 6: /* expression: expression TOK_OP_OR $@1 expression */ { if (yyvsp[-3] != 0) { @@ -1263,11 +1209,9 @@ yyreduce: yyval = yyvsp[-3] || yyvsp[0]; } } - break; - case 7: - + case 7: /* $@2: %empty */ { if (yyvsp[-1] == 0) { @@ -1279,11 +1223,9 @@ yyreduce: context->startIgnoreErrors(); } } - break; - case 8: - + case 8: /* expression: expression TOK_OP_AND $@2 expression */ { if (yyvsp[-3] == 0) { @@ -1295,83 +1237,63 @@ yyreduce: yyval = yyvsp[-3] && yyvsp[0]; } } - break; - case 9: - + case 9: /* expression: expression '|' expression */ { yyval = yyvsp[-2] | yyvsp[0]; } - break; - case 10: - + case 10: /* expression: expression '^' expression */ { yyval = yyvsp[-2] ^ yyvsp[0]; } - break; - case 11: - + case 11: /* expression: expression '&' expression */ { yyval = yyvsp[-2] & yyvsp[0]; } - break; - case 12: - + case 12: /* expression: expression TOK_OP_NE expression */ { yyval = yyvsp[-2] != yyvsp[0]; } - break; - case 13: - + case 13: /* expression: expression TOK_OP_EQ expression */ { yyval = yyvsp[-2] == yyvsp[0]; } - break; - case 14: - + case 14: /* expression: expression TOK_OP_GE expression */ { yyval = yyvsp[-2] >= yyvsp[0]; } - break; - case 15: - + case 15: /* expression: expression TOK_OP_LE expression */ { yyval = yyvsp[-2] <= yyvsp[0]; } - break; - case 16: - + case 16: /* expression: expression '>' expression */ { yyval = yyvsp[-2] > yyvsp[0]; } - break; - case 17: - + case 17: /* expression: expression '<' expression */ { yyval = yyvsp[-2] < yyvsp[0]; } - break; - case 18: - + case 18: /* expression: expression TOK_OP_RIGHT expression */ { if (yyvsp[0] < 0 || yyvsp[0] > 31) { @@ -1396,11 +1318,9 @@ yyreduce: yyval = yyvsp[-2] >> yyvsp[0]; } } - break; - case 19: - + case 19: /* expression: expression TOK_OP_LEFT expression */ { if (yyvsp[0] < 0 || yyvsp[0] > 31) { @@ -1422,27 +1342,21 @@ yyreduce: yyval = static_cast(static_cast(yyvsp[-2]) << yyvsp[0]); } } - break; - case 20: - + case 20: /* expression: expression '-' expression */ { yyval = gl::WrappingDiff(yyvsp[-2], yyvsp[0]); } - break; - case 21: - + case 21: /* expression: expression '+' expression */ { yyval = gl::WrappingSum(yyvsp[-2], yyvsp[0]); } - break; - case 22: - + case 22: /* expression: expression '%' expression */ { if (yyvsp[0] == 0) { @@ -1468,11 +1382,9 @@ yyreduce: yyval = yyvsp[-2] % yyvsp[0]; } } - break; - case 23: - + case 23: /* expression: expression '/' expression */ { if (yyvsp[0] == 0) { @@ -1499,35 +1411,27 @@ yyreduce: yyval = yyvsp[-2] / yyvsp[0]; } } - break; - case 24: - + case 24: /* expression: expression '*' expression */ { yyval = gl::WrappingMul(yyvsp[-2], yyvsp[0]); } - break; - case 25: - + case 25: /* expression: '!' expression */ { yyval = !yyvsp[0]; } - break; - case 26: - + case 26: /* expression: '~' expression */ { yyval = ~yyvsp[0]; } - break; - case 27: - + case 27: /* expression: '-' expression */ { // Check for negation of minimum representable integer to prevent undefined signed int // overflow. @@ -1540,23 +1444,18 @@ yyreduce: yyval = -yyvsp[0]; } } - break; - case 28: - + case 28: /* expression: '+' expression */ { yyval = +yyvsp[0]; } - break; - case 29: - + case 29: /* expression: '(' expression ')' */ { yyval = yyvsp[-1]; } - break; default: @@ -1573,11 +1472,10 @@ yyreduce: case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT("-> $$ =", YY_CAST(yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT(yyss, yyssp); *++yyvsp = yyval; @@ -1599,45 +1497,12 @@ yyreduce: yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE(yychar); - + yytoken = yychar == PPEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE(yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if !YYERROR_VERBOSE yyerror(context, YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error(&yymsg_alloc, &yymsg, yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE(yymsg); - yymsg = (char *)YYSTACK_ALLOC(yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror(context, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif } if (yyerrstatus == 3) @@ -1645,16 +1510,16 @@ yyerrlab: /* If just tried and failed to reuse lookahead token after an error, discard it. */ - if (yychar <= YYEOF) + if (yychar <= PPEOF) { /* Return failure if at end of input. */ - if (yychar == YYEOF) + if (yychar == PPEOF) YYABORT; } else { yydestruct("Error: discarding", yytoken, &yylval, context); - yychar = YYEMPTY; + yychar = PPEMPTY; } } @@ -1670,6 +1535,7 @@ yyerrorlab: label yyerrorlab therefore never appears in user code. */ if (0) YYERROR; + ++yynerrs; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -1685,13 +1551,14 @@ yyerrorlab: yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default(yyn)) { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) { yyn = yytable[yyn]; if (0 < yyn) @@ -1703,7 +1570,7 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - yydestruct("Error: popping", yystos[yystate], yyvsp, context); + yydestruct("Error: popping", YY_ACCESSING_SYMBOL(yystate), yyvsp, context); YYPOPSTACK(1); yystate = *yyssp; YY_STACK_PRINT(yyss, yyssp); @@ -1714,7 +1581,7 @@ yyerrlab1: YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ - YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT("Shifting", YY_ACCESSING_SYMBOL(yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -1724,30 +1591,28 @@ yyerrlab1: `-------------------------------------*/ yyacceptlab: yyresult = 0; - goto yyreturn; + goto yyreturnlab; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; - goto yyreturn; + goto yyreturnlab; -#if !defined yyoverflow || YYERROR_VERBOSE -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ yyexhaustedlab: yyerror(context, YY_("memory exhausted")); yyresult = 2; - /* Fall through. */ -#endif + goto yyreturnlab; -/*-----------------------------------------------------. -| yyreturn -- parsing is finished, return the result. | -`-----------------------------------------------------*/ -yyreturn: - if (yychar != YYEMPTY) +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: + if (yychar != PPEMPTY) { /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ @@ -1760,17 +1625,14 @@ yyreturn: YY_STACK_PRINT(yyss, yyssp); while (yyssp != yyss) { - yydestruct("Cleanup: popping", yystos[*yyssp], yyvsp, context); + yydestruct("Cleanup: popping", YY_ACCESSING_SYMBOL(+*yyssp), yyvsp, context); YYPOPSTACK(1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE(yyss); #endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE(yymsg); -#endif + return yyresult; } diff --git a/src/compiler/translator/glslang_tab_autogen.cpp b/src/compiler/translator/glslang_tab_autogen.cpp index 5aacebed5..233b571b7 100644 --- a/src/compiler/translator/glslang_tab_autogen.cpp +++ b/src/compiler/translator/glslang_tab_autogen.cpp @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.3.2. */ +/* A Bison parser, made by GNU Bison 3.8.2. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -34,6 +34,10 @@ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -41,14 +45,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* Identify Bison output, and Bison version. */ +#define YYBISON 30802 -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "3.3.2" +/* Bison version string. */ +#define YYBISON_VERSION "3.8.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -102,6 +103,15 @@ using namespace sh; +#ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast(Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast(Val) +# else +# define YY_CAST(Type, Val) ((Type)(Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type)(Val)) +# endif +#endif #ifndef YY_NULLPTR # if defined __cplusplus # if 201103L <= __cplusplus @@ -114,296 +124,294 @@ using namespace sh; # endif #endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* In a future release of Bison, this section will be replaced - by #include "glslang_tab_autogen.h". */ -#ifndef YY_YY_GLSLANG_TAB_AUTOGEN_H_INCLUDED -# define YY_YY_GLSLANG_TAB_AUTOGEN_H_INCLUDED -/* Debug traces. */ -# ifndef YYDEBUG -# define YYDEBUG 0 -# endif -# if YYDEBUG -extern int yydebug; -# endif -/* "%code requires" blocks. */ - -# define YYLTYPE TSourceLoc -# define YYLTYPE_IS_DECLARED 1 -# define YYLTYPE_IS_TRIVIAL 1 - -/* Token type. */ -# ifndef YYTOKENTYPE -# define YYTOKENTYPE -enum yytokentype +#include "glslang_tab_autogen.h" +/* Symbol kind. */ +enum yysymbol_kind_t { - INVARIANT = 258, - PRECISE = 259, - HIGH_PRECISION = 260, - MEDIUM_PRECISION = 261, - LOW_PRECISION = 262, - PRECISION = 263, - ATTRIBUTE = 264, - CONST_QUAL = 265, - BOOL_TYPE = 266, - FLOAT_TYPE = 267, - INT_TYPE = 268, - UINT_TYPE = 269, - BREAK = 270, - CONTINUE = 271, - DO = 272, - ELSE = 273, - FOR = 274, - IF = 275, - DISCARD = 276, - RETURN = 277, - SWITCH = 278, - CASE = 279, - DEFAULT = 280, - BVEC2 = 281, - BVEC3 = 282, - BVEC4 = 283, - IVEC2 = 284, - IVEC3 = 285, - IVEC4 = 286, - VEC2 = 287, - VEC3 = 288, - VEC4 = 289, - UVEC2 = 290, - UVEC3 = 291, - UVEC4 = 292, - MATRIX2 = 293, - MATRIX3 = 294, - MATRIX4 = 295, - IN_QUAL = 296, - OUT_QUAL = 297, - INOUT_QUAL = 298, - UNIFORM = 299, - BUFFER = 300, - VARYING = 301, - MATRIX2x3 = 302, - MATRIX3x2 = 303, - MATRIX2x4 = 304, - MATRIX4x2 = 305, - MATRIX3x4 = 306, - MATRIX4x3 = 307, - SAMPLE = 308, - CENTROID = 309, - FLAT = 310, - SMOOTH = 311, - NOPERSPECTIVE = 312, - PATCH = 313, - READONLY = 314, - WRITEONLY = 315, - COHERENT = 316, - RESTRICT = 317, - VOLATILE = 318, - SHARED = 319, - STRUCT = 320, - VOID_TYPE = 321, - WHILE = 322, - SAMPLER2D = 323, - SAMPLERCUBE = 324, - SAMPLER_EXTERNAL_OES = 325, - SAMPLER2DRECT = 326, - SAMPLER2DARRAY = 327, - ISAMPLER2D = 328, - ISAMPLER3D = 329, - ISAMPLERCUBE = 330, - ISAMPLER2DARRAY = 331, - USAMPLER2D = 332, - USAMPLER3D = 333, - USAMPLERCUBE = 334, - USAMPLER2DARRAY = 335, - SAMPLER2DMS = 336, - ISAMPLER2DMS = 337, - USAMPLER2DMS = 338, - SAMPLER2DMSARRAY = 339, - ISAMPLER2DMSARRAY = 340, - USAMPLER2DMSARRAY = 341, - SAMPLER3D = 342, - SAMPLER3DRECT = 343, - SAMPLER2DSHADOW = 344, - SAMPLERCUBESHADOW = 345, - SAMPLER2DARRAYSHADOW = 346, - SAMPLERVIDEOWEBGL = 347, - SAMPLERCUBEARRAYOES = 348, - SAMPLERCUBEARRAYSHADOWOES = 349, - ISAMPLERCUBEARRAYOES = 350, - USAMPLERCUBEARRAYOES = 351, - SAMPLERCUBEARRAYEXT = 352, - SAMPLERCUBEARRAYSHADOWEXT = 353, - ISAMPLERCUBEARRAYEXT = 354, - USAMPLERCUBEARRAYEXT = 355, - SAMPLERBUFFER = 356, - ISAMPLERBUFFER = 357, - USAMPLERBUFFER = 358, - SAMPLEREXTERNAL2DY2YEXT = 359, - IMAGE2D = 360, - IIMAGE2D = 361, - UIMAGE2D = 362, - IMAGE3D = 363, - IIMAGE3D = 364, - UIMAGE3D = 365, - IMAGE2DARRAY = 366, - IIMAGE2DARRAY = 367, - UIMAGE2DARRAY = 368, - IMAGECUBE = 369, - IIMAGECUBE = 370, - UIMAGECUBE = 371, - IMAGECUBEARRAYOES = 372, - IIMAGECUBEARRAYOES = 373, - UIMAGECUBEARRAYOES = 374, - IMAGECUBEARRAYEXT = 375, - IIMAGECUBEARRAYEXT = 376, - UIMAGECUBEARRAYEXT = 377, - IMAGEBUFFER = 378, - IIMAGEBUFFER = 379, - UIMAGEBUFFER = 380, - ATOMICUINT = 381, - PIXELLOCALANGLE = 382, - IPIXELLOCALANGLE = 383, - UPIXELLOCALANGLE = 384, - LAYOUT = 385, - YUVCSCSTANDARDEXT = 386, - YUVCSCSTANDARDEXTCONSTANT = 387, - IDENTIFIER = 388, - TYPE_NAME = 389, - FLOATCONSTANT = 390, - INTCONSTANT = 391, - UINTCONSTANT = 392, - BOOLCONSTANT = 393, - FIELD_SELECTION = 394, - LEFT_OP = 395, - RIGHT_OP = 396, - INC_OP = 397, - DEC_OP = 398, - LE_OP = 399, - GE_OP = 400, - EQ_OP = 401, - NE_OP = 402, - AND_OP = 403, - OR_OP = 404, - XOR_OP = 405, - MUL_ASSIGN = 406, - DIV_ASSIGN = 407, - ADD_ASSIGN = 408, - MOD_ASSIGN = 409, - LEFT_ASSIGN = 410, - RIGHT_ASSIGN = 411, - AND_ASSIGN = 412, - XOR_ASSIGN = 413, - OR_ASSIGN = 414, - SUB_ASSIGN = 415, - LEFT_PAREN = 416, - RIGHT_PAREN = 417, - LEFT_BRACKET = 418, - RIGHT_BRACKET = 419, - LEFT_BRACE = 420, - RIGHT_BRACE = 421, - DOT = 422, - COMMA = 423, - COLON = 424, - EQUAL = 425, - SEMICOLON = 426, - BANG = 427, - DASH = 428, - TILDE = 429, - PLUS = 430, - STAR = 431, - SLASH = 432, - PERCENT = 433, - LEFT_ANGLE = 434, - RIGHT_ANGLE = 435, - VERTICAL_BAR = 436, - CARET = 437, - AMPERSAND = 438, - QUESTION = 439 + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_INVARIANT = 3, /* INVARIANT */ + YYSYMBOL_PRECISE = 4, /* PRECISE */ + YYSYMBOL_HIGH_PRECISION = 5, /* HIGH_PRECISION */ + YYSYMBOL_MEDIUM_PRECISION = 6, /* MEDIUM_PRECISION */ + YYSYMBOL_LOW_PRECISION = 7, /* LOW_PRECISION */ + YYSYMBOL_PRECISION = 8, /* PRECISION */ + YYSYMBOL_ATTRIBUTE = 9, /* ATTRIBUTE */ + YYSYMBOL_CONST_QUAL = 10, /* CONST_QUAL */ + YYSYMBOL_BOOL_TYPE = 11, /* BOOL_TYPE */ + YYSYMBOL_FLOAT_TYPE = 12, /* FLOAT_TYPE */ + YYSYMBOL_INT_TYPE = 13, /* INT_TYPE */ + YYSYMBOL_UINT_TYPE = 14, /* UINT_TYPE */ + YYSYMBOL_BREAK = 15, /* BREAK */ + YYSYMBOL_CONTINUE = 16, /* CONTINUE */ + YYSYMBOL_DO = 17, /* DO */ + YYSYMBOL_ELSE = 18, /* ELSE */ + YYSYMBOL_FOR = 19, /* FOR */ + YYSYMBOL_IF = 20, /* IF */ + YYSYMBOL_DISCARD = 21, /* DISCARD */ + YYSYMBOL_RETURN = 22, /* RETURN */ + YYSYMBOL_SWITCH = 23, /* SWITCH */ + YYSYMBOL_CASE = 24, /* CASE */ + YYSYMBOL_DEFAULT = 25, /* DEFAULT */ + YYSYMBOL_BVEC2 = 26, /* BVEC2 */ + YYSYMBOL_BVEC3 = 27, /* BVEC3 */ + YYSYMBOL_BVEC4 = 28, /* BVEC4 */ + YYSYMBOL_IVEC2 = 29, /* IVEC2 */ + YYSYMBOL_IVEC3 = 30, /* IVEC3 */ + YYSYMBOL_IVEC4 = 31, /* IVEC4 */ + YYSYMBOL_VEC2 = 32, /* VEC2 */ + YYSYMBOL_VEC3 = 33, /* VEC3 */ + YYSYMBOL_VEC4 = 34, /* VEC4 */ + YYSYMBOL_UVEC2 = 35, /* UVEC2 */ + YYSYMBOL_UVEC3 = 36, /* UVEC3 */ + YYSYMBOL_UVEC4 = 37, /* UVEC4 */ + YYSYMBOL_MATRIX2 = 38, /* MATRIX2 */ + YYSYMBOL_MATRIX3 = 39, /* MATRIX3 */ + YYSYMBOL_MATRIX4 = 40, /* MATRIX4 */ + YYSYMBOL_IN_QUAL = 41, /* IN_QUAL */ + YYSYMBOL_OUT_QUAL = 42, /* OUT_QUAL */ + YYSYMBOL_INOUT_QUAL = 43, /* INOUT_QUAL */ + YYSYMBOL_UNIFORM = 44, /* UNIFORM */ + YYSYMBOL_BUFFER = 45, /* BUFFER */ + YYSYMBOL_VARYING = 46, /* VARYING */ + YYSYMBOL_MATRIX2x3 = 47, /* MATRIX2x3 */ + YYSYMBOL_MATRIX3x2 = 48, /* MATRIX3x2 */ + YYSYMBOL_MATRIX2x4 = 49, /* MATRIX2x4 */ + YYSYMBOL_MATRIX4x2 = 50, /* MATRIX4x2 */ + YYSYMBOL_MATRIX3x4 = 51, /* MATRIX3x4 */ + YYSYMBOL_MATRIX4x3 = 52, /* MATRIX4x3 */ + YYSYMBOL_SAMPLE = 53, /* SAMPLE */ + YYSYMBOL_CENTROID = 54, /* CENTROID */ + YYSYMBOL_FLAT = 55, /* FLAT */ + YYSYMBOL_SMOOTH = 56, /* SMOOTH */ + YYSYMBOL_NOPERSPECTIVE = 57, /* NOPERSPECTIVE */ + YYSYMBOL_PATCH = 58, /* PATCH */ + YYSYMBOL_READONLY = 59, /* READONLY */ + YYSYMBOL_WRITEONLY = 60, /* WRITEONLY */ + YYSYMBOL_COHERENT = 61, /* COHERENT */ + YYSYMBOL_RESTRICT = 62, /* RESTRICT */ + YYSYMBOL_VOLATILE = 63, /* VOLATILE */ + YYSYMBOL_SHARED = 64, /* SHARED */ + YYSYMBOL_STRUCT = 65, /* STRUCT */ + YYSYMBOL_VOID_TYPE = 66, /* VOID_TYPE */ + YYSYMBOL_WHILE = 67, /* WHILE */ + YYSYMBOL_SAMPLER2D = 68, /* SAMPLER2D */ + YYSYMBOL_SAMPLERCUBE = 69, /* SAMPLERCUBE */ + YYSYMBOL_SAMPLER_EXTERNAL_OES = 70, /* SAMPLER_EXTERNAL_OES */ + YYSYMBOL_SAMPLER2DRECT = 71, /* SAMPLER2DRECT */ + YYSYMBOL_SAMPLER2DARRAY = 72, /* SAMPLER2DARRAY */ + YYSYMBOL_ISAMPLER2D = 73, /* ISAMPLER2D */ + YYSYMBOL_ISAMPLER3D = 74, /* ISAMPLER3D */ + YYSYMBOL_ISAMPLERCUBE = 75, /* ISAMPLERCUBE */ + YYSYMBOL_ISAMPLER2DARRAY = 76, /* ISAMPLER2DARRAY */ + YYSYMBOL_USAMPLER2D = 77, /* USAMPLER2D */ + YYSYMBOL_USAMPLER3D = 78, /* USAMPLER3D */ + YYSYMBOL_USAMPLERCUBE = 79, /* USAMPLERCUBE */ + YYSYMBOL_USAMPLER2DARRAY = 80, /* USAMPLER2DARRAY */ + YYSYMBOL_SAMPLER2DMS = 81, /* SAMPLER2DMS */ + YYSYMBOL_ISAMPLER2DMS = 82, /* ISAMPLER2DMS */ + YYSYMBOL_USAMPLER2DMS = 83, /* USAMPLER2DMS */ + YYSYMBOL_SAMPLER2DMSARRAY = 84, /* SAMPLER2DMSARRAY */ + YYSYMBOL_ISAMPLER2DMSARRAY = 85, /* ISAMPLER2DMSARRAY */ + YYSYMBOL_USAMPLER2DMSARRAY = 86, /* USAMPLER2DMSARRAY */ + YYSYMBOL_SAMPLER3D = 87, /* SAMPLER3D */ + YYSYMBOL_SAMPLER3DRECT = 88, /* SAMPLER3DRECT */ + YYSYMBOL_SAMPLER2DSHADOW = 89, /* SAMPLER2DSHADOW */ + YYSYMBOL_SAMPLERCUBESHADOW = 90, /* SAMPLERCUBESHADOW */ + YYSYMBOL_SAMPLER2DARRAYSHADOW = 91, /* SAMPLER2DARRAYSHADOW */ + YYSYMBOL_SAMPLERVIDEOWEBGL = 92, /* SAMPLERVIDEOWEBGL */ + YYSYMBOL_SAMPLERCUBEARRAYOES = 93, /* SAMPLERCUBEARRAYOES */ + YYSYMBOL_SAMPLERCUBEARRAYSHADOWOES = 94, /* SAMPLERCUBEARRAYSHADOWOES */ + YYSYMBOL_ISAMPLERCUBEARRAYOES = 95, /* ISAMPLERCUBEARRAYOES */ + YYSYMBOL_USAMPLERCUBEARRAYOES = 96, /* USAMPLERCUBEARRAYOES */ + YYSYMBOL_SAMPLERCUBEARRAYEXT = 97, /* SAMPLERCUBEARRAYEXT */ + YYSYMBOL_SAMPLERCUBEARRAYSHADOWEXT = 98, /* SAMPLERCUBEARRAYSHADOWEXT */ + YYSYMBOL_ISAMPLERCUBEARRAYEXT = 99, /* ISAMPLERCUBEARRAYEXT */ + YYSYMBOL_USAMPLERCUBEARRAYEXT = 100, /* USAMPLERCUBEARRAYEXT */ + YYSYMBOL_SAMPLERBUFFER = 101, /* SAMPLERBUFFER */ + YYSYMBOL_ISAMPLERBUFFER = 102, /* ISAMPLERBUFFER */ + YYSYMBOL_USAMPLERBUFFER = 103, /* USAMPLERBUFFER */ + YYSYMBOL_SAMPLEREXTERNAL2DY2YEXT = 104, /* SAMPLEREXTERNAL2DY2YEXT */ + YYSYMBOL_IMAGE2D = 105, /* IMAGE2D */ + YYSYMBOL_IIMAGE2D = 106, /* IIMAGE2D */ + YYSYMBOL_UIMAGE2D = 107, /* UIMAGE2D */ + YYSYMBOL_IMAGE3D = 108, /* IMAGE3D */ + YYSYMBOL_IIMAGE3D = 109, /* IIMAGE3D */ + YYSYMBOL_UIMAGE3D = 110, /* UIMAGE3D */ + YYSYMBOL_IMAGE2DARRAY = 111, /* IMAGE2DARRAY */ + YYSYMBOL_IIMAGE2DARRAY = 112, /* IIMAGE2DARRAY */ + YYSYMBOL_UIMAGE2DARRAY = 113, /* UIMAGE2DARRAY */ + YYSYMBOL_IMAGECUBE = 114, /* IMAGECUBE */ + YYSYMBOL_IIMAGECUBE = 115, /* IIMAGECUBE */ + YYSYMBOL_UIMAGECUBE = 116, /* UIMAGECUBE */ + YYSYMBOL_IMAGECUBEARRAYOES = 117, /* IMAGECUBEARRAYOES */ + YYSYMBOL_IIMAGECUBEARRAYOES = 118, /* IIMAGECUBEARRAYOES */ + YYSYMBOL_UIMAGECUBEARRAYOES = 119, /* UIMAGECUBEARRAYOES */ + YYSYMBOL_IMAGECUBEARRAYEXT = 120, /* IMAGECUBEARRAYEXT */ + YYSYMBOL_IIMAGECUBEARRAYEXT = 121, /* IIMAGECUBEARRAYEXT */ + YYSYMBOL_UIMAGECUBEARRAYEXT = 122, /* UIMAGECUBEARRAYEXT */ + YYSYMBOL_IMAGEBUFFER = 123, /* IMAGEBUFFER */ + YYSYMBOL_IIMAGEBUFFER = 124, /* IIMAGEBUFFER */ + YYSYMBOL_UIMAGEBUFFER = 125, /* UIMAGEBUFFER */ + YYSYMBOL_ATOMICUINT = 126, /* ATOMICUINT */ + YYSYMBOL_PIXELLOCALANGLE = 127, /* PIXELLOCALANGLE */ + YYSYMBOL_IPIXELLOCALANGLE = 128, /* IPIXELLOCALANGLE */ + YYSYMBOL_UPIXELLOCALANGLE = 129, /* UPIXELLOCALANGLE */ + YYSYMBOL_LAYOUT = 130, /* LAYOUT */ + YYSYMBOL_YUVCSCSTANDARDEXT = 131, /* YUVCSCSTANDARDEXT */ + YYSYMBOL_YUVCSCSTANDARDEXTCONSTANT = 132, /* YUVCSCSTANDARDEXTCONSTANT */ + YYSYMBOL_IDENTIFIER = 133, /* IDENTIFIER */ + YYSYMBOL_TYPE_NAME = 134, /* TYPE_NAME */ + YYSYMBOL_FLOATCONSTANT = 135, /* FLOATCONSTANT */ + YYSYMBOL_INTCONSTANT = 136, /* INTCONSTANT */ + YYSYMBOL_UINTCONSTANT = 137, /* UINTCONSTANT */ + YYSYMBOL_BOOLCONSTANT = 138, /* BOOLCONSTANT */ + YYSYMBOL_FIELD_SELECTION = 139, /* FIELD_SELECTION */ + YYSYMBOL_LEFT_OP = 140, /* LEFT_OP */ + YYSYMBOL_RIGHT_OP = 141, /* RIGHT_OP */ + YYSYMBOL_INC_OP = 142, /* INC_OP */ + YYSYMBOL_DEC_OP = 143, /* DEC_OP */ + YYSYMBOL_LE_OP = 144, /* LE_OP */ + YYSYMBOL_GE_OP = 145, /* GE_OP */ + YYSYMBOL_EQ_OP = 146, /* EQ_OP */ + YYSYMBOL_NE_OP = 147, /* NE_OP */ + YYSYMBOL_AND_OP = 148, /* AND_OP */ + YYSYMBOL_OR_OP = 149, /* OR_OP */ + YYSYMBOL_XOR_OP = 150, /* XOR_OP */ + YYSYMBOL_MUL_ASSIGN = 151, /* MUL_ASSIGN */ + YYSYMBOL_DIV_ASSIGN = 152, /* DIV_ASSIGN */ + YYSYMBOL_ADD_ASSIGN = 153, /* ADD_ASSIGN */ + YYSYMBOL_MOD_ASSIGN = 154, /* MOD_ASSIGN */ + YYSYMBOL_LEFT_ASSIGN = 155, /* LEFT_ASSIGN */ + YYSYMBOL_RIGHT_ASSIGN = 156, /* RIGHT_ASSIGN */ + YYSYMBOL_AND_ASSIGN = 157, /* AND_ASSIGN */ + YYSYMBOL_XOR_ASSIGN = 158, /* XOR_ASSIGN */ + YYSYMBOL_OR_ASSIGN = 159, /* OR_ASSIGN */ + YYSYMBOL_SUB_ASSIGN = 160, /* SUB_ASSIGN */ + YYSYMBOL_LEFT_PAREN = 161, /* LEFT_PAREN */ + YYSYMBOL_RIGHT_PAREN = 162, /* RIGHT_PAREN */ + YYSYMBOL_LEFT_BRACKET = 163, /* LEFT_BRACKET */ + YYSYMBOL_RIGHT_BRACKET = 164, /* RIGHT_BRACKET */ + YYSYMBOL_LEFT_BRACE = 165, /* LEFT_BRACE */ + YYSYMBOL_RIGHT_BRACE = 166, /* RIGHT_BRACE */ + YYSYMBOL_DOT = 167, /* DOT */ + YYSYMBOL_COMMA = 168, /* COMMA */ + YYSYMBOL_COLON = 169, /* COLON */ + YYSYMBOL_EQUAL = 170, /* EQUAL */ + YYSYMBOL_SEMICOLON = 171, /* SEMICOLON */ + YYSYMBOL_BANG = 172, /* BANG */ + YYSYMBOL_DASH = 173, /* DASH */ + YYSYMBOL_TILDE = 174, /* TILDE */ + YYSYMBOL_PLUS = 175, /* PLUS */ + YYSYMBOL_STAR = 176, /* STAR */ + YYSYMBOL_SLASH = 177, /* SLASH */ + YYSYMBOL_PERCENT = 178, /* PERCENT */ + YYSYMBOL_LEFT_ANGLE = 179, /* LEFT_ANGLE */ + YYSYMBOL_RIGHT_ANGLE = 180, /* RIGHT_ANGLE */ + YYSYMBOL_VERTICAL_BAR = 181, /* VERTICAL_BAR */ + YYSYMBOL_CARET = 182, /* CARET */ + YYSYMBOL_AMPERSAND = 183, /* AMPERSAND */ + YYSYMBOL_QUESTION = 184, /* QUESTION */ + YYSYMBOL_YYACCEPT = 185, /* $accept */ + YYSYMBOL_identifier = 186, /* identifier */ + YYSYMBOL_variable_identifier = 187, /* variable_identifier */ + YYSYMBOL_primary_expression = 188, /* primary_expression */ + YYSYMBOL_postfix_expression = 189, /* postfix_expression */ + YYSYMBOL_integer_expression = 190, /* integer_expression */ + YYSYMBOL_function_call = 191, /* function_call */ + YYSYMBOL_function_call_or_method = 192, /* function_call_or_method */ + YYSYMBOL_function_call_generic = 193, /* function_call_generic */ + YYSYMBOL_function_call_header_no_parameters = 194, /* function_call_header_no_parameters */ + YYSYMBOL_function_call_header_with_parameters = 195, /* function_call_header_with_parameters */ + YYSYMBOL_function_call_header = 196, /* function_call_header */ + YYSYMBOL_function_identifier = 197, /* function_identifier */ + YYSYMBOL_unary_expression = 198, /* unary_expression */ + YYSYMBOL_unary_operator = 199, /* unary_operator */ + YYSYMBOL_multiplicative_expression = 200, /* multiplicative_expression */ + YYSYMBOL_additive_expression = 201, /* additive_expression */ + YYSYMBOL_shift_expression = 202, /* shift_expression */ + YYSYMBOL_relational_expression = 203, /* relational_expression */ + YYSYMBOL_equality_expression = 204, /* equality_expression */ + YYSYMBOL_and_expression = 205, /* and_expression */ + YYSYMBOL_exclusive_or_expression = 206, /* exclusive_or_expression */ + YYSYMBOL_inclusive_or_expression = 207, /* inclusive_or_expression */ + YYSYMBOL_logical_and_expression = 208, /* logical_and_expression */ + YYSYMBOL_logical_xor_expression = 209, /* logical_xor_expression */ + YYSYMBOL_logical_or_expression = 210, /* logical_or_expression */ + YYSYMBOL_conditional_expression = 211, /* conditional_expression */ + YYSYMBOL_assignment_expression = 212, /* assignment_expression */ + YYSYMBOL_assignment_operator = 213, /* assignment_operator */ + YYSYMBOL_expression = 214, /* expression */ + YYSYMBOL_constant_expression = 215, /* constant_expression */ + YYSYMBOL_enter_struct = 216, /* enter_struct */ + YYSYMBOL_declaration = 217, /* declaration */ + YYSYMBOL_function_prototype = 218, /* function_prototype */ + YYSYMBOL_function_declarator = 219, /* function_declarator */ + YYSYMBOL_function_header_with_parameters = 220, /* function_header_with_parameters */ + YYSYMBOL_function_header = 221, /* function_header */ + YYSYMBOL_parameter_declarator = 222, /* parameter_declarator */ + YYSYMBOL_parameter_declaration = 223, /* parameter_declaration */ + YYSYMBOL_parameter_type_specifier = 224, /* parameter_type_specifier */ + YYSYMBOL_init_declarator_list = 225, /* init_declarator_list */ + YYSYMBOL_single_declaration = 226, /* single_declaration */ + YYSYMBOL_fully_specified_type = 227, /* fully_specified_type */ + YYSYMBOL_interpolation_qualifier = 228, /* interpolation_qualifier */ + YYSYMBOL_type_qualifier = 229, /* type_qualifier */ + YYSYMBOL_invariant_qualifier = 230, /* invariant_qualifier */ + YYSYMBOL_precise_qualifier = 231, /* precise_qualifier */ + YYSYMBOL_single_type_qualifier = 232, /* single_type_qualifier */ + YYSYMBOL_storage_qualifier = 233, /* storage_qualifier */ + YYSYMBOL_type_specifier = 234, /* type_specifier */ + YYSYMBOL_precision_qualifier = 235, /* precision_qualifier */ + YYSYMBOL_layout_qualifier = 236, /* layout_qualifier */ + YYSYMBOL_layout_qualifier_id_list = 237, /* layout_qualifier_id_list */ + YYSYMBOL_layout_qualifier_id = 238, /* layout_qualifier_id */ + YYSYMBOL_type_specifier_no_prec = 239, /* type_specifier_no_prec */ + YYSYMBOL_array_specifier = 240, /* array_specifier */ + YYSYMBOL_type_specifier_nonarray = 241, /* type_specifier_nonarray */ + YYSYMBOL_struct_specifier = 242, /* struct_specifier */ + YYSYMBOL_243_1 = 243, /* $@1 */ + YYSYMBOL_244_2 = 244, /* $@2 */ + YYSYMBOL_struct_declaration_list = 245, /* struct_declaration_list */ + YYSYMBOL_struct_declaration = 246, /* struct_declaration */ + YYSYMBOL_struct_declarator_list = 247, /* struct_declarator_list */ + YYSYMBOL_struct_declarator = 248, /* struct_declarator */ + YYSYMBOL_initializer = 249, /* initializer */ + YYSYMBOL_declaration_statement = 250, /* declaration_statement */ + YYSYMBOL_statement = 251, /* statement */ + YYSYMBOL_simple_statement = 252, /* simple_statement */ + YYSYMBOL_compound_statement_with_scope = 253, /* compound_statement_with_scope */ + YYSYMBOL_254_3 = 254, /* $@3 */ + YYSYMBOL_255_4 = 255, /* $@4 */ + YYSYMBOL_statement_no_new_scope = 256, /* statement_no_new_scope */ + YYSYMBOL_statement_with_scope = 257, /* statement_with_scope */ + YYSYMBOL_258_5 = 258, /* $@5 */ + YYSYMBOL_259_6 = 259, /* $@6 */ + YYSYMBOL_compound_statement_no_new_scope = 260, /* compound_statement_no_new_scope */ + YYSYMBOL_statement_list = 261, /* statement_list */ + YYSYMBOL_expression_statement = 262, /* expression_statement */ + YYSYMBOL_selection_statement = 263, /* selection_statement */ + YYSYMBOL_selection_rest_statement = 264, /* selection_rest_statement */ + YYSYMBOL_switch_statement = 265, /* switch_statement */ + YYSYMBOL_266_7 = 266, /* $@7 */ + YYSYMBOL_case_label = 267, /* case_label */ + YYSYMBOL_condition = 268, /* condition */ + YYSYMBOL_iteration_statement = 269, /* iteration_statement */ + YYSYMBOL_270_8 = 270, /* $@8 */ + YYSYMBOL_271_9 = 271, /* $@9 */ + YYSYMBOL_272_10 = 272, /* $@10 */ + YYSYMBOL_for_init_statement = 273, /* for_init_statement */ + YYSYMBOL_conditionopt = 274, /* conditionopt */ + YYSYMBOL_for_rest_statement = 275, /* for_rest_statement */ + YYSYMBOL_jump_statement = 276, /* jump_statement */ + YYSYMBOL_translation_unit = 277, /* translation_unit */ + YYSYMBOL_external_declaration = 278, /* external_declaration */ + YYSYMBOL_function_definition = 279, /* function_definition */ + YYSYMBOL_280_11 = 280 /* $@11 */ }; -# endif - -/* Value type. */ -# if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED - -union YYSTYPE -{ - - struct - { - union - { - const char *string; // pool allocated. - float f; - int i; - unsigned int u; - bool b; - }; - const TSymbol *symbol; - } lex; - struct - { - TOperator op; - union - { - TIntermNode *intermNode; - TIntermNodePair nodePair; - TIntermTyped *intermTypedNode; - TIntermAggregate *intermAggregate; - TIntermBlock *intermBlock; - TIntermDeclaration *intermDeclaration; - TIntermFunctionPrototype *intermFunctionPrototype; - TIntermSwitch *intermSwitch; - TIntermCase *intermCase; - }; - union - { - TVector *arraySizes; - TTypeSpecifierNonArray typeSpecifierNonArray; - TPublicType type; - TPrecision precision; - TLayoutQualifier layoutQualifier; - TQualifier qualifier; - TFunction *function; - TFunctionLookup *functionLookup; - TParameter param; - TDeclarator *declarator; - TDeclaratorList *declaratorList; - TFieldList *fieldList; - TQualifierWrapperBase *qualifierWrapper; - TTypeQualifierBuilder *typeQualifierBuilder; - }; - } interm; -}; - -typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -# endif - -/* Location type. */ -# if !defined YYLTYPE && !defined YYLTYPE_IS_DECLARED -typedef struct YYLTYPE YYLTYPE; -struct YYLTYPE -{ - int first_line; - int first_column; - int last_line; - int last_column; -}; -# define YYLTYPE_IS_DECLARED 1 -# define YYLTYPE_IS_TRIVIAL 1 -# endif - -int yyparse(TParseContext *context, void *scanner); - -#endif /* !YY_YY_GLSLANG_TAB_AUTOGEN_H_INCLUDED */ +typedef enum yysymbol_kind_t yysymbol_kind_t; /* Second part of user prologue. */ @@ -478,36 +486,93 @@ extern void yyerror(YYLTYPE *yylloc, TParseContext *context, void *scanner, cons # undef short #endif -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif #endif -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; #else typedef signed char yytype_int8; #endif -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short yytype_uint16; -#endif - -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; #else typedef short yytype_int16; #endif +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + #ifndef YYSIZE_T # ifdef __SIZE_TYPE__ # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif !defined YYSIZE_T +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -515,7 +580,17 @@ typedef short yytype_int16; # endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T)-1) +#define YYSIZE_MAXIMUM \ + YY_CAST(YYPTRDIFF_T, (YYPTRDIFF_MAXIMUM < YY_CAST(YYSIZE_T, -1) ? YYPTRDIFF_MAXIMUM \ + : YY_CAST(YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST(YYPTRDIFF_T, sizeof(X)) + +/* Stored state numbers (used for stacks). */ +typedef yytype_int16 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -529,35 +604,39 @@ typedef short yytype_int16; # endif #endif -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) || \ - defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__((__pure__)) # else -# define YY_ATTRIBUTE(Spec) /* empty */ +# define YY_ATTRIBUTE_PURE # endif #endif -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE((__pure__)) -#endif - #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE((__unused__)) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif #endif /* Suppress unused-variable warnings by "using" E. */ #if !defined lint || defined __GNUC__ -# define YYUSE(E) ((void)(E)) +# define YY_USE(E) ((void)(E)) #else -# define YYUSE(E) /* empty */ +# define YY_USE(E) /* empty */ #endif -#if defined __GNUC__ && !defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ - _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +#if defined __GNUC__ && !defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# endif # define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -570,7 +649,19 @@ typedef short yytype_int16; # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif -#if !defined yyoverflow || YYERROR_VERBOSE +#if defined __cplusplus && defined __GNUC__ && !defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END _Pragma("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + +#define YY_ASSERT(E) ((void)(0 && (E))) + +#if !defined yyoverflow /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -638,7 +729,7 @@ void free(void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ +#endif /* !defined yyoverflow */ #if (!defined yyoverflow && \ (!defined __cplusplus || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL && \ @@ -647,18 +738,19 @@ void free(void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss_alloc; + yy_state_t yyss_alloc; YYSTYPE yyvs_alloc; YYLTYPE yyls_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof(union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF(union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof(yytype_int16) + sizeof(YYSTYPE) + sizeof(YYLTYPE)) + 2 * YYSTACK_GAP_MAXIMUM) +# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF(yy_state_t) + YYSIZEOF(YYSTYPE) + YYSIZEOF(YYLTYPE)) + \ + 2 * YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -667,14 +759,14 @@ union yyalloc elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof(*yyptr); \ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF(*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF(*yyptr); \ } while (0) #endif @@ -684,12 +776,13 @@ union yyalloc not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) __builtin_memcpy(Dst, Src, (Count) * sizeof(*(Src))) +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy(Dst, Src, YY_CAST(YYSIZE_T, (Count)) * sizeof(*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYSIZE_T yyi; \ + YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } while (0) @@ -711,12 +804,14 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 453 -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 439 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK ? YY_CAST(yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ @@ -748,7 +843,7 @@ static const yytype_uint8 yytranslate[] = { #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = { +static const yytype_int16 yyrline[] = { 0, 259, 259, 260, 263, 270, 273, 278, 283, 288, 293, 302, 308, 311, 314, 317, 320, 323, 329, 336, 342, 345, 353, 356, 362, 365, 371, 375, 382, 390, 393, 396, 402, 405, 408, 411, 418, 419, 420, 421, 429, 430, 433, 436, 443, 444, 447, 453, @@ -772,12 +867,19 @@ static const yytype_uint16 yyrline[] = { 1670, 1673, 1676, 1679, 1687, 1693, 1699, 1702, 1708, 1708}; #endif -#if YYDEBUG || YYERROR_VERBOSE || 0 +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST(yysymbol_kind_t, yystos[State]) + +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name(yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = {"$end", +static const char *const yytname[] = {"\"end of file\"", "error", - "$undefined", + "\"invalid token\"", "INVARIANT", "PRECISE", "HIGH_PRECISION", @@ -1057,31 +1159,20 @@ static const char *const yytname[] = {"$end", "function_definition", "$@11", YY_NULLPTR}; + +static const char *yysymbol_name(yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} #endif -#ifdef YYPRINT -/* YYTOKNUM[NUM] -- (External) token number corresponding to the - (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = { - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, - 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, - 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, - 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, - 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439}; -#endif +#define YYPACT_NINF (-397) -#define YYPACT_NINF -397 +#define yypact_value_is_default(Yyn) ((Yyn) == YYPACT_NINF) -#define yypact_value_is_default(Yystate) (!!((Yystate) == (-397))) +#define YYTABLE_NINF (-289) -#define YYTABLE_NINF -289 - -#define yytable_value_is_error(Yytable_value) 0 +#define yytable_value_is_error(Yyn) 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ @@ -1119,7 +1210,7 @@ static const yytype_int16 yypact[] = { /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. Performed when YYTABLE does not specify something else to do. Zero means the default is an error. */ -static const yytype_uint16 yydefact[] = { +static const yytype_int16 yydefact[] = { 0, 127, 128, 153, 154, 155, 0, 135, 137, 173, 170, 171, 172, 177, 178, 179, 180, 181, 182, 174, 175, 176, 183, 184, 185, 186, 187, 188, 138, 139, 140, 143, 144, 136, 189, 190, 191, 192, 193, 194, 151, 141, 123, 122, 124, 142, 145, 146, 147, 148, 149, 150, 0, 169, 196, 198, 229, @@ -1156,7 +1247,7 @@ static const yytype_int16 yypgoto[] = { /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - -1, 279, 207, 208, 209, 366, 210, 211, 212, 213, 214, 215, 216, 254, 218, 219, + 0, 279, 207, 208, 209, 366, 210, 211, 212, 213, 214, 215, 216, 254, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 255, 256, 351, 257, 231, 162, 258, 259, 120, 121, 122, 151, 152, 153, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 174, 175, 232, 166, 136, 137, 236, 170, 190, 191, 280, 281, @@ -1546,9 +1637,9 @@ static const yytype_int16 yycheck[] = { 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, -1, 131, -1, -1, 134}; -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint16 yystos[] = { +/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of + state STATE-NUM. */ +static const yytype_int16 yystos[] = { 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, @@ -1574,8 +1665,8 @@ static const yytype_uint16 yystos[] = { 273, 162, 162, 214, 227, 229, 268, 255, 171, 212, 161, 268, 274, 275, 257, 264, 266, 186, 162, 166, 214, 171, 162, 18, 253, 170, 252, 256, 260, 162, 214, 256, 257, 249, 171}; -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint16 yyr1[] = { +/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ +static const yytype_int16 yyr1[] = { 0, 185, 186, 186, 187, 188, 188, 188, 188, 188, 188, 188, 189, 189, 189, 189, 189, 189, 190, 191, 192, 192, 193, 193, 194, 194, 195, 195, 196, 197, 197, 197, 198, 198, 198, 198, 199, 199, 199, 199, 200, 200, 200, 200, 201, 201, 201, 202, 202, 202, 203, 203, 203, 203, 203, 204, 204, @@ -1595,8 +1686,8 @@ static const yytype_uint16 yyr1[] = { 267, 268, 268, 270, 269, 271, 269, 272, 269, 273, 273, 274, 274, 275, 275, 276, 276, 276, 276, 276, 277, 277, 278, 278, 280, 279}; -/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = { +/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr2[] = { 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 4, 1, 3, 2, 2, 1, 1, 1, 3, 2, 2, 2, 1, 2, 3, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 3, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 3, 3, 1, 3, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 5, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 2, @@ -1609,14 +1700,18 @@ static const yytype_uint8 yyr2[] = { 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 5, 1, 1, 0, 2, 0, 2, 2, 3, 1, 2, 1, 2, 5, 3, 1, 0, 6, 3, 2, 1, 4, 0, 6, 0, 8, 0, 7, 1, 1, 1, 0, 2, 3, 2, 2, 2, 3, 2, 1, 2, 1, 1, 0, 3}; +enum +{ + YYENOMEM = -2 +}; + #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab #define YYRECOVERING() (!!yyerrstatus) @@ -1637,9 +1732,9 @@ static const yytype_uint8 yyr2[] = { } \ while (0) -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends @@ -1680,12 +1775,19 @@ static const yytype_uint8 yyr2[] = { YYFPRINTF Args; \ } while (0) -/* YY_LOCATION_PRINT -- Print the location on the stream. +/* YYLOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ -# ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# ifndef YYLOCATION_PRINT + +# if defined YY_LOCATION_PRINT + +/* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc)) + +# elif defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL /* Print *YYLOCP on YYO. Private, do not rely on its existence. */ @@ -1714,20 +1816,29 @@ static int yy_location_print_(FILE *yyo, YYLTYPE const *const yylocp) return res; } -# define YY_LOCATION_PRINT(File, Loc) yy_location_print_(File, &(Loc)) +# define YYLOCATION_PRINT yy_location_print_ + +/* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc)) # else -# define YY_LOCATION_PRINT(File, Loc) ((void)0) -# endif -# endif -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +# define YYLOCATION_PRINT(File, Loc) ((void)0) +/* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT YYLOCATION_PRINT + +# endif +# endif /* !defined YYLOCATION_PRINT */ + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do \ { \ if (yydebug) \ { \ YYFPRINTF(stderr, "%s ", Title); \ - yy_symbol_print(stderr, Type, Value, Location, context, scanner); \ + yy_symbol_print(stderr, Kind, Value, Location, context, scanner); \ YYFPRINTF(stderr, "\n"); \ } \ } while (0) @@ -1737,24 +1848,22 @@ static int yy_location_print_(FILE *yyo, YYLTYPE const *const yylocp) `-----------------------------------*/ static void yy_symbol_value_print(FILE *yyo, - int yytype, + yysymbol_kind_t yykind, YYSTYPE const *const yyvaluep, YYLTYPE const *const yylocationp, TParseContext *context, void *scanner) { FILE *yyoutput = yyo; - YYUSE(yyoutput); - YYUSE(yylocationp); - YYUSE(context); - YYUSE(scanner); + YY_USE(yyoutput); + YY_USE(yylocationp); + YY_USE(context); + YY_USE(scanner); if (!yyvaluep) return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT(yyo, yytoknum[yytype], *yyvaluep); -# endif - YYUSE(yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE(yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } /*---------------------------. @@ -1762,17 +1871,17 @@ static void yy_symbol_value_print(FILE *yyo, `---------------------------*/ static void yy_symbol_print(FILE *yyo, - int yytype, + yysymbol_kind_t yykind, YYSTYPE const *const yyvaluep, YYLTYPE const *const yylocationp, TParseContext *context, void *scanner) { - YYFPRINTF(yyo, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + YYFPRINTF(yyo, "%s %s (", yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name(yykind)); - YY_LOCATION_PRINT(yyo, *yylocationp); + YYLOCATION_PRINT(yyo, yylocationp); YYFPRINTF(yyo, ": "); - yy_symbol_value_print(yyo, yytype, yyvaluep, yylocationp, context, scanner); + yy_symbol_value_print(yyo, yykind, yyvaluep, yylocationp, context, scanner); YYFPRINTF(yyo, ")"); } @@ -1781,7 +1890,7 @@ static void yy_symbol_print(FILE *yyo, | TOP (included). | `------------------------------------------------------------------*/ -static void yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop) +static void yy_stack_print(yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF(stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -1803,23 +1912,24 @@ static void yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop) | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -static void yy_reduce_print(yytype_int16 *yyssp, +static void yy_reduce_print(yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, TParseContext *context, void *scanner) { - unsigned long yylno = yyrline[yyrule]; - int yynrhs = yyr2[yyrule]; + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF(stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); + YYFPRINTF(stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF(stderr, " $%d = ", yyi + 1); - yy_symbol_print(stderr, yystos[yyssp[yyi + 1 - yynrhs]], &yyvsp[(yyi + 1) - (yynrhs)], - &(yylsp[(yyi + 1) - (yynrhs)]), context, scanner); + yy_symbol_print(stderr, YY_ACCESSING_SYMBOL(+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)], &(yylsp[(yyi + 1) - (yynrhs)]), context, + scanner); YYFPRINTF(stderr, "\n"); } } @@ -1835,8 +1945,8 @@ static void yy_reduce_print(yytype_int16 *yyssp, multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YYDPRINTF(Args) ((void)0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -1857,251 +1967,27 @@ int yydebug; # define YYMAXDEPTH 10000 #endif -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T yystrlen(const char *yystr) -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif - -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char *yystpcpy(char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T yytnamerr(char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - else - goto append; - - append: - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes:; - } - - if (!yyres) - return yystrlen(yystr); - - return (YYSIZE_T)(yystpcpy(yyres, yystr) - yyres); -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int yysyntax_error(YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr(YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum - { - YYERROR_VERBOSE_ARGS_MAXIMUM = 5 - }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default(yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR && - !yytable_value_is_error(yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr(YY_NULLPTR, yytname[yyx]); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - default: /* Avoid compiler warnings. */ - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - YYSIZE_T yysize1 = yysize + yystrlen(yyformat); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (!(yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr(yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ static void yydestruct(const char *yymsg, - int yytype, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, TParseContext *context, void *scanner) { - YYUSE(yyvaluep); - YYUSE(yylocationp); - YYUSE(context); - YYUSE(scanner); + YY_USE(yyvaluep); + YY_USE(yylocationp); + YY_USE(context); + YY_USE(scanner); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT(yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE(yytype); + YY_USE(yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } @@ -2111,7 +1997,7 @@ static void yydestruct(const char *yymsg, int yyparse(TParseContext *context, void *scanner) { - /* The lookahead symbol. */ + /* Lookahead token kind. */ int yychar; /* The semantic value of the lookahead symbol. */ @@ -2129,55 +2015,45 @@ int yyparse(TParseContext *context, void *scanner) YYLTYPE yylloc = yyloc_default; /* Number of syntax errors so far. */ - int yynerrs; + int yynerrs = 0; - int yystate; + yy_state_fast_t yystate = 0; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yyerrstatus = 0; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - 'yyls': related to locations. - - Refer to the stacks through separate pointers, to allow yyoverflow + /* Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; - /* The semantic value stack. */ + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; + + /* The semantic value stack: array, bottom, top. */ YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; - /* The location stack. */ + /* The location stack: array, bottom, top. */ YYLTYPE yylsa[YYINITDEPTH]; - YYLTYPE *yyls; - YYLTYPE *yylsp; - - /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[3]; - - YYSIZE_T yystacksize; + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp = yyls; int yyn; + /* The return value of yyparse. */ int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; YYLTYPE yyloc; -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3]; #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) @@ -2185,18 +2061,11 @@ int yyparse(TParseContext *context, void *scanner) Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yylsp = yyls = yylsa; - yystacksize = YYINITDEPTH; - YYDPRINTF((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - yylsp[0] = yylloc; + yychar = YYEMPTY; /* Cause a token to be read. */ + + yylsp[0] = yylloc; goto yysetstate; /*------------------------------------------------------------. @@ -2208,34 +2077,39 @@ yynewstate: yyssp++; /*--------------------------------------------------------------------. -| yynewstate -- set current state (the top of the stack) to yystate. | +| yysetstate -- set current state (the top of the stack) to yystate. | `--------------------------------------------------------------------*/ yysetstate: - *yyssp = (yytype_int16)yystate; + YYDPRINTF((stderr, "Entering state %d\n", yystate)); + YY_ASSERT(0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST(yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT(yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE - goto yyexhaustedlab; + YYNOMEM; #else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = (YYSIZE_T)(yyssp - yyss + 1); + YYPTRDIFF_T yysize = yyssp - yyss + 1; # if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - YYLTYPE *yyls1 = yyls; + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; + YYLTYPE *yyls1 = yyls; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ - yyoverflow(YY_("memory exhausted"), &yyss1, yysize * sizeof(*yyssp), &yyvs1, - yysize * sizeof(*yyvsp), &yyls1, yysize * sizeof(*yylsp), &yystacksize); + yyoverflow(YY_("memory exhausted"), &yyss1, yysize * YYSIZEOF(*yyssp), &yyvs1, + yysize * YYSIZEOF(*yyvsp), &yyls1, yysize * YYSIZEOF(*yylsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; yyls = yyls1; @@ -2243,16 +2117,17 @@ yysetstate: # else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + YYNOMEM; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = (union yyalloc *)YYSTACK_ALLOC(YYSTACK_BYTES(yystacksize)); + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = YY_CAST( + union yyalloc *, YYSTACK_ALLOC(YY_CAST(YYSIZE_T, YYSTACK_BYTES(yystacksize)))); if (!yyptr) - goto yyexhaustedlab; + YYNOMEM; YYSTACK_RELOCATE(yyss_alloc, yyss); YYSTACK_RELOCATE(yyvs_alloc, yyvs); YYSTACK_RELOCATE(yyls_alloc, yyls); @@ -2266,15 +2141,15 @@ yysetstate: yyvsp = yyvs + yysize - 1; yylsp = yyls + yysize - 1; - YYDPRINTF((stderr, "Stack size increased to %lu\n", (unsigned long)yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF((stderr, "Stack size increased to %ld\n", YY_CAST(long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - YYDPRINTF((stderr, "Entering state %d\n", yystate)); - if (yystate == YYFINAL) YYACCEPT; @@ -2294,18 +2169,30 @@ yybackup: /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ if (yychar == YYEMPTY) { - YYDPRINTF((stderr, "Reading a token: ")); + YYDPRINTF((stderr, "Reading a token\n")); yychar = yylex(&yylval, &yylloc, scanner); } if (yychar <= YYEOF) { - yychar = yytoken = YYEOF; + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; YYDPRINTF((stderr, "Now at end of input.\n")); } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + yyerror_range[1] = yylloc; + goto yyerrlab1; + } else { yytoken = YYTRANSLATE(yychar); @@ -2333,15 +2220,14 @@ yybackup: /* Shift the lookahead token. */ YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; + + /* Discard the shifted token. */ + yychar = YYEMPTY; goto yynewstate; /*-----------------------------------------------------------. @@ -2376,66 +2262,53 @@ yyreduce: YY_REDUCE_PRINT(yyn); switch (yyn) { - case 4: - + case 4: /* variable_identifier: IDENTIFIER */ { // The symbol table search was done in the lexical phase (yyval.interm.intermTypedNode) = context->parseVariableIdentifier( (yylsp[0]), ImmutableString((yyvsp[0].lex).string), (yyvsp[0].lex).symbol); } - break; - case 5: - + case 5: /* primary_expression: variable_identifier */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 6: - + case 6: /* primary_expression: INTCONSTANT */ { TConstantUnion *unionArray = new TConstantUnion[1]; unionArray->setIConst((yyvsp[0].lex).i); (yyval.interm.intermTypedNode) = context->addScalarLiteral(unionArray, (yylsp[0])); } - break; - case 7: - + case 7: /* primary_expression: UINTCONSTANT */ { TConstantUnion *unionArray = new TConstantUnion[1]; unionArray->setUConst((yyvsp[0].lex).u); (yyval.interm.intermTypedNode) = context->addScalarLiteral(unionArray, (yylsp[0])); } - break; - case 8: - + case 8: /* primary_expression: FLOATCONSTANT */ { TConstantUnion *unionArray = new TConstantUnion[1]; unionArray->setFConst((yyvsp[0].lex).f); (yyval.interm.intermTypedNode) = context->addScalarLiteral(unionArray, (yylsp[0])); } - break; - case 9: - + case 9: /* primary_expression: BOOLCONSTANT */ { TConstantUnion *unionArray = new TConstantUnion[1]; unionArray->setBConst((yyvsp[0].lex).b); (yyval.interm.intermTypedNode) = context->addScalarLiteral(unionArray, (yylsp[0])); } - break; - case 10: - + case 10: /* primary_expression: YUVCSCSTANDARDEXTCONSTANT */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::EXT_YUV_target)) { @@ -2447,737 +2320,580 @@ yyreduce: getYuvCscStandardEXT(ImmutableString((yyvsp[0].lex).string))); (yyval.interm.intermTypedNode) = context->addScalarLiteral(unionArray, (yylsp[0])); } - break; - case 11: - + case 11: /* primary_expression: LEFT_PAREN expression RIGHT_PAREN */ { (yyval.interm.intermTypedNode) = (yyvsp[-1].interm.intermTypedNode); } - break; - case 12: - + case 12: /* postfix_expression: primary_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 13: - + case 13: /* postfix_expression: postfix_expression LEFT_BRACKET integer_expression + RIGHT_BRACKET */ { (yyval.interm.intermTypedNode) = context->addIndexExpression((yyvsp[-3].interm.intermTypedNode), (yylsp[-2]), (yyvsp[-1].interm.intermTypedNode)); } - break; - case 14: - + case 14: /* postfix_expression: function_call */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 15: - + case 15: /* postfix_expression: postfix_expression DOT FIELD_SELECTION */ { (yyval.interm.intermTypedNode) = context->addFieldSelectionExpression( (yyvsp[-2].interm.intermTypedNode), (yylsp[-1]), ImmutableString((yyvsp[0].lex).string), (yylsp[0])); } - break; - case 16: - + case 16: /* postfix_expression: postfix_expression INC_OP */ { (yyval.interm.intermTypedNode) = context->addUnaryMathLValue( EOpPostIncrement, (yyvsp[-1].interm.intermTypedNode), (yylsp[0])); } - break; - case 17: - + case 17: /* postfix_expression: postfix_expression DEC_OP */ { (yyval.interm.intermTypedNode) = context->addUnaryMathLValue( EOpPostDecrement, (yyvsp[-1].interm.intermTypedNode), (yylsp[0])); } - break; - case 18: - + case 18: /* integer_expression: expression */ { context->checkIsScalarInteger((yyvsp[0].interm.intermTypedNode), "[]"); (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 19: - + case 19: /* function_call: function_call_or_method */ { (yyval.interm.intermTypedNode) = context->addFunctionCallOrMethod((yyvsp[0].interm.functionLookup), (yylsp[0])); } - break; - case 20: - + case 20: /* function_call_or_method: function_call_generic */ { (yyval.interm.functionLookup) = (yyvsp[0].interm.functionLookup); } - break; - case 21: - + case 21: /* function_call_or_method: postfix_expression DOT function_call_generic */ { ES3_OR_NEWER("", (yylsp[0]), "methods"); (yyval.interm.functionLookup) = (yyvsp[0].interm.functionLookup); (yyval.interm.functionLookup)->setThisNode((yyvsp[-2].interm.intermTypedNode)); } - break; - case 22: - + case 22: /* function_call_generic: function_call_header_with_parameters RIGHT_PAREN */ { (yyval.interm.functionLookup) = (yyvsp[-1].interm.functionLookup); } - break; - case 23: - + case 23: /* function_call_generic: function_call_header_no_parameters RIGHT_PAREN */ { (yyval.interm.functionLookup) = (yyvsp[-1].interm.functionLookup); } - break; - case 24: - + case 24: /* function_call_header_no_parameters: function_call_header VOID_TYPE */ { (yyval.interm.functionLookup) = (yyvsp[-1].interm.functionLookup); } - break; - case 25: - + case 25: /* function_call_header_no_parameters: function_call_header */ { (yyval.interm.functionLookup) = (yyvsp[0].interm.functionLookup); } - break; - case 26: - + case 26: /* function_call_header_with_parameters: function_call_header assignment_expression + */ { (yyval.interm.functionLookup) = (yyvsp[-1].interm.functionLookup); (yyval.interm.functionLookup)->addArgument((yyvsp[0].interm.intermTypedNode)); } - break; - case 27: - + case 27: /* function_call_header_with_parameters: function_call_header_with_parameters COMMA + assignment_expression */ { (yyval.interm.functionLookup) = (yyvsp[-2].interm.functionLookup); (yyval.interm.functionLookup)->addArgument((yyvsp[0].interm.intermTypedNode)); } - break; - case 28: - + case 28: /* function_call_header: function_identifier LEFT_PAREN */ { (yyval.interm.functionLookup) = (yyvsp[-1].interm.functionLookup); } - break; - case 29: - + case 29: /* function_identifier: type_specifier_no_prec */ { (yyval.interm.functionLookup) = context->addConstructorFunc((yyvsp[0].interm.type)); } - break; - case 30: - + case 30: /* function_identifier: IDENTIFIER */ { (yyval.interm.functionLookup) = context->addNonConstructorFunc( ImmutableString((yyvsp[0].lex).string), (yyvsp[0].lex).symbol); } - break; - case 31: - + case 31: /* function_identifier: FIELD_SELECTION */ { (yyval.interm.functionLookup) = context->addNonConstructorFunc( ImmutableString((yyvsp[0].lex).string), (yyvsp[0].lex).symbol); } - break; - case 32: - + case 32: /* unary_expression: postfix_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 33: - + case 33: /* unary_expression: INC_OP unary_expression */ { (yyval.interm.intermTypedNode) = context->addUnaryMathLValue( EOpPreIncrement, (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 34: - + case 34: /* unary_expression: DEC_OP unary_expression */ { (yyval.interm.intermTypedNode) = context->addUnaryMathLValue( EOpPreDecrement, (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 35: - + case 35: /* unary_expression: unary_operator unary_expression */ { (yyval.interm.intermTypedNode) = context->addUnaryMath( (yyvsp[-1].interm.op), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 36: - + case 36: /* unary_operator: PLUS */ { (yyval.interm.op) = EOpPositive; } - break; - case 37: - + case 37: /* unary_operator: DASH */ { (yyval.interm.op) = EOpNegative; } - break; - case 38: - + case 38: /* unary_operator: BANG */ { (yyval.interm.op) = EOpLogicalNot; } - break; - case 39: - + case 39: /* unary_operator: TILDE */ { ES3_OR_NEWER("~", (yyloc), "bit-wise operator"); (yyval.interm.op) = EOpBitwiseNot; } - break; - case 40: - + case 40: /* multiplicative_expression: unary_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 41: - + case 41: /* multiplicative_expression: multiplicative_expression STAR unary_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpMul, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 42: - + case 42: /* multiplicative_expression: multiplicative_expression SLASH unary_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpDiv, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 43: - + case 43: /* multiplicative_expression: multiplicative_expression PERCENT unary_expression */ { ES3_OR_NEWER("%", (yylsp[-1]), "integer modulus operator"); (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpIMod, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 44: - + case 44: /* additive_expression: multiplicative_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 45: - + case 45: /* additive_expression: additive_expression PLUS multiplicative_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpAdd, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 46: - + case 46: /* additive_expression: additive_expression DASH multiplicative_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpSub, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 47: - + case 47: /* shift_expression: additive_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 48: - + case 48: /* shift_expression: shift_expression LEFT_OP additive_expression */ { ES3_OR_NEWER("<<", (yylsp[-1]), "bit-wise operator"); (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpBitShiftLeft, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 49: - + case 49: /* shift_expression: shift_expression RIGHT_OP additive_expression */ { ES3_OR_NEWER(">>", (yylsp[-1]), "bit-wise operator"); (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpBitShiftRight, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 50: - + case 50: /* relational_expression: shift_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 51: - + case 51: /* relational_expression: relational_expression LEFT_ANGLE shift_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult(EOpLessThan, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 52: - + case 52: /* relational_expression: relational_expression RIGHT_ANGLE shift_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult( EOpGreaterThan, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 53: - + case 53: /* relational_expression: relational_expression LE_OP shift_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult( EOpLessThanEqual, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 54: - + case 54: /* relational_expression: relational_expression GE_OP shift_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult( EOpGreaterThanEqual, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 55: - + case 55: /* equality_expression: relational_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 56: - + case 56: /* equality_expression: equality_expression EQ_OP relational_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult(EOpEqual, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 57: - + case 57: /* equality_expression: equality_expression NE_OP relational_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult(EOpNotEqual, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 58: - + case 58: /* and_expression: equality_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 59: - + case 59: /* and_expression: and_expression AMPERSAND equality_expression */ { ES3_OR_NEWER("&", (yylsp[-1]), "bit-wise operator"); (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpBitwiseAnd, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 60: - + case 60: /* exclusive_or_expression: and_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 61: - + case 61: /* exclusive_or_expression: exclusive_or_expression CARET and_expression */ { ES3_OR_NEWER("^", (yylsp[-1]), "bit-wise operator"); (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpBitwiseXor, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 62: - + case 62: /* inclusive_or_expression: exclusive_or_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 63: - + case 63: /* inclusive_or_expression: inclusive_or_expression VERTICAL_BAR + exclusive_or_expression */ { ES3_OR_NEWER("|", (yylsp[-1]), "bit-wise operator"); (yyval.interm.intermTypedNode) = context->addBinaryMath(EOpBitwiseOr, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 64: - + case 64: /* logical_and_expression: inclusive_or_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 65: - + case 65: /* logical_and_expression: logical_and_expression AND_OP inclusive_or_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult( EOpLogicalAnd, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 66: - + case 66: /* logical_xor_expression: logical_and_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 67: - + case 67: /* logical_xor_expression: logical_xor_expression XOR_OP logical_and_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult( EOpLogicalXor, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 68: - + case 68: /* logical_or_expression: logical_xor_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 69: - + case 69: /* logical_or_expression: logical_or_expression OR_OP logical_xor_expression */ { (yyval.interm.intermTypedNode) = context->addBinaryMathBooleanResult( EOpLogicalOr, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 70: - + case 70: /* conditional_expression: logical_or_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 71: - + case 71: /* conditional_expression: logical_or_expression QUESTION expression COLON + assignment_expression */ { (yyval.interm.intermTypedNode) = context->addTernarySelection( (yyvsp[-4].interm.intermTypedNode), (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-3])); } - break; - case 72: - + case 72: /* assignment_expression: conditional_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 73: - + case 73: /* assignment_expression: unary_expression assignment_operator + assignment_expression */ { (yyval.interm.intermTypedNode) = context->addAssign((yyvsp[-1].interm.op), (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 74: - + case 74: /* assignment_operator: EQUAL */ { (yyval.interm.op) = EOpAssign; } - break; - case 75: - + case 75: /* assignment_operator: MUL_ASSIGN */ { (yyval.interm.op) = EOpMulAssign; } - break; - case 76: - + case 76: /* assignment_operator: DIV_ASSIGN */ { (yyval.interm.op) = EOpDivAssign; } - break; - case 77: - + case 77: /* assignment_operator: MOD_ASSIGN */ { ES3_OR_NEWER("%=", (yyloc), "integer modulus operator"); (yyval.interm.op) = EOpIModAssign; } - break; - case 78: - + case 78: /* assignment_operator: ADD_ASSIGN */ { (yyval.interm.op) = EOpAddAssign; } - break; - case 79: - + case 79: /* assignment_operator: SUB_ASSIGN */ { (yyval.interm.op) = EOpSubAssign; } - break; - case 80: - + case 80: /* assignment_operator: LEFT_ASSIGN */ { ES3_OR_NEWER("<<=", (yyloc), "bit-wise operator"); (yyval.interm.op) = EOpBitShiftLeftAssign; } - break; - case 81: - + case 81: /* assignment_operator: RIGHT_ASSIGN */ { ES3_OR_NEWER(">>=", (yyloc), "bit-wise operator"); (yyval.interm.op) = EOpBitShiftRightAssign; } - break; - case 82: - + case 82: /* assignment_operator: AND_ASSIGN */ { ES3_OR_NEWER("&=", (yyloc), "bit-wise operator"); (yyval.interm.op) = EOpBitwiseAndAssign; } - break; - case 83: - + case 83: /* assignment_operator: XOR_ASSIGN */ { ES3_OR_NEWER("^=", (yyloc), "bit-wise operator"); (yyval.interm.op) = EOpBitwiseXorAssign; } - break; - case 84: - + case 84: /* assignment_operator: OR_ASSIGN */ { ES3_OR_NEWER("|=", (yyloc), "bit-wise operator"); (yyval.interm.op) = EOpBitwiseOrAssign; } - break; - case 85: - + case 85: /* expression: assignment_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 86: - + case 86: /* expression: expression COMMA assignment_expression */ { (yyval.interm.intermTypedNode) = context->addComma( (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1])); } - break; - case 87: - + case 87: /* constant_expression: conditional_expression */ { context->checkIsConst((yyvsp[0].interm.intermTypedNode)); (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 88: - + case 88: /* enter_struct: IDENTIFIER LEFT_BRACE */ { context->enterStructDeclaration((yylsp[-1]), ImmutableString((yyvsp[-1].lex).string)); (yyval.lex) = (yyvsp[-1].lex); } - break; - case 89: - + case 89: /* declaration: function_prototype SEMICOLON */ { (yyval.interm.intermNode) = context->addFunctionPrototypeDeclaration( *((yyvsp[-1].interm).function), (yylsp[-1])); } - break; - case 90: - + case 90: /* declaration: init_declarator_list SEMICOLON */ { (yyval.interm.intermNode) = (yyvsp[-1].interm).intermDeclaration; } - break; - case 91: - + case 91: /* declaration: PRECISION precision_qualifier type_specifier_no_prec SEMICOLON */ { context->parseDefaultPrecisionQualifier((yyvsp[-2].interm.precision), (yyvsp[-1].interm.type), (yylsp[-3])); (yyval.interm.intermNode) = nullptr; } - break; - case 92: - + case 92: /* declaration: type_qualifier enter_struct struct_declaration_list RIGHT_BRACE + SEMICOLON */ { ES3_OR_NEWER(ImmutableString((yyvsp[-3].lex).string), (yylsp[-4]), "interface blocks"); (yyval.interm.intermNode) = context->addInterfaceBlock( @@ -3185,11 +2901,10 @@ yyreduce: ImmutableString((yyvsp[-3].lex).string), (yyvsp[-2].interm.fieldList), kEmptyImmutableString, (yyloc), NULL, (yyloc)); } - break; - case 93: - + case 93: /* declaration: type_qualifier enter_struct struct_declaration_list RIGHT_BRACE + IDENTIFIER SEMICOLON */ { ES3_OR_NEWER(ImmutableString((yyvsp[-4].lex).string), (yylsp[-5]), "interface blocks"); (yyval.interm.intermNode) = context->addInterfaceBlock( @@ -3197,11 +2912,10 @@ yyreduce: ImmutableString((yyvsp[-4].lex).string), (yyvsp[-3].interm.fieldList), ImmutableString((yyvsp[-1].lex).string), (yylsp[-1]), NULL, (yyloc)); } - break; - case 94: - + case 94: /* declaration: type_qualifier enter_struct struct_declaration_list RIGHT_BRACE + IDENTIFIER array_specifier SEMICOLON */ { ES3_OR_NEWER(ImmutableString((yyvsp[-5].lex).string), (yylsp[-6]), "interface blocks"); (yyval.interm.intermNode) = context->addInterfaceBlock( @@ -3210,56 +2924,44 @@ yyreduce: ImmutableString((yyvsp[-2].lex).string), (yylsp[-2]), (yyvsp[-1].interm.arraySizes), (yylsp[-1])); } - break; - case 95: - + case 95: /* declaration: type_qualifier SEMICOLON */ { context->parseGlobalLayoutQualifier(*(yyvsp[-1].interm.typeQualifierBuilder)); (yyval.interm.intermNode) = nullptr; } - break; - case 96: - + case 96: /* declaration: type_qualifier IDENTIFIER SEMICOLON */ { (yyval.interm.intermNode) = context->parseGlobalQualifierDeclaration( *(yyvsp[-2].interm.typeQualifierBuilder), (yylsp[-1]), ImmutableString((yyvsp[-1].lex).string), (yyvsp[-1].lex).symbol); } - break; - case 97: - + case 97: /* function_prototype: function_declarator RIGHT_PAREN */ { (yyval.interm).function = context->parseFunctionDeclarator((yylsp[0]), (yyvsp[-1].interm.function)); context->exitFunctionDeclaration(); } - break; - case 98: - + case 98: /* function_declarator: function_header */ { (yyval.interm.function) = (yyvsp[0].interm.function); } - break; - case 99: - + case 99: /* function_declarator: function_header_with_parameters */ { (yyval.interm.function) = (yyvsp[0].interm.function); } - break; - case 100: - + case 100: /* function_header_with_parameters: function_header parameter_declaration */ { // Add the parameter (yyval.interm.function) = (yyvsp[-1].interm.function); @@ -3275,11 +2977,10 @@ yyreduce: (yyvsp[-1].interm.function)->setHasVoidParameter(); } } - break; - case 101: - + case 101: /* function_header_with_parameters: function_header_with_parameters COMMA + parameter_declaration */ { (yyval.interm.function) = (yyvsp[-2].interm.function); // Only first parameter of one-parameter functions can be void @@ -3303,11 +3004,9 @@ yyreduce: ->addParameter((yyvsp[0].interm.param).createVariable(&context->symbolTable)); } } - break; - case 102: - + case 102: /* function_header: fully_specified_type IDENTIFIER LEFT_PAREN */ { (yyval.interm.function) = context->parseFunctionHeader( (yyvsp[-2].interm.type), ImmutableString((yyvsp[-1].lex).string), (yylsp[-1])); @@ -3315,107 +3014,86 @@ yyreduce: context->symbolTable.push(); context->enterFunctionDeclaration(); } - break; - case 103: - + case 103: /* parameter_declarator: type_specifier identifier */ { (yyval.interm.param) = context->parseParameterDeclarator( (yyvsp[-1].interm.type), ImmutableString((yyvsp[0].lex).string), (yylsp[0])); } - break; - case 104: - + case 104: /* parameter_declarator: type_specifier identifier array_specifier */ { (yyval.interm.param) = context->parseParameterArrayDeclarator( ImmutableString((yyvsp[-1].lex).string), (yylsp[-1]), *((yyvsp[0].interm.arraySizes)), (yylsp[0]), &(yyvsp[-2].interm.type)); } - break; - case 105: - + case 105: /* parameter_declaration: type_qualifier parameter_declarator */ { (yyval.interm.param) = (yyvsp[0].interm.param); context->checkIsParameterQualifierValid( (yylsp[0]), *(yyvsp[-1].interm.typeQualifierBuilder), (yyvsp[0].interm.param).type); } - break; - case 106: - + case 106: /* parameter_declaration: parameter_declarator */ { (yyval.interm.param) = (yyvsp[0].interm.param); (yyval.interm.param).type->setQualifier(EvqParamIn); } - break; - case 107: - + case 107: /* parameter_declaration: type_qualifier parameter_type_specifier */ { (yyval.interm.param) = (yyvsp[0].interm.param); context->checkIsParameterQualifierValid( (yylsp[0]), *(yyvsp[-1].interm.typeQualifierBuilder), (yyvsp[0].interm.param).type); } - break; - case 108: - + case 108: /* parameter_declaration: parameter_type_specifier */ { (yyval.interm.param) = (yyvsp[0].interm.param); (yyval.interm.param).type->setQualifier(EvqParamIn); } - break; - case 109: - + case 109: /* parameter_type_specifier: type_specifier */ { TParameter param = {0, new TType((yyvsp[0].interm.type))}; (yyval.interm.param) = param; } - break; - case 110: - + case 110: /* init_declarator_list: single_declaration */ { (yyval.interm) = (yyvsp[0].interm); } - break; - case 111: - + case 111: /* init_declarator_list: init_declarator_list COMMA identifier */ { (yyval.interm) = (yyvsp[-2].interm); context->parseDeclarator((yyval.interm).type, (yylsp[0]), ImmutableString((yyvsp[0].lex).string), (yyval.interm).intermDeclaration); } - break; - case 112: - + case 112: /* init_declarator_list: init_declarator_list COMMA identifier array_specifier */ { (yyval.interm) = (yyvsp[-3].interm); context->parseArrayDeclarator( (yyval.interm).type, (yylsp[-1]), ImmutableString((yyvsp[-1].lex).string), (yylsp[0]), *((yyvsp[0].interm.arraySizes)), (yyval.interm).intermDeclaration); } - break; - case 113: - + case 113: /* init_declarator_list: init_declarator_list COMMA identifier array_specifier + EQUAL initializer */ { ES3_OR_NEWER("=", (yylsp[-1]), "first-class arrays (array initializer)"); (yyval.interm) = (yyvsp[-5].interm); @@ -3424,53 +3102,45 @@ yyreduce: (yylsp[-2]), *((yyvsp[-2].interm.arraySizes)), (yylsp[-1]), (yyvsp[0].interm.intermTypedNode), (yyval.interm).intermDeclaration); } - break; - case 114: - + case 114: /* init_declarator_list: init_declarator_list COMMA identifier EQUAL initializer + */ { (yyval.interm) = (yyvsp[-4].interm); context->parseInitDeclarator( (yyval.interm).type, (yylsp[-2]), ImmutableString((yyvsp[-2].lex).string), (yylsp[-1]), (yyvsp[0].interm.intermTypedNode), (yyval.interm).intermDeclaration); } - break; - case 115: - + case 115: /* single_declaration: fully_specified_type */ { (yyval.interm).type = (yyvsp[0].interm.type); (yyval.interm).intermDeclaration = context->parseSingleDeclaration( (yyval.interm).type, (yylsp[0]), kEmptyImmutableString); } - break; - case 116: - + case 116: /* single_declaration: fully_specified_type identifier */ { (yyval.interm).type = (yyvsp[-1].interm.type); (yyval.interm).intermDeclaration = context->parseSingleDeclaration( (yyval.interm).type, (yylsp[0]), ImmutableString((yyvsp[0].lex).string)); } - break; - case 117: - + case 117: /* single_declaration: fully_specified_type identifier array_specifier */ { (yyval.interm).type = (yyvsp[-2].interm.type); (yyval.interm).intermDeclaration = context->parseSingleArrayDeclaration( (yyval.interm).type, (yylsp[-1]), ImmutableString((yyvsp[-1].lex).string), (yylsp[0]), *((yyvsp[0].interm.arraySizes))); } - break; - case 118: - + case 118: /* single_declaration: fully_specified_type identifier array_specifier EQUAL + initializer */ { ES3_OR_NEWER("[]", (yylsp[-2]), "first-class arrays (array initializer)"); (yyval.interm).type = (yyvsp[-4].interm.type); @@ -3479,56 +3149,44 @@ yyreduce: (yylsp[-2]), *((yyvsp[-2].interm.arraySizes)), (yylsp[-1]), (yyvsp[0].interm.intermTypedNode)); } - break; - case 119: - + case 119: /* single_declaration: fully_specified_type identifier EQUAL initializer */ { (yyval.interm).type = (yyvsp[-3].interm.type); (yyval.interm).intermDeclaration = context->parseSingleInitDeclaration( (yyval.interm).type, (yylsp[-2]), ImmutableString((yyvsp[-2].lex).string), (yylsp[-1]), (yyvsp[0].interm.intermTypedNode)); } - break; - case 120: - + case 120: /* fully_specified_type: type_specifier */ { context->addFullySpecifiedType(&(yyvsp[0].interm.type)); (yyval.interm.type) = (yyvsp[0].interm.type); } - break; - case 121: - + case 121: /* fully_specified_type: type_qualifier type_specifier */ { (yyval.interm.type) = context->addFullySpecifiedType( *(yyvsp[-1].interm.typeQualifierBuilder), (yyvsp[0].interm.type)); } - break; - case 122: - + case 122: /* interpolation_qualifier: SMOOTH */ { (yyval.interm.qualifier) = EvqSmooth; } - break; - case 123: - + case 123: /* interpolation_qualifier: FLAT */ { (yyval.interm.qualifier) = EvqFlat; } - break; - case 124: - + case 124: /* interpolation_qualifier: NOPERSPECTIVE */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::NV_shader_noperspective_interpolation)) @@ -3537,162 +3195,126 @@ yyreduce: } (yyval.interm.qualifier) = EvqNoPerspective; } - break; - case 125: - + case 125: /* type_qualifier: single_type_qualifier */ { (yyval.interm.typeQualifierBuilder) = context->createTypeQualifierBuilder((yylsp[0])); (yyval.interm.typeQualifierBuilder) ->appendQualifier((yyvsp[0].interm.qualifierWrapper)); } - break; - case 126: - + case 126: /* type_qualifier: type_qualifier single_type_qualifier */ { (yyval.interm.typeQualifierBuilder) = (yyvsp[-1].interm.typeQualifierBuilder); (yyval.interm.typeQualifierBuilder) ->appendQualifier((yyvsp[0].interm.qualifierWrapper)); } - break; - case 127: - + case 127: /* invariant_qualifier: INVARIANT */ { // empty } - break; - case 128: - + case 128: /* precise_qualifier: PRECISE */ { context->markShaderHasPrecise(); } - break; - case 129: - + case 129: /* single_type_qualifier: storage_qualifier */ { context->checkLocalVariableConstStorageQualifier(*(yyvsp[0].interm.qualifierWrapper)); (yyval.interm.qualifierWrapper) = (yyvsp[0].interm.qualifierWrapper); } - break; - case 130: - + case 130: /* single_type_qualifier: layout_qualifier */ { context->checkIsAtGlobalLevel((yylsp[0]), "layout"); (yyval.interm.qualifierWrapper) = new TLayoutQualifierWrapper((yyvsp[0].interm.layoutQualifier), (yylsp[0])); } - break; - case 131: - + case 131: /* single_type_qualifier: precision_qualifier */ { (yyval.interm.qualifierWrapper) = new TPrecisionQualifierWrapper((yyvsp[0].interm.precision), (yylsp[0])); } - break; - case 132: - + case 132: /* single_type_qualifier: interpolation_qualifier */ { (yyval.interm.qualifierWrapper) = new TInterpolationQualifierWrapper((yyvsp[0].interm.qualifier), (yylsp[0])); } - break; - case 133: - + case 133: /* single_type_qualifier: invariant_qualifier */ { context->checkIsAtGlobalLevel((yylsp[0]), "invariant"); (yyval.interm.qualifierWrapper) = new TInvariantQualifierWrapper((yylsp[0])); } - break; - case 134: - + case 134: /* single_type_qualifier: precise_qualifier */ { (yyval.interm.qualifierWrapper) = new TPreciseQualifierWrapper((yylsp[0])); } - break; - case 135: - + case 135: /* storage_qualifier: ATTRIBUTE */ { VERTEX_ONLY("attribute", (yylsp[0])); ES2_ONLY("attribute", (yylsp[0])); (yyval.interm.qualifierWrapper) = context->parseGlobalStorageQualifier(EvqAttribute, (yylsp[0])); } - break; - case 136: - + case 136: /* storage_qualifier: VARYING */ { ES2_ONLY("varying", (yylsp[0])); (yyval.interm.qualifierWrapper) = context->parseVaryingQualifier((yylsp[0])); } - break; - case 137: - + case 137: /* storage_qualifier: CONST_QUAL */ { (yyval.interm.qualifierWrapper) = new TStorageQualifierWrapper(EvqConst, (yylsp[0])); } - break; - case 138: - + case 138: /* storage_qualifier: IN_QUAL */ { (yyval.interm.qualifierWrapper) = context->parseInQualifier((yylsp[0])); } - break; - case 139: - + case 139: /* storage_qualifier: OUT_QUAL */ { (yyval.interm.qualifierWrapper) = context->parseOutQualifier((yylsp[0])); } - break; - case 140: - + case 140: /* storage_qualifier: INOUT_QUAL */ { (yyval.interm.qualifierWrapper) = context->parseInOutQualifier((yylsp[0])); } - break; - case 141: - + case 141: /* storage_qualifier: CENTROID */ { ES3_OR_NEWER("centroid", (yylsp[0]), "storage qualifier"); (yyval.interm.qualifierWrapper) = new TStorageQualifierWrapper(EvqCentroid, (yylsp[0])); } - break; - case 142: - + case 142: /* storage_qualifier: PATCH */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::EXT_tessellation_shader)) @@ -3701,216 +3323,168 @@ yyreduce: } (yyval.interm.qualifierWrapper) = new TStorageQualifierWrapper(EvqPatch, (yylsp[0])); } - break; - case 143: - + case 143: /* storage_qualifier: UNIFORM */ { (yyval.interm.qualifierWrapper) = context->parseGlobalStorageQualifier(EvqUniform, (yylsp[0])); } - break; - case 144: - + case 144: /* storage_qualifier: BUFFER */ { ES3_1_OR_NEWER("buffer", (yylsp[0]), "storage qualifier"); (yyval.interm.qualifierWrapper) = context->parseGlobalStorageQualifier(EvqBuffer, (yylsp[0])); } - break; - case 145: - + case 145: /* storage_qualifier: READONLY */ { (yyval.interm.qualifierWrapper) = new TMemoryQualifierWrapper(EvqReadOnly, (yylsp[0])); } - break; - case 146: - + case 146: /* storage_qualifier: WRITEONLY */ { (yyval.interm.qualifierWrapper) = new TMemoryQualifierWrapper(EvqWriteOnly, (yylsp[0])); } - break; - case 147: - + case 147: /* storage_qualifier: COHERENT */ { (yyval.interm.qualifierWrapper) = new TMemoryQualifierWrapper(EvqCoherent, (yylsp[0])); } - break; - case 148: - + case 148: /* storage_qualifier: RESTRICT */ { (yyval.interm.qualifierWrapper) = new TMemoryQualifierWrapper(EvqRestrict, (yylsp[0])); } - break; - case 149: - + case 149: /* storage_qualifier: VOLATILE */ { (yyval.interm.qualifierWrapper) = new TMemoryQualifierWrapper(EvqVolatile, (yylsp[0])); } - break; - case 150: - + case 150: /* storage_qualifier: SHARED */ { COMPUTE_ONLY("shared", (yylsp[0])); (yyval.interm.qualifierWrapper) = context->parseGlobalStorageQualifier(EvqShared, (yylsp[0])); } - break; - case 151: - + case 151: /* storage_qualifier: SAMPLE */ { ES3_OR_NEWER("sample", (yylsp[0]), "storage qualifier"); (yyval.interm.qualifierWrapper) = new TStorageQualifierWrapper(EvqSample, (yylsp[0])); } - break; - case 152: - + case 152: /* type_specifier: type_specifier_no_prec */ { (yyval.interm.type) = (yyvsp[0].interm.type); (yyval.interm.type).precision = context->symbolTable.getDefaultPrecision((yyvsp[0].interm.type).getBasicType()); } - break; - case 153: - + case 153: /* precision_qualifier: HIGH_PRECISION */ { (yyval.interm.precision) = EbpHigh; } - break; - case 154: - + case 154: /* precision_qualifier: MEDIUM_PRECISION */ { (yyval.interm.precision) = EbpMedium; } - break; - case 155: - + case 155: /* precision_qualifier: LOW_PRECISION */ { (yyval.interm.precision) = EbpLow; } - break; - case 156: - + case 156: /* layout_qualifier: LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN */ { context->checkCanUseLayoutQualifier((yylsp[-3])); (yyval.interm.layoutQualifier) = (yyvsp[-1].interm.layoutQualifier); } - break; - case 157: - + case 157: /* layout_qualifier_id_list: layout_qualifier_id */ { (yyval.interm.layoutQualifier) = (yyvsp[0].interm.layoutQualifier); } - break; - case 158: - + case 158: /* layout_qualifier_id_list: layout_qualifier_id_list COMMA layout_qualifier_id */ { (yyval.interm.layoutQualifier) = context->joinLayoutQualifiers( (yyvsp[-2].interm.layoutQualifier), (yyvsp[0].interm.layoutQualifier), (yylsp[0])); } - break; - case 159: - + case 159: /* layout_qualifier_id: IDENTIFIER */ { (yyval.interm.layoutQualifier) = context->parseLayoutQualifier(ImmutableString((yyvsp[0].lex).string), (yylsp[0])); } - break; - case 160: - + case 160: /* layout_qualifier_id: IDENTIFIER EQUAL INTCONSTANT */ { (yyval.interm.layoutQualifier) = context->parseLayoutQualifier( ImmutableString((yyvsp[-2].lex).string), (yylsp[-2]), (yyvsp[0].lex).i, (yylsp[0])); } - break; - case 161: - + case 161: /* layout_qualifier_id: IDENTIFIER EQUAL UINTCONSTANT */ { (yyval.interm.layoutQualifier) = context->parseLayoutQualifier( ImmutableString((yyvsp[-2].lex).string), (yylsp[-2]), (yyvsp[0].lex).i, (yylsp[0])); } - break; - case 162: - + case 162: /* layout_qualifier_id: SHARED */ { (yyval.interm.layoutQualifier) = context->parseLayoutQualifier(ImmutableString("shared"), (yylsp[0])); } - break; - case 163: - + case 163: /* type_specifier_no_prec: type_specifier_nonarray */ { (yyval.interm.type) .initialize((yyvsp[0].interm.typeSpecifierNonArray), (context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary)); } - break; - case 164: - + case 164: /* type_specifier_no_prec: type_specifier_nonarray array_specifier */ { (yyval.interm.type) .initialize((yyvsp[-1].interm.typeSpecifierNonArray), (context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary)); (yyval.interm.type).setArraySizes((yyvsp[0].interm.arraySizes)); } - break; - case 165: - + case 165: /* array_specifier: LEFT_BRACKET RIGHT_BRACKET */ { ES3_OR_NEWER("[]", (yylsp[-1]), "implicitly sized array"); (yyval.interm.arraySizes) = new TVector(); (yyval.interm.arraySizes)->push_back(0u); } - break; - case 166: - + case 166: /* array_specifier: LEFT_BRACKET constant_expression RIGHT_BRACKET */ { (yyval.interm.arraySizes) = new TVector(); unsigned int size = @@ -3920,21 +3494,18 @@ yyreduce: // follow. (yyval.interm.arraySizes)->push_back(size); } - break; - case 167: - + case 167: /* array_specifier: array_specifier LEFT_BRACKET RIGHT_BRACKET */ { ES3_1_OR_NEWER("[]", (yylsp[-1]), "arrays of arrays"); (yyval.interm.arraySizes) = (yyvsp[-2].interm.arraySizes); (yyval.interm.arraySizes)->insert((yyval.interm.arraySizes)->begin(), 0u); } - break; - case 168: - + case 168: /* array_specifier: array_specifier LEFT_BRACKET constant_expression RIGHT_BRACKET + */ { ES3_1_OR_NEWER("[]", (yylsp[-2]), "arrays of arrays"); (yyval.interm.arraySizes) = (yyvsp[-3].interm.arraySizes); @@ -3945,240 +3516,186 @@ yyreduce: // follow. (yyval.interm.arraySizes)->insert((yyval.interm.arraySizes)->begin(), size); } - break; - case 169: - + case 169: /* type_specifier_nonarray: VOID_TYPE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtVoid, (yylsp[0])); } - break; - case 170: - + case 170: /* type_specifier_nonarray: FLOAT_TYPE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); } - break; - case 171: - + case 171: /* type_specifier_nonarray: INT_TYPE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtInt, (yylsp[0])); } - break; - case 172: - + case 172: /* type_specifier_nonarray: UINT_TYPE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUInt, (yylsp[0])); } - break; - case 173: - + case 173: /* type_specifier_nonarray: BOOL_TYPE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtBool, (yylsp[0])); } - break; - case 174: - + case 174: /* type_specifier_nonarray: VEC2 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(2); } - break; - case 175: - + case 175: /* type_specifier_nonarray: VEC3 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(3); } - break; - case 176: - + case 176: /* type_specifier_nonarray: VEC4 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(4); } - break; - case 177: - + case 177: /* type_specifier_nonarray: BVEC2 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtBool, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(2); } - break; - case 178: - + case 178: /* type_specifier_nonarray: BVEC3 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtBool, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(3); } - break; - case 179: - + case 179: /* type_specifier_nonarray: BVEC4 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtBool, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(4); } - break; - case 180: - + case 180: /* type_specifier_nonarray: IVEC2 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtInt, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(2); } - break; - case 181: - + case 181: /* type_specifier_nonarray: IVEC3 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtInt, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(3); } - break; - case 182: - + case 182: /* type_specifier_nonarray: IVEC4 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtInt, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(4); } - break; - case 183: - + case 183: /* type_specifier_nonarray: UVEC2 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUInt, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(2); } - break; - case 184: - + case 184: /* type_specifier_nonarray: UVEC3 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUInt, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(3); } - break; - case 185: - + case 185: /* type_specifier_nonarray: UVEC4 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUInt, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setAggregate(4); } - break; - case 186: - + case 186: /* type_specifier_nonarray: MATRIX2 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(2, 2); } - break; - case 187: - + case 187: /* type_specifier_nonarray: MATRIX3 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(3, 3); } - break; - case 188: - + case 188: /* type_specifier_nonarray: MATRIX4 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(4, 4); } - break; - case 189: - + case 189: /* type_specifier_nonarray: MATRIX2x3 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(2, 3); } - break; - case 190: - + case 190: /* type_specifier_nonarray: MATRIX3x2 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(3, 2); } - break; - case 191: - + case 191: /* type_specifier_nonarray: MATRIX2x4 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(2, 4); } - break; - case 192: - + case 192: /* type_specifier_nonarray: MATRIX4x2 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(4, 2); } - break; - case 193: - + case 193: /* type_specifier_nonarray: MATRIX3x4 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(3, 4); } - break; - case 194: - + case 194: /* type_specifier_nonarray: MATRIX4x3 */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtFloat, (yylsp[0])); (yyval.interm.typeSpecifierNonArray).setMatrix(4, 3); } - break; - case 195: - + case 195: /* type_specifier_nonarray: YUVCSCSTANDARDEXT */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::EXT_YUV_target)) { @@ -4186,59 +3703,45 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtYuvCscStandardEXT, (yylsp[0])); } - break; - case 196: - + case 196: /* type_specifier_nonarray: SAMPLER2D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSampler2D, (yylsp[0])); } - break; - case 197: - + case 197: /* type_specifier_nonarray: SAMPLER3D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSampler3D, (yylsp[0])); } - break; - case 198: - + case 198: /* type_specifier_nonarray: SAMPLERCUBE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerCube, (yylsp[0])); } - break; - case 199: - + case 199: /* type_specifier_nonarray: SAMPLER2DARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSampler2DArray, (yylsp[0])); } - break; - case 200: - + case 200: /* type_specifier_nonarray: SAMPLER2DMS */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSampler2DMS, (yylsp[0])); } - break; - case 201: - + case 201: /* type_specifier_nonarray: SAMPLER2DMSARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSampler2DMSArray, (yylsp[0])); } - break; - case 202: - + case 202: /* type_specifier_nonarray: SAMPLERCUBEARRAYOES */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::OES_texture_cube_map_array)) @@ -4247,11 +3750,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerCubeArray, (yylsp[0])); } - break; - case 203: - + case 203: /* type_specifier_nonarray: SAMPLERCUBEARRAYEXT */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::EXT_texture_cube_map_array)) @@ -4260,11 +3761,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerCubeArray, (yylsp[0])); } - break; - case 204: - + case 204: /* type_specifier_nonarray: SAMPLERBUFFER */ { constexpr std::array extensions{ {TExtension::OES_texture_buffer, TExtension::EXT_texture_buffer}}; @@ -4275,59 +3774,45 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerBuffer, (yylsp[0])); } - break; - case 205: - + case 205: /* type_specifier_nonarray: ISAMPLER2D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtISampler2D, (yylsp[0])); } - break; - case 206: - + case 206: /* type_specifier_nonarray: ISAMPLER3D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtISampler3D, (yylsp[0])); } - break; - case 207: - + case 207: /* type_specifier_nonarray: ISAMPLERCUBE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtISamplerCube, (yylsp[0])); } - break; - case 208: - + case 208: /* type_specifier_nonarray: ISAMPLER2DARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtISampler2DArray, (yylsp[0])); } - break; - case 209: - + case 209: /* type_specifier_nonarray: ISAMPLER2DMS */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtISampler2DMS, (yylsp[0])); } - break; - case 210: - + case 210: /* type_specifier_nonarray: ISAMPLER2DMSARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtISampler2DMSArray, (yylsp[0])); } - break; - case 211: - + case 211: /* type_specifier_nonarray: ISAMPLERCUBEARRAYOES */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::OES_texture_cube_map_array)) @@ -4336,11 +3821,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtISamplerCubeArray, (yylsp[0])); } - break; - case 212: - + case 212: /* type_specifier_nonarray: ISAMPLERCUBEARRAYEXT */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::EXT_texture_cube_map_array)) @@ -4349,11 +3832,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtISamplerCubeArray, (yylsp[0])); } - break; - case 213: - + case 213: /* type_specifier_nonarray: ISAMPLERBUFFER */ { constexpr std::array extensions{ {TExtension::OES_texture_buffer, TExtension::EXT_texture_buffer}}; @@ -4364,59 +3845,45 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtISamplerBuffer, (yylsp[0])); } - break; - case 214: - + case 214: /* type_specifier_nonarray: USAMPLER2D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUSampler2D, (yylsp[0])); } - break; - case 215: - + case 215: /* type_specifier_nonarray: USAMPLER3D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUSampler3D, (yylsp[0])); } - break; - case 216: - + case 216: /* type_specifier_nonarray: USAMPLERCUBE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUSamplerCube, (yylsp[0])); } - break; - case 217: - + case 217: /* type_specifier_nonarray: USAMPLER2DARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUSampler2DArray, (yylsp[0])); } - break; - case 218: - + case 218: /* type_specifier_nonarray: USAMPLER2DMS */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUSampler2DMS, (yylsp[0])); } - break; - case 219: - + case 219: /* type_specifier_nonarray: USAMPLER2DMSARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUSampler2DMSArray, (yylsp[0])); } - break; - case 220: - + case 220: /* type_specifier_nonarray: USAMPLERCUBEARRAYOES */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::OES_texture_cube_map_array)) @@ -4425,11 +3892,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtUSamplerCubeArray, (yylsp[0])); } - break; - case 221: - + case 221: /* type_specifier_nonarray: USAMPLERCUBEARRAYEXT */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::EXT_texture_cube_map_array)) @@ -4438,11 +3903,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtUSamplerCubeArray, (yylsp[0])); } - break; - case 222: - + case 222: /* type_specifier_nonarray: USAMPLERBUFFER */ { constexpr std::array extensions{ {TExtension::OES_texture_buffer, TExtension::EXT_texture_buffer}}; @@ -4453,35 +3916,27 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtUSamplerBuffer, (yylsp[0])); } - break; - case 223: - + case 223: /* type_specifier_nonarray: SAMPLER2DSHADOW */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSampler2DShadow, (yylsp[0])); } - break; - case 224: - + case 224: /* type_specifier_nonarray: SAMPLERCUBESHADOW */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerCubeShadow, (yylsp[0])); } - break; - case 225: - + case 225: /* type_specifier_nonarray: SAMPLER2DARRAYSHADOW */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtSampler2DArrayShadow, (yylsp[0])); } - break; - case 226: - + case 226: /* type_specifier_nonarray: SAMPLERCUBEARRAYSHADOWOES */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::OES_texture_cube_map_array)) @@ -4490,11 +3945,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerCubeArrayShadow, (yylsp[0])); } - break; - case 227: - + case 227: /* type_specifier_nonarray: SAMPLERCUBEARRAYSHADOWEXT */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::EXT_texture_cube_map_array)) @@ -4503,11 +3956,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerCubeArrayShadow, (yylsp[0])); } - break; - case 228: - + case 228: /* type_specifier_nonarray: SAMPLERVIDEOWEBGL */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::WEBGL_video_texture)) { @@ -4515,11 +3966,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerVideoWEBGL, (yylsp[0])); } - break; - case 229: - + case 229: /* type_specifier_nonarray: SAMPLER_EXTERNAL_OES */ { constexpr std::array extensions{ {TExtension::NV_EGL_stream_consumer_external, @@ -4530,11 +3979,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerExternalOES, (yylsp[0])); } - break; - case 230: - + case 230: /* type_specifier_nonarray: SAMPLEREXTERNAL2DY2YEXT */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::EXT_YUV_target)) { @@ -4542,11 +3989,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSamplerExternal2DY2YEXT, (yylsp[0])); } - break; - case 231: - + case 231: /* type_specifier_nonarray: SAMPLER2DRECT */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::ARB_texture_rectangle)) { @@ -4554,107 +3999,81 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtSampler2DRect, (yylsp[0])); } - break; - case 232: - + case 232: /* type_specifier_nonarray: IMAGE2D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtImage2D, (yylsp[0])); } - break; - case 233: - + case 233: /* type_specifier_nonarray: IIMAGE2D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtIImage2D, (yylsp[0])); } - break; - case 234: - + case 234: /* type_specifier_nonarray: UIMAGE2D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUImage2D, (yylsp[0])); } - break; - case 235: - + case 235: /* type_specifier_nonarray: IMAGE3D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtImage3D, (yylsp[0])); } - break; - case 236: - + case 236: /* type_specifier_nonarray: IIMAGE3D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtIImage3D, (yylsp[0])); } - break; - case 237: - + case 237: /* type_specifier_nonarray: UIMAGE3D */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUImage3D, (yylsp[0])); } - break; - case 238: - + case 238: /* type_specifier_nonarray: IMAGE2DARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtImage2DArray, (yylsp[0])); } - break; - case 239: - + case 239: /* type_specifier_nonarray: IIMAGE2DARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtIImage2DArray, (yylsp[0])); } - break; - case 240: - + case 240: /* type_specifier_nonarray: UIMAGE2DARRAY */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUImage2DArray, (yylsp[0])); } - break; - case 241: - + case 241: /* type_specifier_nonarray: IMAGECUBE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtImageCube, (yylsp[0])); } - break; - case 242: - + case 242: /* type_specifier_nonarray: IIMAGECUBE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtIImageCube, (yylsp[0])); } - break; - case 243: - + case 243: /* type_specifier_nonarray: UIMAGECUBE */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtUImageCube, (yylsp[0])); } - break; - case 244: - + case 244: /* type_specifier_nonarray: IMAGECUBEARRAYOES */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::OES_texture_cube_map_array)) @@ -4663,11 +4082,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtImageCubeArray, (yylsp[0])); } - break; - case 245: - + case 245: /* type_specifier_nonarray: IMAGECUBEARRAYEXT */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::EXT_texture_cube_map_array)) @@ -4676,11 +4093,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtImageCubeArray, (yylsp[0])); } - break; - case 246: - + case 246: /* type_specifier_nonarray: IIMAGECUBEARRAYOES */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::OES_texture_cube_map_array)) @@ -4689,11 +4104,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtIImageCubeArray, (yylsp[0])); } - break; - case 247: - + case 247: /* type_specifier_nonarray: IIMAGECUBEARRAYEXT */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::EXT_texture_cube_map_array)) @@ -4702,11 +4115,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtIImageCubeArray, (yylsp[0])); } - break; - case 248: - + case 248: /* type_specifier_nonarray: UIMAGECUBEARRAYOES */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::OES_texture_cube_map_array)) @@ -4715,11 +4126,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtUImageCubeArray, (yylsp[0])); } - break; - case 249: - + case 249: /* type_specifier_nonarray: UIMAGECUBEARRAYEXT */ { if (context->getShaderVersion() < 320 && !context->checkCanUseExtension((yylsp[0]), TExtension::EXT_texture_cube_map_array)) @@ -4728,11 +4137,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtUImageCubeArray, (yylsp[0])); } - break; - case 250: - + case 250: /* type_specifier_nonarray: IMAGEBUFFER */ { constexpr std::array extensions{ {TExtension::OES_texture_buffer, TExtension::EXT_texture_buffer}}; @@ -4743,11 +4150,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtImageBuffer, (yylsp[0])); } - break; - case 251: - + case 251: /* type_specifier_nonarray: IIMAGEBUFFER */ { constexpr std::array extensions{ {TExtension::OES_texture_buffer, TExtension::EXT_texture_buffer}}; @@ -4758,11 +4163,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtIImageBuffer, (yylsp[0])); } - break; - case 252: - + case 252: /* type_specifier_nonarray: UIMAGEBUFFER */ { constexpr std::array extensions{ {TExtension::OES_texture_buffer, TExtension::EXT_texture_buffer}}; @@ -4773,19 +4176,15 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtUImageBuffer, (yylsp[0])); } - break; - case 253: - + case 253: /* type_specifier_nonarray: ATOMICUINT */ { (yyval.interm.typeSpecifierNonArray).initialize(EbtAtomicCounter, (yylsp[0])); } - break; - case 254: - + case 254: /* type_specifier_nonarray: PIXELLOCALANGLE */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::ANGLE_shader_pixel_local_storage)) @@ -4794,11 +4193,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtPixelLocalANGLE, (yylsp[0])); } - break; - case 255: - + case 255: /* type_specifier_nonarray: IPIXELLOCALANGLE */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::ANGLE_shader_pixel_local_storage)) @@ -4807,11 +4204,9 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtIPixelLocalANGLE, (yylsp[0])); } - break; - case 256: - + case 256: /* type_specifier_nonarray: UPIXELLOCALANGLE */ { if (!context->checkCanUseExtension((yylsp[0]), TExtension::ANGLE_shader_pixel_local_storage)) @@ -4820,452 +4215,353 @@ yyreduce: } (yyval.interm.typeSpecifierNonArray).initialize(EbtUPixelLocalANGLE, (yylsp[0])); } - break; - case 257: - + case 257: /* type_specifier_nonarray: struct_specifier */ { (yyval.interm.typeSpecifierNonArray) = (yyvsp[0].interm.typeSpecifierNonArray); } - break; - case 258: - + case 258: /* type_specifier_nonarray: TYPE_NAME */ { // This is for user defined type names. The lexical phase looked up the type. const TStructure *structure = static_cast((yyvsp[0].lex).symbol); (yyval.interm.typeSpecifierNonArray).initializeStruct(structure, false, (yylsp[0])); } - break; - case 259: - + case 259: /* $@1: %empty */ { context->enterStructDeclaration((yylsp[-1]), ImmutableString((yyvsp[-1].lex).string)); } - break; - case 260: - + case 260: /* struct_specifier: STRUCT identifier LEFT_BRACE $@1 struct_declaration_list + RIGHT_BRACE */ { (yyval.interm.typeSpecifierNonArray) = context->addStructure( (yylsp[-5]), (yylsp[-4]), ImmutableString((yyvsp[-4].lex).string), (yyvsp[-1].interm.fieldList)); } - break; - case 261: - + case 261: /* $@2: %empty */ { context->enterStructDeclaration((yylsp[0]), kEmptyImmutableString); } - break; - case 262: - + case 262: /* struct_specifier: STRUCT LEFT_BRACE $@2 struct_declaration_list RIGHT_BRACE */ { (yyval.interm.typeSpecifierNonArray) = context->addStructure( (yylsp[-4]), (yyloc), kEmptyImmutableString, (yyvsp[-1].interm.fieldList)); } - break; - case 263: - + case 263: /* struct_declaration_list: struct_declaration */ { (yyval.interm.fieldList) = context->addStructFieldList((yyvsp[0].interm.fieldList), (yylsp[0])); } - break; - case 264: - + case 264: /* struct_declaration_list: struct_declaration_list struct_declaration */ { (yyval.interm.fieldList) = context->combineStructFieldLists( (yyvsp[-1].interm.fieldList), (yyvsp[0].interm.fieldList), (yylsp[0])); } - break; - case 265: - + case 265: /* struct_declaration: type_specifier struct_declarator_list SEMICOLON */ { (yyval.interm.fieldList) = context->addStructDeclaratorList( (yyvsp[-2].interm.type), (yyvsp[-1].interm.declaratorList)); } - break; - case 266: - + case 266: /* struct_declaration: type_qualifier type_specifier struct_declarator_list + SEMICOLON */ { // ES3 Only, but errors should be handled elsewhere (yyval.interm.fieldList) = context->addStructDeclaratorListWithQualifiers( *(yyvsp[-3].interm.typeQualifierBuilder), &(yyvsp[-2].interm.type), (yyvsp[-1].interm.declaratorList)); } - break; - case 267: - + case 267: /* struct_declarator_list: struct_declarator */ { (yyval.interm.declaratorList) = new TDeclaratorList(); (yyval.interm.declaratorList)->push_back((yyvsp[0].interm.declarator)); } - break; - case 268: - + case 268: /* struct_declarator_list: struct_declarator_list COMMA struct_declarator */ { (yyval.interm.declaratorList)->push_back((yyvsp[0].interm.declarator)); } - break; - case 269: - + case 269: /* struct_declarator: identifier */ { (yyval.interm.declarator) = context->parseStructDeclarator(ImmutableString((yyvsp[0].lex).string), (yylsp[0])); } - break; - case 270: - + case 270: /* struct_declarator: identifier array_specifier */ { (yyval.interm.declarator) = context->parseStructArrayDeclarator( ImmutableString((yyvsp[-1].lex).string), (yylsp[-1]), (yyvsp[0].interm.arraySizes)); } - break; - case 271: - + case 271: /* initializer: assignment_expression */ { (yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode); } - break; - case 272: - + case 272: /* declaration_statement: declaration */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 273: - + case 273: /* statement: compound_statement_with_scope */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermBlock); } - break; - case 274: - + case 274: /* statement: simple_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 275: - + case 275: /* simple_statement: declaration_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 276: - + case 276: /* simple_statement: expression_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 277: - + case 277: /* simple_statement: selection_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 278: - + case 278: /* simple_statement: switch_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermSwitch); } - break; - case 279: - + case 279: /* simple_statement: case_label */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermCase); } - break; - case 280: - + case 280: /* simple_statement: iteration_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 281: - + case 281: /* simple_statement: jump_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 282: - + case 282: /* compound_statement_with_scope: LEFT_BRACE RIGHT_BRACE */ { (yyval.interm.intermBlock) = new TIntermBlock(); (yyval.interm.intermBlock)->setLine((yyloc)); } - break; - case 283: - + case 283: /* $@3: %empty */ { context->symbolTable.push(); } - break; - case 284: - + case 284: /* $@4: %empty */ { context->symbolTable.pop(); } - break; - case 285: - + case 285: /* compound_statement_with_scope: LEFT_BRACE $@3 statement_list $@4 RIGHT_BRACE */ { (yyvsp[-2].interm.intermBlock)->setLine((yyloc)); (yyval.interm.intermBlock) = (yyvsp[-2].interm.intermBlock); } - break; - case 286: - + case 286: /* statement_no_new_scope: compound_statement_no_new_scope */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermBlock); } - break; - case 287: - + case 287: /* statement_no_new_scope: simple_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 288: - + case 288: /* $@5: %empty */ { context->symbolTable.push(); } - break; - case 289: - + case 289: /* statement_with_scope: $@5 compound_statement_no_new_scope */ { context->symbolTable.pop(); (yyval.interm.intermNode) = (yyvsp[0].interm.intermBlock); } - break; - case 290: - + case 290: /* $@6: %empty */ { context->symbolTable.push(); } - break; - case 291: - + case 291: /* statement_with_scope: $@6 simple_statement */ { context->symbolTable.pop(); (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 292: - + case 292: /* compound_statement_no_new_scope: LEFT_BRACE RIGHT_BRACE */ { (yyval.interm.intermBlock) = new TIntermBlock(); (yyval.interm.intermBlock)->setLine((yyloc)); } - break; - case 293: - + case 293: /* compound_statement_no_new_scope: LEFT_BRACE statement_list RIGHT_BRACE */ { (yyvsp[-1].interm.intermBlock)->setLine((yyloc)); (yyval.interm.intermBlock) = (yyvsp[-1].interm.intermBlock); } - break; - case 294: - + case 294: /* statement_list: statement */ { (yyval.interm.intermBlock) = new TIntermBlock(); context->appendStatement((yyval.interm.intermBlock), (yyvsp[0].interm.intermNode)); } - break; - case 295: - + case 295: /* statement_list: statement_list statement */ { (yyval.interm.intermBlock) = (yyvsp[-1].interm.intermBlock); context->appendStatement((yyval.interm.intermBlock), (yyvsp[0].interm.intermNode)); } - break; - case 296: - + case 296: /* expression_statement: SEMICOLON */ { (yyval.interm.intermNode) = context->addEmptyStatement((yyloc)); } - break; - case 297: - + case 297: /* expression_statement: expression SEMICOLON */ { (yyval.interm.intermNode) = (yyvsp[-1].interm.intermTypedNode); } - break; - case 298: - + case 298: /* selection_statement: IF LEFT_PAREN expression RIGHT_PAREN + selection_rest_statement */ { (yyval.interm.intermNode) = context->addIfElse((yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.nodePair), (yylsp[-4])); } - break; - case 299: - + case 299: /* selection_rest_statement: statement_with_scope ELSE statement_with_scope */ { (yyval.interm.nodePair).node1 = (yyvsp[-2].interm.intermNode); (yyval.interm.nodePair).node2 = (yyvsp[0].interm.intermNode); } - break; - case 300: - + case 300: /* selection_rest_statement: statement_with_scope */ { (yyval.interm.nodePair).node1 = (yyvsp[0].interm.intermNode); (yyval.interm.nodePair).node2 = nullptr; } - break; - case 301: - + case 301: /* $@7: %empty */ { context->incrSwitchNestingLevel(); } - break; - case 302: - + case 302: /* switch_statement: SWITCH LEFT_PAREN expression RIGHT_PAREN $@7 + compound_statement_with_scope */ { (yyval.interm.intermSwitch) = context->addSwitch( (yyvsp[-3].interm.intermTypedNode), (yyvsp[0].interm.intermBlock), (yylsp[-5])); context->decrSwitchNestingLevel(); } - break; - case 303: - + case 303: /* case_label: CASE constant_expression COLON */ { (yyval.interm.intermCase) = context->addCase((yyvsp[-1].interm.intermTypedNode), (yylsp[-2])); } - break; - case 304: - + case 304: /* case_label: DEFAULT COLON */ { (yyval.interm.intermCase) = context->addDefault((yylsp[-1])); } - break; - case 305: - + case 305: /* condition: expression */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermTypedNode); context->checkIsScalarBool((yyvsp[0].interm.intermTypedNode)->getLine(), (yyvsp[0].interm.intermTypedNode)); } - break; - case 306: - + case 306: /* condition: fully_specified_type identifier EQUAL initializer */ { (yyval.interm.intermNode) = context->addConditionInitializer( (yyvsp[-3].interm.type), ImmutableString((yyvsp[-2].lex).string), (yyvsp[0].interm.intermTypedNode), (yylsp[-2])); } - break; - case 307: - + case 307: /* $@8: %empty */ { context->symbolTable.push(); context->incrLoopNestingLevel(); } - break; - case 308: - + case 308: /* iteration_statement: WHILE LEFT_PAREN $@8 condition RIGHT_PAREN + statement_no_new_scope */ { context->symbolTable.pop(); (yyval.interm.intermNode) = @@ -5273,39 +4569,33 @@ yyreduce: (yyvsp[0].interm.intermNode), (yylsp[-5])); context->decrLoopNestingLevel(); } - break; - case 309: - + case 309: /* $@9: %empty */ { context->incrLoopNestingLevel(); } - break; - case 310: - + case 310: /* iteration_statement: DO $@9 statement_with_scope WHILE LEFT_PAREN expression + RIGHT_PAREN SEMICOLON */ { (yyval.interm.intermNode) = context->addLoop(ELoopDoWhile, 0, (yyvsp[-2].interm.intermTypedNode), 0, (yyvsp[-5].interm.intermNode), (yylsp[-4])); context->decrLoopNestingLevel(); } - break; - case 311: - + case 311: /* $@10: %empty */ { context->symbolTable.push(); context->incrLoopNestingLevel(); } - break; - case 312: - + case 312: /* iteration_statement: FOR LEFT_PAREN $@10 for_init_statement for_rest_statement + RIGHT_PAREN statement_no_new_scope */ { context->symbolTable.pop(); (yyval.interm.intermNode) = context->addLoop( @@ -5314,152 +4604,117 @@ yyreduce: (yyvsp[0].interm.intermNode), (yylsp[-6])); context->decrLoopNestingLevel(); } - break; - case 313: - + case 313: /* for_init_statement: expression_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 314: - + case 314: /* for_init_statement: declaration_statement */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 315: - + case 315: /* conditionopt: condition */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 316: - + case 316: /* conditionopt: %empty */ { (yyval.interm.intermNode) = nullptr; } - break; - case 317: - + case 317: /* for_rest_statement: conditionopt SEMICOLON */ { (yyval.interm.nodePair).node1 = (yyvsp[-1].interm.intermNode); (yyval.interm.nodePair).node2 = 0; } - break; - case 318: - + case 318: /* for_rest_statement: conditionopt SEMICOLON expression */ { (yyval.interm.nodePair).node1 = (yyvsp[-2].interm.intermNode); (yyval.interm.nodePair).node2 = (yyvsp[0].interm.intermTypedNode); } - break; - case 319: - + case 319: /* jump_statement: CONTINUE SEMICOLON */ { (yyval.interm.intermNode) = context->addBranch(EOpContinue, (yylsp[-1])); } - break; - case 320: - + case 320: /* jump_statement: BREAK SEMICOLON */ { (yyval.interm.intermNode) = context->addBranch(EOpBreak, (yylsp[-1])); } - break; - case 321: - + case 321: /* jump_statement: RETURN SEMICOLON */ { (yyval.interm.intermNode) = context->addBranch(EOpReturn, (yylsp[-1])); } - break; - case 322: - + case 322: /* jump_statement: RETURN expression SEMICOLON */ { (yyval.interm.intermNode) = context->addBranch(EOpReturn, (yyvsp[-1].interm.intermTypedNode), (yylsp[-2])); } - break; - case 323: - + case 323: /* jump_statement: DISCARD SEMICOLON */ { (yyval.interm.intermNode) = context->addBranch(EOpKill, (yylsp[-1])); } - break; - case 324: - + case 324: /* translation_unit: external_declaration */ { (yyval.interm.intermBlock) = new TIntermBlock(); (yyval.interm.intermBlock)->setLine((yyloc)); (yyval.interm.intermBlock)->appendStatement((yyvsp[0].interm.intermNode)); context->setTreeRoot((yyval.interm.intermBlock)); } - break; - case 325: - + case 325: /* translation_unit: translation_unit external_declaration */ { (yyval.interm.intermBlock)->appendStatement((yyvsp[0].interm.intermNode)); } - break; - case 326: - + case 326: /* external_declaration: function_definition */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 327: - + case 327: /* external_declaration: declaration */ { (yyval.interm.intermNode) = (yyvsp[0].interm.intermNode); } - break; - case 328: - + case 328: /* $@11: %empty */ { context->parseFunctionDefinitionHeader((yylsp[0]), (yyvsp[0].interm).function, &((yyvsp[0].interm).intermFunctionPrototype)); } - break; - case 329: - + case 329: /* function_definition: function_prototype $@11 compound_statement_no_new_scope */ { (yyval.interm.intermNode) = context->addFunctionDefinition((yyvsp[-2].interm).intermFunctionPrototype, (yyvsp[0].interm.intermBlock), (yylsp[-2])); } - break; default: @@ -5476,11 +4731,10 @@ yyreduce: case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT("-> $$ =", YY_CAST(yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT(yyss, yyssp); *++yyvsp = yyval; *++yylsp = yyloc; @@ -5503,49 +4757,15 @@ yyreduce: yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE(yychar); - + yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE(yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if !YYERROR_VERBOSE yyerror(&yylloc, context, scanner, YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error(&yymsg_alloc, &yymsg, yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE(yymsg); - yymsg = (char *)YYSTACK_ALLOC(yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror(&yylloc, context, scanner, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif } yyerror_range[1] = yylloc; - if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an @@ -5576,6 +4796,7 @@ yyerrorlab: label yyerrorlab therefore never appears in user code. */ if (0) YYERROR; + ++yynerrs; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -5591,13 +4812,14 @@ yyerrorlab: yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default(yyn)) { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) { yyn = yytable[yyn]; if (0 < yyn) @@ -5610,7 +4832,7 @@ yyerrlab1: YYABORT; yyerror_range[1] = *yylsp; - yydestruct("Error: popping", yystos[yystate], yyvsp, yylsp, context, scanner); + yydestruct("Error: popping", YY_ACCESSING_SYMBOL(yystate), yyvsp, yylsp, context, scanner); YYPOPSTACK(1); yystate = *yyssp; YY_STACK_PRINT(yyss, yyssp); @@ -5621,13 +4843,11 @@ yyerrlab1: YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; - /* Using YYLLOC is tempting, but would change the location of - the lookahead. YYLOC is available though. */ - YYLLOC_DEFAULT(yyloc, yyerror_range, 2); - *++yylsp = yyloc; + ++yylsp; + YYLLOC_DEFAULT(*yylsp, yyerror_range, 2); /* Shift the error token. */ - YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT("Shifting", YY_ACCESSING_SYMBOL(yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -5637,29 +4857,27 @@ yyerrlab1: `-------------------------------------*/ yyacceptlab: yyresult = 0; - goto yyreturn; + goto yyreturnlab; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; - goto yyreturn; + goto yyreturnlab; -#if !defined yyoverflow || YYERROR_VERBOSE -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ yyexhaustedlab: yyerror(&yylloc, context, scanner, YY_("memory exhausted")); yyresult = 2; - /* Fall through. */ -#endif + goto yyreturnlab; -/*-----------------------------------------------------. -| yyreturn -- parsing is finished, return the result. | -`-----------------------------------------------------*/ -yyreturn: +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at @@ -5673,17 +4891,15 @@ yyreturn: YY_STACK_PRINT(yyss, yyssp); while (yyssp != yyss) { - yydestruct("Cleanup: popping", yystos[*yyssp], yyvsp, yylsp, context, scanner); + yydestruct("Cleanup: popping", YY_ACCESSING_SYMBOL(+*yyssp), yyvsp, yylsp, context, + scanner); YYPOPSTACK(1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE(yyss); #endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE(yymsg); -#endif + return yyresult; } diff --git a/src/compiler/translator/glslang_tab_autogen.h b/src/compiler/translator/glslang_tab_autogen.h index fc8e7979a..d5a48edd4 100644 --- a/src/compiler/translator/glslang_tab_autogen.h +++ b/src/compiler/translator/glslang_tab_autogen.h @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.3.2. */ +/* A Bison parser, made by GNU Bison 3.8.2. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -31,8 +31,9 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ #ifndef YY_YY_GLSLANG_TAB_AUTOGEN_H_INCLUDED #define YY_YY_GLSLANG_TAB_AUTOGEN_H_INCLUDED @@ -49,199 +50,203 @@ extern int yydebug; #define YYLTYPE_IS_DECLARED 1 #define YYLTYPE_IS_TRIVIAL 1 -/* Token type. */ +/* Token kinds. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { - INVARIANT = 258, - PRECISE = 259, - HIGH_PRECISION = 260, - MEDIUM_PRECISION = 261, - LOW_PRECISION = 262, - PRECISION = 263, - ATTRIBUTE = 264, - CONST_QUAL = 265, - BOOL_TYPE = 266, - FLOAT_TYPE = 267, - INT_TYPE = 268, - UINT_TYPE = 269, - BREAK = 270, - CONTINUE = 271, - DO = 272, - ELSE = 273, - FOR = 274, - IF = 275, - DISCARD = 276, - RETURN = 277, - SWITCH = 278, - CASE = 279, - DEFAULT = 280, - BVEC2 = 281, - BVEC3 = 282, - BVEC4 = 283, - IVEC2 = 284, - IVEC3 = 285, - IVEC4 = 286, - VEC2 = 287, - VEC3 = 288, - VEC4 = 289, - UVEC2 = 290, - UVEC3 = 291, - UVEC4 = 292, - MATRIX2 = 293, - MATRIX3 = 294, - MATRIX4 = 295, - IN_QUAL = 296, - OUT_QUAL = 297, - INOUT_QUAL = 298, - UNIFORM = 299, - BUFFER = 300, - VARYING = 301, - MATRIX2x3 = 302, - MATRIX3x2 = 303, - MATRIX2x4 = 304, - MATRIX4x2 = 305, - MATRIX3x4 = 306, - MATRIX4x3 = 307, - SAMPLE = 308, - CENTROID = 309, - FLAT = 310, - SMOOTH = 311, - NOPERSPECTIVE = 312, - PATCH = 313, - READONLY = 314, - WRITEONLY = 315, - COHERENT = 316, - RESTRICT = 317, - VOLATILE = 318, - SHARED = 319, - STRUCT = 320, - VOID_TYPE = 321, - WHILE = 322, - SAMPLER2D = 323, - SAMPLERCUBE = 324, - SAMPLER_EXTERNAL_OES = 325, - SAMPLER2DRECT = 326, - SAMPLER2DARRAY = 327, - ISAMPLER2D = 328, - ISAMPLER3D = 329, - ISAMPLERCUBE = 330, - ISAMPLER2DARRAY = 331, - USAMPLER2D = 332, - USAMPLER3D = 333, - USAMPLERCUBE = 334, - USAMPLER2DARRAY = 335, - SAMPLER2DMS = 336, - ISAMPLER2DMS = 337, - USAMPLER2DMS = 338, - SAMPLER2DMSARRAY = 339, - ISAMPLER2DMSARRAY = 340, - USAMPLER2DMSARRAY = 341, - SAMPLER3D = 342, - SAMPLER3DRECT = 343, - SAMPLER2DSHADOW = 344, - SAMPLERCUBESHADOW = 345, - SAMPLER2DARRAYSHADOW = 346, - SAMPLERVIDEOWEBGL = 347, - SAMPLERCUBEARRAYOES = 348, - SAMPLERCUBEARRAYSHADOWOES = 349, - ISAMPLERCUBEARRAYOES = 350, - USAMPLERCUBEARRAYOES = 351, - SAMPLERCUBEARRAYEXT = 352, - SAMPLERCUBEARRAYSHADOWEXT = 353, - ISAMPLERCUBEARRAYEXT = 354, - USAMPLERCUBEARRAYEXT = 355, - SAMPLERBUFFER = 356, - ISAMPLERBUFFER = 357, - USAMPLERBUFFER = 358, - SAMPLEREXTERNAL2DY2YEXT = 359, - IMAGE2D = 360, - IIMAGE2D = 361, - UIMAGE2D = 362, - IMAGE3D = 363, - IIMAGE3D = 364, - UIMAGE3D = 365, - IMAGE2DARRAY = 366, - IIMAGE2DARRAY = 367, - UIMAGE2DARRAY = 368, - IMAGECUBE = 369, - IIMAGECUBE = 370, - UIMAGECUBE = 371, - IMAGECUBEARRAYOES = 372, - IIMAGECUBEARRAYOES = 373, - UIMAGECUBEARRAYOES = 374, - IMAGECUBEARRAYEXT = 375, - IIMAGECUBEARRAYEXT = 376, - UIMAGECUBEARRAYEXT = 377, - IMAGEBUFFER = 378, - IIMAGEBUFFER = 379, - UIMAGEBUFFER = 380, - ATOMICUINT = 381, - PIXELLOCALANGLE = 382, - IPIXELLOCALANGLE = 383, - UPIXELLOCALANGLE = 384, - LAYOUT = 385, - YUVCSCSTANDARDEXT = 386, - YUVCSCSTANDARDEXTCONSTANT = 387, - IDENTIFIER = 388, - TYPE_NAME = 389, - FLOATCONSTANT = 390, - INTCONSTANT = 391, - UINTCONSTANT = 392, - BOOLCONSTANT = 393, - FIELD_SELECTION = 394, - LEFT_OP = 395, - RIGHT_OP = 396, - INC_OP = 397, - DEC_OP = 398, - LE_OP = 399, - GE_OP = 400, - EQ_OP = 401, - NE_OP = 402, - AND_OP = 403, - OR_OP = 404, - XOR_OP = 405, - MUL_ASSIGN = 406, - DIV_ASSIGN = 407, - ADD_ASSIGN = 408, - MOD_ASSIGN = 409, - LEFT_ASSIGN = 410, - RIGHT_ASSIGN = 411, - AND_ASSIGN = 412, - XOR_ASSIGN = 413, - OR_ASSIGN = 414, - SUB_ASSIGN = 415, - LEFT_PAREN = 416, - RIGHT_PAREN = 417, - LEFT_BRACKET = 418, - RIGHT_BRACKET = 419, - LEFT_BRACE = 420, - RIGHT_BRACE = 421, - DOT = 422, - COMMA = 423, - COLON = 424, - EQUAL = 425, - SEMICOLON = 426, - BANG = 427, - DASH = 428, - TILDE = 429, - PLUS = 430, - STAR = 431, - SLASH = 432, - PERCENT = 433, - LEFT_ANGLE = 434, - RIGHT_ANGLE = 435, - VERTICAL_BAR = 436, - CARET = 437, - AMPERSAND = 438, - QUESTION = 439 + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + INVARIANT = 258, /* INVARIANT */ + PRECISE = 259, /* PRECISE */ + HIGH_PRECISION = 260, /* HIGH_PRECISION */ + MEDIUM_PRECISION = 261, /* MEDIUM_PRECISION */ + LOW_PRECISION = 262, /* LOW_PRECISION */ + PRECISION = 263, /* PRECISION */ + ATTRIBUTE = 264, /* ATTRIBUTE */ + CONST_QUAL = 265, /* CONST_QUAL */ + BOOL_TYPE = 266, /* BOOL_TYPE */ + FLOAT_TYPE = 267, /* FLOAT_TYPE */ + INT_TYPE = 268, /* INT_TYPE */ + UINT_TYPE = 269, /* UINT_TYPE */ + BREAK = 270, /* BREAK */ + CONTINUE = 271, /* CONTINUE */ + DO = 272, /* DO */ + ELSE = 273, /* ELSE */ + FOR = 274, /* FOR */ + IF = 275, /* IF */ + DISCARD = 276, /* DISCARD */ + RETURN = 277, /* RETURN */ + SWITCH = 278, /* SWITCH */ + CASE = 279, /* CASE */ + DEFAULT = 280, /* DEFAULT */ + BVEC2 = 281, /* BVEC2 */ + BVEC3 = 282, /* BVEC3 */ + BVEC4 = 283, /* BVEC4 */ + IVEC2 = 284, /* IVEC2 */ + IVEC3 = 285, /* IVEC3 */ + IVEC4 = 286, /* IVEC4 */ + VEC2 = 287, /* VEC2 */ + VEC3 = 288, /* VEC3 */ + VEC4 = 289, /* VEC4 */ + UVEC2 = 290, /* UVEC2 */ + UVEC3 = 291, /* UVEC3 */ + UVEC4 = 292, /* UVEC4 */ + MATRIX2 = 293, /* MATRIX2 */ + MATRIX3 = 294, /* MATRIX3 */ + MATRIX4 = 295, /* MATRIX4 */ + IN_QUAL = 296, /* IN_QUAL */ + OUT_QUAL = 297, /* OUT_QUAL */ + INOUT_QUAL = 298, /* INOUT_QUAL */ + UNIFORM = 299, /* UNIFORM */ + BUFFER = 300, /* BUFFER */ + VARYING = 301, /* VARYING */ + MATRIX2x3 = 302, /* MATRIX2x3 */ + MATRIX3x2 = 303, /* MATRIX3x2 */ + MATRIX2x4 = 304, /* MATRIX2x4 */ + MATRIX4x2 = 305, /* MATRIX4x2 */ + MATRIX3x4 = 306, /* MATRIX3x4 */ + MATRIX4x3 = 307, /* MATRIX4x3 */ + SAMPLE = 308, /* SAMPLE */ + CENTROID = 309, /* CENTROID */ + FLAT = 310, /* FLAT */ + SMOOTH = 311, /* SMOOTH */ + NOPERSPECTIVE = 312, /* NOPERSPECTIVE */ + PATCH = 313, /* PATCH */ + READONLY = 314, /* READONLY */ + WRITEONLY = 315, /* WRITEONLY */ + COHERENT = 316, /* COHERENT */ + RESTRICT = 317, /* RESTRICT */ + VOLATILE = 318, /* VOLATILE */ + SHARED = 319, /* SHARED */ + STRUCT = 320, /* STRUCT */ + VOID_TYPE = 321, /* VOID_TYPE */ + WHILE = 322, /* WHILE */ + SAMPLER2D = 323, /* SAMPLER2D */ + SAMPLERCUBE = 324, /* SAMPLERCUBE */ + SAMPLER_EXTERNAL_OES = 325, /* SAMPLER_EXTERNAL_OES */ + SAMPLER2DRECT = 326, /* SAMPLER2DRECT */ + SAMPLER2DARRAY = 327, /* SAMPLER2DARRAY */ + ISAMPLER2D = 328, /* ISAMPLER2D */ + ISAMPLER3D = 329, /* ISAMPLER3D */ + ISAMPLERCUBE = 330, /* ISAMPLERCUBE */ + ISAMPLER2DARRAY = 331, /* ISAMPLER2DARRAY */ + USAMPLER2D = 332, /* USAMPLER2D */ + USAMPLER3D = 333, /* USAMPLER3D */ + USAMPLERCUBE = 334, /* USAMPLERCUBE */ + USAMPLER2DARRAY = 335, /* USAMPLER2DARRAY */ + SAMPLER2DMS = 336, /* SAMPLER2DMS */ + ISAMPLER2DMS = 337, /* ISAMPLER2DMS */ + USAMPLER2DMS = 338, /* USAMPLER2DMS */ + SAMPLER2DMSARRAY = 339, /* SAMPLER2DMSARRAY */ + ISAMPLER2DMSARRAY = 340, /* ISAMPLER2DMSARRAY */ + USAMPLER2DMSARRAY = 341, /* USAMPLER2DMSARRAY */ + SAMPLER3D = 342, /* SAMPLER3D */ + SAMPLER3DRECT = 343, /* SAMPLER3DRECT */ + SAMPLER2DSHADOW = 344, /* SAMPLER2DSHADOW */ + SAMPLERCUBESHADOW = 345, /* SAMPLERCUBESHADOW */ + SAMPLER2DARRAYSHADOW = 346, /* SAMPLER2DARRAYSHADOW */ + SAMPLERVIDEOWEBGL = 347, /* SAMPLERVIDEOWEBGL */ + SAMPLERCUBEARRAYOES = 348, /* SAMPLERCUBEARRAYOES */ + SAMPLERCUBEARRAYSHADOWOES = 349, /* SAMPLERCUBEARRAYSHADOWOES */ + ISAMPLERCUBEARRAYOES = 350, /* ISAMPLERCUBEARRAYOES */ + USAMPLERCUBEARRAYOES = 351, /* USAMPLERCUBEARRAYOES */ + SAMPLERCUBEARRAYEXT = 352, /* SAMPLERCUBEARRAYEXT */ + SAMPLERCUBEARRAYSHADOWEXT = 353, /* SAMPLERCUBEARRAYSHADOWEXT */ + ISAMPLERCUBEARRAYEXT = 354, /* ISAMPLERCUBEARRAYEXT */ + USAMPLERCUBEARRAYEXT = 355, /* USAMPLERCUBEARRAYEXT */ + SAMPLERBUFFER = 356, /* SAMPLERBUFFER */ + ISAMPLERBUFFER = 357, /* ISAMPLERBUFFER */ + USAMPLERBUFFER = 358, /* USAMPLERBUFFER */ + SAMPLEREXTERNAL2DY2YEXT = 359, /* SAMPLEREXTERNAL2DY2YEXT */ + IMAGE2D = 360, /* IMAGE2D */ + IIMAGE2D = 361, /* IIMAGE2D */ + UIMAGE2D = 362, /* UIMAGE2D */ + IMAGE3D = 363, /* IMAGE3D */ + IIMAGE3D = 364, /* IIMAGE3D */ + UIMAGE3D = 365, /* UIMAGE3D */ + IMAGE2DARRAY = 366, /* IMAGE2DARRAY */ + IIMAGE2DARRAY = 367, /* IIMAGE2DARRAY */ + UIMAGE2DARRAY = 368, /* UIMAGE2DARRAY */ + IMAGECUBE = 369, /* IMAGECUBE */ + IIMAGECUBE = 370, /* IIMAGECUBE */ + UIMAGECUBE = 371, /* UIMAGECUBE */ + IMAGECUBEARRAYOES = 372, /* IMAGECUBEARRAYOES */ + IIMAGECUBEARRAYOES = 373, /* IIMAGECUBEARRAYOES */ + UIMAGECUBEARRAYOES = 374, /* UIMAGECUBEARRAYOES */ + IMAGECUBEARRAYEXT = 375, /* IMAGECUBEARRAYEXT */ + IIMAGECUBEARRAYEXT = 376, /* IIMAGECUBEARRAYEXT */ + UIMAGECUBEARRAYEXT = 377, /* UIMAGECUBEARRAYEXT */ + IMAGEBUFFER = 378, /* IMAGEBUFFER */ + IIMAGEBUFFER = 379, /* IIMAGEBUFFER */ + UIMAGEBUFFER = 380, /* UIMAGEBUFFER */ + ATOMICUINT = 381, /* ATOMICUINT */ + PIXELLOCALANGLE = 382, /* PIXELLOCALANGLE */ + IPIXELLOCALANGLE = 383, /* IPIXELLOCALANGLE */ + UPIXELLOCALANGLE = 384, /* UPIXELLOCALANGLE */ + LAYOUT = 385, /* LAYOUT */ + YUVCSCSTANDARDEXT = 386, /* YUVCSCSTANDARDEXT */ + YUVCSCSTANDARDEXTCONSTANT = 387, /* YUVCSCSTANDARDEXTCONSTANT */ + IDENTIFIER = 388, /* IDENTIFIER */ + TYPE_NAME = 389, /* TYPE_NAME */ + FLOATCONSTANT = 390, /* FLOATCONSTANT */ + INTCONSTANT = 391, /* INTCONSTANT */ + UINTCONSTANT = 392, /* UINTCONSTANT */ + BOOLCONSTANT = 393, /* BOOLCONSTANT */ + FIELD_SELECTION = 394, /* FIELD_SELECTION */ + LEFT_OP = 395, /* LEFT_OP */ + RIGHT_OP = 396, /* RIGHT_OP */ + INC_OP = 397, /* INC_OP */ + DEC_OP = 398, /* DEC_OP */ + LE_OP = 399, /* LE_OP */ + GE_OP = 400, /* GE_OP */ + EQ_OP = 401, /* EQ_OP */ + NE_OP = 402, /* NE_OP */ + AND_OP = 403, /* AND_OP */ + OR_OP = 404, /* OR_OP */ + XOR_OP = 405, /* XOR_OP */ + MUL_ASSIGN = 406, /* MUL_ASSIGN */ + DIV_ASSIGN = 407, /* DIV_ASSIGN */ + ADD_ASSIGN = 408, /* ADD_ASSIGN */ + MOD_ASSIGN = 409, /* MOD_ASSIGN */ + LEFT_ASSIGN = 410, /* LEFT_ASSIGN */ + RIGHT_ASSIGN = 411, /* RIGHT_ASSIGN */ + AND_ASSIGN = 412, /* AND_ASSIGN */ + XOR_ASSIGN = 413, /* XOR_ASSIGN */ + OR_ASSIGN = 414, /* OR_ASSIGN */ + SUB_ASSIGN = 415, /* SUB_ASSIGN */ + LEFT_PAREN = 416, /* LEFT_PAREN */ + RIGHT_PAREN = 417, /* RIGHT_PAREN */ + LEFT_BRACKET = 418, /* LEFT_BRACKET */ + RIGHT_BRACKET = 419, /* RIGHT_BRACKET */ + LEFT_BRACE = 420, /* LEFT_BRACE */ + RIGHT_BRACE = 421, /* RIGHT_BRACE */ + DOT = 422, /* DOT */ + COMMA = 423, /* COMMA */ + COLON = 424, /* COLON */ + EQUAL = 425, /* EQUAL */ + SEMICOLON = 426, /* SEMICOLON */ + BANG = 427, /* BANG */ + DASH = 428, /* DASH */ + TILDE = 429, /* TILDE */ + PLUS = 430, /* PLUS */ + STAR = 431, /* STAR */ + SLASH = 432, /* SLASH */ + PERCENT = 433, /* PERCENT */ + LEFT_ANGLE = 434, /* LEFT_ANGLE */ + RIGHT_ANGLE = 435, /* RIGHT_ANGLE */ + VERTICAL_BAR = 436, /* VERTICAL_BAR */ + CARET = 437, /* CARET */ + AMPERSAND = 438, /* AMPERSAND */ + QUESTION = 439 /* QUESTION */ }; +typedef enum yytokentype yytoken_kind_t; #endif /* Value type. */ #if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED - union YYSTYPE { @@ -291,7 +296,6 @@ union YYSTYPE }; } interm; }; - typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 diff --git a/tools/angle_tools.py b/tools/angle_tools.py index 857d0b282..de606cbaa 100644 --- a/tools/angle_tools.py +++ b/tools/angle_tools.py @@ -33,7 +33,9 @@ def get_exe_name(file_name, windows_extension): def upload_to_google_storage(bucket, files): - upload_script = find_file_in_path('upload_to_google_storage.py') + file_dir = os.path.dirname(os.path.realpath(__file__)) + upload_script = os.path.join(file_dir, '..', 'third_party', 'depot_tools', + 'upload_to_google_storage.py') upload_args = ['python', upload_script, '-b', bucket] + files return subprocess.call(upload_args) == 0 diff --git a/tools/flex-bison/README.md b/tools/flex-bison/README.md index 8dfe12626..fc5979751 100644 --- a/tools/flex-bison/README.md +++ b/tools/flex-bison/README.md @@ -11,10 +11,11 @@ review process. You will also want to run [`scripts/run_code_generation.py`](../../scripts/run_code_generation.py) to update the generated files. -Please update both Windows and Linux binaries at the same time. Use two CLs. One -for each platform. Note that we don't currently support Mac for generating the -lexer and parser files. If we do we should add a flex/bison download for Mac as -well. +Please update both Windows and Linux binaries at the same time. Start with +Windows, then merge your work into a single CL that updates both binaries +simultaneously. Note that we don't currently support Mac for generating the +lexer and parser files. If we do we should add a flex/bison download for Mac +as well. Contact jmadill or syoussefi for any help with updating the binaries. @@ -34,7 +35,7 @@ already be installed. Install bison: $ pacman -S bison ``` -Note the versions of flex and bison so the same versions can be build on Linux. +Note the versions of flex and bison, so you can build the exact same versions on Linux. For example: ``` @@ -42,10 +43,10 @@ $ flex --version flex 2.6.4 $ bison --version -bison (GNU Bison) 3.3.2 +bison (GNU Bison) 3.8.2 ``` -The only dependencies from MSys2 should be the following: +The only dependencies outside /Windows/ from MSys2 should be the following: ``` msys-intl-8.dll @@ -79,7 +80,7 @@ Upload the binaries: ``` $ cd angle/ -$ python tools/flex-bison/update_flex_bison_binaries.py +$ py tools/flex-bison/update_flex_bison_binaries.py ``` ### On Linux @@ -99,8 +100,8 @@ $ make -j ``` # Get the source of bison -$ curl http://ftp.gnu.org/gnu/bison/bison-3.3.2.tar.xz | tar -xJ -$ cd bison-3.3.2 +$ curl http://ftp.gnu.org/gnu/bison/bison-3.8.2.tar.xz | tar -xJ +$ cd bison-3.8.2 # Build $ mkdir build && cd build $ ../configure CFLAGS="-O2" @@ -123,7 +124,7 @@ Upload the binaries: ``` $ cd angle/ -$ python tools/flex-bison/update_flex_bison_binaries.py +$ ./tools/flex-bison/update_flex_bison_binaries.py ``` [Bison]: https://www.gnu.org/software/bison/ diff --git a/tools/flex-bison/linux/bison.sha1 b/tools/flex-bison/linux/bison.sha1 index c93d92de4..67000e25f 100644 --- a/tools/flex-bison/linux/bison.sha1 +++ b/tools/flex-bison/linux/bison.sha1 @@ -1 +1 @@ -e628b73cd0a767d93e1f94b5a86ce51ca83c99d5 \ No newline at end of file +ecf11699b180eb967b8c4d08011b5704a445adeb \ No newline at end of file diff --git a/tools/flex-bison/third_party/skeletons/bison.m4 b/tools/flex-bison/third_party/skeletons/bison.m4 index e3591875c..b7bf5c5c7 100644 --- a/tools/flex-bison/third_party/skeletons/bison.m4 +++ b/tools/flex-bison/third_party/skeletons/bison.m4 @@ -2,7 +2,7 @@ # Language-independent M4 Macros for Bison. -# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation, +# Copyright (C) 2002, 2004-2015, 2018-2021 Free Software Foundation, # Inc. # This program is free software: you can redistribute it and/or modify @@ -16,7 +16,30 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . + + + +# m4_gsub(STRING, RE1, SUBST1, RE2, SUBST2, ...) +# ---------------------------------------------- +# m4 equivalent of +# +# $_ = STRING; +# s/RE1/SUBST1/g; +# s/RE2/SUBST2/g; +# ... +# +# Really similar to m4_bpatsubsts, but behaves properly with quotes. +# See m4.at's "Generating Comments". Super inelegant, but so far, I +# did not find any better solution. +m4_define([b4_gsub], +[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([[[[$1]]]], + [$2], [$3]), + [$4], [$5]), + [$6], [$7])]) + +# m4_shift2 and m4_shift3 are provided by m4sugar. +m4_define([m4_shift4], [m4_shift(m4_shift(m4_shift(m4_shift($@))))]) ## ---------------- ## @@ -26,7 +49,7 @@ # b4_generated_by # --------------- m4_define([b4_generated_by], -[b4_comment([A Bison parser, made by GNU Bison b4_version.]) +[b4_comment([A Bison parser, made by GNU Bison b4_version_string.]) ]) # b4_copyright(TITLE, [YEARS]) @@ -51,7 +74,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program. If not, see .]) +along with this program. If not, see .]) b4_comment([As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -72,8 +95,9 @@ version 2.2 of Bison.]) # ------------- # Issue a warning about private implementation details. m4_define([b4_disclaimer], -[b4_comment([Undocumented macros, especially those whose name start with YY_, -are private implementation details. Do not rely on them.]) +[b4_comment([DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, +especially those whose name start with YY_ or yy_. They are +private implementation details that can be changed or removed.]) ]) @@ -161,7 +185,7 @@ m4_define([b4_error], [b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl [m4_if([$#], [4], [], [m4_foreach([b4_arg], - m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))), + m4_dquote(m4_shift4($@)), [[@,]b4_arg])])[@)]])]) # b4_warn(FORMAT, [ARG1], [ARG2], ...) @@ -192,7 +216,7 @@ m4_define([b4_error], # @warn(1@) # @warn(1@,2@) m4_define([b4_warn], -[b4_error([[warn]], [], [], $@)]) +[b4_warn_at([], [], $@)]) # b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...) # --------------------------------------------------- @@ -210,7 +234,7 @@ m4_define([b4_warn_at], # # See b4_warn example. m4_define([b4_complain], -[b4_error([[complain]], [], [], $@)]) +[b4_complain_at([], [], $@)]) # b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...) # ------------------------------------------------------- @@ -226,8 +250,7 @@ m4_define([b4_complain_at], # # See b4_warn example. m4_define([b4_fatal], -[b4_error([[fatal]], [], [], $@)dnl -m4_exit(1)]) +[b4_fatal_at([], [], $@)]) # b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...) # ---------------------------------------------------- @@ -238,6 +261,13 @@ m4_define([b4_fatal_at], [b4_error([[fatal]], $@)dnl m4_exit(1)]) +# b4_canary(MSG) +# -------------- +# Issue a warning on stderr and in the output. Used in the test suite +# to catch spurious m4 evaluations. +m4_define([b4_canary], +[m4_errprintn([dead canary: $1])DEAD CANARY($1)]) + ## ------------ ## ## Data Types. ## @@ -309,14 +339,14 @@ number is the opposite. If YYTABLE_NINF, syntax error.]]) $1([check], [b4_check]) $1([stos], [b4_stos], - [[YYSTOS[STATE-NUM] -- The (internal number of the) accessing -symbol of state STATE-NUM.]]) + [[YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of +state STATE-NUM.]]) $1([r1], [b4_r1], - [[YYR1[YYN] -- Symbol number of symbol that rule YYN derives.]]) + [[YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.]]) $1([r2], [b4_r2], - [[YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.]]) + [[YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.]]) ]) @@ -368,8 +398,9 @@ m4_define([b4_$3_if], # b4_FLAG_if(IF-TRUE, IF-FALSE) # ----------------------------- # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise. -b4_define_flag_if([defines]) # Whether headers are requested. b4_define_flag_if([glr]) # Whether a GLR parser is requested. +b4_define_flag_if([has_translations]) # Whether some tokens are internationalized. +b4_define_flag_if([header]) # Whether a header is requested. b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. b4_define_flag_if([token_table]) # Whether yytoken_table is demanded. b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. @@ -380,43 +411,100 @@ b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. m4_define([b4_glr_cc_if], [m4_if(b4_skeleton, ["glr.cc"], $@)]) +# b4_glr2_cc_if([IF-TRUE], [IF-FALSE]) +# ------------------------------------ +m4_define([b4_glr2_cc_if], + [m4_if(b4_skeleton, ["glr2.cc"], $@)]) ## --------- ## ## Symbols. ## ## --------- ## -# For a description of the Symbol handling, see README. +# For a description of the Symbol handling, see README.md. # # The following macros provide access to symbol related values. # __b4_symbol(NUM, FIELD) # ----------------------- -# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if -# undefined. +# Fetch FIELD of symbol #NUM. Fail if undefined. m4_define([__b4_symbol], [m4_indir([b4_symbol($1, $2)])]) # _b4_symbol(NUM, FIELD) # ---------------------- -# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if -# undefined. +# Fetch FIELD of symbol #NUM (or "orig NUM", see README.md). +# Fail if undefined. m4_define([_b4_symbol], [m4_ifdef([b4_symbol($1, number)], [__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)], [__b4_symbol([$1], [$2])])]) +# b4_symbol_token_kind(NUM) +# ------------------------- +# The token kind of this symbol. +m4_define([b4_symbol_token_kind], +[b4_percent_define_get([api.token.prefix])dnl +_b4_symbol([$1], [id])]) + + +# b4_symbol_kind_base(NUM) +# ------------------------ +# Build the name of the kind of this symbol. It must always exist, +# otherwise some symbols might not be represented in the enum, which +# might be compiled into too small a type to contain all the symbol +# numbers. +m4_define([b4_symbol_prefix], [b4_percent_define_get([api.symbol.prefix])]) +m4_define([b4_symbol_kind_base], +[b4_percent_define_get([api.symbol.prefix])dnl +m4_case([$1], + [-2], [[YYEMPTY]], + [0], [[YYEOF]], + [1], [[YYerror]], + [2], [[YYUNDEF]], + [m4_case(b4_symbol([$1], [tag]), + [$accept], [[YYACCEPT]], + [b4_symbol_if([$1], [has_id], _b4_symbol([$1], [id]), + [m4_bpatsubst([$1-][]_b4_symbol([$1], [tag]), [[^a-zA-Z_0-9]+], [_])])])])]) + + +# b4_symbol_kind(NUM) +# ------------------- +# Same as b4_symbol_kind, but possibly with a prefix in some +# languages. E.g., EOF's kind_base and kind are YYSYMBOL_YYEOF in C, +# but are S_YYEMPTY and symbol_kind::S_YYEMPTY in C++. +m4_copy([b4_symbol_kind_base], [b4_symbol_kind]) + + +# b4_symbol_slot(NUM) +# ------------------- +# The name of union member that contains the value of these symbols. +# Currently, we are messy, this should actually be type_tag, but type_tag +# has several meanings. +m4_define([b4_symbol_slot], +[m4_case(b4_percent_define_get([[api.value.type]]), + [union], [b4_symbol([$1], [type_tag])], + [variant], [b4_symbol([$1], [type_tag])], + [b4_symbol([$1], [type])])]) + # b4_symbol(NUM, FIELD) # --------------------- -# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if -# undefined. If FIELD = id, prepend the token prefix. +# Fetch FIELD of symbol #NUM (or "orig NUM", or "empty"). Fail if undefined. +# +# If FIELD = id, prepend the token prefix. m4_define([b4_symbol], -[m4_case([$2], - [id], [m4_do([b4_percent_define_get([api.token.prefix])], - [_b4_symbol([$1], [id])])], - [_b4_symbol($@)])]) +[m4_if([$1], [empty], [b4_symbol([-2], [$2])], + [$1], [eof], [b4_symbol([0], [$2])], + [$1], [error], [b4_symbol([1], [$2])], + [$1], [undef], [b4_symbol([2], [$2])], + [m4_case([$2], + [id], [b4_symbol_token_kind([$1])], + [kind_base], [b4_symbol_kind_base([$1])], + [kind], [b4_symbol_kind([$1])], + [slot], [b4_symbol_slot([$1])], + [_b4_symbol($@)])])]) # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE) @@ -438,16 +526,9 @@ m4_define([b4_symbol_tag_comment], ]) -# b4_symbol_action_location(SYMBOL-NUM, KIND) -# ------------------------------------------- -# Report the location of the KIND action as FILE:LINE. -m4_define([b4_symbol_action_location], -[b4_symbol([$1], [$2_file]):b4_syncline([b4_symbol([$1], [$2_line])])]) - - -# b4_symbol_action(SYMBOL-NUM, KIND) -# ---------------------------------- -# Run the action KIND (destructor or printer) for SYMBOL-NUM. +# b4_symbol_action(SYMBOL-NUM, ACTION) +# ------------------------------------ +# Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM. m4_define([b4_symbol_action], [b4_symbol_if([$1], [has_$2], [b4_dollar_pushdef([(*yyvaluep)], @@ -455,9 +536,9 @@ m4_define([b4_symbol_action], [], [(*yylocationp)])dnl _b4_symbol_case([$1])[]dnl -b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])]) - b4_symbol([$1], [$2]) -b4_syncline([@oline@], [@ofile@]) +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl +b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl break; b4_dollar_popdef[]dnl @@ -471,21 +552,21 @@ m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])]) m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])]) -# b4_symbol_actions(KIND, [TYPE = yytype]) -# ---------------------------------------- -# Emit the symbol actions for KIND ("printer" or "destructor"). -# Dispatch on TYPE. +# b4_symbol_actions(ACTION, [KIND = yykind]) +# ------------------------------------------ +# Emit the symbol actions for ACTION ("destructor" or "printer"). +# Dispatch on KIND. m4_define([b4_symbol_actions], [m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl m4_ifval(m4_defn([b4_actions_]), -[switch (m4_default([$2], [yytype])) +[switch (m4_default([$2], [yykind])) { m4_defn([b4_actions_])[]dnl default: break; }dnl ], -[YYUSE (m4_default([$2], [yytype]));])dnl +[b4_use(m4_default([$2], [yykind]));])dnl m4_popdef([b4_actions_])dnl ]) @@ -495,7 +576,7 @@ m4_popdef([b4_actions_])dnl # easier to use with m4_map, but then, use []dnl to suppress the last # one. m4_define([_b4_symbol_case], -[case b4_symbol([$1], [number]): b4_symbol_tag_comment([$1])]) +[case b4_symbol([$1], [kind]): b4_symbol_tag_comment([$1])]) ]) @@ -515,13 +596,14 @@ m4_define([b4_symbol_map], # b4_token_visible_if(NUM, IF-TRUE, IF-FALSE) # ------------------------------------------- -# Whether NUM denotes a token that has an exported definition (i.e., -# shows in enum yytokentype). +# Whether NUM denotes a token kind that has an exported definition +# (i.e., shows in enum yytokentype). m4_define([b4_token_visible_if], [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id], [$2], [$3])], [$3])]) + # b4_token_has_definition(NUM) # ---------------------------- # 1 if NUM is visible, nothing otherwise. @@ -538,13 +620,27 @@ m4_define([b4_any_token_visible_if], # b4_token_format(FORMAT, NUM) # ---------------------------- +# If token NUM has a visible ID, format FORMAT with ID, USER_NUMBER. m4_define([b4_token_format], [b4_token_visible_if([$2], -[m4_quote(m4_format([$1], - [b4_symbol([$2], [id])], - [b4_symbol([$2], [user_number])]))])]) +[m4_format([[$1]], + b4_symbol([$2], [id]), + b4_symbol([$2], b4_api_token_raw_if([[number]], [[code]])))])]) +# b4_last_enum_token +# ------------------ +# The code of the last token visible token. +m4_define([_b4_last_enum_token], +[b4_token_visible_if([$1], + [m4_define([b4_last_enum_token], [$1])])]) +b4_symbol_foreach([_b4_last_enum_token]) + +# b4_last_symbol +# -------------- +# The code of the last symbol. +m4_define([b4_last_symbol], m4_eval(b4_tokens_number + b4_nterms_number - 1)) + ## ------- ## ## Types. ## ## ------- ## @@ -566,11 +662,11 @@ m4_define([_b4_type_action], ])]) -# b4_type_foreach(MACRO) -# ---------------------- +# b4_type_foreach(MACRO, [SEP]) +# ----------------------------- # Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set. m4_define([b4_type_foreach], - [m4_map([$1], m4_defn([b4_type_names]))]) + [m4_map_sep([$1], [$2], m4_defn([b4_type_names]))]) @@ -586,12 +682,15 @@ m4_define([b4_basename], [m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])]) -# b4_syncline(LINE, FILE) -# ----------------------- +# b4_syncline(LINE, FILE)dnl +# -------------------------- +# Should always be following by a dnl. +# +# Emit "#line LINE FILE /* __LINE__ __FILE__ */". m4_define([b4_syncline], [b4_flag_if([synclines], -[b4_sync_start([$1], [$2]) b4_sync_end([__line__], - [b4_basename(m4_quote(__file__))])[]dnl +[b4_sync_start([$1], [$2])[]dnl +b4_sync_end([__line__], [b4_basename(m4_quote(__file__))]) ])]) # b4_sync_start(LINE, FILE) @@ -603,7 +702,17 @@ m4_define([b4_sync_start], [b4_comment([$2:$1])]) # ----------------------- # Syncline for the current place, which ends. Typically a comment # left for the reader. -m4_define([b4_sync_end], [b4_comment([$2:$1])]) +m4_define([b4_sync_end], [ b4_comment([$2:$1])] +) +# This generates dependencies on the Bison skeletons hence lots of +# useless 'git diff'. This location is useless for the regular +# user (who does not care about the skeletons) and is actually not +# useful for Bison developers too (I, Akim, never used this to locate +# the code in skeletons that generated output). So disable it +# completely. If someone thinks this was actually useful, a %define +# variable should be provided to control the level of verbosity of +# '#line', in replacement of --no-lines. +m4_define([b4_sync_end]) # b4_user_code(USER-CODE) @@ -678,7 +787,7 @@ m4_define([b4_check_user_names], [m4_pushdef([b4_occurrence], b4_occurrence)dnl m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl -m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl +m4_pushdef([b4_end], m4_shift2(b4_occurrence))dnl m4_ifndef($3[(]m4_quote(b4_user_name)[)], [b4_complain_at([b4_start], [b4_end], [[%s '%s' is not used]], @@ -753,8 +862,10 @@ m4_define([b4_percent_define_get_kind], [m4_indir([b4_percent_define_kind(]$1[)])], [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) -# b4_percent_define_get_syncline(VARIABLE) -# ---------------------------------------- +# b4_percent_define_get_syncline(VARIABLE)dnl +# ------------------------------------------- +# Should always be following by a dnl. +# # Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly. # That is, if the %define variable VARIABLE is undefined, complain fatally # since that's a Bison or skeleton error. Otherwise, return its definition @@ -871,15 +982,18 @@ m4_define([b4_percent_define_flag_if], # For example: # # b4_percent_define_default([[foo]], [[default value]]) +m4_define([_b4_percent_define_define], +[m4_define([b4_percent_define(]$1[)], [$2])dnl +m4_define([b4_percent_define_kind(]$1[)], + [m4_default([$3], [keyword])])dnl +m4_define([b4_percent_define_loc(]$1[)], + [[[[:-1.-1]], + [[:-1.-1]]]])dnl +m4_define([b4_percent_define_syncline(]$1[)], [[]])]) + m4_define([b4_percent_define_default], [_b4_percent_define_ifdef([$1], [], - [m4_define([b4_percent_define(]$1[)], [$2])dnl - m4_define([b4_percent_define_kind(]$1[)], - [m4_default([$3], [keyword])])dnl - m4_define([b4_percent_define_loc(]$1[)], - [[[[:-1.-1]], - [[:-1.-1]]]])dnl - m4_define([b4_percent_define_syncline(]$1[)], [[]])])]) + [_b4_percent_define_define($@)])]) # b4_percent_define_if_define(NAME, [VARIABLE = NAME]) @@ -889,11 +1003,12 @@ m4_define([b4_percent_define_default], # to '_'. m4_define([_b4_percent_define_if_define], [m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]), - [b4_percent_define_flag_if(m4_default([$2], [$1]), - [$3], [$4])])]) + [b4_percent_define_default([m4_default([$2], [$1])], [[false]])dnl +b4_percent_define_flag_if(m4_default([$2], [$1]), + [$3], [$4])])]) + m4_define([b4_percent_define_if_define], -[b4_percent_define_default([m4_default([$2], [$1])], [[false]]) -_b4_percent_define_if_define([$1], [$2], $[1], $[2])]) +[_b4_percent_define_if_define([$1], [$2], $[1], $[2])]) # b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain]) @@ -968,10 +1083,9 @@ m4_define([b4_percent_code_get], [m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl m4_ifdef(b4_macro_name, -[b4_comment([m4_if([$#], [0], [[Unqualified %code]], - [["%code ]$1["]])[ blocks.]]) -b4_user_code([m4_indir(b4_macro_name)]) -])dnl +[b4_comment(m4_if([$#], [0], [[[Unqualified %code blocks.]]], + [[["%code ]$1[" blocks.]]])) +b4_user_code([m4_indir(b4_macro_name)])])dnl m4_popdef([b4_macro_name])]) # b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE]) @@ -995,10 +1109,12 @@ m4_define([b4_percent_code_ifdef], # b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT]) # b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT]) # ---------------------------------------------------------- +b4_percent_define_if_define([api.token.raw]) b4_percent_define_if_define([token_ctor], [api.token.constructor]) b4_percent_define_if_define([locations]) # Whether locations are tracked. b4_percent_define_if_define([parse.assert]) b4_percent_define_if_define([parse.trace]) +b4_percent_define_if_define([posix]) # b4_bison_locations_if([IF-TRUE]) @@ -1009,31 +1125,37 @@ m4_define([b4_bison_locations_if], [b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])]) -# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT]) + +# %define parse.error "(custom|detailed|simple|verbose)" # ------------------------------------------------------ -# Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and -# b4_error_verbose_flag. b4_percent_define_default([[parse.error]], [[simple]]) b4_percent_define_check_values([[[[parse.error]], - [[simple]], [[verbose]]]]) -m4_define([b4_error_verbose_flag], - [m4_case(b4_percent_define_get([[parse.error]]), - [simple], [[0]], - [verbose], [[1]])]) -b4_define_flag_if([error_verbose]) + [[custom]], [[detailed]], [[simple]], [[verbose]]]]) -# yytoken_table is needed to support verbose errors. -b4_error_verbose_if([m4_define([b4_token_table_flag], [1])]) +# b4_parse_error_case(CASE1, THEN1, CASE2, THEN2, ..., ELSE) +# ---------------------------------------------------------- +m4_define([b4_parse_error_case], +[m4_case(b4_percent_define_get([[parse.error]]), $@)]) + +# b4_parse_error_bmatch(PATTERN1, THEN1, PATTERN2, THEN2, ..., ELSE) +# ------------------------------------------------------------------ +m4_define([b4_parse_error_bmatch], +[m4_bmatch(b4_percent_define_get([[parse.error]]), $@)]) + +# b4_union_if([IF-UNION-ARE-USED], [IF-NOT]) # b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT]) # ---------------------------------------------- -b4_percent_define_if_define([variant]) +# Depend on whether api.value.type is union, or variant. +m4_define([b4_union_flag], [[0]]) m4_define([b4_variant_flag], [[0]]) b4_percent_define_ifdef([[api.value.type]], [m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword], - [m4_case(b4_percent_define_get([[api.value.type]]), [variant], - [m4_define([b4_variant_flag], [[1]])])])]) + [m4_case(b4_percent_define_get([[api.value.type]]), + [union], [m4_define([b4_union_flag], [[1]])], + [variant], [m4_define([b4_variant_flag], [[1]])])])]) +b4_define_flag_if([union]) b4_define_flag_if([variant]) @@ -1071,10 +1193,10 @@ m4_define_default([b4_location_initial_line], [1]) ## Sanity checks. ## ## --------------- ## -# api.location.prefix={...} (Java and C++). +# api.location.type={...} (C, C++ and Java). b4_percent_define_check_kind([api.location.type], [code], [deprecated]) -# api.position.prefix={...} (Java). +# api.position.type={...} (Java). b4_percent_define_check_kind([api.position.type], [code], [deprecated]) # api.prefix >< %name-prefix. @@ -1109,3 +1231,11 @@ b4_percent_define_ifdef([api.value.type], # api.value.union.name. b4_percent_define_check_kind([api.value.union.name], [keyword]) + +# parse.error (custom|detailed) >< token-table. +b4_token_table_if( +[b4_parse_error_bmatch([custom\|detailed], +[b4_complain_at(b4_percent_define_get_loc([parse.error]), + [['%s' and '%s' cannot be used together]], + [%token-table], + [%define parse.error (custom|detailed)])])]) diff --git a/tools/flex-bison/third_party/skeletons/c++-skel.m4 b/tools/flex-bison/third_party/skeletons/c++-skel.m4 new file mode 100644 index 000000000..f22002b96 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/c++-skel.m4 @@ -0,0 +1,27 @@ + -*- Autoconf -*- + +# C++ skeleton dispatching for Bison. + +# Copyright (C) 2006-2007, 2009-2015, 2018-2021 Free Software +# Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])]) +b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.cc]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/tools/flex-bison/third_party/skeletons/c++.m4 b/tools/flex-bison/third_party/skeletons/c++.m4 new file mode 100644 index 000000000..2ae8423ab --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/c++.m4 @@ -0,0 +1,778 @@ + -*- Autoconf -*- + +# C++ skeleton for Bison + +# Copyright (C) 2002-2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Sanity checks, before defaults installed by c.m4. +b4_percent_define_ifdef([[api.value.union.name]], + [b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]), + [named %union is invalid in C++])]) + +b4_percent_define_default([[api.symbol.prefix]], [[S_]]) + +m4_include(b4_skeletonsdir/[c.m4]) + +b4_percent_define_check_kind([api.namespace], [code], [deprecated]) +b4_percent_define_check_kind([api.parser.class], [code], [deprecated]) + + +## ----- ## +## C++. ## +## ----- ## + +# b4_comment(TEXT, [PREFIX]) +# -------------------------- +# Put TEXT in comment. Prefix all the output lines with PREFIX. +m4_define([b4_comment], +[_b4_comment([$1], [$2// ], [$2// ])]) + + +# b4_inline(hh|cc) +# ---------------- +# Expand to `inline\n ` if $1 is hh. +m4_define([b4_inline], +[m4_case([$1], + [cc], [], + [hh], [[inline + ]], + [m4_fatal([$0: invalid argument: $1])])]) + + +# b4_cxx_portability +# ------------------ +m4_define([b4_cxx_portability], +[#if defined __cplusplus +# define YY_CPLUSPLUS __cplusplus +#else +# define YY_CPLUSPLUS 199711L +#endif + +// Support move semantics when possible. +#if 201103L <= YY_CPLUSPLUS +# define YY_MOVE std::move +# define YY_MOVE_OR_COPY move +# define YY_MOVE_REF(Type) Type&& +# define YY_RVREF(Type) Type&& +# define YY_COPY(Type) Type +#else +# define YY_MOVE +# define YY_MOVE_OR_COPY copy +# define YY_MOVE_REF(Type) Type& +# define YY_RVREF(Type) const Type& +# define YY_COPY(Type) const Type& +#endif + +// Support noexcept when possible. +#if 201103L <= YY_CPLUSPLUS +# define YY_NOEXCEPT noexcept +# define YY_NOTHROW +#else +# define YY_NOEXCEPT +# define YY_NOTHROW throw () +#endif + +// Support constexpr when possible. +#if 201703 <= YY_CPLUSPLUS +# define YY_CONSTEXPR constexpr +#else +# define YY_CONSTEXPR +#endif[]dnl +]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +b4_percent_define_default([[api.parser.class]], [[parser]]) + +# Don't do that so that we remember whether we're using a user +# request, or the default value. +# +# b4_percent_define_default([[api.location.type]], [[location]]) + +b4_percent_define_default([[api.filename.type]], [[const std::string]]) +# Make it a warning for those who used betas of Bison 3.0. +b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix])) + +b4_percent_define_default([[define_location_comparison]], + [m4_if(b4_percent_define_get([[filename_type]]), + [std::string], [[true]], [[false]])]) + + + +## ----------- ## +## Namespace. ## +## ----------- ## + +m4_define([b4_namespace_ref], [b4_percent_define_get([[api.namespace]])]) + + +# Don't permit an empty b4_namespace_ref. Any '::parser::foo' appended to it +# would compile as an absolute reference with 'parser' in the global namespace. +# b4_namespace_open would open an anonymous namespace and thus establish +# internal linkage. This would compile. However, it's cryptic, and internal +# linkage for the parser would be specified in all translation units that +# include the header, which is always generated. If we ever need to permit +# internal linkage somehow, surely we can find a cleaner approach. +m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [], +[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), + [[namespace reference is empty]])]) + +# Instead of assuming the C++ compiler will do it, Bison should reject any +# invalid b4_namespace_ref that would be converted to a valid +# b4_namespace_open. The problem is that Bison doesn't always output +# b4_namespace_ref to uncommented code but should reserve the ability to do so +# in future releases without risking breaking any existing user grammars. +# Specifically, don't allow empty names as b4_namespace_open would just convert +# those into anonymous namespaces, and that might tempt some users. +m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [], +[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), + [[namespace reference has consecutive "::"]])]) +m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [], +[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), + [[namespace reference has a trailing "::"]])]) + +m4_define([b4_namespace_open], +[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl +[namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref), + [^\(.\)[ ]*::], [\1])), + [::], [ { namespace ])[ {]])]) + +m4_define([b4_namespace_close], +[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl +m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]), + [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*], + [\1])), + [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])]) + + +## ------------- ## +## Token kinds. ## +## ------------- ## + + +# b4_token_enums +# -------------- +# Output the definition of the token kinds. +m4_define([b4_token_enums], +[[enum token_kind_type + { + ]b4_symbol([-2], [id])[ = -2, +]b4_symbol_foreach([b4_token_enum])dnl +[ };]dnl +]) + + + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +# Defining YYEMPTY here is important: it forces the compiler +# to use a signed type, which matters for yytoken. +m4_define([b4_declare_symbol_enum], +[[enum symbol_kind_type + { + YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens. + ]b4_symbol(empty, kind_base)[ = -2, +]b4_symbol_foreach([ b4_symbol_enum])dnl +[ };]]) + + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + + +# b4_value_type_declare +# --------------------- +# Declare value_type. +m4_define([b4_value_type_declare], +[b4_value_type_setup[]dnl +[ /// Symbol semantic values. +]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), +[code], +[[ typedef ]b4_percent_define_get([[api.value.type]])[ value_type;]], +[m4_bmatch(b4_percent_define_get([[api.value.type]]), +[union\|union-directive], +[[ union value_type + { +]b4_user_union_members[ + };]])])dnl +]) + + +# b4_public_types_declare +# ----------------------- +# Define the public types: token, semantic value, location, and so forth. +# Depending on %define token_lex, may be output in the header or source file. +m4_define([b4_public_types_declare], +[b4_glr2_cc_if( +[b4_value_type_declare], +[[#ifdef ]b4_api_PREFIX[STYPE +# ifdef __GNUC__ +# pragma GCC message "bison: do not #define ]b4_api_PREFIX[STYPE in C++, use %define api.value.type" +# endif + typedef ]b4_api_PREFIX[STYPE value_type; +#else +]b4_value_type_declare[ +#endif + /// Backward compatibility (Bison 3.8). + typedef value_type semantic_type; +]])[]b4_locations_if([ + /// Symbol locations. + typedef b4_percent_define_get([[api.location.type]], + [[location]]) location_type;])[ + + /// Syntax errors thrown from user actions. + struct syntax_error : std::runtime_error + { + syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m) + : std::runtime_error (m)]b4_locations_if([ + , location (l)])[ + {} + + syntax_error (const syntax_error& s) + : std::runtime_error (s.what ())]b4_locations_if([ + , location (s.location)])[ + {} + + ~syntax_error () YY_NOEXCEPT YY_NOTHROW;]b4_locations_if([ + + location_type location;])[ + }; + + /// Token kinds. + struct token + { + ]b4_token_enums[]b4_glr2_cc_if([], [[ + /// Backward compatibility alias (Bison 3.6). + typedef token_kind_type yytokentype;]])[ + }; + + /// Token kind, as returned by yylex. + typedef token::token_kind_type token_kind_type;]b4_glr2_cc_if([], [[ + + /// Backward compatibility alias (Bison 3.6). + typedef token_kind_type token_type;]])[ + + /// Symbol kinds. + struct symbol_kind + { + ]b4_declare_symbol_enum[ + }; + + /// (Internal) symbol kind. + typedef symbol_kind::symbol_kind_type symbol_kind_type; + + /// The number of tokens. + static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS; +]]) + + +# b4_symbol_type_define +# --------------------- +# Define symbol_type, the external type for symbols used for symbol +# constructors. +m4_define([b4_symbol_type_define], +[[ /// A complete symbol. + /// + /// Expects its Base type to provide access to the symbol kind + /// via kind (). + /// + /// Provide access to semantic value]b4_locations_if([ and location])[. + template + struct basic_symbol : Base + { + /// Alias to Base. + typedef Base super_type; + + /// Default constructor. + basic_symbol () YY_NOEXCEPT + : value ()]b4_locations_if([ + , location ()])[ + {} + +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + basic_symbol (basic_symbol&& that) + : Base (std::move (that)) + , value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([ + , location (std::move (that.location))])[ + {]b4_variant_if([ + b4_symbol_variant([this->kind ()], [value], [move], + [std::move (that.value)]) + ])[} +#endif + + /// Copy constructor. + basic_symbol (const basic_symbol& that);]b4_variant_if([[ + + /// Constructors for typed symbols. +]b4_type_foreach([b4_basic_symbol_constructor_define], [ +])], [[ + /// Constructor for valueless symbols. + basic_symbol (typename Base::kind_type t]b4_locations_if([, + YY_MOVE_REF (location_type) l])[); + + /// Constructor for symbols with semantic value. + basic_symbol (typename Base::kind_type t, + YY_RVREF (value_type) v]b4_locations_if([, + YY_RVREF (location_type) l])[); +]])[ + /// Destroy the symbol. + ~basic_symbol () + { + clear (); + } + +]b4_glr2_cc_if([[ + /// Copy assignment. + basic_symbol& operator= (const basic_symbol& that) + { + Base::operator= (that);]b4_variant_if([[ + ]b4_symbol_variant([this->kind ()], [value], [copy], + [that.value])], [[ + value = that.value]])[;]b4_locations_if([[ + location = that.location;]])[ + return *this; + } + + /// Move assignment. + basic_symbol& operator= (basic_symbol&& that) + { + Base::operator= (std::move (that));]b4_variant_if([[ + ]b4_symbol_variant([this->kind ()], [value], [move], + [std::move (that.value)])], [[ + value = std::move (that.value)]])[;]b4_locations_if([[ + location = std::move (that.location);]])[ + return *this; + } +]])[ + + /// Destroy contents, and record that is empty. + void clear () YY_NOEXCEPT + {]b4_variant_if([[ + // User destructor. + symbol_kind_type yykind = this->kind (); + basic_symbol& yysym = *this; + (void) yysym; + switch (yykind) + { +]b4_symbol_foreach([b4_symbol_destructor])dnl +[ default: + break; + } + + // Value type destructor. +]b4_symbol_variant([[yykind]], [[value]], [[template destroy]])])[ + Base::clear (); + } + +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of this symbol. + const char *name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + }]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of this symbol. + const char *name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of this symbol. + std::string name () const YY_NOEXCEPT + { + return ]b4_parser_class[::symbol_name (this->kind ()); + }]])[]b4_glr2_cc_if([], [[ + + /// Backward compatibility (Bison 3.6). + symbol_kind_type type_get () const YY_NOEXCEPT;]])[ + + /// Whether empty. + bool empty () const YY_NOEXCEPT; + + /// Destructive move, \a s is emptied into this. + void move (basic_symbol& s); + + /// The semantic value. + value_type value;]b4_locations_if([ + + /// The location. + location_type location;])[ + + private: +#if YY_CPLUSPLUS < 201103L + /// Assignment operator. + basic_symbol& operator= (const basic_symbol& that); +#endif + }; + + /// Type access provider for token (enum) based symbols. + struct by_kind + { + /// The symbol kind as needed by the constructor. + typedef token_kind_type kind_type; + + /// Default constructor. + by_kind () YY_NOEXCEPT; + +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + by_kind (by_kind&& that) YY_NOEXCEPT; +#endif + + /// Copy constructor. + by_kind (const by_kind& that) YY_NOEXCEPT; + + /// Constructor from (external) token numbers. + by_kind (kind_type t) YY_NOEXCEPT; + +]b4_glr2_cc_if([[ + /// Copy assignment. + by_kind& operator= (const by_kind& that); + + /// Move assignment. + by_kind& operator= (by_kind&& that); +]])[ + + /// Record that this symbol is empty. + void clear () YY_NOEXCEPT; + + /// Steal the symbol kind from \a that. + void move (by_kind& that); + + /// The (internal) type number (corresponding to \a type). + /// \a empty when empty. + symbol_kind_type kind () const YY_NOEXCEPT;]b4_glr2_cc_if([], [[ + + /// Backward compatibility (Bison 3.6). + symbol_kind_type type_get () const YY_NOEXCEPT;]])[ + + /// The symbol kind. + /// \a ]b4_symbol_prefix[YYEMPTY when empty. + symbol_kind_type kind_; + };]b4_glr2_cc_if([], [[ + + /// Backward compatibility for a private implementation detail (Bison 3.6). + typedef by_kind by_type;]])[ + + /// "External" symbols: returned by the scanner. + struct symbol_type : basic_symbol + {]b4_variant_if([[ + /// Superclass. + typedef basic_symbol super_type; + + /// Empty symbol. + symbol_type () YY_NOEXCEPT {} + + /// Constructor for valueless symbols, and symbols from each type. +]b4_type_foreach([_b4_symbol_constructor_define])dnl + ])[}; +]]) + + +# b4_public_types_define(hh|cc) +# ----------------------------- +# Provide the implementation needed by the public types. +m4_define([b4_public_types_define], +[[ // basic_symbol. + template + ]b4_parser_class[::basic_symbol::basic_symbol (const basic_symbol& that) + : Base (that) + , value (]b4_variant_if([], [that.value]))b4_locations_if([ + , location (that.location)])[ + {]b4_variant_if([ + b4_symbol_variant([this->kind ()], [value], [copy], + [YY_MOVE (that.value)]) + ])[} + +]b4_variant_if([], [[ + /// Constructor for valueless symbols. + template + ]b4_parser_class[::basic_symbol::basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_locations_if([YY_MOVE_REF (location_type) l]))[) + : Base (t) + , value ()]b4_locations_if([ + , location (l)])[ + {} + + template + ]b4_parser_class[::basic_symbol::basic_symbol (]b4_join( + [typename Base::kind_type t], + [YY_RVREF (value_type) v], + b4_locations_if([YY_RVREF (location_type) l]))[) + : Base (t) + , value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([ + , location (YY_MOVE (l))])[ + {]b4_variant_if([[ + (void) v; + ]b4_symbol_variant([this->kind ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[ + +]b4_glr2_cc_if([], [[ + template + ]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::basic_symbol::type_get () const YY_NOEXCEPT + { + return this->kind (); + } +]])[ + + template + bool + ]b4_parser_class[::basic_symbol::empty () const YY_NOEXCEPT + { + return this->kind () == ]b4_symbol(empty, kind)[; + } + + template + void + ]b4_parser_class[::basic_symbol::move (basic_symbol& s) + { + super_type::move (s); + ]b4_variant_if([b4_symbol_variant([this->kind ()], [value], [move], + [YY_MOVE (s.value)])], + [value = YY_MOVE (s.value);])[]b4_locations_if([ + location = YY_MOVE (s.location);])[ + } + + // by_kind. + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind () YY_NOEXCEPT + : kind_ (]b4_symbol(empty, kind)[) + {} + +#if 201103L <= YY_CPLUSPLUS + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (by_kind&& that) YY_NOEXCEPT + : kind_ (that.kind_) + { + that.clear (); + } +#endif + + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (const by_kind& that) YY_NOEXCEPT + : kind_ (that.kind_) + {} + + ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (token_kind_type t) YY_NOEXCEPT + : kind_ (yytranslate_ (t)) + {} + +]b4_glr2_cc_if([[ + ]b4_inline([$1])]b4_parser_class[::by_kind& + b4_parser_class[::by_kind::by_kind::operator= (const by_kind& that) + { + kind_ = that.kind_; + return *this; + } + + ]b4_inline([$1])]b4_parser_class[::by_kind& + b4_parser_class[::by_kind::by_kind::operator= (by_kind&& that) + { + kind_ = that.kind_; + that.clear (); + return *this; + } +]])[ + + ]b4_inline([$1])[void + ]b4_parser_class[::by_kind::clear () YY_NOEXCEPT + { + kind_ = ]b4_symbol(empty, kind)[; + } + + ]b4_inline([$1])[void + ]b4_parser_class[::by_kind::move (by_kind& that) + { + kind_ = that.kind_; + that.clear (); + } + + ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_kind::kind () const YY_NOEXCEPT + { + return kind_; + } + +]b4_glr2_cc_if([], [[ + ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_kind::type_get () const YY_NOEXCEPT + { + return this->kind (); + } +]])[ +]]) + + +# b4_token_constructor_define +# ---------------------------- +# Define make_FOO for all the token kinds. +# Use at class-level. Redefined in variant.hh. +m4_define([b4_token_constructor_define], []) + + +# b4_yytranslate_define(cc|hh) +# ---------------------------- +# Define yytranslate_. Sometimes used in the header file ($1=hh), +# sometimes in the cc file. +m4_define([b4_yytranslate_define], +[ b4_inline([$1])b4_parser_class[::symbol_kind_type + ]b4_parser_class[::yytranslate_ (int t) YY_NOEXCEPT + { +]b4_api_token_raw_if( +[[ return static_cast (t);]], +[[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to + // TOKEN-NUM as returned by yylex. + static + const ]b4_int_type_for([b4_translate])[ + translate_table[] = + { + ]b4_translate[ + }; + // Last valid token kind. + const int code_max = ]b4_code_max[; + + if (t <= 0) + return symbol_kind::]b4_symbol_prefix[YYEOF; + else if (t <= code_max) + return static_cast (translate_table[t]); + else + return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[ + } +]]) + + +# b4_lhs_value([TYPE]) +# -------------------- +m4_define([b4_lhs_value], +[b4_symbol_value([yyval], [$1])]) + + +# b4_rhs_value(RULE-LENGTH, POS, [TYPE]) +# -------------------------------------- +# FIXME: Dead code. +m4_define([b4_rhs_value], +[b4_symbol_value([yysemantic_stack_@{($1) - ($2)@}], [$3])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(yyloc)]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[(yylocation_stack_@{($1) - ($2)@})]) + + +# b4_parse_param_decl +# ------------------- +# Extra formal arguments of the constructor. +# Change the parameter names from "foo" into "foo_yyarg", so that +# there is no collision bw the user chosen attribute name, and the +# argument name in the constructor. +m4_define([b4_parse_param_decl], +[m4_ifset([b4_parse_param], + [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])]) + +m4_define([b4_parse_param_decl_1], +[$1_yyarg]) + + + +# b4_parse_param_cons +# ------------------- +# Extra initialisations of the constructor. +m4_define([b4_parse_param_cons], + [m4_ifset([b4_parse_param], + [ + b4_cc_constructor_calls(b4_parse_param)])]) +m4_define([b4_cc_constructor_calls], + [m4_map_sep([b4_cc_constructor_call], [, + ], [$@])]) +m4_define([b4_cc_constructor_call], + [$2 ($2_yyarg)]) + +# b4_parse_param_vars +# ------------------- +# Extra instance variables. +m4_define([b4_parse_param_vars], + [m4_ifset([b4_parse_param], + [ + // User arguments. +b4_cc_var_decls(b4_parse_param)])]) +m4_define([b4_cc_var_decls], + [m4_map_sep([b4_cc_var_decl], [ +], [$@])]) +m4_define([b4_cc_var_decl], + [ $1;]) + + +## ---------## +## Values. ## +## ---------## + +# b4_yylloc_default_define +# ------------------------ +# Define YYLLOC_DEFAULT. +m4_define([b4_yylloc_default_define], +[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +# ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).begin = YYRHSLOC (Rhs, 1).begin; \ + (Current).end = YYRHSLOC (Rhs, N).end; \ + } \ + else \ + { \ + (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ + } \ + while (false) +# endif +]]) + +## -------- ## +## Checks. ## +## -------- ## + +b4_token_ctor_if([b4_variant_if([], + [b4_fatal_at(b4_percent_define_get_loc(api.token.constructor), + [cannot use '%s' without '%s'], + [%define api.token.constructor], + [%define api.value.type variant]))])]) diff --git a/tools/flex-bison/third_party/skeletons/c-like.m4 b/tools/flex-bison/third_party/skeletons/c-like.m4 index 8d891b67e..a9bbc2e86 100644 --- a/tools/flex-bison/third_party/skeletons/c-like.m4 +++ b/tools/flex-bison/third_party/skeletons/c-like.m4 @@ -2,7 +2,7 @@ # Common code for C-like languages (C, C++, Java, etc.) -# Copyright (C) 2012-2015, 2018-2019 Free Software Foundation, Inc. +# Copyright (C) 2012-2015, 2018-2021 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,17 +15,23 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . + # _b4_comment(TEXT, OPEN, CONTINUE, END) # -------------------------------------- # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. # Avoid adding indentation to the first line, as the indentation comes # from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). +# Turn "*/" in TEXT into "* /" so that we don't unexpectedly close +# the comments before its end. # # Prefix all the output lines with PREFIX. m4_define([_b4_comment], -[$2[]m4_bpatsubst(m4_expand([[$1]]), [ +[$2[]b4_gsub(m4_expand([$1]), + [[*]/], [*\\/], + [/[*]], [/\\*], + [ \(.\)], [ $3\1])$4]) diff --git a/tools/flex-bison/third_party/skeletons/c-skel.m4 b/tools/flex-bison/third_party/skeletons/c-skel.m4 new file mode 100644 index 000000000..ac6ddd687 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/c-skel.m4 @@ -0,0 +1,27 @@ + -*- Autoconf -*- + +# C skeleton dispatching for Bison. + +# Copyright (C) 2006-2007, 2009-2015, 2018-2021 Free Software +# Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])]) +b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[yacc.c]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/tools/flex-bison/third_party/skeletons/c.m4 b/tools/flex-bison/third_party/skeletons/c.m4 index 3cde04a95..2425b0715 100644 --- a/tools/flex-bison/third_party/skeletons/c.m4 +++ b/tools/flex-bison/third_party/skeletons/c.m4 @@ -2,7 +2,7 @@ # C M4 Macros for Bison. -# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation, +# Copyright (C) 2002, 2004-2015, 2018-2021 Free Software Foundation, # Inc. # This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . m4_include(b4_skeletonsdir/[c-like.m4]) @@ -58,11 +58,11 @@ m4_define([b4_cpp_guard_close], # b4_pull_flag if they use the values of the %define variables api.pure or # api.push-pull. m4_define([b4_identification], -[[/* Identify Bison output. */ -#define YYBISON 1 +[[/* Identify Bison output, and Bison version. */ +#define YYBISON ]b4_version[ -/* Bison version. */ -#define YYBISON_VERSION "]b4_version[" +/* Bison version string. */ +#define YYBISON_VERSION "]b4_version_string[" /* Skeleton name. */ #define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[ @@ -101,32 +101,45 @@ m4_define_default([b4_prefix], [b4_api_prefix]) b4_percent_define_default([[api.value.union.name]], [b4_api_PREFIX[][STYPE]]) +b4_percent_define_default([[api.symbol.prefix]], [[YYSYMBOL_]]) ## ------------------------ ## ## Pure/impure interfaces. ## ## ------------------------ ## -# b4_lex_formals -# -------------- +# b4_yylex_formals +# ---------------- # All the yylex formal arguments. # b4_lex_param arrives quoted twice, but we want to keep only one level. -m4_define([b4_lex_formals], -[b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl -b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl +m4_define([b4_yylex_formals], +[b4_pure_if([[[b4_api_PREFIX[STYPE *yylvalp]], [[&yylval]]][]dnl +b4_locations_if([, [b4_api_PREFIX[LTYPE *yyllocp], [&yylloc]]])])dnl m4_ifdef([b4_lex_param], [, ]b4_lex_param)]) -# b4_lex -# ------ +# b4_yylex +# -------- # Call yylex. -m4_define([b4_lex], -[b4_function_call([yylex], [int], b4_lex_formals)]) +m4_define([b4_yylex], +[b4_function_call([yylex], [int], b4_yylex_formals)]) # b4_user_args # ------------ m4_define([b4_user_args], -[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])]) +[m4_ifset([b4_parse_param], [, b4_user_args_no_comma])]) + +# b4_user_args_no_comma +# --------------------- +m4_define([b4_user_args_no_comma], +[m4_ifset([b4_parse_param], [b4_args(b4_parse_param)])]) + + +# b4_user_formals +# --------------- +# The possible parse-params formal arguments preceded by a comma. +m4_define([b4_user_formals], +[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) # b4_parse_param @@ -150,13 +163,20 @@ m4_popdef([$2])dnl m4_popdef([$1])dnl ])]) + +# b4_use(EXPR) +# ------------ +# Pacify the compiler about some maybe unused value. +m4_define([b4_use], +[YY_USE ($1)]) + # b4_parse_param_use([VAL], [LOC]) # -------------------------------- -# 'YYUSE' VAL, LOC if locations are enabled, and all the parse-params. +# 'YY_USE' VAL, LOC if locations are enabled, and all the parse-params. m4_define([b4_parse_param_use], -[m4_ifvaln([$1], [ YYUSE ([$1]);])dnl -b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl -b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); +[m4_ifvaln([$1], [ b4_use([$1]);])dnl +b4_locations_if([m4_ifvaln([$2], [ b4_use([$2]);])])dnl +b4_parse_param_for([Decl], [Formal], [ b4_use(Formal); ])dnl ]) @@ -167,38 +187,170 @@ b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); # b4_int_type(MIN, MAX) # --------------------- -# Return the smallest int type able to handle numbers ranging from -# MIN to MAX (included). +# Return a narrow int type able to handle integers ranging from MIN +# to MAX (included) in portable C code. Assume MIN and MAX fall in +# 'int' range. m4_define([b4_int_type], -[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], - b4_ints_in($@, [-128], [127]), [1], [signed char], +[m4_if(b4_ints_in($@, [-127], [127]), [1], [signed char], + b4_ints_in($@, [0], [255]), [1], [unsigned char], + b4_ints_in($@, [-32767], [32767]), [1], [short], b4_ints_in($@, [0], [65535]), [1], [unsigned short], - b4_ints_in($@, [-32768], [32767]), [1], [short], - - m4_eval([0 <= $1]), [1], [unsigned], [int])]) +# b4_c99_int_type(MIN, MAX) +# ------------------------- +# Like b4_int_type, but for C99. +# b4_c99_int_type_define replaces b4_int_type with this. +m4_define([b4_c99_int_type], +[m4_if(b4_ints_in($@, [-127], [127]), [1], [yytype_int8], + b4_ints_in($@, [0], [255]), [1], [yytype_uint8], + + b4_ints_in($@, [-32767], [32767]), [1], [yytype_int16], + b4_ints_in($@, [0], [65535]), [1], [yytype_uint16], + + [int])]) + +# b4_c99_int_type_define +# ---------------------- +# Define private types suitable for holding small integers in C99 or later. +m4_define([b4_c99_int_type_define], +[m4_copy_force([b4_c99_int_type], [b4_int_type])dnl +[#ifdef short +# undef short +#endif + +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif + +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; +#endif + +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif]]) + + +# b4_sizes_types_define +# --------------------- +# Define YYPTRDIFF_T/YYPTRDIFF_MAXIMUM, YYSIZE_T/YYSIZE_MAXIMUM, +# and YYSIZEOF. +m4_define([b4_sizes_types_define], +[[#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) +]]) + # b4_int_type_for(NAME) # --------------------- -# Return the smallest int type able to handle numbers ranging from +# Return a narrow int type able to handle numbers ranging from # 'NAME_min' to 'NAME_max' (included). m4_define([b4_int_type_for], [b4_int_type($1_min, $1_max)]) -# b4_table_value_equals(TABLE, VALUE, LITERAL) -# -------------------------------------------- +# b4_table_value_equals(TABLE, VALUE, LITERAL, SYMBOL) +# ---------------------------------------------------- # Without inducing a comparison warning from the compiler, check if the # literal value LITERAL equals VALUE from table TABLE, which must have -# TABLE_min and TABLE_max defined. +# TABLE_min and TABLE_max defined. SYMBOL denotes m4_define([b4_table_value_equals], [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) || m4_indir([b4_]$1[_max]) < $3), [1], [[0]], - [(!!(($2) == ($3)))])]) + [(($2) == $4)])]) ## ----------------- ## @@ -210,54 +362,72 @@ m4_define([b4_table_value_equals], # Provide portable compiler "attributes". If "noreturn" is passed, define # _Noreturn. m4_define([b4_attribute_define], -[[#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +[[#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else -# define YY_ATTRIBUTE(Spec) /* empty */ +# define YY_ATTRIBUTE_PURE # endif #endif -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif #endif ]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */ -#if ! defined _Noreturn -# if defined __cplusplus && 201103L <= __cplusplus +]dnl This is close to lib/_Noreturn.h, except that we do enable +dnl the use of [[noreturn]], because _Noreturn is used in places +dnl where [[noreturn]] works in C++. We need this in particular +dnl because of glr.cc which compiles code from glr.c in C++. +dnl And the C++ compiler chokes on _Noreturn. Also, we do not +dnl use C' _Noreturn in C++, to avoid -Wc11-extensions warnings. +[#ifndef _Noreturn +# if (defined __cplusplus \ + && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ + || (defined _MSC_VER && 1900 <= _MSC_VER))) # define _Noreturn [[noreturn]] -# elif !(defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__) -# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ - || 0x5110 <= __SUNPRO_C) -# define _Noreturn __attribute__ ((__noreturn__)) -# elif defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn -# endif +# elif ((!defined __cplusplus || defined __clang__) \ + && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ + || (!defined __STRICT_ANSI__ \ + && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \ + || (defined __apple_build_version__ \ + ? 6000000 <= __apple_build_version__ \ + : 3 < __clang_major__ + (5 <= __clang_minor__)))))) + /* _Noreturn works as-is. */ +# elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \ + || 0x5110 <= __SUNPRO_C) +# define _Noreturn __attribute__ ((__noreturn__)) +# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn # endif #endif ]])[/* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +# define YY_USE(E) ((void) (E)) #else -# define YYUSE(E) /* empty */ +# define YY_USE(E) /* empty */ #endif -#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ +#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") +# else +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ +# endif +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -269,9 +439,36 @@ m4_define([b4_attribute_define], #ifndef YY_INITIAL_VALUE # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif ]]) +# b4_cast_define +# -------------- +m4_define([b4_cast_define], +[# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif[]dnl +]) + + # b4_null_define # -------------- # Portability issues: define a YY_NULLPTR appropriate for the current @@ -309,7 +506,7 @@ m4_define([b4_null], [YY_NULLPTR]) # ------------------------------------------------------------- # Define "yy" whose contents is CONTENT. m4_define([b4_integral_parser_table_define], -[m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl +[m4_ifvaln([$3], [b4_comment([$3])])dnl static const b4_int_type_for([$2]) yy$1[[]] = { $2 @@ -317,9 +514,22 @@ static const b4_int_type_for([$2]) yy$1[[]] = ]) -## ------------------------- ## -## Assigning token numbers. ## -## ------------------------- ## +## ------------- ## +## Token kinds. ## +## ------------- ## + +# Because C enums are not scoped, because tokens are exposed in the +# header, and because these tokens are common to all the parsers, we +# need to make sure their names don't collide: use the api.prefix. +# YYEOF is special, since the user may give it a different name. +m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]]) +m4_define([b4_symbol(-2, tag)], [[No symbol.]]) + +m4_if(b4_symbol(eof, id), [YYEOF], + [m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])]) +m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][error]]) +m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]]) + # b4_token_define(TOKEN-NUM) # -------------------------- @@ -331,44 +541,92 @@ m4_define([b4_token_define], # ---------------- # Output the definition of the tokens. m4_define([b4_token_defines], -[b4_any_token_visible_if([/* Tokens. */ -m4_join([ +[[/* Token kinds. */ +#define ]b4_symbol(empty, [id])[ -2 +]m4_join([ ], b4_symbol_map([b4_token_define])) -])]) +]) # b4_token_enum(TOKEN-NUM) # ------------------------ # Output the definition of this token as an enum. m4_define([b4_token_enum], -[b4_token_format([%s = %s], [$1])]) +[b4_token_visible_if([$1], + [m4_format([ %-30s %s], + m4_format([[%s = %s%s%s]], + b4_symbol([$1], [id]), + b4_symbol([$1], b4_api_token_raw_if([[number]], [[code]])), + m4_if([$1], b4_last_enum_token, [], [[,]])), + [b4_symbol_tag_comment([$1])])])]) # b4_token_enums # -------------- -# Output the definition of the tokens (if there are) as enums. +# The definition of the token kinds. m4_define([b4_token_enums], -[b4_any_token_visible_if([[/* Token type. */ +[b4_any_token_visible_if([[/* Token kinds. */ #ifndef ]b4_api_PREFIX[TOKENTYPE # define ]b4_api_PREFIX[TOKENTYPE enum ]b4_api_prefix[tokentype { - ]m4_join([, - ], - b4_symbol_map([b4_token_enum]))[ - }; + ]b4_symbol(empty, [id])[ = -2, +]b4_symbol_foreach([b4_token_enum])dnl +[ }; + typedef enum ]b4_api_prefix[tokentype ]b4_api_prefix[token_kind_t; #endif ]])]) # b4_token_enums_defines # ---------------------- -# Output the definition of the tokens (if there are any) as enums and, +# The definition of the tokens (if there are any) as enums and, # if POSIX Yacc is enabled, as #defines. m4_define([b4_token_enums_defines], [b4_token_enums[]b4_yacc_if([b4_token_defines])]) +# b4_symbol_translate(STRING) +# --------------------------- +# Used by "bison" in the array of symbol names to mark those that +# require translation. +m4_define([b4_symbol_translate], +[[N_($1)]]) + + + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +# b4_symbol_enum(SYMBOL-NUM) +# -------------------------- +# Output the definition of this symbol as an enum. +m4_define([b4_symbol_enum], +[m4_format([ %-40s %s], + m4_format([[%s = %s%s%s]], + b4_symbol([$1], [kind_base]), + [$1], + m4_if([$1], b4_last_symbol, [], [[,]])), + [b4_symbol_tag_comment([$1])])]) + + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +# Defining YYEMPTY here is important: it forces the compiler +# to use a signed type, which matters for yytoken. +m4_define([b4_declare_symbol_enum], +[[/* Symbol kind. */ +enum yysymbol_kind_t +{ + ]b4_symbol(empty, [kind_base])[ = -2, +]b4_symbol_foreach([b4_symbol_enum])dnl +[}; +typedef enum yysymbol_kind_t yysymbol_kind_t; +]])]) + + ## ----------------- ## ## Semantic Values. ## ## ----------------- ## @@ -392,15 +650,6 @@ m4_define([b4_symbol_value], ## ---------------------- ## -# b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...) -# ----------------------------------------------------------- -# Declare the function NAME in C. -m4_define([b4_function_define], -[$2 -$1 (b4_formals(m4_shift2($@)))[]dnl -]) - - # b4_formals([DECL1, NAME1], ...) # ------------------------------- # The formal arguments of a C function definition. @@ -413,12 +662,6 @@ m4_define([b4_formal], [$1]) - -## ----------------------- ## -## Declaring C functions. ## -## ----------------------- ## - - # b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...) # ------------------------------------------------------------ # Declare the function NAME. @@ -428,7 +671,6 @@ m4_define([b4_function_declare], - ## --------------------- ## ## Calling C functions. ## ## --------------------- ## @@ -465,12 +707,12 @@ m4_define([b4_sync_start], [[#]line $1 $2]) ## User actions. ## ## -------------- ## -# b4_case(LABEL, STATEMENTS) -# -------------------------- +# b4_case(LABEL, STATEMENTS, [COMMENTS]) +# -------------------------------------- m4_define([b4_case], -[ case $1: +[ case $1:m4_ifval([$3], [ b4_comment([$3])]) $2 -b4_syncline([@oline@], [@ofile@]) +b4_syncline([@oline@], [@ofile@])dnl break;]) @@ -480,7 +722,7 @@ m4_define([b4_predicate_case], [ case $1: if (! ( $2)) YYERROR; -b4_syncline([@oline@], [@ofile@]) +b4_syncline([@oline@], [@ofile@])dnl break;]) @@ -492,18 +734,15 @@ m4_define_default([b4_yydestruct_define], | Release the memory associated to this symbol. | `-----------------------------------------------*/ -]b4_function_define([yydestruct], - [static void], - [[const char *yymsg], [yymsg]], - [[int yytype], [yytype]], - [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl -b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl -m4_ifset([b4_parse_param], [, b4_parse_param]))[ +static void +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep]b4_locations_if(dnl +[[, YYLTYPE *yylocationp]])[]b4_user_formals[) { ]b4_parse_param_use([yyvaluep], [yylocationp])dnl [ if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN ]b4_symbol_actions([destructor])[ @@ -521,48 +760,39 @@ m4_define_default([b4_yy_symbol_print_define], | Print this symbol's value on YYO. | `-----------------------------------*/ -]b4_function_define([yy_symbol_value_print], - [static void], - [[FILE *yyo], [yyo]], - [[int yytype], [yytype]], - [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl -b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl -m4_ifset([b4_parse_param], [, b4_parse_param]))[ +static void +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl +[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[) { FILE *yyoutput = yyo; ]b4_parse_param_use([yyoutput], [yylocationp])dnl [ if (!yyvaluep) return;] -dnl glr.c does not feature yytoknum. -m4_if(b4_skeleton, ["yacc.c"], -[[# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyo, yytoknum[yytype], *yyvaluep); -# endif -]])dnl - b4_symbol_actions([printer])[ -} +b4_percent_code_get([[pre-printer]])dnl + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + b4_symbol_actions([printer]) + YY_IGNORE_MAYBE_UNINITIALIZED_END +b4_percent_code_get([[post-printer]])dnl +[} /*---------------------------. | Print this symbol on YYO. | `---------------------------*/ -]b4_function_define([yy_symbol_print], - [static void], - [[FILE *yyo], [yyo]], - [[int yytype], [yytype]], - [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl -b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl -m4_ifset([b4_parse_param], [, b4_parse_param]))[ +static void +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl +[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[) { YYFPRINTF (yyo, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); -]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp); +]b4_locations_if([ YYLOCATION_PRINT (yyo, yylocationp); YYFPRINTF (yyo, ": "); ])dnl -[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl +[ yy_symbol_value_print (yyo, yykind, yyvaluep]dnl b4_locations_if([, yylocationp])[]b4_user_args[); YYFPRINTF (yyo, ")"); }]dnl @@ -588,11 +818,11 @@ m4_define([b4_symbol_type_register], [m4_define([b4_symbol($1, type_tag)], [b4_symbol_if([$1], [has_id], [b4_symbol([$1], [id])], - [yytype_[]b4_symbol([$1], [number])])])dnl + [yykind_[]b4_symbol([$1], [number])])])dnl m4_append([b4_union_members], -m4_expand([ - b4_symbol_tag_comment([$1])dnl - b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);])) +m4_expand([m4_format([ %-40s %s], + m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]), + [b4_symbol_tag_comment([$1])])])) ]) @@ -709,13 +939,13 @@ typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE; [m4_bmatch(b4_percent_define_get([[api.value.type]]), [union\|union-directive], [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED -]b4_percent_define_get_syncline([[api.value.union.name]])[ -union ]b4_percent_define_get([[api.value.union.name]])[ +]b4_percent_define_get_syncline([[api.value.union.name]])dnl +[union ]b4_percent_define_get([[api.value.union.name]])[ { ]b4_user_union_members[ }; -]b4_percent_define_get_syncline([[api.value.union.name]])[ -typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[STYPE; +]b4_percent_define_get_syncline([[api.value.union.name]])dnl +[typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[STYPE; # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 #endif @@ -726,7 +956,10 @@ typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[S # ----------------------- m4_define([b4_location_type_define], [[/* Location type. */ -#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED +]b4_percent_define_ifdef([[api.location.type]], +[[typedef ]b4_percent_define_get([[api.location.type]])[ ]b4_api_PREFIX[LTYPE; +]], +[[#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED typedef struct ]b4_api_PREFIX[LTYPE ]b4_api_PREFIX[LTYPE; struct ]b4_api_PREFIX[LTYPE { @@ -738,12 +971,12 @@ struct ]b4_api_PREFIX[LTYPE # define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1 # define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1 #endif -]]) +]])]) # b4_declare_yylstype # ------------------- -# Declarations that might either go into the header (if --defines) or +# Declarations that might either go into the header (if --header) or # in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. m4_define([b4_declare_yylstype], [b4_value_type_define[]b4_locations_if([ @@ -813,25 +1046,30 @@ m4_define([b4_yylloc_default_define], #endif ]]) -# b4_yy_location_print_define -# --------------------------- -# Define YY_LOCATION_PRINT. -m4_define([b4_yy_location_print_define], +# b4_yylocation_print_define +# -------------------------- +# Define YYLOCATION_PRINT. +m4_define([b4_yylocation_print_define], [b4_locations_if([[ -/* YY_LOCATION_PRINT -- Print the location on the stream. +/* YYLOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ -#ifndef YY_LOCATION_PRINT -# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL +# ifndef YYLOCATION_PRINT + +# if defined YY_LOCATION_PRINT + + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc)) + +# elif defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL /* Print *YYLOCP on YYO. Private, do not rely on its existence. */ YY_ATTRIBUTE_UNUSED -]b4_function_define([yy_location_print_], - [static int], - [[FILE *yyo], [yyo]], - [[YYLTYPE const * const yylocp], [yylocp]])[ +static int +yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) { int res = 0; int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; @@ -853,19 +1091,23 @@ YY_ATTRIBUTE_UNUSED res += YYFPRINTF (yyo, "-%d", end_col); } return res; - } +} -# define YY_LOCATION_PRINT(File, Loc) \ - yy_location_print_ (File, &(Loc)) +# define YYLOCATION_PRINT yy_location_print_ -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif -#endif]], -[[/* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif]]) + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc)) + +# else + +# define YYLOCATION_PRINT(File, Loc) ((void) 0) + /* Temporary convenience wrapper in case some people defined the + undocumented and private YY_LOCATION_PRINT macros. */ +# define YY_LOCATION_PRINT YYLOCATION_PRINT + +# endif +# endif /* !defined YYLOCATION_PRINT */]]) ]) # b4_yyloc_default diff --git a/tools/flex-bison/third_party/skeletons/d-skel.m4 b/tools/flex-bison/third_party/skeletons/d-skel.m4 new file mode 100644 index 000000000..2a38f02f2 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/d-skel.m4 @@ -0,0 +1,26 @@ + -*- Autoconf -*- + +# D skeleton dispatching for Bison. + +# Copyright (C) 2018-2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [b4_complain([%%glr-parser not supported for D])]) +b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for D])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.d]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/tools/flex-bison/third_party/skeletons/d.m4 b/tools/flex-bison/third_party/skeletons/d.m4 new file mode 100644 index 000000000..c0632e472 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/d.m4 @@ -0,0 +1,628 @@ + -*- Autoconf -*- + +# D language support for Bison + +# Copyright (C) 2018-2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +m4_include(b4_skeletonsdir/[c-like.m4]) + + +# b4_symbol_action(SYMBOL-NUM, ACTION) +# ------------------------------------ +# Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM. +m4_define([b4_symbol_action], +[b4_symbol_if([$1], [has_$2], +[b4_dollar_pushdef([yyval], + [$1], + [], + [yyloc])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl +b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +b4_dollar_popdef[]dnl +])]) + + +# b4_use(EXPR) +# ------------ +# Pacify the compiler about some maybe unused value. +m4_define([b4_use], +[]) + + +# b4_sync_start(LINE, FILE) +# ------------------------- +m4_define([b4_sync_start], [[#]line $1 $2]) + + +# b4_list2(LIST1, LIST2) +# ---------------------- +# Join two lists with a comma if necessary. +m4_define([b4_list2], + [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2]) + + +# b4_percent_define_get3(DEF, PRE, POST, NOT) +# ------------------------------------------- +# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed, +# otherwise NOT. +m4_define([b4_percent_define_get3], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [$2[]b4_percent_define_get([$1])[]$3], [$4])]) + +# b4_percent_define_if_get2(ARG1, ARG2, DEF, NOT) +# ----------------------------------------------- +# Expand to the value of DEF if ARG1 or ARG2 are %define'ed, +# otherwise NOT. +m4_define([b4_percent_define_if_get2], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [$3], [m4_ifval(m4_quote(b4_percent_define_get([$2])), + [$3], [$4])])]) + +# b4_percent_define_class_before_interface(CLASS, INTERFACE) +# ---------------------------------------------------------- +# Expand to a ', ' if both a class and an interface have been %define'ed +m4_define([b4_percent_define_class_before_interface], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [m4_ifval(m4_quote(b4_percent_define_get([$2])), + [, ])])]) + + +# b4_flag_value(BOOLEAN-FLAG) +# --------------------------- +m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])]) + + +# b4_parser_class_declaration +# --------------------------- +# The declaration of the parser class ("class YYParser"), with all its +# qualifiers/annotations. +b4_percent_define_default([[api.parser.abstract]], [[false]]) +b4_percent_define_default([[api.parser.final]], [[false]]) +b4_percent_define_default([[api.parser.public]], [[false]]) + +m4_define([b4_parser_class_declaration], +[b4_percent_define_get3([api.parser.annotations], [], [ ])dnl +b4_percent_define_flag_if([api.parser.public], [public ])dnl +b4_percent_define_flag_if([api.parser.abstract], [abstract ])dnl +b4_percent_define_flag_if([api.parser.final], [final ])dnl +[class ]b4_parser_class[]dnl +b4_percent_define_if_get2([api.parser.extends], [api.parser.implements], [ : ])dnl +b4_percent_define_get([api.parser.extends])dnl +b4_percent_define_class_before_interface([api.parser.extends], [api.parser.implements])dnl +b4_percent_define_get([api.parser.implements])]) + + +# b4_lexer_if(TRUE, FALSE) +# ------------------------ +m4_define([b4_lexer_if], +[b4_percent_code_ifdef([[lexer]], [$1], [$2])]) + + +# b4_position_type_if(TRUE, FALSE) +# -------------------------------- +m4_define([b4_position_type_if], +[b4_percent_define_ifdef([[position_type]], [$1], [$2])]) + + +# b4_location_type_if(TRUE, FALSE) +# -------------------------------- +m4_define([b4_location_type_if], +[b4_percent_define_ifdef([[location_type]], [$1], [$2])]) + + +# b4_identification +# ----------------- +m4_define([b4_identification], +[[/** Version number for the Bison executable that generated this parser. */ + public static immutable string yy_bison_version = "]b4_version_string["; + + /** Name of the skeleton that generated this parser. */ + public static immutable string yy_bison_skeleton = ]b4_skeleton[; +]]) + + +## ------------ ## +## Data types. ## +## ------------ ## + +# b4_int_type(MIN, MAX) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# MIN to MAX (included). +m4_define([b4_int_type], +[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte], + b4_ints_in($@, [-32768], [32767]), [1], [short], + [int])]) + +# b4_int_type_for(NAME) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# `NAME_min' to `NAME_max' (included). +m4_define([b4_int_type_for], +[b4_int_type($1_min, $1_max)]) + +# b4_null +# ------- +m4_define([b4_null], [null]) + + +# b4_integral_parser_table_define(NAME, DATA, COMMENT) +#----------------------------------------------------- +# Define "yy" whose contents is CONTENT. +m4_define([b4_integral_parser_table_define], +[m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl +private static immutable b4_int_type_for([$2])[[]] yy$1_ = +@{ + $2 +@};dnl +]) + + +## ------------- ## +## Token kinds. ## +## ------------- ## + +m4_define([b4_symbol(-2, id)], [[YYEMPTY]]) +b4_percent_define_default([[api.token.raw]], [[true]]) + +# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) +# --------------------------------------- +# Output the definition of this token as an enum. +m4_define([b4_token_enum], +[b4_token_format([ %s = %s, +], [$1])]) + +# b4_token_enums +# -------------- +# Output the definition of the tokens as enums. +m4_define([b4_token_enums], +[/* Token kinds. */ +public enum TokenKind { + ]b4_symbol(empty, id)[ = -2, +b4_symbol_foreach([b4_token_enum])dnl +} +]) + +# b4_symbol_translate(STRING) +# --------------------------- +# Used by "bison" in the array of symbol names to mark those that +# require translation. +m4_define([b4_symbol_translate], +[[_($1)]]) + + +# _b4_token_constructor_define(SYMBOL-NUM) +# ---------------------------------------- +# Define Symbol.FOO for SYMBOL-NUM. +m4_define([_b4_token_constructor_define], +[b4_token_visible_if([$1], +[[ + static auto ]b4_symbol([$1], [id])[(]b4_symbol_if([$1], [has_type], +[b4_union_if([b4_symbol([$1], [type]], +[[typeof(YYSemanticType.]b4_symbol([$1], [type])[]])) [val]])dnl +[]b4_locations_if([b4_symbol_if([$1], [has_type], [[, ]])[Location l]])[) + { + return Symbol(TokenKind.]b4_symbol([$1], [id])[]b4_symbol_if([$1], [has_type], + [[, val]])[]b4_locations_if([[, l]])[); + }]])]) + +# b4_token_constructor_define +# --------------------------- +# Define Symbol.FOO for each token kind FOO. +m4_define([b4_token_constructor_define], +[[ + /* Implementation of token constructors for each symbol type visible to + * the user. The code generates static methods that have the same names + * as the TokenKinds. + */]b4_symbol_foreach([_b4_token_constructor_define])dnl +]) + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + +# b4_symbol_kind(NUM) +# ------------------- +m4_define([b4_symbol_kind], +[SymbolKind.b4_symbol_kind_base($@)]) + + +# b4_symbol_enum(SYMBOL-NUM) +# -------------------------- +# Output the definition of this symbol as an enum. +m4_define([b4_symbol_enum], +[m4_format([ %-30s %s], + m4_format([[%s = %s,]], + b4_symbol([$1], [kind_base]), + [$1]), + [b4_symbol_tag_comment([$1])])]) + + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +# Defining YYEMPTY here is important: it forces the compiler +# to use a signed type, which matters for yytoken. +m4_define([b4_declare_symbol_enum], +[[ /* Symbol kinds. */ + struct SymbolKind + { + enum + { + ]b4_symbol(empty, kind_base)[ = -2, /* No symbol. */ +]b4_symbol_foreach([b4_symbol_enum])dnl +[ } + + private int yycode_; + alias yycode_ this; + + this(int code) + { + yycode_ = code; + } + + /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + final void toString(W)(W sink) const + if (isOutputRange!(W, char)) + { + immutable string[] yy_sname = @{ + ]b4_symbol_names[ + @};]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + immutable ]b4_int_type_for([b4_translatable])[[] yytranslatable = @{ + ]b4_translatable[ + @};]])[ + + put(sink, yy_sname[yycode_]); + } + } +]]) + + +# b4_case(ID, CODE, [COMMENTS]) +# ----------------------------- +m4_define([b4_case], [ case $1:m4_ifval([$3], [ b4_comment([$3])]) +$2 + break;]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +m4_define([b4_yystype], [b4_percent_define_get([[stype]])]) +b4_percent_define_default([[stype]], [[YYSemanticType]])]) + +# %name-prefix +m4_define_default([b4_prefix], [[YY]]) + +b4_percent_define_default([[api.parser.class]], [b4_prefix[]Parser])]) +m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])]) + +#b4_percent_define_default([[location_type]], [Location])]) +m4_define([b4_location_type], b4_percent_define_ifdef([[location_type]],[b4_percent_define_get([[location_type]])],[YYLocation])) + +#b4_percent_define_default([[position_type]], [Position])]) +m4_define([b4_position_type], b4_percent_define_ifdef([[position_type]],[b4_percent_define_get([[position_type]])],[YYPosition])) + + +## ---------------- ## +## api.value.type. ## +## ---------------- ## + + +# ---------------------- # +# api.value.type=union. # +# ---------------------- # + +# b4_symbol_type_register(SYMBOL-NUM) +# ----------------------------------- +# Symbol SYMBOL-NUM has a type (for union) instead of a type-tag. +# Extend the definition of %union's body (b4_union_members) with a +# field of that type, and extend the symbol's "type" field to point to +# the field name, instead of the type name. +m4_define([b4_symbol_type_register], +[m4_define([b4_symbol($1, type_tag)], + [b4_symbol_if([$1], [has_id], + [b4_symbol([$1], [id])], + [yykind_[]b4_symbol([$1], [number])])])dnl +m4_append([b4_union_members], +m4_expand([m4_format([ %-40s %s], + m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]), + [b4_symbol_tag_comment([$1])])])) +]) + + +# b4_type_define_tag(SYMBOL1-NUM, ...) +# ------------------------------------ +# For the batch of symbols SYMBOL1-NUM... (which all have the same +# type), enhance the %union definition for each of them, and set +# there "type" field to the field tag name, instead of the type name. +m4_define([b4_type_define_tag], +[b4_symbol_if([$1], [has_type], + [m4_map([b4_symbol_type_register], [$@])]) +]) + + +# b4_symbol_value_union(VAL, SYMBOL-NUM, [TYPE]) +# ---------------------------------------------- +# Same of b4_symbol_value, but when api.value.type=union. +m4_define([b4_symbol_value_union], +[m4_ifval([$3], + [(*($3*)(&$1))], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type_tag]))], + [$1])], + [$1])])]) + + +# b4_value_type_setup_union +# ------------------------- +# Setup support for api.value.type=union. Symbols are defined with a +# type instead of a union member name: build the corresponding union, +# and give the symbols their tag. +m4_define([b4_value_type_setup_union], +[m4_define([b4_union_members]) +b4_type_foreach([b4_type_define_tag]) +m4_copy_force([b4_symbol_value_union], [b4_symbol_value]) +]) + + +# _b4_value_type_setup_keyword +# ---------------------------- +# api.value.type is defined with a keyword/string syntax. Check if +# that is properly defined, and prepare its use. +m4_define([_b4_value_type_setup_keyword], +[b4_percent_define_check_values([[[[api.value.type]], + [[none]], + [[union]], + [[union-directive]], + [[yystype]]]])dnl +m4_case(b4_percent_define_get([[api.value.type]]), + [union], [b4_value_type_setup_union])]) + + +# b4_value_type_setup +# ------------------- +# Check if api.value.type is properly defined, and possibly prepare +# its use. +b4_define_silent([b4_value_type_setup], +[ +# Define default value. +b4_percent_define_ifdef([[api.value.type]], [], +[# %union => api.value.type=union-directive +m4_ifdef([b4_union_members], +[m4_define([b4_percent_define_kind(api.value.type)], [keyword]) +m4_define([b4_percent_define(api.value.type)], [union-directive])], +[# no tag seen => api.value.type={int} +m4_if(b4_tag_seen_flag, 0, +[m4_define([b4_percent_define_kind(api.value.type)], [code]) +m4_define([b4_percent_define(api.value.type)], [int])], +[# otherwise api.value.type=yystype +m4_define([b4_percent_define_kind(api.value.type)], [keyword]) +m4_define([b4_percent_define(api.value.type)], [yystype])])])]) + +# Set up. +m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), + [keyword], [_b4_value_type_setup_keyword]) +]) + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +# ---------------------------------------------- +# See README. FIXME: factor in c-like? +m4_define([b4_symbol_value], +[m4_ifval([$3], + [($1.$3)], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type]))], + [$1])], + [$1])])]) + +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. +m4_define([b4_lhs_value], +[b4_symbol_value([yyval], [$1], [$2])]) + + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# See README. +# +# In this simple implementation, %token and %type have class names +# between the angle brackets. +m4_define([b4_rhs_value], +[b4_symbol_value([(yystack.valueAt (b4_subtract([$1], [$2])))], [$3], [$4])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(yyloc)]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[yystack.locationAt (b4_subtract($@))]) + + +# b4_lex_param +# b4_parse_param +# -------------- +# If defined, b4_lex_param arrives double quoted, but below we prefer +# it to be single quoted. Same for b4_parse_param. + +# TODO: should be in bison.m4 +m4_define_default([b4_lex_param], [[]])) +m4_define([b4_lex_param], b4_lex_param)) +m4_define([b4_parse_param], b4_parse_param)) + +# b4_lex_param_decl +# ------------------- +# Extra formal arguments of the constructor. +m4_define([b4_lex_param_decl], +[m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_decls(b4_lex_param))], + [$1])]) + +m4_define([b4_param_decls], + [m4_map([b4_param_decl], [$@])]) +m4_define([b4_param_decl], [, $1]) + +m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)]) + + + +# b4_parse_param_decl +# ------------------- +# Extra formal arguments of the constructor. +m4_define([b4_parse_param_decl], +[m4_ifset([b4_parse_param], + [b4_remove_comma([$1], + b4_param_decls(b4_parse_param))], + [$1])]) + + + +# b4_lex_param_call +# ------------------- +# Delegating the lexer parameters to the lexer constructor. +m4_define([b4_lex_param_call], + [m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_calls(b4_lex_param))], + [$1])]) +m4_define([b4_param_calls], + [m4_map([b4_param_call], [$@])]) +m4_define([b4_param_call], [, $2]) + + + +# b4_parse_param_cons +# ------------------- +# Extra initialisations of the constructor. +m4_define([b4_parse_param_cons], + [m4_ifset([b4_parse_param], + [b4_constructor_calls(b4_parse_param)])]) + +m4_define([b4_constructor_calls], + [m4_map([b4_constructor_call], [$@])]) +m4_define([b4_constructor_call], + [this.$2 = $2; + ]) + + + +# b4_parse_param_vars +# ------------------- +# Extra instance variables. +m4_define([b4_parse_param_vars], + [m4_ifset([b4_parse_param], + [ + /* User arguments. */ +b4_var_decls(b4_parse_param)])]) + +m4_define([b4_var_decls], + [m4_map_sep([b4_var_decl], [ +], [$@])]) +m4_define([b4_var_decl], + [ protected $1;]) + + +# b4_public_types_declare +# ----------------------- +# Define the public types: token, semantic value, location, and so forth. +# Depending on %define token_lex, may be output in the header or source file. +m4_define([b4_public_types_declare], +[[ +alias Symbol = ]b4_parser_class[.Symbol; +alias Value = ]b4_yystype[;]b4_locations_if([[ +alias Location = ]b4_location_type[; +alias Position = ]b4_position_type[;]b4_push_if([[ +alias PUSH_MORE = ]b4_parser_class[.YYPUSH_MORE; +alias ABORT = ]b4_parser_class[.YYABORT; +alias ACCEPT = ]b4_parser_class[.YYACCEPT;]])[]])[ +]]) + + +# b4_basic_symbol_constructor_define +# ---------------------------------- +# Create Symbol struct constructors for all the visible types. +m4_define([b4_basic_symbol_constructor_define], +[b4_token_visible_if([$1], +[[ this(TokenKind token]b4_symbol_if([$1], [has_type], +[[, ]b4_union_if([], [[typeof(YYSemanticType.]])b4_symbol([$1], [type])dnl +[]b4_union_if([], [[) ]])[ val]])[]b4_locations_if([[, Location loc]])[) + { + kind = yytranslate_(token);]b4_union_if([b4_symbol_if([$1], [has_type], [[ + static foreach (member; __traits(allMembers, YYSemanticType)) + { + static if (is(typeof(mixin("value_." ~ member)) == ]b4_symbol([$1], [type])[)) + { + mixin("value_." ~ member ~ " = val;"); + } + }]])], [b4_symbol_if([$1], [has_type], [[ + value_.]b4_symbol([$1], [type])[ = val;]])])[]b4_locations_if([ + location_ = loc;])[ + } +]])]) + + +# b4_symbol_type_define +# --------------------- +# Define symbol_type, the external type for symbols used for symbol +# constructors. +m4_define([b4_symbol_type_define], +[[ + /** + * A complete symbol + */ + struct Symbol + { + private SymbolKind kind; + private Value value_;]b4_locations_if([[ + private Location location_;]])[ + +]b4_type_foreach([b4_basic_symbol_constructor_define])[ + SymbolKind token() { return kind; } + Value value() { return value_; }]b4_locations_if([[ + Location location() { return location_; }]])[ +]b4_token_ctor_if([b4_token_constructor_define])[ + } +]]) diff --git a/tools/flex-bison/third_party/skeletons/glr.c b/tools/flex-bison/third_party/skeletons/glr.c new file mode 100644 index 000000000..fab3733f1 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/glr.c @@ -0,0 +1,2763 @@ +# -*- C -*- + +# GLR skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# If we are loaded by glr.cc, do not override c++.m4 definitions by +# those of c.m4. +m4_if(b4_skeleton, ["glr.c"], + [m4_include(b4_skeletonsdir/[c.m4])]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +# Stack parameters. +m4_define_default([b4_stack_depth_max], [10000]) +m4_define_default([b4_stack_depth_init], [200]) + +# Included header. +b4_percent_define_default([[api.header.include]], + [["@basename(]b4_spec_header_file[@)"]]) + +## ------------------------ ## +## Pure/impure interfaces. ## +## ------------------------ ## + +b4_define_flag_if([pure]) +# If glr.cc is including this file and thus has already set b4_pure_flag, +# do not change the value of b4_pure_flag, and do not record a use of api.pure. +m4_ifndef([b4_pure_flag], +[b4_percent_define_default([[api.pure]], [[false]]) + m4_define([b4_pure_flag], + [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])]) + +# b4_yyerror_args +# --------------- +# Optional effective arguments passed to yyerror: user args plus yylloc, and +# a trailing comma. +m4_define([b4_yyerror_args], +[b4_pure_if([b4_locations_if([yylocp, ])])dnl +m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) + + +# b4_lyyerror_args +# ---------------- +# Same as above, but on the lookahead, hence &yylloc instead of yylocp. +m4_define([b4_lyyerror_args], +[b4_pure_if([b4_locations_if([&yylloc, ])])dnl +m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) + + +# b4_pure_args +# ------------ +# Same as b4_yyerror_args, but with a leading comma. +m4_define([b4_pure_args], +[b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args]) + + +# b4_lpure_args +# ------------- +# Same as above, but on the lookahead, hence &yylloc instead of yylocp. +m4_define([b4_lpure_args], +[b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args]) + + + +# b4_pure_formals +# --------------- +# Arguments passed to yyerror: user formals plus yylocp with leading comma. +m4_define([b4_pure_formals], +[b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals]) + + +# b4_locuser_formals(LOC = yylocp) +# -------------------------------- +# User formal arguments, possibly preceded by location argument. +m4_define([b4_locuser_formals], +[b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals]) + + +# b4_locuser_args(LOC = yylocp) +# ----------------------------- +m4_define([b4_locuser_args], +[b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args]) + + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. +m4_define([b4_lhs_value], +[b4_symbol_value([(*yyvalp)], [$1], [$2])]) + + +# b4_rhs_data(RULE-LENGTH, POS) +# ----------------------------- +# See README. +m4_define([b4_rhs_data], +[YY_CAST (yyGLRStackItem const *, yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate]) + + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# Expansion of $$ or $$, for symbol SYMBOL-NUM. +m4_define([b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yyval], [$3], [$4])]) + + + +## ----------- ## +## Locations. ## +## ----------- ## + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(*yylocp)]) + + +# b4_rhs_location(RULE-LENGTH, NUM) +# --------------------------------- +# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[(b4_rhs_data([$1], [$2]).yyloc)]) + + +# b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM) +# --------------------------------------------------- +m4_define([b4_call_merger], +[b4_case([$1], + [ b4_symbol_if([$3], [has_type], + [yy0->b4_symbol($3, slot) = $2 (*yy0, *yy1);], + [*yy0 = $2 (*yy0, *yy1);])])]) + + +## -------------- ## +## Declarations. ## +## -------------- ## + +# b4_shared_declarations +# ---------------------- +# Declaration that might either go into the header (if --header) +# or open coded in the parser body. glr.cc has its own definition. +m4_if(b4_skeleton, ["glr.c"], +[m4_define([b4_shared_declarations], +[b4_declare_yydebug[ +]b4_percent_code_get([[requires]])[ +]b4_token_enums[ +]b4_declare_yylstype[ +int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[); +]b4_percent_code_get([[provides]])[]dnl +]) +]) + +## -------------- ## +## Output files. ## +## -------------- ## + +# Unfortunately the order of generation between the header and the +# implementation file matters (for glr.c) because of the current +# implementation of api.value.type=union. In that case we still use a +# union for YYSTYPE, but we generate the contents of this union when +# setting up YYSTYPE. This is needed for other aspects, such as +# defining yy_symbol_value_print, since we need to now the name of the +# members of this union. +# +# To avoid this issue, just generate the header before the +# implementation file. But we should also make them more independent. + +# ----------------- # +# The header file. # +# ----------------- # + +# glr.cc produces its own header. +b4_glr_cc_if([], +[b4_header_if( +[b4_output_begin([b4_spec_header_file]) +b4_copyright([Skeleton interface for Bison GLR parsers in C], + [2002-2015, 2018-2021])[ +]b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_shared_declarations[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[ +]b4_output_end[ +]])]) + + +# ------------------------- # +# The implementation file. # +# ------------------------- # + +b4_output_begin([b4_parser_file_name]) +b4_copyright([Skeleton implementation for Bison GLR parsers in C], + [2002-2015, 2018-2021])[ +/* C GLR parser skeleton written by Paul Hilfinger. */ + +]b4_disclaimer[ +]b4_identification[ + +]b4_percent_code_get([[top]])[ +]m4_if(b4_api_prefix, [yy], [], +[[/* Substitute the type names. */ +#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ +#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[ +]m4_if(b4_prefix, [yy], [], +[[/* Substitute the variable and function names. */ +#define ]b4_glr_cc_if([yy_parse_impl], [yyparse])[ ]b4_prefix[]b4_glr_cc_if([_parse_impl], [parse])[ +#define yylex ]b4_prefix[lex +#define yyerror ]b4_prefix[error +#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[ +#define yylval ]b4_prefix[lval +#define yychar ]b4_prefix[char +#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ +#define yylloc ]b4_prefix[lloc]])]))[ + +]b4_user_pre_prologue[ +]b4_cast_define[ +]b4_null_define[ + +]b4_header_if([[#include ]b4_percent_define_get([[api.header.include]])], + [b4_shared_declarations])[ + +]b4_glr_cc_if([b4_glr_cc_setup], + [b4_declare_symbol_enum])[ + +/* Default (constant) value used for initialization for null + right-hand sides. Unlike the standard yacc.c template, here we set + the default value of $$ to a zeroed-out value. Since the default + value is undefined, this behavior is technically correct. */ +static YYSTYPE yyval_default;]b4_locations_if([[ +static YYLTYPE yyloc_default][]b4_yyloc_default;])[ + +]b4_user_post_prologue[ +]b4_percent_code_get[]dnl + +[#include +#include +#include +#include +#include + +]b4_c99_int_type_define[ +]b4_sizes_types_define[ + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif +]b4_has_translations_if([ +#ifndef N_ +# define N_(Msgid) Msgid +#endif +])[ + +#ifndef YYFREE +# define YYFREE free +#endif +#ifndef YYMALLOC +# define YYMALLOC malloc +#endif +#ifndef YYREALLOC +# define YYREALLOC realloc +#endif + +#ifdef __cplusplus + typedef bool yybool; +# define yytrue true +# define yyfalse false +#else + /* When we move to stdbool, get rid of the various casts to yybool. */ + typedef signed char yybool; +# define yytrue 1 +# define yyfalse 0 +#endif + +#ifndef YYSETJMP +# include +# define YYJMP_BUF jmp_buf +# define YYSETJMP(Env) setjmp (Env) +/* Pacify Clang and ICC. */ +# define YYLONGJMP(Env, Val) \ + do { \ + longjmp (Env, Val); \ + YY_ASSERT (0); \ + } while (yyfalse) +#endif + +]b4_attribute_define([noreturn])[ + +]b4_parse_assert_if([[#ifdef NDEBUG +# define YY_ASSERT(E) ((void) (0 && (E))) +#else +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_ASSERT(E) assert (E) +#endif +]], +[[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL ]b4_final_state_number[ +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST ]b4_last[ + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS ]b4_tokens_number[ +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS ]b4_nterms_number[ +/* YYNRULES -- Number of rules. */ +#define YYNRULES ]b4_rules_number[ +/* YYNSTATES -- Number of states. */ +#define YYNSTATES ]b4_states_number[ +/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ +#define YYMAXRHS ]b4_r2_max[ +/* YYMAXLEFT -- Maximum number of symbols to the left of a handle + accessed by $0, $-1, etc., in any rule. */ +#define YYMAXLEFT ]b4_max_left_semantic_context[ + +/* YYMAXUTOK -- Last valid token kind. */ +#define YYMAXUTOK ]b4_code_max[ + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +]b4_api_token_raw_if(dnl +[[#define YYTRANSLATE(YYX) YY_CAST (yysymbol_kind_t, YYX)]], +[[#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : ]b4_symbol_prefix[YYUNDEF) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const ]b4_int_type_for([b4_translate])[ yytranslate[] = +{ + ]b4_translate[ +};]])[ + +#if ]b4_api_PREFIX[DEBUG +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const ]b4_int_type_for([b4_rline])[ yyrline[] = +{ + ]b4_rline[ +}; +#endif + +#define YYPACT_NINF (]b4_pact_ninf[) +#define YYTABLE_NINF (]b4_table_ninf[) + +]b4_parser_tables_define[ + +/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ +static const ]b4_int_type_for([b4_dprec])[ yydprec[] = +{ + ]b4_dprec[ +}; + +/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ +static const ]b4_int_type_for([b4_merger])[ yymerger[] = +{ + ]b4_merger[ +}; + +/* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as + in the case of predicates. */ +static const yybool yyimmediate[] = +{ + ]b4_immediate[ +}; + +/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of + list of conflicting reductions corresponding to action entry for + state STATE-NUM in yytable. 0 means no conflicts. The list in + yyconfl is terminated by a rule number of 0. */ +static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = +{ + ]b4_conflict_list_heads[ +}; + +/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by + 0, pointed into by YYCONFLP. */ +]dnl Do not use b4_int_type_for here, since there are places where +dnl pointers onto yyconfl are taken, whose type is "short*". +dnl We probably ought to introduce a type for confl. +[static const short yyconfl[] = +{ + ]b4_conflicting_rules[ +}; + +]b4_locations_if([[ +]b4_yylloc_default_define[ +# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) +]])[ + +]b4_pure_if( +[ +#undef yynerrs +#define yynerrs (yystackp->yyerrcnt) +#undef yychar +#define yychar (yystackp->yyrawchar) +#undef yylval +#define yylval (yystackp->yyval) +#undef yylloc +#define yylloc (yystackp->yyloc) +m4_if(b4_prefix[], [yy], [], +[#define b4_prefix[]nerrs yynerrs +#define b4_prefix[]char yychar +#define b4_prefix[]lval yylval +#define b4_prefix[]lloc yylloc])], +[YYSTYPE yylval;]b4_locations_if([[ +YYLTYPE yylloc;]])[ + +int yynerrs; +int yychar;])[ + +enum { YYENOMEM = -2 }; + +typedef enum { yyok, yyaccept, yyabort, yyerr, yynomem } YYRESULTTAG; + +#define YYCHK(YYE) \ + do { \ + YYRESULTTAG yychk_flag = YYE; \ + if (yychk_flag != yyok) \ + return yychk_flag; \ + } while (0) + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH ]b4_stack_depth_init[ +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH ]b4_stack_depth_max[ +#endif + +/* Minimum number of free items on the stack allowed after an + allocation. This is to allow allocation and initialization + to be completed by functions that call yyexpandGLRStack before the + stack is expanded, thus insuring that all necessary pointers get + properly redirected to new data. */ +#define YYHEADROOM 2 + +#ifndef YYSTACKEXPANDABLE +# define YYSTACKEXPANDABLE 1 +#endif + +#if YYSTACKEXPANDABLE +# define YY_RESERVE_GLRSTACK(Yystack) \ + do { \ + if (Yystack->yyspaceLeft < YYHEADROOM) \ + yyexpandGLRStack (Yystack); \ + } while (0) +#else +# define YY_RESERVE_GLRSTACK(Yystack) \ + do { \ + if (Yystack->yyspaceLeft < YYHEADROOM) \ + yyMemoryExhausted (Yystack); \ + } while (0) +#endif + +/** State numbers. */ +typedef int yy_state_t; + +/** Rule numbers. */ +typedef int yyRuleNum; + +/** Item references. */ +typedef short yyItemNum; + +typedef struct yyGLRState yyGLRState; +typedef struct yyGLRStateSet yyGLRStateSet; +typedef struct yySemanticOption yySemanticOption; +typedef union yyGLRStackItem yyGLRStackItem; +typedef struct yyGLRStack yyGLRStack; + +struct yyGLRState +{ + /** Type tag: always true. */ + yybool yyisState; + /** Type tag for yysemantics. If true, yyval applies, otherwise + * yyfirstVal applies. */ + yybool yyresolved; + /** Number of corresponding LALR(1) machine state. */ + yy_state_t yylrState; + /** Preceding state in this stack */ + yyGLRState* yypred; + /** Source position of the last token produced by my symbol */ + YYPTRDIFF_T yyposn; + union { + /** First in a chain of alternative reductions producing the + * nonterminal corresponding to this state, threaded through + * yynext. */ + yySemanticOption* yyfirstVal; + /** Semantic value for this state. */ + YYSTYPE yyval; + } yysemantics;]b4_locations_if([[ + /** Source location for this state. */ + YYLTYPE yyloc;]])[ +}; + +struct yyGLRStateSet +{ + yyGLRState** yystates; + /** During nondeterministic operation, yylookaheadNeeds tracks which + * stacks have actually needed the current lookahead. During deterministic + * operation, yylookaheadNeeds[0] is not maintained since it would merely + * duplicate yychar != ]b4_symbol(empty, id)[. */ + yybool* yylookaheadNeeds; + YYPTRDIFF_T yysize; + YYPTRDIFF_T yycapacity; +}; + +struct yySemanticOption +{ + /** Type tag: always false. */ + yybool yyisState; + /** Rule number for this reduction */ + yyRuleNum yyrule; + /** The last RHS state in the list of states to be reduced. */ + yyGLRState* yystate; + /** The lookahead for this reduction. */ + int yyrawchar; + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ + /** Next sibling in chain of options. To facilitate merging, + * options are chained in decreasing order by address. */ + yySemanticOption* yynext; +}; + +/** Type of the items in the GLR stack. The yyisState field + * indicates which item of the union is valid. */ +union yyGLRStackItem { + yyGLRState yystate; + yySemanticOption yyoption; +}; + +struct yyGLRStack { + int yyerrState; +]b4_locations_if([[ /* To compute the location of the error token. */ + yyGLRStackItem yyerror_range[3];]])[ +]b4_pure_if( +[ + int yyerrcnt; + int yyrawchar; + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ +])[ + YYJMP_BUF yyexception_buffer; + yyGLRStackItem* yyitems; + yyGLRStackItem* yynextFree; + YYPTRDIFF_T yyspaceLeft; + yyGLRState* yysplitPoint; + yyGLRState* yylastDeleted; + yyGLRStateSet yytops; +}; + +#if YYSTACKEXPANDABLE +static void yyexpandGLRStack (yyGLRStack* yystackp); +#endif + +_Noreturn static void +yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg) +{ + if (yymsg != YY_NULLPTR) + yyerror (]b4_yyerror_args[yymsg); + YYLONGJMP (yystackp->yyexception_buffer, 1); +} + +_Noreturn static void +yyMemoryExhausted (yyGLRStack* yystackp) +{ + YYLONGJMP (yystackp->yyexception_buffer, 2); +} + +/** Accessing symbol of state YYSTATE. */ +static inline yysymbol_kind_t +yy_accessing_symbol (yy_state_t yystate) +{ + return YY_CAST (yysymbol_kind_t, yystos[yystate]); +} + +#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +]b4_parse_error_bmatch([simple\|verbose], +[[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + ]b4_tname[ +}; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +}]], +[[static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ +}]])[ +#endif + +/** Left-hand-side symbol for rule #YYRULE. */ +static inline yysymbol_kind_t +yylhsNonterm (yyRuleNum yyrule) +{ + return YY_CAST (yysymbol_kind_t, yyr1[yyrule]); +} + +#if ]b4_api_PREFIX[DEBUG + +# ifndef YYFPRINTF +# define YYFPRINTF fprintf +# endif + +# define YY_FPRINTF \ + YY_IGNORE_USELESS_CAST_BEGIN YY_FPRINTF_ + +# define YY_FPRINTF_(Args) \ + do { \ + YYFPRINTF Args; \ + YY_IGNORE_USELESS_CAST_END \ + } while (0) + +# define YY_DPRINTF \ + YY_IGNORE_USELESS_CAST_BEGIN YY_DPRINTF_ + +# define YY_DPRINTF_(Args) \ + do { \ + if (yydebug) \ + YYFPRINTF Args; \ + YY_IGNORE_USELESS_CAST_END \ + } while (0) + +]b4_yylocation_print_define[ + +]b4_yy_symbol_print_define[ + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ + do { \ + if (yydebug) \ + { \ + YY_FPRINTF ((stderr, "%s ", Title)); \ + yy_symbol_print (stderr, Kind, Value]b4_locuser_args([Location])[); \ + YY_FPRINTF ((stderr, "\n")); \ + } \ + } while (0) + +static inline void +yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk, + yyRuleNum yyrule]b4_user_formals[); + +# define YY_REDUCE_PRINT(Args) \ + do { \ + if (yydebug) \ + yy_reduce_print Args; \ + } while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; + +static void yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) + YY_ATTRIBUTE_UNUSED; +static void yypdumpstack (yyGLRStack* yystackp) + YY_ATTRIBUTE_UNUSED; + +#else /* !]b4_api_PREFIX[DEBUG */ + +# define YY_DPRINTF(Args) do {} while (yyfalse) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YY_REDUCE_PRINT(Args) + +#endif /* !]b4_api_PREFIX[DEBUG */ + +]b4_parse_error_case( + [simple], +[[]], +[[#ifndef yystrlen +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +#endif + +]b4_parse_error_bmatch( + [detailed\|verbose], +[[#ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +yystpcpy (char *yydest, const char *yysrc) +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +#endif]])[ + +]b4_parse_error_case( + [verbose], +[[#ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYPTRDIFF_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYPTRDIFF_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else + return yystrlen (yystr); +} +#endif +]])])[ + +/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting + * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred + * containing the pointer to the next state in the chain. */ +static void yyfillin (yyGLRStackItem *, int, int) YY_ATTRIBUTE_UNUSED; +static void +yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) +{ + int i; + yyGLRState *s = yyvsp[yylow0].yystate.yypred; + for (i = yylow0-1; i >= yylow1; i -= 1) + { +#if ]b4_api_PREFIX[DEBUG + yyvsp[i].yystate.yylrState = s->yylrState; +#endif + yyvsp[i].yystate.yyresolved = s->yyresolved; + if (s->yyresolved) + yyvsp[i].yystate.yysemantics.yyval = s->yysemantics.yyval; + else + /* The effect of using yyval or yyloc (in an immediate rule) is + * undefined. */ + yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULLPTR;]b4_locations_if([[ + yyvsp[i].yystate.yyloc = s->yyloc;]])[ + s = yyvsp[i].yystate.yypred = s->yypred; + } +} + +]m4_define([b4_yygetToken_call], + [[yygetToken (&yychar][]b4_pure_if([, yystackp])[]b4_user_args[)]])[ +/** If yychar is empty, fetch the next token. */ +static inline yysymbol_kind_t +yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals[) +{ + yysymbol_kind_t yytoken; +]b4_parse_param_use()dnl +[ if (*yycharp == ]b4_symbol(empty, id)[) + { + YY_DPRINTF ((stderr, "Reading a token\n"));]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + try + { +#endif // YY_EXCEPTIONS + *yycharp = ]b4_yylex[; +#if YY_EXCEPTIONS + } + catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc) + { + YY_DPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([ + yylloc = yyexc.location;])[ + yyerror (]b4_lyyerror_args[yyexc.what ()); + // Map errors caught in the scanner to the undefined token, + // so that error handling is started. However, record this + // with this special value of yychar. + *yycharp = ]b4_symbol(error, id)[; + } +#endif // YY_EXCEPTIONS]], [[ + *yycharp = ]b4_yylex[;]])[ + } + if (*yycharp <= ]b4_symbol(eof, [id])[) + { + *yycharp = ]b4_symbol(eof, [id])[; + yytoken = ]b4_symbol_prefix[YYEOF; + YY_DPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (*yycharp); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + return yytoken; +} + +/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in + * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. + * For convenience, always return YYLOW1. */ +static inline int yyfill (yyGLRStackItem *, int *, int, yybool) + YY_ATTRIBUTE_UNUSED; +static inline int +yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) +{ + if (!yynormal && yylow1 < *yylow) + { + yyfillin (yyvsp, *yylow, yylow1); + *yylow = yylow1; + } + return yylow1; +} + +/** Perform user action for rule number YYN, with RHS length YYRHSLEN, + * and top stack item YYVSP. YYLVALP points to place to put semantic + * value ($$), and yylocp points to place for location information + * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, + * yyerr for YYERROR, yyabort for YYABORT, yynomem for YYNOMEM. */ +static YYRESULTTAG +yyuserAction (yyRuleNum yyrule, int yyrhslen, yyGLRStackItem* yyvsp, + yyGLRStack* yystackp, YYPTRDIFF_T yyk, + YYSTYPE* yyvalp]b4_locuser_formals[) +{ + const yybool yynormal YY_ATTRIBUTE_UNUSED = yystackp->yysplitPoint == YY_NULLPTR; + int yylow = 1; +]b4_parse_param_use([yyvalp], [yylocp])dnl +[ YY_USE (yyk); + YY_USE (yyrhslen); +# undef yyerrok +# define yyerrok (yystackp->yyerrState = 0) +# undef YYACCEPT +# define YYACCEPT return yyaccept +# undef YYABORT +# define YYABORT return yyabort +# undef YYNOMEM +# define YYNOMEM return yynomem +# undef YYERROR +# define YYERROR return yyerrok, yyerr +# undef YYRECOVERING +# define YYRECOVERING() (yystackp->yyerrState != 0) +# undef yyclearin +# define yyclearin (yychar = ]b4_symbol(empty, id)[) +# undef YYFILL +# define YYFILL(N) yyfill (yyvsp, &yylow, (N), yynormal) +# undef YYBACKUP +# define YYBACKUP(Token, Value) \ + return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \ + yyerrok, yyerr + + if (yyrhslen == 0) + *yyvalp = yyval_default; + else + *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yyval;]b4_locations_if([[ + /* Default location. */ + YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); + yystackp->yyerror_range[1].yystate.yyloc = *yylocp;]])[ + /* If yyk == -1, we are running a deferred action on a temporary + stack. In that case, YY_REDUCE_PRINT must not play with YYFILL, + so pretend the stack is "normal". */ + YY_REDUCE_PRINT ((yynormal || yyk == -1, yyvsp, yyk, yyrule]b4_user_args[));]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error; + try + { +#endif // YY_EXCEPTIONS]])[ + switch (yyrule) + { +]b4_user_actions[ + default: break; + }]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + } + catch (const syntax_error& yyexc) + { + YY_DPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([ + *yylocp = yyexc.location;])[ + yyerror (]b4_yyerror_args[yyexc.what ()); + YYERROR; + } +#endif // YY_EXCEPTIONS]])[ + YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), yyvalp, yylocp); + + return yyok; +# undef yyerrok +# undef YYABORT +# undef YYACCEPT +# undef YYNOMEM +# undef YYERROR +# undef YYBACKUP +# undef yyclearin +# undef YYRECOVERING +} + + +static void +yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) +{ + YY_USE (yy0); + YY_USE (yy1); + + switch (yyn) + { +]b4_mergers[ + default: break; + } +} + + /* Bison grammar-table manipulation. */ + +]b4_yydestruct_define[ + +/** Number of symbols composing the right hand side of rule #RULE. */ +static inline int +yyrhsLength (yyRuleNum yyrule) +{ + return yyr2[yyrule]; +} + +static void +yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) +{ + if (yys->yyresolved) + yydestruct (yymsg, yy_accessing_symbol (yys->yylrState), + &yys->yysemantics.yyval]b4_locuser_args([&yys->yyloc])[); + else + { +#if ]b4_api_PREFIX[DEBUG + if (yydebug) + { + if (yys->yysemantics.yyfirstVal) + YY_FPRINTF ((stderr, "%s unresolved", yymsg)); + else + YY_FPRINTF ((stderr, "%s incomplete", yymsg)); + YY_SYMBOL_PRINT ("", yy_accessing_symbol (yys->yylrState), YY_NULLPTR, &yys->yyloc); + } +#endif + + if (yys->yysemantics.yyfirstVal) + { + yySemanticOption *yyoption = yys->yysemantics.yyfirstVal; + yyGLRState *yyrh; + int yyn; + for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); + yyn > 0; + yyrh = yyrh->yypred, yyn -= 1) + yydestroyGLRState (yymsg, yyrh]b4_user_args[); + } + } +} + +#define yypact_value_is_default(Yyn) \ + ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[ + +/** True iff LR state YYSTATE has only a default reduction (regardless + * of token). */ +static inline yybool +yyisDefaultedState (yy_state_t yystate) +{ + return yypact_value_is_default (yypact[yystate]); +} + +/** The default reduction for YYSTATE, assuming it has one. */ +static inline yyRuleNum +yydefaultAction (yy_state_t yystate) +{ + return yydefact[yystate]; +} + +#define yytable_value_is_error(Yyn) \ + ]b4_table_value_equals([[table]], [[Yyn]], [b4_table_ninf], [YYTABLE_NINF])[ + +/** The action to take in YYSTATE on seeing YYTOKEN. + * Result R means + * R < 0: Reduce on rule -R. + * R = 0: Error. + * R > 0: Shift to state R. + * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list + * of conflicting reductions. + */ +static inline int +yygetLRActions (yy_state_t yystate, yysymbol_kind_t yytoken, const short** yyconflicts) +{ + int yyindex = yypact[yystate] + yytoken; + if (yytoken == ]b4_symbol(error, kind)[) + { + // This is the error token. + *yyconflicts = yyconfl; + return 0; + } + else if (yyisDefaultedState (yystate) + || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) + { + *yyconflicts = yyconfl; + return -yydefact[yystate]; + } + else if (! yytable_value_is_error (yytable[yyindex])) + { + *yyconflicts = yyconfl + yyconflp[yyindex]; + return yytable[yyindex]; + } + else + { + *yyconflicts = yyconfl + yyconflp[yyindex]; + return 0; + } +} + +/** Compute post-reduction state. + * \param yystate the current state + * \param yysym the nonterminal to push on the stack + */ +static inline yy_state_t +yyLRgotoState (yy_state_t yystate, yysymbol_kind_t yysym) +{ + int yyr = yypgoto[yysym - YYNTOKENS] + yystate; + if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) + return yytable[yyr]; + else + return yydefgoto[yysym - YYNTOKENS]; +} + +static inline yybool +yyisShiftAction (int yyaction) +{ + return 0 < yyaction; +} + +static inline yybool +yyisErrorAction (int yyaction) +{ + return yyaction == 0; +} + + /* GLRStates */ + +/** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state + * if YYISSTATE, and otherwise a semantic option. Callers should call + * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient + * headroom. */ + +static inline yyGLRStackItem* +yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState) +{ + yyGLRStackItem* yynewItem = yystackp->yynextFree; + yystackp->yyspaceLeft -= 1; + yystackp->yynextFree += 1; + yynewItem->yystate.yyisState = yyisState; + return yynewItem; +} + +/** Add a new semantic action that will execute the action for rule + * YYRULE on the semantic values in YYRHS to the list of + * alternative actions for YYSTATE. Assumes that YYRHS comes from + * stack #YYK of *YYSTACKP. */ +static void +yyaddDeferredAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyGLRState* yystate, + yyGLRState* yyrhs, yyRuleNum yyrule) +{ + yySemanticOption* yynewOption = + &yynewGLRStackItem (yystackp, yyfalse)->yyoption; + YY_ASSERT (!yynewOption->yyisState); + yynewOption->yystate = yyrhs; + yynewOption->yyrule = yyrule; + if (yystackp->yytops.yylookaheadNeeds[yyk]) + { + yynewOption->yyrawchar = yychar; + yynewOption->yyval = yylval;]b4_locations_if([ + yynewOption->yyloc = yylloc;])[ + } + else + yynewOption->yyrawchar = ]b4_symbol(empty, id)[; + yynewOption->yynext = yystate->yysemantics.yyfirstVal; + yystate->yysemantics.yyfirstVal = yynewOption; + + YY_RESERVE_GLRSTACK (yystackp); +} + + /* GLRStacks */ + +/** Initialize YYSET to a singleton set containing an empty stack. */ +static yybool +yyinitStateSet (yyGLRStateSet* yyset) +{ + yyset->yysize = 1; + yyset->yycapacity = 16; + yyset->yystates + = YY_CAST (yyGLRState**, + YYMALLOC (YY_CAST (YYSIZE_T, yyset->yycapacity) + * sizeof yyset->yystates[0])); + if (! yyset->yystates) + return yyfalse; + yyset->yystates[0] = YY_NULLPTR; + yyset->yylookaheadNeeds + = YY_CAST (yybool*, + YYMALLOC (YY_CAST (YYSIZE_T, yyset->yycapacity) + * sizeof yyset->yylookaheadNeeds[0])); + if (! yyset->yylookaheadNeeds) + { + YYFREE (yyset->yystates); + return yyfalse; + } + memset (yyset->yylookaheadNeeds, + 0, + YY_CAST (YYSIZE_T, yyset->yycapacity) * sizeof yyset->yylookaheadNeeds[0]); + return yytrue; +} + +static void yyfreeStateSet (yyGLRStateSet* yyset) +{ + YYFREE (yyset->yystates); + YYFREE (yyset->yylookaheadNeeds); +} + +/** Initialize *YYSTACKP to a single empty stack, with total maximum + * capacity for all stacks of YYSIZE. */ +static yybool +yyinitGLRStack (yyGLRStack* yystackp, YYPTRDIFF_T yysize) +{ + yystackp->yyerrState = 0; + yynerrs = 0; + yystackp->yyspaceLeft = yysize; + yystackp->yyitems + = YY_CAST (yyGLRStackItem*, + YYMALLOC (YY_CAST (YYSIZE_T, yysize) + * sizeof yystackp->yynextFree[0])); + if (!yystackp->yyitems) + return yyfalse; + yystackp->yynextFree = yystackp->yyitems; + yystackp->yysplitPoint = YY_NULLPTR; + yystackp->yylastDeleted = YY_NULLPTR; + return yyinitStateSet (&yystackp->yytops); +} + + +#if YYSTACKEXPANDABLE +# define YYRELOC(YYFROMITEMS, YYTOITEMS, YYX, YYTYPE) \ + &((YYTOITEMS) \ + - ((YYFROMITEMS) - YY_REINTERPRET_CAST (yyGLRStackItem*, (YYX))))->YYTYPE + +/** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the + stack from outside should be considered invalid after this call. + We always expand when there are 1 or fewer items left AFTER an + allocation, so that we can avoid having external pointers exist + across an allocation. */ +static void +yyexpandGLRStack (yyGLRStack* yystackp) +{ + yyGLRStackItem* yynewItems; + yyGLRStackItem* yyp0, *yyp1; + YYPTRDIFF_T yynewSize; + YYPTRDIFF_T yyn; + YYPTRDIFF_T yysize = yystackp->yynextFree - yystackp->yyitems; + if (YYMAXDEPTH - YYHEADROOM < yysize) + yyMemoryExhausted (yystackp); + yynewSize = 2*yysize; + if (YYMAXDEPTH < yynewSize) + yynewSize = YYMAXDEPTH; + yynewItems + = YY_CAST (yyGLRStackItem*, + YYMALLOC (YY_CAST (YYSIZE_T, yynewSize) + * sizeof yynewItems[0])); + if (! yynewItems) + yyMemoryExhausted (yystackp); + for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize; + 0 < yyn; + yyn -= 1, yyp0 += 1, yyp1 += 1) + { + *yyp1 = *yyp0; + if (*YY_REINTERPRET_CAST (yybool *, yyp0)) + { + yyGLRState* yys0 = &yyp0->yystate; + yyGLRState* yys1 = &yyp1->yystate; + if (yys0->yypred != YY_NULLPTR) + yys1->yypred = + YYRELOC (yyp0, yyp1, yys0->yypred, yystate); + if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULLPTR) + yys1->yysemantics.yyfirstVal = + YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); + } + else + { + yySemanticOption* yyv0 = &yyp0->yyoption; + yySemanticOption* yyv1 = &yyp1->yyoption; + if (yyv0->yystate != YY_NULLPTR) + yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); + if (yyv0->yynext != YY_NULLPTR) + yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); + } + } + if (yystackp->yysplitPoint != YY_NULLPTR) + yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems, + yystackp->yysplitPoint, yystate); + + for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1) + if (yystackp->yytops.yystates[yyn] != YY_NULLPTR) + yystackp->yytops.yystates[yyn] = + YYRELOC (yystackp->yyitems, yynewItems, + yystackp->yytops.yystates[yyn], yystate); + YYFREE (yystackp->yyitems); + yystackp->yyitems = yynewItems; + yystackp->yynextFree = yynewItems + yysize; + yystackp->yyspaceLeft = yynewSize - yysize; +} +#endif + +static void +yyfreeGLRStack (yyGLRStack* yystackp) +{ + YYFREE (yystackp->yyitems); + yyfreeStateSet (&yystackp->yytops); +} + +/** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the + * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as + * YYS. */ +static inline void +yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys) +{ + if (yystackp->yysplitPoint != YY_NULLPTR && yystackp->yysplitPoint > yys) + yystackp->yysplitPoint = yys; +} + +/** Invalidate stack #YYK in *YYSTACKP. */ +static inline void +yymarkStackDeleted (yyGLRStack* yystackp, YYPTRDIFF_T yyk) +{ + if (yystackp->yytops.yystates[yyk] != YY_NULLPTR) + yystackp->yylastDeleted = yystackp->yytops.yystates[yyk]; + yystackp->yytops.yystates[yyk] = YY_NULLPTR; +} + +/** Undelete the last stack in *YYSTACKP that was marked as deleted. Can + only be done once after a deletion, and only when all other stacks have + been deleted. */ +static void +yyundeleteLastStack (yyGLRStack* yystackp) +{ + if (yystackp->yylastDeleted == YY_NULLPTR || yystackp->yytops.yysize != 0) + return; + yystackp->yytops.yystates[0] = yystackp->yylastDeleted; + yystackp->yytops.yysize = 1; + YY_DPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); + yystackp->yylastDeleted = YY_NULLPTR; +} + +static inline void +yyremoveDeletes (yyGLRStack* yystackp) +{ + YYPTRDIFF_T yyi, yyj; + yyi = yyj = 0; + while (yyj < yystackp->yytops.yysize) + { + if (yystackp->yytops.yystates[yyi] == YY_NULLPTR) + { + if (yyi == yyj) + YY_DPRINTF ((stderr, "Removing dead stacks.\n")); + yystackp->yytops.yysize -= 1; + } + else + { + yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi]; + /* In the current implementation, it's unnecessary to copy + yystackp->yytops.yylookaheadNeeds[yyi] since, after + yyremoveDeletes returns, the parser immediately either enters + deterministic operation or shifts a token. However, it doesn't + hurt, and the code might evolve to need it. */ + yystackp->yytops.yylookaheadNeeds[yyj] = + yystackp->yytops.yylookaheadNeeds[yyi]; + if (yyj != yyi) + YY_DPRINTF ((stderr, "Rename stack %ld -> %ld.\n", + YY_CAST (long, yyi), YY_CAST (long, yyj))); + yyj += 1; + } + yyi += 1; + } +} + +/** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic + * value *YYVALP and source location *YYLOCP. */ +static inline void +yyglrShift (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState, + YYPTRDIFF_T yyposn, + YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[) +{ + yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; + + yynewState->yylrState = yylrState; + yynewState->yyposn = yyposn; + yynewState->yyresolved = yytrue; + yynewState->yypred = yystackp->yytops.yystates[yyk]; + yynewState->yysemantics.yyval = *yyvalp;]b4_locations_if([ + yynewState->yyloc = *yylocp;])[ + yystackp->yytops.yystates[yyk] = yynewState; + + YY_RESERVE_GLRSTACK (yystackp); +} + +/** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with the (unresolved) + * semantic value of YYRHS under the action for YYRULE. */ +static inline void +yyglrShiftDefer (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yy_state_t yylrState, + YYPTRDIFF_T yyposn, yyGLRState* yyrhs, yyRuleNum yyrule) +{ + yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; + YY_ASSERT (yynewState->yyisState); + + yynewState->yylrState = yylrState; + yynewState->yyposn = yyposn; + yynewState->yyresolved = yyfalse; + yynewState->yypred = yystackp->yytops.yystates[yyk]; + yynewState->yysemantics.yyfirstVal = YY_NULLPTR; + yystackp->yytops.yystates[yyk] = yynewState; + + /* Invokes YY_RESERVE_GLRSTACK. */ + yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule); +} + +#if ]b4_api_PREFIX[DEBUG + +/*----------------------------------------------------------------------. +| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. | +`----------------------------------------------------------------------*/ + +static inline void +yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, YYPTRDIFF_T yyk, + yyRuleNum yyrule]b4_user_formals[) +{ + int yynrhs = yyrhsLength (yyrule);]b4_locations_if([ + int yylow = 1;])[ + int yyi; + YY_FPRINTF ((stderr, "Reducing stack %ld by rule %d (line %d):\n", + YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule])); + if (! yynormal) + yyfillin (yyvsp, 1, -yynrhs); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YY_FPRINTF ((stderr, " $%d = ", yyi + 1)); + yy_symbol_print (stderr, + yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].yystate.yylrState), + &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yyval]b4_locations_if([, + &]b4_rhs_location(yynrhs, yyi + 1))[]dnl + b4_user_args[); + if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved) + YY_FPRINTF ((stderr, " (unresolved)")); + YY_FPRINTF ((stderr, "\n")); + } +} +#endif + +/** Pop the symbols consumed by reduction #YYRULE from the top of stack + * #YYK of *YYSTACKP, and perform the appropriate semantic action on their + * semantic values. Assumes that all ambiguities in semantic values + * have been previously resolved. Set *YYVALP to the resulting value, + * and *YYLOCP to the computed location (if any). Return value is as + * for userAction. */ +static inline YYRESULTTAG +yydoAction (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule, + YYSTYPE* yyvalp]b4_locuser_formals[) +{ + int yynrhs = yyrhsLength (yyrule); + + if (yystackp->yysplitPoint == YY_NULLPTR) + { + /* Standard special case: single stack. */ + yyGLRStackItem* yyrhs + = YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yytops.yystates[yyk]); + YY_ASSERT (yyk == 0); + yystackp->yynextFree -= yynrhs; + yystackp->yyspaceLeft += yynrhs; + yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate; + return yyuserAction (yyrule, yynrhs, yyrhs, yystackp, yyk, + yyvalp]b4_locuser_args[); + } + else + { + yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + yyGLRState* yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred + = yystackp->yytops.yystates[yyk]; + int yyi;]b4_locations_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[ + for (yyi = 0; yyi < yynrhs; yyi += 1) + { + yys = yys->yypred; + YY_ASSERT (yys); + } + yyupdateSplit (yystackp, yys); + yystackp->yytops.yystates[yyk] = yys; + return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + yystackp, yyk, yyvalp]b4_locuser_args[); + } +} + +/** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE, + * and push back on the resulting nonterminal symbol. Perform the + * semantic action associated with YYRULE and store its value with the + * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently + * unambiguous. Otherwise, store the deferred semantic action with + * the new state. If the new state would have an identical input + * position, LR state, and predecessor to an existing state on the stack, + * it is identified with that existing state, eliminating stack #YYK from + * *YYSTACKP. In this case, the semantic value is + * added to the options for the existing state's semantic value. + */ +static inline YYRESULTTAG +yyglrReduce (yyGLRStack* yystackp, YYPTRDIFF_T yyk, yyRuleNum yyrule, + yybool yyforceEval]b4_user_formals[) +{ + YYPTRDIFF_T yyposn = yystackp->yytops.yystates[yyk]->yyposn; + + if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR) + { + YYSTYPE yyval;]b4_locations_if([[ + YYLTYPE yyloc;]])[ + + YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yyval]b4_locuser_args([&yyloc])[); + if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR) + YY_DPRINTF ((stderr, + "Parse on stack %ld rejected by rule %d (line %d).\n", + YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule])); + if (yyflag != yyok) + return yyflag; + yyglrShift (yystackp, yyk, + yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState, + yylhsNonterm (yyrule)), + yyposn, &yyval]b4_locations_if([, &yyloc])[); + } + else + { + YYPTRDIFF_T yyi; + int yyn; + yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk]; + yy_state_t yynewLRState; + + for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); + 0 < yyn; yyn -= 1) + { + yys = yys->yypred; + YY_ASSERT (yys); + } + yyupdateSplit (yystackp, yys); + yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); + YY_DPRINTF ((stderr, + "Reduced stack %ld by rule %d (line %d); action deferred. " + "Now in state %d.\n", + YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule], + yynewLRState)); + for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) + if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR) + { + yyGLRState *yysplit = yystackp->yysplitPoint; + yyGLRState *yyp = yystackp->yytops.yystates[yyi]; + while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) + { + if (yyp->yylrState == yynewLRState && yyp->yypred == yys) + { + yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule); + yymarkStackDeleted (yystackp, yyk); + YY_DPRINTF ((stderr, "Merging stack %ld into stack %ld.\n", + YY_CAST (long, yyk), YY_CAST (long, yyi))); + return yyok; + } + yyp = yyp->yypred; + } + } + yystackp->yytops.yystates[yyk] = yys; + yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule); + } + return yyok; +} + +static YYPTRDIFF_T +yysplitStack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) +{ + if (yystackp->yysplitPoint == YY_NULLPTR) + { + YY_ASSERT (yyk == 0); + yystackp->yysplitPoint = yystackp->yytops.yystates[yyk]; + } + if (yystackp->yytops.yycapacity <= yystackp->yytops.yysize) + { + YYPTRDIFF_T state_size = YYSIZEOF (yystackp->yytops.yystates[0]); + YYPTRDIFF_T half_max_capacity = YYSIZE_MAXIMUM / 2 / state_size; + if (half_max_capacity < yystackp->yytops.yycapacity) + yyMemoryExhausted (yystackp); + yystackp->yytops.yycapacity *= 2; + + { + yyGLRState** yynewStates + = YY_CAST (yyGLRState**, + YYREALLOC (yystackp->yytops.yystates, + (YY_CAST (YYSIZE_T, yystackp->yytops.yycapacity) + * sizeof yynewStates[0]))); + if (yynewStates == YY_NULLPTR) + yyMemoryExhausted (yystackp); + yystackp->yytops.yystates = yynewStates; + } + + { + yybool* yynewLookaheadNeeds + = YY_CAST (yybool*, + YYREALLOC (yystackp->yytops.yylookaheadNeeds, + (YY_CAST (YYSIZE_T, yystackp->yytops.yycapacity) + * sizeof yynewLookaheadNeeds[0]))); + if (yynewLookaheadNeeds == YY_NULLPTR) + yyMemoryExhausted (yystackp); + yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds; + } + } + yystackp->yytops.yystates[yystackp->yytops.yysize] + = yystackp->yytops.yystates[yyk]; + yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize] + = yystackp->yytops.yylookaheadNeeds[yyk]; + yystackp->yytops.yysize += 1; + return yystackp->yytops.yysize - 1; +} + +/** True iff YYY0 and YYY1 represent identical options at the top level. + * That is, they represent the same rule applied to RHS symbols + * that produce the same terminal symbols. */ +static yybool +yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1) +{ + if (yyy0->yyrule == yyy1->yyrule) + { + yyGLRState *yys0, *yys1; + int yyn; + for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, + yyn = yyrhsLength (yyy0->yyrule); + yyn > 0; + yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) + if (yys0->yyposn != yys1->yyposn) + return yyfalse; + return yytrue; + } + else + return yyfalse; +} + +/** Assuming identicalOptions (YYY0,YYY1), destructively merge the + * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */ +static void +yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1) +{ + yyGLRState *yys0, *yys1; + int yyn; + for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, + yyn = yyrhsLength (yyy0->yyrule); + 0 < yyn; + yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) + { + if (yys0 == yys1) + break; + else if (yys0->yyresolved) + { + yys1->yyresolved = yytrue; + yys1->yysemantics.yyval = yys0->yysemantics.yyval; + } + else if (yys1->yyresolved) + { + yys0->yyresolved = yytrue; + yys0->yysemantics.yyval = yys1->yysemantics.yyval; + } + else + { + yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal; + yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal; + while (yytrue) + { + if (yyz1 == *yyz0p || yyz1 == YY_NULLPTR) + break; + else if (*yyz0p == YY_NULLPTR) + { + *yyz0p = yyz1; + break; + } + else if (*yyz0p < yyz1) + { + yySemanticOption* yyz = *yyz0p; + *yyz0p = yyz1; + yyz1 = yyz1->yynext; + (*yyz0p)->yynext = yyz; + } + yyz0p = &(*yyz0p)->yynext; + } + yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal; + } + } +} + +/** Y0 and Y1 represent two possible actions to take in a given + * parsing state; return 0 if no combination is possible, + * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ +static int +yypreference (yySemanticOption* y0, yySemanticOption* y1) +{ + yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule; + int p0 = yydprec[r0], p1 = yydprec[r1]; + + if (p0 == p1) + { + if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) + return 0; + else + return 1; + } + if (p0 == 0 || p1 == 0) + return 0; + if (p0 < p1) + return 3; + if (p1 < p0) + return 2; + return 0; +} + +static YYRESULTTAG +yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[); + + +/** Resolve the previous YYN states starting at and including state YYS + * on *YYSTACKP. If result != yyok, some states may have been left + * unresolved possibly with empty semantic option chains. Regardless + * of whether result = yyok, each state has been left with consistent + * data so that yydestroyGLRState can be invoked if necessary. */ +static YYRESULTTAG +yyresolveStates (yyGLRState* yys, int yyn, + yyGLRStack* yystackp]b4_user_formals[) +{ + if (0 < yyn) + { + YY_ASSERT (yys->yypred); + YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[)); + if (! yys->yyresolved) + YYCHK (yyresolveValue (yys, yystackp]b4_user_args[)); + } + return yyok; +} + +/** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its + * user action, and return the semantic value and location in *YYVALP + * and *YYLOCP. Regardless of whether result = yyok, all RHS states + * have been destroyed (assuming the user action destroys all RHS + * semantic values if invoked). */ +static YYRESULTTAG +yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp, + YYSTYPE* yyvalp]b4_locuser_formals[) +{ + yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + int yynrhs = yyrhsLength (yyopt->yyrule); + YYRESULTTAG yyflag = + yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[); + if (yyflag != yyok) + { + yyGLRState *yys; + for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1) + yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); + return yyflag; + } + + yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[ + { + int yychar_current = yychar; + YYSTYPE yylval_current = yylval;]b4_locations_if([ + YYLTYPE yylloc_current = yylloc;])[ + yychar = yyopt->yyrawchar; + yylval = yyopt->yyval;]b4_locations_if([ + yylloc = yyopt->yyloc;])[ + yyflag = yyuserAction (yyopt->yyrule, yynrhs, + yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + yystackp, -1, yyvalp]b4_locuser_args[); + yychar = yychar_current; + yylval = yylval_current;]b4_locations_if([ + yylloc = yylloc_current;])[ + } + return yyflag; +} + +#if ]b4_api_PREFIX[DEBUG +static void +yyreportTree (yySemanticOption* yyx, int yyindent) +{ + int yynrhs = yyrhsLength (yyx->yyrule); + int yyi; + yyGLRState* yys; + yyGLRState* yystates[1 + YYMAXRHS]; + yyGLRState yyleftmost_state; + + for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) + yystates[yyi] = yys; + if (yys == YY_NULLPTR) + { + yyleftmost_state.yyposn = 0; + yystates[0] = &yyleftmost_state; + } + else + yystates[0] = yys; + + if (yyx->yystate->yyposn < yys->yyposn + 1) + YY_FPRINTF ((stderr, "%*s%s -> \n", + yyindent, "", yysymbol_name (yylhsNonterm (yyx->yyrule)), + yyx->yyrule - 1)); + else + YY_FPRINTF ((stderr, "%*s%s -> \n", + yyindent, "", yysymbol_name (yylhsNonterm (yyx->yyrule)), + yyx->yyrule - 1, YY_CAST (long, yys->yyposn + 1), + YY_CAST (long, yyx->yystate->yyposn))); + for (yyi = 1; yyi <= yynrhs; yyi += 1) + { + if (yystates[yyi]->yyresolved) + { + if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) + YY_FPRINTF ((stderr, "%*s%s \n", yyindent+2, "", + yysymbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)))); + else + YY_FPRINTF ((stderr, "%*s%s \n", yyindent+2, "", + yysymbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)), + YY_CAST (long, yystates[yyi-1]->yyposn + 1), + YY_CAST (long, yystates[yyi]->yyposn))); + } + else + yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); + } +} +#endif + +static YYRESULTTAG +yyreportAmbiguity (yySemanticOption* yyx0, + yySemanticOption* yyx1]b4_pure_formals[) +{ + YY_USE (yyx0); + YY_USE (yyx1); + +#if ]b4_api_PREFIX[DEBUG + YY_FPRINTF ((stderr, "Ambiguity detected.\n")); + YY_FPRINTF ((stderr, "Option 1,\n")); + yyreportTree (yyx0, 2); + YY_FPRINTF ((stderr, "\nOption 2,\n")); + yyreportTree (yyx1, 2); + YY_FPRINTF ((stderr, "\n")); +#endif + + yyerror (]b4_yyerror_args[YY_("syntax is ambiguous")); + return yyabort; +}]b4_locations_if([[ + +/** Resolve the locations for each of the YYN1 states in *YYSTACKP, + * ending at YYS1. Has no effect on previously resolved states. + * The first semantic option of a state is always chosen. */ +static void +yyresolveLocations (yyGLRState *yys1, int yyn1, + yyGLRStack *yystackp]b4_user_formals[) +{ + if (0 < yyn1) + { + yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[); + if (!yys1->yyresolved) + { + yyGLRStackItem yyrhsloc[1 + YYMAXRHS]; + int yynrhs; + yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal; + YY_ASSERT (yyoption); + yynrhs = yyrhsLength (yyoption->yyrule); + if (0 < yynrhs) + { + yyGLRState *yys; + int yyn; + yyresolveLocations (yyoption->yystate, yynrhs, + yystackp]b4_user_args[); + for (yys = yyoption->yystate, yyn = yynrhs; + yyn > 0; + yys = yys->yypred, yyn -= 1) + yyrhsloc[yyn].yystate.yyloc = yys->yyloc; + } + else + { + /* Both yyresolveAction and yyresolveLocations traverse the GSS + in reverse rightmost order. It is only necessary to invoke + yyresolveLocations on a subforest for which yyresolveAction + would have been invoked next had an ambiguity not been + detected. Thus the location of the previous state (but not + necessarily the previous state itself) is guaranteed to be + resolved already. */ + yyGLRState *yyprevious = yyoption->yystate; + yyrhsloc[0].yystate.yyloc = yyprevious->yyloc; + } + YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs); + } + } +}]])[ + +/** Resolve the ambiguity represented in state YYS in *YYSTACKP, + * perform the indicated actions, and set the semantic value of YYS. + * If result != yyok, the chain of semantic options in YYS has been + * cleared instead or it has been left unmodified except that + * redundant options may have been removed. Regardless of whether + * result = yyok, YYS has been left with consistent data so that + * yydestroyGLRState can be invoked if necessary. */ +static YYRESULTTAG +yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[) +{ + yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal; + yySemanticOption* yybest = yyoptionList; + yySemanticOption** yypp; + yybool yymerge = yyfalse; + YYSTYPE yyval; + YYRESULTTAG yyflag;]b4_locations_if([ + YYLTYPE *yylocp = &yys->yyloc;])[ + + for (yypp = &yyoptionList->yynext; *yypp != YY_NULLPTR; ) + { + yySemanticOption* yyp = *yypp; + + if (yyidenticalOptions (yybest, yyp)) + { + yymergeOptionSets (yybest, yyp); + *yypp = yyp->yynext; + } + else + { + switch (yypreference (yybest, yyp)) + { + case 0:]b4_locations_if([[ + yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[ + return yyreportAmbiguity (yybest, yyp]b4_pure_args[); + break; + case 1: + yymerge = yytrue; + break; + case 2: + break; + case 3: + yybest = yyp; + yymerge = yyfalse; + break; + default: + /* This cannot happen so it is not worth a YY_ASSERT (yyfalse), + but some compilers complain if the default case is + omitted. */ + break; + } + yypp = &yyp->yynext; + } + } + + if (yymerge) + { + yySemanticOption* yyp; + int yyprec = yydprec[yybest->yyrule]; + yyflag = yyresolveAction (yybest, yystackp, &yyval]b4_locuser_args[); + if (yyflag == yyok) + for (yyp = yybest->yynext; yyp != YY_NULLPTR; yyp = yyp->yynext) + { + if (yyprec == yydprec[yyp->yyrule]) + { + YYSTYPE yyval_other;]b4_locations_if([ + YYLTYPE yydummy;])[ + yyflag = yyresolveAction (yyp, yystackp, &yyval_other]b4_locuser_args([&yydummy])[); + if (yyflag != yyok) + { + yydestruct ("Cleanup: discarding incompletely merged value for", + yy_accessing_symbol (yys->yylrState), + &yyval]b4_locuser_args[); + break; + } + yyuserMerge (yymerger[yyp->yyrule], &yyval, &yyval_other); + } + } + } + else + yyflag = yyresolveAction (yybest, yystackp, &yyval]b4_locuser_args([yylocp])[); + + if (yyflag == yyok) + { + yys->yyresolved = yytrue; + yys->yysemantics.yyval = yyval; + } + else + yys->yysemantics.yyfirstVal = YY_NULLPTR; + return yyflag; +} + +static YYRESULTTAG +yyresolveStack (yyGLRStack* yystackp]b4_user_formals[) +{ + if (yystackp->yysplitPoint != YY_NULLPTR) + { + yyGLRState* yys; + int yyn; + + for (yyn = 0, yys = yystackp->yytops.yystates[0]; + yys != yystackp->yysplitPoint; + yys = yys->yypred, yyn += 1) + continue; + YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp + ]b4_user_args[)); + } + return yyok; +} + +/** Called when returning to deterministic operation to clean up the extra + * stacks. */ +static void +yycompressStack (yyGLRStack* yystackp) +{ + /* yyr is the state after the split point. */ + yyGLRState *yyr; + + if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULLPTR) + return; + + { + yyGLRState *yyp, *yyq; + for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULLPTR; + yyp != yystackp->yysplitPoint; + yyr = yyp, yyp = yyq, yyq = yyp->yypred) + yyp->yypred = yyr; + } + + yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems; + yystackp->yynextFree = YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yysplitPoint) + 1; + yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems; + yystackp->yysplitPoint = YY_NULLPTR; + yystackp->yylastDeleted = YY_NULLPTR; + + while (yyr != YY_NULLPTR) + { + yystackp->yynextFree->yystate = *yyr; + yyr = yyr->yypred; + yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate; + yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate; + yystackp->yynextFree += 1; + yystackp->yyspaceLeft -= 1; + } +} + +static YYRESULTTAG +yyprocessOneStack (yyGLRStack* yystackp, YYPTRDIFF_T yyk, + YYPTRDIFF_T yyposn]b4_pure_formals[) +{ + while (yystackp->yytops.yystates[yyk] != YY_NULLPTR) + { + yy_state_t yystate = yystackp->yytops.yystates[yyk]->yylrState; + YY_DPRINTF ((stderr, "Stack %ld Entering state %d\n", + YY_CAST (long, yyk), yystate)); + + YY_ASSERT (yystate != YYFINAL); + + if (yyisDefaultedState (yystate)) + { + YYRESULTTAG yyflag; + yyRuleNum yyrule = yydefaultAction (yystate); + if (yyrule == 0) + { + YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yyk))); + yymarkStackDeleted (yystackp, yyk); + return yyok; + } + yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule]]b4_user_args[); + if (yyflag == yyerr) + { + YY_DPRINTF ((stderr, + "Stack %ld dies " + "(predicate failure or explicit user error).\n", + YY_CAST (long, yyk))); + yymarkStackDeleted (yystackp, yyk); + return yyok; + } + if (yyflag != yyok) + return yyflag; + } + else + { + yysymbol_kind_t yytoken = ]b4_yygetToken_call[; + const short* yyconflicts; + const int yyaction = yygetLRActions (yystate, yytoken, &yyconflicts); + yystackp->yytops.yylookaheadNeeds[yyk] = yytrue; + + for (/* nothing */; *yyconflicts; yyconflicts += 1) + { + YYRESULTTAG yyflag; + YYPTRDIFF_T yynewStack = yysplitStack (yystackp, yyk); + YY_DPRINTF ((stderr, "Splitting off stack %ld from %ld.\n", + YY_CAST (long, yynewStack), YY_CAST (long, yyk))); + yyflag = yyglrReduce (yystackp, yynewStack, + *yyconflicts, + yyimmediate[*yyconflicts]]b4_user_args[); + if (yyflag == yyok) + YYCHK (yyprocessOneStack (yystackp, yynewStack, + yyposn]b4_pure_args[)); + else if (yyflag == yyerr) + { + YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yynewStack))); + yymarkStackDeleted (yystackp, yynewStack); + } + else + return yyflag; + } + + if (yyisShiftAction (yyaction)) + break; + else if (yyisErrorAction (yyaction)) + { + YY_DPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yyk))); + yymarkStackDeleted (yystackp, yyk); + break; + } + else + { + YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction, + yyimmediate[-yyaction]]b4_user_args[); + if (yyflag == yyerr) + { + YY_DPRINTF ((stderr, + "Stack %ld dies " + "(predicate failure or explicit user error).\n", + YY_CAST (long, yyk))); + yymarkStackDeleted (yystackp, yyk); + break; + } + else if (yyflag != yyok) + return yyflag; + } + } + } + return yyok; +} + +]b4_parse_error_case([simple], [], +[[/* Put in YYARG at most YYARGN of the expected tokens given the + current YYSTACKP, and return the number of tokens stored in YYARG. If + YYARG is null, return the number of expected tokens (guaranteed to + be less than YYNTOKENS). */ +static int +yypcontext_expected_tokens (const yyGLRStack* yystackp, + yysymbol_kind_t yyarg[], int yyargn) +{ + /* Actual size of YYARG. */ + int yycount = 0; + int yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); + } + } + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(empty, kind)[; + return yycount; +}]])[ + +]b4_parse_error_bmatch( + [custom], +[[/* User defined function to report a syntax error. */ +typedef yyGLRStack yypcontext_t; +static int +yyreport_syntax_error (const yyGLRStack* yystackp]b4_user_formals[); + +/* The kind of the lookahead of this context. */ +static yysymbol_kind_t +yypcontext_token (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; + +static yysymbol_kind_t +yypcontext_token (const yyGLRStack *yystackp) +{ + YY_USE (yystackp); + yysymbol_kind_t yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar); + return yytoken; +} + +]b4_locations_if([[/* The location of the lookahead of this context. */ +static const YYLTYPE * +yypcontext_location (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; + +static const YYLTYPE * +yypcontext_location (const yyGLRStack *yystackp) +{ + YY_USE (yystackp); + return &yylloc; +}]])], + [detailed\|verbose], +[[static int +yy_syntax_error_arguments (const yyGLRStack* yystackp, + yysymbol_kind_t yyarg[], int yyargn) +{ + yysymbol_kind_t yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar); + /* Actual size of YYARG. */ + int yycount = 0; + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != ]b4_symbol(empty, kind)[) + { + int yyn; + if (yyarg) + yyarg[yycount] = yytoken; + ++yycount; + yyn = yypcontext_expected_tokens (yystackp, + yyarg ? yyarg + 1 : yyarg, yyargn - 1); + if (yyn == YYENOMEM) + return YYENOMEM; + else + yycount += yyn; + } + return yycount; +} +]])[ + + +static void +yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) +{ + if (yystackp->yyerrState != 0) + return; +]b4_parse_error_case( + [custom], +[[ if (yyreport_syntax_error (yystackp]b4_user_args[)) + yyMemoryExhausted (yystackp);]], + [simple], +[[ yyerror (]b4_lyyerror_args[YY_("syntax error"));]], +[[ { + yybool yysize_overflow = yyfalse; + char* yymsg = YY_NULLPTR; + enum { YYARGS_MAX = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ + yysymbol_kind_t yyarg[YYARGS_MAX]; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; + + /* Actual size of YYARG. */ + int yycount + = yy_syntax_error_arguments (yystackp, yyarg, YYARGS_MAX); + if (yycount == YYENOMEM) + yyMemoryExhausted (yystackp); + + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: /* Avoid compiler warnings. */ + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } + + /* Compute error message size. Don't count the "%s"s, but reserve + room for the terminator. */ + yysize = yystrlen (yyformat) - 2 * yycount + 1; + { + int yyi; + for (yyi = 0; yyi < yycount; ++yyi) + { + YYPTRDIFF_T yysz + = ]b4_parse_error_case( + [verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]], + [[yystrlen (yysymbol_name (yyarg[yyi]))]]);[ + if (YYSIZE_MAXIMUM - yysize < yysz) + yysize_overflow = yytrue; + else + yysize += yysz; + } + } + + if (!yysize_overflow) + yymsg = YY_CAST (char *, YYMALLOC (YY_CAST (YYSIZE_T, yysize))); + + if (yymsg) + { + char *yyp = yymsg; + int yyi = 0; + while ((*yyp = *yyformat)) + { + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + {]b4_parse_error_case([verbose], [[ + yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[ + yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[ + yyformat += 2; + } + else + { + ++yyp; + ++yyformat; + } + } + yyerror (]b4_lyyerror_args[yymsg); + YYFREE (yymsg); + } + else + { + yyerror (]b4_lyyerror_args[YY_("syntax error")); + yyMemoryExhausted (yystackp); + } + }]])[ + yynerrs += 1; +} + +/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP, + yylval, and yylloc are the syntactic category, semantic value, and location + of the lookahead. */ +static void +yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) +{ + if (yystackp->yyerrState == 3) + /* We just shifted the error token and (perhaps) took some + reductions. Skip tokens until we can proceed. */ + while (yytrue) + { + yysymbol_kind_t yytoken; + int yyj; + if (yychar == ]b4_symbol(eof, [id])[) + yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); + if (yychar != ]b4_symbol(empty, id)[) + {]b4_locations_if([[ + /* We throw away the lookahead, but the error range + of the shifted error token must take it into account. */ + yyGLRState *yys = yystackp->yytops.yystates[0]; + yyGLRStackItem yyerror_range[3]; + yyerror_range[1].yystate.yyloc = yys->yyloc; + yyerror_range[2].yystate.yyloc = yylloc; + YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Error: discarding", + yytoken, &yylval]b4_locuser_args([&yylloc])[); + yychar = ]b4_symbol(empty, id)[; + } + yytoken = ]b4_yygetToken_call[; + yyj = yypact[yystackp->yytops.yystates[0]->yylrState]; + if (yypact_value_is_default (yyj)) + return; + yyj += yytoken; + if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken) + { + if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0) + return; + } + else if (! yytable_value_is_error (yytable[yyj])) + return; + } + + /* Reduce to one stack. */ + { + YYPTRDIFF_T yyk; + for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1) + if (yystackp->yytops.yystates[yyk] != YY_NULLPTR) + break; + if (yyk >= yystackp->yytops.yysize) + yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); + for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1) + yymarkStackDeleted (yystackp, yyk); + yyremoveDeletes (yystackp); + yycompressStack (yystackp); + } + + /* Pop stack until we find a state that shifts the error token. */ + yystackp->yyerrState = 3; + while (yystackp->yytops.yystates[0] != YY_NULLPTR) + { + yyGLRState *yys = yystackp->yytops.yystates[0]; + int yyj = yypact[yys->yylrState]; + if (! yypact_value_is_default (yyj)) + { + yyj += ]b4_symbol(error, kind)[; + if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(error, kind)[ + && yyisShiftAction (yytable[yyj])) + { + /* Shift the error token. */ + int yyaction = yytable[yyj];]b4_locations_if([[ + /* First adjust its location.*/ + YYLTYPE yyerrloc; + yystackp->yyerror_range[2].yystate.yyloc = yylloc; + YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[ + YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yyaction), + &yylval, &yyerrloc); + yyglrShift (yystackp, 0, yyaction, + yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[); + yys = yystackp->yytops.yystates[0]; + break; + } + }]b4_locations_if([[ + yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ + if (yys->yypred != YY_NULLPTR) + yydestroyGLRState ("Error: popping", yys]b4_user_args[); + yystackp->yytops.yystates[0] = yys->yypred; + yystackp->yynextFree -= 1; + yystackp->yyspaceLeft += 1; + } + if (yystackp->yytops.yystates[0] == YY_NULLPTR) + yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); +} + +#define YYCHK1(YYE) \ + do { \ + switch (YYE) { \ + case yyok: break; \ + case yyabort: goto yyabortlab; \ + case yyaccept: goto yyacceptlab; \ + case yyerr: goto yyuser_error; \ + case yynomem: goto yyexhaustedlab; \ + default: goto yybuglab; \ + } \ + } while (0) + +/*----------. +| yyparse. | +`----------*/ + +int +]b4_glr_cc_if([yy_parse_impl], [yyparse])[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) +{ + int yyresult; + yyGLRStack yystack; + yyGLRStack* const yystackp = &yystack; + YYPTRDIFF_T yyposn; + + YY_DPRINTF ((stderr, "Starting parse\n")); + + yychar = ]b4_symbol(empty, id)[; + yylval = yyval_default;]b4_locations_if([ + yylloc = yyloc_default;])[ +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl + b4_user_initial_action +b4_dollar_popdef])[]dnl +[ + if (! yyinitGLRStack (yystackp, YYINITDEPTH)) + goto yyexhaustedlab; + switch (YYSETJMP (yystack.yyexception_buffer)) + { + case 0: break; + case 1: goto yyabortlab; + case 2: goto yyexhaustedlab; + default: goto yybuglab; + } + yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[); + yyposn = 0; + + while (yytrue) + { + /* For efficiency, we have two loops, the first of which is + specialized to deterministic operation (single stack, no + potential ambiguity). */ + /* Standard mode. */ + while (yytrue) + { + yy_state_t yystate = yystack.yytops.yystates[0]->yylrState; + YY_DPRINTF ((stderr, "Entering state %d\n", yystate)); + if (yystate == YYFINAL) + goto yyacceptlab; + if (yyisDefaultedState (yystate)) + { + yyRuleNum yyrule = yydefaultAction (yystate); + if (yyrule == 0) + {]b4_locations_if([[ + yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ + yyreportSyntaxError (&yystack]b4_user_args[); + goto yyuser_error; + } + YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[)); + } + else + { + yysymbol_kind_t yytoken = ]b4_yygetToken_call;[ + const short* yyconflicts; + int yyaction = yygetLRActions (yystate, yytoken, &yyconflicts); + if (*yyconflicts) + /* Enter nondeterministic mode. */ + break; + if (yyisShiftAction (yyaction)) + { + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yychar = ]b4_symbol(empty, id)[; + yyposn += 1; + yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[); + if (0 < yystack.yyerrState) + yystack.yyerrState -= 1; + } + else if (yyisErrorAction (yyaction)) + {]b4_locations_if([[ + yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ + /* Issue an error message unless the scanner already + did. */ + if (yychar != ]b4_symbol(error, id)[) + yyreportSyntaxError (&yystack]b4_user_args[); + goto yyuser_error; + } + else + YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[)); + } + } + + /* Nondeterministic mode. */ + while (yytrue) + { + yysymbol_kind_t yytoken_to_shift; + YYPTRDIFF_T yys; + + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + yystackp->yytops.yylookaheadNeeds[yys] = yychar != ]b4_symbol(empty, id)[; + + /* yyprocessOneStack returns one of three things: + + - An error flag. If the caller is yyprocessOneStack, it + immediately returns as well. When the caller is finally + yyparse, it jumps to an error label via YYCHK1. + + - yyok, but yyprocessOneStack has invoked yymarkStackDeleted + (&yystack, yys), which sets the top state of yys to NULL. Thus, + yyparse's following invocation of yyremoveDeletes will remove + the stack. + + - yyok, when ready to shift a token. + + Except in the first case, yyparse will invoke yyremoveDeletes and + then shift the next token onto all remaining stacks. This + synchronization of the shift (that is, after all preceding + reductions on all stacks) helps prevent double destructor calls + on yylval in the event of memory exhaustion. */ + + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[)); + yyremoveDeletes (&yystack); + if (yystack.yytops.yysize == 0) + { + yyundeleteLastStack (&yystack); + if (yystack.yytops.yysize == 0) + yyFail (&yystack][]b4_lpure_args[, YY_("syntax error")); + YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); + YY_DPRINTF ((stderr, "Returning to deterministic operation.\n"));]b4_locations_if([[ + yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ + yyreportSyntaxError (&yystack]b4_user_args[); + goto yyuser_error; + } + + /* If any yyglrShift call fails, it will fail after shifting. Thus, + a copy of yylval will already be on stack 0 in the event of a + failure in the following loop. Thus, yychar is set to ]b4_symbol(empty, id)[ + before the loop to make sure the user destructor for yylval isn't + called twice. */ + yytoken_to_shift = YYTRANSLATE (yychar); + yychar = ]b4_symbol(empty, id)[; + yyposn += 1; + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + { + yy_state_t yystate = yystack.yytops.yystates[yys]->yylrState; + const short* yyconflicts; + int yyaction = yygetLRActions (yystate, yytoken_to_shift, + &yyconflicts); + /* Note that yyconflicts were handled by yyprocessOneStack. */ + YY_DPRINTF ((stderr, "On stack %ld, ", YY_CAST (long, yys))); + YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc); + yyglrShift (&yystack, yys, yyaction, yyposn, + &yylval]b4_locations_if([, &yylloc])[); + YY_DPRINTF ((stderr, "Stack %ld now in state %d\n", + YY_CAST (long, yys), + yystack.yytops.yystates[yys]->yylrState)); + } + + if (yystack.yytops.yysize == 1) + { + YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); + YY_DPRINTF ((stderr, "Returning to deterministic operation.\n")); + yycompressStack (&yystack); + break; + } + } + continue; + yyuser_error: + yyrecoverSyntaxError (&yystack]b4_user_args[); + yyposn = yystack.yytops.yystates[0]->yyposn; + } + + yyacceptlab: + yyresult = 0; + goto yyreturnlab; + + yybuglab: + YY_ASSERT (yyfalse); + goto yyabortlab; + + yyabortlab: + yyresult = 1; + goto yyreturnlab; + + yyexhaustedlab: + yyerror (]b4_lyyerror_args[YY_("memory exhausted")); + yyresult = 2; + goto yyreturnlab; + + yyreturnlab: + if (yychar != ]b4_symbol(empty, id)[) + yydestruct ("Cleanup: discarding lookahead", + YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[); + + /* If the stack is well-formed, pop the stack until it is empty, + destroying its entries as we go. But free the stack regardless + of whether it is well-formed. */ + if (yystack.yyitems) + { + yyGLRState** yystates = yystack.yytops.yystates; + if (yystates) + { + YYPTRDIFF_T yysize = yystack.yytops.yysize; + YYPTRDIFF_T yyk; + for (yyk = 0; yyk < yysize; yyk += 1) + if (yystates[yyk]) + { + while (yystates[yyk]) + { + yyGLRState *yys = yystates[yyk];]b4_locations_if([[ + yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ + if (yys->yypred != YY_NULLPTR) + yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); + yystates[yyk] = yys->yypred; + yystack.yynextFree -= 1; + yystack.yyspaceLeft += 1; + } + break; + } + } + yyfreeGLRStack (&yystack); + } + + return yyresult; +} + +/* DEBUGGING ONLY */ +#if ]b4_api_PREFIX[DEBUG +/* Print *YYS and its predecessors. */ +static void +yy_yypstack (yyGLRState* yys) +{ + if (yys->yypred) + { + yy_yypstack (yys->yypred); + YY_FPRINTF ((stderr, " -> ")); + } + YY_FPRINTF ((stderr, "%d@@%ld", yys->yylrState, YY_CAST (long, yys->yyposn))); +} + +/* Print YYS (possibly NULL) and its predecessors. */ +static void +yypstates (yyGLRState* yys) +{ + if (yys == YY_NULLPTR) + YY_FPRINTF ((stderr, "")); + else + yy_yypstack (yys); + YY_FPRINTF ((stderr, "\n")); +} + +/* Print the stack #YYK. */ +static void +yypstack (yyGLRStack* yystackp, YYPTRDIFF_T yyk) +{ + yypstates (yystackp->yytops.yystates[yyk]); +} + +/* Print all the stacks. */ +static void +yypdumpstack (yyGLRStack* yystackp) +{ +#define YYINDEX(YYX) \ + YY_CAST (long, \ + ((YYX) \ + ? YY_REINTERPRET_CAST (yyGLRStackItem*, (YYX)) - yystackp->yyitems \ + : -1)) + + yyGLRStackItem* yyp; + for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1) + { + YY_FPRINTF ((stderr, "%3ld. ", + YY_CAST (long, yyp - yystackp->yyitems))); + if (*YY_REINTERPRET_CAST (yybool *, yyp)) + { + YY_ASSERT (yyp->yystate.yyisState); + YY_ASSERT (yyp->yyoption.yyisState); + YY_FPRINTF ((stderr, "Res: %d, LR State: %d, posn: %ld, pred: %ld", + yyp->yystate.yyresolved, yyp->yystate.yylrState, + YY_CAST (long, yyp->yystate.yyposn), + YYINDEX (yyp->yystate.yypred))); + if (! yyp->yystate.yyresolved) + YY_FPRINTF ((stderr, ", firstVal: %ld", + YYINDEX (yyp->yystate.yysemantics.yyfirstVal))); + } + else + { + YY_ASSERT (!yyp->yystate.yyisState); + YY_ASSERT (!yyp->yyoption.yyisState); + YY_FPRINTF ((stderr, "Option. rule: %d, state: %ld, next: %ld", + yyp->yyoption.yyrule - 1, + YYINDEX (yyp->yyoption.yystate), + YYINDEX (yyp->yyoption.yynext))); + } + YY_FPRINTF ((stderr, "\n")); + } + + YY_FPRINTF ((stderr, "Tops:")); + { + YYPTRDIFF_T yyi; + for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) + YY_FPRINTF ((stderr, "%ld: %ld; ", YY_CAST (long, yyi), + YYINDEX (yystackp->yytops.yystates[yyi]))); + YY_FPRINTF ((stderr, "\n")); + } +#undef YYINDEX +} +#endif + +#undef yylval +#undef yychar +#undef yynerrs]b4_locations_if([ +#undef yylloc]) + +m4_if(b4_prefix, [yy], [], +[[/* Substitute the variable and function names. */ +#define yyparse ]b4_prefix[parse +#define yylex ]b4_prefix[lex +#define yyerror ]b4_prefix[error +#define yylval ]b4_prefix[lval +#define yychar ]b4_prefix[char +#define yydebug ]b4_prefix[debug +#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ +#define yylloc ]b4_prefix[lloc]])])[ + +]b4_glr_cc_if([b4_glr_cc_pre_epilogue +b4_glr_cc_cleanup])[ +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/tools/flex-bison/third_party/skeletons/glr.cc b/tools/flex-bison/third_party/skeletons/glr.cc new file mode 100644 index 000000000..1ba02a80f --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/glr.cc @@ -0,0 +1,395 @@ +#C++ GLR skeleton for Bison + +#Copyright(C) 2002 - 2015, 2018 - 2021 Free Software Foundation, Inc. + +#This program is free software : you can redistribute it and / or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program.If not, see < https: // www.gnu.org/licenses/>. + +#This skeleton produces a C++ class that encapsulates a C glr parser. +#This is in order to reduce the maintenance burden.The glr.c +#skeleton is clean and pure enough so that there are no real +#problems.The C++ interface is the same as that of lalr1.cc.In +#fact, glr.c can replace yacc.c without the user noticing any +#difference, and similarly for glr.cc replacing lalr1.cc. +# +#The passing of parse - params +# +#The additional arguments are stored as members of the parser +#object, yyparser.The C routines need to carry yyparser +#throughout the C parser; that's easy: make yyparser an +#additional parse - param.But because the C++ skeleton needs to +#know the "real" original parse - param, we save them +#(b4_parse_param_orig).Note that b4_parse_param is overquoted +#(and c.m4 strips one level of quotes).This is a PITA, and +#explains why there are so many levels of quotes. +# +#The locations +# +#We use location.cc just like lalr1.cc, but because glr.c stores +#the locations in a union, the position and location classes +#must not have a constructor.Therefore, contrary to lalr1.cc, we +#must not define "b4_location_constructors".As a consequence the +#user must initialize the first positions(in particular the +#filename member). + +#We require a pure interface. +m4_define([b4_pure_flag], [1]) + +m4_include(b4_skeletonsdir/[c++.m4]) +b4_bison_locations_if([m4_include(b4_skeletonsdir/[location.cc])]) + +m4_define([b4_parser_class], + [b4_percent_define_get([[api.parser.class]])]) + +#Save the parse parameters. +m4_define([b4_parse_param_orig], m4_defn([b4_parse_param])) + +#b4_parse_param_wrap +#-- -- -- -- -- -- -- -- -- - +#New ones. +m4_ifset([b4_parse_param], +[m4_define([b4_parse_param_wrap], + [[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]],] +m4_defn([b4_parse_param]))], +[m4_define([b4_parse_param_wrap], + [[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]]]) +]) + +#b4_yy_symbol_print_define +#-- -- -- -- -- -- -- -- -- -- -- -- - +#Bypass the default implementation to generate the "yy_symbol_print" +# and "yy_symbol_value_print" functions. +m4_define([b4_yy_symbol_print_define], +[[/*--------------------. +| Print this symbol. | +`--------------------*/ + +static void +yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_kind_type yytoken, + const ]b4_namespace_ref::b4_parser_class[::value_type *yyvaluep]b4_locations_if([[, + const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[) +{ +]b4_parse_param_use[]dnl +[ yyparser.yy_symbol_print_ (yytoken, yyvaluep]b4_locations_if([, yylocationp])[); +} +]])[ + +#Hijack the initial action to initialize the locations. +]b4_bison_locations_if([m4_define([b4_initial_action], +[yylloc.initialize ();]m4_ifdef([b4_initial_action], [ +m4_defn([b4_initial_action])]))])[ + +#Hijack the post prologue to declare yyerror. +]m4_append([b4_post_prologue], +[b4_syncline([@oline@], [@ofile@])dnl +[static void +yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp, + ]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param), + ])[const char* msg);]])[ + +#Inserted before the epilogue to define implementations(yyerror, parser member +#functions etc.). +]m4_define([b4_glr_cc_pre_epilogue], +[b4_syncline([@oline@], [@ofile@])dnl +[ +/*------------------. +| Report an error. | +`------------------*/ + +static void +yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp, + ]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param), + ])[const char* msg) +{ +]b4_parse_param_use[]dnl +[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg); +} + + +]b4_namespace_open[ +]dnl In this section, the parse params are the original parse_params. +m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl +[ /// Build a parser object. + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ + :])[ +#if] b4_api_PREFIX[DEBUG + ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ +#endif] b4_parse_param_cons[ + {} + + ]b4_parser_class::~b4_parser_class[ () + {} + + ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW + {} + + int + ]b4_parser_class[::operator() () + { + return parse(); + } + + int + ]b4_parser_class[::parse () + { + return ::yy_parse_impl (*this]b4_user_args[); + } + +#if] b4_api_PREFIX[DEBUG + /*--------------------. + | Print this symbol. | + `--------------------*/ + + void + ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind, + const value_type* yyvaluep]b4_locations_if([[, + const location_type* yylocationp]])[) const + {]b4_locations_if([[ + YY_USE (yylocationp);]])[ + YY_USE (yyvaluep); + std::ostream& yyo = debug_stream (); + std::ostream& yyoutput = yyo; + YY_USE (yyoutput); + ]b4_symbol_actions([printer])[ + } + + + void + ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind, + const value_type* yyvaluep]b4_locations_if([[, + const location_type* yylocationp]])[) const + { + *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << yysymbol_name (yykind) << " ("]b4_locations_if([[ + << *yylocationp << ": "]])[; + yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[); + *yycdebug_ << ')'; + } + + std::ostream& + ]b4_parser_class[::debug_stream () const + { + return *yycdebug_; + } + + void + ]b4_parser_class[::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + ]b4_parser_class[::debug_level_type + ]b4_parser_class[::debug_level () const + { + return yydebug; + } + + void + ]b4_parser_class[::set_debug_level (debug_level_type l) + { + // Actually, it is yydebug which is really used. + yydebug = l; + } + +#endif +]m4_popdef([b4_parse_param])dnl +b4_namespace_close[]dnl +]) + + +m4_define([b4_define_symbol_kind], +[m4_format([#define %-15s %s], + b4_symbol($][1, kind_base), + b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base)) +]) + +#b4_glr_cc_setup +#-- -- -- -- -- -- -- - +#Setup redirections for glr.c : Map the names used in c.m4 to the ones used +#in c++.m4. +m4_define([b4_glr_cc_setup], +[[]b4_attribute_define[ +]b4_null_define[ + +// This skeleton is based on C, yet compiles it as C++. +// So expect warnings about C style casts. +#if defined __clang__ && 306 <= __clang_major__ * 100 + __clang_minor__ +# pragma clang diagnostic ignored "-Wold-style-cast" +#elif defined __GNUC__ && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + +// On MacOS, PTRDIFF_MAX is defined as long long, which Clang's +// -pedantic reports as being a C++11 extension. +#if defined __APPLE__ && YY_CPLUSPLUS < 201103L && defined __clang__ && 4 <= __clang_major__ +# pragma clang diagnostic ignored "-Wc++11-long-long" +#endif + +#undef] b4_symbol(empty, [id])[ +#define] b4_symbol(empty, [id])[] b4_namespace_ref[::] b4_parser_class[::token::] b4_symbol( \ + empty, [id])[ +#undef] b4_symbol(eof, [id])[ +#define] b4_symbol(eof, [id])[] b4_namespace_ref[::] b4_parser_class[::token::] b4_symbol( \ + eof, [id])[ +#undef] b4_symbol(error, [id])[ +#define] b4_symbol(error, [id])[] b4_namespace_ref[::] b4_parser_class[::token::] b4_symbol( \ + error, [id])[ + +#ifndef] b4_api_PREFIX[STYPE +# define] b4_api_PREFIX[STYPE] b4_namespace_ref[::] b4_parser_class[::value_type +#endif +#ifndef] b4_api_PREFIX[LTYPE +# define] b4_api_PREFIX[LTYPE] b4_namespace_ref[::] b4_parser_class[::location_type +#endif + +typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t; + +// Expose C++ symbol kinds to C. +]b4_define_symbol_kind(-2)dnl +b4_symbol_foreach([b4_define_symbol_kind])])[ +]]) + + +m4_define([b4_undef_symbol_kind], +[[#undef ]b4_symbol($1, kind_base)[ +]]) + +#b4_glr_cc_cleanup +#-- -- -- -- -- -- -- -- - +#Remove redirections for glr.c. +m4_define([b4_glr_cc_cleanup], +[[#undef ]b4_symbol(empty, [id])[ +#undef] b4_symbol(eof, [id])[ +#undef] b4_symbol(error, [id])[ + +]b4_undef_symbol_kind(-2)dnl +b4_symbol_foreach([b4_undef_symbol_kind])dnl +]) + +#b4_shared_declarations(hh | cc) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#Declaration that might either go into the header(if --header, $1 = hh) +# or in the implementation file. +m4_define([b4_shared_declarations], +[m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl +b4_percent_code_get([[requires]])[ +#include +#include +#include + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ +]b4_variant_if([b4_variant_includes])[ + +// Whether we are compiled with exception support. +#ifndef YY_EXCEPTIONS +# if defined __GNUC__ && !defined __EXCEPTIONS +# define YY_EXCEPTIONS 0 +# else +# define YY_EXCEPTIONS 1 +# endif +#endif + +]b4_YYDEBUG_define[ + +]b4_namespace_open[ + +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ + + /// A Bison parser. + class ]b4_parser_class[ + { + public: +]b4_public_types_declare[ + + /// Build a parser object. + ]b4_parser_class[ (]b4_parse_param_decl[); + virtual ~]b4_parser_class[ (); + + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + virtual int parse (); + +#if] b4_api_PREFIX[DEBUG + /// The current debugging stream. + std::ostream& debug_stream () const; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + typedef int debug_level_type; + /// The current debugging level. + debug_level_type debug_level () const; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); +#endif + + /// Report a syntax error.]b4_locations_if([[ + /// \param loc where the syntax error is found.]])[ + /// \param msg a description of the syntax error. + virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); + +#if] b4_api_PREFIX[DEBUG + public: + /// \brief Report a symbol value on the debug stream. + /// \param yykind The symbol kind. + /// \param yyvaluep Its semantic value.]b4_locations_if([[ + /// \param yylocationp Its location.]])[ + virtual void yy_symbol_value_print_ (symbol_kind_type yykind, + const value_type* yyvaluep]b4_locations_if([[, + const location_type* yylocationp]])[) const; + /// \brief Report a symbol on the debug stream. + /// \param yykind The symbol kind. + /// \param yyvaluep Its semantic value.]b4_locations_if([[ + /// \param yylocationp Its location.]])[ + virtual void yy_symbol_print_ (symbol_kind_type yykind, + const value_type* yyvaluep]b4_locations_if([[, + const location_type* yylocationp]])[) const; + private: + /// Debug stream. + std::ostream* yycdebug_; +#endif + +]b4_parse_param_vars[ + }; + +]b4_namespace_close[ + +]b4_percent_code_get([[provides]])[ +]m4_popdef([b4_parse_param])dnl +])[ + +]b4_header_if( +[b4_output_begin([b4_spec_header_file]) +b4_copyright([Skeleton interface for Bison GLR parsers in C++], + [2002-2015, 2018-2021])[ +// C++ GLR parser skeleton written by Akim Demaille. + +]b4_disclaimer[ +]b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_shared_declarations[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[ +]b4_output_end]) + +#Let glr.c(and b4_shared_declarations) believe that the user +#arguments include the parser itself. +m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_wrap])) +m4_include(b4_skeletonsdir/[glr.c]) +m4_popdef([b4_parse_param]) diff --git a/tools/flex-bison/third_party/skeletons/glr2.cc b/tools/flex-bison/third_party/skeletons/glr2.cc new file mode 100644 index 000000000..9b397c679 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/glr2.cc @@ -0,0 +1,3482 @@ +#C++ GLR skeleton for Bison + +#Copyright(C) 2002 - 2015, 2018 - 2021 Free Software Foundation, Inc. + +#This program is free software : you can redistribute it and / or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program.If not, see < https: // www.gnu.org/licenses/>. + +m4_include(b4_skeletonsdir/[c++.m4]) + +#api.value.type = variant is valid. +m4_define([b4_value_type_setup_variant]) + +#b4_tname_if(TNAME - NEEDED, TNAME - NOT - NEEDED) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +m4_define([b4_tname_if], +[m4_case(b4_percent_define_get([[parse.error]]), + [verbose], [$1], + [b4_token_table_if([$1], + [$2])])]) + +b4_bison_locations_if([ + m4_define([b4_location_constructors]) + m4_include(b4_skeletonsdir/[location.cc])]) +b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])]) + +m4_define([b4_parser_class], + [b4_percent_define_get([[api.parser.class]])]) + +]m4_define([b4_define_symbol_kind], +[m4_format([#define %-15s %s], + b4_symbol($][1, kind_base), + b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base)) +]) + +#b4_integral_parser_table_define(TABLE - NAME, CONTENT, COMMENT) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#Define "yy" whose contents is CONTENT.Does not use "static", +#should be in unnamed namespace. +m4_define([b4_integral_parser_table_define], +[m4_ifvaln([$3], [ b4_comment([$3])])dnl + const b4_int_type_for([$2]) yy$1[[]] = + { + $2 + };dnl +]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +#Stack parameters. +m4_define_default([b4_stack_depth_max], [10000]) +m4_define_default([b4_stack_depth_init], [200]) + + + +## ------------ ## +## Interfaces. ## +## ------------ ## + +#b4_user_formals +#-- -- -- -- -- -- -- - +#The possible parse - params formal arguments preceded by a comma. +# +#This is not shared with yacc.c in c.m4 because GLR relies on ISO C +#formal argument declarations. +m4_define([b4_user_formals], +[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) + +#b4_symbol_kind(NUM) +#-- -- -- -- -- -- -- -- -- - +m4_define([b4_symbol_kind], +[symbol_kind::b4_symbol_kind_base($@)]) + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + +#b4_lhs_value(SYMBOL - NUM, [TYPE]) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#See README. +m4_define([b4_lhs_value], +[b4_symbol_value([(*yyvalp)], [$1], [$2])]) + +#b4_rhs_data(RULE - LENGTH, POS) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#See README. +m4_define([b4_rhs_data], +[(static_cast(yyvsp))@{YYFILL (b4_subtract([$2], [$1]))@}.getState()]) + +#b4_rhs_value(RULE - LENGTH, POS, SYMBOL - NUM, [TYPE]) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#Expansion of $$ or $ < TYPE> $, for symbol SYMBOL - NUM. +m4_define([b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])]) + + + +## ----------- ## +## Locations. ## +## ----------- ## + +#b4_lhs_location() +#-- -- -- -- -- -- -- -- - +#Expansion of @$. +m4_define([b4_lhs_location], +[(*yylocp)]) + +#b4_rhs_location(RULE - LENGTH, NUM) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#Expansion of @NUM, where the current rule has RULE - LENGTH symbols +#on RHS. +m4_define([b4_rhs_location], +[(b4_rhs_data([$1], [$2]).yyloc)]) + +#b4_symbol_action(SYMBOL - NUM, KIND) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#Run the action KIND(destructor or printer) for SYMBOL - NUM. +#Same as in C, but using references instead of pointers. +# +#Currently we need two different b4_symbol_action : once for the +#self - contained symbols, and another time for yy_destroy_ and +#yy_symbol_value_print_, which don't use genuine symbols yet. +m4_define([b4_symbol_action], +[b4_symbol_if([$1], [has_$2], +[m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl +b4_dollar_pushdef([yysym.value], + [$1], + [], + [yysym.location])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl + b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +m4_popdef([b4_symbol_value])[]dnl +b4_dollar_popdef[]dnl +])]) + +#b4_symbol_action_for_yyval(SYMBOL - NUM, KIND) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#Run the action KIND(destructor or printer) for SYMBOL - NUM. +#Same as in C, but using references instead of pointers. +m4_define([b4_symbol_action_for_yyval], +[b4_symbol_if([$1], [has_$2], +[b4_dollar_pushdef([yyval], + [$1], + [], + [yyloc])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl + b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +b4_dollar_popdef[]dnl +])]) + +#b4_call_merger(MERGER - NUM, MERGER - NAME, SYMBOL - SUM) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +m4_define([b4_call_merger], +[b4_case([$1], + [ b4_symbol_if([$3], [has_type], + [b4_variant_if([yy0.as< b4_symbol($3, type) > () = $2 (yy0.as< b4_symbol($3, type) >(), yy1.as< b4_symbol($3, type) >());], + [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])], + [yy0 = $2 (yy0, yy1);])])]) + +#b4_yylex +#-- -- -- -- +#Call yylex. +m4_define([b4_yylex], +[b4_token_ctor_if( +[b4_function_call([yylex], + [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))], +[b4_function_call([yylex], [int], + [[value_type *], [&this->yyla.value]][]dnl +b4_locations_if([, [[location_type *], [&this->yyla.location]]])dnl +m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) + +#b4_shared_declarations(hh | cc) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#Declaration that might either go into the header(if --header, $1 = hh) +# or in the implementation file. +m4_define([b4_shared_declarations], +[b4_percent_code_get([[requires]])[ +#include +#include +#include // ptrdiff_t +#include // memcpy +#include +#include +#include +#include +#include +#include + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ +]b4_variant_if([b4_variant_includes])[ + +]b4_YYDEBUG_define[ + +]b4_namespace_open[ + +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ + + /// A Bison parser. + class ]b4_parser_class[ + { + public: +]b4_public_types_declare[ +]b4_symbol_type_define[ + + // FIXME: should be private eventually. + class glr_stack; + class glr_state; + + /// Build a parser object. + ]b4_parser_class[ (]b4_parse_param_decl[); + ~]b4_parser_class[ (); + + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + int parse (); + +#if] b4_api_PREFIX[DEBUG + /// The current debugging stream. + std::ostream& debug_stream () const; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + using debug_level_type = int; + /// The current debugging level. + debug_level_type debug_level () const; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); +#endif + + /// Report a syntax error.]b4_locations_if([[ + /// \param loc where the syntax error is found.]])[ + /// \param msg a description of the syntax error. + void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); + +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol);]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol); +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static std::string symbol_name (symbol_kind_type yysymbol);]])[ + +]b4_token_constructor_define[ +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + class context + { + public: + context(glr_stack & yystack, const symbol_type &yyla); + const symbol_type &lookahead() const YY_NOEXCEPT + { + return yyla_; + } + symbol_kind_type token() const YY_NOEXCEPT + { + return yyla_.kind(); + }]b4_locations_if([[ + const location_type& location () const YY_NOEXCEPT { + return yyla_.location; } +]])[ + /// Put in YYARG at most YYARGN of the expected tokens, and return the + /// number of tokens stored in YYARG. If YYARG is null, return the + /// number of expected tokens (guaranteed to be less than YYNTOKENS). + int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; + + private: + glr_stack& yystack_; + const symbol_type& yyla_; + }; +]])[ +#if] b4_api_PREFIX[DEBUG + public: + /// \brief Report a symbol value on the debug stream. + /// \param yykind The symbol kind. + /// \param yyval Its semantic value.]b4_locations_if([[ + /// \param yyloc Its location.]])[ + void yy_symbol_value_print_ (symbol_kind_type yykind, + const value_type& yyval]b4_locations_if([[, + const location_type& yyloc]])[) const; + /// \brief Report a symbol on the debug stream. + /// \param yykind The symbol kind. + /// \param yyval Its semantic value.]b4_locations_if([[ + /// \param yyloc Its location.]])[ + void yy_symbol_print_ (symbol_kind_type yykind, + const value_type& yyval]b4_locations_if([[, + const location_type& yyloc]])[) const; + private: + /// Debug stream. + std::ostream* yycdebug_; +#endif + +]b4_parse_error_bmatch( +[custom], [[ + private: + /// Report a syntax error + /// \param yyctx the context in which the error occurred. + void report_syntax_error (const context& yyctx) const;]], +[detailed\|verbose], [[ + private: + /// The arguments of the error message. + int yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const; + + /// Generate an error message. + /// \param yyctx the context in which the error occurred. + virtual std::string yysyntax_error_ (const context& yyctx) const;]])[ + + /// Convert a scanner token kind \a t to a symbol kind. + /// In theory \a t should be a token_kind_type, but character literals + /// are valid, yet not members of the token_kind_type enum. + static symbol_kind_type yytranslate_ (int t) YY_NOEXCEPT; + +]b4_parse_error_bmatch( +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// For a symbol, its name in clear. + static const char* const yytname_[]; +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// Convert the symbol name \a n to a form suitable for a diagnostic. + static std::string yytnamerr_ (const char *yystr); + + /// For a symbol, its name in clear. + static const char* const yytname_[]; +]])[ + + /// \brief Reclaim the memory associated to a symbol. + /// \param yymsg Why this token is reclaimed. + /// If null, print nothing. + /// \param yykind The symbol kind. + void yy_destroy_ (const char* yymsg, symbol_kind_type yykind, + value_type& yyval]b4_locations_if([[, + location_type& yyloc]])[); + +]b4_parse_param_vars[ + // Needs access to yy_destroy_, report_syntax_error, etc. + friend glr_stack; + }; + +]b4_token_ctor_if([b4_yytranslate_define([$1])[ +]b4_public_types_define([$1])])[ +]b4_namespace_close[ + +]b4_percent_code_get([[provides]])[ +]])[ + + +## -------------- ## +## Output files. ## +## -------------- ## + +#-- -- -- -- -- -- - # +#Header file.# +#-- -- -- -- -- -- - # + +]b4_header_if([[ +]b4_output_begin([b4_spec_header_file])[ +]b4_copyright([Skeleton interface for Bison GLR parsers in C++], + [2002-2015, 2018-2021])[ +// C++ GLR parser skeleton written by Valentin Tolmer. + +]b4_disclaimer[ +]b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_shared_declarations([hh])[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[ +]b4_output_end])[ + +#-- -- -- -- -- -- -- -- -- -- - # +#Implementation file.# +#-- -- -- -- -- -- -- -- -- -- - # + +]b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison GLR parsers in C], + [2002-2015, 2018-2021])[ +// C++ GLR parser skeleton written by Valentin Tolmer. + +]b4_disclaimer[ +]b4_identification[ + +]b4_percent_code_get([[top]])[ +]m4_if(b4_prefix, [yy], [], +[[/* Substitute the variable and function names. */ +#define yyparse ]b4_prefix[parse +#define yylex ]b4_prefix[lex +#define yyerror ]b4_prefix[error +#define yydebug ]b4_prefix[debug]])[ + +]b4_user_pre_prologue[ + +]b4_null_define[ + +]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]], + [b4_shared_declarations([cc])])[ + +namespace +{ + /* Default (constant) value used for initialization for null + right-hand sides. Unlike the standard yacc.c template, here we set + the default value of $$ to a zeroed-out value. Since the default + value is undefined, this behavior is technically correct. */ + ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default; +} + +]b4_user_post_prologue[ +]b4_percent_code_get[ + +#include +#include + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + +// Whether we are compiled with exception support. +#ifndef YY_EXCEPTIONS +# if defined __GNUC__ && !defined __EXCEPTIONS +# define YY_EXCEPTIONS 0 +# else +# define YY_EXCEPTIONS 1 +# endif +#endif + +#ifndef YYFREE +# define YYFREE free +#endif +#ifndef YYMALLOC +# define YYMALLOC malloc +#endif + +#ifndef YYSETJMP +# include +# define YYJMP_BUF jmp_buf +# define YYSETJMP(Env) setjmp(Env) +/* Pacify Clang and ICC. */ +# define YYLONGJMP(Env, Val) \ + do \ + { \ + longjmp(Env, Val); \ + YYASSERT(0); \ + } while (false) +#endif + +]b4_attribute_define([noreturn])[ + +#if defined __GNUC__ && !defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_NULL_DEREFERENCE_BEGIN \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wnull-dereference\"") +# define YY_IGNORE_NULL_DEREFERENCE_END _Pragma("GCC diagnostic pop") +#else +# define YY_IGNORE_NULL_DEREFERENCE_BEGIN +# define YY_IGNORE_NULL_DEREFERENCE_END +#endif + +]b4_null_define[ +]b4_cast_define[ + +// FIXME: Use the same conventions as lalr1.cc. +]b4_parse_assert_if[ +#ifndef YYASSERT +# define YYASSERT(Condition) ((void)((Condition) || (abort(), 0))) +#endif + +#ifdef YYDEBUG +# define YYDASSERT(Condition) YYASSERT(Condition) +#else +# define YYDASSERT(Condition) +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL ]b4_final_state_number[ +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST ]b4_last[ + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS ]b4_tokens_number[ +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS ]b4_nterms_number[ +/* YYNRULES -- Number of rules. */ +#define YYNRULES ]b4_rules_number[ +/* YYNSTATES -- Number of states. */ +#define YYNSTATES ]b4_states_number[ +/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ +#define YYMAXRHS ]b4_r2_max[ +/* YYMAXLEFT -- Maximum number of symbols to the left of a handle + accessed by $0, $-1, etc., in any rule. */ +#define YYMAXLEFT ]b4_max_left_semantic_context[ + +namespace +{ +#if] b4_api_PREFIX[DEBUG + /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ + const ]b4_int_type_for([b4_rline])[ yyrline[] = + { + ]b4_rline[ + }; +#endif + +#define YYPACT_NINF ]b4_pact_ninf[ +#define YYTABLE_NINF ]b4_table_ninf[ + +]b4_parser_tables_define[ + + /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ + const ]b4_int_type_for([b4_dprec])[ yydprec[] = + { + ]b4_dprec[ + }; + + /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ + const ]b4_int_type_for([b4_merger])[ yymerger[] = + { + ]b4_merger[ + }; + + /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as + in the case of predicates. */ + const bool yyimmediate[] = + { + ]b4_immediate[ + }; + + /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of + list of conflicting reductions corresponding to action entry for + state STATE-NUM in yytable. 0 means no conflicts. The list in + yyconfl is terminated by a rule number of 0. */ + const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = + { + ]b4_conflict_list_heads[ + }; + + /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by + 0, pointed into by YYCONFLP. */ + ]dnl Do not use b4_int_type_for here, since there are places where + dnl pointers onto yyconfl are taken, whose type is "short*". + dnl We probably ought to introduce a type for confl. + [const short yyconfl[] = + { + ]b4_conflicting_rules[ + }; +} // namespace + +/* Error token number */ +#define YYTERROR 1 + +]b4_locations_if([[ +]b4_yylloc_default_define[ +#define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc) +]])[ + +enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr }; + +#define YYCHK(YYE) \ + do \ + { \ + YYRESULTTAG yychk_flag = YYE; \ + if (yychk_flag != yyok) \ + return yychk_flag; \ + } while (false) + +#if] b4_api_PREFIX[DEBUG + +# define YYCDEBUG \ + if (!yydebug) \ + {} \ + else \ + std::cerr + +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ + do \ + { \ + if (yydebug) \ + { \ + std::cerr << Title << ' '; \ + yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \ + std::cerr << '\n'; \ + } \ + } while (false) + +# define YY_REDUCE_PRINT(Args) \ + do \ + { \ + if (yydebug) \ + yystateStack.yy_reduce_print Args; \ + } while (false) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; + +namespace +{ + using glr_stack = ]b4_namespace_ref[::]b4_parser_class[::glr_stack; + using glr_state = ]b4_namespace_ref[::]b4_parser_class[::glr_state; + + void yypstack (const glr_stack& yystack, size_t yyk) + YY_ATTRIBUTE_UNUSED; + void yypdumpstack (const glr_stack& yystack) + YY_ATTRIBUTE_UNUSED; +} + +#else /* !]b4_api_PREFIX[DEBUG */ + +# define YYCDEBUG \ + if (true) \ + {} \ + else \ + std::cerr +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ + {} +# define YY_REDUCE_PRINT(Args) \ + {} + +#endif /* !]b4_api_PREFIX[DEBUG */ + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH ]b4_stack_depth_init[ +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH ]b4_stack_depth_max[ +#endif + +/* Minimum number of free items on the stack allowed after an + allocation. This is to allow allocation and initialization + to be completed by functions that call yyexpandGLRStack before the + stack is expanded, thus insuring that all necessary pointers get + properly redirected to new data. */ +#define YYHEADROOM 2 + +#ifndef YYSTACKEXPANDABLE +# define YYSTACKEXPANDABLE 1 +#endif + +namespace +{ + template + class strong_index_alias + { + public: + static strong_index_alias create(std::ptrdiff_t value) + { + strong_index_alias result; + result.value_ = value; + return result; + } + + std::ptrdiff_t const &get() const { return value_; } + + size_t uget() const { return static_cast(value_); } + + strong_index_alias operator+(std::ptrdiff_t other) const + { + return strong_index_alias(get() + other); + } + + void operator+=(std::ptrdiff_t other) { value_ += other; } + + strong_index_alias operator-(std::ptrdiff_t other) + { + return strong_index_alias(get() - other); + } + + void operator-=(std::ptrdiff_t other) { value_ -= other; } + + size_t operator-(strong_index_alias other) + { + return strong_index_alias(get() - other.get()); + } + + strong_index_alias &operator++() + { + ++value_; + return *this; + } + + bool isValid() const { return value_ != INVALID_INDEX; } + + void setInvalid() { value_ = INVALID_INDEX; } + + bool operator==(strong_index_alias other) { return get() == other.get(); } + + bool operator!=(strong_index_alias other) { return get() != other.get(); } + + bool operator<(strong_index_alias other) { return get() < other.get(); } + + private: + static const std::ptrdiff_t INVALID_INDEX; + + // WARNING: 0-initialized. + std::ptrdiff_t value_; + }; // class strong_index_alias + + template + const std::ptrdiff_t strong_index_alias::INVALID_INDEX = + std::numeric_limits::max(); + + using state_set_index = strong_index_alias; + + state_set_index create_state_set_index(std::ptrdiff_t value) + { + return state_set_index::create(value); + } + + /** State numbers, as in LALR(1) machine */ + using state_num = int; + + /** Rule numbers, as in LALR(1) machine */ + using rule_num = int; + + using parser_type = ]b4_namespace_ref[::]b4_parser_class[; + using glr_state = parser_type::glr_state; + using symbol_kind = parser_type::symbol_kind; + using symbol_kind_type = parser_type::symbol_kind_type; + using symbol_type = parser_type::symbol_type; + using value_type = parser_type::value_type;]b4_locations_if([[ + using location_type = parser_type::location_type;]])[ + + // Forward declarations. + class glr_stack_item; + class semantic_option; +} // namespace + +namespace +{ + /** Accessing symbol of state YYSTATE. */ + inline symbol_kind_type yy_accessing_symbol(state_num yystate) + { + return YY_CAST(symbol_kind_type, yystos[yystate]); + } + + /** Left-hand-side symbol for rule #YYRULE. */ + inline symbol_kind_type yylhsNonterm(rule_num yyrule) + { + return static_cast(yyr1[yyrule]); + } + + /** Number of symbols composing the right hand side of rule #RULE. */ + inline int yyrhsLength(rule_num yyrule) + { + return yyr2[yyrule]; + } +} + +namespace ]b4_namespace_ref[ +{ + class ]b4_parser_class[::glr_state + { + public: + glr_state () + : yyresolved (false) + , yylrState (0) + , yyposn (0) + , yypred (0) + , yyfirstVal (0)]b4_locations_if([[ + , yyloc ()]])[]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {} + + /// Build with a semantic value. + glr_state (state_num lrState, size_t posn, const value_type& val]b4_locations_if([[, const location_type& loc]])[) + : yyresolved (true) + , yylrState (lrState) + , yyposn (posn) + , yypred (0) + , yyval (]b4_variant_if([], [[val]])[)]b4_locations_if([[ + , yyloc (loc)]])[]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {]b4_variant_if([[ + ]b4_symbol_variant([yy_accessing_symbol (lrState)], + [yyval], [copy], [val])])[} + + /// Build with a semantic option. + glr_state (state_num lrState, size_t posn) + : yyresolved (false) + , yylrState (lrState) + , yyposn (posn) + , yypred (0) + , yyfirstVal (0)]b4_locations_if([[ + , yyloc ()]])[]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {} + + glr_state (const glr_state& other) + : yyresolved (other.yyresolved) + , yylrState (other.yylrState) + , yyposn (other.yyposn) + , yypred (0)]b4_locations_if([[ + , yyloc (other.yyloc)]])[]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + { + setPred(other.pred()); + if (other.yyresolved)]b4_variant_if([[ + { + new (&yyval) value_type(); + ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)], + [yyval], [copy], [other.value ()])[ + }]], [[ + new (&yyval) value_type (other.value ());]])[ + else + { + yyfirstVal = 0; + setFirstVal(other.firstVal()); + }]b4_parse_assert_if([[ + check_();]])[ + } + + ~glr_state () + {]b4_parse_assert_if([[ + check_ ();]])[ + if (yyresolved) + {]b4_variant_if([[ + symbol_kind_type yykind = yy_accessing_symbol (yylrState); + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yykind]], [[yyval]], [[template destroy]])])[ + yyval.~value_type (); + }]b4_parse_assert_if([[ + magic_ = 0;]])[ + } + + glr_state& operator= (const glr_state& other) + {]b4_parse_assert_if([[ + check_ (); + other.check_ ();]])[ + if (!yyresolved && other.yyresolved) + new (&yyval) value_type; + yyresolved = other.yyresolved; + yylrState = other.yylrState; + yyposn = other.yyposn; + setPred (other.pred ()); + if (other.yyresolved)]b4_variant_if([[ + ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)], + [yyval], [copy], [other.value ()])], [[ + value () = other.value ();]])[ + else + setFirstVal (other.firstVal ());]b4_locations_if([[ + yyloc = other.yyloc;]])[ + return *this; + } + + /** Type tag for the semantic value. If true, yyval applies, otherwise + * yyfirstVal applies. */ + bool yyresolved; + /** Number of corresponding LALR(1) machine state. */ + state_num yylrState; + /** Source position of the last token produced by my symbol */ + size_t yyposn; + + /// Only call pred() and setPred() on objects in yyitems, not temporaries. + glr_state* pred (); + const glr_state* pred () const; + void setPred (const glr_state* state); + + /// Only call firstVal() and setFirstVal() on objects in yyitems, not + /// temporaries. + semantic_option* firstVal (); + const semantic_option* firstVal () const; + void setFirstVal (const semantic_option* option); + + value_type& value () + {]b4_parse_assert_if([[ + check_ ();]])[ + return yyval; + } + + const value_type& value () const + {]b4_parse_assert_if([[ + check_ ();]])[ + return yyval; + } + + void + destroy (char const *yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser); + + /* DEBUGGING ONLY */ +#if] b4_api_PREFIX[DEBUG + void yy_yypstack () const + {]b4_parse_assert_if([[ + check_ ();]])[ + if (pred () != YY_NULLPTR) + { + pred()->yy_yypstack(); + std::cerr << " -> "; + } + std::cerr << yylrState << "@@" << yyposn; + } +#endif + + std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED; + + glr_stack_item* asItem () + {]b4_parse_assert_if([[ + check_ ();]])[ + return asItem(this); + } + + const glr_stack_item* asItem () const + {]b4_parse_assert_if([[ + check_ ();]])[ + return asItem (this); + } + + private: + template + static const glr_stack_item* asItem (const T* state) + { + return reinterpret_cast(state); + } + template + static glr_stack_item* asItem (T* state) + { + return reinterpret_cast(state); + } + static const char *as_pointer_ (const glr_state *state) + { + return reinterpret_cast(state); + } + static char *as_pointer_ (glr_state *state) + { + return reinterpret_cast(state); + } + /** Preceding state in this stack */ + std::ptrdiff_t yypred; + union { + /** First in a chain of alternative reductions producing the + * nonterminal corresponding to this state, threaded through + * yyfirstVal. Value "0" means empty. */ + std::ptrdiff_t yyfirstVal; + /** Semantic value for this state. */ + value_type yyval; + };]b4_locations_if([[ + // FIXME: Why public? + public: + /** Source location for this state. */ + location_type yyloc;]])[ + +]b4_parse_assert_if([[ + public: + // Check invariants. + void check_ () const + { + YY_IGNORE_NULL_DEREFERENCE_BEGIN + YYASSERT(this->magic_ == MAGIC); + YY_IGNORE_NULL_DEREFERENCE_END + } + + // A magic number to check our pointer arithmetic is sane. + enum { MAGIC = 713705 }; + unsigned int magic_;]])[ + }; // class ]b4_parser_class[::glr_state +} // namespace ]b4_namespace_ref[ + + +namespace +{ + /** A stack of GLRState representing the different heads during + * nondeterministic evaluation. */ + class glr_state_set + { + public: + /** Initialize YYSET to a singleton set containing an empty stack. */ + glr_state_set() : yylastDeleted(YY_NULLPTR) + { + yystates.push_back(YY_NULLPTR); + yylookaheadNeeds.push_back(false); + } + + // Behave like a vector of states. + glr_state *&operator[](state_set_index index) { return yystates[index.uget()]; } + + glr_state *operator[](state_set_index index) const { return yystates[index.uget()]; } + + size_t size() const { return yystates.size(); } + + std::vector::iterator begin() { return yystates.begin(); } + + std::vector::iterator end() { return yystates.end(); } + + bool lookaheadNeeds(state_set_index index) const { return yylookaheadNeeds[index.uget()]; } + + bool setLookaheadNeeds(state_set_index index, bool value) + { + return yylookaheadNeeds[index.uget()] = value; + } + + /** Invalidate stack #YYK. */ + void yymarkStackDeleted(state_set_index yyk) + { + size_t k = yyk.uget(); + if (yystates[k] != YY_NULLPTR) + yylastDeleted = yystates[k]; + yystates[k] = YY_NULLPTR; + } + + /** Undelete the last stack in *this that was marked as deleted. Can + only be done once after a deletion, and only when all other stacks have + been deleted. */ + void yyundeleteLastStack() + { + if (yylastDeleted == YY_NULLPTR || !yystates.empty()) + return; + yystates.push_back(yylastDeleted); + YYCDEBUG << "Restoring last deleted stack as stack #0.\n"; + clearLastDeleted(); + } + + /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later + * ones. */ + void yyremoveDeletes() + { + size_t newsize = yystates.size(); + /* j is the number of live stacks we have seen. */ + for (size_t i = 0, j = 0; j < newsize; ++i) + { + if (yystates[i] == YY_NULLPTR) + { + if (i == j) + { + YYCDEBUG << "Removing dead stacks.\n"; + } + newsize -= 1; + } + else + { + yystates[j] = yystates[i]; + /* In the current implementation, it's unnecessary to copy + yylookaheadNeeds[i] since, after + yyremoveDeletes returns, the parser immediately either enters + deterministic operation or shifts a token. However, it doesn't + hurt, and the code might evolve to need it. */ + yylookaheadNeeds[j] = yylookaheadNeeds[i]; + if (j != i) + { + YYCDEBUG << "Rename stack " << i << " -> " << j << ".\n"; + } + j += 1; + } + } + yystates.resize(newsize); + yylookaheadNeeds.resize(newsize); + } + + state_set_index yysplitStack(state_set_index yyk) + { + const size_t k = yyk.uget(); + yystates.push_back(yystates[k]); + yylookaheadNeeds.push_back(yylookaheadNeeds[k]); + return create_state_set_index(static_cast(yystates.size() - 1)); + } + + void clearLastDeleted() { yylastDeleted = YY_NULLPTR; } + + private: + std::vector yystates; + /** During nondeterministic operation, yylookaheadNeeds tracks which + * stacks have actually needed the current lookahead. During deterministic + * operation, yylookaheadNeeds[0] is not maintained since it would merely + * duplicate !yyla.empty (). */ + std::vector yylookaheadNeeds; + + /** The last stack we invalidated. */ + glr_state *yylastDeleted; + }; // class glr_state_set +} // namespace + +namespace +{ + class semantic_option + { + public: + semantic_option () + : yyrule (0) + , yystate (0) + , yynext (0) + , yyla ()]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {} + + semantic_option (rule_num rule) + : yyrule (rule) + , yystate (0) + , yynext (0) + , yyla ()]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {} + + semantic_option (const semantic_option& that) + : yyrule (that.yyrule) + , yystate (that.yystate) + , yynext (that.yynext) + , yyla (that.yyla)]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {]b4_parse_assert_if([[ + that.check_ ();]])[ + } + + // Needed for the assignment in yynewSemanticOption. + semantic_option& operator= (const semantic_option& that) + {]b4_parse_assert_if([[ + check_ (); + that.check_ ();]])[ + yyrule = that.yyrule; + yystate = that.yystate; + yynext = that.yynext; + yyla = that.yyla; + return *this; + } + + /// Only call state() and setState() on objects in yyitems, not temporaries. + glr_state* state(); + const glr_state* state() const; + void setState(const glr_state* s); + + const semantic_option* next () const YY_ATTRIBUTE_UNUSED; + semantic_option* next (); + void setNext (const semantic_option* s); + + std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED; + + /** True iff YYY0 and YYY1 represent identical options at the top level. + * That is, they represent the same rule applied to RHS symbols + * that produce the same terminal symbols. */ + bool + isIdenticalTo (const semantic_option& yyy1) const + {]b4_parse_assert_if([[ + check_ (); + yyy1.check_ ();]])[ + if (this->yyrule == yyy1.yyrule) + { + const glr_state *yys0, *yys1; + int yyn; + for (yys0 = this->state(), yys1 = yyy1.state(), yyn = yyrhsLength(this->yyrule); + yyn > 0; yys0 = yys0->pred(), yys1 = yys1->pred(), yyn -= 1) + if (yys0->yyposn != yys1->yyposn) + return false; + return true; + } + else + return false; + } + + /** Assuming identicalOptions (YYY0,YYY1), destructively merge the + * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */ + void + mergeWith (semantic_option& yyy1) + {]b4_parse_assert_if([[ + check_ (); + yyy1.check_ ();]])[ + glr_state *yys0 = this->state (); + glr_state *yys1 = yyy1.state (); + for (int yyn = yyrhsLength (this->yyrule); + yyn > 0; + yyn -= 1, yys0 = yys0->pred (), yys1 = yys1->pred ()) + { + if (yys0 == yys1) + break; + else if (yys0->yyresolved) + { + yys1->yyresolved = true;]b4_variant_if([[ + YYASSERT (yys1->yylrState == yys0->yylrState); + ]b4_symbol_variant([yy_accessing_symbol (yys0->yylrState)], + [yys1->value ()], [copy], [yys0->value ()])], [[ + yys1->value () = yys0->value ();]])[ + } + else if (yys1->yyresolved) + { + yys0->yyresolved = true;]b4_variant_if([[ + YYASSERT (yys0->yylrState == yys1->yylrState); + ]b4_symbol_variant([yy_accessing_symbol (yys1->yylrState)], + [yys0->value ()], [copy], [yys1->value ()])], [[ + yys0->value () = yys1->value ();]])[ + } + else + { + semantic_option *yyz0prev = YY_NULLPTR; + semantic_option *yyz0 = yys0->firstVal(); + semantic_option *yyz1 = yys1->firstVal(); + while (true) + { + if (yyz1 == yyz0 || yyz1 == YY_NULLPTR) + break; + else if (yyz0 == YY_NULLPTR) + { + if (yyz0prev != YY_NULLPTR) + yyz0prev->setNext(yyz1); + else + yys0->setFirstVal(yyz1); + break; + } + else if (yyz0 < yyz1) + { + semantic_option *yyz = yyz0; + if (yyz0prev != YY_NULLPTR) + yyz0prev->setNext(yyz1); + else + yys0->setFirstVal(yyz1); + yyz1 = yyz1->next(); + yyz0->setNext(yyz); + } + yyz0prev = yyz0; + yyz0 = yyz0->next(); + } + yys1->setFirstVal(yys0->firstVal()); + } + } + } + +#if] b4_api_PREFIX[DEBUG + void yyreportTree (size_t yyindent = 2) const + {]b4_parse_assert_if([[ + check_ ();]])[ + int yynrhs = yyrhsLength (this->yyrule); + const glr_state* yystates[1 + YYMAXRHS]; + glr_state yyleftmost_state; + + { + const glr_state *yys = this->state(); + for (int yyi = yynrhs; 0 < yyi; yyi -= 1) + { + yystates[yyi] = yys; + yys = yys->pred(); + } + if (yys == YY_NULLPTR) + { + yyleftmost_state.yyposn = 0; + yystates[0] = &yyleftmost_state; + } + else + yystates[0] = yys; + } + + std::string yylhs = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yylhsNonterm (this->yyrule)); + YYASSERT(this->state()); + if (this->state()->yyposn < yystates[0]->yyposn + 1) + std::cerr << std::string(yyindent, ' ') << yylhs << " -> yyrule - 1 << ", empty>\n"; + else + std::cerr << std::string(yyindent, ' ') << yylhs << " -> yyrule - 1 << ", tokens " + << yystates[0]->yyposn + 1 << " .. " + << this->state()->yyposn << ">\n"; + for (int yyi = 1; yyi <= yynrhs; yyi += 1) + { + if (yystates[yyi]->yyresolved) + { + std::string yysym = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)); + if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) + std::cerr << std::string(yyindent + 2, ' ') << yysym + << " \n"; + else + std::cerr << std::string(yyindent + 2, ' ') << yysym + << " yyposn + 1 + << " .. " << yystates[yyi]->yyposn << ">\n"; + } + else + yystates[yyi]->firstVal()->yyreportTree(yyindent + 2); + } + } +#endif + + /** Rule number for this reduction */ + rule_num yyrule; + + private: + template + static const glr_stack_item* asItem(const T* state) + { + return reinterpret_cast(state); + } + template + static glr_stack_item* asItem(T* state) + { + return reinterpret_cast(state); + } + /** The last RHS state in the list of states to be reduced. */ + std::ptrdiff_t yystate; + /** Next sibling in chain of options. To facilitate merging, + * options are chained in decreasing order by address. */ + std::ptrdiff_t yynext; + + public: + /** The lookahead for this reduction. */ + symbol_type yyla; + +]b4_parse_assert_if([[ + public: + // Check invariants. + void check_ () const + { + YY_IGNORE_NULL_DEREFERENCE_BEGIN + YYASSERT(this->magic_ == MAGIC); + YY_IGNORE_NULL_DEREFERENCE_END + } + + // A magic number to check our pointer arithmetic is sane. + enum { MAGIC = 0xeff1cace }; + unsigned int magic_;]])[ + }; // class semantic_option +} // namespace + +namespace +{ + /** Type of the items in the GLR stack. + * It can be either a glr_state or a semantic_option. The is_state_ field + * indicates which item of the union is valid. */ + class glr_stack_item + { + public: + glr_stack_item (bool state = true) + : is_state_ (state)]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + { + if (is_state_) + new (&raw_) glr_state; + else + new (&raw_) semantic_option; + } + + glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW + : is_state_ (other.is_state_)]b4_parse_assert_if([[ + , magic_ (MAGIC)]])[ + {]b4_parse_assert_if([[ + other.check_ ();]])[ + std::memcpy (raw_, other.raw_, union_size); + } + + glr_stack_item& operator= (glr_stack_item other) + {]b4_parse_assert_if([[ + check_ (); + other.check_ ();]])[ + std::swap (is_state_, other.is_state_); + std::swap (raw_, other.raw_); + return *this; + } + + ~glr_stack_item () + {]b4_parse_assert_if([[ + check_ ();]])[ + if (is_state ()) + getState ().~glr_state (); + else + getOption ().~semantic_option (); + } + + void setState (const glr_state &state) + {]b4_parse_assert_if([[ + check_ (); + state.check_ ();]])[ + if (this != state.asItem ()) + { + if (is_state_) + getState().~glr_state(); + else + getOption().~semantic_option(); + new (&raw_) glr_state(state); + is_state_ = true; + } + } + + glr_state& getState () + {]b4_parse_assert_if([[ + check_ ();]])[ + YYDASSERT (is_state ()); + void *yyp = raw_; + glr_state& res = *static_cast (yyp);]b4_parse_assert_if([[ + res.check_ ();]])[ + return res; + } + + const glr_state& getState () const + {]b4_parse_assert_if([[ + check_ ();]])[ + YYDASSERT (is_state ()); + const void *yyp = raw_; + const glr_state& res = *static_cast (yyp);]b4_parse_assert_if([[ + res.check_ ();]])[ + return res; + } + + semantic_option& getOption () + {]b4_parse_assert_if([[ + check_ ();]])[ + YYDASSERT (!is_state ()); + void *yyp = raw_; + return *static_cast (yyp); + } + const semantic_option& getOption () const + {]b4_parse_assert_if([[ + check_ ();]])[ + YYDASSERT (!is_state ()); + const void *yyp = raw_; + return *static_cast (yyp); + } + bool is_state () const + {]b4_parse_assert_if([[ + check_ ();]])[ + return is_state_; + } + + private: + /// The possible contents of raw_. Since they have constructors, they cannot + /// be directly included in the union. + union contents + { + char yystate[sizeof(glr_state)]; + char yyoption[sizeof(semantic_option)]; + }; + enum { union_size = sizeof (contents) }; + union { + /// Strongest alignment constraints. + long double yyalign_me; + /// A buffer large enough to store the contents. + char raw_[union_size]; + }; + /** Type tag for the union. */ + bool is_state_; +]b4_parse_assert_if([[ + public: + // Check invariants. + void check_ () const + { + YYASSERT(this->magic_ == MAGIC); + YYASSERT(this->is_state_ == false || this->is_state_ == true); + } + // A magic number to check our pointer arithmetic is sane. + enum { MAGIC = 0xDEAD1ACC }; // 3735886540. + const unsigned int magic_;]])[ + }; // class glr_stack_item +} // namespace + +glr_state* glr_state::pred () +{]b4_parse_assert_if([[ + check_ ();]])[ + YY_IGNORE_NULL_DEREFERENCE_BEGIN + return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR; + YY_IGNORE_NULL_DEREFERENCE_END +} + +const glr_state* glr_state::pred () const +{]b4_parse_assert_if([[ + check_ ();]])[ + YY_IGNORE_NULL_DEREFERENCE_BEGIN + return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR; + YY_IGNORE_NULL_DEREFERENCE_END +} + +void glr_state::setPred (const glr_state* state) +{]b4_parse_assert_if([[ + check_ (); + if (state) + state->check_ ();]])[ + yypred = state ? as_pointer_ (this) - as_pointer_ (state) : 0; +} + +semantic_option* glr_state::firstVal () +{]b4_parse_assert_if([[ + check_ ();]])[ + return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR; +} + +const semantic_option* glr_state::firstVal () const +{]b4_parse_assert_if([[ + check_ ();]])[ + return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR; +} + +void glr_state::setFirstVal (const semantic_option* option) +{]b4_parse_assert_if([[ + check_ ();]])[ + yyfirstVal = option ? asItem(this) - asItem(option) : 0; +} + +std::ptrdiff_t glr_state::indexIn (const glr_stack_item* array) const +{]b4_parse_assert_if([[ + check_ ();]])[ + return asItem(this) - array; +} + +std::ptrdiff_t semantic_option::indexIn (const glr_stack_item* array) const +{ + return asItem(this) - array; +} + +glr_state* semantic_option::state () +{ + YY_IGNORE_NULL_DEREFERENCE_BEGIN + return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR; + YY_IGNORE_NULL_DEREFERENCE_END +} + +const glr_state* semantic_option::state () const +{ + return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR; +} + +void semantic_option::setState (const glr_state* s) +{ + yystate = s ? asItem(this) - asItem(s) : 0; +} + +const semantic_option* semantic_option::next () const +{ + return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR; +} + +semantic_option* semantic_option::next () +{ + return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR; +} + +void semantic_option::setNext (const semantic_option* s) +{ + yynext = s ? asItem(this) - asItem(s) : 0; +} + +void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser) +{]b4_parse_assert_if([[ + check_ ();]])[ + if (yyresolved) + yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState), + value ()]b4_locations_if([, yyloc])[); + else + { +#if] b4_api_PREFIX[DEBUG + YYCDEBUG << yymsg + << (firstVal() ? " unresolved " : " incomplete ") + << (yy_accessing_symbol (yylrState) < YYNTOKENS ? "token" : "nterm") + << ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState)) + << " ("]b4_locations_if([[ + << yyloc << ": "]])[ + << ")\n"; +#endif + if (firstVal() != YY_NULLPTR) + { + semantic_option &yyoption = *firstVal(); + glr_state *yyrh = yyoption.state(); + for (int yyn = yyrhsLength(yyoption.yyrule); yyn > 0; yyn -= 1) + { + yyrh->destroy(yymsg, yyparser); + yyrh = yyrh->pred(); + } + } + } +} + +#undef YYFILL +#define YYFILL(N) yyfill(yyvsp, yylow, (N), yynormal) + +namespace +{ + class state_stack + { + public: + using parser_type = ]b4_namespace_ref[::]b4_parser_class[; + using symbol_kind = parser_type::symbol_kind; + using value_type = parser_type::value_type;]b4_locations_if([[ + using location_type = parser_type::location_type;]])[ + + /** Initialize to a single empty stack, with total maximum + * capacity for all stacks of YYSIZE. */ + state_stack (size_t yysize) + : yysplitPoint (YY_NULLPTR) + { + yyitems.reserve(yysize); + } + +#if YYSTACKEXPANDABLE + /** Returns false if it tried to expand but could not. */ + bool + yyexpandGLRStackIfNeeded () + { + return YYHEADROOM <= spaceLeft() || yyexpandGLRStack(); + } + + private: + /** If *this is expandable, extend it. WARNING: Pointers into the + stack from outside should be considered invalid after this call. + We always expand when there are 1 or fewer items left AFTER an + allocation, so that we can avoid having external pointers exist + across an allocation. */ + bool + yyexpandGLRStack () + { + const size_t oldsize = yyitems.size(); + if (YYMAXDEPTH - YYHEADROOM < oldsize) + return false; + const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize; + const glr_stack_item *oldbase = &yyitems[0]; + + yyitems.reserve(yynewSize); + const glr_stack_item *newbase = &yyitems[0]; + + // Adjust the pointers. Perform raw pointer arithmetic, as there + // is no reason for objects to be aligned on their size. + const ptrdiff_t disp = + reinterpret_cast(newbase) - reinterpret_cast(oldbase); + if (yysplitPoint) + const_cast(yysplitPoint) = reinterpret_cast( + reinterpret_cast(const_cast(yysplitPoint)) + disp); + + for (std::vector::iterator i = yytops.begin(), yyend = yytops.end(); + i != yyend; ++i) + if (glr_state_not_null(*i)) + *i = reinterpret_cast(reinterpret_cast(*i) + disp); + + return true; + } + + public: +#else + bool yyexpandGLRStackIfNeeded () + { + return YYHEADROOM <= spaceLeft(); + } +#endif +#undef YYSTACKEXPANDABLE + + static bool glr_state_not_null (glr_state* s) + { + return s != YY_NULLPTR; + } + + bool + reduceToOneStack () + { + using iterator = std::vector::iterator; + const iterator yybegin = yytops.begin(); + const iterator yyend = yytops.end(); + const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null); + if (yyit == yyend) + return false; + for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin); + yyk.uget() != numTops(); ++yyk) + yytops.yymarkStackDeleted(yyk); + yytops.yyremoveDeletes(); + yycompressStack(); + return true; + } + + /** Called when returning to deterministic operation to clean up the extra + * stacks. */ + void + yycompressStack () + { + if (yytops.size() != 1 || !isSplit()) + return; + + // yyr is the state after the split point. + glr_state *yyr = YY_NULLPTR; + for (glr_state *yyp = firstTop(), *yyq = yyp->pred(); yyp != yysplitPoint; + yyr = yyp, yyp = yyq, yyq = yyp->pred()) + yyp->setPred(yyr); + + // This const_cast is okay, since anyway we have access to the mutable + // yyitems into which yysplitPoint points. + glr_stack_item *nextFreeItem = const_cast(yysplitPoint)->asItem() + 1; + yysplitPoint = YY_NULLPTR; + yytops.clearLastDeleted(); + + while (yyr != YY_NULLPTR) + { + nextFreeItem->setState(*yyr); + glr_state &nextFreeState = nextFreeItem->getState(); + yyr = yyr->pred(); + nextFreeState.setPred(&(nextFreeItem - 1)->getState()); + setFirstTop(&nextFreeState); + ++nextFreeItem; + } + yyitems.resize(static_cast(nextFreeItem - yyitems.data())); + } + + bool isSplit() const { + return yysplitPoint != YY_NULLPTR; + } + + // Present the interface of a vector of glr_stack_item. + std::vector::const_iterator begin () const + { + return yyitems.begin(); + } + + std::vector::const_iterator end () const + { + return yyitems.end(); + } + + size_t size() const + { + return yyitems.size(); + } + + glr_stack_item& operator[] (size_t i) + { + return yyitems[i]; + } + + glr_stack_item& stackItemAt (size_t index) + { + return yyitems[index]; + } + + size_t numTops () const + { + return yytops.size(); + } + + glr_state* firstTop () const + { + return yytops[create_state_set_index(0)]; + } + + glr_state* topAt (state_set_index i) const + { + return yytops[i]; + } + + void setFirstTop (glr_state* value) + { + yytops[create_state_set_index(0)] = value; + } + + void setTopAt (state_set_index i, glr_state* value) + { + yytops[i] = value; + } + + void pop_back () + { + yyitems.pop_back(); + } + + void pop_back (size_t n) + { + yyitems.resize(yyitems.size() - n); + } + + state_set_index + yysplitStack (state_set_index yyk) + { + if (!isSplit()) + { + YYASSERT(yyk.get() == 0); + yysplitPoint = topAt(yyk); + } + return yytops.yysplitStack(yyk); + } + + /** Assuming that YYS is a GLRState somewhere on *this, update the + * splitpoint of *this, if needed, so that it is at least as deep as + * YYS. */ + void + yyupdateSplit (glr_state& yys) + { + if (isSplit() && &yys < yysplitPoint) + yysplitPoint = &yys; + } + + /** Return a fresh GLRState. + * Callers should call yyreserveStack afterwards to make sure there is + * sufficient headroom. */ + glr_state& yynewGLRState (const glr_state& newState) + { + glr_state &state = yyitems[yynewGLRStackItem(true)].getState(); +#if false && 201103L <= YY_CPLUSPLUS + state = std::move (newState); +#else + state = newState; +#endif + return state; + } + + /** Return a fresh SemanticOption. + * Callers should call yyreserveStack afterwards to make sure there is + * sufficient headroom. */ + semantic_option& yynewSemanticOption (semantic_option newOption) + { + semantic_option &option = yyitems[yynewGLRStackItem(false)].getOption(); + option = std::move(newOption); + return option; + } + + /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in + * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. + * For convenience, always return YYLOW1. */ + int + yyfill (glr_stack_item *yyvsp, int &yylow, int yylow1, bool yynormal) + { + if (!yynormal && yylow1 < yylow) + { + yyfillin(yyvsp, yylow, yylow1); + yylow = yylow1; + } + return yylow1; + } + + /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting + * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred() + * containing the pointer to the next state in the chain. */ + void + yyfillin (glr_stack_item *yyvsp, int yylow0, int yylow1) + { + glr_state *s = yyvsp[yylow0].getState().pred(); + YYASSERT(s != YY_NULLPTR); + for (int i = yylow0 - 1; i >= yylow1; i -= 1, s = s->pred()) + { + glr_state &yys = yyvsp[i].getState(); +#if] b4_api_PREFIX[DEBUG + yys.yylrState = s->yylrState; +#endif + yys.yyresolved = s->yyresolved; + if (s->yyresolved) + {]b4_variant_if([[ + new (&yys.value ()) value_type (); + ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)], + [yys.value ()], [copy], [s->value ()])], [[ + new (&yys.value ()) value_type (s->value ());]])[ + } + else + /* The effect of using yyval or yyloc (in an immediate + * rule) is undefined. */ + yys.setFirstVal(YY_NULLPTR);]b4_locations_if([[ + yys.yyloc = s->yyloc;]])[ + yys.setPred(s->pred()); + } + } + +#if] b4_api_PREFIX[DEBUG + + /*----------------------------------------------------------------------. + | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. | + `----------------------------------------------------------------------*/ + + void + yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk, + rule_num yyrule, parser_type& yyparser) + { + int yynrhs = yyrhsLength(yyrule);]b4_locations_if([ + int yylow = 1;])[ + int yyi; + std::cerr << "Reducing stack " << yyk.get() << " by rule " << yyrule - 1 + << " (line " << int (yyrline[yyrule]) << "):\n"; + if (! yynormal) + yyfillin (yyvsp, 1, -yynrhs); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + std::cerr << " $" << yyi + 1 << " = "; + yyparser.yy_symbol_print_ + (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState), + yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[, + ]b4_rhs_location(yynrhs, yyi + 1)])[); + if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved) + std::cerr << " (unresolved)"; + std::cerr << '\n'; + } + } + +# define YYINDEX(YYX) ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn(yyitems.data())) + + void + dumpStack () const + { + for (size_t yyi = 0; yyi < size(); ++yyi) + { + const glr_stack_item &item = yyitems[yyi]; + std::cerr << std::setw(3) << yyi << ". "; + if (item.is_state()) + { + std::cerr << "Res: " << item.getState().yyresolved + << ", LR State: " << item.getState().yylrState + << ", posn: " << item.getState().yyposn + << ", pred: " << YYINDEX(item.getState().pred()); + if (!item.getState().yyresolved) + std::cerr << ", firstVal: " << YYINDEX(item.getState().firstVal()); + } + else + { + std::cerr << "Option. rule: " << item.getOption().yyrule - 1 + << ", state: " << YYINDEX(item.getOption().state()) + << ", next: " << YYINDEX(item.getOption().next()); + } + std::cerr << '\n'; + } + std::cerr << "Tops:"; + for (state_set_index yyi = create_state_set_index(0); yyi.uget() < numTops(); ++yyi) + { + std::cerr << yyi.get() << ": " << YYINDEX(topAt(yyi)) << "; "; + } + std::cerr << '\n'; + } + +# undef YYINDEX +#endif + + YYRESULTTAG + yyreportAmbiguity (const semantic_option& yyx0, + const semantic_option& yyx1, parser_type& yyparser]b4_locations_if([, const location_type& yyloc])[) + { + YY_USE(yyx0); + YY_USE(yyx1); + +#if] b4_api_PREFIX[DEBUG + std::cerr << "Ambiguity detected.\n" + "Option 1,\n"; + yyx0.yyreportTree(); + std::cerr << "\nOption 2,\n"; + yyx1.yyreportTree(); + std::cerr << '\n'; +#endif + + yyparser.error (]b4_locations_if([yyloc, ])[YY_("syntax is ambiguous")); + return yyabort; + } + +#if] b4_api_PREFIX[DEBUG + /* Print YYS (possibly NULL) and its predecessors. */ + void + yypstates (const glr_state* yys) const + { + if (yys != YY_NULLPTR) + yys->yy_yypstack(); + else + std::cerr << ""; + std::cerr << '\n'; + } +#endif + + private: + size_t spaceLeft() const + { + return yyitems.capacity() - yyitems.size(); + } + + /** Return a fresh GLRStackItem in this. The item is an LR state + * if YYIS_STATE, and otherwise a semantic option. Callers should call + * yyreserveStack afterwards to make sure there is sufficient + * headroom. */ + size_t + yynewGLRStackItem (bool yyis_state) + { + YYDASSERT(yyitems.size() < yyitems.capacity()); + yyitems.push_back(glr_stack_item(yyis_state)); + return yyitems.size() - 1; + } + + + public: + std::vector yyitems; + // Where the stack splits. Anything below this address is deterministic. + const glr_state* yysplitPoint; + glr_state_set yytops; + }; // class state_stack +} // namespace + +#undef YYFILL +#define YYFILL(N) yystateStack.yyfill(yyvsp, yylow, (N), yynormal) + +namespace ]b4_namespace_ref[ +{ + class ]b4_parser_class[::glr_stack + { + public: +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + // Needs access to yypact_value_is_default, etc. + friend context; +]])[ + + glr_stack (size_t yysize, parser_type& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[) + : yyerrState (0) + , yystateStack (yysize) + , yyerrcnt (0) + , yyla () + , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[ + {} + + ~glr_stack () + { + if (!this->yyla.empty()) + yyparser.yy_destroy_ ("Cleanup: discarding lookahead", + this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[); + popall_(); + } + + int yyerrState; +]b4_locations_if([[ /* To compute the location of the error token. */ + glr_stack_item yyerror_range[3];]])[ + state_stack yystateStack; + int yyerrcnt; + symbol_type yyla; + YYJMP_BUF yyexception_buffer; + parser_type& yyparser; + +#define YYCHK1(YYE) \ + do \ + { \ + switch (YYE) \ + { \ + case yyok: \ + break; \ + case yyabort: \ + goto yyabortlab; \ + case yyaccept: \ + goto yyacceptlab; \ + case yyerr: \ + goto yyuser_error; \ + default: \ + goto yybuglab; \ + } \ + } while (false) + + int + parse () + { + int yyresult; + size_t yyposn; + + YYCDEBUG << "Starting parse\n"; + + this->yyla.clear(); +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl + b4_user_initial_action +b4_dollar_popdef])[]dnl +[ + switch (YYSETJMP (this->yyexception_buffer)) + { + case 0: + break; + case 1: + goto yyabortlab; + case 2: + goto yyexhaustedlab; + default: + goto yybuglab; + } + this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla.value]b4_locations_if([, this->yyla.location])[); + yyposn = 0; + + while (true) + { + /* For efficiency, we have two loops, the first of which is + specialized to deterministic operation (single stack, no + potential ambiguity). */ + /* Standard mode */ + while (true) + { + const state_num yystate = this->firstTopState()->yylrState; + YYCDEBUG << "Entering state " << yystate << '\n'; + if (yystate == YYFINAL) + goto yyacceptlab; + if (yy_is_defaulted_state(yystate)) + { + const rule_num yyrule = yy_default_action(yystate); + if (yyrule == 0) + {]b4_locations_if([[ + this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[ + this->yyreportSyntaxError (); + goto yyuser_error; + } + YYCHK1(this->yyglrReduce(create_state_set_index(0), yyrule, true)); + } + else + { + yyget_token(); + const short *yyconflicts; + const int yyaction = + yygetLRActions(yystate, this->yyla.kind(), yyconflicts); + if (*yyconflicts != 0) + break; + if (yy_is_shift_action(yyaction)) + { + YY_SYMBOL_PRINT("Shifting", this->yyla.kind(), this->yyla.value, + this->yyla.location); + yyposn += 1; + // FIXME: we should move yylval. + this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[); + yyla.clear(); + if (0 < this->yyerrState) + this->yyerrState -= 1; + } + else if (yy_is_error_action(yyaction)) + {]b4_locations_if([[ + this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[ + /* Don't issue an error message again for exceptions + thrown from the scanner. */ + if (this->yyla.kind () != ]b4_symbol(error, kind)[) + this->yyreportSyntaxError (); + goto yyuser_error; + } + else + YYCHK1(this->yyglrReduce(create_state_set_index(0), -yyaction, true)); + } + } + + while (true) + { + for (state_set_index yys = create_state_set_index(0); + yys.uget() < this->yystateStack.numTops(); ++yys) + this->yystateStack.yytops.setLookaheadNeeds(yys, !this->yyla.empty()); + + /* yyprocessOneStack returns one of three things: + + - An error flag. If the caller is yyprocessOneStack, it + immediately returns as well. When the caller is finally + yyparse, it jumps to an error label via YYCHK1. + + - yyok, but yyprocessOneStack has invoked yymarkStackDeleted + (yys), which sets the top state of yys to NULL. Thus, + yyparse's following invocation of yyremoveDeletes will remove + the stack. + + - yyok, when ready to shift a token. + + Except in the first case, yyparse will invoke yyremoveDeletes and + then shift the next token onto all remaining stacks. This + synchronization of the shift (that is, after all preceding + reductions on all stacks) helps prevent double destructor calls + on yylval in the event of memory exhaustion. */ + + for (state_set_index yys = create_state_set_index(0); + yys.uget() < this->yystateStack.numTops(); ++yys) + YYCHK1 (this->yyprocessOneStack (yys, yyposn]b4_locations_if([, &this->yyla.location])[)); + this->yystateStack.yytops.yyremoveDeletes(); + if (this->yystateStack.yytops.size() == 0) + { + this->yystateStack.yytops.yyundeleteLastStack(); + if (this->yystateStack.yytops.size() == 0) + this->yyFail (]b4_locations_if([&this->yyla.location, ])[YY_("syntax error")); + YYCHK1(this->yyresolveStack()); + YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[ + this->yyerror_range[1].getState ().yyloc = this->yyla.location;]])[ + this->yyreportSyntaxError (); + goto yyuser_error; + } + + /* If any yyglrShift call fails, it will fail after shifting. Thus, + a copy of yylval will already be on stack 0 in the event of a + failure in the following loop. Thus, yyla is emptied + before the loop to make sure the user destructor for yylval isn't + called twice. */ + symbol_kind_type yytoken_to_shift = this->yyla.kind(); + this->yyla.kind_ = ]b4_symbol(empty, kind)[; + yyposn += 1; + for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys) + { + const state_num yystate = this->topState(yys)->yylrState; + const short *yyconflicts; + const int yyaction = yygetLRActions(yystate, yytoken_to_shift, yyconflicts); + /* Note that yyconflicts were handled by yyprocessOneStack. */ + YYCDEBUG << "On stack " << yys.get() << ", "; + YY_SYMBOL_PRINT("shifting", yytoken_to_shift, this->yyla.value, + this->yyla.location); + this->yyglrShift (yys, yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[); + YYCDEBUG << "Stack " << yys.get() << " now in state " + << this->topState(yys)->yylrState << '\n'; + } +]b4_variant_if([[ + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yytoken_to_shift]], [[this->yyla.value]], [[template destroy]])])[ + + if (this->yystateStack.yytops.size () == 1) + { + YYCHK1(this->yyresolveStack()); + YYCDEBUG << "Returning to deterministic operation.\n"; + this->yystateStack.yycompressStack(); + break; + } + } + continue; + yyuser_error: + this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla.location])[); + yyposn = this->firstTopState()->yyposn; + } + + yyacceptlab: + yyresult = 0; + goto yyreturn; + + yybuglab: + YYASSERT (false); + goto yyabortlab; + + yyabortlab: + yyresult = 1; + goto yyreturn; + + yyexhaustedlab: + yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("memory exhausted")); + yyresult = 2; + goto yyreturn; + + yyreturn: + return yyresult; + } +#undef YYCHK1 + + void yyreserveGlrStack () + { + if (!yystateStack.yyexpandGLRStackIfNeeded()) + yyMemoryExhausted(); + } + + _Noreturn void + yyMemoryExhausted () + { + YYLONGJMP(yyexception_buffer, 2); + } + + _Noreturn void + yyFail (]b4_locations_if([location_type* yylocp, ])[const char* yymsg) + { + if (yymsg != YY_NULLPTR) + yyparser.error (]b4_locations_if([*yylocp, ])[yymsg); + YYLONGJMP(yyexception_buffer, 1); + } + + /* GLRStates */ + + + /** Add a new semantic action that will execute the action for rule + * YYRULE on the semantic values in YYRHS to the list of + * alternative actions for YYSTATE. Assumes that YYRHS comes from + * stack #YYK of *this. */ + void + yyaddDeferredAction (state_set_index yyk, glr_state* yystate, + glr_state* yyrhs, rule_num yyrule) + { + semantic_option &yyopt = yystateStack.yynewSemanticOption(semantic_option(yyrule)); + yyopt.setState(yyrhs); + yyopt.setNext(yystate->firstVal()); + if (yystateStack.yytops.lookaheadNeeds(yyk)) + yyopt.yyla = this->yyla; + yystate->setFirstVal(&yyopt); + + yyreserveGlrStack(); + } + +#if] b4_api_PREFIX[DEBUG + void yypdumpstack () const + { + yystateStack.dumpStack(); + } +#endif + + void + yyreportSyntaxError () + { + if (yyerrState != 0) + return; +]b4_parse_error_case( +[simple], [[ + std::string msg = YY_("syntax error"); + yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]], +[custom], [[ + context yyctx (*this, yyla); + yyparser.report_syntax_error (yyctx);]], +[[ + context yyctx (*this, yyla); + std::string msg = yyparser.yysyntax_error_ (yyctx); + yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[ + yyerrcnt += 1; + } + + /* Recover from a syntax error on this, assuming that yytoken, + yylval, and yylloc are the syntactic category, semantic value, and location + of the lookahead. */ + void + yyrecoverSyntaxError (]b4_locations_if([location_type* yylocp])[) + { + if (yyerrState == 3) + /* We just shifted the error token and (perhaps) took some + reductions. Skip tokens until we can proceed. */ + while (true) + { + if (this->yyla.kind () == ]b4_symbol(eof, kind)[) + yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); + if (this->yyla.kind () != ]b4_symbol(empty, kind)[) + {]b4_locations_if([[ + /* We throw away the lookahead, but the error range + of the shifted error token must take it into account. */ + glr_state *yys = firstTopState(); + yyerror_range[1].getState().yyloc = yys->yyloc; + yyerror_range[2].getState().yyloc = this->yyla.location; + YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[ + yyparser.yy_destroy_ ("Error: discarding", + this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);]b4_variant_if([[ + // Value type destructor. + ]b4_symbol_variant([[this->yyla.kind ()]], [[this->yyla.value]], [[template destroy]])])[ + this->yyla.kind_ = ]b4_symbol(empty, kind)[; + } + yyget_token(); + int yyj = yypact[firstTopState()->yylrState]; + if (yypact_value_is_default(yyj)) + return; + yyj += this->yyla.kind(); + if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yyla.kind()) + { + if (yydefact[firstTopState()->yylrState] != 0) + return; + } + else if (!yytable_value_is_error(yytable[yyj])) + return; + } + + if (!yystateStack.reduceToOneStack()) + yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); + + /* Now pop stack until we find a state that shifts the error token. */ + yyerrState = 3; + while (firstTopState() != YY_NULLPTR) + { + glr_state *yys = firstTopState(); + int yyj = yypact[yys->yylrState]; + if (!yypact_value_is_default(yyj)) + { + yyj += YYTERROR; + if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR && + yy_is_shift_action(yytable[yyj])) + { + /* Shift the error token. */]b4_locations_if([[ + /* First adjust its location.*/ + location_type yyerrloc; + yyerror_range[2].getState().yyloc = this->yyla.location; + YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[ + YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]), + this->yyla.value, yyerrloc); + yyglrShift (create_state_set_index(0), yytable[yyj], + yys->yyposn, yyla.value]b4_locations_if([, yyerrloc])[); + yys = firstTopState(); + break; + } + }]b4_locations_if([[ + yyerror_range[1].getState().yyloc = yys->yyloc;]])[ + if (yys->pred() != YY_NULLPTR) + yys->destroy ("Error: popping", yyparser); + yystateStack.setFirstTop(yys->pred()); + yystateStack.pop_back(); + } + if (firstTopState() == YY_NULLPTR) + yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); + } + + YYRESULTTAG + yyprocessOneStack (state_set_index yyk, + size_t yyposn]b4_locations_if([, location_type* yylocp])[) + { + while (yystateStack.topAt(yyk) != YY_NULLPTR) + { + const state_num yystate = topState(yyk)->yylrState; + YYCDEBUG << "Stack " << yyk.get() << " Entering state " << yystate << '\n'; + + YYASSERT(yystate != YYFINAL); + + if (yy_is_defaulted_state(yystate)) + { + const rule_num yyrule = yy_default_action(yystate); + if (yyrule == 0) + { + YYCDEBUG << "Stack " << yyk.get() << " dies.\n"; + yystateStack.yytops.yymarkStackDeleted(yyk); + return yyok; + } + const YYRESULTTAG yyflag = yyglrReduce(yyk, yyrule, yyimmediate[yyrule]); + if (yyflag == yyerr) + { + YYCDEBUG << "Stack " << yyk.get() + << " dies" + " (predicate failure or explicit user error).\n"; + yystateStack.yytops.yymarkStackDeleted(yyk); + return yyok; + } + if (yyflag != yyok) + return yyflag; + } + else + { + yystateStack.yytops.setLookaheadNeeds(yyk, true); + yyget_token(); + const short *yyconflicts; + const int yyaction = yygetLRActions(yystate, this->yyla.kind(), yyconflicts); + + for (; *yyconflicts != 0; ++yyconflicts) + { + state_set_index yynewStack = yystateStack.yysplitStack(yyk); + YYCDEBUG << "Splitting off stack " << yynewStack.get() << " from " + << yyk.get() << ".\n"; + YYRESULTTAG yyflag = + yyglrReduce(yynewStack, *yyconflicts, yyimmediate[*yyconflicts]); + if (yyflag == yyok) + YYCHK (yyprocessOneStack (yynewStack, + yyposn]b4_locations_if([, yylocp])[)); + else if (yyflag == yyerr) + { + YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n"; + yystateStack.yytops.yymarkStackDeleted(yynewStack); + } + else + return yyflag; + } + + if (yy_is_shift_action(yyaction)) + break; + else if (yy_is_error_action(yyaction)) + { + YYCDEBUG << "Stack " << yyk.get() << " dies.\n"; + yystateStack.yytops.yymarkStackDeleted(yyk); + break; + } + else + { + YYRESULTTAG yyflag = yyglrReduce(yyk, -yyaction, yyimmediate[-yyaction]); + if (yyflag == yyerr) + { + YYCDEBUG << "Stack " << yyk.get() + << " dies" + " (predicate failure or explicit user error).\n"; + yystateStack.yytops.yymarkStackDeleted(yyk); + break; + } + else if (yyflag != yyok) + return yyflag; + } + } + } + return yyok; + } + + /** Perform user action for rule number YYN, with RHS length YYRHSLEN, + * and top stack item YYVSP. YYVALP points to place to put semantic + * value ($$), and yylocp points to place for location information + * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, + * yyerr for YYERROR, yyabort for YYABORT. */ + YYRESULTTAG + yyuserAction (rule_num yyrule, int yyrhslen, glr_stack_item* yyvsp, state_set_index yyk, + value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) + { + bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit(); + int yylow = 1; +]b4_parse_param_use([yyvalp], [yylocp])dnl +[ YY_USE (yyk); + YY_USE (yyrhslen); +#undef yyerrok +#define yyerrok (yyerrState = 0) +#undef YYACCEPT +#define YYACCEPT return yyaccept +#undef YYABORT +#define YYABORT return yyabort +#undef YYERROR +#define YYERROR return yyerrok, yyerr +#undef YYRECOVERING +#define YYRECOVERING() (yyerrState != 0) +#undef yytoken +#define yytoken this->yyla.kind_ +#undef yyclearin +#define yyclearin (yytoken = ]b4_symbol(empty, kind)[) +#undef YYBACKUP +#define YYBACKUP(Token, Value) \ + return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \ + yyerrok, yyerr + +]b4_variant_if([[ + /* Variants are always initialized to an empty instance of the + correct type. The default '$$ = $1' action is NOT applied + when using variants. */ + // However we really need to prepare yyvsp now if we want to get + // correct locations, so invoke YYFILL for $1 anyway. + (void) YYFILL (1-yyrhslen); + ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [(*yyvalp)], [emplace])], [[ + if (yyrhslen == 0) + *yyvalp = yyval_default; + else + *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]])[]b4_locations_if([[ + /* Default location. */ + YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); + yyerror_range[1].getState().yyloc = *yylocp; +]])[ + /* If yyk == -1, we are running a deferred action on a temporary + stack. In that case, YY_REDUCE_PRINT must not play with YYFILL, + so pretend the stack is "normal". */ + YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, yyk, yyrule, yyparser)); +#if YY_EXCEPTIONS + try + { +#endif // YY_EXCEPTIONS + switch (yyrule) + { + ]b4_user_actions[ + default: break; + } +#if YY_EXCEPTIONS + } + catch (const syntax_error& yyexc) + { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([ + *yylocp = yyexc.location;])[ + yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ()); + YYERROR; + } +#endif // YY_EXCEPTIONS + YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp); + + return yyok; +#undef yyerrok +#undef YYABORT +#undef YYACCEPT +#undef YYERROR +#undef YYBACKUP +#undef yytoken +#undef yyclearin +#undef YYRECOVERING + } + + YYRESULTTAG + yyresolveStack () + { + if (yystateStack.isSplit()) + { + int yyn = 0; + for (glr_state *yys = firstTopState(); yys != yystateStack.yysplitPoint; + yys = yys->pred()) + yyn += 1; + YYCHK(yyresolveStates(*firstTopState(), yyn)); + } + return yyok; + } + + /** Pop the symbols consumed by reduction #YYRULE from the top of stack + * #YYK of *YYSTACKP, and perform the appropriate semantic action on their + * semantic values. Assumes that all ambiguities in semantic values + * have been previously resolved. Set *YYVALP to the resulting value, + * and *YYLOCP to the computed location (if any). Return value is as + * for userAction. */ + YYRESULTTAG + yydoAction (state_set_index yyk, rule_num yyrule, + value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) + { + const int yynrhs = yyrhsLength(yyrule); + + if (!yystateStack.isSplit()) + { + /* Standard special case: single stack. */ + YYASSERT(yyk.get() == 0); + glr_stack_item *yyrhs = yystateStack.firstTop()->asItem(); + const YYRESULTTAG res + = yyuserAction (yyrule, yynrhs, yyrhs, yyk, yyvalp]b4_locations_if([, yylocp])[); + yystateStack.pop_back(static_cast(yynrhs)); + yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState()); + return res; + } + else + { + glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + glr_state *yys = yystateStack.topAt(yyk); + yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yys);]b4_locations_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yys->yyloc;]])[ + for (int yyi = 0; yyi < yynrhs; yyi += 1) + { + yys = yys->pred(); + YYASSERT(yys != YY_NULLPTR); + } + yystateStack.yyupdateSplit (*yys); + yystateStack.setTopAt(yyk, yys); + return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + yyk, + yyvalp]b4_locations_if([, yylocp])[); + } + } + + /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE, + * and push back on the resulting nonterminal symbol. Perform the + * semantic action associated with YYRULE and store its value with the + * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently + * unambiguous. Otherwise, store the deferred semantic action with + * the new state. If the new state would have an identical input + * position, LR state, and predecessor to an existing state on the stack, + * it is identified with that existing state, eliminating stack #YYK from + * *YYSTACKP. In this case, the semantic value is + * added to the options for the existing state's semantic value. + */ + YYRESULTTAG + yyglrReduce (state_set_index yyk, rule_num yyrule, bool yyforceEval) + { + size_t yyposn = topState(yyk)->yyposn; + + if (yyforceEval || !yystateStack.isSplit()) + { + value_type val;]b4_locations_if([[ + location_type loc;]])[ + + YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &val]b4_locations_if([, &loc])[); + if (yyflag == yyerr && yystateStack.isSplit()) + {]b4_parse_trace_if([[ + YYCDEBUG << "Parse on stack " << yyk.get () + << " rejected by rule " << yyrule - 1 + << " (line " << int (yyrline[yyrule]) << ").\n"; + ]])[} + if (yyflag != yyok) + return yyflag; + yyglrShift (yyk, + yyLRgotoState (topState(yyk)->yylrState, + yylhsNonterm (yyrule)), + yyposn, val]b4_locations_if([, loc])[);]b4_variant_if([[ + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [[val]], [[template destroy]])])[ + } + else + { + glr_state *yys = yystateStack.topAt(yyk); + glr_state *yys0 = yys; + for (int yyn = yyrhsLength(yyrule); 0 < yyn; yyn -= 1) + { + yys = yys->pred(); + YYASSERT(yys != YY_NULLPTR); + } + yystateStack.yyupdateSplit(*yys); + state_num yynewLRState = yyLRgotoState(yys->yylrState, yylhsNonterm(yyrule));]b4_parse_trace_if([[ + YYCDEBUG << "Reduced stack " << yyk.get () + << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule]) + << "); action deferred. Now in state " << yynewLRState + << ".\n";]])[ + for (state_set_index yyi = create_state_set_index(0); yyi.uget() < yystateStack.numTops(); ++yyi) + if (yyi != yyk && yystateStack.topAt(yyi) != YY_NULLPTR) + { + const glr_state *yysplit = yystateStack.yysplitPoint; + glr_state *yyp = yystateStack.topAt(yyi); + while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) + { + if (yyp->yylrState == yynewLRState && yyp->pred() == yys) + { + yyaddDeferredAction(yyk, yyp, yys0, yyrule); + yystateStack.yytops.yymarkStackDeleted(yyk); + YYCDEBUG << "Merging stack " << yyk.get() << " into stack " << yyi.get() + << ".\n"; + return yyok; + } + yyp = yyp->pred(); + } + } + yystateStack.setTopAt(yyk, yys); + yyglrShiftDefer (yyk, yynewLRState, yyposn, yys0, yyrule); + } + return yyok; + } + + /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with the (unresolved) + * semantic value of YYRHS under the action for YYRULE. */ + void + yyglrShiftDefer (state_set_index yyk, state_num yylrState, + size_t yyposn, glr_state* yyrhs, rule_num yyrule) + { + glr_state &yynewState = yystateStack.yynewGLRState(glr_state(yylrState, yyposn)); + yynewState.setPred(yystateStack.topAt(yyk)); + yystateStack.setTopAt(yyk, &yynewState); + + /* Invokes yyreserveStack. */ + yyaddDeferredAction(yyk, &yynewState, yyrhs, yyrule); + } + + /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic + * value YYVAL_ARG and source location YYLOC_ARG. */ + void + yyglrShift (state_set_index yyk, state_num yylrState, + size_t yyposn, + const value_type& yyval_arg]b4_locations_if([, const location_type& yyloc_arg])[) + { + glr_state& yynewState = yystateStack.yynewGLRState ( + glr_state (yylrState, yyposn, yyval_arg]b4_locations_if([, yyloc_arg])[)); + yynewState.setPred(yystateStack.topAt(yyk)); + yystateStack.setTopAt(yyk, &yynewState); + yyreserveGlrStack(); + } + +#if] b4_api_PREFIX[DEBUG + void + yypstack (state_set_index yyk) const + { + yystateStack.yypstates(yystateStack.topAt(yyk)); + } +#endif + + glr_state* topState(state_set_index i) { + return yystateStack.topAt(i); + } + + glr_state* firstTopState() { + return yystateStack.firstTop(); + } + + private: + + void popall_ () + { + /* If the stack is well-formed, pop the stack until it is empty, + destroying its entries as we go. But free the stack regardless + of whether it is well-formed. */ + for (state_set_index k = create_state_set_index(0); k.uget() < yystateStack.numTops(); + k += 1) + if (yystateStack.topAt(k) != YY_NULLPTR) + { + while (yystateStack.topAt(k) != YY_NULLPTR) + { + glr_state *state = topState(k);]b4_locations_if([[ + yyerror_range[1].getState().yyloc = state->yyloc;]])[ + if (state->pred() != YY_NULLPTR) + state->destroy ("Cleanup: popping", yyparser); + yystateStack.setTopAt(k, state->pred()); + yystateStack.pop_back(); + } + break; + } + } + + /** Resolve the previous YYN states starting at and including state YYS + * on *YYSTACKP. If result != yyok, some states may have been left + * unresolved possibly with empty semantic option chains. Regardless + * of whether result = yyok, each state has been left with consistent + * data so that destroy can be invoked if necessary. */ + YYRESULTTAG + yyresolveStates (glr_state& yys, int yyn) + { + if (0 < yyn) + { + YYASSERT(yys.pred() != YY_NULLPTR); + YYCHK(yyresolveStates(*yys.pred(), yyn - 1)); + if (!yys.yyresolved) + YYCHK(yyresolveValue(yys)); + } + return yyok; + } + + static void + yyuserMerge (int yyn, value_type& yy0, value_type& yy1) + { + YY_USE(yy0); + YY_USE(yy1); + + switch (yyn) + { +]b4_mergers[ + default: break; + } + } + + /** Resolve the ambiguity represented in state YYS in *YYSTACKP, + * perform the indicated actions, and set the semantic value of YYS. + * If result != yyok, the chain of semantic options in YYS has been + * cleared instead or it has been left unmodified except that + * redundant options may have been removed. Regardless of whether + * result = yyok, YYS has been left with consistent data so that + * destroy can be invoked if necessary. */ + YYRESULTTAG + yyresolveValue (glr_state& yys) + { + semantic_option *yybest = yys.firstVal(); + YYASSERT(yybest != YY_NULLPTR); + bool yymerge = false; + YYRESULTTAG yyflag;]b4_locations_if([ + location_type *yylocp = &yys.yyloc;])[ + + semantic_option* yypPrev = yybest; + for (semantic_option* yyp = yybest->next(); + yyp != YY_NULLPTR; ) + { + if (yybest->isIdenticalTo(*yyp)) + { + yybest->mergeWith(*yyp); + yypPrev->setNext(yyp->next()); + yyp = yypPrev->next(); + } + else + { + switch (yypreference(*yybest, *yyp)) + { + case 0:]b4_locations_if([[ + yyresolveLocations (yys, 1);]])[ + return yystateStack.yyreportAmbiguity (*yybest, *yyp, yyparser]b4_locations_if([, *yylocp])[); + break; + case 1: + yymerge = true; + break; + case 2: + break; + case 3: + yybest = yyp; + yymerge = false; + break; + default: + /* This cannot happen so it is not worth a YYASSERT (false), + but some compilers complain if the default case is + omitted. */ + break; + } + yypPrev = yyp; + yyp = yyp->next(); + } + } + + value_type val; + if (yymerge) + { + int yyprec = yydprec[yybest->yyrule]; + yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[); + if (yyflag == yyok) + for (semantic_option *yyp = yybest->next(); yyp != YY_NULLPTR; yyp = yyp->next()) + { + if (yyprec == yydprec[yyp->yyrule]) + { + value_type yyval_other;]b4_locations_if([ + location_type yydummy;])[ + yyflag = yyresolveAction (*yyp, &yyval_other]b4_locations_if([, &yydummy])[); + if (yyflag != yyok) + { + yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for", + yy_accessing_symbol (yys.yylrState), + this->yyla.value]b4_locations_if([, *yylocp])[); + break; + } + yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[ + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[yyval_other]], [[template destroy]])])[ + } + } + } + else + yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[); + + if (yyflag == yyok) + { + yys.yyresolved = true; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN]b4_variant_if([[ + new (&yys.value ()) value_type (); + ]b4_symbol_variant([yy_accessing_symbol (yys.yylrState)], + [yys.value ()], [copy], [val])], [[ + new (&yys.value ()) value_type (val);]])[ + + YY_IGNORE_MAYBE_UNINITIALIZED_END + } + else + yys.setFirstVal(YY_NULLPTR); +]b4_variant_if([[ + // FIXME: User destructors. + // Value type destructor. + ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[val]], [[template destroy]])])[ + return yyflag; + } + + /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its + * user action, and return the semantic value and location in *YYVALP + * and *YYLOCP. Regardless of whether result = yyok, all RHS states + * have been destroyed (assuming the user action destroys all RHS + * semantic values if invoked). */ + YYRESULTTAG + yyresolveAction (semantic_option& yyopt, value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) + { + glr_state *yyoptState = yyopt.state(); + YYASSERT(yyoptState != YY_NULLPTR); + int yynrhs = yyrhsLength(yyopt.yyrule); + YYRESULTTAG yyflag = yyresolveStates(*yyoptState, yynrhs); + if (yyflag != yyok) + { + for (glr_state *yys = yyoptState; yynrhs > 0; yys = yys->pred(), yynrhs -= 1) + yys->destroy("Cleanup: popping", yyparser); + return yyflag; + } + + glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yyopt.state());]b4_locations_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[ + { + symbol_type yyla_current = std::move(this->yyla); + this->yyla = std::move(yyopt.yyla); + yyflag = yyuserAction (yyopt.yyrule, yynrhs, + yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + create_state_set_index (-1), + yyvalp]b4_locations_if([, yylocp])[); + this->yyla = std::move(yyla_current); + } + return yyflag; + }]b4_locations_if([[ + + /** Resolve the locations for each of the YYN1 states in *YYSTACKP, + * ending at YYS1. Has no effect on previously resolved states. + * The first semantic option of a state is always chosen. */ + void + yyresolveLocations (glr_state &yys1, int yyn1) + { + if (0 < yyn1) + { + yyresolveLocations(*yys1.pred(), yyn1 - 1); + if (!yys1.yyresolved) + { + glr_stack_item yyrhsloc[1 + YYMAXRHS]; + YYASSERT(yys1.firstVal() != YY_NULLPTR); + semantic_option &yyoption = *yys1.firstVal(); + const int yynrhs = yyrhsLength(yyoption.yyrule); + if (0 < yynrhs) + { + yyresolveLocations(*yyoption.state(), yynrhs); + const glr_state *yys = yyoption.state(); + for (int yyn = yynrhs; yyn > 0; yyn -= 1) + { + yyrhsloc[yyn].getState().yyloc = yys->yyloc; + yys = yys->pred(); + } + } + else + { + /* Both yyresolveAction and yyresolveLocations traverse the GSS + in reverse rightmost order. It is only necessary to invoke + yyresolveLocations on a subforest for which yyresolveAction + would have been invoked next had an ambiguity not been + detected. Thus the location of the previous state (but not + necessarily the previous state itself) is guaranteed to be + resolved already. */ + YY_IGNORE_NULL_DEREFERENCE_BEGIN + yyrhsloc[0].getState().yyloc = yyoption.state()->yyloc; + YY_IGNORE_NULL_DEREFERENCE_END + } + YYLLOC_DEFAULT((yys1.yyloc), yyrhsloc, yynrhs); + } + } + }]])[ + + /** If yytoken is empty, fetch the next token. */ + void + yyget_token () + { +]b4_parse_param_use()dnl +[ if (this->yyla.empty ()) + { + YYCDEBUG << "Reading a token\n"; +#if YY_EXCEPTIONS + try +#endif // YY_EXCEPTIONS + {]b4_token_ctor_if([[ + symbol_type yylookahead (]b4_yylex[); + yyla.move (yylookahead);]], [[ + yyla.kind_ = yyparser.yytranslate_ (]b4_yylex[);]])[ + } +#if YY_EXCEPTIONS + catch (const parser_type::syntax_error &yyexc) + { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([ + this->yyla.location = yyexc.location;])[ + yyparser.error (]b4_locations_if([this->yyla.location, ])[yyexc.what ()); + // Map errors caught in the scanner to the error token, so that error + // handling is started. + this->yyla.kind_ = ]b4_symbol(error, kind)[; + } + } +#endif // YY_EXCEPTIONS + if (this->yyla.kind () == ]b4_symbol(eof, kind)[) + YYCDEBUG << "Now at end of input.\n"; + else + YY_SYMBOL_PRINT ("Next token is", this->yyla.kind (), this->yyla.value, this->yyla.location); + } + + + /* Bison grammar-table manipulation. */ + + /** The action to take in YYSTATE on seeing YYTOKEN. + * Result R means + * R < 0: Reduce on rule -R. + * R = 0: Error. + * R > 0: Shift to state R. + * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list + * of conflicting reductions. + */ + static int + yygetLRActions (state_num yystate, symbol_kind_type yytoken, const short*& yyconflicts) + { + int yyindex = yypact[yystate] + yytoken; + if (yytoken == ]b4_symbol(error, kind)[) + { + // This is the error token. + yyconflicts = yyconfl; + return 0; + } + else if (yy_is_defaulted_state(yystate) || yyindex < 0 || YYLAST < yyindex || + yycheck[yyindex] != yytoken) + { + yyconflicts = yyconfl; + return -yydefact[yystate]; + } + else if (!yytable_value_is_error(yytable[yyindex])) + { + yyconflicts = yyconfl + yyconflp[yyindex]; + return yytable[yyindex]; + } + else + { + yyconflicts = yyconfl + yyconflp[yyindex]; + return 0; + } + } + + /** Compute post-reduction state. + * \param yystate the current state + * \param yysym the nonterminal to push on the stack + */ + static state_num + yyLRgotoState (state_num yystate, symbol_kind_type yysym) + { + const int yyr = yypgoto[yysym - YYNTOKENS] + yystate; + if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) + return yytable[yyr]; + else + return yydefgoto[yysym - YYNTOKENS]; + } + + static bool + yypact_value_is_default (state_num yystate) + { + return ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf], [YYPACT_NINF])[; + } + + static bool + yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED) + { + return ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[; + } + + static bool + yy_is_shift_action (int yyaction) YY_NOEXCEPT + { + return 0 < yyaction; + } + + static bool + yy_is_error_action (int yyaction) YY_NOEXCEPT + { + return yyaction == 0; + } + + /** Whether LR state YYSTATE has only a default reduction + * (regardless of token). */ + static bool + yy_is_defaulted_state (state_num yystate) + { + return yypact_value_is_default(yypact[yystate]); + } + + /** The default reduction for YYSTATE, assuming it has one. */ + static rule_num + yy_default_action (state_num yystate) + { + return yydefact[yystate]; + } + + /* GLRStacks */ + + /** Y0 and Y1 represent two possible actions to take in a given + * parsing state; return 0 if no combination is possible, + * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ + static int + yypreference (const semantic_option& y0, const semantic_option& y1) + { + const rule_num r0 = y0.yyrule, r1 = y1.yyrule; + const int p0 = yydprec[r0], p1 = yydprec[r1]; + + if (p0 == p1) + { + if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) + return 0; + else + return 1; + } + else if (p0 == 0 || p1 == 0) + return 0; + else if (p0 < p1) + return 3; + else if (p1 < p0) + return 2; + else + return 0; + } + +]b4_parse_param_vars[ + }; // class ]b4_parser_class[::glr_stack +} // namespace ]b4_namespace_ref[ + +#if] b4_api_PREFIX[DEBUG +namespace +{ + void + yypstack (const glr_stack& yystack, size_t yyk) + { + yystack.yypstack (create_state_set_index (static_cast (yyk))); +} + +void yypdumpstack(const glr_stack &yystack) +{ + yystack.yypdumpstack(); +} +} +#endif + +]b4_namespace_open[ + /// Build a parser object. + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ + :])[ +#if] b4_api_PREFIX[DEBUG + ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ +#endif] b4_parse_param_cons[ + {} + + ]b4_parser_class::~b4_parser_class[ () + {} + + ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW + {} + + int + ]b4_parser_class[::operator() () + { + return parse(); + } + + int + ]b4_parser_class[::parse () + { + glr_stack yystack(YYINITDEPTH, *this]b4_user_args[); + return yystack.parse(); + } + +]b4_parse_error_bmatch([custom\|detailed], +[[ const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ + } +]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytname_[yysymbol]; + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + ]b4_parser_class[::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes:; + } + + return yystr; + } + + std::string + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytnamerr_(yytname_[yysymbol]); + } +]])[ + +]b4_parse_error_bmatch([simple\|verbose], +[[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[ + // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + // First, the terminals, then, starting at \a YYNTOKENS, nonterminals. + const char* + const ]b4_parser_class[::yytname_[] = + { + ]b4_tname[ + }; +#endif +]])[ + +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + // ]b4_parser_class[::context. + ]b4_parser_class[::context::context (glr_stack& yystack, const symbol_type& yyla) + : yystack_ (yystack) + , yyla_ (yyla) + {} + + int + ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const + { + // Actual number of expected tokens + int yycount = 0; + const int yyn = yypact[yystack_.firstTopState()->yylrState]; + if (!yystack_.yypact_value_is_default(yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for this + state because they are default actions. */ + const int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + const int yychecklim = YYLAST - yyn + 1; + const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yystack_.yytable_value_is_error (yytable[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST(symbol_kind_type, yyx); + } + } + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(empty, kind)[; + return yycount; + } + +]])[ + +]b4_parse_error_bmatch([detailed\|verbose], [[ + int + ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const + { + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yyla) is + if this state is a consistent state with a default action. + Thus, detecting the absence of a lookahead is sufficient to + determine that there is no unexpected or expected token to + report. In that case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is + a consistent state with a default action. There might have + been a previous inconsistent state, consistent state with a + non-default action, or user semantic action that manipulated + yyla. (However, yyla is currently not documented for users.) + */ + + if (!yyctx.lookahead().empty()) + { + if (yyarg) + yyarg[0] = yyctx.token(); + int yyn = yyctx.expected_tokens(yyarg ? yyarg + 1 : yyarg, yyargn - 1); + return yyn + 1; + } + return 0; + } + + // Generate an error message. + std::string + ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const + { + // Its maximum. + enum + { + YYARGS_MAX = 5 + }; + // Arguments of yyformat. + symbol_kind_type yyarg[YYARGS_MAX]; + int yycount = yy_syntax_error_arguments_(yyctx, yyarg, YYARGS_MAX); + + char const *yyformat = YY_NULLPTR; + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: // Avoid compiler warnings. + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } + + std::string yyres; + // Argument number. + std::ptrdiff_t yyi = 0; + for (char const *yyp = yyformat; *yyp; ++yyp) + if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) + { + yyres += symbol_name(yyarg[yyi++]); + ++yyp; + } + else + yyres += *yyp; + return yyres; + }]])[ + + void + ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind, + value_type& yyval]b4_locations_if([[, + location_type& yyloc]])[) + { + YY_USE(yyval);]b4_locations_if([[ + YY_USE (yyloc);]])[ + if (!yymsg) + yymsg = "Deleting"; + ]b4_parser_class[& yyparser = *this; + YY_USE (yyparser); + YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))], + [b4_symbol_actions([destructor])], + [m4_popdef([b4_symbol_action])])[ + YY_IGNORE_MAYBE_UNINITIALIZED_END + } + +#if] b4_api_PREFIX[DEBUG + /*--------------------. + | Print this symbol. | + `--------------------*/ + + void + ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind, + const value_type& yyval]b4_locations_if([[, + const location_type& yyloc]])[) const + {]b4_locations_if([[ + YY_USE (yyloc);]])[ + YY_USE (yyval); + std::ostream& yyo = debug_stream (); + YY_USE (yyo); + ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))], + [b4_symbol_actions([printer])], + [m4_popdef([b4_symbol_action])])[ + } + + void + ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind, + const value_type& yyval]b4_locations_if([[, + const location_type& yyloc]])[) const + { + *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[ + << yyloc << ": "]])[; + yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[); + *yycdebug_ << ')'; + } + + std::ostream& + ]b4_parser_class[::debug_stream () const + { + return *yycdebug_; + } + + void + ]b4_parser_class[::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + ]b4_parser_class[::debug_level_type + ]b4_parser_class[::debug_level () const + { + return yydebug; + } + + void + ]b4_parser_class[::set_debug_level (debug_level_type l) + { + // Actually, it is yydebug which is really used. + yydebug = l; + } +#endif // ]b4_api_PREFIX[DEBUG + +]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[ + +]b4_token_ctor_if([], [[ + /*---------. + | symbol. | + `---------*/ +]b4_public_types_define([cc])])[ +]b4_namespace_close[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/tools/flex-bison/third_party/skeletons/java-skel.m4 b/tools/flex-bison/third_party/skeletons/java-skel.m4 new file mode 100644 index 000000000..11cbc4999 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/java-skel.m4 @@ -0,0 +1,27 @@ + -*- Autoconf -*- + +# Java skeleton dispatching for Bison. + +# Copyright (C) 2007, 2009-2015, 2018-2021 Free Software Foundation, +# Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [b4_complain([%%glr-parser not supported for Java])]) +b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.java]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/tools/flex-bison/third_party/skeletons/java.m4 b/tools/flex-bison/third_party/skeletons/java.m4 new file mode 100644 index 000000000..8b0828b0b --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/java.m4 @@ -0,0 +1,502 @@ + -*- Autoconf -*- + +# Java language support for Bison + +# Copyright (C) 2007-2015, 2018-2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[c-like.m4]) + + +# b4_list2(LIST1, LIST2) +# ---------------------- +# Join two lists with a comma if necessary. +m4_define([b4_list2], + [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2]) + + +# b4_percent_define_get3(DEF, PRE, POST, NOT) +# ------------------------------------------- +# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed, +# otherwise NOT. +m4_define([b4_percent_define_get3], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [$2[]b4_percent_define_get([$1])[]$3], [$4])]) + + + +# b4_flag_value(BOOLEAN-FLAG) +# --------------------------- +m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])]) + + +# b4_parser_class_declaration +# --------------------------- +# The declaration of the parser class ("class YYParser"), with all its +# qualifiers/annotations. +b4_percent_define_default([[api.parser.abstract]], [[false]]) +b4_percent_define_default([[api.parser.final]], [[false]]) +b4_percent_define_default([[api.parser.public]], [[false]]) +b4_percent_define_default([[api.parser.strictfp]], [[false]]) + +m4_define([b4_parser_class_declaration], +[b4_percent_define_get3([api.parser.annotations], [], [ ])dnl +b4_percent_define_flag_if([api.parser.public], [public ])dnl +b4_percent_define_flag_if([api.parser.abstract], [abstract ])dnl +b4_percent_define_flag_if([api.parser.final], [final ])dnl +b4_percent_define_flag_if([api.parser.strictfp], [strictfp ])dnl +[class ]b4_parser_class[]dnl +b4_percent_define_get3([api.parser.extends], [ extends ])dnl +b4_percent_define_get3([api.parser.implements], [ implements ])]) + + +# b4_lexer_if(TRUE, FALSE) +# ------------------------ +m4_define([b4_lexer_if], +[b4_percent_code_ifdef([[lexer]], [$1], [$2])]) + + +# b4_identification +# ----------------- +m4_define([b4_identification], +[[ /** Version number for the Bison executable that generated this parser. */ + public static final String bisonVersion = "]b4_version_string["; + + /** Name of the skeleton that generated this parser. */ + public static final String bisonSkeleton = ]b4_skeleton[; +]]) + + +## ------------ ## +## Data types. ## +## ------------ ## + +# b4_int_type(MIN, MAX) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# MIN to MAX (included). +m4_define([b4_int_type], +[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte], + b4_ints_in($@, [-32768], [32767]), [1], [short], + [int])]) + +# b4_int_type_for(NAME) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# 'NAME_min' to 'NAME_max' (included). +m4_define([b4_int_type_for], +[b4_int_type($1_min, $1_max)]) + +# b4_null +# ------- +m4_define([b4_null], [null]) + + +# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT) +# ------------------------------------------------------- +# We use intermediate functions (e.g., yypact_init) to work around the +# 64KB limit for JVM methods. See +# https://lists.gnu.org/r/help-bison/2008-11/msg00004.html. +m4_define([b4_typed_parser_table_define], +[m4_ifval([$4], [b4_comment([$4]) + ])dnl +[private static final ]$1[[] yy$2_ = yy$2_init(); + private static final ]$1[[] yy$2_init() + { + return new ]$1[[] + { + ]$3[ + }; + }]]) + + +# b4_integral_parser_table_define(NAME, DATA, COMMENT) +#----------------------------------------------------- +m4_define([b4_integral_parser_table_define], +[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])]) + + +## ------------- ## +## Token kinds. ## +## ------------- ## + + +# b4_token_enum(TOKEN-NUM) +# ------------------------ +# Output the definition of this token as an enum. +m4_define([b4_token_enum], +[b4_token_visible_if([$1], + [m4_format([[ /** Token %s, to be returned by the scanner. */ + static final int %s = %s%s; +]], + b4_symbol([$1], [tag]), + b4_symbol([$1], [id]), + b4_symbol([$1], b4_api_token_raw_if([[number]], [[code]])))])]) + + +# b4_token_enums +# -------------- +# Output the definition of the tokens (if there are) as enums. +m4_define([b4_token_enums], +[b4_any_token_visible_if([ /* Token kinds. */ +b4_symbol_foreach([b4_token_enum])])]) + + + +## -------------- ## +## Symbol kinds. ## +## -------------- ## + + +# b4_symbol_kind(NUM) +# ------------------- +m4_define([b4_symbol_kind], +[SymbolKind.b4_symbol_kind_base($@)]) + + +# b4_symbol_enum(SYMBOL-NUM) +# -------------------------- +# Output the definition of this symbol as an enum. +m4_define([b4_symbol_enum], +[m4_format([ %-30s %s], + m4_format([[%s(%s)%s]], + b4_symbol([$1], [kind_base]), + [$1], + m4_if([$1], b4_last_symbol, [[;]], [[,]])), + [b4_symbol_tag_comment([$1])])]) + + +# b4_declare_symbol_enum +# ---------------------- +# The definition of the symbol internal numbers as an enum. +m4_define([b4_declare_symbol_enum], +[[ public enum SymbolKind + { +]b4_symbol_foreach([b4_symbol_enum])[ + + private final int yycode_; + + SymbolKind (int n) { + this.yycode_ = n; + } + + private static final SymbolKind[] values_ = { + ]m4_map_args_sep([b4_symbol_kind(], [)], [, + ], b4_symbol_numbers)[ + }; + + static final SymbolKind get(int code) { + return values_[code]; + } + + public final int getCode() { + return this.yycode_; + } + +]b4_parse_error_bmatch( +[simple\|verbose], +[[ /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + private static String yytnamerr_(String yystr) + { + if (yystr.charAt (0) == '"') + { + StringBuffer yyr = new StringBuffer(); + strip_quotes: for (int i = 1; i < yystr.length(); i++) + switch (yystr.charAt(i)) + { + case '\'': + case ',': + break strip_quotes; + + case '\\': + if (yystr.charAt(++i) != '\\') + break strip_quotes; + /* Fall through. */ + default: + yyr.append(yystr.charAt(i)); + break; + + case '"': + return yyr.toString(); + } + } + return yystr; + } + + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */ + ]b4_typed_parser_table_define([String], [tname], [b4_tname])[ + + /* The user-facing name of this symbol. */ + public final String getName() { + return yytnamerr_(yytname_[yycode_]); + } +]], +[custom\|detailed], +[[ /* YYNAMES_[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */ + ]b4_typed_parser_table_define([String], [names], [b4_symbol_names])[ + + /* The user-facing name of this symbol. */ + public final String getName() { + return yynames_[yycode_]; + }]])[ + }; +]])]) + + + +# b4_case(ID, CODE, [COMMENTS]) +# ----------------------------- +# We need to fool Java's stupid unreachable code detection. +m4_define([b4_case], +[ case $1:m4_ifval([$3], [ b4_comment([$3])]) + if (yyn == $1) + $2; + break; +]) + + +# b4_predicate_case(LABEL, CONDITIONS) +# ------------------------------------ +m4_define([b4_predicate_case], +[ case $1: + if (! ($2)) YYERROR; + break; +]) + + +## -------- ## +## Checks. ## +## -------- ## + +b4_percent_define_check_kind([[api.value.type]], [code], [deprecated]) + +b4_percent_define_check_kind([[annotations]], [code], [deprecated]) +b4_percent_define_check_kind([[extends]], [code], [deprecated]) +b4_percent_define_check_kind([[implements]], [code], [deprecated]) +b4_percent_define_check_kind([[init_throws]], [code], [deprecated]) +b4_percent_define_check_kind([[lex_throws]], [code], [deprecated]) +b4_percent_define_check_kind([[api.parser.class]], [code], [deprecated]) +b4_percent_define_check_kind([[throws]], [code], [deprecated]) + + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])]) +b4_percent_define_default([[api.value.type]], [[Object]]) +b4_percent_define_default([[api.symbol.prefix]], [[S_]]) + +# b4_api_prefix, b4_api_PREFIX +# ---------------------------- +# Corresponds to %define api.prefix +b4_percent_define_default([[api.prefix]], [[YY]]) +m4_define([b4_api_prefix], +[b4_percent_define_get([[api.prefix]])]) +m4_define([b4_api_PREFIX], +[m4_toupper(b4_api_prefix)]) + +# b4_prefix +# --------- +# If the %name-prefix is not given, it is api.prefix. +m4_define_default([b4_prefix], [b4_api_prefix]) + +b4_percent_define_default([[api.parser.class]], [b4_prefix[]Parser]) +m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])]) + +b4_percent_define_default([[lex_throws]], [[java.io.IOException]]) +m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])]) + +b4_percent_define_default([[throws]], []) +m4_define([b4_throws], [b4_percent_define_get([[throws]])]) + +b4_percent_define_default([[init_throws]], []) +m4_define([b4_init_throws], [b4_percent_define_get([[init_throws]])]) + +b4_percent_define_default([[api.location.type]], [Location]) +m4_define([b4_location_type], [b4_percent_define_get([[api.location.type]])]) + +b4_percent_define_default([[api.position.type]], [Position]) +m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])]) + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_symbol_translate(STRING) +# --------------------------- +# Used by "bison" in the array of symbol names to mark those that +# require translation. +m4_define([b4_symbol_translate], +[[i18n($1)]]) + + +# b4_trans(STRING) +# ---------------- +# Translate a string if i18n is enabled. Avoid collision with b4_translate. +m4_define([b4_trans], +[b4_has_translations_if([i18n($1)], [$1])]) + + + +# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +# ---------------------------------------------- +# See README. +m4_define([b4_symbol_value], +[m4_ifval([$3], + [(($3)($1))], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [((b4_symbol([$2], [type]))($1))], + [$1])], + [$1])])]) + + +# b4_lhs_value([SYMBOL-NUM], [TYPE]) +# ---------------------------------- +# See README. +m4_define([b4_lhs_value], [yyval]) + + +# b4_rhs_data(RULE-LENGTH, POS) +# ----------------------------- +# See README. +m4_define([b4_rhs_data], +[yystack.valueAt (b4_subtract($@))]) + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# See README. +# +# In this simple implementation, %token and %type have class names +# between the angle brackets. +m4_define([b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2])], [$3], [$4])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(yyloc)]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[yystack.locationAt (b4_subtract($@))]) + + +# b4_lex_param +# b4_parse_param +# -------------- +# If defined, b4_lex_param arrives double quoted, but below we prefer +# it to be single quoted. Same for b4_parse_param. + +# TODO: should be in bison.m4 +m4_define_default([b4_lex_param], [[]]) +m4_define([b4_lex_param], b4_lex_param) +m4_define([b4_parse_param], b4_parse_param) + +# b4_lex_param_decl +# ----------------- +# Extra formal arguments of the constructor. +m4_define([b4_lex_param_decl], +[m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_decls(b4_lex_param))], + [$1])]) + +m4_define([b4_param_decls], + [m4_map([b4_param_decl], [$@])]) +m4_define([b4_param_decl], [, $1]) + +m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)]) + + + +# b4_parse_param_decl +# ------------------- +# Extra formal arguments of the constructor. +m4_define([b4_parse_param_decl], +[m4_ifset([b4_parse_param], + [b4_remove_comma([$1], + b4_param_decls(b4_parse_param))], + [$1])]) + + + +# b4_lex_param_call +# ----------------- +# Delegating the lexer parameters to the lexer constructor. +m4_define([b4_lex_param_call], + [m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_calls(b4_lex_param))], + [$1])]) +m4_define([b4_param_calls], + [m4_map([b4_param_call], [$@])]) +m4_define([b4_param_call], [, $2]) + + + +# b4_parse_param_cons +# ------------------- +# Extra initialisations of the constructor. +m4_define([b4_parse_param_cons], + [m4_ifset([b4_parse_param], + [b4_constructor_calls(b4_parse_param)])]) + +m4_define([b4_constructor_calls], + [m4_map([b4_constructor_call], [$@])]) +m4_define([b4_constructor_call], + [this.$2 = $2; + ]) + + + +# b4_parse_param_vars +# ------------------- +# Extra instance variables. +m4_define([b4_parse_param_vars], + [m4_ifset([b4_parse_param], + [ + /* User arguments. */ +b4_var_decls(b4_parse_param)])]) + +m4_define([b4_var_decls], + [m4_map_sep([b4_var_decl], [ +], [$@])]) +m4_define([b4_var_decl], + [ protected final $1;]) + + + +# b4_maybe_throws(THROWS) +# ----------------------- +# Expand to either an empty string or "throws THROWS". +m4_define([b4_maybe_throws], + [m4_ifval($1, [ throws $1])]) diff --git a/tools/flex-bison/third_party/skeletons/lalr1.cc b/tools/flex-bison/third_party/skeletons/lalr1.cc new file mode 100644 index 000000000..85eaf4845 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/lalr1.cc @@ -0,0 +1,1630 @@ +#C++ skeleton for Bison + +#Copyright(C) 2002 - 2015, 2018 - 2021 Free Software Foundation, Inc. + +#This program is free software : you can redistribute it and / or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program.If not, see < https: // www.gnu.org/licenses/>. + +m4_include(b4_skeletonsdir/[c++.m4]) + +#api.value.type = variant is valid. +m4_define([b4_value_type_setup_variant]) + +#parse.lac +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + +#b4_tname_if(TNAME - NEEDED, TNAME - NOT - NEEDED) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +m4_define([b4_tname_if], +[m4_case(b4_percent_define_get([[parse.error]]), + [verbose], [$1], + [b4_token_table_if([$1], + [$2])])]) + +#b4_integral_parser_table_declare(TABLE - NAME, CONTENT, COMMENT) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#Declare "parser::yy_" whose contents is CONTENT. +m4_define([b4_integral_parser_table_declare], +[m4_ifval([$3], [b4_comment([$3], [ ]) +])dnl + static const b4_int_type_for([$2]) yy$1_[[]];dnl +]) + +#b4_integral_parser_table_define(TABLE - NAME, CONTENT, COMMENT) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#Define "parser::yy_" whose contents is CONTENT. +m4_define([b4_integral_parser_table_define], +[ const b4_int_type_for([$2]) + b4_parser_class::yy$1_[[]] = + { + $2 + };dnl +]) + +#b4_symbol_kind(NUM) +#-- -- -- -- -- -- -- -- -- - +m4_define([b4_symbol_kind], +[symbol_kind::b4_symbol_kind_base($@)]) + +#b4_symbol_value_template(VAL, SYMBOL - NUM, [TYPE]) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#Same as b4_symbol_value, but used in a template method.It makes +#a difference when using variants.Note that b4_value_type_setup_union +#overrides b4_symbol_value, so we must override it again. +m4_copy([b4_symbol_value], [b4_symbol_value_template]) +m4_append([b4_value_type_setup_union], +[m4_copy_force([b4_symbol_value_union], [b4_symbol_value_template])]) + +#b4_lhs_value(SYMBOL - NUM, [TYPE]) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#See README. +m4_define([b4_lhs_value], +[b4_symbol_value([yylhs.value], [$1], [$2])]) + +#b4_lhs_location() +#-- -- -- -- -- -- -- -- - +#Expansion of @$. +m4_define([b4_lhs_location], +[yylhs.location]) + +#b4_rhs_data(RULE - LENGTH, POS) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#See README. +m4_define([b4_rhs_data], +[yystack_@{b4_subtract($@)@}]) + +#b4_rhs_state(RULE - LENGTH, POS) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#The state corresponding to the symbol #POS, where the current +#rule has RULE - LENGTH symbols on RHS. +m4_define([b4_rhs_state], +[b4_rhs_data([$1], [$2]).state]) + +#b4_rhs_value(RULE - LENGTH, POS, SYMBOL - NUM, [TYPE]) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#See README. +m4_define([_b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3], [$4])]) + +m4_define([b4_rhs_value], +[b4_percent_define_ifdef([api.value.automove], + [YY_MOVE (_b4_rhs_value($@))], + [_b4_rhs_value($@)])]) + +#b4_rhs_location(RULE - LENGTH, POS) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#Expansion of @POS, where the current rule has RULE - LENGTH symbols +#on RHS. +m4_define([b4_rhs_location], +[b4_rhs_data([$1], [$2]).location]) + +#b4_symbol_action(SYMBOL - NUM, KIND) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +#Run the action KIND(destructor or printer) for SYMBOL - NUM. +#Same as in C, but using references instead of pointers. +m4_define([b4_symbol_action], +[b4_symbol_if([$1], [has_$2], +[m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl +b4_dollar_pushdef([yysym.value], + [$1], + [], + [yysym.location])dnl + _b4_symbol_case([$1])[]dnl +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl + b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl + break; + +m4_popdef([b4_symbol_value])[]dnl +b4_dollar_popdef[]dnl +])]) + +#b4_yylex +#-- -- -- -- +#Call yylex. +m4_define([b4_yylex], +[b4_token_ctor_if( +[b4_function_call([yylex], + [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))], +[b4_function_call([yylex], [int], + [[value_type *], [&yyla.value]][]dnl +b4_locations_if([, [[location_type *], [&yyla.location]]])dnl +m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) + + +m4_pushdef([b4_copyright_years], + [2002-2015, 2018-2021]) + +m4_define([b4_parser_class], + [b4_percent_define_get([[api.parser.class]])]) + +b4_bison_locations_if([# Backward compatibility. + m4_define([b4_location_constructors]) + m4_include(b4_skeletonsdir/[location.cc])]) +m4_include(b4_skeletonsdir/[stack.hh]) +b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])]) + +#b4_shared_declarations(hh | cc) +#-- -- -- -- -- -- -- -- -- -- -- -- -- -- - +#Declaration that might either go into the header(if --header, $1 = hh) +# or in the implementation file. +m4_define([b4_shared_declarations], +[b4_percent_code_get([[requires]])[ +]b4_parse_assert_if([# include ])[ +#include // std::abort +#include +#include +#include +#include + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ +]b4_variant_if([b4_variant_includes])[ + +]b4_attribute_define[ +]b4_cast_define[ +]b4_null_define[ + +]b4_YYDEBUG_define[ + +]b4_namespace_open[ + +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ + + /// A Bison parser. + class ]b4_parser_class[ + { + public: +]b4_public_types_declare[ +]b4_symbol_type_define[ + /// Build a parser object. + ]b4_parser_class[ (]b4_parse_param_decl[); + virtual ~]b4_parser_class[ (); + +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + ]b4_parser_class[ (const ]b4_parser_class[&) = delete; + /// Non copyable. + ]b4_parser_class[& operator= (const ]b4_parser_class[&) = delete; +#endif + + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + virtual int parse (); + +#if] b4_api_PREFIX[DEBUG + /// The current debugging stream. + std::ostream& debug_stream () const YY_ATTRIBUTE_PURE; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + typedef int debug_level_type; + /// The current debugging level. + debug_level_type debug_level () const YY_ATTRIBUTE_PURE; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); +#endif + + /// Report a syntax error.]b4_locations_if([[ + /// \param loc where the syntax error is found.]])[ + /// \param msg a description of the syntax error. + virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); + + /// Report a syntax error. + void error (const syntax_error& err); + +]b4_parse_error_bmatch( +[custom\|detailed], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol);]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static const char *symbol_name (symbol_kind_type yysymbol); +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static std::string symbol_name (symbol_kind_type yysymbol);]])[ + +]b4_token_constructor_define[ +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + class context + { + public: + context (const ]b4_parser_class[& yyparser, const symbol_type& yyla); + const symbol_type &lookahead() const YY_NOEXCEPT + { + return yyla_; + } + symbol_kind_type token() const YY_NOEXCEPT + { + return yyla_.kind(); + }]b4_locations_if([[ + const location_type& location () const YY_NOEXCEPT { + return yyla_.location; } +]])[ + /// Put in YYARG at most YYARGN of the expected tokens, and return the + /// number of tokens stored in YYARG. If YYARG is null, return the + /// number of expected tokens (guaranteed to be less than YYNTOKENS). + int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; + + private: + const ]b4_parser_class[& yyparser_; + const symbol_type& yyla_; + }; +]])[ + private: +#if YY_CPLUSPLUS < 201103L + /// Non copyable. + ]b4_parser_class[ (const ]b4_parser_class[&); + /// Non copyable. + ]b4_parser_class[& operator= (const ]b4_parser_class[&); +#endif +]b4_lac_if([[ + /// Check the lookahead yytoken. + /// \returns true iff the token will be eventually shifted. + bool yy_lac_check_ (symbol_kind_type yytoken) const; + /// Establish the initial context if no initial context currently exists. + /// \returns true iff the token will be eventually shifted. + bool yy_lac_establish_ (symbol_kind_type yytoken); + /// Discard any previous initial lookahead context because of event. + /// \param event the event which caused the lookahead to be discarded. + /// Only used for debbuging output. + void yy_lac_discard_ (const char* event);]])[ + + /// Stored state numbers (used for stacks). + typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type; +]b4_parse_error_bmatch( +[custom], [[ + /// Report a syntax error + /// \param yyctx the context in which the error occurred. + void report_syntax_error (const context& yyctx) const;]], +[detailed\|verbose], [[ + /// The arguments of the error message. + int yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const; + + /// Generate an error message. + /// \param yyctx the context in which the error occurred. + virtual std::string yysyntax_error_ (const context& yyctx) const;]])[ + /// Compute post-reduction state. + /// \param yystate the current state + /// \param yysym the nonterminal to push on the stack + static state_type yy_lr_goto_state_ (state_type yystate, int yysym); + + /// Whether the given \c yypact_ value indicates a defaulted state. + /// \param yyvalue the value to check + static bool yy_pact_value_is_default_ (int yyvalue) YY_NOEXCEPT; + + /// Whether the given \c yytable_ value indicates a syntax error. + /// \param yyvalue the value to check + static bool yy_table_value_is_error_ (int yyvalue) YY_NOEXCEPT; + + static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_; + static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; + + /// Convert a scanner token kind \a t to a symbol kind. + /// In theory \a t should be a token_kind_type, but character literals + /// are valid, yet not members of the token_kind_type enum. + static symbol_kind_type yytranslate_ (int t) YY_NOEXCEPT; + +]b4_parse_error_bmatch( +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + /// For a symbol, its name in clear. + static const char* const yytname_[]; +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /// Convert the symbol name \a n to a form suitable for a diagnostic. + static std::string yytnamerr_ (const char *yystr); + + /// For a symbol, its name in clear. + static const char* const yytname_[]; +]])[ + + // Tables. +]b4_parser_tables_declare[ + +#if] b4_api_PREFIX[DEBUG +]b4_integral_parser_table_declare([rline], [b4_rline], + [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ + /// Report on the debug stream that the rule \a r is going to be reduced. + virtual void yy_reduce_print_ (int r) const; + /// Print the state stack on the debug stream. + virtual void yy_stack_print_ () const; + + /// Debugging level. + int yydebug_; + /// Debug stream. + std::ostream* yycdebug_; + + /// \brief Display a symbol kind, value and location. + /// \param yyo The output stream. + /// \param yysym The symbol. + template + void yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const; +#endif + + /// \brief Reclaim the memory associated to a symbol. + /// \param yymsg Why this token is reclaimed. + /// If null, print nothing. + /// \param yysym The symbol. + template + void yy_destroy_ (const char* yymsg, basic_symbol& yysym) const; + + private: + /// Type access provider for state based symbols. + struct by_state + { + /// Default constructor. + by_state() YY_NOEXCEPT; + + /// The symbol kind as needed by the constructor. + typedef state_type kind_type; + + /// Constructor. + by_state(kind_type s) YY_NOEXCEPT; + + /// Copy constructor. + by_state(const by_state &that) YY_NOEXCEPT; + + /// Record that this symbol is empty. + void clear() YY_NOEXCEPT; + + /// Steal the symbol kind from \a that. + void move(by_state & that); + + /// The symbol kind (corresponding to \a state). + /// \a ]b4_symbol(empty, kind)[ when empty. + symbol_kind_type kind() const YY_NOEXCEPT; + + /// The state number used to denote an empty symbol. + /// We use the initial state, as it does not have a value. + enum + { + empty_state = 0 + }; + + /// The state. + /// \a empty when empty. + state_type state; + }; + + /// "Internal" symbol: element of the stack. + struct stack_symbol_type : basic_symbol + { + /// Superclass. + typedef basic_symbol super_type; + /// Construct an empty symbol. + stack_symbol_type(); + /// Move or copy construction. + stack_symbol_type(YY_RVREF(stack_symbol_type) that); + /// Steal the contents from \a sym to build this. + stack_symbol_type(state_type s, YY_MOVE_REF(symbol_type) sym); +#if YY_CPLUSPLUS < 201103L + /// Assignment, needed by push_back by some old implementations. + /// Moves the contents of that. + stack_symbol_type &operator=(stack_symbol_type &that); + + /// Assignment, needed by push_back by other implementations. + /// Needed by some other old implementations. + stack_symbol_type &operator=(const stack_symbol_type &that); +#endif + }; + +]b4_stack_define[ + + /// Stack type. + typedef stack stack_type; + + /// The stack. + stack_type yystack_;]b4_lac_if([[ + /// The stack for LAC. + /// Logically, the yy_lac_stack's lifetime is confined to the function + /// yy_lac_check_. We just store it as a member of this class to hold + /// on to the memory and to avoid frequent reallocations. + /// Since yy_lac_check_ is const, this member must be mutable. + mutable std::vector yylac_stack_; + /// Whether an initial LAC context was established. + bool yy_lac_established_; +]])[ + + /// Push a new state on the stack. + /// \param m a debug message to display + /// if null, no trace is output. + /// \param sym the symbol + /// \warning the contents of \a s.value is stolen. + void yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym); + + /// Push a new look ahead token on the state on the stack. + /// \param m a debug message to display + /// if null, no trace is output. + /// \param s the state + /// \param sym the symbol (for its value and location). + /// \warning the contents of \a sym.value is stolen. + void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym); + + /// Pop \a n symbols from the stack. + void yypop_ (int n = 1) YY_NOEXCEPT; + + /// Constants. + enum + { + yylast_ = ]b4_last[, ///< Last index in yytable_. + yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols. + yyfinal_ = ]b4_final_state_number[ ///< Termination state number. + }; + +]b4_parse_param_vars[ +]b4_percent_code_get([[yy_bison_internal_hook]])[ + }; + +]b4_token_ctor_if([b4_yytranslate_define([$1])[ +]b4_public_types_define([$1])])[ +]b4_namespace_close[ + +]b4_percent_code_get([[provides]])[ +]])[ + + +## -------------- ## +## Output files. ## +## -------------- ## + +#-- -- -- -- -- -- - # +#Header file.# +#-- -- -- -- -- -- - # + +]b4_header_if([[ +]b4_output_begin([b4_spec_header_file])[ +]b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])[ + +/** + ** \file ]b4_spec_mapped_header_file[ + ** Define the ]b4_namespace_ref[::parser class. + */ + +// C++ LALR(1) parser skeleton written by Akim Demaille. + +]b4_disclaimer[ +]b4_cpp_guard_open([b4_spec_mapped_header_file])[ +]b4_shared_declarations(hh)[ +]b4_cpp_guard_close([b4_spec_mapped_header_file])[ +]b4_output_end[ +]])[ + +#-- -- -- -- -- -- -- -- -- -- - # +#Implementation file.# +#-- -- -- -- -- -- -- -- -- -- - # + +]b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])[ +]b4_disclaimer[ +]b4_percent_code_get([[top]])[]dnl +m4_if(b4_prefix, [yy], [], +[ +// Take the name prefix into account. +[#]define yylex b4_prefix[]lex])[ + +]b4_user_pre_prologue[ + +]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]], + [b4_shared_declarations([cc])])[ + +]b4_user_post_prologue[ +]b4_percent_code_get[ + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include // FIXME: INFRINGES ON USER NAME SPACE. +# define YY_(msgid) dgettext("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif +]b4_has_translations_if([ +#ifndef N_ +# define N_(Msgid) Msgid +#endif +])[ + +// Whether we are compiled with exception support. +#ifndef YY_EXCEPTIONS +# if defined __GNUC__ && !defined __EXCEPTIONS +# define YY_EXCEPTIONS 0 +# else +# define YY_EXCEPTIONS 1 +# endif +#endif + +]b4_locations_if([dnl +[#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) +]b4_yylloc_default_define])[ + +// Enable debugging if requested. +#if] b4_api_PREFIX[DEBUG + +// A pseudo ostream that takes yydebug_ into account. +# define YYCDEBUG \ + if (yydebug_) \ + (*yycdebug_) + +# define YY_SYMBOL_PRINT(Title, Symbol) \ + do \ + { \ + if (yydebug_) \ + { \ + *yycdebug_ << Title << ' '; \ + yy_print_(*yycdebug_, Symbol); \ + *yycdebug_ << '\n'; \ + } \ + } while (false) + +# define YY_REDUCE_PRINT(Rule) \ + do \ + { \ + if (yydebug_) \ + yy_reduce_print_(Rule); \ + } while (false) + +# define YY_STACK_PRINT() \ + do \ + { \ + if (yydebug_) \ + yy_stack_print_(); \ + } while (false) + +#else // !]b4_api_PREFIX[DEBUG + +# define YYCDEBUG \ + if (false) \ + std::cerr +# define YY_SYMBOL_PRINT(Title, Symbol) YY_USE(Symbol) +# define YY_REDUCE_PRINT(Rule) static_cast(0) +# define YY_STACK_PRINT() static_cast(0) + +#endif // !]b4_api_PREFIX[DEBUG + +#define yyerrok (yyerrstatus_ = 0) +#define yyclearin (yyla.clear()) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYRECOVERING() (!!yyerrstatus_) + +]b4_namespace_open[ + /// Build a parser object. + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[) +#if] b4_api_PREFIX[DEBUG + : yydebug_ (false), + yycdebug_ (&std::cerr)]b4_lac_if([,], [m4_ifset([b4_parse_param], [,])])[ +#else +]b4_lac_if([ :], [m4_ifset([b4_parse_param], [ :])])[ +#endif] b4_lac_if([[ + yy_lac_established_ (false)]m4_ifset([b4_parse_param], [,])])[]b4_parse_param_cons[ + {} + + ]b4_parser_class::~b4_parser_class[ () + {} + + ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW + {} + + /*---------. + | symbol. | + `---------*/ + +]b4_token_ctor_if([], [b4_public_types_define([cc])])[ + + // by_state. + ]b4_parser_class[::by_state::by_state () YY_NOEXCEPT + : state (empty_state) + {} + + ]b4_parser_class[::by_state::by_state (const by_state& that) YY_NOEXCEPT + : state (that.state) + {} + + void + ]b4_parser_class[::by_state::clear () YY_NOEXCEPT + { + state = empty_state; + } + + void + ]b4_parser_class[::by_state::move (by_state& that) + { + state = that.state; + that.clear(); + } + + ]b4_parser_class[::by_state::by_state (state_type s) YY_NOEXCEPT + : state (s) + {} + + ]b4_parser_class[::symbol_kind_type + ]b4_parser_class[::by_state::kind () const YY_NOEXCEPT + { + if (state == empty_state) + return ]b4_symbol(empty, kind)[; + else + return YY_CAST (symbol_kind_type, yystos_[+state]); + } + + ]b4_parser_class[::stack_symbol_type::stack_symbol_type () + {} + + ]b4_parser_class[::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that) + : super_type (YY_MOVE (that.state)]b4_variant_if([], [, YY_MOVE (that.value)])b4_locations_if([, YY_MOVE (that.location)])[) + {]b4_variant_if([ + b4_symbol_variant([that.kind ()], + [value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[ +#if 201103L <= YY_CPLUSPLUS + // that is emptied. + that.state = empty_state; +#endif + } + + ]b4_parser_class[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that) + : super_type (s]b4_variant_if([], [, YY_MOVE (that.value)])[]b4_locations_if([, YY_MOVE (that.location)])[) + {]b4_variant_if([ + b4_symbol_variant([that.kind ()], + [value], [move], [YY_MOVE (that.value)])])[ + // that is emptied. + that.kind_ = ]b4_symbol(empty, kind)[; + } + +#if YY_CPLUSPLUS < 201103L + ]b4_parser_class[::stack_symbol_type& + ]b4_parser_class[::stack_symbol_type::operator= (const stack_symbol_type& that) + { + state = that.state; + ]b4_variant_if([b4_symbol_variant([that.kind ()], + [value], [copy], [that.value])], + [[value = that.value;]])[]b4_locations_if([ + location = that.location;])[ + return *this; + } + + ]b4_parser_class[::stack_symbol_type& + ]b4_parser_class[::stack_symbol_type::operator= (stack_symbol_type& that) + { + state = that.state; + ]b4_variant_if([b4_symbol_variant([that.kind ()], + [value], [move], [that.value])], + [[value = that.value;]])[]b4_locations_if([ + location = that.location;])[ + // that is emptied. + that.state = empty_state; + return *this; + } +#endif + + template + void + ]b4_parser_class[::yy_destroy_ (const char* yymsg, basic_symbol& yysym) const + { + if (yymsg) + YY_SYMBOL_PRINT(yymsg, yysym);]b4_variant_if([], [ + + // User destructor. + b4_symbol_actions([destructor], [yysym.kind ()])])[ + } + +#if] b4_api_PREFIX[DEBUG + template + void + ]b4_parser_class[::yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const + { + std::ostream &yyoutput = yyo; + YY_USE(yyoutput); + if (yysym.empty()) + yyo << "empty symbol"; + else + { + symbol_kind_type yykind = yysym.kind(); + yyo << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << yysym.name () << " ("]b4_locations_if([ + << yysym.location << ": "])[; + ]b4_symbol_actions([printer])[ + yyo << ')'; + } + } +#endif + + void + ]b4_parser_class[::yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym) + { + if (m) + YY_SYMBOL_PRINT(m, sym); + yystack_.push(YY_MOVE(sym)); + } + + void + ]b4_parser_class[::yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym) + { +#if 201103L <= YY_CPLUSPLUS + yypush_(m, stack_symbol_type(s, std::move(sym))); +#else + stack_symbol_type ss(s, sym); + yypush_(m, ss); +#endif + } + + void + ]b4_parser_class[::yypop_ (int n) YY_NOEXCEPT + { + yystack_.pop(n); + } + +#if] b4_api_PREFIX[DEBUG + std::ostream& + ]b4_parser_class[::debug_stream () const + { + return *yycdebug_; + } + + void + ]b4_parser_class[::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + ]b4_parser_class[::debug_level_type + ]b4_parser_class[::debug_level () const + { + return yydebug_; + } + + void + ]b4_parser_class[::set_debug_level (debug_level_type l) + { + yydebug_ = l; + } +#endif // ]b4_api_PREFIX[DEBUG + + ]b4_parser_class[::state_type + ]b4_parser_class[::yy_lr_goto_state_ (state_type yystate, int yysym) + { + int yyr = yypgoto_[yysym - YYNTOKENS] + yystate; + if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) + return yytable_[yyr]; + else + return yydefgoto_[yysym - YYNTOKENS]; + } + + bool + ]b4_parser_class[::yy_pact_value_is_default_ (int yyvalue) YY_NOEXCEPT + { + return yyvalue == yypact_ninf_; + } + + bool + ]b4_parser_class[::yy_table_value_is_error_ (int yyvalue) YY_NOEXCEPT + { + return yyvalue == yytable_ninf_; + } + + int + ]b4_parser_class[::operator() () + { + return parse(); + } + + int + ]b4_parser_class[::parse () + { + int yyn; + /// Length of the RHS of the rule being reduced. + int yylen = 0; + + // Error handling. + int yynerrs_ = 0; + int yyerrstatus_ = 0; + + /// The lookahead symbol. + symbol_type yyla;]b4_locations_if([[ + + /// The locations where the error started and ended. + stack_symbol_type yyerror_range[3];]])[ + + /// The return value of parse (). + int yyresult;]b4_lac_if([[ + + // Discard the LAC context in case there still is one left from a + // previous invocation. + yy_lac_discard_ ("init");]])[ + +#if YY_EXCEPTIONS + try +#endif // YY_EXCEPTIONS + { + YYCDEBUG << "Starting parse\n"; + +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl + b4_user_initial_action +b4_dollar_popdef])[]dnl + + [ /* Initialize the stack. The initial state will be set in + yynewstate, since the latter expects the semantical and the + location values to have been already stored, initialize these + stacks with a primary value. */ + yystack_.clear (); + yypush_ (YY_NULLPTR, 0, YY_MOVE (yyla)); + + /*-----------------------------------------------. + | yynewstate -- push a new symbol on the stack. | + `-----------------------------------------------*/ + yynewstate: + YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n'; + YY_STACK_PRINT (); + + // Accept? + if (yystack_[0].state == yyfinal_) + YYACCEPT; + + goto yybackup; + + + /*-----------. + | yybackup. | + `-----------*/ + yybackup: + // Try to take a decision without lookahead. + yyn = yypact_[+yystack_[0].state]; + if (yy_pact_value_is_default_ (yyn)) + goto yydefault; + + // Read a lookahead token. + if (yyla.empty ()) + { + YYCDEBUG << "Reading a token\n"; +#if YY_EXCEPTIONS + try +#endif // YY_EXCEPTIONS + {]b4_token_ctor_if([[ + symbol_type yylookahead (]b4_yylex[); + yyla.move (yylookahead);]], [[ + yyla.kind_ = yytranslate_ (]b4_yylex[);]])[ + } +#if YY_EXCEPTIONS + catch (const syntax_error &yyexc) + { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n'; + error(yyexc); + goto yyerrlab1; + } +#endif // YY_EXCEPTIONS + } + YY_SYMBOL_PRINT ("Next token is", yyla); + + if (yyla.kind () == ]b4_symbol(error, kind)[) + { + // The scanner already issued an error message, process directly + // to error recovery. But do not keep the error token as + // lookahead, it is too special and may lead us to an endless + // loop in error recovery. */ + yyla.kind_ = ]b4_symbol(undef, kind)[; + goto yyerrlab1; + } + + /* If the proper action on seeing token YYLA.TYPE is to reduce or + to detect an error, take that action. */ + yyn += yyla.kind (); + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ()) + {]b4_lac_if([[ + if (!yy_lac_establish_ (yyla.kind ())) + goto yyerrlab;]])[ + goto yydefault; + } + + // Reduce or error. + yyn = yytable_[yyn]; + if (yyn <= 0) + { + if (yy_table_value_is_error_(yyn)) + goto yyerrlab;]b4_lac_if([[ + if (!yy_lac_establish_ (yyla.kind ())) + goto yyerrlab; +]])[ + yyn = -yyn; + goto yyreduce; + } + + // Count tokens shifted since error; after three, turn off error status. + if (yyerrstatus_) + --yyerrstatus_; + + // Shift the lookahead token. + yypush_ ("Shifting", state_type (yyn), YY_MOVE (yyla));]b4_lac_if([[ + yy_lac_discard_ ("shift");]])[ + goto yynewstate; + + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + yydefault: + yyn = yydefact_[+yystack_[0].state]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + + /*-----------------------------. + | yyreduce -- do a reduction. | + `-----------------------------*/ + yyreduce: + yylen = yyr2_[yyn]; + { + stack_symbol_type yylhs; + yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);]b4_variant_if([[ + /* Variants are always initialized to an empty instance of the + correct type. The default '$$ = $1' action is NOT applied + when using variants. */ + ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [[ + /* If YYLEN is nonzero, implement the default value of the + action: '$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYLHS.VALUE to garbage. + This behavior is undocumented and Bison users should not rely + upon it. */ + if (yylen) + yylhs.value = yystack_@{yylen - 1@}.value; + else + yylhs.value = yystack_@{0@}.value;]])[ +]b4_locations_if([dnl +[ + // Default location. + { + stack_type::slice range(yystack_, yylen); + YYLLOC_DEFAULT(yylhs.location, range, yylen); + yyerror_range[1].location = yylhs.location; + }]])[ + + // Perform the reduction. + YY_REDUCE_PRINT (yyn); +#if YY_EXCEPTIONS + try +#endif // YY_EXCEPTIONS + { + switch (yyn) + { +]b4_user_actions[ + default: + break; + } + } +#if YY_EXCEPTIONS + catch (const syntax_error& yyexc) + { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n'; + error(yyexc); + YYERROR; + } +#endif // YY_EXCEPTIONS + YY_SYMBOL_PRINT ("-> $$ =", yylhs); + yypop_ (yylen); + yylen = 0; + + // Shift the result of the reduction. + yypush_ (YY_NULLPTR, YY_MOVE (yylhs)); + } + goto yynewstate; + + + /*--------------------------------------. + | yyerrlab -- here on detecting error. | + `--------------------------------------*/ + yyerrlab: + // If not already recovering from an error, report this error. + if (!yyerrstatus_) + { + ++yynerrs_;]b4_parse_error_case( + [simple], [[ + std::string msg = YY_("syntax error"); + error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]], + [custom], [[ + context yyctx (*this, yyla); + report_syntax_error (yyctx);]], + [[ + context yyctx (*this, yyla); + std::string msg = yysyntax_error_ (yyctx); + error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[ + } + +]b4_locations_if([[ + yyerror_range[1].location = yyla.location;]])[ + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + // Return failure if at end of input. + if (yyla.kind () == ]b4_symbol(eof, kind)[) + YYABORT; + else if (!yyla.empty()) + { + yy_destroy_("Error: discarding", yyla); + yyla.clear(); + } + } + + // Else will try to reuse lookahead token after shifting the error token. + goto yyerrlab1; + + + /*---------------------------------------------------. + | yyerrorlab -- error raised explicitly by YYERROR. | + `---------------------------------------------------*/ + yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and + the label yyerrorlab therefore never appears in user code. */ + if (false) + YYERROR; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + yypop_ (yylen); + yylen = 0; + YY_STACK_PRINT (); + goto yyerrlab1; + + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + yyerrlab1: + yyerrstatus_ = 3; // Each real token shifted decrements this. + // Pop stack until we find a state that shifts the error token. + for (;;) + { + yyn = yypact_[+yystack_[0].state]; + if (!yy_pact_value_is_default_(yyn)) + { + yyn += ]b4_symbol(error, kind)[; + if (0 <= yyn && yyn <= yylast_ + && yycheck_[yyn] == ]b4_symbol(error, kind)[) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + // Pop the current state because it cannot handle the error token. + if (yystack_.size() == 1) + YYABORT; +]b4_locations_if([[ + yyerror_range[1].location = yystack_[0].location;]])[ + yy_destroy_ ("Error: popping", yystack_[0]); + yypop_ (); + YY_STACK_PRINT (); + } + { + stack_symbol_type error_token; +]b4_locations_if([[ + yyerror_range[2].location = yyla.location; + YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[ + + // Shift the error token.]b4_lac_if([[ + yy_lac_discard_ ("error recovery");]])[ + error_token.state = state_type (yyn); + yypush_ ("Shifting", YY_MOVE (error_token)); + } + goto yynewstate; + + + /*-------------------------------------. + | yyacceptlab -- YYACCEPT comes here. | + `-------------------------------------*/ + yyacceptlab: + yyresult = 0; + goto yyreturn; + + + /*-----------------------------------. + | yyabortlab -- YYABORT comes here. | + `-----------------------------------*/ + yyabortlab: + yyresult = 1; + goto yyreturn; + + + /*-----------------------------------------------------. + | yyreturn -- parsing is finished, return the result. | + `-----------------------------------------------------*/ + yyreturn: + if (!yyla.empty ()) + yy_destroy_ ("Cleanup: discarding lookahead", yyla); + + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + yypop_ (yylen); + YY_STACK_PRINT (); + while (1 < yystack_.size ()) + { + yy_destroy_("Cleanup: popping", yystack_[0]); + yypop_(); + } + + return yyresult; + } +#if YY_EXCEPTIONS + catch (...) + { + YYCDEBUG << "Exception caught: cleaning lookahead and stack\n"; + // Do not try to display the values of the reclaimed symbols, + // as their printers might throw an exception. + if (!yyla.empty()) + yy_destroy_(YY_NULLPTR, yyla); + + while (1 < yystack_.size()) + { + yy_destroy_(YY_NULLPTR, yystack_[0]); + yypop_(); + } + throw; + } +#endif // YY_EXCEPTIONS + } + + void + ]b4_parser_class[::error (const syntax_error& yyexc) + { + error (]b4_join(b4_locations_if([yyexc.location]), + [[yyexc.what ()]])[); + } + +]b4_parse_error_bmatch([custom\|detailed], +[[ const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ + } +]], +[simple], +[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ + const char * + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytname_[yysymbol]; + } +#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ +]], +[verbose], +[[ /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + ]b4_parser_class[::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes:; + } + + return yystr; + } + + std::string + ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) + { + return yytnamerr_(yytname_[yysymbol]); + } +]])[ + +]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ + // ]b4_parser_class[::context. + ]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla) + : yyparser_ (yyparser) + , yyla_ (yyla) + {} + + int + ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const + { + // Actual number of expected tokens + int yycount = 0; +]b4_lac_if([[ +#if] b4_api_PREFIX[DEBUG + // Execute LAC once. We don't care if it is successful, we + // only do it for the sake of debugging output. + if (!yyparser_.yy_lac_established_) + yyparser_.yy_lac_check_ (yyla_.kind ()); +#endif + + for (int yyx = 0; yyx < YYNTOKENS; ++yyx) + { + symbol_kind_type yysym = YY_CAST(symbol_kind_type, yyx); + if (yysym != ]b4_symbol(error, kind)[ + && yysym != ]b4_symbol(undef, kind)[ + && yyparser_.yy_lac_check_ (yysym)) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], [[ + const int yyn = yypact_[+yyparser_.yystack_[0].state]; + if (!yy_pact_value_is_default_ (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + const int yyxbegin = yyn < 0 ? -yyn : 0; + // Stay within bounds of both yycheck and yytname. + const int yychecklim = yylast_ - yyn + 1; + const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yy_table_value_is_error_ (yytable_[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST(symbol_kind_type, yyx); + } + } +]])[ + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(empty, kind)[; + return yycount; + } + +]])[ + +]b4_lac_if([[ + bool + ]b4_parser_class[::yy_lac_check_ (symbol_kind_type yytoken) const + { + // Logically, the yylac_stack's lifetime is confined to this function. + // Clear it, to get rid of potential left-overs from previous call. + yylac_stack_.clear(); + // Reduce until we encounter a shift and thereby accept the token. +#if] b4_api_PREFIX[DEBUG + YYCDEBUG << "LAC: checking lookahead " << symbol_name(yytoken) << ':'; +#endif + std::ptrdiff_t lac_top = 0; + while (true) + { + state_type top_state = + (yylac_stack_.empty() ? yystack_[lac_top].state : yylac_stack_.back()); + int yyrule = yypact_[+top_state]; + if (yy_pact_value_is_default_(yyrule) || (yyrule += yytoken) < 0 || yylast_ < yyrule || + yycheck_[yyrule] != yytoken) + { + // Use the default action. + yyrule = yydefact_[+top_state]; + if (yyrule == 0) + { + YYCDEBUG << " Err\n"; + return false; + } + } + else + { + // Use the action from yytable. + yyrule = yytable_[yyrule]; + if (yy_table_value_is_error_(yyrule)) + { + YYCDEBUG << " Err\n"; + return false; + } + if (0 < yyrule) + { + YYCDEBUG << " S" << yyrule << '\n'; + return true; + } + yyrule = -yyrule; + } + // By now we know we have to simulate a reduce. + YYCDEBUG << " R" << yyrule - 1; + // Pop the corresponding number of values from the stack. + { + std::ptrdiff_t yylen = yyr2_[yyrule]; + // First pop from the LAC stack as many tokens as possible. + std::ptrdiff_t lac_size = std::ptrdiff_t(yylac_stack_.size()); + if (yylen < lac_size) + { + yylac_stack_.resize(std::size_t(lac_size - yylen)); + yylen = 0; + } + else if (lac_size) + { + yylac_stack_.clear(); + yylen -= lac_size; + } + // Only afterwards look at the main stack. + // We simulate popping elements by incrementing lac_top. + lac_top += yylen; + } + // Keep top_state in sync with the updated stack. + top_state = (yylac_stack_.empty() ? yystack_[lac_top].state : yylac_stack_.back()); + // Push the resulting state of the reduction. + state_type state = yy_lr_goto_state_(top_state, yyr1_[yyrule]); + YYCDEBUG << " G" << int(state); + yylac_stack_.push_back(state); + } + } + + // Establish the initial context if no initial context currently exists. + bool + ]b4_parser_class[::yy_lac_establish_ (symbol_kind_type yytoken) + { + /* Establish the initial context for the current lookahead if no initial + context is currently established. + + We define a context as a snapshot of the parser stacks. We define + the initial context for a lookahead as the context in which the + parser initially examines that lookahead in order to select a + syntactic action. Thus, if the lookahead eventually proves + syntactically unacceptable (possibly in a later context reached via a + series of reductions), the initial context can be used to determine + the exact set of tokens that would be syntactically acceptable in the + lookahead's place. Moreover, it is the context after which any + further semantic actions would be erroneous because they would be + determined by a syntactically unacceptable token. + + yy_lac_establish_ should be invoked when a reduction is about to be + performed in an inconsistent state (which, for the purposes of LAC, + includes consistent states that don't know they're consistent because + their default reductions have been disabled). + + For parse.lac=full, the implementation of yy_lac_establish_ is as + follows. If no initial context is currently established for the + current lookahead, then check if that lookahead can eventually be + shifted if syntactic actions continue from the current context. */ + if (yy_lac_established_) + return true; + else + { +#if] b4_api_PREFIX[DEBUG + YYCDEBUG << "LAC: initial context established for " << symbol_name(yytoken) << '\n'; +#endif + yy_lac_established_ = true; + return yy_lac_check_(yytoken); + } + } + + // Discard any previous initial lookahead context. + void + ]b4_parser_class[::yy_lac_discard_ (const char* event) + { + /* Discard any previous initial lookahead context because of Event, + which may be a lookahead change or an invalidation of the currently + established initial context for the current lookahead. + + The most common example of a lookahead change is a shift. An example + of both cases is syntax error recovery. That is, a syntax error + occurs when the lookahead is syntactically erroneous for the + currently established initial context, so error recovery manipulates + the parser stacks to try to find a new initial context in which the + current lookahead is syntactically acceptable. If it fails to find + such a context, it discards the lookahead. */ + if (yy_lac_established_) + { + YYCDEBUG << "LAC: initial context discarded due to " << event << '\n'; + yy_lac_established_ = false; + } + }]])[ + +]b4_parse_error_bmatch([detailed\|verbose], [[ + int + ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const + { + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yyla) is + if this state is a consistent state with a default action. + Thus, detecting the absence of a lookahead is sufficient to + determine that there is no unexpected or expected token to + report. In that case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is + a consistent state with a default action. There might have + been a previous inconsistent state, consistent state with a + non-default action, or user semantic action that manipulated + yyla. (However, yyla is currently not documented for users.)]b4_lac_if([[ + In the first two cases, it might appear that the current syntax + error should have been detected in the previous state when + yy_lac_check was invoked. However, at that time, there might + have been a different syntax error that discarded a different + initial context during error recovery, leaving behind the + current lookahead.]], [[ + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state.]])[ + */ + + if (!yyctx.lookahead().empty()) + { + if (yyarg) + yyarg[0] = yyctx.token(); + int yyn = yyctx.expected_tokens(yyarg ? yyarg + 1 : yyarg, yyargn - 1); + return yyn + 1; + } + return 0; + } + + // Generate an error message. + std::string + ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const + { + // Its maximum. + enum + { + YYARGS_MAX = 5 + }; + // Arguments of yyformat. + symbol_kind_type yyarg[YYARGS_MAX]; + int yycount = yy_syntax_error_arguments_(yyctx, yyarg, YYARGS_MAX); + + char const *yyformat = YY_NULLPTR; + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: // Avoid compiler warnings. + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } + + std::string yyres; + // Argument number. + std::ptrdiff_t yyi = 0; + for (char const *yyp = yyformat; *yyp; ++yyp) + if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) + { + yyres += symbol_name(yyarg[yyi++]); + ++yyp; + } + else + yyres += *yyp; + return yyres; + }]])[ + + + const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class::yypact_ninf_ = b4_pact_ninf[; + + const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class::yytable_ninf_ = b4_table_ninf[; + +]b4_parser_tables_define[ + +]b4_parse_error_bmatch([simple\|verbose], +[[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[ + // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + // First, the terminals, then, starting at \a YYNTOKENS, nonterminals. + const char* + const ]b4_parser_class[::yytname_[] = + { + ]b4_tname[ + }; +#endif +]])[ + +#if] b4_api_PREFIX[DEBUG][ +]b4_integral_parser_table_define([rline], [b4_rline])[ + + void + ]b4_parser_class[::yy_stack_print_ () const + { + *yycdebug_ << "Stack now"; + for (stack_type::const_iterator i = yystack_.begin(), i_end = yystack_.end(); i != i_end; ++i) + *yycdebug_ << ' ' << int(i->state); + *yycdebug_ << '\n'; + } + + void + ]b4_parser_class[::yy_reduce_print_ (int yyrule) const + { + int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + // Print the symbols being reduced, and their result. + *yycdebug_ << "Reducing stack by rule " << yyrule - 1 << " (line " << yylno << "):\n"; + // The symbols being reduced. + for (int yyi = 0; yyi < yynrhs; yyi++) + YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", + ]b4_rhs_data(yynrhs, yyi + 1)[); + } +#endif // ]b4_api_PREFIX[DEBUG + +]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[ +]b4_namespace_close[ +]b4_epilogue[]dnl +b4_output_end + + +m4_popdef([b4_copyright_years])dnl diff --git a/tools/flex-bison/third_party/skeletons/lalr1.d b/tools/flex-bison/third_party/skeletons/lalr1.d new file mode 100644 index 000000000..973037722 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/lalr1.d @@ -0,0 +1,1326 @@ +# D skeleton for Bison -*- autoconf -*- + +# Copyright (C) 2007-2012, 2019-2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[d.m4]) + +b4_header_if([b4_complain([%header/%defines does not make sense in D])]) + +# parse.lac +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + + +## --------------- ## +## api.push-pull. ## +## --------------- ## + +b4_percent_define_default([[api.push-pull]], [[pull]]) +b4_percent_define_check_values([[[[api.push-pull]], + [[pull]], [[push]], [[both]]]]) + +# Define m4 conditional macros that encode the value +# of the api.push-pull flag. +b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]]) +b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]]) +m4_case(b4_percent_define_get([[api.push-pull]]), + [pull], [m4_define([b4_push_flag], [[0]])], + [push], [m4_define([b4_pull_flag], [[0]])]) + +# Define a macro to be true when api.push-pull has the value "both". +m4_define([b4_both_if],[b4_push_if([b4_pull_if([$1],[$2])],[$2])]) + +# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing +# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the +# behavior of Bison at all when push parsing is already requested. +b4_define_flag_if([use_push_for_pull]) +b4_use_push_for_pull_if([ + b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], + [m4_define([b4_push_flag], [[1]])])]) + + +# Define a macro to encapsulate the parse state variables. This +# allows them to be defined either in parse() when doing pull parsing, +# or as class instance variable when doing push parsing. +b4_output_begin([b4_parser_file_name]) +b4_copyright([Skeleton implementation for Bison LALR(1) parsers in D], + [2007-2012, 2019-2021])[ +]b4_disclaimer[ +]b4_percent_define_ifdef([package], [module b4_percent_define_get([package]); +])[ +version(D_Version2) { +} else { + static assert(false, "need compiler for D Version 2"); +} + +]b4_user_pre_prologue[ +]b4_user_post_prologue[ +]b4_percent_code_get([[imports]])[ +import std.format; +import std.conv; + +/** + * Handle error message internationalisation. + */ +static if (!is(typeof(YY_))) { + version(YYENABLE_NLS) + { + version(ENABLE_NLS) + { + extern(C) char* dgettext(const char*, const char*); + string YY_(const char* s) + { + return to!string(dgettext("bison-runtime", s)); + } + } + } + static if (!is(typeof(YY_))) + { + pragma(inline, true) + string YY_(string msg) { return msg; } + } +} + +/** + * A Bison parser, automatically generated from ]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[. + * + * @@author LALR (1) parser skeleton written by Paolo Bonzini. + * Port to D language was done by Oliver Mangold. + */ + +/** + * Communication interface between the scanner and the Bison-generated + * parser ]b4_parser_class[. + */ +public interface Lexer +{ + /** + * Entry point for the scanner. Returns the token identifier corresponding + * to the next token and prepares to return the semantic value + * ]b4_locations_if([and beginning/ending positions ])[of the token. + * @@return the token identifier corresponding to the next token. */ + Symbol yylex (); + + /** + * Entry point for error reporting. Emits an error + * ]b4_locations_if([referring to the given location ])[in a user-defined way. + *]b4_locations_if([[ + * @@param loc The location of the element to which the + * error message is related]])[ + * @@param s The string for the error message. */ + void yyerror (]b4_locations_if([[const Location loc, ]])[string s); +]b4_parse_error_bmatch([custom], [[ + /** + * Build and emit a "syntax error" message in a user-defined way. + * + * @@param ctx The context of the error. + */ + void reportSyntaxError(]b4_parser_class[.Context ctx); +]])[ +} + +]b4_public_types_declare[ + +]b4_locations_if([b4_position_type_if([[ +static assert(__traits(compiles, + (new Position[1])[0]=(new Position[1])[0]), + "struct/class Position must be default-constructible " + "and assignable"); +static assert(__traits(compiles, (new string[1])[0]=(new Position).toString()), + "error: struct/class Position must have toString method"); +]], [[ + /** + * A struct denoting a point in the input.*/ +public struct ]b4_position_type[ { + + /** The column index within the line of input. */ + public int column = 1; + /** The line number within an input file. */ + public int line = 1; + /** The name of the input file. */ + public string filename = null; + + /** + * A string representation of the position. */ + public string toString() const { + if (filename) + return format("%s:%d.%d", filename, line, column); + else + return format("%d.%d", line, column); + } +} +]])b4_location_type_if([[ +static assert(__traits(compiles, (new Location((new Position[1])[0]))) && + __traits(compiles, (new Location((new Position[1])[0], (new Position[1])[0]))), + "error: struct/class Location must have " + "default constructor and constructors this(Position) and this(Position, Position)."); +static assert(__traits(compiles, (new Location[1])[0].begin=(new Location[1])[0].begin) && + __traits(compiles, (new Location[1])[0].begin=(new Location[1])[0].end) && + __traits(compiles, (new Location[1])[0].end=(new Location[1])[0].begin) && + __traits(compiles, (new Location[1])[0].end=(new Location[1])[0].end), + "error: struct/class Location must have assignment-compatible " + "members/properties 'begin' and 'end'."); +static assert(__traits(compiles, (new string[1])[0]=(new Location[1])[0].toString()), + "error: struct/class Location must have toString method."); + +private immutable bool yy_location_is_class = !__traits(compiles, *(new Location((new Position[1])[0])));]], [[ +/** + * A struct defining a pair of positions. Positions, defined by the + * Position struct, denote a point in the input. + * Locations represent a part of the input through the beginning + * and ending positions. */ +public struct ]b4_location_type[ +{ + /** The first, inclusive, position in the range. */ + public Position begin; + + /** The first position beyond the range. */ + public Position end; + + /** + * Create a Location denoting an empty range located at + * a given point. + * @@param loc The position at which the range is anchored. */ + public this(Position loc) + { + this.begin = this.end = loc; + } + + /** + * Create a Location from the endpoints of the range. + * @@param begin The first position included in the range. + * @@param end The first position beyond the range. */ + public this(Position begin, Position end) + { + this.begin = begin; + this.end = end; + } + + /** + * Reset initial location to final location. + */ + public void step() + { + this.begin = this.end; + } + + /** + * A representation of the location. + */ + public string toString() const + { + auto end_col = 0 < end.column ? end.column - 1 : 0; + auto res = begin.toString (); + if (end.filename && begin.filename != end.filename) + res ~= "-" ~ format("%s:%d.%d", end.filename, end.line, end_col); + else if (begin.line < end.line) + res ~= "-" ~ format("%d.%d", end.line, end_col); + else if (begin.column < end_col) + res ~= "-" ~ format("%d", end_col); + return res; + } +} + +private immutable bool yy_location_is_class = false; + +]])])[]b4_value_type_setup[]m4_ifdef([b4_user_union_members], [private union YYSemanticType +{ +b4_user_union_members +};], +[m4_if(b4_tag_seen_flag, 0, +[[private alias int YYSemanticType;]])])[ +]b4_token_enums[ +]b4_parser_class_declaration[ +{ + ]b4_identification[ + +]b4_declare_symbol_enum[ + +]b4_locations_if([[ + private final Location yylloc_from_stack (ref YYStack rhs, int n) + { + static if (yy_location_is_class) { + if (n > 0) + return new Location (rhs.locationAt (n-1).begin, rhs.locationAt (0).end); + else + return new Location (rhs.locationAt (0).end); + } else { + if (n > 0) + return Location (rhs.locationAt (n-1).begin, rhs.locationAt (0).end); + else + return Location (rhs.locationAt (0).end); + } + }]])[ + +]b4_lexer_if([[ private class YYLexer implements Lexer { +]b4_percent_code_get([[lexer]])[ + } +]])[ + /** The object doing lexical analysis for us. */ + private Lexer yylexer; + +]b4_parse_param_vars[ + +]b4_lexer_if([[ + /** + * Instantiate the Bison-generated parser. + */ + public this] (b4_parse_param_decl([b4_lex_param_decl])[) { +]b4_percent_code_get([[init]])[]b4_lac_if([[ + this.yylacStack = new int[]; + this.yylacEstablished = false;]])[ + this (new YYLexer(]b4_lex_param_call[)); + } +]])[ + + /** + * Instantiate the Bison-generated parser. + * @@param yylexer The scanner that will supply tokens to the parser. + */ + ]b4_lexer_if([[protected]], [[public]]) [this (]b4_parse_param_decl([[Lexer yylexer]])[) { + this.yylexer = yylexer;]b4_parse_trace_if([[ + this.yyDebugStream = stderr;]])[ +]b4_parse_param_cons[ + } +]b4_parse_trace_if([[ + import std.stdio; + private File yyDebugStream; + + /** + * The File on which the debugging output is + * printed. + */ + public File getDebugStream () { return yyDebugStream; } + + /** + * Set the std.File on which the debug output is printed. + * @@param s The stream that is used for debugging output. + */ + public final void setDebugStream(File s) { yyDebugStream = s; } + + private int yydebug = 0; + + /** + * Answer the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + */ + public final int getDebugLevel() { return yydebug; } + + /** + * Set the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + * @@param level The verbosity level for debugging output. + */ + public final void setDebugLevel(int level) { yydebug = level; } + + protected final void yycdebug (string s) { + if (0 < yydebug) + yyDebugStream.write (s); + } + + protected final void yycdebugln (string s) { + if (0 < yydebug) + yyDebugStream.writeln (s); + } +]])[ + private final ]b4_parser_class[.Symbol yylex () { + return yylexer.yylex (); + } + + protected final void yyerror (]b4_locations_if([[const Location loc, ]])[string s) { + yylexer.yyerror (]b4_locations_if([loc, ])[s); + } + + /** + * The number of syntax errors so far. + */ + public int numberOfErrors() const { return yynerrs_; } + private int yynerrs_ = 0; + + /** + * Returned by a Bison action in order to stop the parsing process and + * return success (true). */ + public static immutable int YYACCEPT = 0; + + /** + * Returned by a Bison action in order to stop the parsing process and + * return failure (false). */ + public static immutable int YYABORT = 1; +]b4_push_if([ + /** + * Returned by a Bison action in order to request a new token. + */ + public static immutable int YYPUSH_MORE = 4;])[ + + /** + * Returned by a Bison action in order to start error recovery without + * printing an error message. */ + public static immutable int YYERROR = 2; + + // Internal return codes that are not supported for user semantic + // actions. + private static immutable int YYERRLAB = 3; + private static immutable int YYNEWSTATE = 4; + private static immutable int YYDEFAULT = 5; + private static immutable int YYREDUCE = 6; + private static immutable int YYERRLAB1 = 7; + private static immutable int YYRETURN = 8; +]b4_push_if([[ private static immutable int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */]])[ + +]b4_locations_if([ + private static immutable YYSemanticType yy_semantic_null;])[ + private int yyerrstatus_ = 0; + + private void yyerrok() + { + yyerrstatus_ = 0; + } + + // Lookahead symbol kind. + SymbolKind yytoken = ]b4_symbol(empty, kind)[; + + /* State. */ + int yyn = 0; + int yylen = 0; + int yystate = 0; + + YYStack yystack; + + int label = YYNEWSTATE; + + /* Error handling. */ +]b4_locations_if([[ + /// The location where the error started. + Location yyerrloc; + + /// Location of the lookahead. + Location yylloc; + + /// @@$. + Location yyloc;]])[ + + /// Semantic value of the lookahead. + Value yylval; + + /** + * Whether error recovery is being done. In this state, the parser + * reads token until it reaches a known state, and then restarts normal + * operation. */ + public final bool recovering () + { + return yyerrstatus_ == 0; + } + + /** Compute post-reduction state. + * @@param yystate the current state + * @@param yysym the nonterminal to push on the stack + */ + private int yyLRGotoState(int yystate, int yysym) { + int yyr = yypgoto_[yysym - yyntokens_] + yystate; + if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) + return yytable_[yyr]; + else + return yydefgoto_[yysym - yyntokens_]; + } + + private int yyaction (int yyn, ref YYStack yystack, int yylen) + { + Value yyval;]b4_locations_if([[ + Location yyloc = yylloc_from_stack (yystack, yylen);]])[ + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. */ + if (yylen > 0) + yyval = yystack.valueAt (yylen - 1); + else + yyval = yystack.valueAt (0); + +]b4_parse_trace_if([[ + yy_reduce_print (yyn, yystack);]])[ + + switch (yyn) + { +]b4_user_actions[ + default: break; + } + +]b4_parse_trace_if([[ + yy_symbol_print ("-> $$ =", to!SymbolKind (yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[ + + yystack.pop (yylen); + yylen = 0; + + /* Shift the result of the reduction. */ + int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]); + yystack.push (yystate, yyval]b4_locations_if([, yyloc])[); + return YYNEWSTATE; + } + +]b4_parse_trace_if([[ + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + private final void yy_symbol_print (string s, SymbolKind yykind, + ref Value yyval]b4_locations_if([, ref Location yyloc])[) + { + if (0 < yydebug) + { + File yyo = yyDebugStream; + yyo.write(s); + yyo.write(yykind < yyntokens_ ? " token " : " nterm "); + yyo.write(format("%s", yykind)); + yyo.write(" ("]b4_locations_if([ ~ yyloc.toString() ~ ": "])[); + ]b4_symbol_actions([printer])[ + yyo.write(")\n"); + } + } +]])[ +]b4_symbol_type_define[ +]b4_push_if([[ + /** + * Push Parse input from external lexer + * + * @@param yyla current Symbol + * + * @@return YYACCEPT, YYABORT, YYPUSH_MORE + */ + public int pushParse(Symbol yyla)]], [[ + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + public bool parse()]])[ + {]b4_push_if([[ + if (!this.pushParseInitialized) + { + pushParseInitialize(); + yyerrstatus_ = 0; + } + else + label = YYGETTOKEN; + + bool push_token_consumed = true; +]], [[ bool yyresult;]b4_lac_if([[ + // Discard the LAC context in case there still is one left from a + // previous invocation. + yylacDiscard("init");]])[]b4_parse_trace_if([[ + + yycdebugln ("Starting parse");]])[ + yyerrstatus_ = 0; + +]m4_ifdef([b4_initial_action], [ +m4_pushdef([b4_at_dollar], [yylloc])dnl +m4_pushdef([b4_dollar_dollar], [yylval])dnl + /* User initialization code. */ + b4_user_initial_action +m4_popdef([b4_dollar_dollar])dnl +m4_popdef([b4_at_dollar])])dnl + + [ /* Initialize the stack. */ + yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); + + label = YYNEWSTATE;]])[ + for (;;) + final switch (label) + { + /* New state. Unlike in the C/C++ skeletons, the state is already + pushed when we come here. */ + case YYNEWSTATE:]b4_parse_trace_if([[ + yycdebugln (format("Entering state %d", yystate)); + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + + /* Accept? */ + if (yystate == yyfinal_)]b4_push_if([[ + { + label = YYACCEPT; + break; + }]], [[ + return true;]])[ + + /* Take a decision. First try without lookahead. */ + yyn = yypact_[yystate]; + if (yyPactValueIsDefault(yyn)) + { + label = YYDEFAULT; + break; + }]b4_push_if([[ + goto case; + + case YYGETTOKEN:]])[ + + /* Read a lookahead token. */ + if (yytoken == ]b4_symbol(empty, kind)[) + {]b4_push_if([[ + if (!push_token_consumed) + return YYPUSH_MORE;]])[]b4_parse_trace_if([[ + yycdebugln ("Reading a token");]])[]b4_push_if([[ + yytoken = yyla.token; + yylval = yyla.value;]b4_locations_if([[ + yylloc = yyla.location;]])[ + push_token_consumed = false;]], [[ + Symbol yysymbol = yylex(); + yytoken = yysymbol.token(); + yylval = yysymbol.value();]b4_locations_if([[ + yylloc = yysymbol.location();]])[]])[ + } + + /* Token already converted to internal form. */]b4_parse_trace_if([[ + yy_symbol_print ("Next token is", yytoken, yylval]b4_locations_if([, yylloc])[);]])[ + + if (yytoken == ]b4_symbol(error, kind)[) + { + // The scanner already issued an error message, process directly + // to error recovery. But do not keep the error token as + // lookahead, it is too special and may lead us to an endless + // loop in error recovery. */ + yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[ + yyerrloc = yylloc;]])[ + label = YYERRLAB1; + } + else + { + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) {]b4_lac_if([[ + if (!yylacEstablish(yystack, yytoken)) + label = YYERRLAB; + else]])[ + label = YYDEFAULT; + } + /* <= 0 means reduce or error. */ + else if ((yyn = yytable_[yyn]) <= 0) + { + if (yyTableValueIsError(yyn)) + label = YYERRLAB;]b4_lac_if([[ + else if (!yylacEstablish(yystack, yytoken)) + label = YYERRLAB;]])[ + else + { + yyn = -yyn; + label = YYREDUCE; + } + } + else + { + /* Shift the lookahead token. */]b4_parse_trace_if([[ + yy_symbol_print ("Shifting", yytoken, yylval]b4_locations_if([, yylloc])[);]])[ + + /* Discard the token being shifted. */ + yytoken = ]b4_symbol(empty, kind)[; + + /* Count tokens shifted since error; after three, turn off error + * status. */ + if (yyerrstatus_ > 0) + --yyerrstatus_; + + yystate = yyn; + yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);]b4_lac_if([[ + yylacDiscard("shift");]])[ + label = YYNEWSTATE; + } + } + break; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + case YYDEFAULT: + yyn = yydefact_[yystate]; + if (yyn == 0) + label = YYERRLAB; + else + label = YYREDUCE; + break; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + case YYREDUCE: + yylen = yyr2_[yyn]; + label = yyaction (yyn, yystack, yylen); + yystate = yystack.stateAt (0); + break; + + /*--------------------------------------. + | yyerrlab -- here on detecting error. | + `--------------------------------------*/ + case YYERRLAB: + /* If not already recovering from an error, report this error. */ + if (yyerrstatus_ == 0) + { + ++yynerrs_; + yyreportSyntaxError(new Context(]b4_lac_if([[this, ]])[yystack, yytoken]b4_locations_if([[, yylloc]])[)); + } +]b4_locations_if([ + yyerrloc = yylloc;])[ + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + * error, discard it. */ + + /* Return failure if at end of input. */ + if (yytoken == ]b4_symbol(eof, [kind])[)]b4_push_if([[ + { + label = YYABORT; + break; + }]], [[ + return false;]])[ + else + yytoken = ]b4_symbol(empty, kind)[; + } + + /* Else will try to reuse lookahead token after shifting the error + * token. */ + label = YYERRLAB1; + break; + + /*-------------------------------------------------. + | errorlab -- error raised explicitly by YYERROR. | + `-------------------------------------------------*/ + case YYERROR:]b4_locations_if([ + yyerrloc = yystack.locationAt (yylen - 1);])[ + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + yystack.pop (yylen); + yylen = 0; + yystate = yystack.stateAt (0); + label = YYERRLAB1; + break; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + case YYERRLAB1: + yyerrstatus_ = 3; /* Each real token shifted decrements this. */ + + // Pop stack until we find a state that shifts the error token. + for (;;) + { + yyn = yypact_[yystate]; + if (!yyPactValueIsDefault(yyn)) + { + yyn += ]b4_symbol(error, kind)[; + if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == ]b4_symbol(error, kind)[) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yystack.height == 1)]b4_push_if([[ + { + label = YYABORT; + break; + }]],[[ + return false;]])[ + +]b4_locations_if([ yyerrloc = yystack.locationAt (0);])[ + yystack.pop (); + yystate = yystack.stateAt (0);]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + }]b4_push_if([[ + if (label == YYABORT) + /* Leave the switch. */ + break; +]])[ +]b4_locations_if([ + /* Muck with the stack to setup for yylloc. */ + yystack.push (0, yy_semantic_null, yylloc); + yystack.push (0, yy_semantic_null, yyerrloc); + yyloc = yylloc_from_stack (yystack, 2); + yystack.pop (2);])[ + + /* Shift the error token. */]b4_lac_if([[ + yylacDiscard("error recovery");]])[]b4_parse_trace_if([[ + yy_symbol_print ("Shifting", to!SymbolKind (yystos_[yyn]), yylval]b4_locations_if([, yyloc])[);]])[ + yystate = yyn; + yystack.push (yyn, yylval]b4_locations_if([, yyloc])[); + label = YYNEWSTATE; + break; + + /* Accept. */ + case YYACCEPT:]b4_push_if([[ + this.pushParseInitialized = false;]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + return YYACCEPT;]], [[ + yyresult = true; + label = YYRETURN; + break;]])[ + + /* Abort. */ + case YYABORT:]b4_push_if([[ + this.pushParseInitialized = false;]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + return YYABORT;]], [[ + yyresult = false; + label = YYRETURN; + break;]])[ +]b4_push_if([[]], [[ ][case YYRETURN:]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + return yyresult;]])[ + } + assert(0); + } + +]b4_push_if([[ + bool pushParseInitialized = false; + + /** + * (Re-)Initialize the state of the push parser. + */ + public void pushParseInitialize() + { + + /* Lookahead and lookahead in internal form. */ + this.yytoken = ]b4_symbol(empty, kind)[; + + /* State. */ + this.yyn = 0; + this.yylen = 0; + this.yystate = 0; + destroy(this.yystack); + this.label = YYNEWSTATE; +]b4_lac_if([[ + destroy(this.yylacStack); + this.yylacEstablished = false;]])[ + + /* Error handling. */ + this.yynerrs_ = 0; +]b4_locations_if([ + /* The location where the error started. */ + this.yyerrloc = Location(Position(), Position()); + this.yylloc = Location(Position(), Position());])[ + + /* Semantic value of the lookahead. */ + //destroy(this.yylval); + + /* Initialize the stack. */ + yystack.push(this.yystate, this.yylval]b4_locations_if([, this.yylloc])[); + + this.pushParseInitialized = true; + }]])[]b4_both_if([[ + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * This version of parse() is defined only when api.push-push=both. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + bool parse() + { + int status = 0; + do { + status = this.pushParse(yylex()); + } while (status == YYPUSH_MORE); + return status == YYACCEPT; + }]])[ + + // Generate an error message. + private final void yyreportSyntaxError(Context yyctx) + {]b4_parse_error_bmatch( +[custom], [[ + yylexer.reportSyntaxError(yyctx);]], +[detailed], [[ + if (yyctx.getToken() != ]b4_symbol(empty, kind)[) + { + // FIXME: This method of building the message is not compatible + // with internationalization. + immutable int argmax = 5; + SymbolKind[] yyarg = new SymbolKind[argmax]; + int yycount = yysyntaxErrorArguments(yyctx, yyarg, argmax); + string res, yyformat; + switch (yycount) + { + case 1: + yyformat = YY_("syntax error, unexpected %s"); + res = format(yyformat, yyarg[0]); + break; + case 2: + yyformat = YY_("syntax error, unexpected %s, expecting %s"); + res = format(yyformat, yyarg[0], yyarg[1]); + break; + case 3: + yyformat = YY_("syntax error, unexpected %s, expecting %s or %s"); + res = format(yyformat, yyarg[0], yyarg[1], yyarg[2]); + break; + case 4: + yyformat = YY_("syntax error, unexpected %s, expecting %s or %s or %s"); + res = format(yyformat, yyarg[0], yyarg[1], yyarg[2], yyarg[3]); + break; + case 5: + yyformat = YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); + res = format(yyformat, yyarg[0], yyarg[1], yyarg[2], yyarg[3], yyarg[4]); + break; + default: + res = YY_("syntax error"); + break; + } + yyerror(]b4_locations_if([yyctx.getLocation(), ])[res); + }]], +[[simple]], [[ + yyerror(]b4_locations_if([yyctx.getLocation(), ])[YY_("syntax error"));]])[ + } + +]b4_parse_error_bmatch( +[detailed], [[ + private int yysyntaxErrorArguments(Context yyctx, SymbolKind[] yyarg, int yyargn) { + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, + then the only way this function was invoked is if the + default action is an error action. In that case, don't + check for expected tokens because there are none. + - The only way there can be no lookahead present (in tok) is + if this state is a consistent state with a default action. + Thus, detecting the absence of a lookahead is sufficient to + determine that there is no unexpected or expected token to + report. In that case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this + state is a consistent state with a default action. There + might have been a previous inconsistent state, consistent + state with a non-default action, or user semantic action + that manipulated yychar. (However, yychar is currently out + of scope during semantic actions.) + - Of course, the expected token list depends on states to + have correct lookahead information, and it depends on the + parser not to perform extra reductions after fetching a + lookahead from the scanner and before detecting a syntax + error. Thus, state merging (from LALR or IELR) and default + reductions corrupt the expected token list. However, the + list is correct for canonical LR with one exception: it + will still contain any token that will not be accepted due + to an error action in a later state. + */ + int yycount = 0; + if (yyctx.getToken() != ]b4_symbol(empty, kind)[) + { + if (yyarg !is null) + yyarg[yycount] = yyctx.getToken(); + yycount += 1; + yycount += yyctx.getExpectedTokens(yyarg, 1, yyargn); + } + return yycount; + } +]])[ + + + /** + * Information needed to get the list of expected tokens and to forge + * a syntax error diagnostic. + */ + public static final class Context + {]b4_lac_if([[ + private ]b4_parser_class[ yyparser;]])[ + private const(YYStack) yystack; + private SymbolKind yytoken;]b4_locations_if([[ + private const(Location) yylocation;]])[ + + this(]b4_lac_if([[]b4_parser_class[ parser, ]])[YYStack stack, SymbolKind kind]b4_locations_if([[, Location loc]])[) + {]b4_lac_if([[ + yyparser = parser;]])[ + yystack = stack; + yytoken = kind;]b4_locations_if([[ + yylocation = loc;]])[ + } + + final SymbolKind getToken() const + { + return yytoken; + }]b4_locations_if([[ + + final const(Location) getLocation() const + { + return yylocation; + }]])[ + /** + * Put in YYARG at most YYARGN of the expected tokens given the + * current YYCTX, and return the number of tokens stored in YYARG. If + * YYARG is null, return the number of expected tokens (guaranteed to + * be less than YYNTOKENS). + */ + int getExpectedTokens(SymbolKind[] yyarg, int yyargn)]b4_lac_if([[]], [[ const]])[ + { + return getExpectedTokens(yyarg, 0, yyargn); + } + + int getExpectedTokens(SymbolKind[] yyarg, int yyoffset, int yyargn)]b4_lac_if([[]], [[ const]])[ + { + int yycount = yyoffset;]b4_lac_if([b4_parse_trace_if([[ + // Execute LAC once. We don't care if it is successful, we + // only do it for the sake of debugging output. + + if (!yyparser.yylacEstablished) + yyparser.yylacCheck(yystack, yytoken); +]])[ + for (int yyx = 0; yyx < yyntokens_; ++yyx) + { + SymbolKind yysym = SymbolKind(yyx); + if (yysym != ]b4_symbol(error, kind)[ + && yysym != ]b4_symbol(undef, kind)[ + && yyparser.yylacCheck(yystack, yysym)) + { + if (yyarg == null) + yycount += 1; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], [[ + int yyn = yypact_[this.yystack.stateAt(0)]; + if (!yyPactValueIsDefault(yyn)) + { + /* Start YYX at -YYN if negative to avoid negative + indexes in YYCHECK. In other words, skip the first + -YYN actions for this state because they are default + actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yyTableValueIsError(yytable_[yyx + yyn])) + { + if (yyarg is null) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = SymbolKind(yyx); + } + }]])[ + if (yyarg !is null && yycount == yyoffset && yyoffset < yyargn) + yyarg[yyoffset] = ]b4_symbol(empty, kind)[; + return yycount - yyoffset; + } + } + +]b4_lac_if([[ + /** Check the lookahead yytoken. + * \returns true iff the token will be eventually shifted. + */ + bool yylacCheck(const YYStack yystack, SymbolKind yytoken) + { + // Logically, the yylacStack's lifetime is confined to this function. + // Clear it, to get rid of potential left-overs from previous call. + destroy(yylacStack); + // Reduce until we encounter a shift and thereby accept the token. +]b4_parse_trace_if([[ + yycdebug("LAC: checking lookahead " ~ format("%s", yytoken) ~ ":");]])[ + int lacTop = 0; + while (true) + { + int topState = (yylacStack.length == 0 + ? yystack.stateAt(lacTop) + : yylacStack[$ - 1]); + int yyrule = yypact_[topState]; + if (yyPactValueIsDefault(yyrule) + || (yyrule += yytoken) < 0 || yylast_ < yyrule + || yycheck_[yyrule] != yytoken) + { + // Use the default action. + yyrule = yydefact_[+topState]; + if (yyrule == 0) + {]b4_parse_trace_if([[ + yycdebugln(" Err");]])[ + return false; + } + } + else + { + // Use the action from yytable. + yyrule = yytable_[yyrule]; + if (yyTableValueIsError(yyrule)) + {]b4_parse_trace_if([[ + yycdebugln(" Err");]])[ + return false; + } + if (0 < yyrule) + {]b4_parse_trace_if([[ + yycdebugln(" S" ~ to!string(yyrule));]])[ + return true; + } + yyrule = -yyrule; + } + // By now we know we have to simulate a reduce. +]b4_parse_trace_if([[ + yycdebug(" R" ~ to!string(yyrule - 1));]])[ + // Pop the corresponding number of values from the stack. + { + int yylen = yyr2_[yyrule]; + // First pop from the LAC stack as many tokens as possible. + int lacSize = cast (int) yylacStack.length; + if (yylen < lacSize) + { + yylacStack.length -= yylen; + yylen = 0; + } + else if (lacSize != 0) + { + destroy(yylacStack); + yylen -= lacSize; + } + // Only afterwards look at the main stack. + // We simulate popping elements by incrementing lacTop. + lacTop += yylen; + } + // Keep topState in sync with the updated stack. + topState = (yylacStack.length == 0 + ? yystack.stateAt(lacTop) + : yylacStack[$ - 1]); + // Push the resulting state of the reduction. + int state = yyLRGotoState(topState, yyr1_[yyrule]);]b4_parse_trace_if([[ + yycdebug(" G" ~ to!string(state));]])[ + yylacStack.length++; + yylacStack[$ - 1] = state; + } + } + + /** Establish the initial context if no initial context currently exists. + * \returns true iff the token will be eventually shifted. + */ + bool yylacEstablish(YYStack yystack, SymbolKind yytoken) + { + /* Establish the initial context for the current lookahead if no initial + context is currently established. + + We define a context as a snapshot of the parser stacks. We define + the initial context for a lookahead as the context in which the + parser initially examines that lookahead in order to select a + syntactic action. Thus, if the lookahead eventually proves + syntactically unacceptable (possibly in a later context reached via a + series of reductions), the initial context can be used to determine + the exact set of tokens that would be syntactically acceptable in the + lookahead's place. Moreover, it is the context after which any + further semantic actions would be erroneous because they would be + determined by a syntactically unacceptable token. + + yylacEstablish should be invoked when a reduction is about to be + performed in an inconsistent state (which, for the purposes of LAC, + includes consistent states that don't know they're consistent because + their default reductions have been disabled). + + For parse.lac=full, the implementation of yylacEstablish is as + follows. If no initial context is currently established for the + current lookahead, then check if that lookahead can eventually be + shifted if syntactic actions continue from the current context. */ + if (yylacEstablished) + return true; + else + {]b4_parse_trace_if([[ + yycdebugln("LAC: initial context established for " ~ format("%s", yytoken));]])[ + yylacEstablished = true; + return yylacCheck(yystack, yytoken); + } + } + + /** Discard any previous initial lookahead context because of event. + * \param event the event which caused the lookahead to be discarded. + * Only used for debbuging output. */ + void yylacDiscard(string event) + { + /* Discard any previous initial lookahead context because of Event, + which may be a lookahead change or an invalidation of the currently + established initial context for the current lookahead. + + The most common example of a lookahead change is a shift. An example + of both cases is syntax error recovery. That is, a syntax error + occurs when the lookahead is syntactically erroneous for the + currently established initial context, so error recovery manipulates + the parser stacks to try to find a new initial context in which the + current lookahead is syntactically acceptable. If it fails to find + such a context, it discards the lookahead. */ + if (yylacEstablished) + {]b4_parse_trace_if([[ + yycdebugln("LAC: initial context discarded due to " ~ event);]])[ + yylacEstablished = false; + } + } + + /** The stack for LAC. + * Logically, the yylacStack's lifetime is confined to the function + * yylacCheck. We just store it as a member of this class to hold + * on to the memory and to avoid frequent reallocations. + */ + int[] yylacStack; + /** Whether an initial LAC context was established. */ + bool yylacEstablished; +]])[ + + /** + * Whether the given yypact_ value indicates a defaulted state. + * @@param yyvalue the value to check + */ + private static bool yyPactValueIsDefault(int yyvalue) + { + return yyvalue == yypact_ninf_; + } + + /** + * Whether the given yytable_ value indicates a syntax error. + * @@param yyvalue the value to check + */ + private static bool yyTableValueIsError(int yyvalue) + { + return yyvalue == yytable_ninf_; + } + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ + private static immutable ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[; + + /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If YYTABLE_NINF_, syntax error. */ + private static immutable ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[; + + ]b4_parser_tables_define[ + +]b4_parse_trace_if([[ + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + private static immutable ]b4_int_type_for([b4_rline])[[] yyrline_ = + @{ + ]b4_rline[ + @}; + + // Report on the debug stream that the rule yyrule is going to be reduced. + private final void yy_reduce_print (int yyrule, ref YYStack yystack) + { + if (yydebug == 0) + return; + + int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + /* Print the symbols being reduced, and their result. */ + yycdebugln (format("Reducing stack by rule %d (line %d):", + yyrule - 1, yylno)); + + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + yy_symbol_print (format(" $%d =", yyi + 1), + to!SymbolKind (yystos_[yystack.stateAt(yynrhs - (yyi + 1))]), + ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([, + b4_rhs_location(yynrhs, yyi + 1)])[); + } +]])[ + + private static auto yytranslate_ (int t) + { +]b4_api_token_raw_if( +[[ return SymbolKind(t);]], +[[ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ + immutable ]b4_int_type_for([b4_translate])[[] translate_table = + @{ + ]b4_translate[ + @}; + + // Last valid token kind. + immutable int code_max = ]b4_code_max[; + + if (t <= 0) + return ]b4_symbol(eof, kind)[; + else if (t <= code_max) + return SymbolKind(translate_table[t]); + else + return ]b4_symbol(undef, kind)[;]])[ + } + + private static immutable int yylast_ = ]b4_last[; + private static immutable int yynnts_ = ]b4_nterms_number[; + private static immutable int yyfinal_ = ]b4_final_state_number[; + private static immutable int yyntokens_ = ]b4_tokens_number[; + + private final struct YYStackElement { + int state; + Value value;]b4_locations_if( + b4_location_type[[] location;])[ + } + + private final struct YYStack { + private YYStackElement[] stack = []; + + public final ulong height() + { + return stack.length; + } + + public final void push (int state, Value value]dnl + b4_locations_if([, ref Location loc])[) + { + stack ~= YYStackElement(state, value]b4_locations_if([, loc])[); + } + + public final void pop () + { + pop (1); + } + + public final void pop (int num) + { + stack.length -= num; + } + + public final int stateAt (int i) const + { + return stack[$-i-1].state; + } + +]b4_locations_if([[ + public final ref Location locationAt (int i) + { + return stack[$-i-1].location; + }]])[ + + public final ref Value valueAt (int i) + { + return stack[$-i-1].value; + } +]b4_parse_trace_if([[ + // Print the state stack on the debug stream. + public final void print (File stream) + { + stream.write ("Stack now"); + for (int i = 0; i < stack.length; i++) + stream.write (" ", stack[i].state); + stream.writeln (); + }]])[ + } +]b4_percent_code_get[ +} +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/tools/flex-bison/third_party/skeletons/lalr1.java b/tools/flex-bison/third_party/skeletons/lalr1.java new file mode 100644 index 000000000..a01f90fa5 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/lalr1.java @@ -0,0 +1,1326 @@ +#Java skeleton for Bison - *-java - *- + +#Copyright(C) 2007 - 2015, 2018 - 2021 Free Software Foundation, Inc. + +#This program is free software : you can redistribute it and / or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program.If not, see < https: // www.gnu.org/licenses/>. + +m4_include(b4_skeletonsdir/[java.m4]) + +b4_header_if([b4_complain([%header/%defines does not make sense in Java])]) + +m4_define([b4_symbol_no_destructor_assert], +[b4_symbol_if([$1], [has_destructor], + [b4_complain_at(m4_unquote(b4_symbol([$1], [destructor_loc])), + [%destructor does not make sense in Java])])]) +b4_symbol_foreach([b4_symbol_no_destructor_assert]) + +## --------------- ## +## api.push-pull. ## +## --------------- ## + +b4_percent_define_default([[api.push-pull]], [[pull]]) +b4_percent_define_check_values([[[[api.push-pull]], + [[pull]], [[push]], [[both]]]]) + +#Define m4 conditional macros that encode the value +#of the api.push - pull flag. +b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]]) +b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]]) +m4_case(b4_percent_define_get([[api.push-pull]]), + [pull], [m4_define([b4_push_flag], [[0]])], + [push], [m4_define([b4_pull_flag], [[0]])]) + +#Define a macro to be true when api.push - pull has the value "both". +m4_define([b4_both_if],[b4_push_if([b4_pull_if([$1],[$2])],[$2])]) + +#Handle BISON_USE_PUSH_FOR_PULL for the test suite.So that push parsing +#tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the +#behavior of Bison at all when push parsing is already requested. +b4_define_flag_if([use_push_for_pull]) +b4_use_push_for_pull_if([ + b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], + [m4_define([b4_push_flag], [[1]])])]) + +#Define a macro to encapsulate the parse state variables.This +#allows them to be defined either in parse() when doing pull parsing, +#or as class instance variable when doing push parsing. +m4_define([b4_define_state], +[[ + /* Lookahead token kind. */ + int yychar = YYEMPTY_; + /* Lookahead symbol kind. */ + SymbolKind yytoken = null; + + /* State. */ + int yyn = 0; + int yylen = 0; + int yystate = 0; + YYStack yystack = new YYStack (); + int label = YYNEWSTATE; + +]b4_locations_if([[ + /* The location where the error started. */ + ]b4_location_type[ yyerrloc = null; + + /* Location. */ + ]b4_location_type[ yylloc = new ]b4_location_type[ (null, null);]])[ + + /* Semantic value of the lookahead. */ + ]b4_yystype[ yylval = null; +]]) + +#parse.lac +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + + +## ------------- ## +## Parser File. ## +## ------------- ## + +b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java], + [2007-2015, 2018-2021])[ +]b4_disclaimer[ +]b4_percent_define_ifdef([api.package], [package b4_percent_define_get([api.package]);[ +]])[ +]b4_user_pre_prologue[ +]b4_user_post_prologue[ +import java.text.MessageFormat; +import java.util.ArrayList; +]b4_percent_code_get([[imports]])[ +/** + * A Bison parser, automatically generated from ]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[. + * + * @@author LALR (1) parser skeleton written by Paolo Bonzini. + */ +]b4_parser_class_declaration[ +{ +]b4_identification[ +][ +]b4_parse_error_bmatch( + [detailed\|verbose], [[ + /** + * True if verbose error messages are enabled. + */ + private boolean yyErrorVerbose = true; + + /** + * Whether verbose error messages are enabled. + */ + public final boolean getErrorVerbose() { + return yyErrorVerbose; } + + /** + * Set the verbosity of error messages. + * @@param verbose True to request verbose error messages. + */ + public final void setErrorVerbose(boolean verbose) + { + yyErrorVerbose = verbose; } +]])[ + +]b4_locations_if([[ + /** + * A class defining a pair of positions. Positions, defined by the + * ]b4_position_type[ class, denote a point in the input. + * Locations represent a part of the input through the beginning + * and ending positions. + */ + public static class ]b4_location_type[ { + /** + * The first, inclusive, position in the range. + */ + public ]b4_position_type[ begin; + + /** + * The first position beyond the range. + */ + public ]b4_position_type[ end; + + /** + * Create a ]b4_location_type[ denoting an empty range located at + * a given point. + * @@param loc The position at which the range is anchored. + */ + public ]b4_location_type[ (]b4_position_type[ loc) { + this.begin = this.end = loc; + } + + /** + * Create a ]b4_location_type[ from the endpoints of the range. + * @@param begin The first position included in the range. + * @@param end The first position beyond the range. + */ + public ]b4_location_type[ (]b4_position_type[ begin, ]b4_position_type[ end) { + this.begin = begin; + this.end = end; + } + + /** + * Print a representation of the location. For this to be correct, + * ]b4_position_type[ should override the equals + * method. + */ + public String toString() { + if (begin.equals(end)) + return begin.toString(); + else + return begin.toString() + "-" + end.toString(); + } + } + + private ]b4_location_type[ yylloc(YYStack rhs, int n) + { + if (0 < n) + return new ]b4_location_type[(rhs.locationAt(n-1).begin, rhs.locationAt(0).end); + else + return new ]b4_location_type[(rhs.locationAt(0).end); + }]])[ + +]b4_declare_symbol_enum[ + + /** + * Communication interface between the scanner and the Bison-generated + * parser ]b4_parser_class[. + */ + public interface Lexer { +]b4_token_enums[ + /** Deprecated, use ]b4_symbol(eof, id)[ instead. */ + public static final int EOF = ]b4_symbol(eof, id)[; +]b4_pull_if([b4_locations_if([[ + /** + * Method to retrieve the beginning position of the last scanned token. + * @@return the position at which the last scanned token starts. + */ + ]b4_position_type[ getStartPos(); + + /** + * Method to retrieve the ending position of the last scanned token. + * @@return the first position beyond the last scanned token. + */ + ]b4_position_type[ getEndPos();]])[ + + /** + * Method to retrieve the semantic value of the last scanned token. + * @@return the semantic value of the last scanned token. + */ + ]b4_yystype[ getLVal(); + + /** + * Entry point for the scanner. Returns the token identifier corresponding + * to the next token and prepares to return the semantic value + * ]b4_locations_if([and beginning/ending positions ])[of the token. + * @@return the token identifier corresponding to the next token. + */ + int yylex()]b4_maybe_throws([b4_lex_throws])[; +]])[ + /** + * Emit an error]b4_locations_if([ referring to the given location])[in a user-defined way. + * + *]b4_locations_if([[ @@param loc The location of the element to which the + * error message is related.]])[ + * @@param msg The string for the error message. + */ + void yyerror(]b4_locations_if([b4_location_type[ loc, ]])[String msg); + +]b4_parse_error_bmatch( + [custom], [[ + /** + * Build and emit a "syntax error" message in a user-defined way. + * + * @@param ctx The context of the error. + */ + void reportSyntaxError(Context ctx); +]])[ + } + +]b4_lexer_if([[ + private class YYLexer implements Lexer { +]b4_percent_code_get([[lexer]])[ + } + +]])[ + /** + * The object doing lexical analysis for us. + */ + private Lexer yylexer; + +]b4_parse_param_vars[ + +]b4_lexer_if([[ + /** + * Instantiates the Bison-generated parser. + */ + public ]b4_parser_class[(]b4_parse_param_decl([b4_lex_param_decl])[)]b4_maybe_throws([b4_init_throws])[ + { +]b4_percent_code_get([[init]])[]b4_lac_if([[ + this.yylacStack = new ArrayList(); + this.yylacEstablished = false;]])[ + this.yylexer = new YYLexer(]b4_lex_param_call[); +]b4_parse_param_cons[ + } +]])[ + + /** + * Instantiates the Bison-generated parser. + * @@param yylexer The scanner that will supply tokens to the parser. + */ + ]b4_lexer_if([[protected]], [[public]]) b4_parser_class[(]b4_parse_param_decl([[Lexer yylexer]])[)]b4_maybe_throws([b4_init_throws])[ + { +]b4_percent_code_get([[init]])[]b4_lac_if([[ + this.yylacStack = new ArrayList(); + this.yylacEstablished = false;]])[ + this.yylexer = yylexer; +]b4_parse_param_cons[ + } + +]b4_parse_trace_if([[ + private java.io.PrintStream yyDebugStream = System.err; + + /** + * The PrintStream on which the debugging output is printed. + */ + public final java.io.PrintStream getDebugStream() { + return yyDebugStream; } + + /** + * Set the PrintStream on which the debug output is printed. + * @@param s The stream that is used for debugging output. + */ + public final void setDebugStream(java.io.PrintStream s) { + yyDebugStream = s; } + + private int yydebug = 0; + + /** + * Answer the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + */ + public final int getDebugLevel() { + return yydebug; } + + /** + * Set the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + * @@param level The verbosity level for debugging output. + */ + public final void setDebugLevel(int level) { + yydebug = level; } +]])[ + + private int yynerrs = 0; + + /** + * The number of syntax errors so far. + */ + public final int getNumberOfErrors() { + return yynerrs; } + + /** + * Print an error message via the lexer. + *]b4_locations_if([[ Use a null location.]])[ + * @@param msg The error message. + */ + public final void yyerror(String msg) { + yylexer.yyerror(]b4_locations_if([[(]b4_location_type[)null, ]])[msg); + } +]b4_locations_if([[ + /** + * Print an error message via the lexer. + * @@param loc The location associated with the message. + * @@param msg The error message. + */ + public final void yyerror(]b4_location_type[ loc, String msg) { + yylexer.yyerror(loc, msg); + } + + /** + * Print an error message via the lexer. + * @@param pos The position associated with the message. + * @@param msg The error message. + */ + public final void yyerror(]b4_position_type[ pos, String msg) { + yylexer.yyerror(new ]b4_location_type[ (pos), msg); + }]])[ +]b4_parse_trace_if([[ + protected final void yycdebugNnl(String s) { + if (0 < yydebug) yyDebugStream.print(s); + } + + protected final void yycdebug(String s) { + if (0 < yydebug) yyDebugStream.println(s); + }]])[ + + private final class YYStack { + private int[] stateStack = new int[16];]b4_locations_if([[ + private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[ + private ]b4_yystype[[] valueStack = new ]b4_yystype[[16]; + + public int size = 16; + public int height = -1; + + public final void push(int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) { + height++; + if (size == height) + { + int[] newStateStack = new int[size * 2]; + System.arraycopy(stateStack, 0, newStateStack, 0, height); + stateStack = newStateStack;]b4_locations_if([[ + ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2]; + System.arraycopy(locStack, 0, newLocStack, 0, height); + locStack = newLocStack;]]) + + b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2]; + System.arraycopy(valueStack, 0, newValueStack, 0, height); + valueStack = newValueStack; + + size *= 2; + } + + stateStack[height] = state;]b4_locations_if([[ + locStack[height] = loc;]])[ + valueStack[height] = value; + } + + public final void pop() { + pop(1); + } + + public final void pop(int num) { + // Avoid memory leaks... garbage collection is a white lie! + if (0 < num) + { + java.util.Arrays.fill(valueStack, height - num + 1, height + 1, null);]b4_locations_if([[ + java.util.Arrays.fill(locStack, height - num + 1, height + 1, null);]])[ + } + height -= num; + } + + public final int stateAt(int i) { + return stateStack[height - i]; + } +]b4_locations_if([[ + + public final ]b4_location_type[ locationAt(int i) { + return locStack[height - i]; + } +]])[ + public final ]b4_yystype[ valueAt(int i) { + return valueStack[height - i]; + } + + // Print the state stack on the debug stream. + public void print(java.io.PrintStream out) { + out.print("Stack now"); + + for (int i = 0; i <= height; i++) + { + out.print(' '); + out.print(stateStack[i]); + } + out.println(); + } + } + + /** + * Returned by a Bison action in order to stop the parsing process and + * return success (true). + */ + public static final int YYACCEPT = 0; + + /** + * Returned by a Bison action in order to stop the parsing process and + * return failure (false). + */ + public static final int YYABORT = 1; + +]b4_push_if([ + /** + * Returned by a Bison action in order to request a new token. + */ + public static final int YYPUSH_MORE = 4;])[ + + /** + * Returned by a Bison action in order to start error recovery without + * printing an error message. + */ + public static final int YYERROR = 2; + + /** + * Internal return codes that are not supported for user semantic + * actions. + */ + private static final int YYERRLAB = 3; + private static final int YYNEWSTATE = 4; + private static final int YYDEFAULT = 5; + private static final int YYREDUCE = 6; + private static final int YYERRLAB1 = 7; + private static final int YYRETURN = 8; +]b4_push_if([[ private static final int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */]])[ + + private int yyerrstatus_ = 0; + +]b4_push_if([b4_define_state])[ + /** + * Whether error recovery is being done. In this state, the parser + * reads token until it reaches a known state, and then restarts normal + * operation. + */ + public final boolean recovering () + { + return yyerrstatus_ == 0; + } + + /** Compute post-reduction state. + * @@param yystate the current state + * @@param yysym the nonterminal to push on the stack + */ + private int yyLRGotoState(int yystate, int yysym) { + int yyr = yypgoto_[yysym - YYNTOKENS_] + yystate; + if (0 <= yyr && yyr <= YYLAST_ && yycheck_[yyr] == yystate) + return yytable_[yyr]; + else + return yydefgoto_[yysym - YYNTOKENS_]; + } + + private int yyaction(int yyn, YYStack yystack, int yylen)]b4_maybe_throws([b4_throws])[ + { + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. */ + ]b4_yystype[ yyval = (0 < yylen) ? yystack.valueAt(yylen - 1) : yystack.valueAt(0);]b4_locations_if([[ + ]b4_location_type[ yyloc = yylloc(yystack, yylen);]])[]b4_parse_trace_if([[ + + yyReducePrint(yyn, yystack);]])[ + + switch (yyn) + { + ]b4_user_actions[ + default: break; + }]b4_parse_trace_if([[ + + yySymbolPrint("-> $$ =", SymbolKind.get(yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[ + + yystack.pop(yylen); + yylen = 0; + /* Shift the result of the reduction. */ + int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]); + yystack.push(yystate, yyval]b4_locations_if([, yyloc])[); + return YYNEWSTATE; + } + +]b4_parse_trace_if([[ + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + private void yySymbolPrint(String s, SymbolKind yykind, + ]b4_yystype[ yyvalue]b4_locations_if([, ]b4_location_type[ yylocation])[) { + if (0 < yydebug) + { + yycdebug(s + + (yykind.getCode() < YYNTOKENS_ ? " token " : " nterm ") + + yykind.getName() + " ("]b4_locations_if([ + + yylocation + ": "])[ + + (yyvalue == null ? "(null)" : yyvalue.toString()) + ")"); + } + }]])[ + +]b4_push_if([],[[ + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[ +]b4_push_if([ + /** + * Push Parse input from external lexer + * + * @@param yylextoken current token + * @@param yylexval current lval]b4_locations_if([[ + * @@param yylexloc current position]])[ + * + * @@return YYACCEPT, YYABORT, YYPUSH_MORE + */ + public int push_parse(int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[ + {]b4_locations_if([[ + /* @@$. */ + ]b4_location_type[ yyloc;]])[ +]b4_push_if([],[[ +]b4_define_state[ +]b4_lac_if([[ + // Discard the LAC context in case there still is one left from a + // previous invocation. + yylacDiscard("init");]])[ +]b4_parse_trace_if([[ + yycdebug ("Starting parse");]])[ + yyerrstatus_ = 0; + yynerrs = 0; + + /* Initialize the stack. */ + yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl + b4_user_initial_action +b4_dollar_popdef[]dnl +])[ +]])[ +]b4_push_if([[ + if (!this.push_parse_initialized) + { + push_parse_initialize(); +]m4_ifdef([b4_initial_action], [ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl + b4_user_initial_action +b4_dollar_popdef[]dnl +])[]b4_parse_trace_if([[ + yycdebug ("Starting parse");]])[ + yyerrstatus_ = 0; + } else + label = YYGETTOKEN; + + boolean push_token_consumed = true; +]])[ + for (;;) + switch (label) + { + /* New state. Unlike in the C/C++ skeletons, the state is already + pushed when we come here. */ + case YYNEWSTATE:]b4_parse_trace_if([[ + yycdebug ("Entering state " + yystate); + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + + /* Accept? */ + if (yystate == YYFINAL_) + ]b4_push_if([{ + label = YYACCEPT; + break;}], + [return true;])[ + + /* Take a decision. First try without lookahead. */ + yyn = yypact_[yystate]; + if (yyPactValueIsDefault (yyn)) + { + label = YYDEFAULT; + break; + } +]b4_push_if([ /* Fall Through */ + + case YYGETTOKEN:])[ + /* Read a lookahead token. */ + if (yychar == YYEMPTY_) + { +]b4_push_if([[ + if (!push_token_consumed) + return YYPUSH_MORE;]b4_parse_trace_if([[ + yycdebug ("Reading a token");]])[ + yychar = yylextoken; + yylval = yylexval;]b4_locations_if([ + yylloc = yylexloc;])[ + push_token_consumed = false;]], [b4_parse_trace_if([[ + yycdebug ("Reading a token");]])[ + yychar = yylexer.yylex (); + yylval = yylexer.getLVal();]b4_locations_if([[ + yylloc = new ]b4_location_type[(yylexer.getStartPos(), + yylexer.getEndPos());]])[ +]])[ + } + + /* Convert token to internal form. */ + yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[ + yySymbolPrint("Next token is", yytoken, + yylval]b4_locations_if([, yylloc])[);]])[ + + if (yytoken == ]b4_symbol(error, kind)[) + { + // The scanner already issued an error message, process directly + // to error recovery. But do not keep the error token as + // lookahead, it is too special and may lead us to an endless + // loop in error recovery. */ + yychar = Lexer.]b4_symbol(undef, id)[; + yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[ + yyerrloc = yylloc;]])[ + label = YYERRLAB1; + } + else + { + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken.getCode(); + if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode()) + {]b4_lac_if([[ + if (!yylacEstablish(yystack, yytoken)) { + label = YYERRLAB; + } else]])[ + label = YYDEFAULT; + } + + /* <= 0 means reduce or error. */ + else if ((yyn = yytable_[yyn]) <= 0) + { + if (yyTableValueIsError(yyn)) + { + label = YYERRLAB; + }]b4_lac_if([[ else if (!yylacEstablish(yystack, yytoken)) { + label = YYERRLAB; + }]])[ else { + yyn = -yyn; + label = YYREDUCE; + } + } + + else + { + /* Shift the lookahead token. */]b4_parse_trace_if([[ + yySymbolPrint("Shifting", yytoken, + yylval]b4_locations_if([, yylloc])[); +]])[ + /* Discard the token being shifted. */ + yychar = YYEMPTY_; + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus_ > 0) + --yyerrstatus_; + + yystate = yyn; + yystack.push(yystate, yylval]b4_locations_if([, yylloc])[);]b4_lac_if([[ + yylacDiscard("shift");]])[ + label = YYNEWSTATE; + } + } + break; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + case YYDEFAULT: + yyn = yydefact_[yystate]; + if (yyn == 0) + label = YYERRLAB; + else + label = YYREDUCE; + break; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + case YYREDUCE: + yylen = yyr2_[yyn]; + label = yyaction(yyn, yystack, yylen); + yystate = yystack.stateAt(0); + break; + + /*------------------------------------. + | yyerrlab -- here on detecting error | + `------------------------------------*/ + case YYERRLAB: + /* If not already recovering from an error, report this error. */ + if (yyerrstatus_ == 0) + { + ++yynerrs; + if (yychar == YYEMPTY_) yytoken = null; + yyreportSyntaxError(new Context(this, yystack, yytoken]b4_locations_if([[, yylloc]])[)); + } +]b4_locations_if([[ + yyerrloc = yylloc;]])[ + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= Lexer.]b4_symbol(eof, id)[) + { + /* Return failure if at end of input. */ + if (yychar == Lexer.]b4_symbol(eof, id)[) + ]b4_push_if([{ + label = YYABORT; + break;}], [return false;])[ + } + else + yychar = YYEMPTY_; + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + label = YYERRLAB1; + break; + + /*-------------------------------------------------. + | errorlab -- error raised explicitly by YYERROR. | + `-------------------------------------------------*/ + case YYERROR:]b4_locations_if([[ + yyerrloc = yystack.locationAt (yylen - 1);]])[ + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + yystack.pop (yylen); + yylen = 0; + yystate = yystack.stateAt(0); + label = YYERRLAB1; + break; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + case YYERRLAB1: + yyerrstatus_ = 3; /* Each real token shifted decrements this. */ + + // Pop stack until we find a state that shifts the error token. + for (;;) + { + yyn = yypact_[yystate]; + if (!yyPactValueIsDefault(yyn)) + { + yyn += ]b4_symbol(error, kind)[.getCode(); + if (0 <= yyn && yyn <= YYLAST_ + && yycheck_[yyn] == ]b4_symbol(error, kind)[.getCode()) + { + yyn = yytable_[yyn]; + if (0 < yyn) break; + } + } + + /* Pop the current state because it cannot handle the + * error token. */ + if (yystack.height == 0) + ]b4_push_if([{ + label = YYABORT; + break;}],[return false;])[ + +]b4_locations_if([[ + yyerrloc = yystack.locationAt (0);]])[ + yystack.pop (); + yystate = yystack.stateAt(0);]b4_parse_trace_if([[ + if (0 < yydebug) + yystack.print (yyDebugStream);]])[ + } + + if (label == YYABORT) + /* Leave the switch. */ + break; + +]b4_locations_if([[ + /* Muck with the stack to setup for yylloc. */ + yystack.push (0, null, yylloc); + yystack.push (0, null, yyerrloc); + yyloc = yylloc (yystack, 2); + yystack.pop (2);]])[ + + /* Shift the error token. */]b4_lac_if([[ + yylacDiscard("error recovery");]])[]b4_parse_trace_if([[ + yySymbolPrint("Shifting", SymbolKind.get(yystos_[yyn]), + yylval]b4_locations_if([, yyloc])[);]])[ + + yystate = yyn; + yystack.push (yyn, yylval]b4_locations_if([, yyloc])[); + label = YYNEWSTATE; + break; + + /* Accept. */ + case YYACCEPT: + ]b4_push_if([this.push_parse_initialized = false; return YYACCEPT;], + [return true;])[ + + /* Abort. */ + case YYABORT: + ]b4_push_if([this.push_parse_initialized = false; return YYABORT;], + [return false;])[ + } +} +]b4_push_if([[ + boolean push_parse_initialized = false; + + /** + * (Re-)Initialize the state of the push parser. + */ + public void push_parse_initialize () + { + /* Lookahead and lookahead in internal form. */ + this.yychar = YYEMPTY_; + this.yytoken = null; + + /* State. */ + this.yyn = 0; + this.yylen = 0; + this.yystate = 0; + this.yystack = new YYStack();]b4_lac_if([[ + this.yylacStack = new ArrayList(); + this.yylacEstablished = false;]])[ + this.label = YYNEWSTATE; + + /* Error handling. */ + this.yynerrs = 0;]b4_locations_if([[ + /* The location where the error started. */ + this.yyerrloc = null; + this.yylloc = new ]b4_location_type[ (null, null);]])[ + + /* Semantic value of the lookahead. */ + this.yylval = null; + + yystack.push (this.yystate, this.yylval]b4_locations_if([, this.yylloc])[); + + this.push_parse_initialized = true; + + } +]b4_locations_if([[ + /** + * Push parse given input from an external lexer. + * + * @@param yylextoken current token + * @@param yylexval current lval + * @@param yyylexpos current position + * + * @@return YYACCEPT, YYABORT, YYPUSH_MORE + */ + public int push_parse(int yylextoken, ]b4_yystype[ yylexval, ]b4_position_type[ yylexpos)]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ { + return push_parse(yylextoken, yylexval, new ]b4_location_type[(yylexpos)); + } +]])])[ + +]b4_both_if([[ + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * This version of parse() is defined only when api.push-push=both. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + public boolean parse()]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[ { + if (yylexer == null) throw new NullPointerException("Null Lexer"); + int status; + do + { + int token = yylexer.yylex(); + ]b4_yystype[ lval = yylexer.getLVal();]b4_locations_if([[ + ]b4_location_type[ yyloc = new ]b4_location_type[(yylexer.getStartPos(), yylexer.getEndPos()); + status = push_parse(token, lval, yyloc);]], [[ + status = push_parse(token, lval);]])[ + } while (status == YYPUSH_MORE); + return status == YYACCEPT; + } +]])[ + + /** + * Information needed to get the list of expected tokens and to forge + * a syntax error diagnostic. + */ + public static final class Context { + Context(]b4_parser_class[ parser, YYStack stack, SymbolKind token]b4_locations_if([[, ]b4_location_type[ loc]])[) + { + yyparser = parser; + yystack = stack; + yytoken = token;]b4_locations_if([[ + yylocation = loc;]])[ + } + + private ]b4_parser_class[ yyparser; + private YYStack yystack; + + + /** + * The symbol kind of the lookahead token. + */ + public final SymbolKind getToken() { + return yytoken; + } + + private SymbolKind yytoken;]b4_locations_if([[ + + /** + * The location of the lookahead. + */ + public final ]b4_location_type[ getLocation() { + return yylocation; + } + + private ]b4_location_type[ yylocation;]])[ + static final int NTOKENS = ]b4_parser_class[.YYNTOKENS_; + + /** + * Put in YYARG at most YYARGN of the expected tokens given the + * current YYCTX, and return the number of tokens stored in YYARG. If + * YYARG is null, return the number of expected tokens (guaranteed to + * be less than YYNTOKENS). + */ + int getExpectedTokens(SymbolKind yyarg[], int yyargn) { + return getExpectedTokens(yyarg, 0, yyargn); + } + + int getExpectedTokens(SymbolKind yyarg[], int yyoffset, int yyargn) { + int yycount = yyoffset;]b4_lac_if([b4_parse_trace_if([[ + // Execute LAC once. We don't care if it is successful, we + // only do it for the sake of debugging output. + if (!yyparser.yylacEstablished) + yyparser.yylacCheck(yystack, yytoken); +]])[ + for (int yyx = 0; yyx < YYNTOKENS_; ++yyx) + { + SymbolKind yysym = SymbolKind.get(yyx); + if (yysym != ]b4_symbol(error, kind)[ + && yysym != ]b4_symbol(undef, kind)[ + && yyparser.yylacCheck(yystack, yysym)) + { + if (yyarg == null) + yycount += 1; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], [[ + int yyn = yypact_[this.yystack.stateAt(0)]; + if (!yyPactValueIsDefault(yyn)) + { + /* Start YYX at -YYN if negative to avoid negative + indexes in YYCHECK. In other words, skip the first + -YYN actions for this state because they are default + actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST_ - yyn + 1; + int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[.getCode() + && !yyTableValueIsError(yytable_[yyx + yyn])) + { + if (yyarg == null) + yycount += 1; + else if (yycount == yyargn) + return 0; // FIXME: this is incorrect. + else + yyarg[yycount++] = SymbolKind.get(yyx); + } + }]])[ + if (yyarg != null && yycount == yyoffset && yyoffset < yyargn) + yyarg[yycount] = null; + return yycount - yyoffset; + } + } + +]b4_lac_if([[ + /** Check the lookahead yytoken. + * \returns true iff the token will be eventually shifted. + */ + boolean yylacCheck(YYStack yystack, SymbolKind yytoken) + { + // Logically, the yylacStack's lifetime is confined to this function. + // Clear it, to get rid of potential left-overs from previous call. + yylacStack.clear(); + // Reduce until we encounter a shift and thereby accept the token. + yycdebugNnl("LAC: checking lookahead " + yytoken.getName() + ":"); + int lacTop = 0; + while (true) + { + int topState = (yylacStack.isEmpty() ? yystack.stateAt(lacTop) + : yylacStack.get(yylacStack.size() - 1)); + int yyrule = yypact_[topState]; + if (yyPactValueIsDefault(yyrule) || (yyrule += yytoken.getCode()) < 0 + || YYLAST_ < yyrule || yycheck_[yyrule] != yytoken.getCode()) + { + // Use the default action. + yyrule = yydefact_[+topState]; + if (yyrule == 0) + { + yycdebug(" Err"); + return false; + } + } + else + { + // Use the action from yytable. + yyrule = yytable_[yyrule]; + if (yyTableValueIsError(yyrule)) + { + yycdebug(" Err"); + return false; + } + if (0 < yyrule) + { + yycdebug(" S" + yyrule); + return true; + } + yyrule = -yyrule; + } + // By now we know we have to simulate a reduce. + yycdebugNnl(" R" + (yyrule - 1)); + // Pop the corresponding number of values from the stack. + { + int yylen = yyr2_[yyrule]; + // First pop from the LAC stack as many tokens as possible. + int lacSize = yylacStack.size(); + if (yylen < lacSize) + { + // yylacStack.setSize(lacSize - yylen); + for (/* Nothing */; 0 < yylen; yylen -= 1) + { + yylacStack.remove(yylacStack.size() - 1); + } + yylen = 0; + } + else if (lacSize != 0) + { + yylacStack.clear(); + yylen -= lacSize; + } + // Only afterwards look at the main stack. + // We simulate popping elements by incrementing lacTop. + lacTop += yylen; + } + // Keep topState in sync with the updated stack. + topState = (yylacStack.isEmpty() ? yystack.stateAt(lacTop) + : yylacStack.get(yylacStack.size() - 1)); + // Push the resulting state of the reduction. + int state = yyLRGotoState(topState, yyr1_[yyrule]); + yycdebugNnl(" G" + state); + yylacStack.add(state); + } + } + + /** Establish the initial context if no initial context currently exists. + * \returns true iff the token will be eventually shifted. + */ + boolean yylacEstablish(YYStack yystack, SymbolKind yytoken) { + /* Establish the initial context for the current lookahead if no initial + context is currently established. + + We define a context as a snapshot of the parser stacks. We define + the initial context for a lookahead as the context in which the + parser initially examines that lookahead in order to select a + syntactic action. Thus, if the lookahead eventually proves + syntactically unacceptable (possibly in a later context reached via a + series of reductions), the initial context can be used to determine + the exact set of tokens that would be syntactically acceptable in the + lookahead's place. Moreover, it is the context after which any + further semantic actions would be erroneous because they would be + determined by a syntactically unacceptable token. + + yylacEstablish should be invoked when a reduction is about to be + performed in an inconsistent state (which, for the purposes of LAC, + includes consistent states that don't know they're consistent because + their default reductions have been disabled). + + For parse.lac=full, the implementation of yylacEstablish is as + follows. If no initial context is currently established for the + current lookahead, then check if that lookahead can eventually be + shifted if syntactic actions continue from the current context. */ + if (yylacEstablished) + { + return true; + } + else + { + yycdebug("LAC: initial context established for " + yytoken.getName()); + yylacEstablished = true; + return yylacCheck(yystack, yytoken); + } + } + + /** Discard any previous initial lookahead context because of event. + * \param event the event which caused the lookahead to be discarded. + * Only used for debbuging output. */ + void yylacDiscard(String event) { + /* Discard any previous initial lookahead context because of Event, + which may be a lookahead change or an invalidation of the currently + established initial context for the current lookahead. + + The most common example of a lookahead change is a shift. An example + of both cases is syntax error recovery. That is, a syntax error + occurs when the lookahead is syntactically erroneous for the + currently established initial context, so error recovery manipulates + the parser stacks to try to find a new initial context in which the + current lookahead is syntactically acceptable. If it fails to find + such a context, it discards the lookahead. */ + if (yylacEstablished) + { + yycdebug("LAC: initial context discarded due to " + event); + yylacEstablished = false; + } + } + + /** The stack for LAC. + * Logically, the yylacStack's lifetime is confined to the function + * yylacCheck. We just store it as a member of this class to hold + * on to the memory and to avoid frequent reallocations. + */ + ArrayList yylacStack; + /** Whether an initial LAC context was established. */ + boolean yylacEstablished; +]])[ + +]b4_parse_error_bmatch( +[detailed\|verbose], [[ + private int yysyntaxErrorArguments(Context yyctx, SymbolKind[] yyarg, int yyargn) { + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, + then the only way this function was invoked is if the + default action is an error action. In that case, don't + check for expected tokens because there are none. + - The only way there can be no lookahead present (in tok) is + if this state is a consistent state with a default action. + Thus, detecting the absence of a lookahead is sufficient to + determine that there is no unexpected or expected token to + report. In that case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this + state is a consistent state with a default action. There + might have been a previous inconsistent state, consistent + state with a non-default action, or user semantic action + that manipulated yychar. (However, yychar is currently out + of scope during semantic actions.) + - Of course, the expected token list depends on states to + have correct lookahead information, and it depends on the + parser not to perform extra reductions after fetching a + lookahead from the scanner and before detecting a syntax + error. Thus, state merging (from LALR or IELR) and default + reductions corrupt the expected token list. However, the + list is correct for canonical LR with one exception: it + will still contain any token that will not be accepted due + to an error action in a later state. + */ + int yycount = 0; + if (yyctx.getToken() != null) + { + if (yyarg != null) yyarg[yycount] = yyctx.getToken(); + yycount += 1; + yycount += yyctx.getExpectedTokens(yyarg, 1, yyargn); + } + return yycount; + } +]])[ + + /** + * Build and emit a "syntax error" message in a user-defined way. + * + * @@param ctx The context of the error. + */ + private void yyreportSyntaxError(Context yyctx) {]b4_parse_error_bmatch( +[custom], [[ + yylexer.reportSyntaxError(yyctx);]], +[detailed\|verbose], [[ + if (yyErrorVerbose) { + final int argmax = 5; + SymbolKind[] yyarg = new SymbolKind[argmax]; + int yycount = yysyntaxErrorArguments(yyctx, yyarg, argmax); + String[] yystr = new String[yycount]; + for (int yyi = 0; yyi < yycount; ++yyi) + { + yystr[yyi] = yyarg[yyi].getName(); + } + String yyformat; + switch (yycount) + { + default: + case 0: yyformat = ]b4_trans(["syntax error"])[; break; + case 1: yyformat = ]b4_trans(["syntax error, unexpected {0}"])[; break; + case 2: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1}"])[; break; + case 3: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2}"])[; break; + case 4: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3}"])[; break; + case 5: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3} or {4}"])[; break; + } + yyerror(]b4_locations_if([[yyctx.yylocation, ]])[new MessageFormat(yyformat).format(yystr)); + } else { + yyerror(]b4_locations_if([[yyctx.yylocation, ]])[]b4_trans(["syntax error"])[); + }]], +[simple], [[ + yyerror(]b4_locations_if([[yyctx.yylocation, ]])[]b4_trans(["syntax error"])[);]])[ + } + + /** + * Whether the given yypact_ value indicates a defaulted state. + * @@param yyvalue the value to check + */ + private static boolean yyPactValueIsDefault(int yyvalue) { + return yyvalue == yypact_ninf_; + } + + /** + * Whether the given yytable_ + * value indicates a syntax error. + * @@param yyvalue the value to check + */ + private static boolean yyTableValueIsError(int yyvalue) { + return yyvalue == yytable_ninf_; + } + + private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[; + private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[; + +]b4_parser_tables_define[ + +]b4_parse_trace_if([[ + ]b4_integral_parser_table_define([rline], [b4_rline], + [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ + + + // Report on the debug stream that the rule yyrule is going to be reduced. + private void yyReducePrint (int yyrule, YYStack yystack) + { + if (yydebug == 0) return; + + int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + /* Print the symbols being reduced, and their result. */ + yycdebug("Reducing stack by rule " + (yyrule - 1) + " (line " + yylno + "):"); + + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + yySymbolPrint(" $" + (yyi + 1) + " =", + SymbolKind.get(yystos_[yystack.stateAt(yynrhs - (yyi + 1))]), + ]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([, + b4_rhs_location(yynrhs, yyi + 1)])[); + }]])[ + + /* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ + private static final SymbolKind yytranslate_(int t) +]b4_api_token_raw_if(dnl +[[ { + return SymbolKind.get(t); + } +]], +[[ { + // Last valid token kind. + int code_max = ]b4_code_max[; + if (t <= 0) + return ]b4_symbol(eof, kind)[; + else if (t <= code_max) + return SymbolKind.get(yytranslate_table_[t]); + else + return ]b4_symbol(undef, kind)[; + } + ]b4_integral_parser_table_define([translate_table], [b4_translate])[ +]])[ + + private static final int YYLAST_ = ]b4_last[; + private static final int YYEMPTY_ = -2; + private static final int YYFINAL_ = ]b4_final_state_number[; + private static final int YYNTOKENS_ = ]b4_tokens_number[; + +]b4_percent_code_get[ +} +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl +b4_output_end diff --git a/tools/flex-bison/third_party/skeletons/location.cc b/tools/flex-bison/third_party/skeletons/location.cc new file mode 100644 index 000000000..5337147c9 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/location.cc @@ -0,0 +1,371 @@ +#C++ skeleton for Bison + +#Copyright(C) 2002 - 2015, 2018 - 2021 Free Software Foundation, Inc. + +#This program is free software : you can redistribute it and / or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program.If not, see < https: // www.gnu.org/licenses/>. + +m4_pushdef([b4_copyright_years], + [2002-2015, 2018-2021]) + +#b4_location_file +#-- -- -- -- -- -- -- -- +#Name of the file containing the position / location class, +#if we want this file. +b4_percent_define_check_file([b4_location_file], + [[api.location.file]], + b4_header_if([[location.hh]])) + +# b4_location_include +# -- -- -- -- -- -- -- -- -- - +# If location.hh is to be generated, the name under which should it be +# included. +# +# b4_location_path +# -- -- -- -- -- -- -- -- +# The path to use for the CPP guard. +m4_ifdef([b4_location_file], +[m4_define([b4_location_include], + [b4_percent_define_get([[api.location.include]], + ["b4_location_file"])]) + m4_define([b4_location_path], + b4_percent_define_get([[api.location.include]], + ["b4_mapped_dir_prefix[]b4_location_file"])) + m4_define([b4_location_path], + m4_substr(m4_defn([b4_location_path]), 1, m4_eval(m4_len(m4_defn([b4_location_path])) - 2))) + ]) + +# b4_position_file +# -- -- -- -- -- -- -- -- +# Name of the file containing the position class, if we want this file. +b4_header_if( + [b4_required_version_if( + [30200], [], + [m4_ifdef([b4_location_file], + [m4_define([b4_position_file], [position.hh])])])]) + +# b4_location_define +# -- -- -- -- -- -- -- -- -- +# Define the position and location classes. +m4_define([b4_location_define], +[[ /// A point in a source file. + class position + { + public: + /// Type for file name. + typedef ]b4_percent_define_get([[api.filename.type]])[ filename_type; + /// Type for line and column numbers. + typedef int counter_type; +]m4_ifdef([b4_location_constructors], [[ + /// Construct a position. + explicit position (filename_type* f = YY_NULLPTR, + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) + : filename (f) + , line (l) + , column (c) + {} + +]])[ + /// Initialization. + void initialize (filename_type* fn = YY_NULLPTR, + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) + { + filename = fn; + line = l; + column = c; + } + + /** \name Line and Column related manipulators + ** \{ */ + /// (line related) Advance to the COUNT next lines. + void lines (counter_type count = 1) + { + if (count) + { + column = ]b4_location_initial_column[; + line = add_ (line, count, ]b4_location_initial_line[); + } + } + + /// (column related) Advance to the COUNT next columns. + void columns (counter_type count = 1) + { + column = add_ (column, count, ]b4_location_initial_column[); + } + /** \} */ + + /// File name to which this position refers. + filename_type* filename; + /// Current line number. + counter_type line; + /// Current column number. + counter_type column; + + private: + /// Compute max (min, lhs+rhs). + static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min) + { + return lhs + rhs < min ? min : lhs + rhs; + } + }; + + /// Add \a width columns, in place. + inline position& + operator+= (position& res, position::counter_type width) + { + res.columns(width); + return res; + } + + /// Add \a width columns. + inline position + operator+ (position res, position::counter_type width) + { + return res += width; + } + + /// Subtract \a width columns, in place. + inline position& + operator-= (position& res, position::counter_type width) + { + return res += -width; + } + + /// Subtract \a width columns. + inline position + operator- (position res, position::counter_type width) + { + return res -= width; + } +]b4_percent_define_flag_if([[define_location_comparison]], [[ + /// Compare two position objects. + inline bool + operator== (const position& pos1, const position& pos2) + { + return (pos1.line == pos2.line && pos1.column == pos2.column && + (pos1.filename == pos2.filename || + (pos1.filename && pos2.filename && *pos1.filename == *pos2.filename))); + } + + /// Compare two position objects. + inline bool + operator!= (const position& pos1, const position& pos2) + { + return !(pos1 == pos2); + } +]])[ + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param pos a reference to the position to redirect + */ + template + std::basic_ostream& + operator<< (std::basic_ostream& ostr, const position& pos) + { + if (pos.filename) + ostr << *pos.filename << ':'; + return ostr << pos.line << '.' << pos.column; + } + + /// Two points in a source file. + class location + { + public: + /// Type for file name. + typedef position::filename_type filename_type; + /// Type for line and column numbers. + typedef position::counter_type counter_type; +]m4_ifdef([b4_location_constructors], [ + /// Construct a location from \a b to \a e. + location (const position& b, const position& e) + : begin (b) + , end (e) + {} + + /// Construct a 0-width location in \a p. + explicit location (const position& p = position ()) + : begin (p) + , end (p) + {} + + /// Construct a 0-width location in \a f, \a l, \a c. + explicit location (filename_type* f, + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) + : begin (f, l, c) + , end (f, l, c) + {} + +])[ + /// Initialization. + void initialize (filename_type* f = YY_NULLPTR, + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) + { + begin.initialize(f, l, c); + end = begin; + } + + /** \name Line and Column related manipulators + ** \{ */ + public: + /// Reset initial location to final location. + void step () + { + begin = end; + } + + /// Extend the current location to the COUNT next columns. + void columns (counter_type count = 1) + { + end += count; + } + + /// Extend the current location to the COUNT next lines. + void lines (counter_type count = 1) + { + end.lines(count); + } + /** \} */ + + + public: + /// Beginning of the located region. + position begin; + /// End of the located region. + position end; + }; + + /// Join two locations, in place. + inline location& + operator+= (location& res, const location& end) + { + res.end = end.end; + return res; + } + + /// Join two locations. + inline location + operator+ (location res, const location& end) + { + return res += end; + } + + /// Add \a width columns to the end position, in place. + inline location& + operator+= (location& res, location::counter_type width) + { + res.columns(width); + return res; + } + + /// Add \a width columns to the end position. + inline location + operator+ (location res, location::counter_type width) + { + return res += width; + } + + /// Subtract \a width columns to the end position, in place. + inline location& + operator-= (location& res, location::counter_type width) + { + return res += -width; + } + + /// Subtract \a width columns to the end position. + inline location + operator- (location res, location::counter_type width) + { + return res -= width; + } +]b4_percent_define_flag_if([[define_location_comparison]], [[ + /// Compare two location objects. + inline bool + operator== (const location& loc1, const location& loc2) + { + return loc1.begin == loc2.begin && loc1.end == loc2.end; + } + + /// Compare two location objects. + inline bool + operator!= (const location& loc1, const location& loc2) + { + return !(loc1 == loc2); + } +]])[ + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param loc a reference to the location to redirect + ** + ** Avoid duplicate information. + */ + template + std::basic_ostream& + operator<< (std::basic_ostream& ostr, const location& loc) + { + location::counter_type end_col = 0 < loc.end.column ? loc.end.column - 1 : 0; + ostr << loc.begin; + if (loc.end.filename && (!loc.begin.filename || *loc.begin.filename != *loc.end.filename)) + ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col; + else if (loc.begin.line < loc.end.line) + ostr << '-' << loc.end.line << '.' << end_col; + else if (loc.begin.column < end_col) + ostr << '-' << end_col; + return ostr; + } +]]) + + +m4_ifdef([b4_position_file], [[ +]b4_output_begin([b4_dir_prefix], [b4_position_file])[ +]b4_generated_by[ +// Starting with Bison 3.2, this file is useless: the structure it +// used to define is now defined in "]b4_location_file[". +// +// To get rid of this file: +// 1. add '%require "3.2"' (or newer) to your grammar file +// 2. remove references to this file from your build system +// 3. if you used to include it, include "]b4_location_file[" instead. + +# include] b4_location_include[ +]b4_output_end[ +]]) + + +m4_ifdef([b4_location_file], [[ +]b4_output_begin([b4_dir_prefix], [b4_location_file])[ +]b4_copyright([Locations for Bison parsers in C++])[ +/** + ** \file ]b4_location_path[ + ** Define the ]b4_namespace_ref[::location class. + */ + +]b4_cpp_guard_open([b4_location_path])[ + +# include +# include + +]b4_null_define[ + +]b4_namespace_open[ +]b4_location_define[ +]b4_namespace_close[ +]b4_cpp_guard_close([b4_location_path])[ +]b4_output_end[ +]]) + + +m4_popdef([b4_copyright_years]) diff --git a/tools/flex-bison/third_party/skeletons/stack.hh b/tools/flex-bison/third_party/skeletons/stack.hh new file mode 100644 index 000000000..98913258f --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/stack.hh @@ -0,0 +1,157 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# b4_stack_file +# ------------- +# Name of the file containing the stack class, if we want this file. +b4_header_if([b4_required_version_if([30200], [], + [m4_define([b4_stack_file], [stack.hh])])]) + + +# b4_stack_define +# --------------- +m4_define([b4_stack_define], +[[ /// A stack with random access from its top. + template > + class stack + { + public: + // Hide our reversed order. + typedef typename S::iterator iterator; + typedef typename S::const_iterator const_iterator; + typedef typename S::size_type size_type; + typedef typename std::ptrdiff_t index_type; + + stack (size_type n = 200) YY_NOEXCEPT + : seq_ (n) + {} + +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + stack (const stack&) = delete; + /// Non copyable. + stack& operator= (const stack&) = delete; +#endif + + /// Random access. + /// + /// Index 0 returns the topmost element. + const T& + operator[] (index_type i) const + { + return seq_[size_type (size () - 1 - i)]; + } + + /// Random access. + /// + /// Index 0 returns the topmost element. + T& + operator[] (index_type i) + { + return seq_[size_type (size () - 1 - i)]; + } + + /// Steal the contents of \a t. + /// + /// Close to move-semantics. + void + push (YY_MOVE_REF (T) t) + { + seq_.push_back (T ()); + operator[] (0).move (t); + } + + /// Pop elements from the stack. + void + pop (std::ptrdiff_t n = 1) YY_NOEXCEPT + { + for (; 0 < n; --n) + seq_.pop_back (); + } + + /// Pop all elements from the stack. + void + clear () YY_NOEXCEPT + { + seq_.clear (); + } + + /// Number of elements on the stack. + index_type + size () const YY_NOEXCEPT + { + return index_type (seq_.size ()); + } + + /// Iterator on top of the stack (going downwards). + const_iterator + begin () const YY_NOEXCEPT + { + return seq_.begin (); + } + + /// Bottom of the stack. + const_iterator + end () const YY_NOEXCEPT + { + return seq_.end (); + } + + /// Present a slice of the top of a stack. + class slice + { + public: + slice (const stack& stack, index_type range) YY_NOEXCEPT + : stack_ (stack) + , range_ (range) + {} + + const T& + operator[] (index_type i) const + { + return stack_[range_ - i]; + } + + private: + const stack& stack_; + index_type range_; + }; + + private: +#if YY_CPLUSPLUS < 201103L + /// Non copyable. + stack (const stack&); + /// Non copyable. + stack& operator= (const stack&); +#endif + /// The wrapped container. + S seq_; + }; +]]) + +m4_ifdef([b4_stack_file], +[b4_output_begin([b4_dir_prefix], [b4_stack_file])[ +]b4_generated_by[ +// Starting with Bison 3.2, this file is useless: the structure it +// used to define is now defined with the parser itself. +// +// To get rid of this file: +// 1. add '%require "3.2"' (or newer) to your grammar file +// 2. remove references to this file from your build system. +]b4_output_end[ +]]) diff --git a/tools/flex-bison/third_party/skeletons/traceon.m4 b/tools/flex-bison/third_party/skeletons/traceon.m4 new file mode 100644 index 000000000..344d7d1c5 --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/traceon.m4 @@ -0,0 +1,2 @@ +dnl GNU M4 treats -dV in a position-independent manner. +m4_debugmode(V)m4_traceon()dnl diff --git a/tools/flex-bison/third_party/skeletons/variant.hh b/tools/flex-bison/third_party/skeletons/variant.hh new file mode 100644 index 000000000..2a490e8fa --- /dev/null +++ b/tools/flex-bison/third_party/skeletons/variant.hh @@ -0,0 +1,525 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +## --------- ## +## variant. ## +## --------- ## + +# b4_assert +# --------- +# The name of YY_ASSERT. +m4_define([b4_assert], + [b4_api_PREFIX[]_ASSERT]) + + +# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS]) +# ------------------------------------------------ +# Run some ACTION ("build", or "destroy") on YYVAL of symbol type +# YYTYPE. +m4_define([b4_symbol_variant], +[m4_pushdef([b4_dollar_dollar], + [$2.$3< $][3 > (m4_shift3($@))])dnl +switch ($1) + { +b4_type_foreach([_b4_type_action])[]dnl + default: + break; + } +m4_popdef([b4_dollar_dollar])dnl +]) + + +# _b4_char_sizeof_counter +# ----------------------- +# A counter used by _b4_char_sizeof_dummy to create fresh symbols. +m4_define([_b4_char_sizeof_counter], +[0]) + +# _b4_char_sizeof_dummy +# --------------------- +# At each call return a new C++ identifier. +m4_define([_b4_char_sizeof_dummy], +[m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl +dummy[]_b4_char_sizeof_counter]) + + +# b4_char_sizeof(SYMBOL-NUMS) +# --------------------------- +# To be mapped on the list of type names to produce: +# +# char dummy1[sizeof (type_name_1)]; +# char dummy2[sizeof (type_name_2)]; +# +# for defined type names. +m4_define([b4_char_sizeof], +[b4_symbol_if([$1], [has_type], +[ +m4_map([ b4_symbol_tag_comment], [$@])dnl + char _b4_char_sizeof_dummy@{sizeof (b4_symbol([$1], [type]))@}; +])]) + + +# b4_variant_includes +# ------------------- +# The needed includes for variants support. +m4_define([b4_variant_includes], +[b4_parse_assert_if([[#include +#ifndef ]b4_assert[ +# include +# define ]b4_assert[ assert +#endif +]])]) + + + +## -------------------------- ## +## Adjustments for variants. ## +## -------------------------- ## + + +# b4_value_type_declare +# --------------------- +# Define value_type. +m4_define([b4_value_type_declare], +[[ /// A buffer to store and retrieve objects. + /// + /// Sort of a variant, but does not keep track of the nature + /// of the stored data, since that knowledge is available + /// via the current parser state. + class value_type + { + public: + /// Type of *this. + typedef value_type self_type; + + /// Empty construction. + value_type () YY_NOEXCEPT + : yyraw_ ()]b4_parse_assert_if([ + , yytypeid_ (YY_NULLPTR)])[ + {} + + /// Construct and fill. + template + value_type (YY_RVREF (T) t)]b4_parse_assert_if([ + : yytypeid_ (&typeid (T))])[ + {]b4_parse_assert_if([[ + ]b4_assert[ (sizeof (T) <= size);]])[ + new (yyas_ ()) T (YY_MOVE (t)); + } + +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + value_type (const self_type&) = delete; + /// Non copyable. + self_type& operator= (const self_type&) = delete; +#endif + + /// Destruction, allowed only if empty. + ~value_type () YY_NOEXCEPT + {]b4_parse_assert_if([ + ]b4_assert[ (!yytypeid_); + ])[} + +# if 201103L <= YY_CPLUSPLUS + /// Instantiate a \a T in here from \a t. + template + T& + emplace (U&&... u) + {]b4_parse_assert_if([[ + ]b4_assert[ (!yytypeid_); + ]b4_assert[ (sizeof (T) <= size); + yytypeid_ = & typeid (T);]])[ + return *new (yyas_ ()) T (std::forward (u)...); + } +# else + /// Instantiate an empty \a T in here. + template + T& + emplace () + {]b4_parse_assert_if([[ + ]b4_assert[ (!yytypeid_); + ]b4_assert[ (sizeof (T) <= size); + yytypeid_ = & typeid (T);]])[ + return *new (yyas_ ()) T (); + } + + /// Instantiate a \a T in here from \a t. + template + T& + emplace (const T& t) + {]b4_parse_assert_if([[ + ]b4_assert[ (!yytypeid_); + ]b4_assert[ (sizeof (T) <= size); + yytypeid_ = & typeid (T);]])[ + return *new (yyas_ ()) T (t); + } +# endif + + /// Instantiate an empty \a T in here. + /// Obsolete, use emplace. + template + T& + build () + { + return emplace (); + } + + /// Instantiate a \a T in here from \a t. + /// Obsolete, use emplace. + template + T& + build (const T& t) + { + return emplace (t); + } + + /// Accessor to a built \a T. + template + T& + as () YY_NOEXCEPT + {]b4_parse_assert_if([[ + ]b4_assert[ (yytypeid_); + ]b4_assert[ (*yytypeid_ == typeid (T)); + ]b4_assert[ (sizeof (T) <= size);]])[ + return *yyas_ (); + } + + /// Const accessor to a built \a T (for %printer). + template + const T& + as () const YY_NOEXCEPT + {]b4_parse_assert_if([[ + ]b4_assert[ (yytypeid_); + ]b4_assert[ (*yytypeid_ == typeid (T)); + ]b4_assert[ (sizeof (T) <= size);]])[ + return *yyas_ (); + } + + /// Swap the content with \a that, of same type. + /// + /// Both variants must be built beforehand, because swapping the actual + /// data requires reading it (with as()), and this is not possible on + /// unconstructed variants: it would require some dynamic testing, which + /// should not be the variant's responsibility. + /// Swapping between built and (possibly) non-built is done with + /// self_type::move (). + template + void + swap (self_type& that) YY_NOEXCEPT + {]b4_parse_assert_if([[ + ]b4_assert[ (yytypeid_); + ]b4_assert[ (*yytypeid_ == *that.yytypeid_);]])[ + std::swap (as (), that.as ()); + } + + /// Move the content of \a that to this. + /// + /// Destroys \a that. + template + void + move (self_type& that) + { +# if 201103L <= YY_CPLUSPLUS + emplace (std::move (that.as ())); +# else + emplace (); + swap (that); +# endif + that.destroy (); + } + +# if 201103L <= YY_CPLUSPLUS + /// Move the content of \a that to this. + template + void + move (self_type&& that) + { + emplace (std::move (that.as ())); + that.destroy (); + } +#endif + + /// Copy the content of \a that to this. + template + void + copy (const self_type& that) + { + emplace (that.as ()); + } + + /// Destroy the stored \a T. + template + void + destroy () + { + as ().~T ();]b4_parse_assert_if([ + yytypeid_ = YY_NULLPTR;])[ + } + + private: +#if YY_CPLUSPLUS < 201103L + /// Non copyable. + value_type (const self_type&); + /// Non copyable. + self_type& operator= (const self_type&); +#endif + + /// Accessor to raw memory as \a T. + template + T* + yyas_ () YY_NOEXCEPT + { + void *yyp = yyraw_; + return static_cast (yyp); + } + + /// Const accessor to raw memory as \a T. + template + const T* + yyas_ () const YY_NOEXCEPT + { + const void *yyp = yyraw_; + return static_cast (yyp); + } + + /// An auxiliary type to compute the largest semantic type. + union union_type + {]b4_type_foreach([b4_char_sizeof])[ }; + + /// The size of the largest semantic type. + enum { size = sizeof (union_type) }; + + /// A buffer to store semantic values. + union + { + /// Strongest alignment constraints. + long double yyalign_me_; + /// A buffer large enough to store any of the semantic values. + char yyraw_[size]; + };]b4_parse_assert_if([ + + /// Whether the content is built: if defined, the name of the stored type. + const std::type_info *yytypeid_;])[ + }; +]]) + + +# How the semantic value is extracted when using variants. + +# b4_symbol_value(VAL, SYMBOL-NUM, [TYPE]) +# ---------------------------------------- +# See README. +m4_define([b4_symbol_value], +[m4_ifval([$3], + [$1.as< $3 > ()], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [$1.as < b4_symbol([$2], [type]) > ()], + [$1])], + [$1])])]) + +# b4_symbol_value_template(VAL, SYMBOL-NUM, [TYPE]) +# ------------------------------------------------- +# Same as b4_symbol_value, but used in a template method. +m4_define([b4_symbol_value_template], +[m4_ifval([$3], + [$1.template as< $3 > ()], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [$1.template as < b4_symbol([$2], [type]) > ()], + [$1])], + [$1])])]) + + + +## ------------- ## +## make_SYMBOL. ## +## ------------- ## + + +# _b4_includes_tokens(SYMBOL-NUM...) +# ---------------------------------- +# Expands to non-empty iff one of the SYMBOL-NUM denotes +# a token. +m4_define([_b4_is_token], + [b4_symbol_if([$1], [is_token], [1])]) +m4_define([_b4_includes_tokens], + [m4_map([_b4_is_token], [$@])]) + + +# _b4_token_maker_define(SYMBOL-NUM) +# ---------------------------------- +# Declare make_SYMBOL for SYMBOL-NUM. Use at class-level. +m4_define([_b4_token_maker_define], +[b4_token_visible_if([$1], +[#if 201103L <= YY_CPLUSPLUS + static + symbol_type + make_[]_b4_symbol([$1], [id]) (b4_join( + b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))); + } +#else + static + symbol_type + make_[]_b4_symbol([$1], [id]) (b4_join( + b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [v]), + b4_locations_if([l]))); + } +#endif +])]) + + +# b4_token_kind(SYMBOL-NUM) +# ------------------------- +# Some tokens don't have an ID. +m4_define([b4_token_kind], +[b4_symbol_if([$1], [has_id], + [token::b4_symbol([$1], [id])], + [b4_symbol([$1], [code])])]) + + +# _b4_tok_in(SYMBOL-NUM, ...) +# --------------------------- +# See b4_tok_in below. The SYMBOL-NUMs... are tokens only. +# +# We iterate over the tokens to group them by "range" of token numbers (not +# symbols numbers!). +# +# b4_fst is the start of that range. +# b4_prev is the previous value. +# b4_val is the current value. +# If b4_val is the successor of b4_prev in token numbers, update the latter, +# otherwise emit the code for range b4_fst .. b4_prev. +# $1 is also used as a terminator in the foreach, but it will not be printed. +# +m4_define([_b4_tok_in], +[m4_pushdef([b4_prev], [$1])dnl +m4_pushdef([b4_fst], [$1])dnl +m4_pushdef([b4_sep], [])dnl +m4_foreach([b4_val], m4_dquote(m4_shift($@, $1)), + [m4_if(b4_symbol(b4_val, [code]), m4_eval(b4_symbol(b4_prev, [code]) + 1), [], + [b4_sep[]m4_if(b4_fst, b4_prev, + [tok == b4_token_kind(b4_fst)], + [(b4_token_kind(b4_fst) <= tok && tok <= b4_token_kind(b4_prev))])[]dnl +m4_define([b4_fst], b4_val)dnl +m4_define([b4_sep], [ + || ])])dnl +m4_define([b4_prev], b4_val)])dnl +m4_popdef([b4_sep])dnl +m4_popdef([b4_fst])dnl +m4_popdef([b4_prev])dnl +]) + + +# _b4_filter_tokens(SYMBOL-NUM, ...) +# ---------------------------------- +# Expand as the list of tokens amongst SYMBOL-NUM. +m4_define([_b4_filter_tokens], +[m4_pushdef([b4_sep])dnl +m4_foreach([b4_val], [$@], + [b4_symbol_if(b4_val, [is_token], [b4_sep[]b4_val[]m4_define([b4_sep], [,])])])dnl +m4_popdef([b4_sep])dnl +]) + + +# b4_tok_in(SYMBOL-NUM, ...) +# --------------------------- +# A C++ conditional that checks that `tok` is a member of this list of symbol +# numbers. +m4_define([b4_tok_in], + [_$0(_b4_filter_tokens($@))]) + + + + +# _b4_symbol_constructor_define(SYMBOL-NUM...) +# -------------------------------------------- +# Define a symbol_type constructor common to all the SYMBOL-NUM (they +# have the same type). Use at class-level. +m4_define([_b4_symbol_constructor_define], +[m4_ifval(_b4_includes_tokens($@), +[[#if 201103L <= YY_CPLUSPLUS + symbol_type (]b4_join( + [int tok], + b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))[) + : super_type (]b4_join([token_kind_type (tok)], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))[) +#else + symbol_type (]b4_join( + [int tok], + b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))[) + : super_type (]b4_join([token_kind_type (tok)], + b4_symbol_if([$1], [has_type], [v]), + b4_locations_if([l]))[) +#endif + {]b4_parse_assert_if([[ +#if !defined _MSC_VER || defined __clang__ + ]b4_assert[ (]b4_tok_in($@)[); +#endif + ]])[} +]])]) + + +# b4_basic_symbol_constructor_define(SYMBOL-NUM) +# ---------------------------------------------- +# Generate a constructor for basic_symbol from given type. +m4_define([b4_basic_symbol_constructor_define], +[[#if 201103L <= YY_CPLUSPLUS + basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]), + b4_locations_if([location_type&& l]))[) + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (std::move (v))])[]b4_locations_if([ + , location (std::move (l))])[ + {} +#else + basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))[) + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (v)])[]b4_locations_if([ + , location (l)])[ + {} +#endif +]]) + + +# b4_token_constructor_define +# --------------------------- +# Define the overloaded versions of make_FOO for all the token kinds. +m4_define([b4_token_constructor_define], +[ // Implementation of make_symbol for each token kind. +b4_symbol_foreach([_b4_token_maker_define])]) diff --git a/tools/flex-bison/third_party/skeletons/yacc.c b/tools/flex-bison/third_party/skeletons/yacc.c index 54e40e674..64b9ac625 100644 --- a/tools/flex-bison/third_party/skeletons/yacc.c +++ b/tools/flex-bison/third_party/skeletons/yacc.c @@ -1,11 +1,11 @@ - -*- C -*- +# -*- C -*- # Yacc compatible skeleton for Bison -# Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software +# Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software # Foundation, Inc. m4_pushdef([b4_copyright_years], - [1984, 1989-1990, 2000-2015, 2018-2019]) + [1984, 1989-1990, 2000-2015, 2018-2021]) # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,53 +18,14 @@ m4_pushdef([b4_copyright_years], # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# Check the value of %define api.push-pull. -b4_percent_define_default([[api.push-pull]], [[pull]]) -b4_percent_define_check_values([[[[api.push-pull]], - [[pull]], [[push]], [[both]]]]) -b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]]) -b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]]) -m4_case(b4_percent_define_get([[api.push-pull]]), - [pull], [m4_define([b4_push_flag], [[0]])], - [push], [m4_define([b4_pull_flag], [[0]])]) - -# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing -# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the -# behavior of Bison at all when push parsing is already requested. -b4_define_flag_if([use_push_for_pull]) -b4_use_push_for_pull_if([ - b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], - [m4_define([b4_push_flag], [[1]])])]) - -# Check the value of %define parse.lac and friends, where LAC stands for -# lookahead correction. -b4_percent_define_default([[parse.lac]], [[none]]) -b4_percent_define_default([[parse.lac.es-capacity-initial]], [[20]]) -b4_percent_define_default([[parse.lac.memory-trace]], [[failures]]) -b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]], - [[[[parse.lac.memory-trace]], - [[failures]], [[full]]]]) -b4_define_flag_if([lac]) -m4_define([b4_lac_flag], - [m4_if(b4_percent_define_get([[parse.lac]]), - [none], [[0]], [[1]])]) +# along with this program. If not, see . m4_include(b4_skeletonsdir/[c.m4]) -## ---------------- ## -## Default values. ## -## ---------------- ## -# Stack parameters. -m4_define_default([b4_stack_depth_max], [10000]) -m4_define_default([b4_stack_depth_init], [200]) - - -## ------------------------ ## -## Pure/impure interfaces. ## -## ------------------------ ## +## ---------- ## +## api.pure. ## +## ---------- ## b4_percent_define_default([[api.pure]], [[false]]) b4_percent_define_check_values([[[[api.pure]], @@ -84,6 +45,55 @@ m4_define([b4_pure_if], [2], [$1])]) [m4_fatal([invalid api.pure value: ]$1)])]) +## --------------- ## +## api.push-pull. ## +## --------------- ## + +# b4_pull_if, b4_push_if +# ---------------------- +# Whether the pull/push APIs are needed. Both can be enabled. + +b4_percent_define_default([[api.push-pull]], [[pull]]) +b4_percent_define_check_values([[[[api.push-pull]], + [[pull]], [[push]], [[both]]]]) +b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]]) +b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]]) +m4_case(b4_percent_define_get([[api.push-pull]]), + [pull], [m4_define([b4_push_flag], [[0]])], + [push], [m4_define([b4_pull_flag], [[0]])]) + +# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing +# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the +# behavior of Bison at all when push parsing is already requested. +b4_define_flag_if([use_push_for_pull]) +b4_use_push_for_pull_if([ + b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], + [m4_define([b4_push_flag], [[1]])])]) + +## ----------- ## +## parse.lac. ## +## ----------- ## + +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_default([[parse.lac.es-capacity-initial]], [[20]]) +b4_percent_define_default([[parse.lac.memory-trace]], [[failures]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]], + [[[[parse.lac.memory-trace]], + [[failures]], [[full]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + +## ---------------- ## +## Default values. ## +## ---------------- ## + +# Stack parameters. +m4_define_default([b4_stack_depth_max], [10000]) +m4_define_default([b4_stack_depth_init], [200]) + + # b4_yyerror_arg_loc_if(ARG) # -------------------------- # Expand ARG iff yyerror is to be given a location as argument. @@ -92,6 +102,16 @@ m4_define([b4_yyerror_arg_loc_if], [1], [m4_ifset([b4_parse_param], [$1])], [2], [$1])])]) +# b4_yyerror_formals +# ------------------ +m4_define([b4_yyerror_formals], +[b4_pure_if([b4_locations_if([, [[const ]b4_api_PREFIX[LTYPE *yyllocp], [&yylloc]]])[]dnl +m4_ifdef([b4_parse_param], [, b4_parse_param])[]dnl +,])dnl +[[const char *msg], [msg]]]) + + + # b4_yyerror_args # --------------- # Arguments passed to yyerror: user args plus yylloc. @@ -101,33 +121,21 @@ m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) -## ------------ ## -## Data Types. ## -## ------------ ## - -# b4_int_type(MIN, MAX) -# --------------------- -# Return the smallest int type able to handle numbers ranging from -# MIN to MAX (included). Overwrite the version from c.m4, which -# uses only C89 types, so that the user can override the shorter -# types, and so that pre-C89 compilers are handled correctly. -m4_define([b4_int_type], -[m4_if(b4_ints_in($@, [0], [255]), [1], [yytype_uint8], - b4_ints_in($@, [-128], [127]), [1], [yytype_int8], - - b4_ints_in($@, [0], [65535]), [1], [yytype_uint16], - b4_ints_in($@, [-32768], [32767]), [1], [yytype_int16], - - m4_eval([0 <= $1]), [1], [unsigned], - - [int])]) - - ## ----------------- ## ## Semantic Values. ## ## ----------------- ## +# b4_accept([SYMBOL-NUM]) +# ----------------------- +# Used in actions of the rules of accept, the initial symbol, to call +# YYACCEPT. If SYMBOL-NUM is specified, run "yyvalue->SLOT = $2;" +# before, using the slot of SYMBOL-NUM. +m4_define([b4_accept], +[m4_ifval([$1], + [b4_symbol_value(yyimpl->yyvalue, [$1]) = b4_rhs_value(2, 1, [$1]); ]) YYACCEPT]) + + # b4_lhs_value(SYMBOL-NUM, [TYPE]) # -------------------------------- # See README. @@ -149,6 +157,7 @@ m4_define([b4_rhs_value], # b4_lhs_location() # ----------------- # Expansion of @$. +# Overparenthetized to avoid obscure problems with "foo$$bar = foo$1bar". m4_define([b4_lhs_location], [(yyloc)]) @@ -157,6 +166,7 @@ m4_define([b4_lhs_location], # --------------------------------- # Expansion of @POS, where the current rule has RULE-LENGTH symbols # on RHS. +# Overparenthetized to avoid obscure problems with "foo$$bar = foo$1bar". m4_define([b4_rhs_location], [(yylsp@{b4_subtract([$2], [$1])@})]) @@ -165,14 +175,61 @@ m4_define([b4_rhs_location], ## Declarations. ## ## -------------- ## +# _b4_declare_sub_yyparse(START-SYMBOL-NUM, SWITCHING-TOKEN-SYMBOL-NUM) +# --------------------------------------------------------------------- +# Define the return type of the parsing function for SYMBOL-NUM, and +# declare its parsing function. +m4_define([_b4_declare_sub_yyparse], +[[ +// Return type when parsing one ]_b4_symbol($1, tag)[. +typedef struct +{]b4_symbol_if([$1], [has_type], [[ + ]_b4_symbol($1, type)[ yyvalue;]])[ + int yystatus; + int yynerrs; +} ]b4_prefix[parse_]_b4_symbol($1, id)[_t; + +// Parse one ]_b4_symbol($1, tag)[. +]b4_prefix[parse_]_b4_symbol($1, id)[_t ]b4_prefix[parse_]_b4_symbol($1, id)[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[); +]]) + + +# _b4_first_switching_token +# ------------------------- +m4_define([b4_first], [$1]) +m4_define([b4_second], [$2]) +m4_define([_b4_first_switching_token], +[b4_second(b4_first(b4_start_symbols))]) + + +# _b4_define_sub_yyparse(START-SYMBOL-NUM, SWITCHING-TOKEN-SYMBOL-NUM) +# -------------------------------------------------------------------- +# Define the parsing function for START-SYMBOL-NUM. +m4_define([_b4_define_sub_yyparse], +[[ +]b4_prefix[parse_]_b4_symbol($1, id)[_t +]b4_prefix[parse_]_b4_symbol($1, id)[ (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) +{ + ]b4_prefix[parse_]_b4_symbol($1, id)[_t yyres; + yy_parse_impl_t yyimpl; + yyres.yystatus = yy_parse_impl (]b4_symbol($2, id)[, &yyimpl]m4_ifset([b4_parse_param], + [[, ]b4_args(b4_parse_param)])[);]b4_symbol_if([$1], [has_type], [[ + yyres.yyvalue = yyimpl.yyvalue.]b4_symbol($1, slot)[;]])[ + yyres.yynerrs = yyimpl.yynerrs; + return yyres; +} +]]) + + # b4_declare_scanner_communication_variables # ------------------------------------------ # Declare the variables that are global, or local to YYPARSE if # pure-parser. m4_define([b4_declare_scanner_communication_variables], [[ -/* The lookahead symbol. */ +]m4_ifdef([b4_start_symbols], [], +[[/* Lookahead token kind. */ int yychar; - +]])[ ]b4_pure_if([[ /* The semantic value of the lookahead symbol. */ /* Default value used for initialization, for pacifying older GCCs @@ -191,49 +248,79 @@ YYLTYPE yylloc]b4_yyloc_default[;]])[ int yynerrs;]])]) -# b4_declare_parser_state_variables -# --------------------------------- +# b4_declare_parser_state_variables([INIT]) +# ----------------------------------------- # Declare all the variables that are needed to maintain the parser state # between calls to yypush_parse. -m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ +# If INIT is non-null, initialize these variables. +m4_define([b4_declare_parser_state_variables], +[b4_pure_if([[ /* Number of syntax errors so far. */ - int yynerrs; + int yynerrs]m4_ifval([$1], [ = 0])[; ]])[ - int yystate; + yy_state_fast_t yystate]m4_ifval([$1], [ = 0])[; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yyerrstatus]m4_ifval([$1], [ = 0])[; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values.]b4_locations_if([[ - 'yyls': related to locations.]])[ - - Refer to the stacks through separate pointers, to allow yyoverflow + /* Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* Their size. */ + YYPTRDIFF_T yystacksize]m4_ifval([$1], [ = YYINITDEPTH])[; - /* The semantic value stack. */ + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss]m4_ifval([$1], [ = yyssa])[; + yy_state_t *yyssp]m4_ifval([$1], [ = yyss])[; + + /* The semantic value stack: array, bottom, top. */ YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp;]b4_locations_if([[ + YYSTYPE *yyvs]m4_ifval([$1], [ = yyvsa])[; + YYSTYPE *yyvsp]m4_ifval([$1], [ = yyvs])[;]b4_locations_if([[ - /* The location stack. */ + /* The location stack: array, bottom, top. */ YYLTYPE yylsa[YYINITDEPTH]; - YYLTYPE *yyls; - YYLTYPE *yylsp; + YYLTYPE *yyls]m4_ifval([$1], [ = yylsa])[; + YYLTYPE *yylsp]m4_ifval([$1], [ = yyls])[;]])[]b4_lac_if([[ - /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[3];]])[ + yy_state_t yyesa@{]b4_percent_define_get([[parse.lac.es-capacity-initial]])[@}; + yy_state_t *yyes]m4_ifval([$1], [ = yyesa])[; + YYPTRDIFF_T yyes_capacity][]m4_ifval([$1], + [m4_do([ = b4_percent_define_get([[parse.lac.es-capacity-initial]]) < YYMAXDEPTH], + [ ? b4_percent_define_get([[parse.lac.es-capacity-initial]])], + [ : YYMAXDEPTH])])[;]])]) + + +m4_define([b4_macro_define], +[[#]define $1 $2]) + +m4_define([b4_macro_undef], +[[#]undef $1]) + +m4_define([b4_pstate_macro_define], +[b4_macro_define([$1], [yyps->$1])]) + +# b4_parse_state_variable_macros(b4_macro_define|b4_macro_undef) +# -------------------------------------------------------------- +m4_define([b4_parse_state_variable_macros], +[b4_pure_if([$1([b4_prefix[]nerrs])]) +$1([yystate]) +$1([yyerrstatus]) +$1([yyssa]) +$1([yyss]) +$1([yyssp]) +$1([yyvsa]) +$1([yyvs]) +$1([yyvsp])[]b4_locations_if([ +$1([yylsa]) +$1([yyls]) +$1([yylsp])]) +$1([yystacksize])[]b4_lac_if([ +$1([yyesa]) +$1([yyes]) +$1([yyes_capacity])])]) - YYSIZE_T yystacksize;]b4_lac_if([[ - yytype_int16 yyesa@{]b4_percent_define_get([[parse.lac.es-capacity-initial]])[@}; - yytype_int16 *yyes; - YYSIZE_T yyes_capacity;]])]) # _b4_declare_yyparse_push @@ -248,27 +335,23 @@ enum { YYPUSH_MORE = 4 }; typedef struct ]b4_prefix[pstate ]b4_prefix[pstate; -]b4_pull_if([b4_function_declare([b4_prefix[parse]], [[int]], b4_parse_param) -])b4_function_declare([b4_prefix[push_parse]], [[int]], - [[b4_prefix[pstate *ps]], [[ps]]]b4_pure_if([, - [[[int pushed_char]], [[pushed_char]]], - [[b4_api_PREFIX[STYPE const *pushed_val]], [[pushed_val]]]b4_locations_if([, - [[b4_api_PREFIX[LTYPE *pushed_loc]], [[pushed_loc]]]])])m4_ifset([b4_parse_param], [, - b4_parse_param])) -b4_pull_if([b4_function_declare([b4_prefix[pull_parse]], [[int]], - [[b4_prefix[pstate *ps]], [[ps]]]m4_ifset([b4_parse_param], [, - b4_parse_param]))]) -b4_function_declare([b4_prefix[pstate_new]], [b4_prefix[pstate *]], - [[[void]], []]) -b4_function_declare([b4_prefix[pstate_delete]], [[void]], - [[b4_prefix[pstate *ps]], [[ps]]])dnl -]) +]b4_pull_if([[ +int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[);]])[ +int ]b4_prefix[push_parse (]b4_prefix[pstate *ps]b4_pure_if([[, + int pushed_char, ]b4_api_PREFIX[STYPE const *pushed_val]b4_locations_if([[, ]b4_api_PREFIX[LTYPE *pushed_loc]])])b4_user_formals[); +]b4_pull_if([[int ]b4_prefix[pull_parse (]b4_prefix[pstate *ps]b4_user_formals[);]])[ +]b4_prefix[pstate *]b4_prefix[pstate_new (void); +void ]b4_prefix[pstate_delete (]b4_prefix[pstate *ps); +]]) + # _b4_declare_yyparse # ------------------- # When not the push parser. m4_define([_b4_declare_yyparse], -[b4_function_declare(b4_prefix[parse], [int], b4_parse_param)]) +[[int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[); +]m4_ifdef([b4_start_symbols], + [m4_map([_b4_declare_sub_yyparse], m4_defn([b4_start_symbols]))])]) # b4_declare_yyparse @@ -279,30 +362,75 @@ m4_define([b4_declare_yyparse], ]) +# b4_declare_yyerror_and_yylex +# ---------------------------- +# Comply with POSIX Yacc. +# +m4_define([b4_declare_yyerror_and_yylex], +[b4_posix_if([[#if !defined ]b4_prefix[error && !defined ]b4_api_PREFIX[ERROR_IS_DECLARED +]b4_function_declare([b4_prefix[error]], void, b4_yyerror_formals)[ +#endif +#if !defined ]b4_prefix[lex && !defined ]b4_api_PREFIX[LEX_IS_DECLARED +]b4_function_declare([b4_prefix[lex]], int, b4_yylex_formals)[ +#endif +]])dnl +]) + + # b4_shared_declarations # ---------------------- -# Declaration that might either go into the header (if --defines) -# or open coded in the parser body. +# Declarations that might either go into the header (if --header) +# or into the implementation file. m4_define([b4_shared_declarations], -[b4_cpp_guard_open([b4_spec_defines_file])[ +[b4_cpp_guard_open([b4_spec_mapped_header_file])[ ]b4_declare_yydebug[ ]b4_percent_code_get([[requires]])[ ]b4_token_enums_defines[ ]b4_declare_yylstype[ +]b4_declare_yyerror_and_yylex[ ]b4_declare_yyparse[ ]b4_percent_code_get([[provides]])[ -]b4_cpp_guard_close([b4_spec_defines_file])[]dnl +]b4_cpp_guard_close([b4_spec_mapped_header_file])[]dnl ]) + +# b4_header_include_if(IF-TRUE, IF-FALSE) +# --------------------------------------- +# Run IF-TRUE if we generate an output file and api.header.include +# is defined. +m4_define([b4_header_include_if], +[m4_ifval(m4_quote(b4_spec_header_file), + [b4_percent_define_ifdef([[api.header.include]], + [$1], + [$2])], + [$2])]) + +m4_if(b4_spec_header_file, [y.tab.h], [], + [b4_percent_define_default([[api.header.include]], + [["@basename(]b4_spec_header_file[@)"]])]) + + + + ## -------------- ## ## Output files. ## ## -------------- ## + +b4_header_if([[ +]b4_output_begin([b4_spec_header_file])[ +]b4_copyright([Bison interface for Yacc-like parsers in C])[ +]b4_disclaimer[ +]b4_shared_declarations[ +]b4_output_end[ +]])# b4_header_if + b4_output_begin([b4_parser_file_name])[ ]b4_copyright([Bison implementation for Yacc-like parsers in C])[ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +]b4_disclaimer[ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -310,7 +438,6 @@ b4_output_begin([b4_parser_file_name])[ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -]b4_disclaimer[ ]b4_identification[ ]b4_percent_code_get([[top]])[]dnl m4_if(b4_api_prefix, [yy], [], @@ -323,79 +450,39 @@ m4_if(b4_api_prefix, [yy], [], #define yypush_parse ]b4_prefix[push_parse]b4_pull_if([[ #define yypull_parse ]b4_prefix[pull_parse]])[ #define yypstate_new ]b4_prefix[pstate_new +#define yypstate_clear ]b4_prefix[pstate_clear #define yypstate_delete ]b4_prefix[pstate_delete #define yypstate ]b4_prefix[pstate]])[ #define yylex ]b4_prefix[lex #define yyerror ]b4_prefix[error #define yydebug ]b4_prefix[debug -#define yynerrs ]b4_prefix[nerrs -]]b4_pure_if([], [[ +#define yynerrs ]b4_prefix[nerrs]]b4_pure_if([], [[ #define yylval ]b4_prefix[lval #define yychar ]b4_prefix[char]b4_locations_if([[ #define yylloc ]b4_prefix[lloc]])]))[ ]b4_user_pre_prologue[ +]b4_cast_define[ ]b4_null_define[ -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[ -#endif - -]m4_ifval(m4_quote(b4_spec_defines_file), -[[/* In a future release of Bison, this section will be replaced - by #include "@basename(]b4_spec_defines_file[@)". */ -]])dnl -b4_shared_declarations[ +]b4_header_include_if([[#include ]b4_percent_define_get([[api.header.include]])], + [m4_ifval(m4_quote(b4_spec_header_file), + [/* Use api.header.include to #include this header + instead of duplicating it here. */ +])b4_shared_declarations])[ +]b4_declare_symbol_enum[ ]b4_user_post_prologue[ -]b4_percent_code_get[]dnl +]b4_percent_code_get[ +]b4_c99_int_type_define[ -[#ifdef short -# undef short -#endif +]b4_sizes_types_define[ -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; -#endif +/* Stored state numbers (used for stacks). */ +typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yy_state_t; -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#else -typedef signed char yytype_int8; -#endif - -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short yytype_uint16; -#endif - -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; -#else -typedef short yytype_int16; -#endif - -#ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned -# endif -#endif - -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -408,10 +495,24 @@ typedef short yytype_int16; # define YY_(Msgid) Msgid # endif #endif +]b4_has_translations_if([ +#ifndef N_ +# define N_(Msgid) Msgid +#endif +])[ ]b4_attribute_define[ -#if ]b4_lac_if([[1]], [[! defined yyoverflow || YYERROR_VERBOSE]])[ +]b4_parse_assert_if([[#ifdef NDEBUG +# define YY_ASSERT(E) ((void) (0 && (E))) +#else +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_ASSERT(E) assert (E) +#endif +]], +[[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ + +#if ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ /* The parser invokes alloca or malloc; define the necessary symbols. */]dnl b4_push_if([], [b4_lac_if([], [[ @@ -478,8 +579,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif]b4_lac_if([[ # define YYCOPY_NEEDED 1]])[ -#endif]b4_lac_if([], [[ /* ! defined yyoverflow || YYERROR_VERBOSE */]])[ - +#endif /* ]b4_lac_if([[1]], [b4_parse_error_case([simple], [[!defined yyoverflow]], [[1]])])[ */ #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -489,22 +589,23 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss_alloc; + yy_state_t yyss_alloc; YYSTYPE yyvs_alloc;]b4_locations_if([ YYLTYPE yyls_alloc;])[ }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ ]b4_locations_if( [# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \ + + YYSIZEOF (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM)], [# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM)])[ # define YYCOPY_NEEDED 1 @@ -517,11 +618,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYSIZE_T yynewbytes; \ + YYPTRDIFF_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ } \ while (0) @@ -533,12 +634,12 @@ union yyalloc # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYSIZE_T yyi; \ + YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ @@ -561,71 +662,100 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES ]b4_states_number[ -#define YYUNDEFTOK ]b4_undef_token_number[ -#define YYMAXUTOK ]b4_user_token_number_max[ +/* YYMAXUTOK -- Last valid token kind. */ +#define YYMAXUTOK ]b4_code_max[ + /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) \ - ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +]b4_api_token_raw_if(dnl +[[#define YYTRANSLATE(YYX) YY_CAST (yysymbol_kind_t, YYX)]], +[[#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : ]b4_symbol_prefix[YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = { ]b4_translate[ -}; +};]])[ #if ]b4_api_PREFIX[DEBUG ]b4_integral_parser_table_define([rline], [b4_rline], [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ #endif -#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[ -/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + +]b4_parse_error_bmatch([simple\|verbose], +[[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { ]b4_tname[ }; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +}]], +[[static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + static const char *const yy_sname[] = + { + ]b4_symbol_names[ + };]b4_has_translations_if([[ + /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is + internationalizable. */ + static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = + { + ]b4_translatable[ + }; + return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] + ? _(yy_sname[yysymbol]) + : yy_sname[yysymbol]);]], [[ + return yy_sname[yysymbol];]])[ +}]])[ #endif -# ifdef YYPRINT -/* YYTOKNUM[NUM] -- (External) token number corresponding to the - (internal) symbol number NUM (which must be that of a token). */ -static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = -{ - ]b4_toknum[ -}; -# endif +#define YYPACT_NINF (]b4_pact_ninf[) -#define YYPACT_NINF ]b4_pact_ninf[ +#define yypact_value_is_default(Yyn) \ + ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[ -#define yypact_value_is_default(Yystate) \ - ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[ +#define YYTABLE_NINF (]b4_table_ninf[) -#define YYTABLE_NINF ]b4_table_ninf[ - -#define yytable_value_is_error(Yytable_value) \ - ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[ +#define yytable_value_is_error(Yyn) \ + ]b4_table_value_equals([[table]], [[Yyn]], [b4_table_ninf], [YYTABLE_NINF])[ ]b4_parser_tables_define[ +enum { YYENOMEM = -2 }; + #define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 +#define yyclearin (yychar = ]b4_symbol(empty, id)[) #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab +#define YYNOMEM goto yyexhaustedlab #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ - if (yychar == YYEMPTY) \ + if (yychar == ]b4_symbol(empty, id)[) \ { \ yychar = (Token); \ yylval = (Value); \ @@ -641,10 +771,9 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = } \ while (0) -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +/* Backward compatibility with an undocumented macro. + Use ]b4_symbol(error, id)[ or ]b4_symbol(undef, id)[. */ +#define YYERRCODE ]b4_symbol(undef, id)[ ]b4_locations_if([[ ]b4_yylloc_default_define[ #define YYRHSLOC(Rhs, K) ((Rhs)[K]) @@ -664,15 +793,15 @@ do { \ YYFPRINTF Args; \ } while (0) -]b4_yy_location_print_define[ +]b4_yylocation_print_define[ -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value]b4_locations_if([, Location])[]b4_user_args[); \ + Kind, Value]b4_locations_if([, Location])[]b4_user_args[); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -684,9 +813,8 @@ do { \ | TOP (included). | `------------------------------------------------------------------*/ -]b4_function_define([yy_stack_print], [static void], - [[yytype_int16 *yybottom], [yybottom]], - [[yytype_int16 *yytop], [yytop]])[ +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -708,27 +836,23 @@ do { \ | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -]b4_function_define([yy_reduce_print], [static void], - [[yytype_int16 *yyssp], [yyssp]], - [[YYSTYPE *yyvsp], [yyvsp]], - b4_locations_if([[[YYLTYPE *yylsp], [yylsp]], - ])[[int yyrule], [yyrule]]m4_ifset([b4_parse_param], [, - b4_parse_param]))[ +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,]b4_locations_if([[ YYLTYPE *yylsp,]])[ + int yyrule]b4_user_formals[) { - unsigned long yylno = yyrline[yyrule]; + int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &]b4_rhs_value(yynrhs, yyi + 1)[ - ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl - b4_user_args[); + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &]b4_rhs_value(yynrhs, yyi + 1)[]b4_locations_if([, + &]b4_rhs_location(yynrhs, yyi + 1))[]b4_user_args[); YYFPRINTF (stderr, "\n"); } } @@ -743,8 +867,8 @@ do { \ multiple parsers can coexist. */ int yydebug; #else /* !]b4_api_PREFIX[DEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !]b4_api_PREFIX[DEBUG */ @@ -764,7 +888,18 @@ int yydebug; #ifndef YYMAXDEPTH # define YYMAXDEPTH ]b4_stack_depth_max[ -#endif]b4_lac_if([[ +#endif]b4_push_if([[ +/* Parser data structure. */ +struct yypstate + {]b4_declare_parser_state_variables[ + /* Whether this instance has not started parsing yet. + * If 2, it corresponds to a finished parsing. */ + int yynew; + };]b4_pure_if([], [[ + +/* Whether the only allowed instance of yypstate is allocated. */ +static char yypstate_allocated = 0;]])])[ +]b4_lac_if([[ /* Given a state stack such that *YYBOTTOM is its bottom, such that *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty @@ -775,24 +910,24 @@ int yydebug; *YYTOP, and *YYCAPACITY to reflect the new capacity and memory location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack using YYSTACK_FREE. Return 0 if successful or if no reallocation is - required. Return 1 if memory is exhausted. */ + required. Return YYENOMEM if memory is exhausted. */ static int -yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, +yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, #if ]b4_api_PREFIX[DEBUG char const *yydebug_prefix, char const *yydebug_suffix, #endif - yytype_int16 **yybottom, - yytype_int16 *yybottom_no_free, - yytype_int16 **yytop, yytype_int16 *yytop_empty) + yy_state_t **yybottom, + yy_state_t *yybottom_no_free, + yy_state_t **yytop, yy_state_t *yytop_empty) { - YYSIZE_T yysize_old = - (YYSIZE_T) (*yytop == yytop_empty ? 0 : *yytop - *yybottom + 1); - YYSIZE_T yysize_new = yysize_old + yyadd; + YYPTRDIFF_T yysize_old = + *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1; + YYPTRDIFF_T yysize_new = yysize_old + yyadd; if (*yycapacity < yysize_new) { - YYSIZE_T yyalloc = 2 * yysize_new; - yytype_int16 *yybottom_new; + YYPTRDIFF_T yyalloc = 2 * yysize_new; + yy_state_t *yybottom_new; /* Use YYMAXDEPTH for maximum stack size given that the stack should never need to grow larger than the main state stack needs to grow without LAC. */ @@ -800,17 +935,19 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, { YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix, yydebug_suffix)); - return 1; + return YYENOMEM; } if (YYMAXDEPTH < yyalloc) yyalloc = YYMAXDEPTH; yybottom_new = - (yytype_int16*) YYSTACK_ALLOC (yyalloc * sizeof *yybottom_new); + YY_CAST (yy_state_t *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, + yyalloc * YYSIZEOF (*yybottom_new)))); if (!yybottom_new) { YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix, yydebug_suffix)); - return 1; + return YYENOMEM; } if (*yytop != yytop_empty) { @@ -822,8 +959,10 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, *yybottom = yybottom_new; *yycapacity = yyalloc;]m4_if(b4_percent_define_get([[parse.lac.memory-trace]]), [full], [[ - YYDPRINTF ((stderr, "%srealloc to %lu%s", yydebug_prefix, - (unsigned long) yyalloc, yydebug_suffix));]])[ + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "%srealloc to %ld%s", yydebug_prefix, + YY_CAST (long, yyalloc), yydebug_suffix)); + YY_IGNORE_USELESS_CAST_END]])[ } return 0; } @@ -854,23 +993,22 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, current lookahead, then check if that lookahead can eventually be shifted if syntactic actions continue from the current context. Report a syntax error if it cannot. */ -#define YY_LAC_ESTABLISH \ -do { \ - if (!yy_lac_established) \ - { \ - YYDPRINTF ((stderr, \ - "LAC: initial context established for %s\n", \ - yytname[yytoken])); \ - yy_lac_established = 1; \ - { \ - int yy_lac_status = \ - yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken); \ - if (yy_lac_status == 2) \ - goto yyexhaustedlab; \ - if (yy_lac_status == 1) \ - goto yyerrlab; \ - } \ - } \ +#define YY_LAC_ESTABLISH \ +do { \ + if (!yy_lac_established) \ + { \ + YYDPRINTF ((stderr, \ + "LAC: initial context established for %s\n", \ + yysymbol_name (yytoken))); \ + yy_lac_established = 1; \ + switch (yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken)) \ + { \ + case YYENOMEM: \ + YYNOMEM; \ + case 1: \ + goto yyerrlab; \ + } \ + } \ } while (0) /* Discard any previous initial lookahead context because of Event, @@ -889,9 +1027,8 @@ do { \ do { \ if (yy_lac_established) \ { \ - if (yydebug) \ - YYFPRINTF (stderr, "LAC: initial context discarded due to " \ - Event "\n"); \ + YYDPRINTF ((stderr, "LAC: initial context discarded due to " \ + Event "\n")); \ yy_lac_established = 0; \ } \ } while (0) @@ -901,32 +1038,34 @@ do { \ /* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can eventually (after perhaps some reductions) be shifted, return 1 if - not, or return 2 if memory is exhausted. As preconditions and + not, or return YYENOMEM if memory is exhausted. As preconditions and postconditions: *YYES_CAPACITY is the allocated size of the array to which *YYES points, and either *YYES = YYESA or *YYES points to an array allocated with YYSTACK_ALLOC. yy_lac may overwrite the contents of either array, alter *YYES and *YYES_CAPACITY, and free any old *YYES other than YYESA. */ static int -yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, - YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken) +yy_lac (yy_state_t *yyesa, yy_state_t **yyes, + YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, yysymbol_kind_t yytoken) { - yytype_int16 *yyes_prev = yyssp; - yytype_int16 *yyesp = yyes_prev; - YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken])); - if (yytoken == YYUNDEFTOK) + yy_state_t *yyes_prev = yyssp; + yy_state_t *yyesp = yyes_prev; + /* Reduce until we encounter a shift and thereby accept the token. */ + YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yysymbol_name (yytoken))); + if (yytoken == ]b4_symbol_prefix[YYUNDEF) { YYDPRINTF ((stderr, " Always Err\n")); return 1; } while (1) { - int yyrule = yypact[*yyesp]; + int yyrule = yypact[+*yyesp]; if (yypact_value_is_default (yyrule) || (yyrule += yytoken) < 0 || YYLAST < yyrule || yycheck[yyrule] != yytoken) { - yyrule = yydefact[*yyesp]; + /* Use the default action. */ + yyrule = yydefact[+*yyesp]; if (yyrule == 0) { YYDPRINTF ((stderr, " Err\n")); @@ -935,6 +1074,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, } else { + /* Use the action from yytable. */ yyrule = yytable[yyrule]; if (yytable_value_is_error (yyrule)) { @@ -948,12 +1088,15 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, } yyrule = -yyrule; } + /* By now we know we have to simulate a reduce. */ + YYDPRINTF ((stderr, " R%d", yyrule - 1)); { - YYSIZE_T yylen = yyr2[yyrule]; - YYDPRINTF ((stderr, " R%d", yyrule - 1)); + /* Pop the corresponding number of values from the stack. */ + YYPTRDIFF_T yylen = yyr2[yyrule]; + /* First pop from the LAC stack as many tokens as possible. */ if (yyesp != yyes_prev) { - YYSIZE_T yysize = (YYSIZE_T) (yyesp - *yyes + 1); + YYPTRDIFF_T yysize = yyesp - *yyes + 1; if (yylen < yysize) { yyesp -= yylen; @@ -961,27 +1104,30 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, } else { - yylen -= yysize; yyesp = yyes_prev; + yylen -= yysize; } } + /* Only afterwards look at the main stack. */ if (yylen) yyesp = yyes_prev -= yylen; } + /* Push the resulting state of the reduction. */ { - yytype_int16 yystate; + yy_state_fast_t yystate; { const int yylhs = yyr1[yyrule] - YYNTOKENS; const int yyi = yypgoto[yylhs] + *yyesp; - yystate = ((yytype_int16) - (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp - ? yytable[yyi] - : yydefgoto[yylhs])); + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp + ? yytable[yyi] + : yydefgoto[yylhs]); } if (yyesp == yyes_prev) { yyesp = *yyes; - *yyesp = yystate; + YY_IGNORE_USELESS_CAST_BEGIN + *yyesp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END } else { @@ -992,42 +1138,155 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, yyes, yyesa, &yyesp, yyes_prev)) { YYDPRINTF ((stderr, "\n")); - return 2; + return YYENOMEM; } - *++yyesp = yystate; + YY_IGNORE_USELESS_CAST_BEGIN + *++yyesp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END } - YYDPRINTF ((stderr, " G%d", (int) yystate)); + YYDPRINTF ((stderr, " G%d", yystate)); } } }]])[ +]b4_parse_error_case([simple], [], +[[/* Context of a parse error. */ +typedef struct +{]b4_push_if([[ + yypstate* yyps;]], [[ + yy_state_t *yyssp;]b4_lac_if([[ + yy_state_t *yyesa; + yy_state_t **yyes; + YYPTRDIFF_T *yyes_capacity;]])])[ + yysymbol_kind_t yytoken;]b4_locations_if([[ + YYLTYPE *yylloc;]])[ +} yypcontext_t; -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -]b4_function_define([yystrlen], [static YYSIZE_T], - [[const char *yystr], [yystr]])[ +/* Put in YYARG at most YYARGN of the expected tokens given the + current YYCTX, and return the number of tokens stored in YYARG. If + YYARG is null, return the number of expected tokens (guaranteed to + be less than YYNTOKENS). Return YYENOMEM on memory exhaustion. + Return 0 if there are more than YYARGN expected tokens, yet fill + YYARG up to YYARGN. */]b4_push_if([[ +static int +yypstate_expected_tokens (yypstate *yyps, + yysymbol_kind_t yyarg[], int yyargn)]], [[ +static int +yypcontext_expected_tokens (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn)]])[ { - YYSIZE_T yylen; + /* Actual size of YYARG. */ + int yycount = 0; +]b4_lac_if([[ + int yyx; + for (yyx = 0; yyx < YYNTOKENS; ++yyx) + { + yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx); + if (yysym != ]b4_symbol(error, kind)[ && yysym != ]b4_symbol_prefix[YYUNDEF) + switch (yy_lac (]b4_push_if([[yyps->yyesa, &yyps->yyes, &yyps->yyes_capacity, yyps->yyssp, yysym]], + [[yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, yyctx->yyssp, yysym]])[)) + { + case YYENOMEM: + return YYENOMEM; + case 1: + continue; + default: + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = yysym; + } + }]], +[[ int yyn = yypact@{+*]b4_push_if([yyps], [yyctx])[->yyssp@}; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (yysymbol_kind_t, yyx); + } + }]])[ + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = ]b4_symbol(empty, kind)[; + return yycount; +} + +]b4_push_if([[ +/* Similar to the previous function. */ +static int +yypcontext_expected_tokens (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) +{ + return yypstate_expected_tokens (yyctx->yyps, yyarg, yyargn); +}]])[ +]])[ + +]b4_parse_error_bmatch( + [custom], +[[/* The kind of the lookahead of this context. */ +static yysymbol_kind_t +yypcontext_token (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED; + +static yysymbol_kind_t +yypcontext_token (const yypcontext_t *yyctx) +{ + return yyctx->yytoken; +} + +]b4_locations_if([[/* The location of the lookahead of this context. */ +static YYLTYPE * +yypcontext_location (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED; + +static YYLTYPE * +yypcontext_location (const yypcontext_t *yyctx) +{ + return yyctx->yylloc; +}]])[ + +/* User defined function to report a syntax error. */ +static int +yyreport_syntax_error (const yypcontext_t *yyctx]b4_user_formals[);]], + [detailed\|verbose], +[[#ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +# else +/* Return the length of YYSTR. */ +static YYPTRDIFF_T +yystrlen (const char *yystr) +{ + YYPTRDIFF_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } -# endif # endif +#endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else +#ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -]b4_function_define([yystpcpy], [static char *], - [[char *yydest], [yydest]], [[const char *yysrc], [yysrc]])[ +static char * +yystpcpy (char *yydest, const char *yysrc) { char *yyd = yydest; const char *yys = yysrc; @@ -1037,10 +1296,12 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, return yyd - 1; } -# endif # endif +#endif -# ifndef yytnamerr +]b4_parse_error_case( + [verbose], +[[#ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string @@ -1048,14 +1309,13 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ -static YYSIZE_T +static YYPTRDIFF_T yytnamerr (char *yyres, const char *yystr) { if (*yystr == '"') { - YYSIZE_T yyn = 0; + YYPTRDIFF_T yyn = 0; char const *yyp = yystr; - for (;;) switch (*++yyp) { @@ -1084,39 +1344,20 @@ yytnamerr (char *yyres, const char *yystr) do_not_strip_quotes: ; } - if (! yyres) + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else return yystrlen (yystr); - - return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres); } -# endif +#endif +]])[ -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP.]b4_lac_if([[ In order to see if a particular token T is a - valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).]])[ - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store]b4_lac_if([[ or if - yy_lac returned 2]])[. */ static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - ]b4_lac_if([[yytype_int16 *yyesa, yytype_int16 **yyes, - YYSIZE_T *yyes_capacity, ]])[yytype_int16 *yyssp, int yytoken) +yy_syntax_error_arguments (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ + /* Actual size of YYARG. */ int yycount = 0; - /* There are many possibilities here to consider: - If this state is a consistent state with a default action, then the only way this function was invoked is if the default action @@ -1145,66 +1386,59 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, one exception: it will still contain any token that will not be accepted due to an error action in a later state.]])[ */ - if (yytoken != YYEMPTY) + if (yyctx->yytoken != ]b4_symbol(empty, kind)[) { - int yyn = yypact[*yyssp];]b4_lac_if([[ + int yyn;]b4_lac_if([[ YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[ - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - {]b4_lac_if([], [[ - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;]])[ - int yyx;]b4_lac_if([[ - - for (yyx = 0; yyx < YYNTOKENS; ++yyx) - if (yyx != YYTERROR && yyx != YYUNDEFTOK) - { - { - int yy_lac_status = yy_lac (yyesa, yyes, yyes_capacity, - yyssp, yyx); - if (yy_lac_status == 2) - return 2; - if (yy_lac_status == 1) - continue; - }]], [[ - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - {]])[ - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - } - }]b4_lac_if([[ -# if ]b4_api_PREFIX[DEBUG - else if (yydebug) - YYFPRINTF (stderr, "No expected tokens.\n"); -# endif]])[ + if (yyarg) + yyarg[yycount] = yyctx->yytoken; + ++yycount; + yyn = yypcontext_expected_tokens (yyctx, + yyarg ? yyarg + 1 : yyarg, yyargn - 1); + if (yyn == YYENOMEM) + return YYENOMEM;]b4_lac_if([[ + else if (yyn == 0) + YYDPRINTF ((stderr, "No expected tokens.\n"));]])[ + else + yycount += yyn; } + return yycount; +} + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP.]b4_lac_if([[ In order to see if a particular token T is a + valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).]])[ + + Return 0 if *YYMSG was successfully written. Return -1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return YYENOMEM if the + required number of bytes is too large to store]b4_lac_if([[ or if + yy_lac returned YYENOMEM]])[. */ +static int +yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, + const yypcontext_t *yyctx) +{ + enum { YYARGS_MAX = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ + yysymbol_kind_t yyarg[YYARGS_MAX]; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; + + /* Actual size of YYARG. */ + int yycount = yy_syntax_error_arguments (yyctx, yyarg, YYARGS_MAX); + if (yycount == YYENOMEM) + return YYENOMEM; switch (yycount) { -# define YYCASE_(N, S) \ +#define YYCASE_(N, S) \ case N: \ yyformat = S; \ - break + break default: /* Avoid compiler warnings. */ YYCASE_(0, YY_("syntax error")); YYCASE_(1, YY_("syntax error, unexpected %s")); @@ -1212,15 +1446,25 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ +#undef YYCASE_ } + /* Compute error message size. Don't count the "%s"s, but reserve + room for the terminator. */ + yysize = yystrlen (yyformat) - 2 * yycount + 1; { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; + int yyi; + for (yyi = 0; yyi < yycount; ++yyi) + { + YYPTRDIFF_T yysize1 + = yysize + ]b4_parse_error_case( + [verbose], [[yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]])]], + [[yystrlen (yysymbol_name (yyarg[yyi]))]]);[ + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return YYENOMEM; + } } if (*yymsg_alloc < yysize) @@ -1229,7 +1473,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, if (! (yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; + return -1; } /* Avoid sprintf, as that infringes on the user's name space. @@ -1240,165 +1484,188 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, int yyi = 0; while ((*yyp = *yyformat) != '\0') if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); + {]b4_parse_error_case([verbose], [[ + yyp += yytnamerr (yyp, yytname[yyarg[yyi++]]);]], [[ + yyp = yystpcpy (yyp, yysymbol_name (yyarg[yyi++]));]])[ yyformat += 2; } else { - yyp++; - yyformat++; + ++yyp; + ++yyformat; } } return 0; } -#endif /* YYERROR_VERBOSE */ +]])[ ]b4_yydestruct_define[ -]b4_pure_if([], [ +]b4_pure_if([], [b4_declare_scanner_communication_variables])[ -b4_declare_scanner_communication_variables])[]b4_push_if([[ +]b4_push_if([b4_pull_if([[ -struct yypstate - {]b4_declare_parser_state_variables[ - /* Used to determine if this is the first time this instance has - been used. */ - int yynew; - };]b4_pure_if([], [[ - -static char yypstate_allocated = 0;]])b4_pull_if([ - -b4_function_define([[yyparse]], [[int]], b4_parse_param)[ +int +yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) { - return yypull_parse (YY_NULLPTR]m4_ifset([b4_parse_param], - [[, ]b4_args(b4_parse_param)])[); + yypstate *yyps = yypstate_new (); + if (!yyps) + {]b4_pure_if([b4_locations_if([[ + static YYLTYPE yyloc_default][]b4_yyloc_default[; + YYLTYPE yylloc = yyloc_default;]])[ + yyerror (]b4_yyerror_args[YY_("memory exhausted"));]], [[ + if (!yypstate_allocated) + yyerror (]b4_yyerror_args[YY_("memory exhausted"));]])[ + return 2; + } + int yystatus = yypull_parse (yyps]b4_user_args[); + yypstate_delete (yyps); + return yystatus; } -]b4_function_define([[yypull_parse]], [[int]], - [[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [, - b4_parse_param]))[ -{]b4_pure_if([b4_locations_if([[ +int +yypull_parse (yypstate *yyps]b4_user_formals[) +{ + YY_ASSERT (yyps);]b4_pure_if([b4_locations_if([[ static YYLTYPE yyloc_default][]b4_yyloc_default[; YYLTYPE yylloc = yyloc_default;]])])[ - yypstate *yyps_local; - if (yyps) - yyps_local = yyps; - else - { - yyps_local = yypstate_new (); - if (!yyps_local) - {]b4_pure_if([[ - yyerror (]b4_yyerror_args[YY_("memory exhausted"));]], [[ - if (!yypstate_allocated) - yyerror (]b4_yyerror_args[YY_("memory exhausted"));]])[ - return 2; - } - } int yystatus; - do {]b4_pure_if([[ - YYSTYPE yylval; - int ]])[yychar = ]b4_lex[; - yystatus = - yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[); + do { +]b4_pure_if([[ YYSTYPE yylval; + int ]])[yychar = ]b4_yylex[; + yystatus = yypush_parse (yyps]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[); } while (yystatus == YYPUSH_MORE); - if (!yyps) - yypstate_delete (yyps_local); return yystatus; }]])[ +]b4_parse_state_variable_macros([b4_pstate_macro_define])[ + /* Initialize the parser data structure. */ -]b4_function_define([[yypstate_new]], [[yypstate *]])[ +static void +yypstate_clear (yypstate *yyps) +{ + yynerrs = 0; + yystate = 0; + yyerrstatus = 0; + + yyssp = yyss; + yyvsp = yyvs;]b4_locations_if([[ + yylsp = yyls;]])[ + + /* Initialize the state stack, in case yypcontext_expected_tokens is + called before the first call to yyparse. */ + *yyssp = 0; + yyps->yynew = 1; +} + +/* Initialize the parser data structure. */ +yypstate * +yypstate_new (void) { yypstate *yyps;]b4_pure_if([], [[ if (yypstate_allocated) return YY_NULLPTR;]])[ - yyps = (yypstate *) malloc (sizeof *yyps); + yyps = YY_CAST (yypstate *, YYMALLOC (sizeof *yyps)); if (!yyps) - return YY_NULLPTR; - yyps->yynew = 1;]b4_pure_if([], [[ + return YY_NULLPTR;]b4_pure_if([], [[ yypstate_allocated = 1;]])[ + yystacksize = YYINITDEPTH; + yyss = yyssa; + yyvs = yyvsa;]b4_locations_if([[ + yyls = yylsa;]])[]b4_lac_if([[ + yyes = yyesa; + yyes_capacity = ]b4_percent_define_get([[parse.lac.es-capacity-initial]])[; + if (YYMAXDEPTH < yyes_capacity) + yyes_capacity = YYMAXDEPTH;]])[ + yypstate_clear (yyps); return yyps; } -]b4_function_define([[yypstate_delete]], [[void]], - [[[yypstate *yyps]], [[yyps]]])[ +void +yypstate_delete (yypstate *yyps) { if (yyps) { #ifndef yyoverflow /* If the stack was reallocated but the parse did not complete, then the stack still needs to be freed. */ - if (!yyps->yynew && yyps->yyss != yyps->yyssa) - YYSTACK_FREE (yyps->yyss); + if (yyss != yyssa) + YYSTACK_FREE (yyss); #endif]b4_lac_if([[ - if (!yyps->yynew && yyps->yyes != yyps->yyesa) - YYSTACK_FREE (yyps->yyes);]])[ - free (yyps);]b4_pure_if([], [[ + if (yyes != yyesa) + YYSTACK_FREE (yyes);]])[ + YYFREE (yyps);]b4_pure_if([], [[ yypstate_allocated = 0;]])[ } } -]b4_pure_if([[ -#define ]b4_prefix[nerrs yyps->]b4_prefix[nerrs]])[ -#define yystate yyps->yystate -#define yyerrstatus yyps->yyerrstatus -#define yyssa yyps->yyssa -#define yyss yyps->yyss -#define yyssp yyps->yyssp -#define yyvsa yyps->yyvsa -#define yyvs yyps->yyvs -#define yyvsp yyps->yyvsp]b4_locations_if([[ -#define yylsa yyps->yylsa -#define yyls yyps->yyls -#define yylsp yyps->yylsp -#define yyerror_range yyps->yyerror_range]])[ -#define yystacksize yyps->yystacksize]b4_lac_if([[ -#define yyesa yyps->yyesa -#define yyes yyps->yyes -#define yyes_capacity yyps->yyes_capacity]])[ - +]])[ +]b4_push_if([[ /*---------------. | yypush_parse. | `---------------*/ -]b4_function_define([[yypush_parse]], [[int]], - [[[yypstate *yyps]], [[yyps]]]b4_pure_if([, - [[[int yypushed_char]], [[yypushed_char]]], - [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([, - [[[YYLTYPE *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [, - b4_parse_param]))], [[ - - +int +yypush_parse (yypstate *yyps]b4_pure_if([[, + int yypushed_char, YYSTYPE const *yypushed_val]b4_locations_if([[, YYLTYPE *yypushed_loc]])])b4_user_formals[)]], +[[ /*----------. | yyparse. | `----------*/ -]b4_function_define([yyparse], [int], b4_parse_param)])[ +]m4_ifdef([b4_start_symbols], +[[// Extract data from the parser. +typedef struct +{ + YYSTYPE yyvalue; + int yynerrs; +} yy_parse_impl_t; + +// Run a full parse, using YYCHAR as switching token. +static int +yy_parse_impl (int yychar, yy_parse_impl_t *yyimpl]m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])[); + +]m4_map([_b4_define_sub_yyparse], m4_defn([b4_start_symbols]))[ + +int +yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[) +{ + return yy_parse_impl (]b4_symbol(_b4_first_switching_token, id)[, YY_NULLPTR]m4_ifset([b4_parse_param], + [[, ]b4_args(b4_parse_param)])[); +} + +static int +yy_parse_impl (int yychar, yy_parse_impl_t *yyimpl]m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])[)]], +[[int +yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])])[ {]b4_pure_if([b4_declare_scanner_communication_variables ])b4_push_if([b4_pure_if([], [[ int yypushed_char = yychar; YYSTYPE yypushed_val = yylval;]b4_locations_if([[ YYLTYPE yypushed_loc = yylloc;]]) ])], - [b4_declare_parser_state_variables + [b4_declare_parser_state_variables([init]) ])b4_lac_if([[ + /* Whether LAC context is established. A Boolean. */ int yy_lac_established = 0;]])[ int yyn; + /* The return value of yyparse. */ int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = ]b4_symbol(empty, kind)[; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval;]b4_locations_if([[ - YYLTYPE yyloc;]])[ + YYLTYPE yyloc; -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3];]])[ + +]b4_parse_error_bmatch([detailed\|verbose], +[[ /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif + YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;]])[ #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_locations_if([, yylsp -= (N)])[) @@ -1406,28 +1673,25 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ Keep to zero when no symbol should be popped. */ int yylen = 0;]b4_push_if([[ - if (!yyps->yynew) + switch (yyps->yynew) { + case 0: yyn = yypact[yystate]; goto yyread_pushed_token; + + case 2: + yypstate_clear (yyps); + break; + + default: + break; }]])[ - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa;]b4_locations_if([[ - yylsp = yyls = yylsa;]])[ - yystacksize = YYINITDEPTH;]b4_lac_if([[ - - yyes = yyesa; - yyes_capacity = sizeof yyesa / sizeof *yyes; - if (YYMAXDEPTH < yyes_capacity) - yyes_capacity = YYMAXDEPTH;]])[ - YYDPRINTF ((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ +]m4_ifdef([b4_start_symbols], [], +[[ yychar = ]b4_symbol(empty, id)[; /* Cause a token to be read. */ +]])[ ]m4_ifdef([b4_initial_action], [ b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], [], [b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl @@ -1450,26 +1714,31 @@ yynewstate: /*--------------------------------------------------------------------. -| yynewstate -- set current state (the top of the stack) to yystate. | +| yysetstate -- set current state (the top of the stack) to yystate. | `--------------------------------------------------------------------*/ yysetstate: - *yyssp = (yytype_int16) yystate; + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE - goto yyexhaustedlab; + YYNOMEM; #else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1); + YYPTRDIFF_T yysize = yyssp - yyss + 1; # if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss;]b4_locations_if([ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs;]b4_locations_if([ YYLTYPE *yyls1 = yyls;])[ /* Each stack pointer address is followed by the size of the @@ -1477,9 +1746,9 @@ yysetstate: conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp),]b4_locations_if([ - &yyls1, yysize * sizeof (*yylsp),])[ + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp),]b4_locations_if([ + &yyls1, yysize * YYSIZEOF (*yylsp),])[ &yystacksize); yyss = yyss1; yyvs = yyvs1;]b4_locations_if([ @@ -1488,21 +1757,22 @@ yysetstate: # else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + YYNOMEM; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; + yy_state_t *yyss1 = yyss; union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) - goto yyexhaustedlab; + YYNOMEM; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs);]b4_locations_if([ YYSTACK_RELOCATE (yyls_alloc, yyls);])[ -# undef YYSTACK_RELOCATE +# undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } @@ -1512,18 +1782,19 @@ yysetstate: yyvsp = yyvs + yysize - 1;]b4_locations_if([ yylsp = yyls + yysize - 1;])[ - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long) yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - +]m4_ifdef([b4_start_symbols], [], [[ if (yystate == YYFINAL) - YYACCEPT; + YYACCEPT;]])[ goto yybackup; @@ -1542,8 +1813,8 @@ yybackup: /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + if (yychar == ]b4_symbol(empty, id)[) {]b4_push_if([[ if (!yyps->yynew) {]b4_use_push_for_pull_if([], [[ @@ -1559,20 +1830,32 @@ yybackup: yylval = yypushed_val;]b4_locations_if([[ yylloc = yypushed_loc;]])])[ yyread_pushed_token:]])[ - YYDPRINTF ((stderr, "Reading a token: "));]b4_push_if([b4_pure_if([[ + YYDPRINTF ((stderr, "Reading a token\n"));]b4_push_if([b4_pure_if([[ yychar = yypushed_char; if (yypushed_val) yylval = *yypushed_val;]b4_locations_if([[ if (yypushed_loc) yylloc = *yypushed_loc;]])])], [[ - yychar = ]b4_lex[;]])[ + yychar = ]b4_yylex[;]])[ } - if (yychar <= YYEOF) + if (yychar <= ]b4_symbol(eof, [id])[) { - yychar = yytoken = YYEOF; + yychar = ]b4_symbol(eof, [id])[; + yytoken = ]b4_symbol(eof, [kind])[; YYDPRINTF ((stderr, "Now at end of input.\n")); } + else if (yychar == ]b4_symbol(error, [id])[) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = ]b4_symbol(undef, [id])[; + yytoken = ]b4_symbol(error, [kind])[;]b4_locations_if([[ + yyerror_range[1] = yylloc;]])[ + goto yyerrlab1; + } else { yytoken = YYTRANSLATE (yychar); @@ -1592,9 +1875,9 @@ yyread_pushed_token:]])[ if (yyn <= 0) { if (yytable_value_is_error (yyn)) - goto yyerrlab;]b4_lac_if([[ + goto yyerrlab; + yyn = -yyn;]b4_lac_if([[ YY_LAC_ESTABLISH;]])[ - yyn = -yyn; goto yyreduce; } @@ -1605,16 +1888,15 @@ yyread_pushed_token:]])[ /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY;]b4_lac_if([[ - YY_LAC_DISCARD ("shift");]])[ - yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END -]b4_locations_if([ *++yylsp = yylloc;])[ + YY_IGNORE_MAYBE_UNINITIALIZED_END]b4_locations_if([ + *++yylsp = yylloc;])[ + + /* Discard the shifted token. */ + yychar = ]b4_symbol(empty, id)[;]b4_lac_if([[ + YY_LAC_DISCARD ("shift");]])[ goto yynewstate; @@ -1662,7 +1944,7 @@ yyreduce: }]], [[ switch (yyn) { - ]b4_user_actions[ +]b4_user_actions[ default: break; }]])[ /* User semantic actions sometimes alter yychar, and that requires @@ -1676,11 +1958,10 @@ yyreduce: case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval;]b4_locations_if([ *++yylsp = yyloc;])[ @@ -1705,69 +1986,76 @@ yyreduce: yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - + yytoken = yychar == ]b4_symbol(empty, id)[ ? ]b4_symbol(empty, kind)[ : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (]b4_yyerror_args[YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \]b4_lac_if([[ - yyesa, &yyes, &yyes_capacity, \]])[ - yyssp, yytoken) - { +]b4_parse_error_case( + [custom], +[[ { + yypcontext_t yyctx + = {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[};]b4_lac_if([[ + if (yychar != ]b4_symbol(empty, id)[) + YY_LAC_ESTABLISH;]])[ + if (yyreport_syntax_error (&yyctx]m4_ifset([b4_parse_param], + [[, ]b4_args(b4_parse_param)])[) == 2) + YYNOMEM; + }]], + [simple], +[[ yyerror (]b4_yyerror_args[YY_("syntax error"));]], +[[ { + yypcontext_t yyctx + = {]b4_push_if([[yyps]], [[yyssp]b4_lac_if([[, yyesa, &yyes, &yyes_capacity]])])[, yytoken]b4_locations_if([[, &yylloc]])[}; char const *yymsgp = YY_("syntax error"); int yysyntax_error_status;]b4_lac_if([[ - if (yychar != YYEMPTY) + if (yychar != ]b4_symbol(empty, id)[) YY_LAC_ESTABLISH;]])[ - yysyntax_error_status = YYSYNTAX_ERROR; + yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); if (yysyntax_error_status == 0) yymsgp = yymsg; - else if (yysyntax_error_status == 1) + else if (yysyntax_error_status == -1) { if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) + yymsg = YY_CAST (char *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); + if (yymsg) { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; + yysyntax_error_status + = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx); + yymsgp = yymsg; } else { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = YYENOMEM; } } yyerror (]b4_yyerror_args[yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif + if (yysyntax_error_status == YYENOMEM) + YYNOMEM; + }]])[ } - -]b4_locations_if([[ yyerror_range[1] = yylloc;]])[ - +]b4_locations_if([[ + yyerror_range[1] = yylloc;]])[ if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ - if (yychar <= YYEOF) + if (yychar <= ]b4_symbol(eof, [id])[) { /* Return failure if at end of input. */ - if (yychar == YYEOF) + if (yychar == ]b4_symbol(eof, [id])[) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[); - yychar = YYEMPTY; + yychar = ]b4_symbol(empty, id)[; } } @@ -1784,6 +2072,7 @@ yyerrorlab: label yyerrorlab therefore never appears in user code. */ if (0) YYERROR; + ++yynerrs; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -1800,13 +2089,14 @@ yyerrorlab: yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + yyn += ]b4_symbol(error, kind)[; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(error, kind)[) { yyn = yytable[yyn]; if (0 < yyn) @@ -1820,7 +2110,7 @@ yyerrlab1: ]b4_locations_if([[ yyerror_range[1] = *yylsp;]])[ yydestruct ("Error: popping", - yystos[yystate], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); + YY_ACCESSING_SYMBOL (yystate), yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1835,13 +2125,11 @@ yyerrlab1: YY_IGNORE_MAYBE_UNINITIALIZED_END ]b4_locations_if([[ yyerror_range[2] = yylloc; - /* Using YYLLOC is tempting, but would change the location of - the lookahead. YYLOC is available though. */ - YYLLOC_DEFAULT (yyloc, yyerror_range, 2); - *++yylsp = yyloc;]])[ + ++yylsp; + YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);]])[ /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -1852,7 +2140,7 @@ yyerrlab1: `-------------------------------------*/ yyacceptlab: yyresult = 0; - goto yyreturn; + goto yyreturnlab; /*-----------------------------------. @@ -1860,25 +2148,23 @@ yyacceptlab: `-----------------------------------*/ yyabortlab: yyresult = 1; - goto yyreturn; + goto yyreturnlab; -#if ]b4_lac_if([[1]], [[!defined yyoverflow || YYERROR_VERBOSE]])[ -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ +/*-----------------------------------------------------------. +| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | +`-----------------------------------------------------------*/ yyexhaustedlab: yyerror (]b4_yyerror_args[YY_("memory exhausted")); yyresult = 2; - /* Fall through. */ -#endif + goto yyreturnlab; -/*-----------------------------------------------------. -| yyreturn -- parsing is finished, return the result. | -`-----------------------------------------------------*/ -yyreturn: - if (yychar != YYEMPTY) +/*----------------------------------------------------------. +| yyreturnlab -- parsing is finished, clean up and return. | +`----------------------------------------------------------*/ +yyreturnlab: + if (yychar != ]b4_symbol(empty, id)[) { /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ @@ -1893,35 +2179,31 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); YYPOPSTACK (1); - } + }]b4_push_if([[ + yyps->yynew = 2; + goto yypushreturn; + + +/*-------------------------. +| yypushreturn -- return. | +`-------------------------*/ +yypushreturn:]], [[ #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif]b4_lac_if([[ if (yyes != yyesa) - YYSTACK_FREE (yyes);]])b4_push_if([[ - yyps->yynew = 1; - - -/*-----------------------------------------. -| yypushreturn -- ask for the next token. | -`-----------------------------------------*/ -yypushreturn:]])[ -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif + YYSTACK_FREE (yyes);]])])[ +]b4_parse_error_bmatch([detailed\|verbose], +[[ if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg);]])[]m4_ifdef([b4_start_symbols], [[ + if (yyimpl) + yyimpl->yynerrs = yynerrs;]])[ return yyresult; } -]b4_epilogue[]dnl +]b4_push_if([b4_parse_state_variable_macros([b4_macro_undef])])[ +]b4_percent_code_get([[epilogue]])[]dnl +b4_epilogue[]dnl b4_output_end - -b4_defines_if([[ -]b4_output_begin([b4_spec_defines_file])[ -]b4_copyright([Bison interface for Yacc-like parsers in C])[ -]b4_disclaimer[ -]b4_shared_declarations[ -]b4_output_end[ -]])# b4_defines_if diff --git a/tools/flex-bison/windows/bison.exe.sha1 b/tools/flex-bison/windows/bison.exe.sha1 index 8cb5f4fb5..a810f4f97 100644 --- a/tools/flex-bison/windows/bison.exe.sha1 +++ b/tools/flex-bison/windows/bison.exe.sha1 @@ -1 +1 @@ -4a6e1dced61dab2fcd828edbfbfa7eb0215cf2a4 \ No newline at end of file +061b603bf44294decd88febdb111398610f92a87 \ No newline at end of file diff --git a/tools/flex-bison/windows/flex.exe.sha1 b/tools/flex-bison/windows/flex.exe.sha1 index faa78edca..8e3da665c 100644 --- a/tools/flex-bison/windows/flex.exe.sha1 +++ b/tools/flex-bison/windows/flex.exe.sha1 @@ -1 +1 @@ -bc50b3b6e84a30940aa1223f692c9f1fc9bedbf9 \ No newline at end of file +0c624de29f012d318b2e2b055257704fd88077d5 \ No newline at end of file diff --git a/tools/flex-bison/windows/m4.exe.sha1 b/tools/flex-bison/windows/m4.exe.sha1 index 5643dfb3b..eb05726b1 100644 --- a/tools/flex-bison/windows/m4.exe.sha1 +++ b/tools/flex-bison/windows/m4.exe.sha1 @@ -1 +1 @@ -06836e45b05d597d56b74febe3bcfd76e80ef8f8 \ No newline at end of file +4e40328eccb622c73629e488c04460d008752d21 \ No newline at end of file diff --git a/tools/flex-bison/windows/msys-2.0.dll.sha1 b/tools/flex-bison/windows/msys-2.0.dll.sha1 index 98352c746..1c192f79e 100644 --- a/tools/flex-bison/windows/msys-2.0.dll.sha1 +++ b/tools/flex-bison/windows/msys-2.0.dll.sha1 @@ -1 +1 @@ -d0beab7ec77b25ac71bd2d3bf54f4efd39e3947f \ No newline at end of file +d3f9be12ad495666fd5df5375f18d4ed61debbdc \ No newline at end of file diff --git a/tools/flex-bison/windows/msys-iconv-2.dll.sha1 b/tools/flex-bison/windows/msys-iconv-2.dll.sha1 index f52bc4b42..66f0ff90b 100644 --- a/tools/flex-bison/windows/msys-iconv-2.dll.sha1 +++ b/tools/flex-bison/windows/msys-iconv-2.dll.sha1 @@ -1 +1 @@ -0579f1563e220d6121b65a5f4729919cd0cb6af9 \ No newline at end of file +d57393e08051fab9edd79eb148fb184821fcde61 \ No newline at end of file diff --git a/tools/flex-bison/windows/msys-intl-8.dll.sha1 b/tools/flex-bison/windows/msys-intl-8.dll.sha1 index a73592113..ed764ec42 100644 --- a/tools/flex-bison/windows/msys-intl-8.dll.sha1 +++ b/tools/flex-bison/windows/msys-intl-8.dll.sha1 @@ -1 +1 @@ -212a9ef90e21a98ff57ca301a60c84cbeca7be28 \ No newline at end of file +828bf580e9db618cb93067a1bd90fcce6a9d869a \ No newline at end of file