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