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