Update URLs to prefer https: to http:
[bison.git] / src / parse-gram.c
blob9fe7b45bc20c61bffb1da4c730a534946da9b2d7
1 /* A Bison parser, made by GNU Bison 3.7.4.23-44a69. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
6 Inc.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
48 /* Identify Bison output, and Bison version. */
49 #define YYBISON 30704
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.7.4.23-44a69"
54 /* Skeleton name. */
55 #define YYSKELETON_NAME "yacc.c"
57 /* Pure parsers. */
58 #define YYPURE 2
60 /* Push parsers. */
61 #define YYPUSH 0
63 /* Pull parsers. */
64 #define YYPULL 1
66 /* "%code top" blocks. */
68 /* On column 0 to please syntax-check. */
69 #include <config.h>
71 /* Substitute the type names. */
72 #define YYSTYPE GRAM_STYPE
73 #define YYLTYPE GRAM_LTYPE
74 /* Substitute the variable and function names. */
75 #define yyparse gram_parse
76 #define yylex gram_lex
77 #define yyerror gram_error
78 #define yydebug gram_debug
79 #define yynerrs gram_nerrs
82 # ifndef YY_CAST
83 # ifdef __cplusplus
84 # define YY_CAST(Type, Val) static_cast<Type> (Val)
85 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
86 # else
87 # define YY_CAST(Type, Val) ((Type) (Val))
88 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
89 # endif
90 # endif
91 # ifndef YY_NULLPTR
92 # if defined __cplusplus
93 # if 201103L <= __cplusplus
94 # define YY_NULLPTR nullptr
95 # else
96 # define YY_NULLPTR 0
97 # endif
98 # else
99 # define YY_NULLPTR ((void*)0)
100 # endif
101 # endif
103 #include "src/parse-gram.h"
104 /* Symbol kind. */
105 enum yysymbol_kind_t
107 YYSYMBOL_YYEMPTY = -2,
108 YYSYMBOL_YYEOF = 0, /* "end of file" */
109 YYSYMBOL_YYerror = 1, /* error */
110 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
111 YYSYMBOL_STRING = 3, /* "string" */
112 YYSYMBOL_TSTRING = 4, /* "translatable string" */
113 YYSYMBOL_PERCENT_TOKEN = 5, /* "%token" */
114 YYSYMBOL_PERCENT_NTERM = 6, /* "%nterm" */
115 YYSYMBOL_PERCENT_TYPE = 7, /* "%type" */
116 YYSYMBOL_PERCENT_DESTRUCTOR = 8, /* "%destructor" */
117 YYSYMBOL_PERCENT_PRINTER = 9, /* "%printer" */
118 YYSYMBOL_PERCENT_LEFT = 10, /* "%left" */
119 YYSYMBOL_PERCENT_RIGHT = 11, /* "%right" */
120 YYSYMBOL_PERCENT_NONASSOC = 12, /* "%nonassoc" */
121 YYSYMBOL_PERCENT_PRECEDENCE = 13, /* "%precedence" */
122 YYSYMBOL_PERCENT_PREC = 14, /* "%prec" */
123 YYSYMBOL_PERCENT_DPREC = 15, /* "%dprec" */
124 YYSYMBOL_PERCENT_MERGE = 16, /* "%merge" */
125 YYSYMBOL_PERCENT_CODE = 17, /* "%code" */
126 YYSYMBOL_PERCENT_DEFAULT_PREC = 18, /* "%default-prec" */
127 YYSYMBOL_PERCENT_DEFINE = 19, /* "%define" */
128 YYSYMBOL_PERCENT_DEFINES = 20, /* "%defines" */
129 YYSYMBOL_PERCENT_ERROR_VERBOSE = 21, /* "%error-verbose" */
130 YYSYMBOL_PERCENT_EXPECT = 22, /* "%expect" */
131 YYSYMBOL_PERCENT_EXPECT_RR = 23, /* "%expect-rr" */
132 YYSYMBOL_PERCENT_FLAG = 24, /* "%<flag>" */
133 YYSYMBOL_PERCENT_FILE_PREFIX = 25, /* "%file-prefix" */
134 YYSYMBOL_PERCENT_GLR_PARSER = 26, /* "%glr-parser" */
135 YYSYMBOL_PERCENT_INITIAL_ACTION = 27, /* "%initial-action" */
136 YYSYMBOL_PERCENT_LANGUAGE = 28, /* "%language" */
137 YYSYMBOL_PERCENT_NAME_PREFIX = 29, /* "%name-prefix" */
138 YYSYMBOL_PERCENT_NO_DEFAULT_PREC = 30, /* "%no-default-prec" */
139 YYSYMBOL_PERCENT_NO_LINES = 31, /* "%no-lines" */
140 YYSYMBOL_PERCENT_NONDETERMINISTIC_PARSER = 32, /* "%nondeterministic-parser" */
141 YYSYMBOL_PERCENT_OUTPUT = 33, /* "%output" */
142 YYSYMBOL_PERCENT_PURE_PARSER = 34, /* "%pure-parser" */
143 YYSYMBOL_PERCENT_REQUIRE = 35, /* "%require" */
144 YYSYMBOL_PERCENT_SKELETON = 36, /* "%skeleton" */
145 YYSYMBOL_PERCENT_START = 37, /* "%start" */
146 YYSYMBOL_PERCENT_TOKEN_TABLE = 38, /* "%token-table" */
147 YYSYMBOL_PERCENT_VERBOSE = 39, /* "%verbose" */
148 YYSYMBOL_PERCENT_YACC = 40, /* "%yacc" */
149 YYSYMBOL_BRACED_CODE = 41, /* "{...}" */
150 YYSYMBOL_BRACED_PREDICATE = 42, /* "%?{...}" */
151 YYSYMBOL_BRACKETED_ID = 43, /* "[identifier]" */
152 YYSYMBOL_CHAR_LITERAL = 44, /* "character literal" */
153 YYSYMBOL_COLON = 45, /* ":" */
154 YYSYMBOL_EPILOGUE = 46, /* "epilogue" */
155 YYSYMBOL_EQUAL = 47, /* "=" */
156 YYSYMBOL_ID = 48, /* "identifier" */
157 YYSYMBOL_ID_COLON = 49, /* "identifier:" */
158 YYSYMBOL_PERCENT_PERCENT = 50, /* "%%" */
159 YYSYMBOL_PIPE = 51, /* "|" */
160 YYSYMBOL_PROLOGUE = 52, /* "%{...%}" */
161 YYSYMBOL_SEMICOLON = 53, /* ";" */
162 YYSYMBOL_TAG = 54, /* "<tag>" */
163 YYSYMBOL_TAG_ANY = 55, /* "<*>" */
164 YYSYMBOL_TAG_NONE = 56, /* "<>" */
165 YYSYMBOL_INT_LITERAL = 57, /* "integer literal" */
166 YYSYMBOL_PERCENT_PARAM = 58, /* "%param" */
167 YYSYMBOL_PERCENT_UNION = 59, /* "%union" */
168 YYSYMBOL_PERCENT_EMPTY = 60, /* "%empty" */
169 YYSYMBOL_YYACCEPT = 61, /* $accept */
170 YYSYMBOL_input = 62, /* input */
171 YYSYMBOL_prologue_declarations = 63, /* prologue_declarations */
172 YYSYMBOL_prologue_declaration = 64, /* prologue_declaration */
173 YYSYMBOL_65_1 = 65, /* $@1 */
174 YYSYMBOL_params = 66, /* params */
175 YYSYMBOL_grammar_declaration = 67, /* grammar_declaration */
176 YYSYMBOL_code_props_type = 68, /* code_props_type */
177 YYSYMBOL_union_name = 69, /* union_name */
178 YYSYMBOL_symbol_declaration = 70, /* symbol_declaration */
179 YYSYMBOL_71_2 = 71, /* $@2 */
180 YYSYMBOL_72_3 = 72, /* $@3 */
181 YYSYMBOL_precedence_declarator = 73, /* precedence_declarator */
182 YYSYMBOL_74_tag_opt = 74, /* tag.opt */
183 YYSYMBOL_generic_symlist = 75, /* generic_symlist */
184 YYSYMBOL_generic_symlist_item = 76, /* generic_symlist_item */
185 YYSYMBOL_tag = 77, /* tag */
186 YYSYMBOL_nterm_decls = 78, /* nterm_decls */
187 YYSYMBOL_token_decls = 79, /* token_decls */
188 YYSYMBOL_80_token_decl_1 = 80, /* token_decl.1 */
189 YYSYMBOL_token_decl = 81, /* token_decl */
190 YYSYMBOL_82_int_opt = 82, /* int.opt */
191 YYSYMBOL_alias = 83, /* alias */
192 YYSYMBOL_token_decls_for_prec = 84, /* token_decls_for_prec */
193 YYSYMBOL_85_token_decl_for_prec_1 = 85, /* token_decl_for_prec.1 */
194 YYSYMBOL_token_decl_for_prec = 86, /* token_decl_for_prec */
195 YYSYMBOL_symbol_decls = 87, /* symbol_decls */
196 YYSYMBOL_88_symbol_decl_1 = 88, /* symbol_decl.1 */
197 YYSYMBOL_grammar = 89, /* grammar */
198 YYSYMBOL_rules_or_grammar_declaration = 90, /* rules_or_grammar_declaration */
199 YYSYMBOL_rules = 91, /* rules */
200 YYSYMBOL_92_4 = 92, /* $@4 */
201 YYSYMBOL_93_rhses_1 = 93, /* rhses.1 */
202 YYSYMBOL_rhs = 94, /* rhs */
203 YYSYMBOL_95_named_ref_opt = 95, /* named_ref.opt */
204 YYSYMBOL_variable = 96, /* variable */
205 YYSYMBOL_value = 97, /* value */
206 YYSYMBOL_id = 98, /* id */
207 YYSYMBOL_id_colon = 99, /* id_colon */
208 YYSYMBOL_symbol = 100, /* symbol */
209 YYSYMBOL_string_as_id = 101, /* string_as_id */
210 YYSYMBOL_102_epilogue_opt = 102 /* epilogue.opt */
212 typedef enum yysymbol_kind_t yysymbol_kind_t;
216 /* Unqualified %code blocks. */
218 #include "system.h"
220 #include <c-ctype.h>
221 #include <quotearg.h>
222 #include <vasnprintf.h>
223 #include <xmemdup0.h>
225 #include "complain.h"
226 #include "conflicts.h"
227 #include "files.h"
228 #include "getargs.h"
229 #include "gram.h"
230 #include "named-ref.h"
231 #include "reader.h"
232 #include "scan-code.h"
233 #include "scan-gram.h"
234 #include "strversion.h"
236 /* Pretend to be at least that version, to check features published
237 in that version while developping it. */
238 static const char* api_version = "3.7";
240 static int current_prec = 0;
241 static location current_lhs_loc;
242 static named_ref *current_lhs_named_ref;
243 static symbol *current_lhs_symbol;
244 static symbol_class current_class = unknown_sym;
246 /** Set the new current left-hand side symbol, possibly common
247 * to several right-hand side parts of rule.
249 static void current_lhs (symbol *sym, location loc, named_ref *ref);
251 #define YYLLOC_DEFAULT(Current, Rhs, N) \
252 (Current) = lloc_default (Rhs, N)
253 static YYLTYPE lloc_default (YYLTYPE const *, int);
255 #define YY_LOCATION_PRINT(File, Loc) \
256 location_print (Loc, File)
258 /* Strip initial '{' and final '}' (must be first and last characters).
259 Return the result. */
260 static char *strip_braces (char *code);
262 /* Convert CODE by calling code_props_plain_init if PLAIN, otherwise
263 code_props_symbol_action_init. Calls
264 gram_scanner_last_string_free to release the latest string from
265 the scanner (should be CODE). */
266 static char const *translate_code (char *code, location loc, bool plain);
268 /* Convert CODE by calling code_props_plain_init after having
269 stripped the first and last characters (expected to be '{', and
270 '}'). Calls gram_scanner_last_string_free to release the latest
271 string from the scanner (should be CODE). */
272 static char const *translate_code_braceless (char *code, location loc);
274 /* Handle a %defines directive. */
275 static void handle_defines (char const *value);
277 /* Handle a %error-verbose directive. */
278 static void handle_error_verbose (location const *loc, char const *directive);
280 /* Handle a %file-prefix directive. */
281 static void handle_file_prefix (location const *loc,
282 location const *dir_loc,
283 char const *directive, char const *value);
285 /* Handle a %language directive. */
286 static void handle_language (location const *loc, char const *lang);
288 /* Handle a %name-prefix directive. */
289 static void handle_name_prefix (location const *loc,
290 char const *directive, char const *value);
292 /* Handle a %pure-parser directive. */
293 static void handle_pure_parser (location const *loc, char const *directive);
295 /* Handle a %require directive. */
296 static void handle_require (location const *loc, char const *version);
298 /* Handle a %skeleton directive. */
299 static void handle_skeleton (location const *loc, char const *skel);
301 /* Handle a %yacc directive. */
302 static void handle_yacc (location const *loc);
304 /* Implementation of yyerror. */
305 static void gram_error (location const *, char const *);
307 /* A string that describes a char (e.g., 'a' -> "'a'"). */
308 static char const *char_name (char);
310 /* Add style to semantic values in traces. */
311 static void tron (FILE *yyo);
312 static void troff (FILE *yyo);
314 /* Interpret a quoted string (such as `"Hello, \"World\"\n\""`).
315 Manages the memory of the result. */
316 static char *unquote (const char *str);
318 /* Discard the latest unquoted string. */
319 static void unquote_free (char *last_string);
321 /** Add a lex-param and/or a parse-param.
323 * \param type where to push this formal argument.
324 * \param decl the formal argument. Destroyed.
325 * \param loc the location in the source.
327 static void add_param (param_type type, char *decl, location loc);
328 static param_type current_param = param_none;
331 #ifdef short
332 # undef short
333 #endif
335 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
336 <limits.h> and (if available) <stdint.h> are included
337 so that the code can choose integer types of a good width. */
339 #ifndef __PTRDIFF_MAX__
340 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
341 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
342 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
343 # define YY_STDINT_H
344 # endif
345 #endif
347 /* Narrow types that promote to a signed type and that can represent a
348 signed or unsigned integer of at least N bits. In tables they can
349 save space and decrease cache pressure. Promoting to a signed type
350 helps avoid bugs in integer arithmetic. */
352 #ifdef __INT_LEAST8_MAX__
353 typedef __INT_LEAST8_TYPE__ yytype_int8;
354 #elif defined YY_STDINT_H
355 typedef int_least8_t yytype_int8;
356 #else
357 typedef signed char yytype_int8;
358 #endif
360 #ifdef __INT_LEAST16_MAX__
361 typedef __INT_LEAST16_TYPE__ yytype_int16;
362 #elif defined YY_STDINT_H
363 typedef int_least16_t yytype_int16;
364 #else
365 typedef short yytype_int16;
366 #endif
368 /* Work around bug in HP-UX 11.23, which defines these macros
369 incorrectly for preprocessor constants. This workaround can likely
370 be removed in 2023, as HPE has promised support for HP-UX 11.23
371 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
372 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
373 #ifdef __hpux
374 # undef UINT_LEAST8_MAX
375 # undef UINT_LEAST16_MAX
376 # define UINT_LEAST8_MAX 255
377 # define UINT_LEAST16_MAX 65535
378 #endif
380 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
381 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
382 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
383 && UINT_LEAST8_MAX <= INT_MAX)
384 typedef uint_least8_t yytype_uint8;
385 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
386 typedef unsigned char yytype_uint8;
387 #else
388 typedef short yytype_uint8;
389 #endif
391 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
392 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
393 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
394 && UINT_LEAST16_MAX <= INT_MAX)
395 typedef uint_least16_t yytype_uint16;
396 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
397 typedef unsigned short yytype_uint16;
398 #else
399 typedef int yytype_uint16;
400 #endif
402 #ifndef YYPTRDIFF_T
403 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
404 # define YYPTRDIFF_T __PTRDIFF_TYPE__
405 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
406 # elif defined PTRDIFF_MAX
407 # ifndef ptrdiff_t
408 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
409 # endif
410 # define YYPTRDIFF_T ptrdiff_t
411 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
412 # else
413 # define YYPTRDIFF_T long
414 # define YYPTRDIFF_MAXIMUM LONG_MAX
415 # endif
416 #endif
418 #ifndef YYSIZE_T
419 # ifdef __SIZE_TYPE__
420 # define YYSIZE_T __SIZE_TYPE__
421 # elif defined size_t
422 # define YYSIZE_T size_t
423 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
424 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
425 # define YYSIZE_T size_t
426 # else
427 # define YYSIZE_T unsigned
428 # endif
429 #endif
431 #define YYSIZE_MAXIMUM \
432 YY_CAST (YYPTRDIFF_T, \
433 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
434 ? YYPTRDIFF_MAXIMUM \
435 : YY_CAST (YYSIZE_T, -1)))
437 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
440 /* Stored state numbers (used for stacks). */
441 typedef yytype_uint8 yy_state_t;
443 /* State numbers in computations. */
444 typedef int yy_state_fast_t;
446 #ifndef YY_
447 # if defined YYENABLE_NLS && YYENABLE_NLS
448 # if ENABLE_NLS
449 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
450 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
451 # endif
452 # endif
453 # ifndef YY_
454 # define YY_(Msgid) Msgid
455 # endif
456 #endif
458 #ifndef N_
459 # define N_(Msgid) Msgid
460 #endif
463 #ifndef YY_ATTRIBUTE_PURE
464 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
465 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
466 # else
467 # define YY_ATTRIBUTE_PURE
468 # endif
469 #endif
471 #ifndef YY_ATTRIBUTE_UNUSED
472 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
473 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
474 # else
475 # define YY_ATTRIBUTE_UNUSED
476 # endif
477 #endif
479 /* Suppress unused-variable warnings by "using" E. */
480 #if ! defined lint || defined __GNUC__
481 # define YY_USE(E) ((void) (E))
482 #else
483 # define YY_USE(E) /* empty */
484 #endif
486 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
487 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
488 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
489 _Pragma ("GCC diagnostic push") \
490 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
491 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
492 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
493 _Pragma ("GCC diagnostic pop")
494 #else
495 # define YY_INITIAL_VALUE(Value) Value
496 #endif
497 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
498 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
499 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
500 #endif
501 #ifndef YY_INITIAL_VALUE
502 # define YY_INITIAL_VALUE(Value) /* Nothing. */
503 #endif
505 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
506 # define YY_IGNORE_USELESS_CAST_BEGIN \
507 _Pragma ("GCC diagnostic push") \
508 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
509 # define YY_IGNORE_USELESS_CAST_END \
510 _Pragma ("GCC diagnostic pop")
511 #endif
512 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
513 # define YY_IGNORE_USELESS_CAST_BEGIN
514 # define YY_IGNORE_USELESS_CAST_END
515 #endif
518 #define YY_ASSERT(E) ((void) (0 && (E)))
520 #if 1
522 /* The parser invokes alloca or malloc; define the necessary symbols. */
524 # ifdef YYSTACK_ALLOC
525 /* Pacify GCC's 'empty if-body' warning. */
526 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
527 # ifndef YYSTACK_ALLOC_MAXIMUM
528 /* The OS might guarantee only one guard page at the bottom of the stack,
529 and a page size can be as small as 4096 bytes. So we cannot safely
530 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
531 to allow for a few compiler-allocated temporary stack slots. */
532 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
533 # endif
534 # else
535 # define YYSTACK_ALLOC YYMALLOC
536 # define YYSTACK_FREE YYFREE
537 # ifndef YYSTACK_ALLOC_MAXIMUM
538 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
539 # endif
540 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
541 && ! ((defined YYMALLOC || defined malloc) \
542 && (defined YYFREE || defined free)))
543 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
544 # ifndef EXIT_SUCCESS
545 # define EXIT_SUCCESS 0
546 # endif
547 # endif
548 # ifndef YYMALLOC
549 # define YYMALLOC malloc
550 # if ! defined malloc && ! defined EXIT_SUCCESS
551 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
552 # endif
553 # endif
554 # ifndef YYFREE
555 # define YYFREE free
556 # if ! defined free && ! defined EXIT_SUCCESS
557 void free (void *); /* INFRINGES ON USER NAME SPACE */
558 # endif
559 # endif
560 # endif
561 # define YYCOPY_NEEDED 1
562 #endif /* 1 */
564 #if (! defined yyoverflow \
565 && (! defined __cplusplus \
566 || (defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL \
567 && defined GRAM_STYPE_IS_TRIVIAL && GRAM_STYPE_IS_TRIVIAL)))
569 /* A type that is properly aligned for any stack member. */
570 union yyalloc
572 yy_state_t yyss_alloc;
573 YYSTYPE yyvs_alloc;
574 YYLTYPE yyls_alloc;
577 /* The size of the maximum gap between one aligned stack and the next. */
578 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
580 /* The size of an array large to enough to hold all stacks, each with
581 N elements. */
582 # define YYSTACK_BYTES(N) \
583 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \
584 + YYSIZEOF (YYLTYPE)) \
585 + 2 * YYSTACK_GAP_MAXIMUM)
587 # define YYCOPY_NEEDED 1
589 /* Relocate STACK from its old location to the new one. The
590 local variables YYSIZE and YYSTACKSIZE give the old and new number of
591 elements in the stack, and YYPTR gives the new location of the
592 stack. Advance YYPTR to a properly aligned location for the next
593 stack. */
594 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
595 do \
597 YYPTRDIFF_T yynewbytes; \
598 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
599 Stack = &yyptr->Stack_alloc; \
600 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
601 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
603 while (0)
605 #endif
607 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
608 /* Copy COUNT objects from SRC to DST. The source and destination do
609 not overlap. */
610 # ifndef YYCOPY
611 # if defined __GNUC__ && 1 < __GNUC__
612 # define YYCOPY(Dst, Src, Count) \
613 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
614 # else
615 # define YYCOPY(Dst, Src, Count) \
616 do \
618 YYPTRDIFF_T yyi; \
619 for (yyi = 0; yyi < (Count); yyi++) \
620 (Dst)[yyi] = (Src)[yyi]; \
622 while (0)
623 # endif
624 # endif
625 #endif /* !YYCOPY_NEEDED */
627 /* YYFINAL -- State number of the termination state. */
628 #define YYFINAL 3
629 /* YYLAST -- Last index in YYTABLE. */
630 #define YYLAST 234
632 /* YYNTOKENS -- Number of terminals. */
633 #define YYNTOKENS 61
634 /* YYNNTS -- Number of nonterminals. */
635 #define YYNNTS 42
636 /* YYNRULES -- Number of rules. */
637 #define YYNRULES 123
638 /* YYNSTATES -- Number of states. */
639 #define YYNSTATES 167
641 /* YYMAXUTOK -- Last valid token kind. */
642 #define YYMAXUTOK 315
645 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
646 as returned by yylex, with out-of-bounds checking. */
647 #define YYTRANSLATE(YYX) YY_CAST (yysymbol_kind_t, YYX)
649 #if GRAM_DEBUG
650 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
651 static const yytype_int16 yyrline[] =
653 0, 311, 311, 320, 321, 325, 326, 332, 336, 341,
654 342, 343, 344, 345, 346, 347, 352, 357, 358, 359,
655 360, 361, 362, 362, 363, 364, 365, 366, 367, 368,
656 369, 370, 374, 375, 384, 385, 389, 400, 404, 408,
657 416, 426, 427, 437, 438, 444, 457, 457, 462, 462,
658 467, 471, 481, 482, 483, 484, 488, 489, 494, 495,
659 499, 500, 504, 505, 506, 519, 528, 532, 536, 544,
660 545, 549, 562, 563, 568, 569, 570, 588, 592, 596,
661 604, 606, 611, 618, 628, 632, 636, 644, 649, 661,
662 662, 668, 669, 670, 677, 677, 685, 686, 687, 692,
663 695, 697, 699, 701, 703, 705, 707, 709, 711, 716,
664 717, 726, 750, 751, 752, 753, 765, 767, 791, 796,
665 797, 802, 810, 811
667 #endif
669 /** Accessing symbol of state STATE. */
670 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
672 #if 1
673 /* The user-facing name of the symbol whose (internal) number is
674 YYSYMBOL. No bounds checking. */
675 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
677 static const char *
678 yysymbol_name (yysymbol_kind_t yysymbol)
680 static const char *const yy_sname[] =
682 N_("end of file"), N_("error"), N_("invalid token"), N_("string"),
683 N_("translatable string"), "%token", "%nterm", "%type", "%destructor",
684 "%printer", "%left", "%right", "%nonassoc", "%precedence", "%prec",
685 "%dprec", "%merge", "%code", "%default-prec", "%define", "%defines",
686 "%error-verbose", "%expect", "%expect-rr", "%<flag>", "%file-prefix",
687 "%glr-parser", "%initial-action", "%language", "%name-prefix",
688 "%no-default-prec", "%no-lines", "%nondeterministic-parser", "%output",
689 "%pure-parser", "%require", "%skeleton", "%start", "%token-table",
690 "%verbose", "%yacc", "{...}", "%?{...}", N_("[identifier]"),
691 N_("character literal"), ":", N_("epilogue"), "=", N_("identifier"),
692 N_("identifier:"), "%%", "|", "%{...%}", ";", N_("<tag>"), "<*>", "<>",
693 N_("integer literal"), "%param", "%union", "%empty", "$accept", "input",
694 "prologue_declarations", "prologue_declaration", "$@1", "params",
695 "grammar_declaration", "code_props_type", "union_name",
696 "symbol_declaration", "$@2", "$@3", "precedence_declarator", "tag.opt",
697 "generic_symlist", "generic_symlist_item", "tag", "nterm_decls",
698 "token_decls", "token_decl.1", "token_decl", "int.opt", "alias",
699 "token_decls_for_prec", "token_decl_for_prec.1", "token_decl_for_prec",
700 "symbol_decls", "symbol_decl.1", "grammar",
701 "rules_or_grammar_declaration", "rules", "$@4", "rhses.1", "rhs",
702 "named_ref.opt", "variable", "value", "id", "id_colon", "symbol",
703 "string_as_id", "epilogue.opt", YY_NULLPTR
705 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
706 internationalizable. */
707 static yytype_int8 yytranslatable[] =
709 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
710 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
711 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
712 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
713 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
714 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
717 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
718 ? _(yy_sname[yysymbol])
719 : yy_sname[yysymbol]);
721 #endif
723 #ifdef YYPRINT
724 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
725 (internal) symbol number NUM (which must be that of a token). */
726 static const yytype_int16 yytoknum[] =
728 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
729 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
730 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
731 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
732 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
733 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
736 #endif
738 #define YYPACT_NINF (-80)
740 #define yypact_value_is_default(Yyn) \
741 ((Yyn) == YYPACT_NINF)
743 #define YYTABLE_NINF (-123)
745 #define yytable_value_is_error(Yyn) \
748 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
749 STATE-NUM. */
750 static const yytype_int16 yypact[] =
752 -80, 5, 120, -80, -17, -80, -80, 23, -80, -80,
753 -80, -80, -80, -80, -7, -80, 10, 58, -80, 6,
754 34, -80, 82, -80, 54, 95, 101, -80, -80, -80,
755 103, -80, 105, 107, 24, -80, -80, -80, 175, -80,
756 -80, -80, 64, -80, -80, 75, -80, 61, -80, -15,
757 -15, -80, -80, -80, 24, 63, 24, -80, -80, -80,
758 -80, 77, -80, 46, -80, -80, -80, -80, -80, -80,
759 -80, -80, -80, -80, -80, 67, -80, 69, 7, -80,
760 -80, 80, 93, -80, 94, -1, 24, 108, 24, -80,
761 79, -80, -38, 109, -38, -80, 79, -80, 109, 24,
762 24, -80, -80, -80, -80, -80, -80, -80, -80, 115,
763 -80, -80, -80, -80, -80, 123, -80, -80, -80, -80,
764 -1, -80, -80, -80, 24, 24, -80, -80, -80, -38,
765 -38, -80, 28, 24, -80, 121, -80, -80, 24, -38,
766 -80, -80, -80, -80, -23, 59, -80, -80, 24, 110,
767 111, 112, 114, -80, -80, -80, 127, 80, 59, -80,
768 -80, -80, -80, -80, 80, -80, -80
771 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
772 Performed when YYTABLE does not specify something else to do. Zero
773 means the default is an error. */
774 static const yytype_int8 yydefact[] =
776 3, 0, 0, 1, 0, 48, 46, 0, 41, 42,
777 52, 53, 54, 55, 0, 37, 0, 9, 11, 0,
778 0, 7, 0, 15, 0, 0, 0, 38, 19, 20,
779 0, 24, 0, 0, 0, 27, 28, 29, 0, 6,
780 31, 22, 43, 4, 5, 0, 34, 0, 30, 0,
781 0, 121, 117, 116, 0, 50, 84, 119, 87, 120,
782 39, 0, 111, 112, 10, 12, 13, 14, 16, 17,
783 18, 21, 25, 26, 35, 0, 118, 0, 0, 89,
784 91, 109, 0, 44, 0, 0, 0, 51, 77, 80,
785 72, 83, 0, 49, 66, 69, 72, 47, 65, 85,
786 0, 88, 40, 114, 115, 113, 8, 93, 92, 0,
787 90, 2, 110, 94, 33, 23, 45, 62, 63, 64,
788 36, 58, 61, 60, 78, 0, 81, 73, 82, 67,
789 0, 70, 74, 86, 123, 0, 32, 59, 79, 68,
790 76, 71, 75, 99, 95, 96, 99, 98, 0, 0,
791 0, 0, 0, 102, 57, 103, 0, 109, 97, 104,
792 105, 106, 107, 108, 109, 100, 101
795 /* YYPGOTO[NTERM-NUM]. */
796 static const yytype_int16 yypgoto[] =
798 -80, -80, -80, -80, -80, -80, 172, -80, -80, -80,
799 -80, -80, -80, -80, -80, 55, -80, -80, 139, -54,
800 -59, 81, -80, -80, -65, -79, -80, -31, -80, 113,
801 -80, -80, -80, 44, -67, -80, -80, -46, -80, -34,
802 -36, -80
805 /* YYDEFGOTO[NTERM-NUM]. */
806 static const yytype_uint8 yydefgoto[] =
808 0, 1, 2, 43, 82, 115, 77, 45, 84, 46,
809 50, 49, 47, 156, 120, 121, 122, 97, 93, 94,
810 95, 128, 141, 87, 88, 89, 55, 56, 78, 79,
811 80, 135, 144, 145, 113, 63, 106, 57, 81, 58,
812 59, 111
815 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
816 positive, shift that token. If negative, reduce the rule whose
817 number is the opposite. If YYTABLE_NINF, syntax error. */
818 static const yytype_int16 yytable[] =
820 74, 90, 51, 96, 96, 3, 52, -122, 75, 126,
821 53, 91, 5, 6, 7, 8, 9, 10, 11, 12,
822 13, 124, 101, 99, 14, 15, 51, 51, 146, 52,
823 147, 51, 140, 53, 60, 131, 48, 27, 129, 92,
824 90, 61, 90, 52, 34, 126, 96, 53, 96, 103,
825 91, 123, 91, 117, 118, 119, 76, 109, 62, 126,
826 138, 64, 51, 65, 51, 101, 42, 52, 52, 133,
827 131, 53, 53, 148, 149, 150, 139, 54, 90, 90,
828 131, 151, 152, 96, 96, 67, 123, 104, 91, 91,
829 165, 66, 90, 96, 105, 68, 142, 166, 69, 101,
830 -56, 153, 91, 52, 70, 52, 71, 53, 72, 53,
831 73, 157, 83, 154, 159, 86, 85, 100, 102, 155,
832 107, 4, 108, 112, 157, 5, 6, 7, 8, 9,
833 10, 11, 12, 13, 114, 116, 127, 14, 15, 16,
834 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
835 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
836 37, 134, 125, 130, 136, 161, 143, 160, 164, 162,
837 38, 163, 39, 40, 44, 137, 75, 132, 41, 42,
838 5, 6, 7, 8, 9, 10, 11, 12, 13, 98,
839 158, 110, 14, 15, 0, 0, 0, 0, 0, 0,
840 0, 0, 0, 0, 0, 27, 0, 0, 0, 0,
841 0, 0, 34, 0, 0, 0, 0, 0, 0, 0,
842 0, 0, 0, 0, 76, 0, 0, 0, 0, 0,
843 0, 0, 0, 0, 42
846 static const yytype_int16 yycheck[] =
848 34, 47, 3, 49, 50, 0, 44, 0, 1, 88,
849 48, 47, 5, 6, 7, 8, 9, 10, 11, 12,
850 13, 86, 56, 54, 17, 18, 3, 3, 51, 44,
851 53, 3, 4, 48, 41, 94, 53, 30, 92, 54,
852 86, 48, 88, 44, 37, 124, 92, 48, 94, 3,
853 86, 85, 88, 54, 55, 56, 49, 50, 48, 138,
854 125, 3, 3, 57, 3, 99, 59, 44, 44, 100,
855 129, 48, 48, 14, 15, 16, 130, 54, 124, 125,
856 139, 22, 23, 129, 130, 3, 120, 41, 124, 125,
857 157, 57, 138, 139, 48, 41, 132, 164, 3, 133,
858 41, 42, 138, 44, 3, 44, 3, 48, 3, 48,
859 3, 145, 48, 54, 148, 54, 41, 54, 41, 60,
860 53, 1, 53, 43, 158, 5, 6, 7, 8, 9,
861 10, 11, 12, 13, 41, 41, 57, 17, 18, 19,
862 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
863 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
864 40, 46, 54, 54, 41, 54, 45, 57, 41, 57,
865 50, 57, 52, 53, 2, 120, 1, 96, 58, 59,
866 5, 6, 7, 8, 9, 10, 11, 12, 13, 50,
867 146, 78, 17, 18, -1, -1, -1, -1, -1, -1,
868 -1, -1, -1, -1, -1, 30, -1, -1, -1, -1,
869 -1, -1, 37, -1, -1, -1, -1, -1, -1, -1,
870 -1, -1, -1, -1, 49, -1, -1, -1, -1, -1,
871 -1, -1, -1, -1, 59
874 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
875 symbol of state STATE-NUM. */
876 static const yytype_int8 yystos[] =
878 0, 62, 63, 0, 1, 5, 6, 7, 8, 9,
879 10, 11, 12, 13, 17, 18, 19, 20, 21, 22,
880 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
881 33, 34, 35, 36, 37, 38, 39, 40, 50, 52,
882 53, 58, 59, 64, 67, 68, 70, 73, 53, 72,
883 71, 3, 44, 48, 54, 87, 88, 98, 100, 101,
884 41, 48, 48, 96, 3, 57, 57, 3, 41, 3,
885 3, 3, 3, 3, 100, 1, 49, 67, 89, 90,
886 91, 99, 65, 48, 69, 41, 54, 84, 85, 86,
887 98, 101, 54, 79, 80, 81, 98, 78, 79, 88,
888 54, 100, 41, 3, 41, 48, 97, 53, 53, 50,
889 90, 102, 43, 95, 41, 66, 41, 54, 55, 56,
890 75, 76, 77, 100, 85, 54, 86, 57, 82, 80,
891 54, 81, 82, 88, 46, 92, 41, 76, 85, 80,
892 4, 83, 101, 45, 93, 94, 51, 53, 14, 15,
893 16, 22, 23, 42, 54, 60, 74, 100, 94, 100,
894 57, 54, 57, 57, 41, 95, 95
897 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
898 static const yytype_int8 yyr1[] =
900 0, 61, 62, 63, 63, 64, 64, 64, 64, 64,
901 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
902 64, 64, 65, 64, 64, 64, 64, 64, 64, 64,
903 64, 64, 66, 66, 67, 67, 67, 67, 67, 67,
904 67, 68, 68, 69, 69, 67, 71, 70, 72, 70,
905 70, 70, 73, 73, 73, 73, 74, 74, 75, 75,
906 76, 76, 77, 77, 77, 78, 79, 79, 79, 80,
907 80, 81, 82, 82, 83, 83, 83, 84, 84, 84,
908 85, 85, 86, 86, 87, 87, 87, 88, 88, 89,
909 89, 90, 90, 90, 92, 91, 93, 93, 93, 94,
910 94, 94, 94, 94, 94, 94, 94, 94, 94, 95,
911 95, 96, 97, 97, 97, 97, 98, 98, 99, 100,
912 100, 101, 102, 102
915 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
916 static const yytype_int8 yyr2[] =
918 0, 2, 4, 0, 2, 1, 1, 1, 3, 1,
919 2, 1, 2, 2, 2, 1, 2, 2, 2, 1,
920 1, 2, 0, 3, 1, 2, 2, 1, 1, 1,
921 2, 1, 2, 1, 1, 2, 3, 1, 1, 2,
922 3, 1, 1, 0, 1, 3, 0, 3, 0, 3,
923 2, 2, 1, 1, 1, 1, 0, 1, 1, 2,
924 1, 1, 1, 1, 1, 1, 1, 2, 3, 1,
925 2, 3, 0, 1, 0, 1, 1, 1, 2, 3,
926 1, 2, 2, 1, 1, 2, 3, 1, 2, 1,
927 2, 1, 2, 2, 0, 5, 1, 3, 2, 0,
928 3, 4, 2, 2, 3, 3, 3, 3, 3, 0,
929 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
930 1, 1, 0, 2
934 enum { YYENOMEM = -2 };
936 #define yyerrok (yyerrstatus = 0)
937 #define yyclearin (yychar = GRAM_EMPTY)
939 #define YYACCEPT goto yyacceptlab
940 #define YYABORT goto yyabortlab
941 #define YYERROR goto yyerrorlab
944 #define YYRECOVERING() (!!yyerrstatus)
946 #define YYBACKUP(Token, Value) \
947 do \
948 if (yychar == GRAM_EMPTY) \
950 yychar = (Token); \
951 yylval = (Value); \
952 YYPOPSTACK (yylen); \
953 yystate = *yyssp; \
954 YY_LAC_DISCARD ("YYBACKUP"); \
955 goto yybackup; \
957 else \
959 yyerror (&yylloc, YY_("syntax error: cannot back up")); \
960 YYERROR; \
962 while (0)
964 /* Backward compatibility with an undocumented macro.
965 Use GRAM_error or GRAM_UNDEF. */
966 #define YYERRCODE GRAM_UNDEF
968 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
969 If N is 0, then set CURRENT to the empty location which ends
970 the previous symbol: RHS[0] (always defined). */
972 #ifndef YYLLOC_DEFAULT
973 # define YYLLOC_DEFAULT(Current, Rhs, N) \
974 do \
975 if (N) \
977 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
978 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
979 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
980 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
982 else \
984 (Current).first_line = (Current).last_line = \
985 YYRHSLOC (Rhs, 0).last_line; \
986 (Current).first_column = (Current).last_column = \
987 YYRHSLOC (Rhs, 0).last_column; \
989 while (0)
990 #endif
992 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
995 /* Enable debugging if requested. */
996 #if GRAM_DEBUG
998 # ifndef YYFPRINTF
999 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1000 # define YYFPRINTF fprintf
1001 # endif
1003 # define YYDPRINTF(Args) \
1004 do { \
1005 if (yydebug) \
1006 YYFPRINTF Args; \
1007 } while (0)
1010 /* YY_LOCATION_PRINT -- Print the location on the stream.
1011 This macro was not mandated originally: define only if we know
1012 we won't break user code: when these are the locations we know. */
1014 # ifndef YY_LOCATION_PRINT
1015 # if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
1017 /* Print *YYLOCP on YYO. Private, do not rely on its existence. */
1019 YY_ATTRIBUTE_UNUSED
1020 static int
1021 yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
1023 int res = 0;
1024 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
1025 if (0 <= yylocp->first_line)
1027 res += YYFPRINTF (yyo, "%d", yylocp->first_line);
1028 if (0 <= yylocp->first_column)
1029 res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
1031 if (0 <= yylocp->last_line)
1033 if (yylocp->first_line < yylocp->last_line)
1035 res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
1036 if (0 <= end_col)
1037 res += YYFPRINTF (yyo, ".%d", end_col);
1039 else if (0 <= end_col && yylocp->first_column < end_col)
1040 res += YYFPRINTF (yyo, "-%d", end_col);
1042 return res;
1045 # define YY_LOCATION_PRINT(File, Loc) \
1046 yy_location_print_ (File, &(Loc))
1048 # else
1049 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1050 # endif
1051 # endif /* !defined YY_LOCATION_PRINT */
1054 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
1055 do { \
1056 if (yydebug) \
1058 YYFPRINTF (stderr, "%s ", Title); \
1059 yy_symbol_print (stderr, \
1060 Kind, Value, Location); \
1061 YYFPRINTF (stderr, "\n"); \
1063 } while (0)
1066 /*-----------------------------------.
1067 | Print this symbol's value on YYO. |
1068 `-----------------------------------*/
1070 static void
1071 yy_symbol_value_print (FILE *yyo,
1072 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1074 FILE *yyoutput = yyo;
1075 YY_USE (yyoutput);
1076 YY_USE (yylocationp);
1077 if (!yyvaluep)
1078 return;
1079 # ifdef YYPRINT
1080 if (yykind < YYNTOKENS)
1081 YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
1082 # endif
1083 /* "%code pre-printer" blocks. */
1084 tron (yyo);
1086 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1087 switch (yykind)
1089 case YYSYMBOL_STRING: /* "string" */
1090 { fputs (((*yyvaluep).STRING), yyo); }
1091 break;
1093 case YYSYMBOL_TSTRING: /* "translatable string" */
1094 { fputs (((*yyvaluep).TSTRING), yyo); }
1095 break;
1097 case YYSYMBOL_PERCENT_ERROR_VERBOSE: /* "%error-verbose" */
1098 { fputs (((*yyvaluep).PERCENT_ERROR_VERBOSE), yyo); }
1099 break;
1101 case YYSYMBOL_PERCENT_FLAG: /* "%<flag>" */
1102 { fprintf (yyo, "%%%s", ((*yyvaluep).PERCENT_FLAG)); }
1103 break;
1105 case YYSYMBOL_PERCENT_FILE_PREFIX: /* "%file-prefix" */
1106 { fputs (((*yyvaluep).PERCENT_FILE_PREFIX), yyo); }
1107 break;
1109 case YYSYMBOL_PERCENT_NAME_PREFIX: /* "%name-prefix" */
1110 { fputs (((*yyvaluep).PERCENT_NAME_PREFIX), yyo); }
1111 break;
1113 case YYSYMBOL_PERCENT_PURE_PARSER: /* "%pure-parser" */
1114 { fputs (((*yyvaluep).PERCENT_PURE_PARSER), yyo); }
1115 break;
1117 case YYSYMBOL_BRACED_CODE: /* "{...}" */
1118 { fputs (((*yyvaluep).BRACED_CODE), yyo); }
1119 break;
1121 case YYSYMBOL_BRACED_PREDICATE: /* "%?{...}" */
1122 { fputs (((*yyvaluep).BRACED_PREDICATE), yyo); }
1123 break;
1125 case YYSYMBOL_BRACKETED_ID: /* "[identifier]" */
1126 { fprintf (yyo, "[%s]", ((*yyvaluep).BRACKETED_ID)); }
1127 break;
1129 case YYSYMBOL_CHAR_LITERAL: /* "character literal" */
1130 { fputs (char_name (((*yyvaluep).CHAR_LITERAL)), yyo); }
1131 break;
1133 case YYSYMBOL_EPILOGUE: /* "epilogue" */
1134 { fputs (((*yyvaluep).EPILOGUE), yyo); }
1135 break;
1137 case YYSYMBOL_ID: /* "identifier" */
1138 { fputs (((*yyvaluep).ID), yyo); }
1139 break;
1141 case YYSYMBOL_ID_COLON: /* "identifier:" */
1142 { fprintf (yyo, "%s:", ((*yyvaluep).ID_COLON)); }
1143 break;
1145 case YYSYMBOL_PROLOGUE: /* "%{...%}" */
1146 { fputs (((*yyvaluep).PROLOGUE), yyo); }
1147 break;
1149 case YYSYMBOL_TAG: /* "<tag>" */
1150 { fprintf (yyo, "<%s>", ((*yyvaluep).TAG)); }
1151 break;
1153 case YYSYMBOL_INT_LITERAL: /* "integer literal" */
1154 { fprintf (yyo, "%d", ((*yyvaluep).INT_LITERAL)); }
1155 break;
1157 case YYSYMBOL_PERCENT_PARAM: /* "%param" */
1159 switch (((*yyvaluep).PERCENT_PARAM))
1161 #define CASE(In, Out) \
1162 case param_ ## In: fputs ("%" #Out, yyo); break
1163 CASE (lex, lex-param);
1164 CASE (parse, parse-param);
1165 CASE (both, param);
1166 #undef CASE
1167 case param_none: aver (false); break;
1170 break;
1172 case YYSYMBOL_code_props_type: /* code_props_type */
1173 { fprintf (yyo, "%s", code_props_type_string (((*yyvaluep).code_props_type))); }
1174 break;
1176 case YYSYMBOL_74_tag_opt: /* tag.opt */
1177 { fputs (((*yyvaluep).yykind_74), yyo); }
1178 break;
1180 case YYSYMBOL_generic_symlist: /* generic_symlist */
1181 { symbol_list_syms_print (((*yyvaluep).generic_symlist), yyo); }
1182 break;
1184 case YYSYMBOL_generic_symlist_item: /* generic_symlist_item */
1185 { symbol_list_syms_print (((*yyvaluep).generic_symlist_item), yyo); }
1186 break;
1188 case YYSYMBOL_tag: /* tag */
1189 { fprintf (yyo, "<%s>", ((*yyvaluep).tag)); }
1190 break;
1192 case YYSYMBOL_nterm_decls: /* nterm_decls */
1193 { symbol_list_syms_print (((*yyvaluep).nterm_decls), yyo); }
1194 break;
1196 case YYSYMBOL_token_decls: /* token_decls */
1197 { symbol_list_syms_print (((*yyvaluep).token_decls), yyo); }
1198 break;
1200 case YYSYMBOL_80_token_decl_1: /* token_decl.1 */
1201 { symbol_list_syms_print (((*yyvaluep).yykind_80), yyo); }
1202 break;
1204 case YYSYMBOL_token_decl: /* token_decl */
1205 { fprintf (yyo, "%s", ((*yyvaluep).token_decl) ? ((*yyvaluep).token_decl)->tag : "<NULL>"); }
1206 break;
1208 case YYSYMBOL_82_int_opt: /* int.opt */
1209 { fprintf (yyo, "%d", ((*yyvaluep).yykind_82)); }
1210 break;
1212 case YYSYMBOL_alias: /* alias */
1213 { fprintf (yyo, "%s", ((*yyvaluep).alias) ? ((*yyvaluep).alias)->tag : "<NULL>"); }
1214 break;
1216 case YYSYMBOL_token_decls_for_prec: /* token_decls_for_prec */
1217 { symbol_list_syms_print (((*yyvaluep).token_decls_for_prec), yyo); }
1218 break;
1220 case YYSYMBOL_85_token_decl_for_prec_1: /* token_decl_for_prec.1 */
1221 { symbol_list_syms_print (((*yyvaluep).yykind_85), yyo); }
1222 break;
1224 case YYSYMBOL_token_decl_for_prec: /* token_decl_for_prec */
1225 { fprintf (yyo, "%s", ((*yyvaluep).token_decl_for_prec) ? ((*yyvaluep).token_decl_for_prec)->tag : "<NULL>"); }
1226 break;
1228 case YYSYMBOL_symbol_decls: /* symbol_decls */
1229 { symbol_list_syms_print (((*yyvaluep).symbol_decls), yyo); }
1230 break;
1232 case YYSYMBOL_88_symbol_decl_1: /* symbol_decl.1 */
1233 { symbol_list_syms_print (((*yyvaluep).yykind_88), yyo); }
1234 break;
1236 case YYSYMBOL_variable: /* variable */
1237 { fputs (((*yyvaluep).variable), yyo); }
1238 break;
1240 case YYSYMBOL_value: /* value */
1242 switch (((*yyvaluep).value).kind)
1244 case muscle_code: fprintf (yyo, "{%s}", ((*yyvaluep).value).chars); break;
1245 case muscle_keyword: fprintf (yyo, "%s", ((*yyvaluep).value).chars); break;
1246 case muscle_string: fprintf (yyo, "\"%s\"", ((*yyvaluep).value).chars); break;
1249 break;
1251 case YYSYMBOL_id: /* id */
1252 { fprintf (yyo, "%s", ((*yyvaluep).id) ? ((*yyvaluep).id)->tag : "<NULL>"); }
1253 break;
1255 case YYSYMBOL_id_colon: /* id_colon */
1256 { fprintf (yyo, "%s:", ((*yyvaluep).id_colon)->tag); }
1257 break;
1259 case YYSYMBOL_symbol: /* symbol */
1260 { fprintf (yyo, "%s", ((*yyvaluep).symbol) ? ((*yyvaluep).symbol)->tag : "<NULL>"); }
1261 break;
1263 case YYSYMBOL_string_as_id: /* string_as_id */
1264 { fprintf (yyo, "%s", ((*yyvaluep).string_as_id) ? ((*yyvaluep).string_as_id)->tag : "<NULL>"); }
1265 break;
1267 default:
1268 break;
1270 YY_IGNORE_MAYBE_UNINITIALIZED_END
1271 /* "%code post-printer" blocks. */
1272 troff (yyo);
1277 /*---------------------------.
1278 | Print this symbol on YYO. |
1279 `---------------------------*/
1281 static void
1282 yy_symbol_print (FILE *yyo,
1283 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1285 YYFPRINTF (yyo, "%s %s (",
1286 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
1288 YY_LOCATION_PRINT (yyo, *yylocationp);
1289 YYFPRINTF (yyo, ": ");
1290 yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp);
1291 YYFPRINTF (yyo, ")");
1294 /*------------------------------------------------------------------.
1295 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1296 | TOP (included). |
1297 `------------------------------------------------------------------*/
1299 static void
1300 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
1302 YYFPRINTF (stderr, "Stack now");
1303 for (; yybottom <= yytop; yybottom++)
1305 int yybot = *yybottom;
1306 YYFPRINTF (stderr, " %d", yybot);
1308 YYFPRINTF (stderr, "\n");
1311 # define YY_STACK_PRINT(Bottom, Top) \
1312 do { \
1313 if (yydebug) \
1314 yy_stack_print ((Bottom), (Top)); \
1315 } while (0)
1318 /*------------------------------------------------.
1319 | Report that the YYRULE is going to be reduced. |
1320 `------------------------------------------------*/
1322 static void
1323 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp,
1324 int yyrule)
1326 int yylno = yyrline[yyrule];
1327 int yynrhs = yyr2[yyrule];
1328 int yyi;
1329 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
1330 yyrule - 1, yylno);
1331 /* The symbols being reduced. */
1332 for (yyi = 0; yyi < yynrhs; yyi++)
1334 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1335 yy_symbol_print (stderr,
1336 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
1337 &yyvsp[(yyi + 1) - (yynrhs)],
1338 &(yylsp[(yyi + 1) - (yynrhs)]));
1339 YYFPRINTF (stderr, "\n");
1343 # define YY_REDUCE_PRINT(Rule) \
1344 do { \
1345 if (yydebug) \
1346 yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
1347 } while (0)
1349 /* Nonzero means print parse trace. It is left uninitialized so that
1350 multiple parsers can coexist. */
1351 int yydebug;
1352 #else /* !GRAM_DEBUG */
1353 # define YYDPRINTF(Args) ((void) 0)
1354 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1355 # define YY_STACK_PRINT(Bottom, Top)
1356 # define YY_REDUCE_PRINT(Rule)
1357 #endif /* !GRAM_DEBUG */
1360 /* YYINITDEPTH -- initial size of the parser's stacks. */
1361 #ifndef YYINITDEPTH
1362 # define YYINITDEPTH 200
1363 #endif
1365 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1366 if the built-in stack extension method is used).
1368 Do not make this value too large; the results are undefined if
1369 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1370 evaluated with infinite-precision integer arithmetic. */
1372 #ifndef YYMAXDEPTH
1373 # define YYMAXDEPTH 10000
1374 #endif
1377 /* Given a state stack such that *YYBOTTOM is its bottom, such that
1378 *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty
1379 stack, and such that *YYCAPACITY is the maximum number of elements it
1380 can hold without a reallocation, make sure there is enough room to
1381 store YYADD more elements. If not, allocate a new stack using
1382 YYSTACK_ALLOC, copy the existing elements, and adjust *YYBOTTOM,
1383 *YYTOP, and *YYCAPACITY to reflect the new capacity and memory
1384 location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack
1385 using YYSTACK_FREE. Return 0 if successful or if no reallocation is
1386 required. Return YYENOMEM if memory is exhausted. */
1387 static int
1388 yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd,
1389 #if GRAM_DEBUG
1390 char const *yydebug_prefix,
1391 char const *yydebug_suffix,
1392 #endif
1393 yy_state_t **yybottom,
1394 yy_state_t *yybottom_no_free,
1395 yy_state_t **yytop, yy_state_t *yytop_empty)
1397 YYPTRDIFF_T yysize_old =
1398 *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
1399 YYPTRDIFF_T yysize_new = yysize_old + yyadd;
1400 if (*yycapacity < yysize_new)
1402 YYPTRDIFF_T yyalloc = 2 * yysize_new;
1403 yy_state_t *yybottom_new;
1404 /* Use YYMAXDEPTH for maximum stack size given that the stack
1405 should never need to grow larger than the main state stack
1406 needs to grow without LAC. */
1407 if (YYMAXDEPTH < yysize_new)
1409 YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix,
1410 yydebug_suffix));
1411 return YYENOMEM;
1413 if (YYMAXDEPTH < yyalloc)
1414 yyalloc = YYMAXDEPTH;
1415 yybottom_new =
1416 YY_CAST (yy_state_t *,
1417 YYSTACK_ALLOC (YY_CAST (YYSIZE_T,
1418 yyalloc * YYSIZEOF (*yybottom_new))));
1419 if (!yybottom_new)
1421 YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix,
1422 yydebug_suffix));
1423 return YYENOMEM;
1425 if (*yytop != yytop_empty)
1427 YYCOPY (yybottom_new, *yybottom, yysize_old);
1428 *yytop = yybottom_new + (yysize_old - 1);
1430 if (*yybottom != yybottom_no_free)
1431 YYSTACK_FREE (*yybottom);
1432 *yybottom = yybottom_new;
1433 *yycapacity = yyalloc;
1435 return 0;
1438 /* Establish the initial context for the current lookahead if no initial
1439 context is currently established.
1441 We define a context as a snapshot of the parser stacks. We define
1442 the initial context for a lookahead as the context in which the
1443 parser initially examines that lookahead in order to select a
1444 syntactic action. Thus, if the lookahead eventually proves
1445 syntactically unacceptable (possibly in a later context reached via a
1446 series of reductions), the initial context can be used to determine
1447 the exact set of tokens that would be syntactically acceptable in the
1448 lookahead's place. Moreover, it is the context after which any
1449 further semantic actions would be erroneous because they would be
1450 determined by a syntactically unacceptable token.
1452 YY_LAC_ESTABLISH should be invoked when a reduction is about to be
1453 performed in an inconsistent state (which, for the purposes of LAC,
1454 includes consistent states that don't know they're consistent because
1455 their default reductions have been disabled). Iff there is a
1456 lookahead token, it should also be invoked before reporting a syntax
1457 error. This latter case is for the sake of the debugging output.
1459 For parse.lac=full, the implementation of YY_LAC_ESTABLISH is as
1460 follows. If no initial context is currently established for the
1461 current lookahead, then check if that lookahead can eventually be
1462 shifted if syntactic actions continue from the current context.
1463 Report a syntax error if it cannot. */
1464 #define YY_LAC_ESTABLISH \
1465 do { \
1466 if (!yy_lac_established) \
1468 YYDPRINTF ((stderr, \
1469 "LAC: initial context established for %s\n", \
1470 yysymbol_name (yytoken))); \
1471 yy_lac_established = 1; \
1472 switch (yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken)) \
1474 case YYENOMEM: \
1475 goto yyexhaustedlab; \
1476 case 1: \
1477 goto yyerrlab; \
1480 } while (0)
1482 /* Discard any previous initial lookahead context because of Event,
1483 which may be a lookahead change or an invalidation of the currently
1484 established initial context for the current lookahead.
1486 The most common example of a lookahead change is a shift. An example
1487 of both cases is syntax error recovery. That is, a syntax error
1488 occurs when the lookahead is syntactically erroneous for the
1489 currently established initial context, so error recovery manipulates
1490 the parser stacks to try to find a new initial context in which the
1491 current lookahead is syntactically acceptable. If it fails to find
1492 such a context, it discards the lookahead. */
1493 #if GRAM_DEBUG
1494 # define YY_LAC_DISCARD(Event) \
1495 do { \
1496 if (yy_lac_established) \
1498 YYDPRINTF ((stderr, "LAC: initial context discarded due to " \
1499 Event "\n")); \
1500 yy_lac_established = 0; \
1502 } while (0)
1503 #else
1504 # define YY_LAC_DISCARD(Event) yy_lac_established = 0
1505 #endif
1507 /* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can
1508 eventually (after perhaps some reductions) be shifted, return 1 if
1509 not, or return YYENOMEM if memory is exhausted. As preconditions and
1510 postconditions: *YYES_CAPACITY is the allocated size of the array to
1511 which *YYES points, and either *YYES = YYESA or *YYES points to an
1512 array allocated with YYSTACK_ALLOC. yy_lac may overwrite the
1513 contents of either array, alter *YYES and *YYES_CAPACITY, and free
1514 any old *YYES other than YYESA. */
1515 static int
1516 yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
1517 YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, yysymbol_kind_t yytoken)
1519 yy_state_t *yyes_prev = yyssp;
1520 yy_state_t *yyesp = yyes_prev;
1521 /* Reduce until we encounter a shift and thereby accept the token. */
1522 YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yysymbol_name (yytoken)));
1523 if (yytoken == YYSYMBOL_YYUNDEF)
1525 YYDPRINTF ((stderr, " Always Err\n"));
1526 return 1;
1528 while (1)
1530 int yyrule = yypact[+*yyesp];
1531 if (yypact_value_is_default (yyrule)
1532 || (yyrule += yytoken) < 0 || YYLAST < yyrule
1533 || yycheck[yyrule] != yytoken)
1535 /* Use the default action. */
1536 yyrule = yydefact[+*yyesp];
1537 if (yyrule == 0)
1539 YYDPRINTF ((stderr, " Err\n"));
1540 return 1;
1543 else
1545 /* Use the action from yytable. */
1546 yyrule = yytable[yyrule];
1547 if (yytable_value_is_error (yyrule))
1549 YYDPRINTF ((stderr, " Err\n"));
1550 return 1;
1552 if (0 < yyrule)
1554 YYDPRINTF ((stderr, " S%d\n", yyrule));
1555 return 0;
1557 yyrule = -yyrule;
1559 /* By now we know we have to simulate a reduce. */
1560 YYDPRINTF ((stderr, " R%d", yyrule - 1));
1562 /* Pop the corresponding number of values from the stack. */
1563 YYPTRDIFF_T yylen = yyr2[yyrule];
1564 /* First pop from the LAC stack as many tokens as possible. */
1565 if (yyesp != yyes_prev)
1567 YYPTRDIFF_T yysize = yyesp - *yyes + 1;
1568 if (yylen < yysize)
1570 yyesp -= yylen;
1571 yylen = 0;
1573 else
1575 yyesp = yyes_prev;
1576 yylen -= yysize;
1579 /* Only afterwards look at the main stack. */
1580 if (yylen)
1581 yyesp = yyes_prev -= yylen;
1583 /* Push the resulting state of the reduction. */
1585 yy_state_fast_t yystate;
1587 const int yylhs = yyr1[yyrule] - YYNTOKENS;
1588 const int yyi = yypgoto[yylhs] + *yyesp;
1589 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp
1590 ? yytable[yyi]
1591 : yydefgoto[yylhs]);
1593 if (yyesp == yyes_prev)
1595 yyesp = *yyes;
1596 YY_IGNORE_USELESS_CAST_BEGIN
1597 *yyesp = YY_CAST (yy_state_t, yystate);
1598 YY_IGNORE_USELESS_CAST_END
1600 else
1602 if (yy_lac_stack_realloc (yyes_capacity, 1,
1603 #if GRAM_DEBUG
1604 " (", ")",
1605 #endif
1606 yyes, yyesa, &yyesp, yyes_prev))
1608 YYDPRINTF ((stderr, "\n"));
1609 return YYENOMEM;
1611 YY_IGNORE_USELESS_CAST_BEGIN
1612 *++yyesp = YY_CAST (yy_state_t, yystate);
1613 YY_IGNORE_USELESS_CAST_END
1615 YYDPRINTF ((stderr, " G%d", yystate));
1620 /* Context of a parse error. */
1621 typedef struct
1623 yy_state_t *yyssp;
1624 yy_state_t *yyesa;
1625 yy_state_t **yyes;
1626 YYPTRDIFF_T *yyes_capacity;
1627 yysymbol_kind_t yytoken;
1628 YYLTYPE *yylloc;
1629 } yypcontext_t;
1631 /* Put in YYARG at most YYARGN of the expected tokens given the
1632 current YYCTX, and return the number of tokens stored in YYARG. If
1633 YYARG is null, return the number of expected tokens (guaranteed to
1634 be less than YYNTOKENS). Return YYENOMEM on memory exhaustion.
1635 Return 0 if there are more than YYARGN expected tokens, yet fill
1636 YYARG up to YYARGN. */
1637 static int
1638 yypcontext_expected_tokens (const yypcontext_t *yyctx,
1639 yysymbol_kind_t yyarg[], int yyargn)
1641 /* Actual size of YYARG. */
1642 int yycount = 0;
1644 int yyx;
1645 for (yyx = 0; yyx < YYNTOKENS; ++yyx)
1647 yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx);
1648 if (yysym != YYSYMBOL_YYerror && yysym != YYSYMBOL_YYUNDEF)
1649 switch (yy_lac (yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, yyctx->yyssp, yysym))
1651 case YYENOMEM:
1652 return YYENOMEM;
1653 case 1:
1654 continue;
1655 default:
1656 if (!yyarg)
1657 ++yycount;
1658 else if (yycount == yyargn)
1659 return 0;
1660 else
1661 yyarg[yycount++] = yysym;
1664 if (yyarg && yycount == 0 && 0 < yyargn)
1665 yyarg[0] = YYSYMBOL_YYEMPTY;
1666 return yycount;
1672 /* The kind of the lookahead of this context. */
1673 static yysymbol_kind_t
1674 yypcontext_token (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED;
1676 static yysymbol_kind_t
1677 yypcontext_token (const yypcontext_t *yyctx)
1679 return yyctx->yytoken;
1682 /* The location of the lookahead of this context. */
1683 static YYLTYPE *
1684 yypcontext_location (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED;
1686 static YYLTYPE *
1687 yypcontext_location (const yypcontext_t *yyctx)
1689 return yyctx->yylloc;
1692 /* User defined function to report a syntax error. */
1693 static int
1694 yyreport_syntax_error (const yypcontext_t *yyctx);
1696 /*-----------------------------------------------.
1697 | Release the memory associated to this symbol. |
1698 `-----------------------------------------------*/
1700 static void
1701 yydestruct (const char *yymsg,
1702 yysymbol_kind_t yykind, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1704 YY_USE (yyvaluep);
1705 YY_USE (yylocationp);
1706 if (!yymsg)
1707 yymsg = "Deleting";
1708 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1710 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1711 switch (yykind)
1713 case YYSYMBOL_generic_symlist: /* generic_symlist */
1714 { symbol_list_free (((*yyvaluep).generic_symlist)); }
1715 break;
1717 case YYSYMBOL_generic_symlist_item: /* generic_symlist_item */
1718 { symbol_list_free (((*yyvaluep).generic_symlist_item)); }
1719 break;
1721 case YYSYMBOL_nterm_decls: /* nterm_decls */
1722 { symbol_list_free (((*yyvaluep).nterm_decls)); }
1723 break;
1725 case YYSYMBOL_token_decls: /* token_decls */
1726 { symbol_list_free (((*yyvaluep).token_decls)); }
1727 break;
1729 case YYSYMBOL_80_token_decl_1: /* token_decl.1 */
1730 { symbol_list_free (((*yyvaluep).yykind_80)); }
1731 break;
1733 case YYSYMBOL_token_decls_for_prec: /* token_decls_for_prec */
1734 { symbol_list_free (((*yyvaluep).token_decls_for_prec)); }
1735 break;
1737 case YYSYMBOL_85_token_decl_for_prec_1: /* token_decl_for_prec.1 */
1738 { symbol_list_free (((*yyvaluep).yykind_85)); }
1739 break;
1741 case YYSYMBOL_symbol_decls: /* symbol_decls */
1742 { symbol_list_free (((*yyvaluep).symbol_decls)); }
1743 break;
1745 case YYSYMBOL_88_symbol_decl_1: /* symbol_decl.1 */
1746 { symbol_list_free (((*yyvaluep).yykind_88)); }
1747 break;
1749 default:
1750 break;
1752 YY_IGNORE_MAYBE_UNINITIALIZED_END
1760 /*----------.
1761 | yyparse. |
1762 `----------*/
1765 yyparse (void)
1767 /* Lookahead token kind. */
1768 int yychar;
1771 /* The semantic value of the lookahead symbol. */
1772 /* Default value used for initialization, for pacifying older GCCs
1773 or non-GCC compilers. */
1774 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1775 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1777 /* Location data for the lookahead symbol. */
1778 static YYLTYPE yyloc_default
1779 # if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
1780 = { 1, 1, 1, 1 }
1781 # endif
1783 YYLTYPE yylloc = yyloc_default;
1785 /* Number of syntax errors so far. */
1786 int yynerrs = 0;
1788 yy_state_fast_t yystate = 0;
1789 /* Number of tokens to shift before error messages enabled. */
1790 int yyerrstatus = 0;
1792 /* Refer to the stacks through separate pointers, to allow yyoverflow
1793 to reallocate them elsewhere. */
1795 /* Their size. */
1796 YYPTRDIFF_T yystacksize = YYINITDEPTH;
1798 /* The state stack: array, bottom, top. */
1799 yy_state_t yyssa[YYINITDEPTH];
1800 yy_state_t *yyss = yyssa;
1801 yy_state_t *yyssp = yyss;
1803 /* The semantic value stack: array, bottom, top. */
1804 YYSTYPE yyvsa[YYINITDEPTH];
1805 YYSTYPE *yyvs = yyvsa;
1806 YYSTYPE *yyvsp = yyvs;
1808 /* The location stack: array, bottom, top. */
1809 YYLTYPE yylsa[YYINITDEPTH];
1810 YYLTYPE *yyls = yylsa;
1811 YYLTYPE *yylsp = yyls;
1813 yy_state_t yyesa[20];
1814 yy_state_t *yyes = yyesa;
1815 YYPTRDIFF_T yyes_capacity = 20 < YYMAXDEPTH ? 20 : YYMAXDEPTH;
1817 /* Whether LAC context is established. A Boolean. */
1818 int yy_lac_established = 0;
1819 int yyn;
1820 /* The return value of yyparse. */
1821 int yyresult;
1822 /* Lookahead symbol kind. */
1823 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1824 /* The variables used to return semantic value and location from the
1825 action routines. */
1826 YYSTYPE yyval;
1827 YYLTYPE yyloc;
1829 /* The locations where the error started and ended. */
1830 YYLTYPE yyerror_range[3];
1834 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1836 /* The number of symbols on the RHS of the reduced rule.
1837 Keep to zero when no symbol should be popped. */
1838 int yylen = 0;
1840 YYDPRINTF ((stderr, "Starting parse\n"));
1842 yychar = GRAM_EMPTY; /* Cause a token to be read. */
1844 /* User initialization code. */
1846 /* Bison's grammar can initial empty locations, hence a default
1847 location is needed. */
1848 boundary_set (&yylloc.start, grammar_file, 1, 1, 1);
1849 boundary_set (&yylloc.end, grammar_file, 1, 1, 1);
1853 yylsp[0] = yylloc;
1854 goto yysetstate;
1857 /*------------------------------------------------------------.
1858 | yynewstate -- push a new state, which is found in yystate. |
1859 `------------------------------------------------------------*/
1860 yynewstate:
1861 /* In all cases, when you get here, the value and location stacks
1862 have just been pushed. So pushing a state here evens the stacks. */
1863 yyssp++;
1866 /*--------------------------------------------------------------------.
1867 | yysetstate -- set current state (the top of the stack) to yystate. |
1868 `--------------------------------------------------------------------*/
1869 yysetstate:
1870 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1871 YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1872 YY_IGNORE_USELESS_CAST_BEGIN
1873 *yyssp = YY_CAST (yy_state_t, yystate);
1874 YY_IGNORE_USELESS_CAST_END
1875 YY_STACK_PRINT (yyss, yyssp);
1877 if (yyss + yystacksize - 1 <= yyssp)
1878 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1879 goto yyexhaustedlab;
1880 #else
1882 /* Get the current used size of the three stacks, in elements. */
1883 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1885 # if defined yyoverflow
1887 /* Give user a chance to reallocate the stack. Use copies of
1888 these so that the &'s don't force the real ones into
1889 memory. */
1890 yy_state_t *yyss1 = yyss;
1891 YYSTYPE *yyvs1 = yyvs;
1892 YYLTYPE *yyls1 = yyls;
1894 /* Each stack pointer address is followed by the size of the
1895 data in use in that stack, in bytes. This used to be a
1896 conditional around just the two extra args, but that might
1897 be undefined if yyoverflow is a macro. */
1898 yyoverflow (YY_("memory exhausted"),
1899 &yyss1, yysize * YYSIZEOF (*yyssp),
1900 &yyvs1, yysize * YYSIZEOF (*yyvsp),
1901 &yyls1, yysize * YYSIZEOF (*yylsp),
1902 &yystacksize);
1903 yyss = yyss1;
1904 yyvs = yyvs1;
1905 yyls = yyls1;
1907 # else /* defined YYSTACK_RELOCATE */
1908 /* Extend the stack our own way. */
1909 if (YYMAXDEPTH <= yystacksize)
1910 goto yyexhaustedlab;
1911 yystacksize *= 2;
1912 if (YYMAXDEPTH < yystacksize)
1913 yystacksize = YYMAXDEPTH;
1916 yy_state_t *yyss1 = yyss;
1917 union yyalloc *yyptr =
1918 YY_CAST (union yyalloc *,
1919 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1920 if (! yyptr)
1921 goto yyexhaustedlab;
1922 YYSTACK_RELOCATE (yyss_alloc, yyss);
1923 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1924 YYSTACK_RELOCATE (yyls_alloc, yyls);
1925 # undef YYSTACK_RELOCATE
1926 if (yyss1 != yyssa)
1927 YYSTACK_FREE (yyss1);
1929 # endif
1931 yyssp = yyss + yysize - 1;
1932 yyvsp = yyvs + yysize - 1;
1933 yylsp = yyls + yysize - 1;
1935 YY_IGNORE_USELESS_CAST_BEGIN
1936 YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1937 YY_CAST (long, yystacksize)));
1938 YY_IGNORE_USELESS_CAST_END
1940 if (yyss + yystacksize - 1 <= yyssp)
1941 YYABORT;
1943 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1945 if (yystate == YYFINAL)
1946 YYACCEPT;
1948 goto yybackup;
1951 /*-----------.
1952 | yybackup. |
1953 `-----------*/
1954 yybackup:
1955 /* Do appropriate processing given the current state. Read a
1956 lookahead token if we need one and don't already have one. */
1958 /* First try to decide what to do without reference to lookahead token. */
1959 yyn = yypact[yystate];
1960 if (yypact_value_is_default (yyn))
1961 goto yydefault;
1963 /* Not known => get a lookahead token if don't already have one. */
1965 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1966 if (yychar == GRAM_EMPTY)
1968 YYDPRINTF ((stderr, "Reading a token\n"));
1969 yychar = yylex (&yylval, &yylloc);
1972 if (yychar <= GRAM_EOF)
1974 yychar = GRAM_EOF;
1975 yytoken = YYSYMBOL_YYEOF;
1976 YYDPRINTF ((stderr, "Now at end of input.\n"));
1978 else if (yychar == GRAM_error)
1980 /* The scanner already issued an error message, process directly
1981 to error recovery. But do not keep the error token as
1982 lookahead, it is too special and may lead us to an endless
1983 loop in error recovery. */
1984 yychar = GRAM_UNDEF;
1985 yytoken = YYSYMBOL_YYerror;
1986 yyerror_range[1] = yylloc;
1987 goto yyerrlab1;
1989 else
1991 yytoken = YYTRANSLATE (yychar);
1992 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1995 /* If the proper action on seeing token YYTOKEN is to reduce or to
1996 detect an error, take that action. */
1997 yyn += yytoken;
1998 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2000 YY_LAC_ESTABLISH;
2001 goto yydefault;
2003 yyn = yytable[yyn];
2004 if (yyn <= 0)
2006 if (yytable_value_is_error (yyn))
2007 goto yyerrlab;
2008 YY_LAC_ESTABLISH;
2009 yyn = -yyn;
2010 goto yyreduce;
2013 /* Count tokens shifted since error; after three, turn off error
2014 status. */
2015 if (yyerrstatus)
2016 yyerrstatus--;
2018 /* Shift the lookahead token. */
2019 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2020 yystate = yyn;
2021 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2022 *++yyvsp = yylval;
2023 YY_IGNORE_MAYBE_UNINITIALIZED_END
2024 *++yylsp = yylloc;
2026 /* Discard the shifted token. */
2027 yychar = GRAM_EMPTY;
2028 YY_LAC_DISCARD ("shift");
2029 goto yynewstate;
2032 /*-----------------------------------------------------------.
2033 | yydefault -- do the default action for the current state. |
2034 `-----------------------------------------------------------*/
2035 yydefault:
2036 yyn = yydefact[yystate];
2037 if (yyn == 0)
2038 goto yyerrlab;
2039 goto yyreduce;
2042 /*-----------------------------.
2043 | yyreduce -- do a reduction. |
2044 `-----------------------------*/
2045 yyreduce:
2046 /* yyn is the number of a rule to reduce with. */
2047 yylen = yyr2[yyn];
2049 /* If YYLEN is nonzero, implement the default value of the action:
2050 '$$ = $1'.
2052 Otherwise, the following line sets YYVAL to garbage.
2053 This behavior is undocumented and Bison
2054 users should not rely upon it. Assigning to YYVAL
2055 unconditionally makes the parser a bit smaller, and it avoids a
2056 GCC warning that YYVAL may be used uninitialized. */
2057 yyval = yyvsp[1-yylen];
2059 /* Default location. */
2060 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
2061 yyerror_range[1] = yyloc;
2062 YY_REDUCE_PRINT (yyn);
2064 int yychar_backup = yychar;
2065 switch (yyn)
2067 case 6: /* prologue_declaration: "%{...%}" */
2069 muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue",
2070 translate_code ((yyvsp[0].PROLOGUE), (yylsp[0]), true), (yylsp[0]));
2071 code_scanner_last_string_free ();
2073 break;
2075 case 7: /* prologue_declaration: "%<flag>" */
2077 muscle_percent_define_ensure ((yyvsp[0].PERCENT_FLAG), (yylsp[0]), true);
2079 break;
2081 case 8: /* prologue_declaration: "%define" variable value */
2083 muscle_percent_define_insert ((yyvsp[-1].variable), (yyloc), (yyvsp[0].value).kind, (yyvsp[0].value).chars,
2084 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
2086 break;
2088 case 9: /* prologue_declaration: "%defines" */
2089 { defines_flag = true; }
2090 break;
2092 case 10: /* prologue_declaration: "%defines" "string" */
2093 { handle_defines ((yyvsp[0].STRING)); }
2094 break;
2096 case 11: /* prologue_declaration: "%error-verbose" */
2097 { handle_error_verbose (&(yyloc), (yyvsp[0].PERCENT_ERROR_VERBOSE)); }
2098 break;
2100 case 12: /* prologue_declaration: "%expect" "integer literal" */
2101 { expected_sr_conflicts = (yyvsp[0].INT_LITERAL); }
2102 break;
2104 case 13: /* prologue_declaration: "%expect-rr" "integer literal" */
2105 { expected_rr_conflicts = (yyvsp[0].INT_LITERAL); }
2106 break;
2108 case 14: /* prologue_declaration: "%file-prefix" "string" */
2109 { handle_file_prefix (&(yyloc), &(yylsp[-1]), (yyvsp[-1].PERCENT_FILE_PREFIX), (yyvsp[0].STRING)); }
2110 break;
2112 case 15: /* prologue_declaration: "%glr-parser" */
2114 nondeterministic_parser = true;
2115 glr_parser = true;
2117 break;
2119 case 16: /* prologue_declaration: "%initial-action" "{...}" */
2121 muscle_code_grow ("initial_action", translate_code ((yyvsp[0].BRACED_CODE), (yylsp[0]), false), (yylsp[0]));
2122 code_scanner_last_string_free ();
2124 break;
2126 case 17: /* prologue_declaration: "%language" "string" */
2127 { handle_language (&(yylsp[-1]), (yyvsp[0].STRING)); }
2128 break;
2130 case 18: /* prologue_declaration: "%name-prefix" "string" */
2131 { handle_name_prefix (&(yyloc), (yyvsp[-1].PERCENT_NAME_PREFIX), (yyvsp[0].STRING)); }
2132 break;
2134 case 19: /* prologue_declaration: "%no-lines" */
2135 { no_lines_flag = true; }
2136 break;
2138 case 20: /* prologue_declaration: "%nondeterministic-parser" */
2139 { nondeterministic_parser = true; }
2140 break;
2142 case 21: /* prologue_declaration: "%output" "string" */
2143 { spec_outfile = unquote ((yyvsp[0].STRING)); gram_scanner_last_string_free (); }
2144 break;
2146 case 22: /* $@1: %empty */
2147 { current_param = (yyvsp[0].PERCENT_PARAM); }
2148 break;
2150 case 23: /* prologue_declaration: "%param" $@1 params */
2151 { current_param = param_none; }
2152 break;
2154 case 24: /* prologue_declaration: "%pure-parser" */
2155 { handle_pure_parser (&(yyloc), (yyvsp[0].PERCENT_PURE_PARSER)); }
2156 break;
2158 case 25: /* prologue_declaration: "%require" "string" */
2159 { handle_require (&(yylsp[0]), (yyvsp[0].STRING)); }
2160 break;
2162 case 26: /* prologue_declaration: "%skeleton" "string" */
2163 { handle_skeleton (&(yylsp[0]), (yyvsp[0].STRING)); }
2164 break;
2166 case 27: /* prologue_declaration: "%token-table" */
2167 { token_table_flag = true; }
2168 break;
2170 case 28: /* prologue_declaration: "%verbose" */
2171 { report_flag |= report_states; }
2172 break;
2174 case 29: /* prologue_declaration: "%yacc" */
2175 { handle_yacc (&(yyloc)); }
2176 break;
2178 case 30: /* prologue_declaration: error ";" */
2179 { current_class = unknown_sym; yyerrok; }
2180 break;
2182 case 32: /* params: params "{...}" */
2183 { add_param (current_param, (yyvsp[0].BRACED_CODE), (yylsp[0])); }
2184 break;
2186 case 33: /* params: "{...}" */
2187 { add_param (current_param, (yyvsp[0].BRACED_CODE), (yylsp[0])); }
2188 break;
2190 case 35: /* grammar_declaration: "%start" symbol */
2192 grammar_start_symbol_set ((yyvsp[0].symbol), (yylsp[0]));
2194 break;
2196 case 36: /* grammar_declaration: code_props_type "{...}" generic_symlist */
2198 code_props code;
2199 code_props_symbol_action_init (&code, (yyvsp[-1].BRACED_CODE), (yylsp[-1]));
2200 code_props_translate_code (&code);
2202 for (symbol_list *list = (yyvsp[0].generic_symlist); list; list = list->next)
2203 symbol_list_code_props_set (list, (yyvsp[-2].code_props_type), &code);
2204 symbol_list_free ((yyvsp[0].generic_symlist));
2207 break;
2209 case 37: /* grammar_declaration: "%default-prec" */
2211 default_prec = true;
2213 break;
2215 case 38: /* grammar_declaration: "%no-default-prec" */
2217 default_prec = false;
2219 break;
2221 case 39: /* grammar_declaration: "%code" "{...}" */
2223 /* Do not invoke muscle_percent_code_grow here since it invokes
2224 muscle_user_name_list_grow. */
2225 muscle_code_grow ("percent_code()",
2226 translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0]));
2227 code_scanner_last_string_free ();
2229 break;
2231 case 40: /* grammar_declaration: "%code" "identifier" "{...}" */
2233 muscle_percent_code_grow ((yyvsp[-1].ID), (yylsp[-1]), translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0]));
2234 code_scanner_last_string_free ();
2236 break;
2238 case 41: /* code_props_type: "%destructor" */
2239 { (yyval.code_props_type) = destructor; }
2240 break;
2242 case 42: /* code_props_type: "%printer" */
2243 { (yyval.code_props_type) = printer; }
2244 break;
2246 case 43: /* union_name: %empty */
2248 break;
2250 case 44: /* union_name: "identifier" */
2251 { muscle_percent_define_insert ("api.value.union.name",
2252 (yylsp[0]), muscle_keyword, (yyvsp[0].ID),
2253 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); }
2254 break;
2256 case 45: /* grammar_declaration: "%union" union_name "{...}" */
2258 union_seen = true;
2259 muscle_code_grow ("union_members", translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0]));
2260 code_scanner_last_string_free ();
2262 break;
2264 case 46: /* $@2: %empty */
2265 { current_class = nterm_sym; }
2266 break;
2268 case 47: /* symbol_declaration: "%nterm" $@2 nterm_decls */
2270 current_class = unknown_sym;
2271 symbol_list_free ((yyvsp[0].nterm_decls));
2273 break;
2275 case 48: /* $@3: %empty */
2276 { current_class = token_sym; }
2277 break;
2279 case 49: /* symbol_declaration: "%token" $@3 token_decls */
2281 current_class = unknown_sym;
2282 symbol_list_free ((yyvsp[0].token_decls));
2284 break;
2286 case 50: /* symbol_declaration: "%type" symbol_decls */
2288 symbol_list_free ((yyvsp[0].symbol_decls));
2290 break;
2292 case 51: /* symbol_declaration: precedence_declarator token_decls_for_prec */
2294 ++current_prec;
2295 for (symbol_list *list = (yyvsp[0].token_decls_for_prec); list; list = list->next)
2296 symbol_precedence_set (list->content.sym, current_prec, (yyvsp[-1].precedence_declarator), (yylsp[-1]));
2297 symbol_list_free ((yyvsp[0].token_decls_for_prec));
2299 break;
2301 case 52: /* precedence_declarator: "%left" */
2302 { (yyval.precedence_declarator) = left_assoc; }
2303 break;
2305 case 53: /* precedence_declarator: "%right" */
2306 { (yyval.precedence_declarator) = right_assoc; }
2307 break;
2309 case 54: /* precedence_declarator: "%nonassoc" */
2310 { (yyval.precedence_declarator) = non_assoc; }
2311 break;
2313 case 55: /* precedence_declarator: "%precedence" */
2314 { (yyval.precedence_declarator) = precedence_assoc; }
2315 break;
2317 case 56: /* tag.opt: %empty */
2318 { (yyval.yykind_74) = NULL; }
2319 break;
2321 case 57: /* tag.opt: "<tag>" */
2322 { (yyval.yykind_74) = (yyvsp[0].TAG); }
2323 break;
2325 case 59: /* generic_symlist: generic_symlist generic_symlist_item */
2326 { (yyval.generic_symlist) = symbol_list_append ((yyvsp[-1].generic_symlist), (yyvsp[0].generic_symlist_item)); }
2327 break;
2329 case 60: /* generic_symlist_item: symbol */
2330 { (yyval.generic_symlist_item) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); }
2331 break;
2333 case 61: /* generic_symlist_item: tag */
2334 { (yyval.generic_symlist_item) = symbol_list_type_new ((yyvsp[0].tag), (yylsp[0])); }
2335 break;
2337 case 63: /* tag: "<*>" */
2338 { (yyval.tag) = uniqstr_new ("*"); }
2339 break;
2341 case 64: /* tag: "<>" */
2342 { (yyval.tag) = uniqstr_new (""); }
2343 break;
2345 case 66: /* token_decls: token_decl.1 */
2347 (yyval.token_decls) = (yyvsp[0].yykind_80);
2349 break;
2351 case 67: /* token_decls: "<tag>" token_decl.1 */
2353 (yyval.token_decls) = symbol_list_type_set ((yyvsp[0].yykind_80), (yyvsp[-1].TAG));
2355 break;
2357 case 68: /* token_decls: token_decls "<tag>" token_decl.1 */
2359 (yyval.token_decls) = symbol_list_append ((yyvsp[-2].token_decls), symbol_list_type_set ((yyvsp[0].yykind_80), (yyvsp[-1].TAG)));
2361 break;
2363 case 69: /* token_decl.1: token_decl */
2364 { (yyval.yykind_80) = symbol_list_sym_new ((yyvsp[0].token_decl), (yylsp[0])); }
2365 break;
2367 case 70: /* token_decl.1: token_decl.1 token_decl */
2368 { (yyval.yykind_80) = symbol_list_append ((yyvsp[-1].yykind_80), symbol_list_sym_new ((yyvsp[0].token_decl), (yylsp[0]))); }
2369 break;
2371 case 71: /* token_decl: id int.opt alias */
2373 (yyval.token_decl) = (yyvsp[-2].id);
2374 symbol_class_set ((yyvsp[-2].id), current_class, (yylsp[-2]), true);
2375 if (0 <= (yyvsp[-1].yykind_82))
2376 symbol_code_set ((yyvsp[-2].id), (yyvsp[-1].yykind_82), (yylsp[-1]));
2377 if ((yyvsp[0].alias))
2378 symbol_make_alias ((yyvsp[-2].id), (yyvsp[0].alias), (yylsp[0]));
2380 break;
2382 case 72: /* int.opt: %empty */
2383 { (yyval.yykind_82) = -1; }
2384 break;
2386 case 74: /* alias: %empty */
2387 { (yyval.alias) = NULL; }
2388 break;
2390 case 75: /* alias: string_as_id */
2391 { (yyval.alias) = (yyvsp[0].string_as_id); }
2392 break;
2394 case 76: /* alias: "translatable string" */
2396 (yyval.alias) = symbol_get ((yyvsp[0].TSTRING), (yylsp[0]));
2397 symbol_class_set ((yyval.alias), token_sym, (yylsp[0]), false);
2398 (yyval.alias)->translatable = true;
2400 break;
2402 case 77: /* token_decls_for_prec: token_decl_for_prec.1 */
2404 (yyval.token_decls_for_prec) = (yyvsp[0].yykind_85);
2406 break;
2408 case 78: /* token_decls_for_prec: "<tag>" token_decl_for_prec.1 */
2410 (yyval.token_decls_for_prec) = symbol_list_type_set ((yyvsp[0].yykind_85), (yyvsp[-1].TAG));
2412 break;
2414 case 79: /* token_decls_for_prec: token_decls_for_prec "<tag>" token_decl_for_prec.1 */
2416 (yyval.token_decls_for_prec) = symbol_list_append ((yyvsp[-2].token_decls_for_prec), symbol_list_type_set ((yyvsp[0].yykind_85), (yyvsp[-1].TAG)));
2418 break;
2420 case 80: /* token_decl_for_prec.1: token_decl_for_prec */
2421 { (yyval.yykind_85) = symbol_list_sym_new ((yyvsp[0].token_decl_for_prec), (yylsp[0])); }
2422 break;
2424 case 81: /* token_decl_for_prec.1: token_decl_for_prec.1 token_decl_for_prec */
2425 { (yyval.yykind_85) = symbol_list_append ((yyvsp[-1].yykind_85), symbol_list_sym_new ((yyvsp[0].token_decl_for_prec), (yylsp[0]))); }
2426 break;
2428 case 82: /* token_decl_for_prec: id int.opt */
2430 (yyval.token_decl_for_prec) = (yyvsp[-1].id);
2431 symbol_class_set ((yyvsp[-1].id), token_sym, (yylsp[-1]), false);
2432 if (0 <= (yyvsp[0].yykind_82))
2433 symbol_code_set ((yyvsp[-1].id), (yyvsp[0].yykind_82), (yylsp[0]));
2435 break;
2437 case 84: /* symbol_decls: symbol_decl.1 */
2439 (yyval.symbol_decls) = (yyvsp[0].yykind_88);
2441 break;
2443 case 85: /* symbol_decls: "<tag>" symbol_decl.1 */
2445 (yyval.symbol_decls) = symbol_list_type_set ((yyvsp[0].yykind_88), (yyvsp[-1].TAG));
2447 break;
2449 case 86: /* symbol_decls: symbol_decls "<tag>" symbol_decl.1 */
2451 (yyval.symbol_decls) = symbol_list_append ((yyvsp[-2].symbol_decls), symbol_list_type_set ((yyvsp[0].yykind_88), (yyvsp[-1].TAG)));
2453 break;
2455 case 87: /* symbol_decl.1: symbol */
2457 symbol_class_set ((yyvsp[0].symbol), pct_type_sym, (yylsp[0]), false);
2458 (yyval.yykind_88) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]));
2460 break;
2462 case 88: /* symbol_decl.1: symbol_decl.1 symbol */
2464 symbol_class_set ((yyvsp[0].symbol), pct_type_sym, (yylsp[0]), false);
2465 (yyval.yykind_88) = symbol_list_append ((yyvsp[-1].yykind_88), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])));
2467 break;
2469 case 93: /* rules_or_grammar_declaration: error ";" */
2471 yyerrok;
2473 break;
2475 case 94: /* $@4: %empty */
2476 { current_lhs ((yyvsp[-1].id_colon), (yylsp[-1]), (yyvsp[0].yykind_95)); }
2477 break;
2479 case 95: /* rules: id_colon named_ref.opt $@4 ":" rhses.1 */
2481 /* Free the current lhs. */
2482 current_lhs (0, (yylsp[-4]), 0);
2484 break;
2486 case 96: /* rhses.1: rhs */
2487 { grammar_current_rule_end ((yylsp[0])); }
2488 break;
2490 case 97: /* rhses.1: rhses.1 "|" rhs */
2491 { grammar_current_rule_end ((yylsp[0])); }
2492 break;
2494 case 99: /* rhs: %empty */
2495 { grammar_current_rule_begin (current_lhs_symbol, current_lhs_loc,
2496 current_lhs_named_ref); }
2497 break;
2499 case 100: /* rhs: rhs symbol named_ref.opt */
2500 { grammar_current_rule_symbol_append ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].yykind_95)); }
2501 break;
2503 case 101: /* rhs: rhs tag.opt "{...}" named_ref.opt */
2504 { grammar_current_rule_action_append ((yyvsp[-1].BRACED_CODE), (yylsp[-1]), (yyvsp[0].yykind_95), (yyvsp[-2].yykind_74)); }
2505 break;
2507 case 102: /* rhs: rhs "%?{...}" */
2508 { grammar_current_rule_predicate_append ((yyvsp[0].BRACED_PREDICATE), (yylsp[0])); }
2509 break;
2511 case 103: /* rhs: rhs "%empty" */
2512 { grammar_current_rule_empty_set ((yylsp[0])); }
2513 break;
2515 case 104: /* rhs: rhs "%prec" symbol */
2516 { grammar_current_rule_prec_set ((yyvsp[0].symbol), (yylsp[0])); }
2517 break;
2519 case 105: /* rhs: rhs "%dprec" "integer literal" */
2520 { grammar_current_rule_dprec_set ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
2521 break;
2523 case 106: /* rhs: rhs "%merge" "<tag>" */
2524 { grammar_current_rule_merge_set ((yyvsp[0].TAG), (yylsp[0])); }
2525 break;
2527 case 107: /* rhs: rhs "%expect" "integer literal" */
2528 { grammar_current_rule_expect_sr ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
2529 break;
2531 case 108: /* rhs: rhs "%expect-rr" "integer literal" */
2532 { grammar_current_rule_expect_rr ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
2533 break;
2535 case 109: /* named_ref.opt: %empty */
2536 { (yyval.yykind_95) = NULL; }
2537 break;
2539 case 110: /* named_ref.opt: "[identifier]" */
2540 { (yyval.yykind_95) = named_ref_new ((yyvsp[0].BRACKETED_ID), (yylsp[0])); }
2541 break;
2543 case 112: /* value: %empty */
2544 { (yyval.value).kind = muscle_keyword; (yyval.value).chars = ""; }
2545 break;
2547 case 113: /* value: "identifier" */
2548 { (yyval.value).kind = muscle_keyword; (yyval.value).chars = (yyvsp[0].ID); }
2549 break;
2551 case 114: /* value: "string" */
2552 { (yyval.value).kind = muscle_string; (yyval.value).chars = unquote ((yyvsp[0].STRING)); gram_scanner_last_string_free ();}
2553 break;
2555 case 115: /* value: "{...}" */
2556 { (yyval.value).kind = muscle_code; (yyval.value).chars = strip_braces ((yyvsp[0].BRACED_CODE)); gram_scanner_last_string_free (); }
2557 break;
2559 case 116: /* id: "identifier" */
2560 { (yyval.id) = symbol_from_uniqstr ((yyvsp[0].ID), (yylsp[0])); }
2561 break;
2563 case 117: /* id: "character literal" */
2565 const char *var = "api.token.raw";
2566 if (current_class == nterm_sym)
2568 complain (&(yylsp[0]), complaint,
2569 _("character literals cannot be nonterminals"));
2570 YYERROR;
2572 if (muscle_percent_define_ifdef (var))
2574 complain (&(yylsp[0]), complaint,
2575 _("character literals cannot be used together"
2576 " with %s"), var);
2577 location loc = muscle_percent_define_get_loc (var);
2578 subcomplain (&loc, complaint, _("definition of %s"), var);
2580 (yyval.id) = symbol_get (char_name ((yyvsp[0].CHAR_LITERAL)), (yylsp[0]));
2581 symbol_class_set ((yyval.id), token_sym, (yylsp[0]), false);
2582 symbol_code_set ((yyval.id), (yyvsp[0].CHAR_LITERAL), (yylsp[0]));
2584 break;
2586 case 118: /* id_colon: "identifier:" */
2587 { (yyval.id_colon) = symbol_from_uniqstr ((yyvsp[0].ID_COLON), (yylsp[0])); }
2588 break;
2590 case 121: /* string_as_id: "string" */
2592 (yyval.string_as_id) = symbol_get ((yyvsp[0].STRING), (yylsp[0]));
2593 symbol_class_set ((yyval.string_as_id), token_sym, (yylsp[0]), false);
2595 break;
2597 case 123: /* epilogue.opt: "%%" "epilogue" */
2599 muscle_code_grow ("epilogue", translate_code ((yyvsp[0].EPILOGUE), (yylsp[0]), true), (yylsp[0]));
2600 code_scanner_last_string_free ();
2602 break;
2606 default: break;
2608 if (yychar_backup != yychar)
2609 YY_LAC_DISCARD ("yychar change");
2611 /* User semantic actions sometimes alter yychar, and that requires
2612 that yytoken be updated with the new translation. We take the
2613 approach of translating immediately before every use of yytoken.
2614 One alternative is translating here after every semantic action,
2615 but that translation would be missed if the semantic action invokes
2616 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2617 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2618 incorrect destructor might then be invoked immediately. In the
2619 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2620 to an incorrect destructor call or verbose syntax error message
2621 before the lookahead is translated. */
2622 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
2624 YYPOPSTACK (yylen);
2625 yylen = 0;
2627 *++yyvsp = yyval;
2628 *++yylsp = yyloc;
2630 /* Now 'shift' the result of the reduction. Determine what state
2631 that goes to, based on the state we popped back to and the rule
2632 number reduced by. */
2634 const int yylhs = yyr1[yyn] - YYNTOKENS;
2635 const int yyi = yypgoto[yylhs] + *yyssp;
2636 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
2637 ? yytable[yyi]
2638 : yydefgoto[yylhs]);
2641 goto yynewstate;
2644 /*--------------------------------------.
2645 | yyerrlab -- here on detecting error. |
2646 `--------------------------------------*/
2647 yyerrlab:
2648 /* Make sure we have latest lookahead translation. See comments at
2649 user semantic actions for why this is necessary. */
2650 yytoken = yychar == GRAM_EMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
2651 /* If not already recovering from an error, report this error. */
2652 if (!yyerrstatus)
2654 ++yynerrs;
2656 yypcontext_t yyctx
2657 = {yyssp, yyesa, &yyes, &yyes_capacity, yytoken, &yylloc};
2658 if (yychar != GRAM_EMPTY)
2659 YY_LAC_ESTABLISH;
2660 if (yyreport_syntax_error (&yyctx) == 2)
2661 goto yyexhaustedlab;
2665 yyerror_range[1] = yylloc;
2666 if (yyerrstatus == 3)
2668 /* If just tried and failed to reuse lookahead token after an
2669 error, discard it. */
2671 if (yychar <= GRAM_EOF)
2673 /* Return failure if at end of input. */
2674 if (yychar == GRAM_EOF)
2675 YYABORT;
2677 else
2679 yydestruct ("Error: discarding",
2680 yytoken, &yylval, &yylloc);
2681 yychar = GRAM_EMPTY;
2685 /* Else will try to reuse lookahead token after shifting the error
2686 token. */
2687 goto yyerrlab1;
2690 /*---------------------------------------------------.
2691 | yyerrorlab -- error raised explicitly by YYERROR. |
2692 `---------------------------------------------------*/
2693 yyerrorlab:
2694 /* Pacify compilers when the user code never invokes YYERROR and the
2695 label yyerrorlab therefore never appears in user code. */
2696 if (0)
2697 YYERROR;
2699 /* Do not reclaim the symbols of the rule whose action triggered
2700 this YYERROR. */
2701 YYPOPSTACK (yylen);
2702 yylen = 0;
2703 YY_STACK_PRINT (yyss, yyssp);
2704 yystate = *yyssp;
2705 goto yyerrlab1;
2708 /*-------------------------------------------------------------.
2709 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2710 `-------------------------------------------------------------*/
2711 yyerrlab1:
2712 yyerrstatus = 3; /* Each real token shifted decrements this. */
2714 /* Pop stack until we find a state that shifts the error token. */
2715 for (;;)
2717 yyn = yypact[yystate];
2718 if (!yypact_value_is_default (yyn))
2720 yyn += YYSYMBOL_YYerror;
2721 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
2723 yyn = yytable[yyn];
2724 if (0 < yyn)
2725 break;
2729 /* Pop the current state because it cannot handle the error token. */
2730 if (yyssp == yyss)
2731 YYABORT;
2733 yyerror_range[1] = *yylsp;
2734 yydestruct ("Error: popping",
2735 YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp);
2736 YYPOPSTACK (1);
2737 yystate = *yyssp;
2738 YY_STACK_PRINT (yyss, yyssp);
2741 /* If the stack popping above didn't lose the initial context for the
2742 current lookahead token, the shift below will for sure. */
2743 YY_LAC_DISCARD ("error recovery");
2745 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2746 *++yyvsp = yylval;
2747 YY_IGNORE_MAYBE_UNINITIALIZED_END
2749 yyerror_range[2] = yylloc;
2750 ++yylsp;
2751 YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);
2753 /* Shift the error token. */
2754 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
2756 yystate = yyn;
2757 goto yynewstate;
2760 /*-------------------------------------.
2761 | yyacceptlab -- YYACCEPT comes here. |
2762 `-------------------------------------*/
2763 yyacceptlab:
2764 yyresult = 0;
2765 goto yyreturn;
2768 /*-----------------------------------.
2769 | yyabortlab -- YYABORT comes here. |
2770 `-----------------------------------*/
2771 yyabortlab:
2772 yyresult = 1;
2773 goto yyreturn;
2776 #if 1
2777 /*-------------------------------------------------.
2778 | yyexhaustedlab -- memory exhaustion comes here. |
2779 `-------------------------------------------------*/
2780 yyexhaustedlab:
2781 yyerror (&yylloc, YY_("memory exhausted"));
2782 yyresult = 2;
2783 goto yyreturn;
2784 #endif
2787 /*-------------------------------------------------------.
2788 | yyreturn -- parsing is finished, clean up and return. |
2789 `-------------------------------------------------------*/
2790 yyreturn:
2791 if (yychar != GRAM_EMPTY)
2793 /* Make sure we have latest lookahead translation. See comments at
2794 user semantic actions for why this is necessary. */
2795 yytoken = YYTRANSLATE (yychar);
2796 yydestruct ("Cleanup: discarding lookahead",
2797 yytoken, &yylval, &yylloc);
2799 /* Do not reclaim the symbols of the rule whose action triggered
2800 this YYABORT or YYACCEPT. */
2801 YYPOPSTACK (yylen);
2802 YY_STACK_PRINT (yyss, yyssp);
2803 while (yyssp != yyss)
2805 yydestruct ("Cleanup: popping",
2806 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yylsp);
2807 YYPOPSTACK (1);
2809 #ifndef yyoverflow
2810 if (yyss != yyssa)
2811 YYSTACK_FREE (yyss);
2812 #endif
2813 if (yyes != yyesa)
2814 YYSTACK_FREE (yyes);
2816 return yyresult;
2822 yyreport_syntax_error (const yypcontext_t *ctx)
2824 int res = 0;
2825 /* Arguments of format: reported tokens (one for the "unexpected",
2826 one per "expected"). */
2827 enum { ARGS_MAX = 5 };
2828 const char *argv[ARGS_MAX];
2829 int argc = 0;
2830 yysymbol_kind_t unexpected = yypcontext_token (ctx);
2831 if (unexpected != YYSYMBOL_YYEMPTY)
2833 argv[argc++] = yysymbol_name (unexpected);
2834 yysymbol_kind_t expected[ARGS_MAX - 1];
2835 int nexpected = yypcontext_expected_tokens (ctx, expected, ARGS_MAX - 1);
2836 if (nexpected < 0)
2837 res = nexpected;
2838 else
2839 for (int i = 0; i < nexpected; ++i)
2840 argv[argc++] = yysymbol_name (expected[i]);
2842 syntax_error (*yypcontext_location (ctx), argc, argv);
2843 return res;
2847 /* Return the location of the left-hand side of a rule whose
2848 right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
2849 the right-hand side, and return an empty location equal to the end
2850 boundary of RHS[0] if the right-hand side is empty. */
2852 static YYLTYPE
2853 lloc_default (YYLTYPE const *rhs, int n)
2855 YYLTYPE loc;
2857 /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
2858 The bug is fixed in 7.4.2m, but play it safe for now. */
2859 loc.start = rhs[n].end;
2860 loc.end = rhs[n].end;
2862 /* Ignore empty nonterminals the start of the right-hand side.
2863 Do not bother to ignore them at the end of the right-hand side,
2864 since empty nonterminals have the same end as their predecessors. */
2865 for (int i = 1; i <= n; i++)
2866 if (! equal_boundaries (rhs[i].start, rhs[i].end))
2868 loc.start = rhs[i].start;
2869 break;
2872 return loc;
2875 static
2876 char *strip_braces (char *code)
2878 code[strlen (code) - 1] = 0;
2879 return code + 1;
2882 static
2883 char const *
2884 translate_code (char *code, location loc, bool plain)
2886 code_props plain_code;
2887 if (plain)
2888 code_props_plain_init (&plain_code, code, loc);
2889 else
2890 code_props_symbol_action_init (&plain_code, code, loc);
2891 code_props_translate_code (&plain_code);
2892 gram_scanner_last_string_free ();
2893 return plain_code.code;
2896 static
2897 char const *
2898 translate_code_braceless (char *code, location loc)
2900 return translate_code (strip_braces (code), loc, true);
2903 static void
2904 add_param (param_type type, char *decl, location loc)
2906 static char const alphanum[26 + 26 + 1 + 10 + 1] =
2907 "abcdefghijklmnopqrstuvwxyz"
2908 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2910 "0123456789";
2912 char const *name_start = NULL;
2914 char *p;
2915 /* Stop on last actual character. */
2916 for (p = decl; p[1]; p++)
2917 if ((p == decl
2918 || ! memchr (alphanum, p[-1], sizeof alphanum - 1))
2919 && memchr (alphanum, p[0], sizeof alphanum - 10 - 1))
2920 name_start = p;
2922 /* Strip the surrounding '{' and '}', and any blanks just inside
2923 the braces. */
2924 --p;
2925 while (c_isspace ((unsigned char) *p))
2926 --p;
2927 p[1] = '\0';
2928 ++decl;
2929 while (c_isspace ((unsigned char) *decl))
2930 ++decl;
2933 if (! name_start)
2934 complain (&loc, complaint, _("missing identifier in parameter declaration"));
2935 else
2937 char *name = xmemdup0 (name_start, strspn (name_start, alphanum));
2938 if (type & param_lex)
2939 muscle_pair_list_grow ("lex_param", decl, name);
2940 if (type & param_parse)
2941 muscle_pair_list_grow ("parse_param", decl, name);
2942 free (name);
2945 gram_scanner_last_string_free ();
2949 static void
2950 handle_defines (char const *value)
2952 defines_flag = true;
2953 char *file = unquote (value);
2954 spec_header_file = xstrdup (file);
2955 gram_scanner_last_string_free ();
2956 unquote_free (file);
2960 static void
2961 handle_error_verbose (location const *loc, char const *directive)
2963 bison_directive (loc, directive);
2964 muscle_percent_define_insert (directive, *loc, muscle_keyword, "",
2965 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
2969 static void
2970 handle_file_prefix (location const *loc,
2971 location const *dir_loc,
2972 char const *directive, char const *value_quoted)
2974 char *value = unquote (value_quoted);
2975 bison_directive (loc, directive);
2976 bool warned = false;
2978 if (location_empty (spec_file_prefix_loc))
2980 spec_file_prefix_loc = *loc;
2981 spec_file_prefix = value;
2983 else
2985 duplicate_directive (directive, spec_file_prefix_loc, *loc);
2986 warned = true;
2989 if (!warned
2990 && STRNEQ (directive, "%file-prefix"))
2991 deprecated_directive (dir_loc, directive, "%file-prefix");
2994 static void
2995 handle_language (location const *loc, char const *lang)
2997 language_argmatch (unquote (lang), grammar_prio, *loc);
3001 static void
3002 handle_name_prefix (location const *loc,
3003 char const *directive, char const *value_quoted)
3005 char *value = unquote (value_quoted);
3006 bison_directive (loc, directive);
3008 char buf1[1024];
3009 size_t len1 = sizeof (buf1);
3010 char *old = asnprintf (buf1, &len1, "%s\"%s\"", directive, value);
3011 if (!old)
3012 xalloc_die ();
3014 if (location_empty (spec_name_prefix_loc))
3016 spec_name_prefix = value;
3017 spec_name_prefix_loc = *loc;
3019 char buf2[1024];
3020 size_t len2 = sizeof (buf2);
3021 char *new = asnprintf (buf2, &len2, "%%define api.prefix {%s}", value);
3022 if (!new)
3023 xalloc_die ();
3024 deprecated_directive (loc, old, new);
3025 if (new != buf2)
3026 free (new);
3028 else
3029 duplicate_directive (old, spec_file_prefix_loc, *loc);
3031 if (old != buf1)
3032 free (old);
3036 static void
3037 handle_pure_parser (location const *loc, char const *directive)
3039 bison_directive (loc, directive);
3040 deprecated_directive (loc, directive, "%define api.pure");
3041 muscle_percent_define_insert ("api.pure", *loc, muscle_keyword, "",
3042 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
3046 static void
3047 handle_require (location const *loc, char const *version_quoted)
3049 char *version = unquote (version_quoted);
3050 required_version = strversion_to_int (version);
3051 if (required_version == -1)
3053 complain (loc, complaint, _("invalid version requirement: %s"),
3054 version);
3055 required_version = 0;
3057 else
3059 const char* package_version =
3060 0 < strverscmp (api_version, PACKAGE_VERSION)
3061 ? api_version : PACKAGE_VERSION;
3062 if (0 < strverscmp (version, package_version))
3064 complain (loc, complaint, _("require bison %s, but have %s"),
3065 version, package_version);
3066 exit (EX_MISMATCH);
3069 unquote_free (version);
3070 gram_scanner_last_string_free ();
3073 static void
3074 handle_skeleton (location const *loc, char const *skel_quoted)
3076 char *skel = unquote (skel_quoted);
3077 char const *skeleton_user = skel;
3078 if (strchr (skeleton_user, '/'))
3080 size_t dir_length = strlen (grammar_file);
3081 while (dir_length && grammar_file[dir_length - 1] != '/')
3082 --dir_length;
3083 while (dir_length && grammar_file[dir_length - 1] == '/')
3084 --dir_length;
3085 char *skeleton_build =
3086 xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
3087 if (dir_length > 0)
3089 memcpy (skeleton_build, grammar_file, dir_length);
3090 skeleton_build[dir_length++] = '/';
3092 strcpy (skeleton_build + dir_length, skeleton_user);
3093 skeleton_user = uniqstr_new (skeleton_build);
3094 free (skeleton_build);
3096 skeleton_arg (skeleton_user, grammar_prio, *loc);
3100 static void
3101 handle_yacc (location const *loc)
3103 const char *directive = "%yacc";
3104 bison_directive (loc, directive);
3105 if (location_empty (yacc_loc))
3106 yacc_loc = *loc;
3107 else
3108 duplicate_directive (directive, yacc_loc, *loc);
3112 static void
3113 gram_error (location const *loc, char const *msg)
3115 complain (loc, complaint, "%s", msg);
3118 static char const *
3119 char_name (char c)
3121 if (c == '\'')
3122 return "'\\''";
3123 else
3125 char buf[4];
3126 buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
3127 return quotearg_style (escape_quoting_style, buf);
3131 static void
3132 current_lhs (symbol *sym, location loc, named_ref *ref)
3134 current_lhs_symbol = sym;
3135 current_lhs_loc = loc;
3136 if (sym)
3137 symbol_location_as_lhs_set (sym, loc);
3138 /* In order to simplify memory management, named references for lhs
3139 are always assigned by deep copy into the current symbol_list
3140 node. This is because a single named-ref in the grammar may
3141 result in several uses when the user factors lhs between several
3142 rules using "|". Therefore free the parser's original copy. */
3143 free (current_lhs_named_ref);
3144 current_lhs_named_ref = ref;
3147 static void tron (FILE *yyo)
3149 begin_use_class ("value", yyo);
3152 static void troff (FILE *yyo)
3154 end_use_class ("value", yyo);
3158 /*----------.
3159 | Unquote. |
3160 `----------*/
3162 struct obstack obstack_for_unquote;
3164 void
3165 parser_init (void)
3167 obstack_init (&obstack_for_unquote);
3170 void
3171 parser_free (void)
3173 obstack_free (&obstack_for_unquote, 0);
3176 static void
3177 unquote_free (char *last_string)
3179 obstack_free (&obstack_for_unquote, last_string);
3182 static char *
3183 unquote (const char *cp)
3185 #define GROW(Char) \
3186 obstack_1grow (&obstack_for_unquote, Char);
3187 for (++cp; *cp && *cp != '"'; ++cp)
3188 switch (*cp)
3190 case '"':
3191 break;
3192 case '\\':
3193 ++cp;
3194 switch (*cp)
3196 case '0': case '1': case '2': case '3': case '4':
3197 case '5': case '6': case '7': case '8': case '9':
3199 int c = cp[0] - '0';
3200 if (c_isdigit (cp[1]))
3202 ++cp;
3203 c = c * 8 + cp[0] - '0';
3205 if (c_isdigit (cp[1]))
3207 ++cp;
3208 c = c * 8 + cp[0] - '0';
3210 GROW (c);
3212 break;
3214 case 'a': GROW ('\a'); break;
3215 case 'b': GROW ('\b'); break;
3216 case 'f': GROW ('\f'); break;
3217 case 'n': GROW ('\n'); break;
3218 case 'r': GROW ('\r'); break;
3219 case 't': GROW ('\t'); break;
3220 case 'v': GROW ('\v'); break;
3222 case 'x':
3224 int c = 0;
3225 while (c_isxdigit (cp[1]))
3227 ++cp;
3228 c = (c * 16 + (c_isdigit (cp[0]) ? cp[0] - '0'
3229 : c_isupper (cp[0]) ? cp[0] - 'A'
3230 : cp[0] - '0'));
3232 GROW (c);
3233 break;
3236 break;
3238 default:
3239 GROW (*cp);
3240 break;
3242 assert (*cp == '"');
3243 ++cp;
3244 assert (*cp == '\0');
3245 #undef GROW
3246 return obstack_finish0 (&obstack_for_unquote);