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