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