From 6d694a4a581a2d3a6014711c691a23b6dce9badc Mon Sep 17 00:00:00 2001 From: itchyny Date: Wed, 28 Jun 2023 17:59:46 +0900 Subject: Validate module metadata to be an object (#2357) --- src/compile.c | 1 + src/lexer.c | 35 +- src/lexer.h | 11 +- src/parser.c | 2907 +++++++++++++++++++++++++++++++-------------------------- src/parser.h | 127 +-- src/parser.y | 4 + tests/jq.test | 4 + 7 files changed, 1701 insertions(+), 1388 deletions(-) diff --git a/src/compile.c b/src/compile.c index 559bfd0b..b713bc37 100644 --- a/src/compile.c +++ b/src/compile.c @@ -514,6 +514,7 @@ jv block_list_funcs(block body, int omit_underscores) { } block gen_module(block metadata) { + assert(block_is_const(metadata) && block_const_kind(metadata) == JV_KIND_OBJECT); inst* i = inst_new(MODULEMETA); i->imm.constant = block_const(metadata); if (jv_get_kind(i->imm.constant) != JV_KIND_OBJECT) diff --git a/src/lexer.c b/src/lexer.c index 3745819a..764bc73d 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1,6 +1,6 @@ -#line 2 "src/lexer.c" +#line 1 "src/lexer.c" -#line 4 "src/lexer.c" +#line 3 "src/lexer.c" #define YY_INT_ALIGNED short int @@ -281,6 +281,7 @@ typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; +typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; @@ -445,7 +446,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - int yy_n_chars; + yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -522,7 +523,7 @@ static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len , yyscan_t yyscanner ); void *yyalloc ( yy_size_t , yyscan_t yyscanner ); void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); @@ -569,7 +570,7 @@ static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner ); */ #define YY_DO_BEFORE_ACTION \ yyg->yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ + yyleng = (yy_size_t) (yy_cp - yy_bp); \ yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ yyg->yy_c_buf_p = yy_cp; @@ -842,8 +843,8 @@ struct yyguts_t size_t yy_buffer_stack_max; /**< capacity of stack. */ YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ char yy_hold_char; - int yy_n_chars; - int yyleng_r; + yy_size_t yy_n_chars; + yy_size_t yyleng_r; char *yy_c_buf_p; int yy_init; int yy_start; @@ -900,7 +901,7 @@ FILE *yyget_out ( yyscan_t yyscanner ); void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); - int yyget_leng ( yyscan_t yyscanner ); + yy_size_t yyget_leng ( yyscan_t yyscanner ); char *yyget_text ( yyscan_t yyscanner ); @@ -985,7 +986,7 @@ static int input ( yyscan_t yyscanner ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - int n; \ + yy_size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -1636,7 +1637,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else { - int num_to_read = + yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) @@ -1650,7 +1651,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) if ( b->yy_is_our_buffer ) { - int new_size = b->yy_buf_size * 2; + yy_size_t new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1708,7 +1709,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) @@ -1815,7 +1816,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else { /* need more input */ - int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); + yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr; ++yyg->yy_c_buf_p; switch ( yy_get_next_buffer( yyscanner ) ) @@ -2193,12 +2194,12 @@ YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner) * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner) +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner) { YY_BUFFER_STATE b; char *buf; yy_size_t n; - int i; + yy_size_t i; /* Get memory for full buffer, including space for trailing EOB's. */ n = (yy_size_t) (_yybytes_len + 2); @@ -2283,7 +2284,7 @@ static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner) do \ { \ /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ + yy_size_t yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ yytext[yyleng] = yyg->yy_hold_char; \ yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ @@ -2351,7 +2352,7 @@ FILE *yyget_out (yyscan_t yyscanner) /** Get the length of the current token. * @param yyscanner The scanner object. */ -int yyget_leng (yyscan_t yyscanner) +yy_size_t yyget_leng (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; return yyleng; diff --git a/src/lexer.h b/src/lexer.h index 8ad2a44b..8446055b 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -2,9 +2,9 @@ #define jq_yyHEADER_H 1 #define jq_yyIN_HEADER 1 -#line 6 "src/lexer.h" +#line 5 "src/lexer.h" -#line 8 "src/lexer.h" +#line 7 "src/lexer.h" #define YY_INT_ALIGNED short int @@ -285,6 +285,7 @@ typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; +typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; @@ -398,7 +399,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - int yy_n_chars; + yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -442,7 +443,7 @@ void yypop_buffer_state ( yyscan_t yyscanner ); YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len , yyscan_t yyscanner ); void *yyalloc ( yy_size_t , yyscan_t yyscanner ); void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); @@ -500,7 +501,7 @@ FILE *yyget_out ( yyscan_t yyscanner ); void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); - int yyget_leng ( yyscan_t yyscanner ); + yy_size_t yyget_leng ( yyscan_t yyscanner ); char *yyget_text ( yyscan_t yyscanner ); diff --git a/src/parser.c b/src/parser.c index 82bf21d6..28d47c50 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,8 +1,9 @@ -/* A Bison parser, made by GNU Bison 3.0.4. */ +/* 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 Free Software Foundation, Inc. + 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 it under the terms of the GNU General Public License as published by @@ -15,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 @@ -33,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. @@ -40,11 +45,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Identify Bison output. */ -#define YYBISON 1 +/* Identify Bison output, and Bison version. */ +#define YYBISON 30802 -/* Bison version. */ -#define YYBISON_VERSION "3.0.4" +/* Bison version string. */ +#define YYBISON_VERSION "3.8.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -61,8 +66,8 @@ -/* Copy the first part of user declarations. */ -#line 1 "src/parser.y" /* yacc.c:339 */ +/* First part of user prologue. */ +#line 1 "src/parser.y" #include #include @@ -73,26 +78,31 @@ #define YYMALLOC jv_mem_alloc #define YYFREE jv_mem_free -#line 77 "src/parser.c" /* yacc.c:339 */ +#line 82 "src/parser.c" +# 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 && 201103L <= __cplusplus -# define YY_NULLPTR nullptr +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif # else -# define YY_NULLPTR 0 +# define YY_NULLPTR ((void*)0) # endif # endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 1 -#endif - -/* In a future release of Bison, this section will be replaced - by #include "y.tab.h". */ +/* Use api.header.include to #include this header + instead of duplicating it here. */ #ifndef YY_YY_SRC_PARSER_H_INCLUDED # define YY_YY_SRC_PARSER_H_INCLUDED /* Debug traces. */ @@ -103,7 +113,7 @@ extern int yydebug; #endif /* "%code requires" blocks. */ -#line 11 "src/parser.y" /* yacc.c:355 */ +#line 11 "src/parser.y" #include "locfile.h" struct lexer_param; @@ -120,61 +130,70 @@ struct lexer_param; } \ } while (0) -#line 124 "src/parser.c" /* yacc.c:355 */ +#line 134 "src/parser.c" -/* Token type. */ +/* Token kinds. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { - INVALID_CHARACTER = 258, - IDENT = 259, - FIELD = 260, - LITERAL = 261, - FORMAT = 262, - REC = 263, - SETMOD = 264, - EQ = 265, - NEQ = 266, - DEFINEDOR = 267, - AS = 268, - DEF = 269, - MODULE = 270, - IMPORT = 271, - INCLUDE = 272, - IF = 273, - THEN = 274, - ELSE = 275, - ELSE_IF = 276, - REDUCE = 277, - FOREACH = 278, - END = 279, - AND = 280, - OR = 281, - TRY = 282, - CATCH = 283, - LABEL = 284, - BREAK = 285, - LOC = 286, - SETPIPE = 287, - SETPLUS = 288, - SETMINUS = 289, - SETMULT = 290, - SETDIV = 291, - SETDEFINEDOR = 292, - LESSEQ = 293, - GREATEREQ = 294, - ALTERNATION = 295, - QQSTRING_START = 296, - QQSTRING_TEXT = 297, - QQSTRING_INTERP_START = 298, - QQSTRING_INTERP_END = 299, - QQSTRING_END = 300, - FUNCDEF = 301, - NONOPT = 302 + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + INVALID_CHARACTER = 258, /* INVALID_CHARACTER */ + IDENT = 259, /* IDENT */ + FIELD = 260, /* FIELD */ + LITERAL = 261, /* LITERAL */ + FORMAT = 262, /* FORMAT */ + REC = 263, /* ".." */ + SETMOD = 264, /* "%=" */ + EQ = 265, /* "==" */ + NEQ = 266, /* "!=" */ + DEFINEDOR = 267, /* "//" */ + AS = 268, /* "as" */ + DEF = 269, /* "def" */ + MODULE = 270, /* "module" */ + IMPORT = 271, /* "import" */ + INCLUDE = 272, /* "include" */ + IF = 273, /* "if" */ + THEN = 274, /* "then" */ + ELSE = 275, /* "else" */ + ELSE_IF = 276, /* "elif" */ + REDUCE = 277, /* "reduce" */ + FOREACH = 278, /* "foreach" */ + END = 279, /* "end" */ + AND = 280, /* "and" */ + OR = 281, /* "or" */ + TRY = 282, /* "try" */ + CATCH = 283, /* "catch" */ + LABEL = 284, /* "label" */ + BREAK = 285, /* "break" */ + LOC = 286, /* "__loc__" */ + SETPIPE = 287, /* "|=" */ + SETPLUS = 288, /* "+=" */ + SETMINUS = 289, /* "-=" */ + SETMULT = 290, /* "*=" */ + SETDIV = 291, /* "/=" */ + SETDEFINEDOR = 292, /* "//=" */ + LESSEQ = 293, /* "<=" */ + GREATEREQ = 294, /* ">=" */ + ALTERNATION = 295, /* "?//" */ + QQSTRING_START = 296, /* QQSTRING_START */ + QQSTRING_TEXT = 297, /* QQSTRING_TEXT */ + QQSTRING_INTERP_START = 298, /* QQSTRING_INTERP_START */ + QQSTRING_INTERP_END = 299, /* QQSTRING_INTERP_END */ + QQSTRING_END = 300, /* QQSTRING_END */ + FUNCDEF = 301, /* FUNCDEF */ + NONOPT = 302 /* NONOPT */ }; + typedef enum yytokentype yytoken_kind_t; #endif -/* Tokens. */ +/* Token kinds. */ +#define YYEMPTY -2 +#define YYEOF 0 +#define YYerror 256 +#define YYUNDEF 257 #define INVALID_CHARACTER 258 #define IDENT 259 #define FIELD 260 @@ -223,17 +242,16 @@ struct lexer_param; /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED - union YYSTYPE { -#line 31 "src/parser.y" /* yacc.c:355 */ +#line 31 "src/parser.y" jv literal; block blk; -#line 235 "src/parser.c" /* yacc.c:355 */ -}; +#line 253 "src/parser.c" +}; typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 @@ -255,12 +273,120 @@ struct YYLTYPE + int yyparse (block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr); + #endif /* !YY_YY_SRC_PARSER_H_INCLUDED */ +/* 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_INVALID_CHARACTER = 3, /* INVALID_CHARACTER */ + YYSYMBOL_IDENT = 4, /* IDENT */ + YYSYMBOL_FIELD = 5, /* FIELD */ + YYSYMBOL_LITERAL = 6, /* LITERAL */ + YYSYMBOL_FORMAT = 7, /* FORMAT */ + YYSYMBOL_REC = 8, /* ".." */ + YYSYMBOL_SETMOD = 9, /* "%=" */ + YYSYMBOL_EQ = 10, /* "==" */ + YYSYMBOL_NEQ = 11, /* "!=" */ + YYSYMBOL_DEFINEDOR = 12, /* "//" */ + YYSYMBOL_AS = 13, /* "as" */ + YYSYMBOL_DEF = 14, /* "def" */ + YYSYMBOL_MODULE = 15, /* "module" */ + YYSYMBOL_IMPORT = 16, /* "import" */ + YYSYMBOL_INCLUDE = 17, /* "include" */ + YYSYMBOL_IF = 18, /* "if" */ + YYSYMBOL_THEN = 19, /* "then" */ + YYSYMBOL_ELSE = 20, /* "else" */ + YYSYMBOL_ELSE_IF = 21, /* "elif" */ + YYSYMBOL_REDUCE = 22, /* "reduce" */ + YYSYMBOL_FOREACH = 23, /* "foreach" */ + YYSYMBOL_END = 24, /* "end" */ + YYSYMBOL_AND = 25, /* "and" */ + YYSYMBOL_OR = 26, /* "or" */ + YYSYMBOL_TRY = 27, /* "try" */ + YYSYMBOL_CATCH = 28, /* "catch" */ + YYSYMBOL_LABEL = 29, /* "label" */ + YYSYMBOL_BREAK = 30, /* "break" */ + YYSYMBOL_LOC = 31, /* "__loc__" */ + YYSYMBOL_SETPIPE = 32, /* "|=" */ + YYSYMBOL_SETPLUS = 33, /* "+=" */ + YYSYMBOL_SETMINUS = 34, /* "-=" */ + YYSYMBOL_SETMULT = 35, /* "*=" */ + YYSYMBOL_SETDIV = 36, /* "/=" */ + YYSYMBOL_SETDEFINEDOR = 37, /* "//=" */ + YYSYMBOL_LESSEQ = 38, /* "<=" */ + YYSYMBOL_GREATEREQ = 39, /* ">=" */ + YYSYMBOL_ALTERNATION = 40, /* "?//" */ + YYSYMBOL_QQSTRING_START = 41, /* QQSTRING_START */ + YYSYMBOL_QQSTRING_TEXT = 42, /* QQSTRING_TEXT */ + YYSYMBOL_QQSTRING_INTERP_START = 43, /* QQSTRING_INTERP_START */ + YYSYMBOL_QQSTRING_INTERP_END = 44, /* QQSTRING_INTERP_END */ + YYSYMBOL_QQSTRING_END = 45, /* QQSTRING_END */ + YYSYMBOL_FUNCDEF = 46, /* FUNCDEF */ + YYSYMBOL_47_ = 47, /* '|' */ + YYSYMBOL_48_ = 48, /* ',' */ + YYSYMBOL_49_ = 49, /* '=' */ + YYSYMBOL_50_ = 50, /* '<' */ + YYSYMBOL_51_ = 51, /* '>' */ + YYSYMBOL_52_ = 52, /* '+' */ + YYSYMBOL_53_ = 53, /* '-' */ + YYSYMBOL_54_ = 54, /* '*' */ + YYSYMBOL_55_ = 55, /* '/' */ + YYSYMBOL_56_ = 56, /* '%' */ + YYSYMBOL_NONOPT = 57, /* NONOPT */ + YYSYMBOL_58_ = 58, /* '?' */ + YYSYMBOL_59_ = 59, /* ';' */ + YYSYMBOL_60_ = 60, /* '(' */ + YYSYMBOL_61_ = 61, /* ')' */ + YYSYMBOL_62_ = 62, /* '$' */ + YYSYMBOL_63_ = 63, /* ':' */ + YYSYMBOL_64_ = 64, /* '.' */ + YYSYMBOL_65_ = 65, /* '[' */ + YYSYMBOL_66_ = 66, /* ']' */ + YYSYMBOL_67_ = 67, /* '{' */ + YYSYMBOL_68_ = 68, /* '}' */ + YYSYMBOL_YYACCEPT = 69, /* $accept */ + YYSYMBOL_TopLevel = 70, /* TopLevel */ + YYSYMBOL_Module = 71, /* Module */ + YYSYMBOL_Imports = 72, /* Imports */ + YYSYMBOL_FuncDefs = 73, /* FuncDefs */ + YYSYMBOL_Exp = 74, /* Exp */ + YYSYMBOL_Import = 75, /* Import */ + YYSYMBOL_ImportWhat = 76, /* ImportWhat */ + YYSYMBOL_ImportFrom = 77, /* ImportFrom */ + YYSYMBOL_FuncDef = 78, /* FuncDef */ + YYSYMBOL_Params = 79, /* Params */ + YYSYMBOL_Param = 80, /* Param */ + YYSYMBOL_String = 81, /* String */ + YYSYMBOL_82_1 = 82, /* @1 */ + YYSYMBOL_83_2 = 83, /* @2 */ + YYSYMBOL_QQString = 84, /* QQString */ + YYSYMBOL_ElseBody = 85, /* ElseBody */ + YYSYMBOL_ExpD = 86, /* ExpD */ + YYSYMBOL_Term = 87, /* Term */ + YYSYMBOL_Args = 88, /* Args */ + YYSYMBOL_Arg = 89, /* Arg */ + YYSYMBOL_RepPatterns = 90, /* RepPatterns */ + YYSYMBOL_Patterns = 91, /* Patterns */ + YYSYMBOL_Pattern = 92, /* Pattern */ + YYSYMBOL_ArrayPats = 93, /* ArrayPats */ + YYSYMBOL_ObjPats = 94, /* ObjPats */ + YYSYMBOL_ObjPat = 95, /* ObjPat */ + YYSYMBOL_Keyword = 96, /* Keyword */ + YYSYMBOL_MkDict = 97, /* MkDict */ + YYSYMBOL_MkDictPair = 98 /* MkDictPair */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; -/* Copy the second part of user declarations. */ -#line 124 "src/parser.y" /* yacc.c:358 */ + +/* Second part of user prologue. */ +#line 124 "src/parser.y" #include "lexer.h" struct lexer_param { @@ -440,34 +566,94 @@ static block gen_update(block object, block val, int optype) { } -#line 444 "src/parser.c" /* yacc.c:358 */ +#line 570 "src/parser.c" + #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; +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; #else -typedef unsigned short int yytype_uint16; +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 -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; +#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 int yytype_int16; +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 @@ -475,15 +661,28 @@ typedef short int yytype_int16; # 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 -# define YYSIZE_T unsigned int +# define YYSIZE_T unsigned # 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 @@ -497,47 +696,43 @@ typedef short int 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) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif -#endif #ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif #endif #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) -#endif - -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) # else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) +# 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__ && 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 @@ -550,8 +745,22 @@ typedef short int yytype_int16; # 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 -#if ! defined yyoverflow || YYERROR_VERBOSE + +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if 1 /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -616,8 +825,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - +#endif /* 1 */ #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -627,18 +835,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)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \ + + YYSIZEOF (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -651,11 +860,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) @@ -667,12 +876,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]; \ } \ @@ -695,17 +904,20 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 326 -/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned - by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 302 -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#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, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = + as returned by yylex. */ +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, @@ -741,81 +953,79 @@ static const yytype_uint8 yytranslate[] = }; #if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_int16 yyrline[] = { - 0, 306, 306, 309, 314, 317, 328, 331, 336, 339, - 344, 348, 351, 355, 359, 363, 366, 369, 374, 378, - 382, 387, 394, 398, 402, 406, 410, 414, 418, 422, - 426, 430, 434, 438, 442, 446, 450, 454, 458, 464, - 470, 474, 478, 482, 486, 490, 494, 498, 502, 507, - 510, 527, 536, 543, 551, 562, 567, 573, 576, 581, - 585, 589, 596, 596, 600, 600, 607, 610, 613, 619, - 622, 627, 630, 633, 639, 642, 645, 653, 657, 660, - 663, 666, 669, 672, 675, 678, 681, 685, 691, 694, - 697, 700, 703, 706, 709, 712, 715, 718, 721, 724, - 727, 730, 733, 736, 739, 742, 745, 767, 771, 775, - 784, 796, 801, 802, 803, 804, 807, 810, 815, 820, - 823, 828, 831, 836, 840, 843, 848, 851, 856, 859, - 864, 867, 870, 873, 876, 879, 887, 893, 896, 899, - 902, 905, 908, 911, 914, 917, 920, 923, 926, 929, - 932, 935, 938, 941, 944, 947, 952, 955, 956, 957, - 960, 963, 966, 969, 973, 977, 981, 985, 989, 993, - 1001 + 0, 306, 306, 309, 314, 317, 332, 335, 340, 343, + 348, 352, 355, 359, 363, 367, 370, 373, 378, 382, + 386, 391, 398, 402, 406, 410, 414, 418, 422, 426, + 430, 434, 438, 442, 446, 450, 454, 458, 462, 468, + 474, 478, 482, 486, 490, 494, 498, 502, 506, 511, + 514, 531, 540, 547, 555, 566, 571, 577, 580, 585, + 589, 593, 600, 600, 604, 604, 611, 614, 617, 623, + 626, 631, 634, 637, 643, 646, 649, 657, 661, 664, + 667, 670, 673, 676, 679, 682, 685, 689, 695, 698, + 701, 704, 707, 710, 713, 716, 719, 722, 725, 728, + 731, 734, 737, 740, 743, 746, 749, 771, 775, 779, + 788, 800, 805, 806, 807, 808, 811, 814, 819, 824, + 827, 832, 835, 840, 844, 847, 852, 855, 860, 863, + 868, 871, 874, 877, 880, 883, 891, 897, 900, 903, + 906, 909, 912, 915, 918, 921, 924, 927, 930, 933, + 936, 939, 942, 945, 948, 951, 956, 959, 960, 961, + 964, 967, 970, 973, 977, 981, 985, 989, 993, 997, + 1005 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 1 +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if 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; + /* 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", "INVALID_CHARACTER", "IDENT", "FIELD", - "LITERAL", "FORMAT", "\"..\"", "\"%=\"", "\"==\"", "\"!=\"", "\"//\"", - "\"as\"", "\"def\"", "\"module\"", "\"import\"", "\"include\"", "\"if\"", - "\"then\"", "\"else\"", "\"elif\"", "\"reduce\"", "\"foreach\"", - "\"end\"", "\"and\"", "\"or\"", "\"try\"", "\"catch\"", "\"label\"", - "\"break\"", "\"__loc__\"", "\"|=\"", "\"+=\"", "\"-=\"", "\"*=\"", - "\"/=\"", "\"//=\"", "\"<=\"", "\">=\"", "\"?//\"", "QQSTRING_START", - "QQSTRING_TEXT", "QQSTRING_INTERP_START", "QQSTRING_INTERP_END", - "QQSTRING_END", "FUNCDEF", "'|'", "','", "'='", "'<'", "'>'", "'+'", - "'-'", "'*'", "'/'", "'%'", "NONOPT", "'?'", "';'", "'('", "')'", "'$'", - "':'", "'.'", "'['", "']'", "'{'", "'}'", "$accept", "TopLevel", - "Module", "Imports", "FuncDefs", "Exp", "Import", "ImportWhat", - "ImportFrom", "FuncDef", "Params", "Param", "String", "@1", "@2", - "QQString", "ElseBody", "ExpD", "Term", "Args", "Arg", "RepPatterns", - "Patterns", "Pattern", "ArrayPats", "ObjPats", "ObjPat", "Keyword", - "MkDict", "MkDictPair", YY_NULLPTR + "\"end of file\"", "error", "\"invalid token\"", "INVALID_CHARACTER", + "IDENT", "FIELD", "LITERAL", "FORMAT", "\"..\"", "\"%=\"", "\"==\"", + "\"!=\"", "\"//\"", "\"as\"", "\"def\"", "\"module\"", "\"import\"", + "\"include\"", "\"if\"", "\"then\"", "\"else\"", "\"elif\"", + "\"reduce\"", "\"foreach\"", "\"end\"", "\"and\"", "\"or\"", "\"try\"", + "\"catch\"", "\"label\"", "\"break\"", "\"__loc__\"", "\"|=\"", "\"+=\"", + "\"-=\"", "\"*=\"", "\"/=\"", "\"//=\"", "\"<=\"", "\">=\"", "\"?//\"", + "QQSTRING_START", "QQSTRING_TEXT", "QQSTRING_INTERP_START", + "QQSTRING_INTERP_END", "QQSTRING_END", "FUNCDEF", "'|'", "','", "'='", + "'<'", "'>'", "'+'", "'-'", "'*'", "'/'", "'%'", "NONOPT", "'?'", "';'", + "'('", "')'", "'$'", "':'", "'.'", "'['", "']'", "'{'", "'}'", "$accept", + "TopLevel", "Module", "Imports", "FuncDefs", "Exp", "Import", + "ImportWhat", "ImportFrom", "FuncDef", "Params", "Param", "String", "@1", + "@2", "QQString", "ElseBody", "ExpD", "Term", "Args", "Arg", + "RepPatterns", "Patterns", "Pattern", "ArrayPats", "ObjPats", "ObjPat", + "Keyword", "MkDict", "MkDictPair", YY_NULLPTR }; -#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[] = +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) { - 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, 124, 44, 61, - 60, 62, 43, 45, 42, 47, 37, 302, 63, 59, - 40, 41, 36, 58, 46, 91, 93, 123, 125 -}; -# endif + return yytname[yysymbol]; +} +#endif -#define YYPACT_NINF -120 +#define YYPACT_NINF (-120) -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-120))) +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) -#define YYTABLE_NINF -157 +#define YYTABLE_NINF (-157) -#define yytable_value_is_error(Yytable_value) \ - (!!((Yytable_value) == (-157))) +#define yytable_value_is_error(Yyn) \ + ((Yyn) == YYTABLE_NINF) - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ static const yytype_int16 yypact[] = { 13, 775, 14, 49, -55, 11, -120, 7, -120, 32, @@ -853,9 +1063,9 @@ static const yytype_int16 yypact[] = -120, -120, 775, -120, 1357, -120 }; - /* 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. */ +/* 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[] = { 4, 0, 0, 6, 110, 83, 100, 102, 75, 0, @@ -893,7 +1103,7 @@ static const yytype_uint8 yydefact[] = 69, 12, 0, 14, 0, 13 }; - /* YYPGOTO[NTERM-NUM]. */ +/* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { -120, -120, -120, 171, 83, -1, -120, -120, 176, -12, @@ -901,17 +1111,17 @@ static const yytype_int16 yypgoto[] = 22, -120, -16, -119, -120, -120, -68, -18, -105, -120 }; - /* YYDEFGOTO[NTERM-NUM]. */ +/* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - -1, 2, 3, 30, 119, 111, 31, 32, 116, 24, + 0, 2, 3, 30, 119, 111, 31, 32, 116, 24, 201, 202, 25, 44, 128, 137, 258, 218, 26, 126, 127, 184, 185, 186, 228, 234, 235, 82, 83, 84 }; - /* 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. */ +/* 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_int16 yytable[] = { 23, 69, 199, 42, 72, 33, 38, 39, 112, 37, @@ -1350,9 +1560,9 @@ static const yytype_int16 yycheck[] = 28, 29, 30, 31 }; - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = +/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of + state STATE-NUM. */ +static const yytype_int8 yystos[] = { 0, 15, 70, 71, 4, 5, 6, 7, 8, 14, 18, 22, 23, 27, 29, 30, 41, 53, 60, 62, @@ -1389,8 +1599,8 @@ static const yytype_uint8 yystos[] = 85, 61, 59, 61, 74, 61 }; - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = +/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ +static const yytype_int8 yyr1[] = { 0, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, @@ -1412,8 +1622,8 @@ static const yytype_uint8 yyr1[] = 98 }; - /* 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, 3, 3, 0, 3, 0, 2, 0, 2, 2, 5, 9, 11, 9, 5, 5, 4, 4, 2, @@ -1436,39 +1646,39 @@ static const yytype_uint8 yyr2[] = }; +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) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (&yylloc, answer, errors, locations, lexer_param_ptr, YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) - -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (&yylloc, answer, errors, locations, lexer_param_ptr, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* 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 @@ -1512,20 +1722,27 @@ do { \ } 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. */ YY_ATTRIBUTE_UNUSED -static unsigned +static int yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) { - unsigned res = 0; + int res = 0; int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; if (0 <= yylocp->first_line) { @@ -1545,67 +1762,75 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) 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 + /* 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 */ -# 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, Location, answer, errors, locations, lexer_param_ptr); \ + Kind, Value, Location, answer, errors, locations, lexer_param_ptr); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) -/*----------------------------------------. -| Print this symbol's value on YYOUTPUT. | -`----------------------------------------*/ +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr) +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr) { - FILE *yyo = yyoutput; - YYUSE (yyo); - YYUSE (yylocationp); - YYUSE (answer); - YYUSE (errors); - YYUSE (locations); - YYUSE (lexer_param_ptr); + FILE *yyoutput = yyo; + YY_USE (yyoutput); + YY_USE (yylocationp); + YY_USE (answer); + YY_USE (errors); + YY_USE (locations); + YY_USE (lexer_param_ptr); if (!yyvaluep) return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr) +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr) { - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - YY_LOCATION_PRINT (yyoutput, *yylocationp); - YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, answer, errors, locations, lexer_param_ptr); - YYFPRINTF (yyoutput, ")"); + YYLOCATION_PRINT (yyo, yylocationp); + YYFPRINTF (yyo, ": "); + yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp, answer, errors, locations, lexer_param_ptr); + YYFPRINTF (yyo, ")"); } /*------------------------------------------------------------------. @@ -1614,7 +1839,7 @@ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYL `------------------------------------------------------------------*/ static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -1637,21 +1862,22 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr) +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, + int yyrule, block* answer, int* errors, struct locfile* locations, struct lexer_param* lexer_param_ptr) { - unsigned long int 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]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , answer, errors, locations, lexer_param_ptr); + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)], + &(yylsp[(yyi + 1) - (yynrhs)]), answer, errors, locations, lexer_param_ptr); YYFPRINTF (stderr, "\n"); } } @@ -1666,8 +1892,8 @@ do { \ 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 */ @@ -1690,28 +1916,77 @@ int yydebug; #endif -#if YYERROR_VERBOSE +/* Context of a parse error. */ +typedef struct +{ + yy_state_t *yyssp; + yysymbol_kind_t yytoken; + YYLTYPE *yylloc; +} yypcontext_t; + +/* 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. */ +static int +yypcontext_expected_tokens (const yypcontext_t *yyctx, + yysymbol_kind_t yyarg[], int yyargn) +{ + /* Actual size of YYARG. */ + int yycount = 0; + int yyn = yypact[+*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 != YYSYMBOL_YYerror + && !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] = YYSYMBOL_YYEMPTY; + return yycount; +} + + -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else + +#ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +# else /* Return the length of YYSTR. */ -static YYSIZE_T +static YYPTRDIFF_T yystrlen (const char *yystr) { - YYSIZE_T yylen; + 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. */ static char * @@ -1725,10 +2000,10 @@ yystpcpy (char *yydest, const char *yysrc) return yyd - 1; } -# endif # endif +#endif -# ifndef yytnamerr +#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 @@ -1736,14 +2011,13 @@ yystpcpy (char *yydest, const char *yysrc) 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) { @@ -1754,7 +2028,10 @@ yytnamerr (char *yyres, const char *yystr) case '\\': if (*++yyp != '\\') goto do_not_strip_quotes; - /* Fall through. */ + else + goto append; + + append: default: if (yyres) yyres[yyn] = *yyp; @@ -1769,36 +2046,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 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. - 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) +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 @@ -1822,63 +2083,78 @@ 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) - { - 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)) - return 2; - yysize = yysize1; - } - } - } + if (yyctx->yytoken != YYSYMBOL_YYEMPTY) + { + int yyn; + if (yyarg) + yyarg[yycount] = yyctx->yytoken; + ++yycount; + yyn = yypcontext_expected_tokens (yyctx, + yyarg ? yyarg + 1 : yyarg, yyargn - 1); + if (yyn == YYENOMEM) + return YYENOMEM; + 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. + + 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. */ +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")); 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_ +#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)) - return 2; - yysize = yysize1; + int yyi; + for (yyi = 0; yyi < yycount; ++yyi) + { + YYPTRDIFF_T yysize1 + = yysize + yytnamerr (YY_NULLPTR, yytname[yyarg[yyi]]); + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return YYENOMEM; + } } if (*yymsg_alloc < yysize) @@ -1887,7 +2163,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. @@ -1899,226 +2175,226 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **y