]> git.saurik.com Git - bison.git/blob - data/glr.c
lalr1.cc: check (and fix) %initial-action exception safety
[bison.git] / data / glr.c
1 -*- C -*-
2
3 # GLR skeleton for Bison
4
5 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21 # If we are loaded by glr.cc, do not override c++.m4 definitions by
22 # those of c.m4.
23 m4_if(b4_skeleton, ["glr.c"],
24 [m4_include(b4_pkgdatadir/[c.m4])])
25
26 ## ---------------- ##
27 ## Default values. ##
28 ## ---------------- ##
29
30 # Stack parameters.
31 m4_define_default([b4_stack_depth_max], [10000])
32 m4_define_default([b4_stack_depth_init], [200])
33
34
35
36 ## ------------------------ ##
37 ## Pure/impure interfaces. ##
38 ## ------------------------ ##
39
40 b4_define_flag_if([pure])
41 # If glr.cc is including this file and thus has already set b4_pure_flag,
42 # do not change the value of b4_pure_flag, and do not record a use of api.pure.
43 m4_ifndef([b4_pure_flag],
44 [b4_percent_define_default([[api.pure]], [[false]])
45 m4_define([b4_pure_flag],
46 [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])])
47
48 # b4_user_formals
49 # ---------------
50 # The possible parse-params formal arguments preceded by a comma.
51 #
52 # This is not shared with yacc.c in c.m4 because GLR relies on ISO C
53 # formal argument declarations.
54 m4_define([b4_user_formals],
55 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
56
57
58 # b4_lex_param
59 # ------------
60 # Accumule in b4_lex_param all the yylex arguments.
61 # Yes, this is quite ugly...
62 m4_define([b4_lex_param],
63 m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl
64 b4_locations_if([, [[YYLTYPE *], [&yylloc]]])])dnl
65 m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
66
67
68 # b4_yyerror_args
69 # ---------------
70 # Optional effective arguments passed to yyerror: user args plus yylloc, and
71 # a trailing comma.
72 m4_define([b4_yyerror_args],
73 [b4_pure_if([b4_locations_if([yylocp, ])])dnl
74 m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
75
76
77 # b4_lyyerror_args
78 # ----------------
79 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
80 m4_define([b4_lyyerror_args],
81 [b4_pure_if([b4_locations_if([&yylloc, ])])dnl
82 m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
83
84
85 # b4_pure_args
86 # ------------
87 # Same as b4_yyerror_args, but with a leading comma.
88 m4_define([b4_pure_args],
89 [b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args])
90
91
92 # b4_lpure_args
93 # -------------
94 # Same as above, but on the lookahead, hence &yylloc instead of yylocp.
95 m4_define([b4_lpure_args],
96 [b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args])
97
98
99
100 # b4_pure_formals
101 # ---------------
102 # Arguments passed to yyerror: user formals plus yylocp with leading comma.
103 m4_define([b4_pure_formals],
104 [b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals])
105
106
107 # b4_locuser_formals(LOC = yylocp)
108 # --------------------------------
109 m4_define([b4_locuser_formals],
110 [b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals])
111
112
113 # b4_locuser_args(LOC = yylocp)
114 # -----------------------------
115 m4_define([b4_locuser_args],
116 [b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args])
117
118
119
120 ## ----------------- ##
121 ## Semantic Values. ##
122 ## ----------------- ##
123
124
125 # b4_lhs_value([TYPE])
126 # --------------------
127 # Expansion of $<TYPE>$.
128 m4_define([b4_lhs_value],
129 [((*yyvalp)[]m4_ifval([$1], [.$1]))])
130
131
132 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
133 # --------------------------------------
134 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
135 # symbols on RHS.
136 m4_define([b4_rhs_value],
137 [(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3]))])
138
139
140
141 ## ----------- ##
142 ## Locations. ##
143 ## ----------- ##
144
145 # b4_lhs_location()
146 # -----------------
147 # Expansion of @$.
148 m4_define([b4_lhs_location],
149 [(*yylocp)])
150
151
152 # b4_rhs_location(RULE-LENGTH, NUM)
153 # ---------------------------------
154 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
155 # on RHS.
156 m4_define([b4_rhs_location],
157 [(((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate.yyloc)])
158
159
160 ## -------------- ##
161 ## Declarations. ##
162 ## -------------- ##
163
164 # b4_shared_declarations
165 # ----------------------
166 # Declaration that might either go into the header (if --defines)
167 # or open coded in the parser body.
168 m4_define([b4_shared_declarations],
169 [b4_declare_yydebug[
170 ]b4_percent_code_get([[requires]])[
171 ]b4_token_enums(b4_tokens)[
172 ]b4_declare_yylstype[
173 ]b4_c_ansi_function_decl(b4_prefix[parse], [int], b4_parse_param)[
174 ]b4_percent_code_get([[provides]])[]dnl
175 ])
176
177
178 ## -------------- ##
179 ## Output files. ##
180 ## -------------- ##
181
182 # We do want M4 expansion after # for CPP macros.
183 m4_changecom()
184 m4_divert_push(0)dnl
185 @output(b4_parser_file_name@)@
186 b4_copyright([Skeleton implementation for Bison GLR parsers in C],
187 [2002-2012])
188 [
189 /* C GLR parser skeleton written by Paul Hilfinger. */
190
191 ]b4_identification
192
193 b4_percent_code_get([[top]])[
194 ]m4_if(b4_api_prefix, [yy], [],
195 [[/* Substitute the type names. */
196 #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
197 #define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
198 ]m4_if(b4_prefix, [yy], [],
199 [[/* Substitute the variable and function names. */
200 #define yyparse ]b4_prefix[parse
201 #define yylex ]b4_prefix[lex
202 #define yyerror ]b4_prefix[error
203 #define yylval ]b4_prefix[lval
204 #define yychar ]b4_prefix[char
205 #define yydebug ]b4_prefix[debug
206 #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
207 #define yylloc ]b4_prefix[lloc]])])[
208
209 /* Copy the first part of user declarations. */
210 ]b4_user_pre_prologue[
211
212 ]b4_null_define[
213
214 ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
215 [b4_shared_declarations])[
216
217 /* Enabling verbose error messages. */
218 #ifdef YYERROR_VERBOSE
219 # undef YYERROR_VERBOSE
220 # define YYERROR_VERBOSE 1
221 #else
222 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
223 #endif
224
225 /* Default (constant) value used for initialization for null
226 right-hand sides. Unlike the standard yacc.c template,
227 here we set the default value of $$ to a zeroed-out value.
228 Since the default value is undefined, this behavior is
229 technically correct. */
230 static YYSTYPE yyval_default;
231
232 /* Copy the second part of user declarations. */
233 ]b4_user_post_prologue
234 b4_percent_code_get[]dnl
235
236 [#include <stdio.h>
237 #include <stdlib.h>
238 #include <string.h>
239
240 #ifndef YY_
241 # if defined YYENABLE_NLS && YYENABLE_NLS
242 # if ENABLE_NLS
243 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
244 # define YY_(msgid) dgettext ("bison-runtime", msgid)
245 # endif
246 # endif
247 # ifndef YY_
248 # define YY_(msgid) msgid
249 # endif
250 #endif
251
252 /* Suppress unused-variable warnings by "using" E. */
253 #if ! defined lint || defined __GNUC__
254 # define YYUSE(e) ((void) (e))
255 #else
256 # define YYUSE(e) /* empty */
257 #endif
258
259 /* Identity function, used to suppress warnings about constant conditions. */
260 #ifndef lint
261 # define YYID(n) (n)
262 #else
263 ]b4_c_function_def([YYID], [static int], [[int i], [i]])[
264 {
265 return i;
266 }
267 #endif
268
269 #ifndef YYFREE
270 # define YYFREE free
271 #endif
272 #ifndef YYMALLOC
273 # define YYMALLOC malloc
274 #endif
275 #ifndef YYREALLOC
276 # define YYREALLOC realloc
277 #endif
278
279 #define YYSIZEMAX ((size_t) -1)
280
281 #ifdef __cplusplus
282 typedef bool yybool;
283 #else
284 typedef unsigned char yybool;
285 #endif
286 #define yytrue 1
287 #define yyfalse 0
288
289 #ifndef YYSETJMP
290 # include <setjmp.h>
291 # define YYJMP_BUF jmp_buf
292 # define YYSETJMP(env) setjmp (env)
293 # define YYLONGJMP(env, val) longjmp (env, val)
294 #endif
295
296 /*-----------------.
297 | GCC extensions. |
298 `-----------------*/
299
300 #ifndef __attribute__
301 /* This feature is available in gcc versions 2.5 and later. */
302 # if (! defined __GNUC__ || __GNUC__ < 2 \
303 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
304 # define __attribute__(Spec) /* empty */
305 # endif
306 #endif
307
308 ]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
309 #ifdef __cplusplus
310 # define YYOPTIONAL_LOC(Name) /* empty */
311 #else
312 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
313 #endif])[
314
315 #ifndef YYASSERT
316 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
317 #endif
318
319 /* YYFINAL -- State number of the termination state. */
320 #define YYFINAL ]b4_final_state_number[
321 /* YYLAST -- Last index in YYTABLE. */
322 #define YYLAST ]b4_last[
323
324 /* YYNTOKENS -- Number of terminals. */
325 #define YYNTOKENS ]b4_tokens_number[
326 /* YYNNTS -- Number of nonterminals. */
327 #define YYNNTS ]b4_nterms_number[
328 /* YYNRULES -- Number of rules. */
329 #define YYNRULES ]b4_rules_number[
330 /* YYNRULES -- Number of states. */
331 #define YYNSTATES ]b4_states_number[
332 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
333 #define YYMAXRHS ]b4_r2_max[
334 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
335 accessed by $0, $-1, etc., in any rule. */
336 #define YYMAXLEFT ]b4_max_left_semantic_context[
337
338 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
339 #define YYUNDEFTOK ]b4_undef_token_number[
340 #define YYMAXUTOK ]b4_user_token_number_max[
341
342 #define YYTRANSLATE(YYX) \
343 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
344
345 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
346 static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
347 {
348 ]b4_translate[
349 };
350
351 #if ]b4_api_PREFIX[DEBUG
352 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
353 YYRHS. */
354 static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
355 {
356 ]b4_prhs[
357 };
358
359 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
360 static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
361 {
362 ]b4_rhs[
363 };
364
365 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
366 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
367 {
368 ]b4_rline[
369 };
370 #endif
371
372 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
373 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
374 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
375 static const char *const yytname[] =
376 {
377 ]b4_tname[
378 };
379 #endif
380
381 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
382 static const ]b4_int_type_for([b4_r1])[ yyr1[] =
383 {
384 ]b4_r1[
385 };
386
387 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
388 static const ]b4_int_type_for([b4_r2])[ yyr2[] =
389 {
390 ]b4_r2[
391 };
392
393 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
394 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
395 {
396 ]b4_dprec[
397 };
398
399 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
400 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
401 {
402 ]b4_merger[
403 };
404
405 /* YYDEFACT[S] -- default reduction number in state S. Performed when
406 YYTABLE doesn't specify something else to do. Zero means the default
407 is an error. */
408 static const ]b4_int_type_for([b4_defact])[ yydefact[] =
409 {
410 ]b4_defact[
411 };
412
413 /* YYPDEFGOTO[NTERM-NUM]. */
414 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
415 {
416 ]b4_defgoto[
417 };
418
419 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
420 STATE-NUM. */
421 #define YYPACT_NINF ]b4_pact_ninf[
422 static const ]b4_int_type_for([b4_pact])[ yypact[] =
423 {
424 ]b4_pact[
425 };
426
427 /* YYPGOTO[NTERM-NUM]. */
428 static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
429 {
430 ]b4_pgoto[
431 };
432
433 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
434 positive, shift that token. If negative, reduce the rule which
435 number is the opposite. If YYTABLE_NINF, syntax error. */
436 #define YYTABLE_NINF ]b4_table_ninf[
437 static const ]b4_int_type_for([b4_table])[ yytable[] =
438 {
439 ]b4_table[
440 };
441
442 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
443 list of conflicting reductions corresponding to action entry for
444 state STATE-NUM in yytable. 0 means no conflicts. The list in
445 yyconfl is terminated by a rule number of 0. */
446 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
447 {
448 ]b4_conflict_list_heads[
449 };
450
451 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
452 0, pointed into by YYCONFLP. */
453 ]dnl Do not use b4_int_type_for here, since there are places where
454 dnl pointers onto yyconfl are taken, which type is "short int *".
455 dnl We probably ought to introduce a type for confl.
456 [static const short int yyconfl[] =
457 {
458 ]b4_conflicting_rules[
459 };
460
461 static const ]b4_int_type_for([b4_check])[ yycheck[] =
462 {
463 ]b4_check[
464 };
465
466 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
467 symbol of state STATE-NUM. */
468 static const ]b4_int_type_for([b4_stos])[ yystos[] =
469 {
470 ]b4_stos[
471 };
472
473 /* Error token number */
474 #define YYTERROR 1
475
476 ]b4_locations_if([[
477 #ifndef YYLLOC_DEFAULT
478 ]b4_yylloc_default_define[
479 # define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
480
481 /* YY_LOCATION_PRINT -- Print the location on the stream.
482 This macro was not mandated originally: define only if we know
483 we won't break user code: when these are the locations we know. */
484
485 # define YY_LOCATION_PRINT(File, Loc) \
486 fprintf (File, "%d.%d-%d.%d", \
487 (Loc).first_line, (Loc).first_column, \
488 (Loc).last_line, (Loc).last_column)
489 #endif
490 ]],[
491 #ifndef YYLLOC_DEFAULT
492 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
493 #endif
494 ])[
495
496 #ifndef YY_LOCATION_PRINT
497 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
498 #endif
499
500 /* YYLEX -- calling `yylex' with the right arguments. */
501 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
502
503 ]b4_pure_if(
504 [
505 #undef yynerrs
506 #define yynerrs (yystackp->yyerrcnt)
507 #undef yychar
508 #define yychar (yystackp->yyrawchar)
509 #undef yylval
510 #define yylval (yystackp->yyval)
511 #undef yylloc
512 #define yylloc (yystackp->yyloc)
513 m4_if(b4_prefix[], [yy], [],
514 [#define b4_prefix[]nerrs yynerrs
515 #define b4_prefix[]char yychar
516 #define b4_prefix[]lval yylval
517 #define b4_prefix[]lloc yylloc])],
518 [YYSTYPE yylval;]b4_locations_if([[
519 YYLTYPE yylloc;]])[
520
521 int yynerrs;
522 int yychar;])[
523
524 static const int YYEOF = 0;
525 static const int YYEMPTY = -2;
526
527 typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
528
529 #define YYCHK(YYE) \
530 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
531 while (YYID (0))
532
533 #if ]b4_api_PREFIX[DEBUG
534
535 # ifndef YYFPRINTF
536 # define YYFPRINTF fprintf
537 # endif
538
539 # define YYDPRINTF(Args) \
540 do { \
541 if (yydebug) \
542 YYFPRINTF Args; \
543 } while (YYID (0))
544
545 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def])[
546
547 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
548 do { \
549 if (yydebug) \
550 { \
551 YYFPRINTF (stderr, "%s ", Title); \
552 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
553 YYFPRINTF (stderr, "\n"); \
554 } \
555 } while (YYID (0))
556
557 /* Nonzero means print parse trace. It is left uninitialized so that
558 multiple parsers can coexist. */
559 int yydebug;
560
561 #else /* !]b4_api_PREFIX[DEBUG */
562
563 # define YYDPRINTF(Args)
564 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
565
566 #endif /* !]b4_api_PREFIX[DEBUG */
567
568 /* YYINITDEPTH -- initial size of the parser's stacks. */
569 #ifndef YYINITDEPTH
570 # define YYINITDEPTH ]b4_stack_depth_init[
571 #endif
572
573 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
574 if the built-in stack extension method is used).
575
576 Do not make this value too large; the results are undefined if
577 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
578 evaluated with infinite-precision integer arithmetic. */
579
580 #ifndef YYMAXDEPTH
581 # define YYMAXDEPTH ]b4_stack_depth_max[
582 #endif
583
584 /* Minimum number of free items on the stack allowed after an
585 allocation. This is to allow allocation and initialization
586 to be completed by functions that call yyexpandGLRStack before the
587 stack is expanded, thus insuring that all necessary pointers get
588 properly redirected to new data. */
589 #define YYHEADROOM 2
590
591 #ifndef YYSTACKEXPANDABLE
592 # if (! defined __cplusplus \
593 || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
594 && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL))
595 # define YYSTACKEXPANDABLE 1
596 # else
597 # define YYSTACKEXPANDABLE 0
598 # endif
599 #endif
600
601 #if YYSTACKEXPANDABLE
602 # define YY_RESERVE_GLRSTACK(Yystack) \
603 do { \
604 if (Yystack->yyspaceLeft < YYHEADROOM) \
605 yyexpandGLRStack (Yystack); \
606 } while (YYID (0))
607 #else
608 # define YY_RESERVE_GLRSTACK(Yystack) \
609 do { \
610 if (Yystack->yyspaceLeft < YYHEADROOM) \
611 yyMemoryExhausted (Yystack); \
612 } while (YYID (0))
613 #endif
614
615
616 #if YYERROR_VERBOSE
617
618 # ifndef yystpcpy
619 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
620 # define yystpcpy stpcpy
621 # else
622 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
623 YYDEST. */
624 static char *
625 yystpcpy (char *yydest, const char *yysrc)
626 {
627 char *yyd = yydest;
628 const char *yys = yysrc;
629
630 while ((*yyd++ = *yys++) != '\0')
631 continue;
632
633 return yyd - 1;
634 }
635 # endif
636 # endif
637
638 # ifndef yytnamerr
639 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
640 quotes and backslashes, so that it's suitable for yyerror. The
641 heuristic is that double-quoting is unnecessary unless the string
642 contains an apostrophe, a comma, or backslash (other than
643 backslash-backslash). YYSTR is taken from yytname. If YYRES is
644 null, do not copy; instead, return the length of what the result
645 would have been. */
646 static size_t
647 yytnamerr (char *yyres, const char *yystr)
648 {
649 if (*yystr == '"')
650 {
651 size_t yyn = 0;
652 char const *yyp = yystr;
653
654 for (;;)
655 switch (*++yyp)
656 {
657 case '\'':
658 case ',':
659 goto do_not_strip_quotes;
660
661 case '\\':
662 if (*++yyp != '\\')
663 goto do_not_strip_quotes;
664 /* Fall through. */
665 default:
666 if (yyres)
667 yyres[yyn] = *yyp;
668 yyn++;
669 break;
670
671 case '"':
672 if (yyres)
673 yyres[yyn] = '\0';
674 return yyn;
675 }
676 do_not_strip_quotes: ;
677 }
678
679 if (! yyres)
680 return strlen (yystr);
681
682 return yystpcpy (yyres, yystr) - yyres;
683 }
684 # endif
685
686 #endif /* !YYERROR_VERBOSE */
687
688 /** State numbers, as in LALR(1) machine */
689 typedef int yyStateNum;
690
691 /** Rule numbers, as in LALR(1) machine */
692 typedef int yyRuleNum;
693
694 /** Grammar symbol */
695 typedef short int yySymbol;
696
697 /** Item references, as in LALR(1) machine */
698 typedef short int yyItemNum;
699
700 typedef struct yyGLRState yyGLRState;
701 typedef struct yyGLRStateSet yyGLRStateSet;
702 typedef struct yySemanticOption yySemanticOption;
703 typedef union yyGLRStackItem yyGLRStackItem;
704 typedef struct yyGLRStack yyGLRStack;
705
706 struct yyGLRState {
707 /** Type tag: always true. */
708 yybool yyisState;
709 /** Type tag for yysemantics. If true, yysval applies, otherwise
710 * yyfirstVal applies. */
711 yybool yyresolved;
712 /** Number of corresponding LALR(1) machine state. */
713 yyStateNum yylrState;
714 /** Preceding state in this stack */
715 yyGLRState* yypred;
716 /** Source position of the first token produced by my symbol */
717 size_t yyposn;
718 union {
719 /** First in a chain of alternative reductions producing the
720 * non-terminal corresponding to this state, threaded through
721 * yynext. */
722 yySemanticOption* yyfirstVal;
723 /** Semantic value for this state. */
724 YYSTYPE yysval;
725 } yysemantics;]b4_locations_if([[
726 /** Source location for this state. */
727 YYLTYPE yyloc;]])[
728 };
729
730 struct yyGLRStateSet {
731 yyGLRState** yystates;
732 /** During nondeterministic operation, yylookaheadNeeds tracks which
733 * stacks have actually needed the current lookahead. During deterministic
734 * operation, yylookaheadNeeds[0] is not maintained since it would merely
735 * duplicate yychar != YYEMPTY. */
736 yybool* yylookaheadNeeds;
737 size_t yysize, yycapacity;
738 };
739
740 struct yySemanticOption {
741 /** Type tag: always false. */
742 yybool yyisState;
743 /** Rule number for this reduction */
744 yyRuleNum yyrule;
745 /** The last RHS state in the list of states to be reduced. */
746 yyGLRState* yystate;
747 /** The lookahead for this reduction. */
748 int yyrawchar;
749 YYSTYPE yyval;]b4_locations_if([[
750 YYLTYPE yyloc;]])[
751 /** Next sibling in chain of options. To facilitate merging,
752 * options are chained in decreasing order by address. */
753 yySemanticOption* yynext;
754 };
755
756 /** Type of the items in the GLR stack. The yyisState field
757 * indicates which item of the union is valid. */
758 union yyGLRStackItem {
759 yyGLRState yystate;
760 yySemanticOption yyoption;
761 };
762
763 struct yyGLRStack {
764 int yyerrState;
765 ]b4_locations_if([[ /* To compute the location of the error token. */
766 yyGLRStackItem yyerror_range[3];]])[
767 ]b4_pure_if(
768 [
769 int yyerrcnt;
770 int yyrawchar;
771 YYSTYPE yyval;]b4_locations_if([[
772 YYLTYPE yyloc;]])[
773 ])[
774 YYJMP_BUF yyexception_buffer;
775 yyGLRStackItem* yyitems;
776 yyGLRStackItem* yynextFree;
777 size_t yyspaceLeft;
778 yyGLRState* yysplitPoint;
779 yyGLRState* yylastDeleted;
780 yyGLRStateSet yytops;
781 };
782
783 #if YYSTACKEXPANDABLE
784 static void yyexpandGLRStack (yyGLRStack* yystackp);
785 #endif
786
787 static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
788 __attribute__ ((__noreturn__));
789 static void
790 yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
791 {
792 if (yymsg != YY_NULL)
793 yyerror (]b4_yyerror_args[yymsg);
794 YYLONGJMP (yystackp->yyexception_buffer, 1);
795 }
796
797 static void yyMemoryExhausted (yyGLRStack* yystackp)
798 __attribute__ ((__noreturn__));
799 static void
800 yyMemoryExhausted (yyGLRStack* yystackp)
801 {
802 YYLONGJMP (yystackp->yyexception_buffer, 2);
803 }
804
805 #if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
806 /** A printable representation of TOKEN. */
807 static inline const char*
808 yytokenName (yySymbol yytoken)
809 {
810 if (yytoken == YYEMPTY)
811 return "";
812
813 return yytname[yytoken];
814 }
815 #endif
816
817 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
818 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
819 * containing the pointer to the next state in the chain. */
820 static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
821 static void
822 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
823 {
824 int i;
825 yyGLRState *s = yyvsp[yylow0].yystate.yypred;
826 for (i = yylow0-1; i >= yylow1; i -= 1)
827 {
828 YYASSERT (s->yyresolved);
829 yyvsp[i].yystate.yyresolved = yytrue;
830 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;]b4_locations_if([[
831 yyvsp[i].yystate.yyloc = s->yyloc;]])[
832 s = yyvsp[i].yystate.yypred = s->yypred;
833 }
834 }
835
836 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
837 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
838 * For convenience, always return YYLOW1. */
839 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
840 __attribute__ ((__unused__));
841 static inline int
842 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
843 {
844 if (!yynormal && yylow1 < *yylow)
845 {
846 yyfillin (yyvsp, *yylow, yylow1);
847 *yylow = yylow1;
848 }
849 return yylow1;
850 }
851
852 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
853 * and top stack item YYVSP. YYLVALP points to place to put semantic
854 * value ($$), and yylocp points to place for location information
855 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
856 * yyerr for YYERROR, yyabort for YYABORT. */
857 /*ARGSUSED*/ static YYRESULTTAG
858 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
859 yyGLRStack* yystackp,
860 YYSTYPE* yyvalp]b4_locuser_formals[)
861 {
862 yybool yynormal __attribute__ ((__unused__)) =
863 (yystackp->yysplitPoint == YY_NULL);
864 int yylow;
865 ]b4_parse_param_use[]dnl
866 [# undef yyerrok
867 # define yyerrok (yystackp->yyerrState = 0)
868 # undef YYACCEPT
869 # define YYACCEPT return yyaccept
870 # undef YYABORT
871 # define YYABORT return yyabort
872 # undef YYERROR
873 # define YYERROR return yyerrok, yyerr
874 # undef YYRECOVERING
875 # define YYRECOVERING() (yystackp->yyerrState != 0)
876 # undef yyclearin
877 # define yyclearin (yychar = YYEMPTY)
878 # undef YYFILL
879 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
880 # undef YYBACKUP
881 # define YYBACKUP(Token, Value) \
882 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
883 yyerrok, yyerr
884
885 yylow = 1;
886 if (yyrhslen == 0)
887 *yyvalp = yyval_default;
888 else
889 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
890 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
891 yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
892 ]])[
893 switch (yyn)
894 {
895 ]b4_user_actions[
896 default: break;
897 }
898
899 return yyok;
900 # undef yyerrok
901 # undef YYABORT
902 # undef YYACCEPT
903 # undef YYERROR
904 # undef YYBACKUP
905 # undef yyclearin
906 # undef YYRECOVERING
907 }
908 \f
909
910 /*ARGSUSED*/ static void
911 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
912 {
913 YYUSE (yy0);
914 YYUSE (yy1);
915
916 switch (yyn)
917 {
918 ]b4_mergers[
919 default: break;
920 }
921 }
922
923 /* Bison grammar-table manipulation. */
924
925 ]b4_yydestruct_generate([b4_c_ansi_function_def])[
926
927 /** Number of symbols composing the right hand side of rule #RULE. */
928 static inline int
929 yyrhsLength (yyRuleNum yyrule)
930 {
931 return yyr2[yyrule];
932 }
933
934 static void
935 yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
936 {
937 if (yys->yyresolved)
938 yydestruct (yymsg, yystos[yys->yylrState],
939 &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
940 else
941 {
942 #if ]b4_api_PREFIX[DEBUG
943 if (yydebug)
944 {
945 if (yys->yysemantics.yyfirstVal)
946 YYFPRINTF (stderr, "%s unresolved ", yymsg);
947 else
948 YYFPRINTF (stderr, "%s incomplete ", yymsg);
949 yy_symbol_print (stderr, yystos[yys->yylrState],
950 YY_NULL]b4_locuser_args([&yys->yyloc])[);
951 YYFPRINTF (stderr, "\n");
952 }
953 #endif
954
955 if (yys->yysemantics.yyfirstVal)
956 {
957 yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
958 yyGLRState *yyrh;
959 int yyn;
960 for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
961 yyn > 0;
962 yyrh = yyrh->yypred, yyn -= 1)
963 yydestroyGLRState (yymsg, yyrh]b4_user_args[);
964 }
965 }
966 }
967
968 /** Left-hand-side symbol for rule #RULE. */
969 static inline yySymbol
970 yylhsNonterm (yyRuleNum yyrule)
971 {
972 return yyr1[yyrule];
973 }
974
975 #define yypact_value_is_default(yystate) \
976 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
977
978 /** True iff LR state STATE has only a default reduction (regardless
979 * of token). */
980 static inline yybool
981 yyisDefaultedState (yyStateNum yystate)
982 {
983 return yypact_value_is_default (yypact[yystate]);
984 }
985
986 /** The default reduction for STATE, assuming it has one. */
987 static inline yyRuleNum
988 yydefaultAction (yyStateNum yystate)
989 {
990 return yydefact[yystate];
991 }
992
993 #define yytable_value_is_error(yytable_value) \
994 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
995
996 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
997 * Result R means
998 * R < 0: Reduce on rule -R.
999 * R = 0: Error.
1000 * R > 0: Shift to state R.
1001 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1002 * conflicting reductions.
1003 */
1004 static inline void
1005 yygetLRActions (yyStateNum yystate, int yytoken,
1006 int* yyaction, const short int** yyconflicts)
1007 {
1008 int yyindex = yypact[yystate] + yytoken;
1009 if (yypact_value_is_default (yypact[yystate])
1010 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
1011 {
1012 *yyaction = -yydefact[yystate];
1013 *yyconflicts = yyconfl;
1014 }
1015 else if (! yytable_value_is_error (yytable[yyindex]))
1016 {
1017 *yyaction = yytable[yyindex];
1018 *yyconflicts = yyconfl + yyconflp[yyindex];
1019 }
1020 else
1021 {
1022 *yyaction = 0;
1023 *yyconflicts = yyconfl + yyconflp[yyindex];
1024 }
1025 }
1026
1027 static inline yyStateNum
1028 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
1029 {
1030 int yyr;
1031 yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
1032 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
1033 return yytable[yyr];
1034 else
1035 return yydefgoto[yylhs - YYNTOKENS];
1036 }
1037
1038 static inline yybool
1039 yyisShiftAction (int yyaction)
1040 {
1041 return 0 < yyaction;
1042 }
1043
1044 static inline yybool
1045 yyisErrorAction (int yyaction)
1046 {
1047 return yyaction == 0;
1048 }
1049
1050 /* GLRStates */
1051
1052 /** Return a fresh GLRStackItem. Callers should call
1053 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1054 * headroom. */
1055
1056 static inline yyGLRStackItem*
1057 yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
1058 {
1059 yyGLRStackItem* yynewItem = yystackp->yynextFree;
1060 yystackp->yyspaceLeft -= 1;
1061 yystackp->yynextFree += 1;
1062 yynewItem->yystate.yyisState = yyisState;
1063 return yynewItem;
1064 }
1065
1066 /** Add a new semantic action that will execute the action for rule
1067 * RULENUM on the semantic values in RHS to the list of
1068 * alternative actions for STATE. Assumes that RHS comes from
1069 * stack #K of *STACKP. */
1070 static void
1071 yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
1072 yyGLRState* rhs, yyRuleNum yyrule)
1073 {
1074 yySemanticOption* yynewOption =
1075 &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
1076 yynewOption->yystate = rhs;
1077 yynewOption->yyrule = yyrule;
1078 if (yystackp->yytops.yylookaheadNeeds[yyk])
1079 {
1080 yynewOption->yyrawchar = yychar;
1081 yynewOption->yyval = yylval;]b4_locations_if([
1082 yynewOption->yyloc = yylloc;])[
1083 }
1084 else
1085 yynewOption->yyrawchar = YYEMPTY;
1086 yynewOption->yynext = yystate->yysemantics.yyfirstVal;
1087 yystate->yysemantics.yyfirstVal = yynewOption;
1088
1089 YY_RESERVE_GLRSTACK (yystackp);
1090 }
1091
1092 /* GLRStacks */
1093
1094 /** Initialize SET to a singleton set containing an empty stack. */
1095 static yybool
1096 yyinitStateSet (yyGLRStateSet* yyset)
1097 {
1098 yyset->yysize = 1;
1099 yyset->yycapacity = 16;
1100 yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
1101 if (! yyset->yystates)
1102 return yyfalse;
1103 yyset->yystates[0] = YY_NULL;
1104 yyset->yylookaheadNeeds =
1105 (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
1106 if (! yyset->yylookaheadNeeds)
1107 {
1108 YYFREE (yyset->yystates);
1109 return yyfalse;
1110 }
1111 return yytrue;
1112 }
1113
1114 static void yyfreeStateSet (yyGLRStateSet* yyset)
1115 {
1116 YYFREE (yyset->yystates);
1117 YYFREE (yyset->yylookaheadNeeds);
1118 }
1119
1120 /** Initialize STACK to a single empty stack, with total maximum
1121 * capacity for all stacks of SIZE. */
1122 static yybool
1123 yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
1124 {
1125 yystackp->yyerrState = 0;
1126 yynerrs = 0;
1127 yystackp->yyspaceLeft = yysize;
1128 yystackp->yyitems =
1129 (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
1130 if (!yystackp->yyitems)
1131 return yyfalse;
1132 yystackp->yynextFree = yystackp->yyitems;
1133 yystackp->yysplitPoint = YY_NULL;
1134 yystackp->yylastDeleted = YY_NULL;
1135 return yyinitStateSet (&yystackp->yytops);
1136 }
1137
1138
1139 #if YYSTACKEXPANDABLE
1140 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1141 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1142
1143 /** If STACK is expandable, extend it. WARNING: Pointers into the
1144 stack from outside should be considered invalid after this call.
1145 We always expand when there are 1 or fewer items left AFTER an
1146 allocation, so that we can avoid having external pointers exist
1147 across an allocation. */
1148 static void
1149 yyexpandGLRStack (yyGLRStack* yystackp)
1150 {
1151 yyGLRStackItem* yynewItems;
1152 yyGLRStackItem* yyp0, *yyp1;
1153 size_t yynewSize;
1154 size_t yyn;
1155 size_t yysize = yystackp->yynextFree - yystackp->yyitems;
1156 if (YYMAXDEPTH - YYHEADROOM < yysize)
1157 yyMemoryExhausted (yystackp);
1158 yynewSize = 2*yysize;
1159 if (YYMAXDEPTH < yynewSize)
1160 yynewSize = YYMAXDEPTH;
1161 yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
1162 if (! yynewItems)
1163 yyMemoryExhausted (yystackp);
1164 for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
1165 0 < yyn;
1166 yyn -= 1, yyp0 += 1, yyp1 += 1)
1167 {
1168 *yyp1 = *yyp0;
1169 if (*(yybool *) yyp0)
1170 {
1171 yyGLRState* yys0 = &yyp0->yystate;
1172 yyGLRState* yys1 = &yyp1->yystate;
1173 if (yys0->yypred != YY_NULL)
1174 yys1->yypred =
1175 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
1176 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULL)
1177 yys1->yysemantics.yyfirstVal =
1178 YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
1179 }
1180 else
1181 {
1182 yySemanticOption* yyv0 = &yyp0->yyoption;
1183 yySemanticOption* yyv1 = &yyp1->yyoption;
1184 if (yyv0->yystate != YY_NULL)
1185 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
1186 if (yyv0->yynext != YY_NULL)
1187 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
1188 }
1189 }
1190 if (yystackp->yysplitPoint != YY_NULL)
1191 yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
1192 yystackp->yysplitPoint, yystate);
1193
1194 for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
1195 if (yystackp->yytops.yystates[yyn] != YY_NULL)
1196 yystackp->yytops.yystates[yyn] =
1197 YYRELOC (yystackp->yyitems, yynewItems,
1198 yystackp->yytops.yystates[yyn], yystate);
1199 YYFREE (yystackp->yyitems);
1200 yystackp->yyitems = yynewItems;
1201 yystackp->yynextFree = yynewItems + yysize;
1202 yystackp->yyspaceLeft = yynewSize - yysize;
1203 }
1204 #endif
1205
1206 static void
1207 yyfreeGLRStack (yyGLRStack* yystackp)
1208 {
1209 YYFREE (yystackp->yyitems);
1210 yyfreeStateSet (&yystackp->yytops);
1211 }
1212
1213 /** Assuming that S is a GLRState somewhere on STACK, update the
1214 * splitpoint of STACK, if needed, so that it is at least as deep as
1215 * S. */
1216 static inline void
1217 yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
1218 {
1219 if (yystackp->yysplitPoint != YY_NULL && yystackp->yysplitPoint > yys)
1220 yystackp->yysplitPoint = yys;
1221 }
1222
1223 /** Invalidate stack #K in STACK. */
1224 static inline void
1225 yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
1226 {
1227 if (yystackp->yytops.yystates[yyk] != YY_NULL)
1228 yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
1229 yystackp->yytops.yystates[yyk] = YY_NULL;
1230 }
1231
1232 /** Undelete the last stack that was marked as deleted. Can only be
1233 done once after a deletion, and only when all other stacks have
1234 been deleted. */
1235 static void
1236 yyundeleteLastStack (yyGLRStack* yystackp)
1237 {
1238 if (yystackp->yylastDeleted == YY_NULL || yystackp->yytops.yysize != 0)
1239 return;
1240 yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
1241 yystackp->yytops.yysize = 1;
1242 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
1243 yystackp->yylastDeleted = YY_NULL;
1244 }
1245
1246 static inline void
1247 yyremoveDeletes (yyGLRStack* yystackp)
1248 {
1249 size_t yyi, yyj;
1250 yyi = yyj = 0;
1251 while (yyj < yystackp->yytops.yysize)
1252 {
1253 if (yystackp->yytops.yystates[yyi] == YY_NULL)
1254 {
1255 if (yyi == yyj)
1256 {
1257 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
1258 }
1259 yystackp->yytops.yysize -= 1;
1260 }
1261 else
1262 {
1263 yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
1264 /* In the current implementation, it's unnecessary to copy
1265 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1266 yyremoveDeletes returns, the parser immediately either enters
1267 deterministic operation or shifts a token. However, it doesn't
1268 hurt, and the code might evolve to need it. */
1269 yystackp->yytops.yylookaheadNeeds[yyj] =
1270 yystackp->yytops.yylookaheadNeeds[yyi];
1271 if (yyj != yyi)
1272 {
1273 YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
1274 (unsigned long int) yyi, (unsigned long int) yyj));
1275 }
1276 yyj += 1;
1277 }
1278 yyi += 1;
1279 }
1280 }
1281
1282 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1283 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1284 static inline void
1285 yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1286 size_t yyposn,
1287 YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
1288 {
1289 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1290
1291 yynewState->yylrState = yylrState;
1292 yynewState->yyposn = yyposn;
1293 yynewState->yyresolved = yytrue;
1294 yynewState->yypred = yystackp->yytops.yystates[yyk];
1295 yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([
1296 yynewState->yyloc = *yylocp;])[
1297 yystackp->yytops.yystates[yyk] = yynewState;
1298
1299 YY_RESERVE_GLRSTACK (yystackp);
1300 }
1301
1302 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1303 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1304 * semantic value of YYRHS under the action for YYRULE. */
1305 static inline void
1306 yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1307 size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule)
1308 {
1309 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1310
1311 yynewState->yylrState = yylrState;
1312 yynewState->yyposn = yyposn;
1313 yynewState->yyresolved = yyfalse;
1314 yynewState->yypred = yystackp->yytops.yystates[yyk];
1315 yynewState->yysemantics.yyfirstVal = YY_NULL;
1316 yystackp->yytops.yystates[yyk] = yynewState;
1317
1318 /* Invokes YY_RESERVE_GLRSTACK. */
1319 yyaddDeferredAction (yystackp, yyk, yynewState, rhs, yyrule);
1320 }
1321
1322 /** Pop the symbols consumed by reduction #RULE from the top of stack
1323 * #K of STACK, and perform the appropriate semantic action on their
1324 * semantic values. Assumes that all ambiguities in semantic values
1325 * have been previously resolved. Set *VALP to the resulting value,
1326 * and *LOCP to the computed location (if any). Return value is as
1327 * for userAction. */
1328 static inline YYRESULTTAG
1329 yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1330 YYSTYPE* yyvalp]b4_locuser_formals[)
1331 {
1332 int yynrhs = yyrhsLength (yyrule);
1333
1334 if (yystackp->yysplitPoint == YY_NULL)
1335 {
1336 /* Standard special case: single stack. */
1337 yyGLRStackItem* rhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
1338 YYASSERT (yyk == 0);
1339 yystackp->yynextFree -= yynrhs;
1340 yystackp->yyspaceLeft += yynrhs;
1341 yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
1342 return yyuserAction (yyrule, yynrhs, rhs, yystackp,
1343 yyvalp]b4_locuser_args[);
1344 }
1345 else
1346 {
1347 /* At present, doAction is never called in nondeterministic
1348 * mode, so this branch is never taken. It is here in
1349 * anticipation of a future feature that will allow immediate
1350 * evaluation of selected actions in nondeterministic mode. */
1351 int yyi;
1352 yyGLRState* yys;
1353 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1354 yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
1355 = yystackp->yytops.yystates[yyk];]b4_locations_if([[
1356 if (yynrhs == 0)
1357 /* Set default location. */
1358 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
1359 for (yyi = 0; yyi < yynrhs; yyi += 1)
1360 {
1361 yys = yys->yypred;
1362 YYASSERT (yys);
1363 }
1364 yyupdateSplit (yystackp, yys);
1365 yystackp->yytops.yystates[yyk] = yys;
1366 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1367 yystackp, yyvalp]b4_locuser_args[);
1368 }
1369 }
1370
1371 #if !]b4_api_PREFIX[DEBUG
1372 # define YY_REDUCE_PRINT(Args)
1373 #else
1374 # define YY_REDUCE_PRINT(Args) \
1375 do { \
1376 if (yydebug) \
1377 yy_reduce_print Args; \
1378 } while (YYID (0))
1379
1380 /*----------------------------------------------------------.
1381 | Report that the RULE is going to be reduced on stack #K. |
1382 `----------------------------------------------------------*/
1383
1384 /*ARGSUSED*/ static inline void
1385 yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1386 YYSTYPE* yyvalp]b4_locuser_formals[)
1387 {
1388 int yynrhs = yyrhsLength (yyrule);
1389 yybool yynormal __attribute__ ((__unused__)) =
1390 (yystackp->yysplitPoint == YY_NULL);
1391 yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
1392 int yylow = 1;
1393 int yyi;
1394 YYUSE (yyvalp);]b4_locations_if([
1395 YYUSE (yylocp);])[
1396 ]b4_parse_param_use[]dnl
1397 [ YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
1398 (unsigned long int) yyk, yyrule - 1,
1399 (unsigned long int) yyrline[yyrule]);
1400 /* The symbols being reduced. */
1401 for (yyi = 0; yyi < yynrhs; yyi++)
1402 {
1403 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1404 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1405 &]b4_rhs_value(yynrhs, yyi + 1)[
1406 ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
1407 b4_user_args[);
1408 YYFPRINTF (stderr, "\n");
1409 }
1410 }
1411 #endif
1412
1413 /** Pop items off stack #K of STACK according to grammar rule RULE,
1414 * and push back on the resulting nonterminal symbol. Perform the
1415 * semantic action associated with RULE and store its value with the
1416 * newly pushed state, if FORCEEVAL or if STACK is currently
1417 * unambiguous. Otherwise, store the deferred semantic action with
1418 * the new state. If the new state would have an identical input
1419 * position, LR state, and predecessor to an existing state on the stack,
1420 * it is identified with that existing state, eliminating stack #K from
1421 * the STACK. In this case, the (necessarily deferred) semantic value is
1422 * added to the options for the existing state's semantic value.
1423 */
1424 static inline YYRESULTTAG
1425 yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1426 yybool yyforceEval]b4_user_formals[)
1427 {
1428 size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
1429
1430 if (yyforceEval || yystackp->yysplitPoint == YY_NULL)
1431 {
1432 YYSTYPE yysval;]b4_locations_if([
1433 YYLTYPE yyloc;])[
1434
1435 YY_REDUCE_PRINT ((yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[));
1436 YYCHK (yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[));
1437 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
1438 yyglrShift (yystackp, yyk,
1439 yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
1440 yylhsNonterm (yyrule)),
1441 yyposn, &yysval]b4_locations_if([, &yyloc])[);
1442 }
1443 else
1444 {
1445 size_t yyi;
1446 int yyn;
1447 yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
1448 yyStateNum yynewLRState;
1449
1450 for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1451 0 < yyn; yyn -= 1)
1452 {
1453 yys = yys->yypred;
1454 YYASSERT (yys);
1455 }
1456 yyupdateSplit (yystackp, yys);
1457 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1458 YYDPRINTF ((stderr,
1459 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1460 (unsigned long int) yyk, yyrule - 1, yynewLRState));
1461 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
1462 if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULL)
1463 {
1464 yyGLRState *yysplit = yystackp->yysplitPoint;
1465 yyGLRState *yyp = yystackp->yytops.yystates[yyi];
1466 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1467 {
1468 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1469 {
1470 yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
1471 yymarkStackDeleted (yystackp, yyk);
1472 YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
1473 (unsigned long int) yyk,
1474 (unsigned long int) yyi));
1475 return yyok;
1476 }
1477 yyp = yyp->yypred;
1478 }
1479 }
1480 yystackp->yytops.yystates[yyk] = yys;
1481 yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
1482 }
1483 return yyok;
1484 }
1485
1486 static size_t
1487 yysplitStack (yyGLRStack* yystackp, size_t yyk)
1488 {
1489 if (yystackp->yysplitPoint == YY_NULL)
1490 {
1491 YYASSERT (yyk == 0);
1492 yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
1493 }
1494 if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
1495 {
1496 yyGLRState** yynewStates;
1497 yybool* yynewLookaheadNeeds;
1498
1499 yynewStates = YY_NULL;
1500
1501 if (yystackp->yytops.yycapacity
1502 > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
1503 yyMemoryExhausted (yystackp);
1504 yystackp->yytops.yycapacity *= 2;
1505
1506 yynewStates =
1507 (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
1508 (yystackp->yytops.yycapacity
1509 * sizeof yynewStates[0]));
1510 if (yynewStates == YY_NULL)
1511 yyMemoryExhausted (yystackp);
1512 yystackp->yytops.yystates = yynewStates;
1513
1514 yynewLookaheadNeeds =
1515 (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
1516 (yystackp->yytops.yycapacity
1517 * sizeof yynewLookaheadNeeds[0]));
1518 if (yynewLookaheadNeeds == YY_NULL)
1519 yyMemoryExhausted (yystackp);
1520 yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
1521 }
1522 yystackp->yytops.yystates[yystackp->yytops.yysize]
1523 = yystackp->yytops.yystates[yyk];
1524 yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
1525 = yystackp->yytops.yylookaheadNeeds[yyk];
1526 yystackp->yytops.yysize += 1;
1527 return yystackp->yytops.yysize-1;
1528 }
1529
1530 /** True iff Y0 and Y1 represent identical options at the top level.
1531 * That is, they represent the same rule applied to RHS symbols
1532 * that produce the same terminal symbols. */
1533 static yybool
1534 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1535 {
1536 if (yyy0->yyrule == yyy1->yyrule)
1537 {
1538 yyGLRState *yys0, *yys1;
1539 int yyn;
1540 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1541 yyn = yyrhsLength (yyy0->yyrule);
1542 yyn > 0;
1543 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1544 if (yys0->yyposn != yys1->yyposn)
1545 return yyfalse;
1546 return yytrue;
1547 }
1548 else
1549 return yyfalse;
1550 }
1551
1552 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1553 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1554 static void
1555 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1556 {
1557 yyGLRState *yys0, *yys1;
1558 int yyn;
1559 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1560 yyn = yyrhsLength (yyy0->yyrule);
1561 yyn > 0;
1562 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1563 {
1564 if (yys0 == yys1)
1565 break;
1566 else if (yys0->yyresolved)
1567 {
1568 yys1->yyresolved = yytrue;
1569 yys1->yysemantics.yysval = yys0->yysemantics.yysval;
1570 }
1571 else if (yys1->yyresolved)
1572 {
1573 yys0->yyresolved = yytrue;
1574 yys0->yysemantics.yysval = yys1->yysemantics.yysval;
1575 }
1576 else
1577 {
1578 yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
1579 yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
1580 while (YYID (yytrue))
1581 {
1582 if (yyz1 == *yyz0p || yyz1 == YY_NULL)
1583 break;
1584 else if (*yyz0p == YY_NULL)
1585 {
1586 *yyz0p = yyz1;
1587 break;
1588 }
1589 else if (*yyz0p < yyz1)
1590 {
1591 yySemanticOption* yyz = *yyz0p;
1592 *yyz0p = yyz1;
1593 yyz1 = yyz1->yynext;
1594 (*yyz0p)->yynext = yyz;
1595 }
1596 yyz0p = &(*yyz0p)->yynext;
1597 }
1598 yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
1599 }
1600 }
1601 }
1602
1603 /** Y0 and Y1 represent two possible actions to take in a given
1604 * parsing state; return 0 if no combination is possible,
1605 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1606 static int
1607 yypreference (yySemanticOption* y0, yySemanticOption* y1)
1608 {
1609 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1610 int p0 = yydprec[r0], p1 = yydprec[r1];
1611
1612 if (p0 == p1)
1613 {
1614 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1615 return 0;
1616 else
1617 return 1;
1618 }
1619 if (p0 == 0 || p1 == 0)
1620 return 0;
1621 if (p0 < p1)
1622 return 3;
1623 if (p1 < p0)
1624 return 2;
1625 return 0;
1626 }
1627
1628 static YYRESULTTAG yyresolveValue (yyGLRState* yys,
1629 yyGLRStack* yystackp]b4_user_formals[);
1630
1631
1632 /** Resolve the previous N states starting at and including state S. If result
1633 * != yyok, some states may have been left unresolved possibly with empty
1634 * semantic option chains. Regardless of whether result = yyok, each state
1635 * has been left with consistent data so that yydestroyGLRState can be invoked
1636 * if necessary. */
1637 static YYRESULTTAG
1638 yyresolveStates (yyGLRState* yys, int yyn,
1639 yyGLRStack* yystackp]b4_user_formals[)
1640 {
1641 if (0 < yyn)
1642 {
1643 YYASSERT (yys->yypred);
1644 YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
1645 if (! yys->yyresolved)
1646 YYCHK (yyresolveValue (yys, yystackp]b4_user_args[));
1647 }
1648 return yyok;
1649 }
1650
1651 /** Resolve the states for the RHS of OPT, perform its user action, and return
1652 * the semantic value and location. Regardless of whether result = yyok, all
1653 * RHS states have been destroyed (assuming the user action destroys all RHS
1654 * semantic values if invoked). */
1655 static YYRESULTTAG
1656 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
1657 YYSTYPE* yyvalp]b4_locuser_formals[)
1658 {
1659 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1660 int yynrhs = yyrhsLength (yyopt->yyrule);
1661 YYRESULTTAG yyflag =
1662 yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
1663 if (yyflag != yyok)
1664 {
1665 yyGLRState *yys;
1666 for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
1667 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
1668 return yyflag;
1669 }
1670
1671 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[
1672 if (yynrhs == 0)
1673 /* Set default location. */
1674 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
1675 {
1676 int yychar_current = yychar;
1677 YYSTYPE yylval_current = yylval;]b4_locations_if([
1678 YYLTYPE yylloc_current = yylloc;])[
1679 yychar = yyopt->yyrawchar;
1680 yylval = yyopt->yyval;]b4_locations_if([
1681 yylloc = yyopt->yyloc;])[
1682 yyflag = yyuserAction (yyopt->yyrule, yynrhs,
1683 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1684 yystackp, yyvalp]b4_locuser_args[);
1685 yychar = yychar_current;
1686 yylval = yylval_current;]b4_locations_if([
1687 yylloc = yylloc_current;])[
1688 }
1689 return yyflag;
1690 }
1691
1692 #if ]b4_api_PREFIX[DEBUG
1693 static void
1694 yyreportTree (yySemanticOption* yyx, int yyindent)
1695 {
1696 int yynrhs = yyrhsLength (yyx->yyrule);
1697 int yyi;
1698 yyGLRState* yys;
1699 yyGLRState* yystates[1 + YYMAXRHS];
1700 yyGLRState yyleftmost_state;
1701
1702 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1703 yystates[yyi] = yys;
1704 if (yys == YY_NULL)
1705 {
1706 yyleftmost_state.yyposn = 0;
1707 yystates[0] = &yyleftmost_state;
1708 }
1709 else
1710 yystates[0] = yys;
1711
1712 if (yyx->yystate->yyposn < yys->yyposn + 1)
1713 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1714 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1715 yyx->yyrule - 1);
1716 else
1717 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1718 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1719 yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
1720 (unsigned long int) yyx->yystate->yyposn);
1721 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1722 {
1723 if (yystates[yyi]->yyresolved)
1724 {
1725 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1726 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1727 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
1728 else
1729 YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
1730 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1731 (unsigned long int) (yystates[yyi - 1]->yyposn + 1),
1732 (unsigned long int) yystates[yyi]->yyposn);
1733 }
1734 else
1735 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1736 }
1737 }
1738 #endif
1739
1740 /*ARGSUSED*/ static YYRESULTTAG
1741 yyreportAmbiguity (yySemanticOption* yyx0,
1742 yySemanticOption* yyx1]b4_pure_formals[)
1743 {
1744 YYUSE (yyx0);
1745 YYUSE (yyx1);
1746
1747 #if ]b4_api_PREFIX[DEBUG
1748 YYFPRINTF (stderr, "Ambiguity detected.\n");
1749 YYFPRINTF (stderr, "Option 1,\n");
1750 yyreportTree (yyx0, 2);
1751 YYFPRINTF (stderr, "\nOption 2,\n");
1752 yyreportTree (yyx1, 2);
1753 YYFPRINTF (stderr, "\n");
1754 #endif
1755
1756 yyerror (]b4_yyerror_args[YY_("syntax is ambiguous"));
1757 return yyabort;
1758 }]b4_locations_if([[
1759
1760 /** Starting at and including state S1, resolve the location for each of the
1761 * previous N1 states that is unresolved. The first semantic option of a state
1762 * is always chosen. */
1763 static void
1764 yyresolveLocations (yyGLRState* yys1, int yyn1,
1765 yyGLRStack *yystackp]b4_user_formals[)
1766 {
1767 if (0 < yyn1)
1768 {
1769 yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
1770 if (!yys1->yyresolved)
1771 {
1772 yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
1773 int yynrhs;
1774 yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
1775 YYASSERT (yyoption != YY_NULL);
1776 yynrhs = yyrhsLength (yyoption->yyrule);
1777 if (yynrhs > 0)
1778 {
1779 yyGLRState *yys;
1780 int yyn;
1781 yyresolveLocations (yyoption->yystate, yynrhs,
1782 yystackp]b4_user_args[);
1783 for (yys = yyoption->yystate, yyn = yynrhs;
1784 yyn > 0;
1785 yys = yys->yypred, yyn -= 1)
1786 yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
1787 }
1788 else
1789 {
1790 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1791 in reverse rightmost order. It is only necessary to invoke
1792 yyresolveLocations on a subforest for which yyresolveAction
1793 would have been invoked next had an ambiguity not been
1794 detected. Thus the location of the previous state (but not
1795 necessarily the previous state itself) is guaranteed to be
1796 resolved already. */
1797 yyGLRState *yyprevious = yyoption->yystate;
1798 yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
1799 }
1800 {
1801 int yychar_current = yychar;
1802 YYSTYPE yylval_current = yylval;
1803 YYLTYPE yylloc_current = yylloc;
1804 yychar = yyoption->yyrawchar;
1805 yylval = yyoption->yyval;
1806 yylloc = yyoption->yyloc;
1807 YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
1808 yychar = yychar_current;
1809 yylval = yylval_current;
1810 yylloc = yylloc_current;
1811 }
1812 }
1813 }
1814 }]])[
1815
1816 /** Resolve the ambiguity represented in state S, perform the indicated
1817 * actions, and set the semantic value of S. If result != yyok, the chain of
1818 * semantic options in S has been cleared instead or it has been left
1819 * unmodified except that redundant options may have been removed. Regardless
1820 * of whether result = yyok, S has been left with consistent data so that
1821 * yydestroyGLRState can be invoked if necessary. */
1822 static YYRESULTTAG
1823 yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
1824 {
1825 yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
1826 yySemanticOption* yybest = yyoptionList;
1827 yySemanticOption** yypp;
1828 yybool yymerge = yyfalse;
1829 YYSTYPE yysval;
1830 YYRESULTTAG yyflag;]b4_locations_if([
1831 YYLTYPE *yylocp = &yys->yyloc;])[
1832
1833 for (yypp = &yyoptionList->yynext; *yypp != YY_NULL; )
1834 {
1835 yySemanticOption* yyp = *yypp;
1836
1837 if (yyidenticalOptions (yybest, yyp))
1838 {
1839 yymergeOptionSets (yybest, yyp);
1840 *yypp = yyp->yynext;
1841 }
1842 else
1843 {
1844 switch (yypreference (yybest, yyp))
1845 {
1846 case 0:]b4_locations_if([[
1847 yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[
1848 return yyreportAmbiguity (yybest, yyp]b4_pure_args[);
1849 break;
1850 case 1:
1851 yymerge = yytrue;
1852 break;
1853 case 2:
1854 break;
1855 case 3:
1856 yybest = yyp;
1857 yymerge = yyfalse;
1858 break;
1859 default:
1860 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1861 but some compilers complain if the default case is
1862 omitted. */
1863 break;
1864 }
1865 yypp = &yyp->yynext;
1866 }
1867 }
1868
1869 if (yymerge)
1870 {
1871 yySemanticOption* yyp;
1872 int yyprec = yydprec[yybest->yyrule];
1873 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[);
1874 if (yyflag == yyok)
1875 for (yyp = yybest->yynext; yyp != YY_NULL; yyp = yyp->yynext)
1876 {
1877 if (yyprec == yydprec[yyp->yyrule])
1878 {
1879 YYSTYPE yysval_other;]b4_locations_if([
1880 YYLTYPE yydummy;])[
1881 yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[);
1882 if (yyflag != yyok)
1883 {
1884 yydestruct ("Cleanup: discarding incompletely merged value for",
1885 yystos[yys->yylrState],
1886 &yysval]b4_locuser_args[);
1887 break;
1888 }
1889 yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
1890 }
1891 }
1892 }
1893 else
1894 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[);
1895
1896 if (yyflag == yyok)
1897 {
1898 yys->yyresolved = yytrue;
1899 yys->yysemantics.yysval = yysval;
1900 }
1901 else
1902 yys->yysemantics.yyfirstVal = YY_NULL;
1903 return yyflag;
1904 }
1905
1906 static YYRESULTTAG
1907 yyresolveStack (yyGLRStack* yystackp]b4_user_formals[)
1908 {
1909 if (yystackp->yysplitPoint != YY_NULL)
1910 {
1911 yyGLRState* yys;
1912 int yyn;
1913
1914 for (yyn = 0, yys = yystackp->yytops.yystates[0];
1915 yys != yystackp->yysplitPoint;
1916 yys = yys->yypred, yyn += 1)
1917 continue;
1918 YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
1919 ]b4_user_args[));
1920 }
1921 return yyok;
1922 }
1923
1924 static void
1925 yycompressStack (yyGLRStack* yystackp)
1926 {
1927 yyGLRState* yyp, *yyq, *yyr;
1928
1929 if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULL)
1930 return;
1931
1932 for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULL;
1933 yyp != yystackp->yysplitPoint;
1934 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1935 yyp->yypred = yyr;
1936
1937 yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
1938 yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
1939 yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
1940 yystackp->yysplitPoint = YY_NULL;
1941 yystackp->yylastDeleted = YY_NULL;
1942
1943 while (yyr != YY_NULL)
1944 {
1945 yystackp->yynextFree->yystate = *yyr;
1946 yyr = yyr->yypred;
1947 yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
1948 yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
1949 yystackp->yynextFree += 1;
1950 yystackp->yyspaceLeft -= 1;
1951 }
1952 }
1953
1954 static YYRESULTTAG
1955 yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
1956 size_t yyposn]b4_pure_formals[)
1957 {
1958 int yyaction;
1959 const short int* yyconflicts;
1960 yyRuleNum yyrule;
1961
1962 while (yystackp->yytops.yystates[yyk] != YY_NULL)
1963 {
1964 yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
1965 YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
1966 (unsigned long int) yyk, yystate));
1967
1968 YYASSERT (yystate != YYFINAL);
1969
1970 if (yyisDefaultedState (yystate))
1971 {
1972 yyrule = yydefaultAction (yystate);
1973 if (yyrule == 0)
1974 {
1975 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1976 (unsigned long int) yyk));
1977 yymarkStackDeleted (yystackp, yyk);
1978 return yyok;
1979 }
1980 YYCHK (yyglrReduce (yystackp, yyk, yyrule, yyfalse]b4_user_args[));
1981 }
1982 else
1983 {
1984 yySymbol yytoken;
1985 yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
1986 if (yychar == YYEMPTY)
1987 {
1988 YYDPRINTF ((stderr, "Reading a token: "));
1989 yychar = YYLEX;
1990 }
1991
1992 if (yychar <= YYEOF)
1993 {
1994 yychar = yytoken = YYEOF;
1995 YYDPRINTF ((stderr, "Now at end of input.\n"));
1996 }
1997 else
1998 {
1999 yytoken = YYTRANSLATE (yychar);
2000 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2001 }
2002
2003 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
2004
2005 while (*yyconflicts != 0)
2006 {
2007 size_t yynewStack = yysplitStack (yystackp, yyk);
2008 YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
2009 (unsigned long int) yynewStack,
2010 (unsigned long int) yyk));
2011 YYCHK (yyglrReduce (yystackp, yynewStack,
2012 *yyconflicts, yyfalse]b4_user_args[));
2013 YYCHK (yyprocessOneStack (yystackp, yynewStack,
2014 yyposn]b4_pure_args[));
2015 yyconflicts += 1;
2016 }
2017
2018 if (yyisShiftAction (yyaction))
2019 break;
2020 else if (yyisErrorAction (yyaction))
2021 {
2022 YYDPRINTF ((stderr, "Stack %lu dies.\n",
2023 (unsigned long int) yyk));
2024 yymarkStackDeleted (yystackp, yyk);
2025 break;
2026 }
2027 else
2028 YYCHK (yyglrReduce (yystackp, yyk, -yyaction,
2029 yyfalse]b4_user_args[));
2030 }
2031 }
2032 return yyok;
2033 }
2034
2035 /*ARGSUSED*/ static void
2036 yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
2037 {
2038 if (yystackp->yyerrState != 0)
2039 return;
2040 #if ! YYERROR_VERBOSE
2041 yyerror (]b4_lyyerror_args[YY_("syntax error"));
2042 #else
2043 yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2044 size_t yysize0 = yytnamerr (YY_NULL, yytokenName (yytoken));
2045 size_t yysize = yysize0;
2046 size_t yysize1;
2047 yybool yysize_overflow = yyfalse;
2048 char* yymsg = YY_NULL;
2049 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
2050 /* Internationalized format string. */
2051 const char *yyformat = YY_NULL;
2052 /* Arguments of yyformat. */
2053 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
2054 /* Number of reported tokens (one for the "unexpected", one per
2055 "expected"). */
2056 int yycount = 0;
2057
2058 /* There are many possibilities here to consider:
2059 - If this state is a consistent state with a default action, then
2060 the only way this function was invoked is if the default action
2061 is an error action. In that case, don't check for expected
2062 tokens because there are none.
2063 - The only way there can be no lookahead present (in yychar) is if
2064 this state is a consistent state with a default action. Thus,
2065 detecting the absence of a lookahead is sufficient to determine
2066 that there is no unexpected or expected token to report. In that
2067 case, just report a simple "syntax error".
2068 - Don't assume there isn't a lookahead just because this state is a
2069 consistent state with a default action. There might have been a
2070 previous inconsistent state, consistent state with a non-default
2071 action, or user semantic action that manipulated yychar.
2072 - Of course, the expected token list depends on states to have
2073 correct lookahead information, and it depends on the parser not
2074 to perform extra reductions after fetching a lookahead from the
2075 scanner and before detecting a syntax error. Thus, state merging
2076 (from LALR or IELR) and default reductions corrupt the expected
2077 token list. However, the list is correct for canonical LR with
2078 one exception: it will still contain any token that will not be
2079 accepted due to an error action in a later state.
2080 */
2081 if (yytoken != YYEMPTY)
2082 {
2083 int yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
2084 yyarg[yycount++] = yytokenName (yytoken);
2085 if (!yypact_value_is_default (yyn))
2086 {
2087 /* Start YYX at -YYN if negative to avoid negative indexes in
2088 YYCHECK. In other words, skip the first -YYN actions for this
2089 state because they are default actions. */
2090 int yyxbegin = yyn < 0 ? -yyn : 0;
2091 /* Stay within bounds of both yycheck and yytname. */
2092 int yychecklim = YYLAST - yyn + 1;
2093 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
2094 int yyx;
2095 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
2096 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
2097 && !yytable_value_is_error (yytable[yyx + yyn]))
2098 {
2099 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
2100 {
2101 yycount = 1;
2102 yysize = yysize0;
2103 break;
2104 }
2105 yyarg[yycount++] = yytokenName (yyx);
2106 yysize1 = yysize + yytnamerr (YY_NULL, yytokenName (yyx));
2107 yysize_overflow |= yysize1 < yysize;
2108 yysize = yysize1;
2109 }
2110 }
2111 }
2112
2113 switch (yycount)
2114 {
2115 #define YYCASE_(N, S) \
2116 case N: \
2117 yyformat = S; \
2118 break
2119 YYCASE_(0, YY_("syntax error"));
2120 YYCASE_(1, YY_("syntax error, unexpected %s"));
2121 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2122 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2123 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2124 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2125 #undef YYCASE_
2126 }
2127
2128 yysize1 = yysize + strlen (yyformat);
2129 yysize_overflow |= yysize1 < yysize;
2130 yysize = yysize1;
2131
2132 if (!yysize_overflow)
2133 yymsg = (char *) YYMALLOC (yysize);
2134
2135 if (yymsg)
2136 {
2137 char *yyp = yymsg;
2138 int yyi = 0;
2139 while ((*yyp = *yyformat))
2140 {
2141 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
2142 {
2143 yyp += yytnamerr (yyp, yyarg[yyi++]);
2144 yyformat += 2;
2145 }
2146 else
2147 {
2148 yyp++;
2149 yyformat++;
2150 }
2151 }
2152 yyerror (]b4_lyyerror_args[yymsg);
2153 YYFREE (yymsg);
2154 }
2155 else
2156 {
2157 yyerror (]b4_lyyerror_args[YY_("syntax error"));
2158 yyMemoryExhausted (yystackp);
2159 }
2160 #endif /* YYERROR_VERBOSE */
2161 yynerrs += 1;
2162 }
2163
2164 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2165 yylval, and yylloc are the syntactic category, semantic value, and location
2166 of the lookahead. */
2167 /*ARGSUSED*/ static void
2168 yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
2169 {
2170 size_t yyk;
2171 int yyj;
2172
2173 if (yystackp->yyerrState == 3)
2174 /* We just shifted the error token and (perhaps) took some
2175 reductions. Skip tokens until we can proceed. */
2176 while (YYID (yytrue))
2177 {
2178 yySymbol yytoken;
2179 if (yychar == YYEOF)
2180 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
2181 if (yychar != YYEMPTY)
2182 {]b4_locations_if([[
2183 /* We throw away the lookahead, but the error range
2184 of the shifted error token must take it into account. */
2185 yyGLRState *yys = yystackp->yytops.yystates[0];
2186 yyGLRStackItem yyerror_range[3];
2187 yyerror_range[1].yystate.yyloc = yys->yyloc;
2188 yyerror_range[2].yystate.yyloc = yylloc;
2189 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2190 yytoken = YYTRANSLATE (yychar);
2191 yydestruct ("Error: discarding",
2192 yytoken, &yylval]b4_locuser_args([&yylloc])[);
2193 }
2194 YYDPRINTF ((stderr, "Reading a token: "));
2195 yychar = YYLEX;
2196 if (yychar <= YYEOF)
2197 {
2198 yychar = yytoken = YYEOF;
2199 YYDPRINTF ((stderr, "Now at end of input.\n"));
2200 }
2201 else
2202 {
2203 yytoken = YYTRANSLATE (yychar);
2204 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2205 }
2206 yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
2207 if (yypact_value_is_default (yyj))
2208 return;
2209 yyj += yytoken;
2210 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
2211 {
2212 if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
2213 return;
2214 }
2215 else if (! yytable_value_is_error (yytable[yyj]))
2216 return;
2217 }
2218
2219 /* Reduce to one stack. */
2220 for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
2221 if (yystackp->yytops.yystates[yyk] != YY_NULL)
2222 break;
2223 if (yyk >= yystackp->yytops.yysize)
2224 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
2225 for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
2226 yymarkStackDeleted (yystackp, yyk);
2227 yyremoveDeletes (yystackp);
2228 yycompressStack (yystackp);
2229
2230 /* Now pop stack until we find a state that shifts the error token. */
2231 yystackp->yyerrState = 3;
2232 while (yystackp->yytops.yystates[0] != YY_NULL)
2233 {
2234 yyGLRState *yys = yystackp->yytops.yystates[0];
2235 yyj = yypact[yys->yylrState];
2236 if (! yypact_value_is_default (yyj))
2237 {
2238 yyj += YYTERROR;
2239 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2240 && yyisShiftAction (yytable[yyj]))
2241 {
2242 /* Shift the error token. */]b4_locations_if([[
2243 /* First adjust its location.*/
2244 YYLTYPE yyerrloc;
2245 yystackp->yyerror_range[2].yystate.yyloc = yylloc;
2246 YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
2247 YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
2248 &yylval, &yyerrloc);
2249 yyglrShift (yystackp, 0, yytable[yyj],
2250 yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
2251 yys = yystackp->yytops.yystates[0];
2252 break;
2253 }
2254 }]b4_locations_if([[
2255 yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
2256 if (yys->yypred != YY_NULL)
2257 yydestroyGLRState ("Error: popping", yys]b4_user_args[);
2258 yystackp->yytops.yystates[0] = yys->yypred;
2259 yystackp->yynextFree -= 1;
2260 yystackp->yyspaceLeft += 1;
2261 }
2262 if (yystackp->yytops.yystates[0] == YY_NULL)
2263 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
2264 }
2265
2266 #define YYCHK1(YYE) \
2267 do { \
2268 switch (YYE) { \
2269 case yyok: \
2270 break; \
2271 case yyabort: \
2272 goto yyabortlab; \
2273 case yyaccept: \
2274 goto yyacceptlab; \
2275 case yyerr: \
2276 goto yyuser_error; \
2277 default: \
2278 goto yybuglab; \
2279 } \
2280 } while (YYID (0))
2281
2282
2283 /*----------.
2284 | yyparse. |
2285 `----------*/
2286
2287 ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[
2288 {
2289 int yyresult;
2290 yyGLRStack yystack;
2291 yyGLRStack* const yystackp = &yystack;
2292 size_t yyposn;
2293
2294 YYDPRINTF ((stderr, "Starting parse\n"));
2295
2296 yychar = YYEMPTY;
2297 yylval = yyval_default;
2298 ]b4_locations_if([
2299 #if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
2300 yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
2301 yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
2302 #endif
2303 ])
2304 m4_ifdef([b4_initial_action], [
2305 b4_dollar_pushdef([yylval], [], [yylloc])dnl
2306 /* User initialization code. */
2307 b4_user_initial_action
2308 b4_dollar_popdef])[]dnl
2309 [
2310 if (! yyinitGLRStack (yystackp, YYINITDEPTH))
2311 goto yyexhaustedlab;
2312 switch (YYSETJMP (yystack.yyexception_buffer))
2313 {
2314 case 0: break;
2315 case 1: goto yyabortlab;
2316 case 2: goto yyexhaustedlab;
2317 default: goto yybuglab;
2318 }
2319 yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[);
2320 yyposn = 0;
2321
2322 while (YYID (yytrue))
2323 {
2324 /* For efficiency, we have two loops, the first of which is
2325 specialized to deterministic operation (single stack, no
2326 potential ambiguity). */
2327 /* Standard mode */
2328 while (YYID (yytrue))
2329 {
2330 yyRuleNum yyrule;
2331 int yyaction;
2332 const short int* yyconflicts;
2333
2334 yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
2335 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2336 if (yystate == YYFINAL)
2337 goto yyacceptlab;
2338 if (yyisDefaultedState (yystate))
2339 {
2340 yyrule = yydefaultAction (yystate);
2341 if (yyrule == 0)
2342 {
2343 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2344 yyreportSyntaxError (&yystack]b4_user_args[);
2345 goto yyuser_error;
2346 }
2347 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
2348 }
2349 else
2350 {
2351 yySymbol yytoken;
2352 if (yychar == YYEMPTY)
2353 {
2354 YYDPRINTF ((stderr, "Reading a token: "));
2355 yychar = YYLEX;
2356 }
2357
2358 if (yychar <= YYEOF)
2359 {
2360 yychar = yytoken = YYEOF;
2361 YYDPRINTF ((stderr, "Now at end of input.\n"));
2362 }
2363 else
2364 {
2365 yytoken = YYTRANSLATE (yychar);
2366 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2367 }
2368
2369 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
2370 if (*yyconflicts != 0)
2371 break;
2372 if (yyisShiftAction (yyaction))
2373 {
2374 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2375 yychar = YYEMPTY;
2376 yyposn += 1;
2377 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[);
2378 if (0 < yystack.yyerrState)
2379 yystack.yyerrState -= 1;
2380 }
2381 else if (yyisErrorAction (yyaction))
2382 {
2383 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2384 yyreportSyntaxError (&yystack]b4_user_args[);
2385 goto yyuser_error;
2386 }
2387 else
2388 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));
2389 }
2390 }
2391
2392 while (YYID (yytrue))
2393 {
2394 yySymbol yytoken_to_shift;
2395 size_t yys;
2396
2397 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2398 yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
2399
2400 /* yyprocessOneStack returns one of three things:
2401
2402 - An error flag. If the caller is yyprocessOneStack, it
2403 immediately returns as well. When the caller is finally
2404 yyparse, it jumps to an error label via YYCHK1.
2405
2406 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2407 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2408 yyparse's following invocation of yyremoveDeletes will remove
2409 the stack.
2410
2411 - yyok, when ready to shift a token.
2412
2413 Except in the first case, yyparse will invoke yyremoveDeletes and
2414 then shift the next token onto all remaining stacks. This
2415 synchronization of the shift (that is, after all preceding
2416 reductions on all stacks) helps prevent double destructor calls
2417 on yylval in the event of memory exhaustion. */
2418
2419 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2420 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
2421 yyremoveDeletes (&yystack);
2422 if (yystack.yytops.yysize == 0)
2423 {
2424 yyundeleteLastStack (&yystack);
2425 if (yystack.yytops.yysize == 0)
2426 yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
2427 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2428 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2429 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2430 yyreportSyntaxError (&yystack]b4_user_args[);
2431 goto yyuser_error;
2432 }
2433
2434 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2435 a copy of yylval will already be on stack 0 in the event of a
2436 failure in the following loop. Thus, yychar is set to YYEMPTY
2437 before the loop to make sure the user destructor for yylval isn't
2438 called twice. */
2439 yytoken_to_shift = YYTRANSLATE (yychar);
2440 yychar = YYEMPTY;
2441 yyposn += 1;
2442 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2443 {
2444 int yyaction;
2445 const short int* yyconflicts;
2446 yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
2447 yygetLRActions (yystate, yytoken_to_shift, &yyaction,
2448 &yyconflicts);
2449 /* Note that yyconflicts were handled by yyprocessOneStack. */
2450 YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
2451 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
2452 yyglrShift (&yystack, yys, yyaction, yyposn,
2453 &yylval]b4_locations_if([, &yylloc])[);
2454 YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
2455 (unsigned long int) yys,
2456 yystack.yytops.yystates[yys]->yylrState));
2457 }
2458
2459 if (yystack.yytops.yysize == 1)
2460 {
2461 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2462 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2463 yycompressStack (&yystack);
2464 break;
2465 }
2466 }
2467 continue;
2468 yyuser_error:
2469 yyrecoverSyntaxError (&yystack]b4_user_args[);
2470 yyposn = yystack.yytops.yystates[0]->yyposn;
2471 }
2472
2473 yyacceptlab:
2474 yyresult = 0;
2475 goto yyreturn;
2476
2477 yybuglab:
2478 YYASSERT (yyfalse);
2479 goto yyabortlab;
2480
2481 yyabortlab:
2482 yyresult = 1;
2483 goto yyreturn;
2484
2485 yyexhaustedlab:
2486 yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
2487 yyresult = 2;
2488 goto yyreturn;
2489
2490 yyreturn:
2491 if (yychar != YYEMPTY)
2492 yydestruct ("Cleanup: discarding lookahead",
2493 YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[);
2494
2495 /* If the stack is well-formed, pop the stack until it is empty,
2496 destroying its entries as we go. But free the stack regardless
2497 of whether it is well-formed. */
2498 if (yystack.yyitems)
2499 {
2500 yyGLRState** yystates = yystack.yytops.yystates;
2501 if (yystates)
2502 {
2503 size_t yysize = yystack.yytops.yysize;
2504 size_t yyk;
2505 for (yyk = 0; yyk < yysize; yyk += 1)
2506 if (yystates[yyk])
2507 {
2508 while (yystates[yyk])
2509 {
2510 yyGLRState *yys = yystates[yyk];
2511 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
2512 )[ if (yys->yypred != YY_NULL)
2513 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
2514 yystates[yyk] = yys->yypred;
2515 yystack.yynextFree -= 1;
2516 yystack.yyspaceLeft += 1;
2517 }
2518 break;
2519 }
2520 }
2521 yyfreeGLRStack (&yystack);
2522 }
2523
2524 /* Make sure YYID is used. */
2525 return YYID (yyresult);
2526 }
2527
2528 /* DEBUGGING ONLY */
2529 #if ]b4_api_PREFIX[DEBUG
2530 static void yypstack (yyGLRStack* yystackp, size_t yyk)
2531 __attribute__ ((__unused__));
2532 static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
2533
2534 static void
2535 yy_yypstack (yyGLRState* yys)
2536 {
2537 if (yys->yypred)
2538 {
2539 yy_yypstack (yys->yypred);
2540 YYFPRINTF (stderr, " -> ");
2541 }
2542 YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
2543 (unsigned long int) yys->yyposn);
2544 }
2545
2546 static void
2547 yypstates (yyGLRState* yyst)
2548 {
2549 if (yyst == YY_NULL)
2550 YYFPRINTF (stderr, "<null>");
2551 else
2552 yy_yypstack (yyst);
2553 YYFPRINTF (stderr, "\n");
2554 }
2555
2556 static void
2557 yypstack (yyGLRStack* yystackp, size_t yyk)
2558 {
2559 yypstates (yystackp->yytops.yystates[yyk]);
2560 }
2561
2562 #define YYINDEX(YYX) \
2563 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2564
2565
2566 static void
2567 yypdumpstack (yyGLRStack* yystackp)
2568 {
2569 yyGLRStackItem* yyp;
2570 size_t yyi;
2571 for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
2572 {
2573 YYFPRINTF (stderr, "%3lu. ",
2574 (unsigned long int) (yyp - yystackp->yyitems));
2575 if (*(yybool *) yyp)
2576 {
2577 YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2578 yyp->yystate.yyresolved, yyp->yystate.yylrState,
2579 (unsigned long int) yyp->yystate.yyposn,
2580 (long int) YYINDEX (yyp->yystate.yypred));
2581 if (! yyp->yystate.yyresolved)
2582 YYFPRINTF (stderr, ", firstVal: %ld",
2583 (long int) YYINDEX (yyp->yystate
2584 .yysemantics.yyfirstVal));
2585 }
2586 else
2587 {
2588 YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
2589 yyp->yyoption.yyrule - 1,
2590 (long int) YYINDEX (yyp->yyoption.yystate),
2591 (long int) YYINDEX (yyp->yyoption.yynext));
2592 }
2593 YYFPRINTF (stderr, "\n");
2594 }
2595 YYFPRINTF (stderr, "Tops:");
2596 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
2597 YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
2598 (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
2599 YYFPRINTF (stderr, "\n");
2600 }
2601 #endif
2602 ]b4_epilogue[]dnl
2603 dnl
2604 dnl glr.cc produces its own header.
2605 dnl
2606 m4_if(b4_skeleton, ["glr.c"],
2607 [b4_defines_if(
2608 [@output(b4_spec_defines_file@)@
2609 b4_copyright([Skeleton interface for Bison GLR parsers in C],
2610 [2002-2012])[
2611
2612 ]b4_cpp_guard_open([b4_spec_defines_file])[
2613 ]b4_shared_declarations[
2614 ]b4_cpp_guard_close([b4_spec_defines_file])[
2615 ]])])dnl
2616 m4_divert_pop(0)