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