gnulib: update
[bison.git] / src / parse-gram.c
blob95fe43e0d4e30870de81f34fb176dfc9295491d0
1 /* A Bison parser, made by GNU Bison 3.7.5.297-b46a. */
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 30705
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.7.5.297-b46a"
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_ERROR_VERBOSE = 20, /* "%error-verbose" */
129 YYSYMBOL_PERCENT_EXPECT = 21, /* "%expect" */
130 YYSYMBOL_PERCENT_EXPECT_RR = 22, /* "%expect-rr" */
131 YYSYMBOL_PERCENT_FILE_PREFIX = 23, /* "%file-prefix" */
132 YYSYMBOL_PERCENT_FLAG = 24, /* "%<flag>" */
133 YYSYMBOL_PERCENT_GLR_PARSER = 25, /* "%glr-parser" */
134 YYSYMBOL_PERCENT_HEADER = 26, /* "%header" */
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_73_4 = 73, /* $@4 */
182 YYSYMBOL_precedence_declarator = 74, /* precedence_declarator */
183 YYSYMBOL_75_string_opt = 75, /* string.opt */
184 YYSYMBOL_76_tag_opt = 76, /* tag.opt */
185 YYSYMBOL_generic_symlist = 77, /* generic_symlist */
186 YYSYMBOL_generic_symlist_item = 78, /* generic_symlist_item */
187 YYSYMBOL_tag = 79, /* tag */
188 YYSYMBOL_nterm_decls = 80, /* nterm_decls */
189 YYSYMBOL_token_decls = 81, /* token_decls */
190 YYSYMBOL_82_token_decl_1 = 82, /* token_decl.1 */
191 YYSYMBOL_token_decl = 83, /* token_decl */
192 YYSYMBOL_84_int_opt = 84, /* int.opt */
193 YYSYMBOL_alias = 85, /* alias */
194 YYSYMBOL_token_decls_for_prec = 86, /* token_decls_for_prec */
195 YYSYMBOL_87_token_decl_for_prec_1 = 87, /* token_decl_for_prec.1 */
196 YYSYMBOL_token_decl_for_prec = 88, /* token_decl_for_prec */
197 YYSYMBOL_symbol_decls = 89, /* symbol_decls */
198 YYSYMBOL_90_symbols_1 = 90, /* symbols.1 */
199 YYSYMBOL_grammar = 91, /* grammar */
200 YYSYMBOL_rules_or_grammar_declaration = 92, /* rules_or_grammar_declaration */
201 YYSYMBOL_rules = 93, /* rules */
202 YYSYMBOL_94_5 = 94, /* $@5 */
203 YYSYMBOL_95_rhses_1 = 95, /* rhses.1 */
204 YYSYMBOL_rhs = 96, /* rhs */
205 YYSYMBOL_97_named_ref_opt = 97, /* named_ref.opt */
206 YYSYMBOL_variable = 98, /* variable */
207 YYSYMBOL_value = 99, /* value */
208 YYSYMBOL_id = 100, /* id */
209 YYSYMBOL_id_colon = 101, /* id_colon */
210 YYSYMBOL_symbol = 102, /* symbol */
211 YYSYMBOL_string_as_id = 103, /* string_as_id */
212 YYSYMBOL_104_epilogue_opt = 104 /* epilogue.opt */
214 typedef enum yysymbol_kind_t yysymbol_kind_t;
218 /* Unqualified %code blocks. */
220 #include "system.h"
222 #include <c-ctype.h>
223 #include <quotearg.h>
224 #include <vasnprintf.h>
225 #include <xmemdup0.h>
227 #include "complain.h"
228 #include "conflicts.h"
229 #include "files.h"
230 #include "getargs.h"
231 #include "gram.h"
232 #include "named-ref.h"
233 #include "reader.h"
234 #include "scan-code.h"
235 #include "scan-gram.h"
236 #include "strversion.h"
238 /* Pretend to be at least that version, to check features published
239 in that version while developping it. */
240 static const char* api_version = "3.8";
242 static int current_prec = 0;
243 static location current_lhs_loc;
244 static named_ref *current_lhs_named_ref;
245 static symbol *current_lhs_symbol;
246 static symbol_class current_class = unknown_sym;
248 /** Set the new current left-hand side symbol, possibly common
249 * to several right-hand side parts of rule.
251 static void current_lhs (symbol *sym, location loc, named_ref *ref);
253 #define YYLLOC_DEFAULT(Current, Rhs, N) \
254 (Current) = lloc_default (Rhs, N)
255 static YYLTYPE lloc_default (YYLTYPE const *, int);
257 #define YY_LOCATION_PRINT(File, Loc) \
258 location_print (Loc, File)
260 /* Strip initial '{' and final '}' (must be first and last characters).
261 Return the result. */
262 static char *strip_braces (char *code);
264 /* Convert CODE by calling code_props_plain_init if PLAIN, otherwise
265 code_props_symbol_action_init. Calls
266 gram_scanner_last_string_free to release the latest string from
267 the scanner (should be CODE). */
268 static char const *translate_code (char *code, location loc, bool plain);
270 /* Convert CODE by calling code_props_plain_init after having
271 stripped the first and last characters (expected to be '{', and
272 '}'). Calls gram_scanner_last_string_free to release the latest
273 string from the scanner (should be CODE). */
274 static char const *translate_code_braceless (char *code, location loc);
276 /* Handle a %header directive. */
277 static void handle_header (char const *value);
279 /* Handle a %error-verbose directive. */
280 static void handle_error_verbose (location const *loc, char const *directive);
282 /* Handle a %file-prefix directive. */
283 static void handle_file_prefix (location const *loc,
284 location const *dir_loc,
285 char const *directive, char const *value);
287 /* Handle a %language directive. */
288 static void handle_language (location const *loc, char const *lang);
290 /* Handle a %name-prefix directive. */
291 static void handle_name_prefix (location const *loc,
292 char const *directive, char const *value);
294 /* Handle a %pure-parser directive. */
295 static void handle_pure_parser (location const *loc, char const *directive);
297 /* Handle a %require directive. */
298 static void handle_require (location const *loc, char const *version);
300 /* Handle a %skeleton directive. */
301 static void handle_skeleton (location const *loc, char const *skel);
303 /* Handle a %yacc directive. */
304 static void handle_yacc (location const *loc);
306 /* Implementation of yyerror. */
307 static void gram_error (location const *, char const *);
309 /* A string that describes a char (e.g., 'a' -> "'a'"). */
310 static char const *char_name (char);
312 /* Add style to semantic values in traces. */
313 static void tron (FILE *yyo);
314 static void troff (FILE *yyo);
316 /* Interpret a quoted string (such as `"Hello, \"World\"\n\""`).
317 Manages the memory of the result. */
318 static char *unquote (const char *str);
320 /* Discard the latest unquoted string. */
321 static void unquote_free (char *last_string);
323 /** Add a lex-param and/or a parse-param.
325 * \param type where to push this formal argument.
326 * \param decl the formal argument. Destroyed.
327 * \param loc the location in the source.
329 static void add_param (param_type type, char *decl, location loc);
330 static param_type current_param = param_none;
333 #ifdef short
334 # undef short
335 #endif
337 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
338 <limits.h> and (if available) <stdint.h> are included
339 so that the code can choose integer types of a good width. */
341 #ifndef __PTRDIFF_MAX__
342 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
343 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
344 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
345 # define YY_STDINT_H
346 # endif
347 #endif
349 /* Narrow types that promote to a signed type and that can represent a
350 signed or unsigned integer of at least N bits. In tables they can
351 save space and decrease cache pressure. Promoting to a signed type
352 helps avoid bugs in integer arithmetic. */
354 #ifdef __INT_LEAST8_MAX__
355 typedef __INT_LEAST8_TYPE__ yytype_int8;
356 #elif defined YY_STDINT_H
357 typedef int_least8_t yytype_int8;
358 #else
359 typedef signed char yytype_int8;
360 #endif
362 #ifdef __INT_LEAST16_MAX__
363 typedef __INT_LEAST16_TYPE__ yytype_int16;
364 #elif defined YY_STDINT_H
365 typedef int_least16_t yytype_int16;
366 #else
367 typedef short yytype_int16;
368 #endif
370 /* Work around bug in HP-UX 11.23, which defines these macros
371 incorrectly for preprocessor constants. This workaround can likely
372 be removed in 2023, as HPE has promised support for HP-UX 11.23
373 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
374 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
375 #ifdef __hpux
376 # undef UINT_LEAST8_MAX
377 # undef UINT_LEAST16_MAX
378 # define UINT_LEAST8_MAX 255
379 # define UINT_LEAST16_MAX 65535
380 #endif
382 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
383 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
384 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
385 && UINT_LEAST8_MAX <= INT_MAX)
386 typedef uint_least8_t yytype_uint8;
387 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
388 typedef unsigned char yytype_uint8;
389 #else
390 typedef short yytype_uint8;
391 #endif
393 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
394 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
395 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
396 && UINT_LEAST16_MAX <= INT_MAX)
397 typedef uint_least16_t yytype_uint16;
398 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
399 typedef unsigned short yytype_uint16;
400 #else
401 typedef int yytype_uint16;
402 #endif
404 #ifndef YYPTRDIFF_T
405 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
406 # define YYPTRDIFF_T __PTRDIFF_TYPE__
407 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
408 # elif defined PTRDIFF_MAX
409 # ifndef ptrdiff_t
410 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
411 # endif
412 # define YYPTRDIFF_T ptrdiff_t
413 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
414 # else
415 # define YYPTRDIFF_T long
416 # define YYPTRDIFF_MAXIMUM LONG_MAX
417 # endif
418 #endif
420 #ifndef YYSIZE_T
421 # ifdef __SIZE_TYPE__
422 # define YYSIZE_T __SIZE_TYPE__
423 # elif defined size_t
424 # define YYSIZE_T size_t
425 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
426 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
427 # define YYSIZE_T size_t
428 # else
429 # define YYSIZE_T unsigned
430 # endif
431 #endif
433 #define YYSIZE_MAXIMUM \
434 YY_CAST (YYPTRDIFF_T, \
435 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
436 ? YYPTRDIFF_MAXIMUM \
437 : YY_CAST (YYSIZE_T, -1)))
439 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
442 /* Stored state numbers (used for stacks). */
443 typedef yytype_uint8 yy_state_t;
445 /* State numbers in computations. */
446 typedef int yy_state_fast_t;
448 #ifndef YY_
449 # if defined YYENABLE_NLS && YYENABLE_NLS
450 # if ENABLE_NLS
451 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
452 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
453 # endif
454 # endif
455 # ifndef YY_
456 # define YY_(Msgid) Msgid
457 # endif
458 #endif
460 #ifndef N_
461 # define N_(Msgid) Msgid
462 #endif
465 #ifndef YY_ATTRIBUTE_PURE
466 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
467 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
468 # else
469 # define YY_ATTRIBUTE_PURE
470 # endif
471 #endif
473 #ifndef YY_ATTRIBUTE_UNUSED
474 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
475 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
476 # else
477 # define YY_ATTRIBUTE_UNUSED
478 # endif
479 #endif
481 /* Suppress unused-variable warnings by "using" E. */
482 #if ! defined lint || defined __GNUC__
483 # define YY_USE(E) ((void) (E))
484 #else
485 # define YY_USE(E) /* empty */
486 #endif
488 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
489 #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
490 # if __GNUC__ * 100 + __GNUC_MINOR__ < 407
491 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
492 _Pragma ("GCC diagnostic push") \
493 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
494 # else
495 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
496 _Pragma ("GCC diagnostic push") \
497 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
498 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
499 # endif
500 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
501 _Pragma ("GCC diagnostic pop")
502 #else
503 # define YY_INITIAL_VALUE(Value) Value
504 #endif
505 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
506 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
507 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
508 #endif
509 #ifndef YY_INITIAL_VALUE
510 # define YY_INITIAL_VALUE(Value) /* Nothing. */
511 #endif
513 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
514 # define YY_IGNORE_USELESS_CAST_BEGIN \
515 _Pragma ("GCC diagnostic push") \
516 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
517 # define YY_IGNORE_USELESS_CAST_END \
518 _Pragma ("GCC diagnostic pop")
519 #endif
520 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
521 # define YY_IGNORE_USELESS_CAST_BEGIN
522 # define YY_IGNORE_USELESS_CAST_END
523 #endif
526 #define YY_ASSERT(E) ((void) (0 && (E)))
528 #if 1
530 /* The parser invokes alloca or malloc; define the necessary symbols. */
532 # ifdef YYSTACK_ALLOC
533 /* Pacify GCC's 'empty if-body' warning. */
534 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
535 # ifndef YYSTACK_ALLOC_MAXIMUM
536 /* The OS might guarantee only one guard page at the bottom of the stack,
537 and a page size can be as small as 4096 bytes. So we cannot safely
538 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
539 to allow for a few compiler-allocated temporary stack slots. */
540 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
541 # endif
542 # else
543 # define YYSTACK_ALLOC YYMALLOC
544 # define YYSTACK_FREE YYFREE
545 # ifndef YYSTACK_ALLOC_MAXIMUM
546 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
547 # endif
548 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
549 && ! ((defined YYMALLOC || defined malloc) \
550 && (defined YYFREE || defined free)))
551 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
552 # ifndef EXIT_SUCCESS
553 # define EXIT_SUCCESS 0
554 # endif
555 # endif
556 # ifndef YYMALLOC
557 # define YYMALLOC malloc
558 # if ! defined malloc && ! defined EXIT_SUCCESS
559 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
560 # endif
561 # endif
562 # ifndef YYFREE
563 # define YYFREE free
564 # if ! defined free && ! defined EXIT_SUCCESS
565 void free (void *); /* INFRINGES ON USER NAME SPACE */
566 # endif
567 # endif
568 # endif
569 # define YYCOPY_NEEDED 1
570 #endif /* 1 */
572 #if (! defined yyoverflow \
573 && (! defined __cplusplus \
574 || (defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL \
575 && defined GRAM_STYPE_IS_TRIVIAL && GRAM_STYPE_IS_TRIVIAL)))
577 /* A type that is properly aligned for any stack member. */
578 union yyalloc
580 yy_state_t yyss_alloc;
581 YYSTYPE yyvs_alloc;
582 YYLTYPE yyls_alloc;
585 /* The size of the maximum gap between one aligned stack and the next. */
586 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
588 /* The size of an array large to enough to hold all stacks, each with
589 N elements. */
590 # define YYSTACK_BYTES(N) \
591 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \
592 + YYSIZEOF (YYLTYPE)) \
593 + 2 * YYSTACK_GAP_MAXIMUM)
595 # define YYCOPY_NEEDED 1
597 /* Relocate STACK from its old location to the new one. The
598 local variables YYSIZE and YYSTACKSIZE give the old and new number of
599 elements in the stack, and YYPTR gives the new location of the
600 stack. Advance YYPTR to a properly aligned location for the next
601 stack. */
602 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
603 do \
605 YYPTRDIFF_T yynewbytes; \
606 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
607 Stack = &yyptr->Stack_alloc; \
608 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
609 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
611 while (0)
613 #endif
615 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
616 /* Copy COUNT objects from SRC to DST. The source and destination do
617 not overlap. */
618 # ifndef YYCOPY
619 # if defined __GNUC__ && 1 < __GNUC__
620 # define YYCOPY(Dst, Src, Count) \
621 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
622 # else
623 # define YYCOPY(Dst, Src, Count) \
624 do \
626 YYPTRDIFF_T yyi; \
627 for (yyi = 0; yyi < (Count); yyi++) \
628 (Dst)[yyi] = (Src)[yyi]; \
630 while (0)
631 # endif
632 # endif
633 #endif /* !YYCOPY_NEEDED */
635 /* YYFINAL -- State number of the termination state. */
636 #define YYFINAL 3
637 /* YYLAST -- Last index in YYTABLE. */
638 #define YYLAST 240
640 /* YYNTOKENS -- Number of terminals. */
641 #define YYNTOKENS 61
642 /* YYNNTS -- Number of nonterminals. */
643 #define YYNNTS 44
644 /* YYNRULES -- Number of rules. */
645 #define YYNRULES 125
646 /* YYNSTATES -- Number of states. */
647 #define YYNSTATES 169
649 /* YYMAXUTOK -- Last valid token kind. */
650 #define YYMAXUTOK 315
653 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
654 as returned by yylex, with out-of-bounds checking. */
655 #define YYTRANSLATE(YYX) YY_CAST (yysymbol_kind_t, YYX)
657 #if GRAM_DEBUG
658 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
659 static const yytype_int16 yyrline[] =
661 0, 310, 310, 319, 320, 324, 325, 331, 335, 340,
662 341, 342, 343, 344, 345, 350, 355, 356, 357, 358,
663 359, 360, 360, 361, 362, 363, 364, 365, 366, 367,
664 368, 372, 373, 382, 383, 387, 398, 402, 406, 414,
665 424, 425, 435, 436, 442, 455, 455, 460, 460, 465,
666 465, 470, 480, 481, 482, 483, 488, 489, 493, 494,
667 499, 500, 504, 505, 509, 510, 511, 524, 533, 537,
668 541, 549, 550, 554, 567, 568, 573, 574, 575, 593,
669 597, 601, 609, 611, 616, 623, 633, 637, 641, 649,
670 655, 668, 669, 675, 676, 677, 684, 684, 692, 693,
671 694, 699, 702, 704, 706, 708, 710, 712, 714, 716,
672 718, 723, 724, 733, 757, 758, 759, 760, 772, 774,
673 798, 803, 804, 809, 817, 818
675 #endif
677 /** Accessing symbol of state STATE. */
678 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
680 #if 1
681 /* The user-facing name of the symbol whose (internal) number is
682 YYSYMBOL. No bounds checking. */
683 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
685 static const char *
686 yysymbol_name (yysymbol_kind_t yysymbol)
688 static const char *const yy_sname[] =
690 N_("end of file"), N_("error"), N_("invalid token"), N_("string"),
691 N_("translatable string"), "%token", "%nterm", "%type", "%destructor",
692 "%printer", "%left", "%right", "%nonassoc", "%precedence", "%prec",
693 "%dprec", "%merge", "%code", "%default-prec", "%define",
694 "%error-verbose", "%expect", "%expect-rr", "%file-prefix", "%<flag>",
695 "%glr-parser", "%header", "%initial-action", "%language", "%name-prefix",
696 "%no-default-prec", "%no-lines", "%nondeterministic-parser", "%output",
697 "%pure-parser", "%require", "%skeleton", "%start", "%token-table",
698 "%verbose", "%yacc", "{...}", "%?{...}", N_("[identifier]"),
699 N_("character literal"), ":", N_("epilogue"), "=", N_("identifier"),
700 N_("identifier:"), "%%", "|", "%{...%}", ";", N_("<tag>"), "<*>", "<>",
701 N_("integer literal"), "%param", "%union", "%empty", "$accept", "input",
702 "prologue_declarations", "prologue_declaration", "$@1", "params",
703 "grammar_declaration", "code_props_type", "union_name",
704 "symbol_declaration", "$@2", "$@3", "$@4", "precedence_declarator",
705 "string.opt", "tag.opt", "generic_symlist", "generic_symlist_item",
706 "tag", "nterm_decls", "token_decls", "token_decl.1", "token_decl",
707 "int.opt", "alias", "token_decls_for_prec", "token_decl_for_prec.1",
708 "token_decl_for_prec", "symbol_decls", "symbols.1", "grammar",
709 "rules_or_grammar_declaration", "rules", "$@5", "rhses.1", "rhs",
710 "named_ref.opt", "variable", "value", "id", "id_colon", "symbol",
711 "string_as_id", "epilogue.opt", YY_NULLPTR
713 /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
714 internationalizable. */
715 static yytype_int8 yytranslatable[] =
717 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
718 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
719 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
720 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
721 0, 0, 0, 1, 1, 0, 1, 0, 1, 1,
722 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
725 return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
726 ? _(yy_sname[yysymbol])
727 : yy_sname[yysymbol]);
729 #endif
731 #define YYPACT_NINF (-148)
733 #define yypact_value_is_default(Yyn) \
734 ((Yyn) == YYPACT_NINF)
736 #define YYTABLE_NINF (-125)
738 #define yytable_value_is_error(Yyn) \
741 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
742 STATE-NUM. */
743 static const yytype_int16 yypact[] =
745 -148, 13, 113, -148, -27, -148, -148, -148, -148, -148,
746 -148, -148, -148, -148, -33, -148, -21, -148, -29, -26,
747 26, -148, -148, 27, -9, 30, 31, -148, -148, -148,
748 32, -148, 34, 36, 112, -148, -148, -148, 168, -148,
749 -148, -148, -3, -148, -148, 19, -148, 7, -148, -37,
750 -37, 164, -148, 33, -148, 2, -148, -148, -148, -148,
751 -148, -148, -148, -148, -148, -148, -148, -148, -148, -148,
752 112, -148, -148, -148, 9, -148, 20, 58, -148, -148,
753 37, 38, -148, 40, 155, 112, 35, 112, -148, 41,
754 -148, -28, 43, -28, -148, 41, -148, 43, 112, 46,
755 112, -148, -148, -148, -148, -148, -148, -148, -148, 44,
756 -148, -148, -148, -148, -148, 50, -148, -148, -148, -148,
757 155, -148, -148, -148, 112, 112, -148, -148, -148, -28,
758 -28, -148, 21, 112, 112, -148, 59, -148, -148, 112,
759 -28, -148, -148, -148, 112, -148, -30, 180, -148, -148,
760 112, 48, 49, 52, 53, -148, -148, -148, 65, 37,
761 180, -148, -148, -148, -148, -148, 37, -148, -148
764 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
765 Performed when YYTABLE does not specify something else to do. Zero
766 means the default is an error. */
767 static const yytype_int8 yydefact[] =
769 3, 0, 0, 1, 0, 47, 45, 49, 40, 41,
770 52, 53, 54, 55, 0, 36, 0, 10, 0, 0,
771 0, 7, 14, 56, 0, 0, 0, 37, 18, 19,
772 0, 23, 0, 0, 0, 26, 27, 28, 0, 6,
773 30, 21, 42, 4, 5, 0, 33, 0, 29, 0,
774 0, 0, 38, 0, 113, 114, 11, 12, 13, 57,
775 9, 15, 16, 17, 20, 24, 25, 123, 119, 118,
776 34, 121, 89, 122, 0, 120, 0, 0, 91, 93,
777 111, 0, 43, 0, 0, 0, 51, 79, 82, 74,
778 85, 0, 48, 68, 71, 74, 46, 67, 0, 50,
779 86, 39, 116, 117, 115, 8, 90, 95, 94, 0,
780 92, 2, 112, 96, 32, 22, 44, 64, 65, 66,
781 35, 60, 63, 62, 80, 0, 83, 75, 84, 69,
782 0, 72, 76, 87, 0, 125, 0, 31, 61, 81,
783 70, 78, 73, 77, 88, 101, 97, 98, 101, 100,
784 0, 0, 0, 0, 0, 104, 59, 105, 0, 111,
785 99, 106, 107, 108, 109, 110, 111, 102, 103
788 /* YYPGOTO[NTERM-NUM]. */
789 static const yytype_int16 yypgoto[] =
791 -148, -148, -148, -148, -148, -148, 109, -148, -148, -148,
792 -148, -148, -148, -148, -148, -148, -148, -7, -148, -148,
793 66, -73, -87, 60, -148, -148, -71, -83, -148, -50,
794 -148, 51, -148, -148, -148, -19, -147, -148, -148, -47,
795 -148, -48, -38, -148
798 /* YYDEFGOTO[NTERM-NUM]. */
799 static const yytype_uint8 yydefgoto[] =
801 0, 1, 2, 43, 81, 115, 76, 45, 83, 46,
802 50, 49, 51, 47, 60, 158, 120, 121, 122, 96,
803 92, 93, 94, 128, 142, 86, 87, 88, 99, 70,
804 77, 78, 79, 136, 146, 147, 113, 55, 105, 71,
805 80, 72, 73, 111
808 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
809 positive, shift that token. If negative, reduce the rule whose
810 number is the opposite. If YYTABLE_NINF, syntax error. */
811 static const yytype_int16 yytable[] =
813 89, 100, 95, 95, 126, 102, 131, 68, 52, 90,
814 67, 69, 167, 3, 124, 53, 68, 91, 129, 168,
815 69, 148, 106, 149, 67, 141, 48, 54, 56, 58,
816 59, 57, 61, 62, 63, 64, 123, 65, 89, 66,
817 89, 126, 131, 103, 95, 82, 95, 90, 133, 90,
818 104, 68, 106, 131, 139, 69, 126, 140, -124, 74,
819 84, 85, 107, 5, 6, 7, 8, 9, 10, 11,
820 12, 13, 123, 108, 101, 14, 15, 89, 89, 114,
821 112, 116, 95, 95, 144, 106, 90, 90, 27, 125,
822 135, 137, 89, 95, 143, 34, 106, 130, 127, 159,
823 134, 90, 161, 163, 145, 162, 166, 75, 109, 164,
824 165, 44, 159, 138, 4, 67, 97, 42, 5, 6,
825 7, 8, 9, 10, 11, 12, 13, 0, 110, 160,
826 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
827 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
828 34, 35, 36, 37, 0, 132, 68, 0, 67, 0,
829 69, 0, 0, 38, 0, 39, 40, 67, 0, 74,
830 0, 41, 42, 5, 6, 7, 8, 9, 10, 11,
831 12, 13, 0, 67, 0, 14, 15, 0, 0, 0,
832 0, 0, 0, 0, 150, 151, 152, 0, 27, 68,
833 0, 153, 154, 69, 0, 34, 0, 0, 68, 117,
834 118, 119, 69, 0, 0, 0, 0, 75, 98, 0,
835 0, -58, 155, 0, 68, 0, 0, 42, 69, 0,
836 0, 0, 0, 0, 156, 0, 0, 0, 0, 0,
840 static const yytype_int16 yycheck[] =
842 47, 51, 49, 50, 87, 3, 93, 44, 41, 47,
843 3, 48, 159, 0, 85, 48, 44, 54, 91, 166,
844 48, 51, 70, 53, 3, 4, 53, 48, 57, 3,
845 3, 57, 41, 3, 3, 3, 84, 3, 85, 3,
846 87, 124, 129, 41, 91, 48, 93, 85, 98, 87,
847 48, 44, 100, 140, 125, 48, 139, 130, 0, 1,
848 41, 54, 53, 5, 6, 7, 8, 9, 10, 11,
849 12, 13, 120, 53, 41, 17, 18, 124, 125, 41,
850 43, 41, 129, 130, 134, 133, 124, 125, 30, 54,
851 46, 41, 139, 140, 132, 37, 144, 54, 57, 147,
852 54, 139, 150, 54, 45, 57, 41, 49, 50, 57,
853 57, 2, 160, 120, 1, 3, 50, 59, 5, 6,
854 7, 8, 9, 10, 11, 12, 13, -1, 77, 148,
855 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
856 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
857 37, 38, 39, 40, -1, 95, 44, -1, 3, -1,
858 48, -1, -1, 50, -1, 52, 53, 3, -1, 1,
859 -1, 58, 59, 5, 6, 7, 8, 9, 10, 11,
860 12, 13, -1, 3, -1, 17, 18, -1, -1, -1,
861 -1, -1, -1, -1, 14, 15, 16, -1, 30, 44,
862 -1, 21, 22, 48, -1, 37, -1, -1, 44, 54,
863 55, 56, 48, -1, -1, -1, -1, 49, 54, -1,
864 -1, 41, 42, -1, 44, -1, -1, 59, 48, -1,
865 -1, -1, -1, -1, 54, -1, -1, -1, -1, -1,
869 /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
870 state STATE-NUM. */
871 static const yytype_int8 yystos[] =
873 0, 62, 63, 0, 1, 5, 6, 7, 8, 9,
874 10, 11, 12, 13, 17, 18, 19, 20, 21, 22,
875 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
876 33, 34, 35, 36, 37, 38, 39, 40, 50, 52,
877 53, 58, 59, 64, 67, 68, 70, 74, 53, 72,
878 71, 73, 41, 48, 48, 98, 57, 57, 3, 3,
879 75, 41, 3, 3, 3, 3, 3, 3, 44, 48,
880 90, 100, 102, 103, 1, 49, 67, 91, 92, 93,
881 101, 65, 48, 69, 41, 54, 86, 87, 88, 100,
882 103, 54, 81, 82, 83, 100, 80, 81, 54, 89,
883 90, 41, 3, 41, 48, 99, 102, 53, 53, 50,
884 92, 104, 43, 97, 41, 66, 41, 54, 55, 56,
885 77, 78, 79, 102, 87, 54, 88, 57, 84, 82,
886 54, 83, 84, 90, 54, 46, 94, 41, 78, 87,
887 82, 4, 85, 103, 90, 45, 95, 96, 51, 53,
888 14, 15, 16, 21, 22, 42, 54, 60, 76, 102,
889 96, 102, 57, 54, 57, 57, 41, 97, 97
892 /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
893 static const yytype_int8 yyr1[] =
895 0, 61, 62, 63, 63, 64, 64, 64, 64, 64,
896 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
897 64, 65, 64, 64, 64, 64, 64, 64, 64, 64,
898 64, 66, 66, 67, 67, 67, 67, 67, 67, 67,
899 68, 68, 69, 69, 67, 71, 70, 72, 70, 73,
900 70, 70, 74, 74, 74, 74, 75, 75, 76, 76,
901 77, 77, 78, 78, 79, 79, 79, 80, 81, 81,
902 81, 82, 82, 83, 84, 84, 85, 85, 85, 86,
903 86, 86, 87, 87, 88, 88, 89, 89, 89, 90,
904 90, 91, 91, 92, 92, 92, 94, 93, 95, 95,
905 95, 96, 96, 96, 96, 96, 96, 96, 96, 96,
906 96, 97, 97, 98, 99, 99, 99, 99, 100, 100,
907 101, 102, 102, 103, 104, 104
910 /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
911 static const yytype_int8 yyr2[] =
913 0, 2, 4, 0, 2, 1, 1, 1, 3, 2,
914 1, 2, 2, 2, 1, 2, 2, 2, 1, 1,
915 2, 0, 3, 1, 2, 2, 1, 1, 1, 2,
916 1, 2, 1, 1, 2, 3, 1, 1, 2, 3,
917 1, 1, 0, 1, 3, 0, 3, 0, 3, 0,
918 3, 2, 1, 1, 1, 1, 0, 1, 0, 1,
919 1, 2, 1, 1, 1, 1, 1, 1, 1, 2,
920 3, 1, 2, 3, 0, 1, 0, 1, 1, 1,
921 2, 3, 1, 2, 2, 1, 1, 2, 3, 1,
922 2, 1, 2, 1, 2, 2, 0, 5, 1, 3,
923 2, 0, 3, 4, 2, 2, 3, 3, 3, 3,
924 3, 0, 1, 1, 0, 1, 1, 1, 1, 1,
925 1, 1, 1, 1, 0, 2
929 enum { YYENOMEM = -2 };
931 #define yyerrok (yyerrstatus = 0)
932 #define yyclearin (yychar = GRAM_EMPTY)
934 #define YYACCEPT goto yyacceptlab
935 #define YYABORT goto yyabortlab
936 #define YYERROR goto yyerrorlab
937 #define YYNOMEM goto yyexhaustedlab
940 #define YYRECOVERING() (!!yyerrstatus)
942 #define YYBACKUP(Token, Value) \
943 do \
944 if (yychar == GRAM_EMPTY) \
946 yychar = (Token); \
947 yylval = (Value); \
948 YYPOPSTACK (yylen); \
949 yystate = *yyssp; \
950 YY_LAC_DISCARD ("YYBACKUP"); \
951 goto yybackup; \
953 else \
955 yyerror (&yylloc, YY_("syntax error: cannot back up")); \
956 YYERROR; \
958 while (0)
960 /* Backward compatibility with an undocumented macro.
961 Use GRAM_error or GRAM_UNDEF. */
962 #define YYERRCODE GRAM_UNDEF
964 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
965 If N is 0, then set CURRENT to the empty location which ends
966 the previous symbol: RHS[0] (always defined). */
968 #ifndef YYLLOC_DEFAULT
969 # define YYLLOC_DEFAULT(Current, Rhs, N) \
970 do \
971 if (N) \
973 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
974 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
975 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
976 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
978 else \
980 (Current).first_line = (Current).last_line = \
981 YYRHSLOC (Rhs, 0).last_line; \
982 (Current).first_column = (Current).last_column = \
983 YYRHSLOC (Rhs, 0).last_column; \
985 while (0)
986 #endif
988 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
991 /* Enable debugging if requested. */
992 #if GRAM_DEBUG
994 # ifndef YYFPRINTF
995 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
996 # define YYFPRINTF fprintf
997 # endif
999 # define YYDPRINTF(Args) \
1000 do { \
1001 if (yydebug) \
1002 YYFPRINTF Args; \
1003 } while (0)
1006 /* YYLOCATION_PRINT -- Print the location on the stream.
1007 This macro was not mandated originally: define only if we know
1008 we won't break user code: when these are the locations we know. */
1010 # ifndef YYLOCATION_PRINT
1012 # if defined YY_LOCATION_PRINT
1014 /* Temporary convenience wrapper in case some people defined the
1015 undocumented and private YY_LOCATION_PRINT macros. */
1016 # define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc))
1018 # elif defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
1020 /* Print *YYLOCP on YYO. Private, do not rely on its existence. */
1022 YY_ATTRIBUTE_UNUSED
1023 static int
1024 yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
1026 int res = 0;
1027 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
1028 if (0 <= yylocp->first_line)
1030 res += YYFPRINTF (yyo, "%d", yylocp->first_line);
1031 if (0 <= yylocp->first_column)
1032 res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
1034 if (0 <= yylocp->last_line)
1036 if (yylocp->first_line < yylocp->last_line)
1038 res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
1039 if (0 <= end_col)
1040 res += YYFPRINTF (yyo, ".%d", end_col);
1042 else if (0 <= end_col && yylocp->first_column < end_col)
1043 res += YYFPRINTF (yyo, "-%d", end_col);
1045 return res;
1048 # define YYLOCATION_PRINT yy_location_print_
1050 /* Temporary convenience wrapper in case some people defined the
1051 undocumented and private YY_LOCATION_PRINT macros. */
1052 # define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc))
1054 # else
1056 # define YYLOCATION_PRINT(File, Loc) ((void) 0)
1057 /* Temporary convenience wrapper in case some people defined the
1058 undocumented and private YY_LOCATION_PRINT macros. */
1059 # define YY_LOCATION_PRINT YYLOCATION_PRINT
1061 # endif
1062 # endif /* !defined YYLOCATION_PRINT */
1065 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
1066 do { \
1067 if (yydebug) \
1069 YYFPRINTF (stderr, "%s ", Title); \
1070 yy_symbol_print (stderr, \
1071 Kind, Value, Location); \
1072 YYFPRINTF (stderr, "\n"); \
1074 } while (0)
1077 /*-----------------------------------.
1078 | Print this symbol's value on YYO. |
1079 `-----------------------------------*/
1081 static void
1082 yy_symbol_value_print (FILE *yyo,
1083 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1085 FILE *yyoutput = yyo;
1086 YY_USE (yyoutput);
1087 YY_USE (yylocationp);
1088 if (!yyvaluep)
1089 return;
1090 /* "%code pre-printer" blocks. */
1091 tron (yyo);
1093 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1094 switch (yykind)
1096 case YYSYMBOL_STRING: /* "string" */
1097 { fputs (((*yyvaluep).STRING), yyo); }
1098 break;
1100 case YYSYMBOL_TSTRING: /* "translatable string" */
1101 { fputs (((*yyvaluep).TSTRING), yyo); }
1102 break;
1104 case YYSYMBOL_PERCENT_ERROR_VERBOSE: /* "%error-verbose" */
1105 { fputs (((*yyvaluep).PERCENT_ERROR_VERBOSE), yyo); }
1106 break;
1108 case YYSYMBOL_PERCENT_FILE_PREFIX: /* "%file-prefix" */
1109 { fputs (((*yyvaluep).PERCENT_FILE_PREFIX), yyo); }
1110 break;
1112 case YYSYMBOL_PERCENT_FLAG: /* "%<flag>" */
1113 { fprintf (yyo, "%%%s", ((*yyvaluep).PERCENT_FLAG)); }
1114 break;
1116 case YYSYMBOL_PERCENT_NAME_PREFIX: /* "%name-prefix" */
1117 { fputs (((*yyvaluep).PERCENT_NAME_PREFIX), yyo); }
1118 break;
1120 case YYSYMBOL_PERCENT_PURE_PARSER: /* "%pure-parser" */
1121 { fputs (((*yyvaluep).PERCENT_PURE_PARSER), yyo); }
1122 break;
1124 case YYSYMBOL_BRACED_CODE: /* "{...}" */
1125 { fputs (((*yyvaluep).BRACED_CODE), yyo); }
1126 break;
1128 case YYSYMBOL_BRACED_PREDICATE: /* "%?{...}" */
1129 { fputs (((*yyvaluep).BRACED_PREDICATE), yyo); }
1130 break;
1132 case YYSYMBOL_BRACKETED_ID: /* "[identifier]" */
1133 { fprintf (yyo, "[%s]", ((*yyvaluep).BRACKETED_ID)); }
1134 break;
1136 case YYSYMBOL_CHAR_LITERAL: /* "character literal" */
1137 { fputs (char_name (((*yyvaluep).CHAR_LITERAL)), yyo); }
1138 break;
1140 case YYSYMBOL_EPILOGUE: /* "epilogue" */
1141 { fputs (((*yyvaluep).EPILOGUE), yyo); }
1142 break;
1144 case YYSYMBOL_ID: /* "identifier" */
1145 { fputs (((*yyvaluep).ID), yyo); }
1146 break;
1148 case YYSYMBOL_ID_COLON: /* "identifier:" */
1149 { fprintf (yyo, "%s:", ((*yyvaluep).ID_COLON)); }
1150 break;
1152 case YYSYMBOL_PROLOGUE: /* "%{...%}" */
1153 { fputs (((*yyvaluep).PROLOGUE), yyo); }
1154 break;
1156 case YYSYMBOL_TAG: /* "<tag>" */
1157 { fprintf (yyo, "<%s>", ((*yyvaluep).TAG)); }
1158 break;
1160 case YYSYMBOL_INT_LITERAL: /* "integer literal" */
1161 { fprintf (yyo, "%d", ((*yyvaluep).INT_LITERAL)); }
1162 break;
1164 case YYSYMBOL_PERCENT_PARAM: /* "%param" */
1166 switch (((*yyvaluep).PERCENT_PARAM))
1168 #define CASE(In, Out) \
1169 case param_ ## In: fputs ("%" #Out, yyo); break
1170 CASE (lex, lex-param);
1171 CASE (parse, parse-param);
1172 CASE (both, param);
1173 #undef CASE
1174 case param_none: aver (false); break;
1177 break;
1179 case YYSYMBOL_code_props_type: /* code_props_type */
1180 { fprintf (yyo, "%s", code_props_type_string (((*yyvaluep).code_props_type))); }
1181 break;
1183 case YYSYMBOL_75_string_opt: /* string.opt */
1184 { fputs (((*yyvaluep).yykind_75), yyo); }
1185 break;
1187 case YYSYMBOL_76_tag_opt: /* tag.opt */
1188 { fputs (((*yyvaluep).yykind_76), yyo); }
1189 break;
1191 case YYSYMBOL_generic_symlist: /* generic_symlist */
1192 { symbol_list_syms_print (((*yyvaluep).generic_symlist), yyo); }
1193 break;
1195 case YYSYMBOL_generic_symlist_item: /* generic_symlist_item */
1196 { symbol_list_syms_print (((*yyvaluep).generic_symlist_item), yyo); }
1197 break;
1199 case YYSYMBOL_tag: /* tag */
1200 { fprintf (yyo, "<%s>", ((*yyvaluep).tag)); }
1201 break;
1203 case YYSYMBOL_nterm_decls: /* nterm_decls */
1204 { symbol_list_syms_print (((*yyvaluep).nterm_decls), yyo); }
1205 break;
1207 case YYSYMBOL_token_decls: /* token_decls */
1208 { symbol_list_syms_print (((*yyvaluep).token_decls), yyo); }
1209 break;
1211 case YYSYMBOL_82_token_decl_1: /* token_decl.1 */
1212 { symbol_list_syms_print (((*yyvaluep).yykind_82), yyo); }
1213 break;
1215 case YYSYMBOL_token_decl: /* token_decl */
1216 { fprintf (yyo, "%s", ((*yyvaluep).token_decl) ? ((*yyvaluep).token_decl)->tag : "<NULL>"); }
1217 break;
1219 case YYSYMBOL_84_int_opt: /* int.opt */
1220 { fprintf (yyo, "%d", ((*yyvaluep).yykind_84)); }
1221 break;
1223 case YYSYMBOL_alias: /* alias */
1224 { fprintf (yyo, "%s", ((*yyvaluep).alias) ? ((*yyvaluep).alias)->tag : "<NULL>"); }
1225 break;
1227 case YYSYMBOL_token_decls_for_prec: /* token_decls_for_prec */
1228 { symbol_list_syms_print (((*yyvaluep).token_decls_for_prec), yyo); }
1229 break;
1231 case YYSYMBOL_87_token_decl_for_prec_1: /* token_decl_for_prec.1 */
1232 { symbol_list_syms_print (((*yyvaluep).yykind_87), yyo); }
1233 break;
1235 case YYSYMBOL_token_decl_for_prec: /* token_decl_for_prec */
1236 { fprintf (yyo, "%s", ((*yyvaluep).token_decl_for_prec) ? ((*yyvaluep).token_decl_for_prec)->tag : "<NULL>"); }
1237 break;
1239 case YYSYMBOL_symbol_decls: /* symbol_decls */
1240 { symbol_list_syms_print (((*yyvaluep).symbol_decls), yyo); }
1241 break;
1243 case YYSYMBOL_90_symbols_1: /* symbols.1 */
1244 { symbol_list_syms_print (((*yyvaluep).yykind_90), yyo); }
1245 break;
1247 case YYSYMBOL_variable: /* variable */
1248 { fputs (((*yyvaluep).variable), yyo); }
1249 break;
1251 case YYSYMBOL_value: /* value */
1253 switch (((*yyvaluep).value).kind)
1255 case muscle_code: fprintf (yyo, "{%s}", ((*yyvaluep).value).chars); break;
1256 case muscle_keyword: fprintf (yyo, "%s", ((*yyvaluep).value).chars); break;
1257 case muscle_string: fprintf (yyo, "\"%s\"", ((*yyvaluep).value).chars); break;
1260 break;
1262 case YYSYMBOL_id: /* id */
1263 { fprintf (yyo, "%s", ((*yyvaluep).id) ? ((*yyvaluep).id)->tag : "<NULL>"); }
1264 break;
1266 case YYSYMBOL_id_colon: /* id_colon */
1267 { fprintf (yyo, "%s:", ((*yyvaluep).id_colon)->tag); }
1268 break;
1270 case YYSYMBOL_symbol: /* symbol */
1271 { fprintf (yyo, "%s", ((*yyvaluep).symbol) ? ((*yyvaluep).symbol)->tag : "<NULL>"); }
1272 break;
1274 case YYSYMBOL_string_as_id: /* string_as_id */
1275 { fprintf (yyo, "%s", ((*yyvaluep).string_as_id) ? ((*yyvaluep).string_as_id)->tag : "<NULL>"); }
1276 break;
1278 default:
1279 break;
1281 YY_IGNORE_MAYBE_UNINITIALIZED_END
1282 /* "%code post-printer" blocks. */
1283 troff (yyo);
1288 /*---------------------------.
1289 | Print this symbol on YYO. |
1290 `---------------------------*/
1292 static void
1293 yy_symbol_print (FILE *yyo,
1294 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
1296 YYFPRINTF (yyo, "%s %s (",
1297 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
1299 YYLOCATION_PRINT (yyo, yylocationp);
1300 YYFPRINTF (yyo, ": ");
1301 yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp);
1302 YYFPRINTF (yyo, ")");
1305 /*------------------------------------------------------------------.
1306 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1307 | TOP (included). |
1308 `------------------------------------------------------------------*/
1310 static void
1311 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
1313 YYFPRINTF (stderr, "Stack now");
1314 for (; yybottom <= yytop; yybottom++)
1316 int yybot = *yybottom;
1317 YYFPRINTF (stderr, " %d", yybot);
1319 YYFPRINTF (stderr, "\n");
1322 # define YY_STACK_PRINT(Bottom, Top) \
1323 do { \
1324 if (yydebug) \
1325 yy_stack_print ((Bottom), (Top)); \
1326 } while (0)
1329 /*------------------------------------------------.
1330 | Report that the YYRULE is going to be reduced. |
1331 `------------------------------------------------*/
1333 static void
1334 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp,
1335 int yyrule)
1337 int yylno = yyrline[yyrule];
1338 int yynrhs = yyr2[yyrule];
1339 int yyi;
1340 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
1341 yyrule - 1, yylno);
1342 /* The symbols being reduced. */
1343 for (yyi = 0; yyi < yynrhs; yyi++)
1345 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1346 yy_symbol_print (stderr,
1347 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
1348 &yyvsp[(yyi + 1) - (yynrhs)],
1349 &(yylsp[(yyi + 1) - (yynrhs)]));
1350 YYFPRINTF (stderr, "\n");
1354 # define YY_REDUCE_PRINT(Rule) \
1355 do { \
1356 if (yydebug) \
1357 yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
1358 } while (0)
1360 /* Nonzero means print parse trace. It is left uninitialized so that
1361 multiple parsers can coexist. */
1362 int yydebug;
1363 #else /* !GRAM_DEBUG */
1364 # define YYDPRINTF(Args) ((void) 0)
1365 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1366 # define YY_STACK_PRINT(Bottom, Top)
1367 # define YY_REDUCE_PRINT(Rule)
1368 #endif /* !GRAM_DEBUG */
1371 /* YYINITDEPTH -- initial size of the parser's stacks. */
1372 #ifndef YYINITDEPTH
1373 # define YYINITDEPTH 200
1374 #endif
1376 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1377 if the built-in stack extension method is used).
1379 Do not make this value too large; the results are undefined if
1380 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1381 evaluated with infinite-precision integer arithmetic. */
1383 #ifndef YYMAXDEPTH
1384 # define YYMAXDEPTH 10000
1385 #endif
1388 /* Given a state stack such that *YYBOTTOM is its bottom, such that
1389 *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty
1390 stack, and such that *YYCAPACITY is the maximum number of elements it
1391 can hold without a reallocation, make sure there is enough room to
1392 store YYADD more elements. If not, allocate a new stack using
1393 YYSTACK_ALLOC, copy the existing elements, and adjust *YYBOTTOM,
1394 *YYTOP, and *YYCAPACITY to reflect the new capacity and memory
1395 location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack
1396 using YYSTACK_FREE. Return 0 if successful or if no reallocation is
1397 required. Return YYENOMEM if memory is exhausted. */
1398 static int
1399 yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd,
1400 #if GRAM_DEBUG
1401 char const *yydebug_prefix,
1402 char const *yydebug_suffix,
1403 #endif
1404 yy_state_t **yybottom,
1405 yy_state_t *yybottom_no_free,
1406 yy_state_t **yytop, yy_state_t *yytop_empty)
1408 YYPTRDIFF_T yysize_old =
1409 *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
1410 YYPTRDIFF_T yysize_new = yysize_old + yyadd;
1411 if (*yycapacity < yysize_new)
1413 YYPTRDIFF_T yyalloc = 2 * yysize_new;
1414 yy_state_t *yybottom_new;
1415 /* Use YYMAXDEPTH for maximum stack size given that the stack
1416 should never need to grow larger than the main state stack
1417 needs to grow without LAC. */
1418 if (YYMAXDEPTH < yysize_new)
1420 YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix,
1421 yydebug_suffix));
1422 return YYENOMEM;
1424 if (YYMAXDEPTH < yyalloc)
1425 yyalloc = YYMAXDEPTH;
1426 yybottom_new =
1427 YY_CAST (yy_state_t *,
1428 YYSTACK_ALLOC (YY_CAST (YYSIZE_T,
1429 yyalloc * YYSIZEOF (*yybottom_new))));
1430 if (!yybottom_new)
1432 YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix,
1433 yydebug_suffix));
1434 return YYENOMEM;
1436 if (*yytop != yytop_empty)
1438 YYCOPY (yybottom_new, *yybottom, yysize_old);
1439 *yytop = yybottom_new + (yysize_old - 1);
1441 if (*yybottom != yybottom_no_free)
1442 YYSTACK_FREE (*yybottom);
1443 *yybottom = yybottom_new;
1444 *yycapacity = yyalloc;
1446 return 0;
1449 /* Establish the initial context for the current lookahead if no initial
1450 context is currently established.
1452 We define a context as a snapshot of the parser stacks. We define
1453 the initial context for a lookahead as the context in which the
1454 parser initially examines that lookahead in order to select a
1455 syntactic action. Thus, if the lookahead eventually proves
1456 syntactically unacceptable (possibly in a later context reached via a
1457 series of reductions), the initial context can be used to determine
1458 the exact set of tokens that would be syntactically acceptable in the
1459 lookahead's place. Moreover, it is the context after which any
1460 further semantic actions would be erroneous because they would be
1461 determined by a syntactically unacceptable token.
1463 YY_LAC_ESTABLISH should be invoked when a reduction is about to be
1464 performed in an inconsistent state (which, for the purposes of LAC,
1465 includes consistent states that don't know they're consistent because
1466 their default reductions have been disabled). Iff there is a
1467 lookahead token, it should also be invoked before reporting a syntax
1468 error. This latter case is for the sake of the debugging output.
1470 For parse.lac=full, the implementation of YY_LAC_ESTABLISH is as
1471 follows. If no initial context is currently established for the
1472 current lookahead, then check if that lookahead can eventually be
1473 shifted if syntactic actions continue from the current context.
1474 Report a syntax error if it cannot. */
1475 #define YY_LAC_ESTABLISH \
1476 do { \
1477 if (!yy_lac_established) \
1479 YYDPRINTF ((stderr, \
1480 "LAC: initial context established for %s\n", \
1481 yysymbol_name (yytoken))); \
1482 yy_lac_established = 1; \
1483 switch (yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken)) \
1485 case YYENOMEM: \
1486 YYNOMEM; \
1487 case 1: \
1488 goto yyerrlab; \
1491 } while (0)
1493 /* Discard any previous initial lookahead context because of Event,
1494 which may be a lookahead change or an invalidation of the currently
1495 established initial context for the current lookahead.
1497 The most common example of a lookahead change is a shift. An example
1498 of both cases is syntax error recovery. That is, a syntax error
1499 occurs when the lookahead is syntactically erroneous for the
1500 currently established initial context, so error recovery manipulates
1501 the parser stacks to try to find a new initial context in which the
1502 current lookahead is syntactically acceptable. If it fails to find
1503 such a context, it discards the lookahead. */
1504 #if GRAM_DEBUG
1505 # define YY_LAC_DISCARD(Event) \
1506 do { \
1507 if (yy_lac_established) \
1509 YYDPRINTF ((stderr, "LAC: initial context discarded due to " \
1510 Event "\n")); \
1511 yy_lac_established = 0; \
1513 } while (0)
1514 #else
1515 # define YY_LAC_DISCARD(Event) yy_lac_established = 0
1516 #endif
1518 /* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can
1519 eventually (after perhaps some reductions) be shifted, return 1 if
1520 not, or return YYENOMEM if memory is exhausted. As preconditions and
1521 postconditions: *YYES_CAPACITY is the allocated size of the array to
1522 which *YYES points, and either *YYES = YYESA or *YYES points to an
1523 array allocated with YYSTACK_ALLOC. yy_lac may overwrite the
1524 contents of either array, alter *YYES and *YYES_CAPACITY, and free
1525 any old *YYES other than YYESA. */
1526 static int
1527 yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
1528 YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, yysymbol_kind_t yytoken)
1530 yy_state_t *yyes_prev = yyssp;
1531 yy_state_t *yyesp = yyes_prev;
1532 /* Reduce until we encounter a shift and thereby accept the token. */
1533 YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yysymbol_name (yytoken)));
1534 if (yytoken == YYSYMBOL_YYUNDEF)
1536 YYDPRINTF ((stderr, " Always Err\n"));
1537 return 1;
1539 while (1)
1541 int yyrule = yypact[+*yyesp];
1542 if (yypact_value_is_default (yyrule)
1543 || (yyrule += yytoken) < 0 || YYLAST < yyrule
1544 || yycheck[yyrule] != yytoken)
1546 /* Use the default action. */
1547 yyrule = yydefact[+*yyesp];
1548 if (yyrule == 0)
1550 YYDPRINTF ((stderr, " Err\n"));
1551 return 1;
1554 else
1556 /* Use the action from yytable. */
1557 yyrule = yytable[yyrule];
1558 if (yytable_value_is_error (yyrule))
1560 YYDPRINTF ((stderr, " Err\n"));
1561 return 1;
1563 if (0 < yyrule)
1565 YYDPRINTF ((stderr, " S%d\n", yyrule));
1566 return 0;
1568 yyrule = -yyrule;
1570 /* By now we know we have to simulate a reduce. */
1571 YYDPRINTF ((stderr, " R%d", yyrule - 1));
1573 /* Pop the corresponding number of values from the stack. */
1574 YYPTRDIFF_T yylen = yyr2[yyrule];
1575 /* First pop from the LAC stack as many tokens as possible. */
1576 if (yyesp != yyes_prev)
1578 YYPTRDIFF_T yysize = yyesp - *yyes + 1;
1579 if (yylen < yysize)
1581 yyesp -= yylen;
1582 yylen = 0;
1584 else
1586 yyesp = yyes_prev;
1587 yylen -= yysize;
1590 /* Only afterwards look at the main stack. */
1591 if (yylen)
1592 yyesp = yyes_prev -= yylen;
1594 /* Push the resulting state of the reduction. */
1596 yy_state_fast_t yystate;
1598 const int yylhs = yyr1[yyrule] - YYNTOKENS;
1599 const int yyi = yypgoto[yylhs] + *yyesp;
1600 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp
1601 ? yytable[yyi]
1602 : yydefgoto[yylhs]);
1604 if (yyesp == yyes_prev)
1606 yyesp = *yyes;
1607 YY_IGNORE_USELESS_CAST_BEGIN
1608 *yyesp = YY_CAST (yy_state_t, yystate);
1609 YY_IGNORE_USELESS_CAST_END
1611 else
1613 if (yy_lac_stack_realloc (yyes_capacity, 1,
1614 #if GRAM_DEBUG
1615 " (", ")",
1616 #endif
1617 yyes, yyesa, &yyesp, yyes_prev))
1619 YYDPRINTF ((stderr, "\n"));
1620 return YYENOMEM;
1622 YY_IGNORE_USELESS_CAST_BEGIN
1623 *++yyesp = YY_CAST (yy_state_t, yystate);
1624 YY_IGNORE_USELESS_CAST_END
1626 YYDPRINTF ((stderr, " G%d", yystate));
1631 /* Context of a parse error. */
1632 typedef struct
1634 yy_state_t *yyssp;
1635 yy_state_t *yyesa;
1636 yy_state_t **yyes;
1637 YYPTRDIFF_T *yyes_capacity;
1638 yysymbol_kind_t yytoken;
1639 YYLTYPE *yylloc;
1640 } yypcontext_t;
1642 /* Put in YYARG at most YYARGN of the expected tokens given the
1643 current YYCTX, and return the number of tokens stored in YYARG. If
1644 YYARG is null, return the number of expected tokens (guaranteed to
1645 be less than YYNTOKENS). Return YYENOMEM on memory exhaustion.
1646 Return 0 if there are more than YYARGN expected tokens, yet fill
1647 YYARG up to YYARGN. */
1648 static int
1649 yypcontext_expected_tokens (const yypcontext_t *yyctx,
1650 yysymbol_kind_t yyarg[], int yyargn)
1652 /* Actual size of YYARG. */
1653 int yycount = 0;
1655 int yyx;
1656 for (yyx = 0; yyx < YYNTOKENS; ++yyx)
1658 yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx);
1659 if (yysym != YYSYMBOL_YYerror && yysym != YYSYMBOL_YYUNDEF)
1660 switch (yy_lac (yyctx->yyesa, yyctx->yyes, yyctx->yyes_capacity, yyctx->yyssp, yysym))
1662 case YYENOMEM:
1663 return YYENOMEM;
1664 case 1:
1665 continue;
1666 default:
1667 if (!yyarg)
1668 ++yycount;
1669 else if (yycount == yyargn)
1670 return 0;
1671 else
1672 yyarg[yycount++] = yysym;
1675 if (yyarg && yycount == 0 && 0 < yyargn)
1676 yyarg[0] = YYSYMBOL_YYEMPTY;
1677 return yycount;
1683 /* The kind of the lookahead of this context. */
1684 static yysymbol_kind_t
1685 yypcontext_token (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED;
1687 static yysymbol_kind_t
1688 yypcontext_token (const yypcontext_t *yyctx)
1690 return yyctx->yytoken;
1693 /* The location of the lookahead of this context. */
1694 static YYLTYPE *
1695 yypcontext_location (const yypcontext_t *yyctx) YY_ATTRIBUTE_UNUSED;
1697 static YYLTYPE *
1698 yypcontext_location (const yypcontext_t *yyctx)
1700 return yyctx->yylloc;
1703 /* User defined function to report a syntax error. */
1704 static int
1705 yyreport_syntax_error (const yypcontext_t *yyctx);
1707 /*-----------------------------------------------.
1708 | Release the memory associated to this symbol. |
1709 `-----------------------------------------------*/
1711 static void
1712 yydestruct (const char *yymsg,
1713 yysymbol_kind_t yykind, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
1715 YY_USE (yyvaluep);
1716 YY_USE (yylocationp);
1717 if (!yymsg)
1718 yymsg = "Deleting";
1719 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1721 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1722 switch (yykind)
1724 case YYSYMBOL_generic_symlist: /* generic_symlist */
1725 { symbol_list_free (((*yyvaluep).generic_symlist)); }
1726 break;
1728 case YYSYMBOL_generic_symlist_item: /* generic_symlist_item */
1729 { symbol_list_free (((*yyvaluep).generic_symlist_item)); }
1730 break;
1732 case YYSYMBOL_nterm_decls: /* nterm_decls */
1733 { symbol_list_free (((*yyvaluep).nterm_decls)); }
1734 break;
1736 case YYSYMBOL_token_decls: /* token_decls */
1737 { symbol_list_free (((*yyvaluep).token_decls)); }
1738 break;
1740 case YYSYMBOL_82_token_decl_1: /* token_decl.1 */
1741 { symbol_list_free (((*yyvaluep).yykind_82)); }
1742 break;
1744 case YYSYMBOL_token_decls_for_prec: /* token_decls_for_prec */
1745 { symbol_list_free (((*yyvaluep).token_decls_for_prec)); }
1746 break;
1748 case YYSYMBOL_87_token_decl_for_prec_1: /* token_decl_for_prec.1 */
1749 { symbol_list_free (((*yyvaluep).yykind_87)); }
1750 break;
1752 case YYSYMBOL_symbol_decls: /* symbol_decls */
1753 { symbol_list_free (((*yyvaluep).symbol_decls)); }
1754 break;
1756 case YYSYMBOL_90_symbols_1: /* symbols.1 */
1757 { symbol_list_free (((*yyvaluep).yykind_90)); }
1758 break;
1760 default:
1761 break;
1763 YY_IGNORE_MAYBE_UNINITIALIZED_END
1771 /*----------.
1772 | yyparse. |
1773 `----------*/
1776 yyparse (void)
1778 /* Lookahead token kind. */
1779 int yychar;
1782 /* The semantic value of the lookahead symbol. */
1783 /* Default value used for initialization, for pacifying older GCCs
1784 or non-GCC compilers. */
1785 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
1786 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1788 /* Location data for the lookahead symbol. */
1789 static YYLTYPE yyloc_default
1790 # if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
1791 = { 1, 1, 1, 1 }
1792 # endif
1794 YYLTYPE yylloc = yyloc_default;
1796 /* Number of syntax errors so far. */
1797 int yynerrs = 0;
1799 yy_state_fast_t yystate = 0;
1800 /* Number of tokens to shift before error messages enabled. */
1801 int yyerrstatus = 0;
1803 /* Refer to the stacks through separate pointers, to allow yyoverflow
1804 to reallocate them elsewhere. */
1806 /* Their size. */
1807 YYPTRDIFF_T yystacksize = YYINITDEPTH;
1809 /* The state stack: array, bottom, top. */
1810 yy_state_t yyssa[YYINITDEPTH];
1811 yy_state_t *yyss = yyssa;
1812 yy_state_t *yyssp = yyss;
1814 /* The semantic value stack: array, bottom, top. */
1815 YYSTYPE yyvsa[YYINITDEPTH];
1816 YYSTYPE *yyvs = yyvsa;
1817 YYSTYPE *yyvsp = yyvs;
1819 /* The location stack: array, bottom, top. */
1820 YYLTYPE yylsa[YYINITDEPTH];
1821 YYLTYPE *yyls = yylsa;
1822 YYLTYPE *yylsp = yyls;
1824 yy_state_t yyesa[20];
1825 yy_state_t *yyes = yyesa;
1826 YYPTRDIFF_T yyes_capacity = 20 < YYMAXDEPTH ? 20 : YYMAXDEPTH;
1828 /* Whether LAC context is established. A Boolean. */
1829 int yy_lac_established = 0;
1830 int yyn;
1831 /* The return value of yyparse. */
1832 int yyresult;
1833 /* Lookahead symbol kind. */
1834 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1835 /* The variables used to return semantic value and location from the
1836 action routines. */
1837 YYSTYPE yyval;
1838 YYLTYPE yyloc;
1840 /* The locations where the error started and ended. */
1841 YYLTYPE yyerror_range[3];
1845 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
1847 /* The number of symbols on the RHS of the reduced rule.
1848 Keep to zero when no symbol should be popped. */
1849 int yylen = 0;
1851 YYDPRINTF ((stderr, "Starting parse\n"));
1853 yychar = GRAM_EMPTY; /* Cause a token to be read. */
1856 /* User initialization code. */
1858 /* Bison's grammar can initial empty locations, hence a default
1859 location is needed. */
1860 boundary_set (&yylloc.start, grammar_file, 1, 1, 1);
1861 boundary_set (&yylloc.end, grammar_file, 1, 1, 1);
1865 yylsp[0] = yylloc;
1866 goto yysetstate;
1869 /*------------------------------------------------------------.
1870 | yynewstate -- push a new state, which is found in yystate. |
1871 `------------------------------------------------------------*/
1872 yynewstate:
1873 /* In all cases, when you get here, the value and location stacks
1874 have just been pushed. So pushing a state here evens the stacks. */
1875 yyssp++;
1878 /*--------------------------------------------------------------------.
1879 | yysetstate -- set current state (the top of the stack) to yystate. |
1880 `--------------------------------------------------------------------*/
1881 yysetstate:
1882 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1883 YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1884 YY_IGNORE_USELESS_CAST_BEGIN
1885 *yyssp = YY_CAST (yy_state_t, yystate);
1886 YY_IGNORE_USELESS_CAST_END
1887 YY_STACK_PRINT (yyss, yyssp);
1889 if (yyss + yystacksize - 1 <= yyssp)
1890 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1891 YYNOMEM;
1892 #else
1894 /* Get the current used size of the three stacks, in elements. */
1895 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1897 # if defined yyoverflow
1899 /* Give user a chance to reallocate the stack. Use copies of
1900 these so that the &'s don't force the real ones into
1901 memory. */
1902 yy_state_t *yyss1 = yyss;
1903 YYSTYPE *yyvs1 = yyvs;
1904 YYLTYPE *yyls1 = yyls;
1906 /* Each stack pointer address is followed by the size of the
1907 data in use in that stack, in bytes. This used to be a
1908 conditional around just the two extra args, but that might
1909 be undefined if yyoverflow is a macro. */
1910 yyoverflow (YY_("memory exhausted"),
1911 &yyss1, yysize * YYSIZEOF (*yyssp),
1912 &yyvs1, yysize * YYSIZEOF (*yyvsp),
1913 &yyls1, yysize * YYSIZEOF (*yylsp),
1914 &yystacksize);
1915 yyss = yyss1;
1916 yyvs = yyvs1;
1917 yyls = yyls1;
1919 # else /* defined YYSTACK_RELOCATE */
1920 /* Extend the stack our own way. */
1921 if (YYMAXDEPTH <= yystacksize)
1922 YYNOMEM;
1923 yystacksize *= 2;
1924 if (YYMAXDEPTH < yystacksize)
1925 yystacksize = YYMAXDEPTH;
1928 yy_state_t *yyss1 = yyss;
1929 union yyalloc *yyptr =
1930 YY_CAST (union yyalloc *,
1931 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1932 if (! yyptr)
1933 YYNOMEM;
1934 YYSTACK_RELOCATE (yyss_alloc, yyss);
1935 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1936 YYSTACK_RELOCATE (yyls_alloc, yyls);
1937 # undef YYSTACK_RELOCATE
1938 if (yyss1 != yyssa)
1939 YYSTACK_FREE (yyss1);
1941 # endif
1943 yyssp = yyss + yysize - 1;
1944 yyvsp = yyvs + yysize - 1;
1945 yylsp = yyls + yysize - 1;
1947 YY_IGNORE_USELESS_CAST_BEGIN
1948 YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1949 YY_CAST (long, yystacksize)));
1950 YY_IGNORE_USELESS_CAST_END
1952 if (yyss + yystacksize - 1 <= yyssp)
1953 YYABORT;
1955 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1958 if (yystate == YYFINAL)
1959 YYACCEPT;
1961 goto yybackup;
1964 /*-----------.
1965 | yybackup. |
1966 `-----------*/
1967 yybackup:
1968 /* Do appropriate processing given the current state. Read a
1969 lookahead token if we need one and don't already have one. */
1971 /* First try to decide what to do without reference to lookahead token. */
1972 yyn = yypact[yystate];
1973 if (yypact_value_is_default (yyn))
1974 goto yydefault;
1976 /* Not known => get a lookahead token if don't already have one. */
1978 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1979 if (yychar == GRAM_EMPTY)
1981 YYDPRINTF ((stderr, "Reading a token\n"));
1982 yychar = yylex (&yylval, &yylloc);
1985 if (yychar <= GRAM_EOF)
1987 yychar = GRAM_EOF;
1988 yytoken = YYSYMBOL_YYEOF;
1989 YYDPRINTF ((stderr, "Now at end of input.\n"));
1991 else if (yychar == GRAM_error)
1993 /* The scanner already issued an error message, process directly
1994 to error recovery. But do not keep the error token as
1995 lookahead, it is too special and may lead us to an endless
1996 loop in error recovery. */
1997 yychar = GRAM_UNDEF;
1998 yytoken = YYSYMBOL_YYerror;
1999 yyerror_range[1] = yylloc;
2000 goto yyerrlab1;
2002 else
2004 yytoken = YYTRANSLATE (yychar);
2005 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2008 /* If the proper action on seeing token YYTOKEN is to reduce or to
2009 detect an error, take that action. */
2010 yyn += yytoken;
2011 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2013 YY_LAC_ESTABLISH;
2014 goto yydefault;
2016 yyn = yytable[yyn];
2017 if (yyn <= 0)
2019 if (yytable_value_is_error (yyn))
2020 goto yyerrlab;
2021 yyn = -yyn;
2022 YY_LAC_ESTABLISH;
2023 goto yyreduce;
2026 /* Count tokens shifted since error; after three, turn off error
2027 status. */
2028 if (yyerrstatus)
2029 yyerrstatus--;
2031 /* Shift the lookahead token. */
2032 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2033 yystate = yyn;
2034 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2035 *++yyvsp = yylval;
2036 YY_IGNORE_MAYBE_UNINITIALIZED_END
2037 *++yylsp = yylloc;
2039 /* Discard the shifted token. */
2040 yychar = GRAM_EMPTY;
2041 YY_LAC_DISCARD ("shift");
2042 goto yynewstate;
2045 /*-----------------------------------------------------------.
2046 | yydefault -- do the default action for the current state. |
2047 `-----------------------------------------------------------*/
2048 yydefault:
2049 yyn = yydefact[yystate];
2050 if (yyn == 0)
2051 goto yyerrlab;
2052 goto yyreduce;
2055 /*-----------------------------.
2056 | yyreduce -- do a reduction. |
2057 `-----------------------------*/
2058 yyreduce:
2059 /* yyn is the number of a rule to reduce with. */
2060 yylen = yyr2[yyn];
2062 /* If YYLEN is nonzero, implement the default value of the action:
2063 '$$ = $1'.
2065 Otherwise, the following line sets YYVAL to garbage.
2066 This behavior is undocumented and Bison
2067 users should not rely upon it. Assigning to YYVAL
2068 unconditionally makes the parser a bit smaller, and it avoids a
2069 GCC warning that YYVAL may be used uninitialized. */
2070 yyval = yyvsp[1-yylen];
2072 /* Default location. */
2073 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
2074 yyerror_range[1] = yyloc;
2075 YY_REDUCE_PRINT (yyn);
2077 int yychar_backup = yychar;
2078 switch (yyn)
2080 case 6: /* prologue_declaration: "%{...%}" */
2082 muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue",
2083 translate_code ((yyvsp[0].PROLOGUE), (yylsp[0]), true), (yylsp[0]));
2084 code_scanner_last_string_free ();
2086 break;
2088 case 7: /* prologue_declaration: "%<flag>" */
2090 muscle_percent_define_ensure ((yyvsp[0].PERCENT_FLAG), (yylsp[0]), true);
2092 break;
2094 case 8: /* prologue_declaration: "%define" variable value */
2096 muscle_percent_define_insert ((yyvsp[-1].variable), (yyloc), (yyvsp[0].value).kind, (yyvsp[0].value).chars,
2097 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
2099 break;
2101 case 9: /* prologue_declaration: "%header" string.opt */
2102 { handle_header ((yyvsp[0].yykind_75)); }
2103 break;
2105 case 10: /* prologue_declaration: "%error-verbose" */
2106 { handle_error_verbose (&(yyloc), (yyvsp[0].PERCENT_ERROR_VERBOSE)); }
2107 break;
2109 case 11: /* prologue_declaration: "%expect" "integer literal" */
2110 { expected_sr_conflicts = (yyvsp[0].INT_LITERAL); }
2111 break;
2113 case 12: /* prologue_declaration: "%expect-rr" "integer literal" */
2114 { expected_rr_conflicts = (yyvsp[0].INT_LITERAL); }
2115 break;
2117 case 13: /* prologue_declaration: "%file-prefix" "string" */
2118 { handle_file_prefix (&(yyloc), &(yylsp[-1]), (yyvsp[-1].PERCENT_FILE_PREFIX), (yyvsp[0].STRING)); }
2119 break;
2121 case 14: /* prologue_declaration: "%glr-parser" */
2123 nondeterministic_parser = true;
2124 glr_parser = true;
2126 break;
2128 case 15: /* prologue_declaration: "%initial-action" "{...}" */
2130 muscle_code_grow ("initial_action", translate_code ((yyvsp[0].BRACED_CODE), (yylsp[0]), false), (yylsp[0]));
2131 code_scanner_last_string_free ();
2133 break;
2135 case 16: /* prologue_declaration: "%language" "string" */
2136 { handle_language (&(yylsp[-1]), (yyvsp[0].STRING)); }
2137 break;
2139 case 17: /* prologue_declaration: "%name-prefix" "string" */
2140 { handle_name_prefix (&(yyloc), (yyvsp[-1].PERCENT_NAME_PREFIX), (yyvsp[0].STRING)); }
2141 break;
2143 case 18: /* prologue_declaration: "%no-lines" */
2144 { no_lines_flag = true; }
2145 break;
2147 case 19: /* prologue_declaration: "%nondeterministic-parser" */
2148 { nondeterministic_parser = true; }
2149 break;
2151 case 20: /* prologue_declaration: "%output" "string" */
2152 { spec_outfile = unquote ((yyvsp[0].STRING)); gram_scanner_last_string_free (); }
2153 break;
2155 case 21: /* $@1: %empty */
2156 { current_param = (yyvsp[0].PERCENT_PARAM); }
2157 break;
2159 case 22: /* prologue_declaration: "%param" $@1 params */
2160 { current_param = param_none; }
2161 break;
2163 case 23: /* prologue_declaration: "%pure-parser" */
2164 { handle_pure_parser (&(yyloc), (yyvsp[0].PERCENT_PURE_PARSER)); }
2165 break;
2167 case 24: /* prologue_declaration: "%require" "string" */
2168 { handle_require (&(yylsp[0]), (yyvsp[0].STRING)); }
2169 break;
2171 case 25: /* prologue_declaration: "%skeleton" "string" */
2172 { handle_skeleton (&(yylsp[0]), (yyvsp[0].STRING)); }
2173 break;
2175 case 26: /* prologue_declaration: "%token-table" */
2176 { token_table_flag = true; }
2177 break;
2179 case 27: /* prologue_declaration: "%verbose" */
2180 { report_flag |= report_states; }
2181 break;
2183 case 28: /* prologue_declaration: "%yacc" */
2184 { handle_yacc (&(yyloc)); }
2185 break;
2187 case 29: /* prologue_declaration: error ";" */
2188 { current_class = unknown_sym; yyerrok; }
2189 break;
2191 case 31: /* params: params "{...}" */
2192 { add_param (current_param, (yyvsp[0].BRACED_CODE), (yylsp[0])); }
2193 break;
2195 case 32: /* params: "{...}" */
2196 { add_param (current_param, (yyvsp[0].BRACED_CODE), (yylsp[0])); }
2197 break;
2199 case 34: /* grammar_declaration: "%start" symbols.1 */
2201 grammar_start_symbols_add ((yyvsp[0].yykind_90));
2203 break;
2205 case 35: /* grammar_declaration: code_props_type "{...}" generic_symlist */
2207 code_props code;
2208 code_props_symbol_action_init (&code, (yyvsp[-1].BRACED_CODE), (yylsp[-1]));
2209 code_props_translate_code (&code);
2211 for (symbol_list *list = (yyvsp[0].generic_symlist); list; list = list->next)
2212 symbol_list_code_props_set (list, (yyvsp[-2].code_props_type), &code);
2213 symbol_list_free ((yyvsp[0].generic_symlist));
2216 break;
2218 case 36: /* grammar_declaration: "%default-prec" */
2220 default_prec = true;
2222 break;
2224 case 37: /* grammar_declaration: "%no-default-prec" */
2226 default_prec = false;
2228 break;
2230 case 38: /* grammar_declaration: "%code" "{...}" */
2232 /* Do not invoke muscle_percent_code_grow here since it invokes
2233 muscle_user_name_list_grow. */
2234 muscle_code_grow ("percent_code()",
2235 translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0]));
2236 code_scanner_last_string_free ();
2238 break;
2240 case 39: /* grammar_declaration: "%code" "identifier" "{...}" */
2242 muscle_percent_code_grow ((yyvsp[-1].ID), (yylsp[-1]), translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0]));
2243 code_scanner_last_string_free ();
2245 break;
2247 case 40: /* code_props_type: "%destructor" */
2248 { (yyval.code_props_type) = destructor; }
2249 break;
2251 case 41: /* code_props_type: "%printer" */
2252 { (yyval.code_props_type) = printer; }
2253 break;
2255 case 42: /* union_name: %empty */
2257 break;
2259 case 43: /* union_name: "identifier" */
2260 { muscle_percent_define_insert ("api.value.union.name",
2261 (yylsp[0]), muscle_keyword, (yyvsp[0].ID),
2262 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); }
2263 break;
2265 case 44: /* grammar_declaration: "%union" union_name "{...}" */
2267 union_seen = true;
2268 muscle_code_grow ("union_members", translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0]));
2269 code_scanner_last_string_free ();
2271 break;
2273 case 45: /* $@2: %empty */
2274 { current_class = nterm_sym; }
2275 break;
2277 case 46: /* symbol_declaration: "%nterm" $@2 nterm_decls */
2279 current_class = unknown_sym;
2280 symbol_list_free ((yyvsp[0].nterm_decls));
2282 break;
2284 case 47: /* $@3: %empty */
2285 { current_class = token_sym; }
2286 break;
2288 case 48: /* symbol_declaration: "%token" $@3 token_decls */
2290 current_class = unknown_sym;
2291 symbol_list_free ((yyvsp[0].token_decls));
2293 break;
2295 case 49: /* $@4: %empty */
2296 { current_class = pct_type_sym; }
2297 break;
2299 case 50: /* symbol_declaration: "%type" $@4 symbol_decls */
2301 current_class = unknown_sym;
2302 symbol_list_free ((yyvsp[0].symbol_decls));
2304 break;
2306 case 51: /* symbol_declaration: precedence_declarator token_decls_for_prec */
2308 ++current_prec;
2309 for (symbol_list *list = (yyvsp[0].token_decls_for_prec); list; list = list->next)
2310 symbol_precedence_set (list->content.sym, current_prec, (yyvsp[-1].precedence_declarator), (yylsp[-1]));
2311 symbol_list_free ((yyvsp[0].token_decls_for_prec));
2313 break;
2315 case 52: /* precedence_declarator: "%left" */
2316 { (yyval.precedence_declarator) = left_assoc; }
2317 break;
2319 case 53: /* precedence_declarator: "%right" */
2320 { (yyval.precedence_declarator) = right_assoc; }
2321 break;
2323 case 54: /* precedence_declarator: "%nonassoc" */
2324 { (yyval.precedence_declarator) = non_assoc; }
2325 break;
2327 case 55: /* precedence_declarator: "%precedence" */
2328 { (yyval.precedence_declarator) = precedence_assoc; }
2329 break;
2331 case 56: /* string.opt: %empty */
2332 { (yyval.yykind_75) = NULL; }
2333 break;
2335 case 57: /* string.opt: "string" */
2336 { (yyval.yykind_75) = (yyvsp[0].STRING); }
2337 break;
2339 case 58: /* tag.opt: %empty */
2340 { (yyval.yykind_76) = NULL; }
2341 break;
2343 case 59: /* tag.opt: "<tag>" */
2344 { (yyval.yykind_76) = (yyvsp[0].TAG); }
2345 break;
2347 case 61: /* generic_symlist: generic_symlist generic_symlist_item */
2348 { (yyval.generic_symlist) = symbol_list_append ((yyvsp[-1].generic_symlist), (yyvsp[0].generic_symlist_item)); }
2349 break;
2351 case 62: /* generic_symlist_item: symbol */
2352 { (yyval.generic_symlist_item) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); }
2353 break;
2355 case 63: /* generic_symlist_item: tag */
2356 { (yyval.generic_symlist_item) = symbol_list_type_new ((yyvsp[0].tag), (yylsp[0])); }
2357 break;
2359 case 65: /* tag: "<*>" */
2360 { (yyval.tag) = uniqstr_new ("*"); }
2361 break;
2363 case 66: /* tag: "<>" */
2364 { (yyval.tag) = uniqstr_new (""); }
2365 break;
2367 case 68: /* token_decls: token_decl.1 */
2369 (yyval.token_decls) = (yyvsp[0].yykind_82);
2371 break;
2373 case 69: /* token_decls: "<tag>" token_decl.1 */
2375 (yyval.token_decls) = symbol_list_type_set ((yyvsp[0].yykind_82), (yyvsp[-1].TAG));
2377 break;
2379 case 70: /* token_decls: token_decls "<tag>" token_decl.1 */
2381 (yyval.token_decls) = symbol_list_append ((yyvsp[-2].token_decls), symbol_list_type_set ((yyvsp[0].yykind_82), (yyvsp[-1].TAG)));
2383 break;
2385 case 71: /* token_decl.1: token_decl */
2386 { (yyval.yykind_82) = symbol_list_sym_new ((yyvsp[0].token_decl), (yylsp[0])); }
2387 break;
2389 case 72: /* token_decl.1: token_decl.1 token_decl */
2390 { (yyval.yykind_82) = symbol_list_append ((yyvsp[-1].yykind_82), symbol_list_sym_new ((yyvsp[0].token_decl), (yylsp[0]))); }
2391 break;
2393 case 73: /* token_decl: id int.opt alias */
2395 (yyval.token_decl) = (yyvsp[-2].id);
2396 symbol_class_set ((yyvsp[-2].id), current_class, (yylsp[-2]), true);
2397 if (0 <= (yyvsp[-1].yykind_84))
2398 symbol_code_set ((yyvsp[-2].id), (yyvsp[-1].yykind_84), (yylsp[-1]));
2399 if ((yyvsp[0].alias))
2400 symbol_make_alias ((yyvsp[-2].id), (yyvsp[0].alias), (yylsp[0]));
2402 break;
2404 case 74: /* int.opt: %empty */
2405 { (yyval.yykind_84) = -1; }
2406 break;
2408 case 76: /* alias: %empty */
2409 { (yyval.alias) = NULL; }
2410 break;
2412 case 77: /* alias: string_as_id */
2413 { (yyval.alias) = (yyvsp[0].string_as_id); }
2414 break;
2416 case 78: /* alias: "translatable string" */
2418 (yyval.alias) = symbol_get ((yyvsp[0].TSTRING), (yylsp[0]));
2419 symbol_class_set ((yyval.alias), token_sym, (yylsp[0]), false);
2420 (yyval.alias)->translatable = true;
2422 break;
2424 case 79: /* token_decls_for_prec: token_decl_for_prec.1 */
2426 (yyval.token_decls_for_prec) = (yyvsp[0].yykind_87);
2428 break;
2430 case 80: /* token_decls_for_prec: "<tag>" token_decl_for_prec.1 */
2432 (yyval.token_decls_for_prec) = symbol_list_type_set ((yyvsp[0].yykind_87), (yyvsp[-1].TAG));
2434 break;
2436 case 81: /* token_decls_for_prec: token_decls_for_prec "<tag>" token_decl_for_prec.1 */
2438 (yyval.token_decls_for_prec) = symbol_list_append ((yyvsp[-2].token_decls_for_prec), symbol_list_type_set ((yyvsp[0].yykind_87), (yyvsp[-1].TAG)));
2440 break;
2442 case 82: /* token_decl_for_prec.1: token_decl_for_prec */
2443 { (yyval.yykind_87) = symbol_list_sym_new ((yyvsp[0].token_decl_for_prec), (yylsp[0])); }
2444 break;
2446 case 83: /* token_decl_for_prec.1: token_decl_for_prec.1 token_decl_for_prec */
2447 { (yyval.yykind_87) = symbol_list_append ((yyvsp[-1].yykind_87), symbol_list_sym_new ((yyvsp[0].token_decl_for_prec), (yylsp[0]))); }
2448 break;
2450 case 84: /* token_decl_for_prec: id int.opt */
2452 (yyval.token_decl_for_prec) = (yyvsp[-1].id);
2453 symbol_class_set ((yyvsp[-1].id), token_sym, (yylsp[-1]), false);
2454 if (0 <= (yyvsp[0].yykind_84))
2455 symbol_code_set ((yyvsp[-1].id), (yyvsp[0].yykind_84), (yylsp[0]));
2457 break;
2459 case 86: /* symbol_decls: symbols.1 */
2461 (yyval.symbol_decls) = (yyvsp[0].yykind_90);
2463 break;
2465 case 87: /* symbol_decls: "<tag>" symbols.1 */
2467 (yyval.symbol_decls) = symbol_list_type_set ((yyvsp[0].yykind_90), (yyvsp[-1].TAG));
2469 break;
2471 case 88: /* symbol_decls: symbol_decls "<tag>" symbols.1 */
2473 (yyval.symbol_decls) = symbol_list_append ((yyvsp[-2].symbol_decls), symbol_list_type_set ((yyvsp[0].yykind_90), (yyvsp[-1].TAG)));
2475 break;
2477 case 89: /* symbols.1: symbol */
2479 if (current_class != unknown_sym)
2480 symbol_class_set ((yyvsp[0].symbol), current_class, (yylsp[0]), false);
2481 (yyval.yykind_90) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]));
2483 break;
2485 case 90: /* symbols.1: symbols.1 symbol */
2487 if (current_class != unknown_sym)
2488 symbol_class_set ((yyvsp[0].symbol), current_class, (yylsp[0]), false);
2489 (yyval.yykind_90) = symbol_list_append ((yyvsp[-1].yykind_90), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])));
2491 break;
2493 case 95: /* rules_or_grammar_declaration: error ";" */
2495 yyerrok;
2497 break;
2499 case 96: /* $@5: %empty */
2500 { current_lhs ((yyvsp[-1].id_colon), (yylsp[-1]), (yyvsp[0].yykind_97)); }
2501 break;
2503 case 97: /* rules: id_colon named_ref.opt $@5 ":" rhses.1 */
2505 /* Free the current lhs. */
2506 current_lhs (0, (yylsp[-4]), 0);
2508 break;
2510 case 98: /* rhses.1: rhs */
2511 { grammar_current_rule_end ((yylsp[0])); }
2512 break;
2514 case 99: /* rhses.1: rhses.1 "|" rhs */
2515 { grammar_current_rule_end ((yylsp[0])); }
2516 break;
2518 case 101: /* rhs: %empty */
2519 { grammar_current_rule_begin (current_lhs_symbol, current_lhs_loc,
2520 current_lhs_named_ref); }
2521 break;
2523 case 102: /* rhs: rhs symbol named_ref.opt */
2524 { grammar_current_rule_symbol_append ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].yykind_97)); }
2525 break;
2527 case 103: /* rhs: rhs tag.opt "{...}" named_ref.opt */
2528 { grammar_current_rule_action_append ((yyvsp[-1].BRACED_CODE), (yylsp[-1]), (yyvsp[0].yykind_97), (yyvsp[-2].yykind_76)); }
2529 break;
2531 case 104: /* rhs: rhs "%?{...}" */
2532 { grammar_current_rule_predicate_append ((yyvsp[0].BRACED_PREDICATE), (yylsp[0])); }
2533 break;
2535 case 105: /* rhs: rhs "%empty" */
2536 { grammar_current_rule_empty_set ((yylsp[0])); }
2537 break;
2539 case 106: /* rhs: rhs "%prec" symbol */
2540 { grammar_current_rule_prec_set ((yyvsp[0].symbol), (yylsp[0])); }
2541 break;
2543 case 107: /* rhs: rhs "%dprec" "integer literal" */
2544 { grammar_current_rule_dprec_set ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
2545 break;
2547 case 108: /* rhs: rhs "%merge" "<tag>" */
2548 { grammar_current_rule_merge_set ((yyvsp[0].TAG), (yylsp[0])); }
2549 break;
2551 case 109: /* rhs: rhs "%expect" "integer literal" */
2552 { grammar_current_rule_expect_sr ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
2553 break;
2555 case 110: /* rhs: rhs "%expect-rr" "integer literal" */
2556 { grammar_current_rule_expect_rr ((yyvsp[0].INT_LITERAL), (yylsp[0])); }
2557 break;
2559 case 111: /* named_ref.opt: %empty */
2560 { (yyval.yykind_97) = NULL; }
2561 break;
2563 case 112: /* named_ref.opt: "[identifier]" */
2564 { (yyval.yykind_97) = named_ref_new ((yyvsp[0].BRACKETED_ID), (yylsp[0])); }
2565 break;
2567 case 114: /* value: %empty */
2568 { (yyval.value).kind = muscle_keyword; (yyval.value).chars = ""; }
2569 break;
2571 case 115: /* value: "identifier" */
2572 { (yyval.value).kind = muscle_keyword; (yyval.value).chars = (yyvsp[0].ID); }
2573 break;
2575 case 116: /* value: "string" */
2576 { (yyval.value).kind = muscle_string; (yyval.value).chars = unquote ((yyvsp[0].STRING)); gram_scanner_last_string_free ();}
2577 break;
2579 case 117: /* value: "{...}" */
2580 { (yyval.value).kind = muscle_code; (yyval.value).chars = strip_braces ((yyvsp[0].BRACED_CODE)); gram_scanner_last_string_free (); }
2581 break;
2583 case 118: /* id: "identifier" */
2584 { (yyval.id) = symbol_from_uniqstr ((yyvsp[0].ID), (yylsp[0])); }
2585 break;
2587 case 119: /* id: "character literal" */
2589 const char *var = "api.token.raw";
2590 if (current_class == nterm_sym)
2592 complain (&(yylsp[0]), complaint,
2593 _("character literals cannot be nonterminals"));
2594 YYERROR;
2596 if (muscle_percent_define_ifdef (var))
2598 complain (&(yylsp[0]), complaint,
2599 _("character literals cannot be used together"
2600 " with %s"), var);
2601 location loc = muscle_percent_define_get_loc (var);
2602 subcomplain (&loc, complaint, _("definition of %s"), var);
2604 (yyval.id) = symbol_get (char_name ((yyvsp[0].CHAR_LITERAL)), (yylsp[0]));
2605 symbol_class_set ((yyval.id), token_sym, (yylsp[0]), false);
2606 symbol_code_set ((yyval.id), (yyvsp[0].CHAR_LITERAL), (yylsp[0]));
2608 break;
2610 case 120: /* id_colon: "identifier:" */
2611 { (yyval.id_colon) = symbol_from_uniqstr ((yyvsp[0].ID_COLON), (yylsp[0])); }
2612 break;
2614 case 123: /* string_as_id: "string" */
2616 (yyval.string_as_id) = symbol_get ((yyvsp[0].STRING), (yylsp[0]));
2617 symbol_class_set ((yyval.string_as_id), token_sym, (yylsp[0]), false);
2619 break;
2621 case 125: /* epilogue.opt: "%%" "epilogue" */
2623 muscle_code_grow ("epilogue", translate_code ((yyvsp[0].EPILOGUE), (yylsp[0]), true), (yylsp[0]));
2624 code_scanner_last_string_free ();
2626 break;
2630 default: break;
2632 if (yychar_backup != yychar)
2633 YY_LAC_DISCARD ("yychar change");
2635 /* User semantic actions sometimes alter yychar, and that requires
2636 that yytoken be updated with the new translation. We take the
2637 approach of translating immediately before every use of yytoken.
2638 One alternative is translating here after every semantic action,
2639 but that translation would be missed if the semantic action invokes
2640 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2641 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2642 incorrect destructor might then be invoked immediately. In the
2643 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2644 to an incorrect destructor call or verbose syntax error message
2645 before the lookahead is translated. */
2646 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
2648 YYPOPSTACK (yylen);
2649 yylen = 0;
2651 *++yyvsp = yyval;
2652 *++yylsp = yyloc;
2654 /* Now 'shift' the result of the reduction. Determine what state
2655 that goes to, based on the state we popped back to and the rule
2656 number reduced by. */
2658 const int yylhs = yyr1[yyn] - YYNTOKENS;
2659 const int yyi = yypgoto[yylhs] + *yyssp;
2660 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
2661 ? yytable[yyi]
2662 : yydefgoto[yylhs]);
2665 goto yynewstate;
2668 /*--------------------------------------.
2669 | yyerrlab -- here on detecting error. |
2670 `--------------------------------------*/
2671 yyerrlab:
2672 /* Make sure we have latest lookahead translation. See comments at
2673 user semantic actions for why this is necessary. */
2674 yytoken = yychar == GRAM_EMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
2675 /* If not already recovering from an error, report this error. */
2676 if (!yyerrstatus)
2678 ++yynerrs;
2680 yypcontext_t yyctx
2681 = {yyssp, yyesa, &yyes, &yyes_capacity, yytoken, &yylloc};
2682 if (yychar != GRAM_EMPTY)
2683 YY_LAC_ESTABLISH;
2684 if (yyreport_syntax_error (&yyctx) == 2)
2685 YYNOMEM;
2689 yyerror_range[1] = yylloc;
2690 if (yyerrstatus == 3)
2692 /* If just tried and failed to reuse lookahead token after an
2693 error, discard it. */
2695 if (yychar <= GRAM_EOF)
2697 /* Return failure if at end of input. */
2698 if (yychar == GRAM_EOF)
2699 YYABORT;
2701 else
2703 yydestruct ("Error: discarding",
2704 yytoken, &yylval, &yylloc);
2705 yychar = GRAM_EMPTY;
2709 /* Else will try to reuse lookahead token after shifting the error
2710 token. */
2711 goto yyerrlab1;
2714 /*---------------------------------------------------.
2715 | yyerrorlab -- error raised explicitly by YYERROR. |
2716 `---------------------------------------------------*/
2717 yyerrorlab:
2718 /* Pacify compilers when the user code never invokes YYERROR and the
2719 label yyerrorlab therefore never appears in user code. */
2720 if (0)
2721 YYERROR;
2722 ++yynerrs;
2724 /* Do not reclaim the symbols of the rule whose action triggered
2725 this YYERROR. */
2726 YYPOPSTACK (yylen);
2727 yylen = 0;
2728 YY_STACK_PRINT (yyss, yyssp);
2729 yystate = *yyssp;
2730 goto yyerrlab1;
2733 /*-------------------------------------------------------------.
2734 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2735 `-------------------------------------------------------------*/
2736 yyerrlab1:
2737 yyerrstatus = 3; /* Each real token shifted decrements this. */
2739 /* Pop stack until we find a state that shifts the error token. */
2740 for (;;)
2742 yyn = yypact[yystate];
2743 if (!yypact_value_is_default (yyn))
2745 yyn += YYSYMBOL_YYerror;
2746 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
2748 yyn = yytable[yyn];
2749 if (0 < yyn)
2750 break;
2754 /* Pop the current state because it cannot handle the error token. */
2755 if (yyssp == yyss)
2756 YYABORT;
2758 yyerror_range[1] = *yylsp;
2759 yydestruct ("Error: popping",
2760 YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp);
2761 YYPOPSTACK (1);
2762 yystate = *yyssp;
2763 YY_STACK_PRINT (yyss, yyssp);
2766 /* If the stack popping above didn't lose the initial context for the
2767 current lookahead token, the shift below will for sure. */
2768 YY_LAC_DISCARD ("error recovery");
2770 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2771 *++yyvsp = yylval;
2772 YY_IGNORE_MAYBE_UNINITIALIZED_END
2774 yyerror_range[2] = yylloc;
2775 ++yylsp;
2776 YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);
2778 /* Shift the error token. */
2779 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
2781 yystate = yyn;
2782 goto yynewstate;
2785 /*-------------------------------------.
2786 | yyacceptlab -- YYACCEPT comes here. |
2787 `-------------------------------------*/
2788 yyacceptlab:
2789 yyresult = 0;
2790 goto yyreturnlab;
2793 /*-----------------------------------.
2794 | yyabortlab -- YYABORT comes here. |
2795 `-----------------------------------*/
2796 yyabortlab:
2797 yyresult = 1;
2798 goto yyreturnlab;
2801 /*-----------------------------------------------------------.
2802 | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
2803 `-----------------------------------------------------------*/
2804 yyexhaustedlab:
2805 yyerror (&yylloc, YY_("memory exhausted"));
2806 yyresult = 2;
2807 goto yyreturnlab;
2810 /*----------------------------------------------------------.
2811 | yyreturnlab -- parsing is finished, clean up and return. |
2812 `----------------------------------------------------------*/
2813 yyreturnlab:
2814 if (yychar != GRAM_EMPTY)
2816 /* Make sure we have latest lookahead translation. See comments at
2817 user semantic actions for why this is necessary. */
2818 yytoken = YYTRANSLATE (yychar);
2819 yydestruct ("Cleanup: discarding lookahead",
2820 yytoken, &yylval, &yylloc);
2822 /* Do not reclaim the symbols of the rule whose action triggered
2823 this YYABORT or YYACCEPT. */
2824 YYPOPSTACK (yylen);
2825 YY_STACK_PRINT (yyss, yyssp);
2826 while (yyssp != yyss)
2828 yydestruct ("Cleanup: popping",
2829 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, yylsp);
2830 YYPOPSTACK (1);
2832 #ifndef yyoverflow
2833 if (yyss != yyssa)
2834 YYSTACK_FREE (yyss);
2835 #endif
2836 if (yyes != yyesa)
2837 YYSTACK_FREE (yyes);
2839 return yyresult;
2845 yyreport_syntax_error (const yypcontext_t *ctx)
2847 int res = 0;
2848 /* Arguments of format: reported tokens (one for the "unexpected",
2849 one per "expected"). */
2850 enum { ARGS_MAX = 5 };
2851 const char *argv[ARGS_MAX];
2852 int argc = 0;
2853 yysymbol_kind_t unexpected = yypcontext_token (ctx);
2854 if (unexpected != YYSYMBOL_YYEMPTY)
2856 argv[argc++] = yysymbol_name (unexpected);
2857 yysymbol_kind_t expected[ARGS_MAX - 1];
2858 int nexpected = yypcontext_expected_tokens (ctx, expected, ARGS_MAX - 1);
2859 if (nexpected < 0)
2860 res = nexpected;
2861 else
2862 for (int i = 0; i < nexpected; ++i)
2863 argv[argc++] = yysymbol_name (expected[i]);
2865 syntax_error (*yypcontext_location (ctx), argc, argv);
2866 return res;
2870 /* Return the location of the left-hand side of a rule whose
2871 right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
2872 the right-hand side, and return an empty location equal to the end
2873 boundary of RHS[0] if the right-hand side is empty. */
2875 static YYLTYPE
2876 lloc_default (YYLTYPE const *rhs, int n)
2878 YYLTYPE loc;
2880 /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
2881 The bug is fixed in 7.4.2m, but play it safe for now. */
2882 loc.start = rhs[n].end;
2883 loc.end = rhs[n].end;
2885 /* Ignore empty nonterminals the start of the right-hand side.
2886 Do not bother to ignore them at the end of the right-hand side,
2887 since empty nonterminals have the same end as their predecessors. */
2888 for (int i = 1; i <= n; i++)
2889 if (! equal_boundaries (rhs[i].start, rhs[i].end))
2891 loc.start = rhs[i].start;
2892 break;
2895 return loc;
2898 static
2899 char *strip_braces (char *code)
2901 code[strlen (code) - 1] = 0;
2902 return code + 1;
2905 static
2906 char const *
2907 translate_code (char *code, location loc, bool plain)
2909 code_props plain_code;
2910 if (plain)
2911 code_props_plain_init (&plain_code, code, loc);
2912 else
2913 code_props_symbol_action_init (&plain_code, code, loc);
2914 code_props_translate_code (&plain_code);
2915 gram_scanner_last_string_free ();
2916 return plain_code.code;
2919 static
2920 char const *
2921 translate_code_braceless (char *code, location loc)
2923 return translate_code (strip_braces (code), loc, true);
2926 static void
2927 add_param (param_type type, char *decl, location loc)
2929 static char const alphanum[26 + 26 + 1 + 10 + 1] =
2930 "abcdefghijklmnopqrstuvwxyz"
2931 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2933 "0123456789";
2935 char const *name_start = NULL;
2937 char *p;
2938 /* Stop on last actual character. */
2939 for (p = decl; p[1]; p++)
2940 if ((p == decl
2941 || ! memchr (alphanum, p[-1], sizeof alphanum - 1))
2942 && memchr (alphanum, p[0], sizeof alphanum - 10 - 1))
2943 name_start = p;
2945 /* Strip the surrounding '{' and '}', and any blanks just inside
2946 the braces. */
2947 --p;
2948 while (c_isspace ((unsigned char) *p))
2949 --p;
2950 p[1] = '\0';
2951 ++decl;
2952 while (c_isspace ((unsigned char) *decl))
2953 ++decl;
2956 if (! name_start)
2957 complain (&loc, complaint, _("missing identifier in parameter declaration"));
2958 else
2960 char *name = xmemdup0 (name_start, strspn (name_start, alphanum));
2961 if (type & param_lex)
2962 muscle_pair_list_grow ("lex_param", decl, name);
2963 if (type & param_parse)
2964 muscle_pair_list_grow ("parse_param", decl, name);
2965 free (name);
2968 gram_scanner_last_string_free ();
2972 static void
2973 handle_header (char const *value)
2975 header_flag = true;
2976 if (value)
2978 char *file = unquote (value);
2979 spec_header_file = xstrdup (file);
2980 gram_scanner_last_string_free ();
2981 unquote_free (file);
2986 static void
2987 handle_error_verbose (location const *loc, char const *directive)
2989 bison_directive (loc, directive);
2990 muscle_percent_define_insert (directive, *loc, muscle_keyword, "",
2991 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
2995 static void
2996 handle_file_prefix (location const *loc,
2997 location const *dir_loc,
2998 char const *directive, char const *value_quoted)
3000 char *value = unquote (value_quoted);
3001 bison_directive (loc, directive);
3002 bool warned = false;
3004 if (location_empty (spec_file_prefix_loc))
3006 spec_file_prefix_loc = *loc;
3007 spec_file_prefix = value;
3009 else
3011 duplicate_directive (directive, spec_file_prefix_loc, *loc);
3012 warned = true;
3015 if (!warned
3016 && STRNEQ (directive, "%file-prefix"))
3017 deprecated_directive (dir_loc, directive, "%file-prefix");
3020 static void
3021 handle_language (location const *loc, char const *lang)
3023 language_argmatch (unquote (lang), grammar_prio, *loc);
3027 static void
3028 handle_name_prefix (location const *loc,
3029 char const *directive, char const *value_quoted)
3031 char *value = unquote (value_quoted);
3032 bison_directive (loc, directive);
3034 char buf1[1024];
3035 size_t len1 = sizeof (buf1);
3036 char *old = asnprintf (buf1, &len1, "%s\"%s\"", directive, value);
3037 if (!old)
3038 xalloc_die ();
3040 if (location_empty (spec_name_prefix_loc))
3042 spec_name_prefix = value;
3043 spec_name_prefix_loc = *loc;
3045 char buf2[1024];
3046 size_t len2 = sizeof (buf2);
3047 char *new = asnprintf (buf2, &len2, "%%define api.prefix {%s}", value);
3048 if (!new)
3049 xalloc_die ();
3050 deprecated_directive (loc, old, new);
3051 if (new != buf2)
3052 free (new);
3054 else
3055 duplicate_directive (old, spec_file_prefix_loc, *loc);
3057 if (old != buf1)
3058 free (old);
3062 static void
3063 handle_pure_parser (location const *loc, char const *directive)
3065 bison_directive (loc, directive);
3066 deprecated_directive (loc, directive, "%define api.pure");
3067 muscle_percent_define_insert ("api.pure", *loc, muscle_keyword, "",
3068 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
3072 static void
3073 handle_require (location const *loc, char const *version_quoted)
3075 char *version = unquote (version_quoted);
3076 required_version = strversion_to_int (version);
3077 if (required_version == -1)
3079 complain (loc, complaint, _("invalid version requirement: %s"),
3080 version);
3081 required_version = 0;
3083 else
3085 const char* package_version =
3086 0 < strverscmp (api_version, PACKAGE_VERSION)
3087 ? api_version : PACKAGE_VERSION;
3088 if (0 < strverscmp (version, package_version))
3090 complain (loc, complaint, _("require bison %s, but have %s"),
3091 version, package_version);
3092 exit (EX_MISMATCH);
3095 unquote_free (version);
3096 gram_scanner_last_string_free ();
3099 static void
3100 handle_skeleton (location const *loc, char const *skel_quoted)
3102 char *skel = unquote (skel_quoted);
3103 char const *skeleton_user = skel;
3104 if (strchr (skeleton_user, '/'))
3106 size_t dir_length = strlen (grammar_file);
3107 while (dir_length && grammar_file[dir_length - 1] != '/')
3108 --dir_length;
3109 while (dir_length && grammar_file[dir_length - 1] == '/')
3110 --dir_length;
3111 char *skeleton_build =
3112 xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
3113 if (dir_length > 0)
3115 memcpy (skeleton_build, grammar_file, dir_length);
3116 skeleton_build[dir_length++] = '/';
3118 strcpy (skeleton_build + dir_length, skeleton_user);
3119 skeleton_user = uniqstr_new (skeleton_build);
3120 free (skeleton_build);
3122 skeleton_arg (skeleton_user, grammar_prio, *loc);
3126 static void
3127 handle_yacc (location const *loc)
3129 const char *directive = "%yacc";
3130 bison_directive (loc, directive);
3131 if (location_empty (yacc_loc))
3132 yacc_loc = *loc;
3133 else
3134 duplicate_directive (directive, yacc_loc, *loc);
3138 static void
3139 gram_error (location const *loc, char const *msg)
3141 complain (loc, complaint, "%s", msg);
3144 static char const *
3145 char_name (char c)
3147 if (c == '\'')
3148 return "'\\''";
3149 else
3151 char buf[4];
3152 buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
3153 return quotearg_style (escape_quoting_style, buf);
3157 static void
3158 current_lhs (symbol *sym, location loc, named_ref *ref)
3160 current_lhs_symbol = sym;
3161 current_lhs_loc = loc;
3162 if (sym)
3163 symbol_location_as_lhs_set (sym, loc);
3164 /* In order to simplify memory management, named references for lhs
3165 are always assigned by deep copy into the current symbol_list
3166 node. This is because a single named-ref in the grammar may
3167 result in several uses when the user factors lhs between several
3168 rules using "|". Therefore free the parser's original copy. */
3169 free (current_lhs_named_ref);
3170 current_lhs_named_ref = ref;
3173 static void tron (FILE *yyo)
3175 begin_use_class ("value", yyo);
3178 static void troff (FILE *yyo)
3180 end_use_class ("value", yyo);
3184 /*----------.
3185 | Unquote. |
3186 `----------*/
3188 struct obstack obstack_for_unquote;
3190 void
3191 parser_init (void)
3193 obstack_init (&obstack_for_unquote);
3196 void
3197 parser_free (void)
3199 obstack_free (&obstack_for_unquote, 0);
3202 static void
3203 unquote_free (char *last_string)
3205 obstack_free (&obstack_for_unquote, last_string);
3208 static char *
3209 unquote (const char *cp)
3211 #define GROW(Char) \
3212 obstack_1grow (&obstack_for_unquote, Char);
3213 for (++cp; *cp && *cp != '"'; ++cp)
3214 switch (*cp)
3216 case '"':
3217 break;
3218 case '\\':
3219 ++cp;
3220 switch (*cp)
3222 case '0': case '1': case '2': case '3': case '4':
3223 case '5': case '6': case '7': case '8': case '9':
3225 int c = cp[0] - '0';
3226 if (c_isdigit (cp[1]))
3228 ++cp;
3229 c = c * 8 + cp[0] - '0';
3231 if (c_isdigit (cp[1]))
3233 ++cp;
3234 c = c * 8 + cp[0] - '0';
3236 GROW (c);
3238 break;
3240 case 'a': GROW ('\a'); break;
3241 case 'b': GROW ('\b'); break;
3242 case 'f': GROW ('\f'); break;
3243 case 'n': GROW ('\n'); break;
3244 case 'r': GROW ('\r'); break;
3245 case 't': GROW ('\t'); break;
3246 case 'v': GROW ('\v'); break;
3248 case 'x':
3250 int c = 0;
3251 while (c_isxdigit (cp[1]))
3253 ++cp;
3254 c = (c * 16 + (c_isdigit (cp[0]) ? cp[0] - '0'
3255 : c_isupper (cp[0]) ? cp[0] - 'A'
3256 : cp[0] - '0'));
3258 GROW (c);
3259 break;
3262 break;
3264 default:
3265 GROW (*cp);
3266 break;
3268 assert (*cp == '"');
3269 ++cp;
3270 assert (*cp == '\0');
3271 #undef GROW
3272 return obstack_finish0 (&obstack_for_unquote);