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