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