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