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