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