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