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