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