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