]> git.saurik.com Git - bison.git/blob - data/glr.c
* data/glr.c: Switch to Bison 2.2 special-exception language in
[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_location_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_location_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 look-ahead, hence &yylloc instead of yylocp.
71 m4_define([b4_lyyerror_args],
72 [b4_pure_if([b4_location_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_location_if([, yylocp])])[]b4_user_args])
81
82
83 # b4_lpure_args
84 # -------------
85 # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
86 m4_define([b4_lpure_args],
87 [b4_pure_if([b4_location_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_location_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 /* As a special exception, you may create a larger work that contains
150 part or all of the Bison parser skeleton and distribute that work
151 under terms of your choice, so long as that work isn't itself a
152 parser generator using the skeleton or a modified version thereof
153 as a parser skeleton. Alternatively, if you modify or redistribute
154 the parser skeleton itself, you may (at your option) remove this
155 special exception, which will cause the skeleton and the resulting
156 Bison output files to be licensed under the GNU General Public
157 License without this special exception.
158
159 This special exception was added by the Free Software Foundation in
160 version 2.2 of Bison. */
161
162 /* C GLR parser skeleton written by Paul Hilfinger. */
163
164 ]b4_identification
165
166 m4_if(b4_prefix, [yy], [],
167 [/* Substitute the variable and function names. */
168 #define yyparse b4_prefix[]parse
169 #define yylex b4_prefix[]lex
170 #define yyerror b4_prefix[]error
171 #define yylval b4_prefix[]lval
172 #define yychar b4_prefix[]char
173 #define yydebug b4_prefix[]debug
174 #define yynerrs b4_prefix[]nerrs
175 #define yylloc b4_prefix[]lloc])
176
177 dnl # b4_shared_declarations
178 dnl # ----------------------
179 dnl # Declaration that might either go into the header (if --defines)
180 dnl # or open coded in the parser body.
181 m4_define([b4_shared_declarations],
182 [b4_token_enums(b4_tokens)[
183
184 /* Copy the first part of user declarations. */
185 ]b4_pre_prologue[
186
187 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
188 ]m4_ifdef([b4_stype],
189 [typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])
190 b4_stype
191 /* Line __line__ of glr.c. */
192 b4_syncline([@oline@], [@ofile@])
193 YYSTYPE;],
194 [typedef int YYSTYPE;])[
195 # define YYSTYPE_IS_DECLARED 1
196 # define YYSTYPE_IS_TRIVIAL 1
197 #endif
198
199 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
200 typedef struct YYLTYPE
201 {
202 ]b4_location_if([
203 int first_line;
204 int first_column;
205 int last_line;
206 int last_column;
207 ],[
208 char yydummy;
209 ])[
210 } YYLTYPE;
211 # define YYLTYPE_IS_DECLARED 1
212 # define YYLTYPE_IS_TRIVIAL 1
213 #endif
214 ]])
215
216 m4_if(b4_defines_flag, 0,
217 [b4_shared_declarations],
218 [#include @output_header_name@])[
219
220 /* Enabling traces. */
221 #ifndef YYDEBUG
222 # define YYDEBUG ]b4_debug[
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[
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_post_prologue[
247
248 ]/* Line __line__ of glr.c. */
249 b4_syncline([@oline@], [@ofile@])
250 [
251 #include <stdio.h>
252 #include <stdlib.h>
253 #include <string.h>
254 #include <stdarg.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_location_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 ((YYX <= 0) ? YYEOF : \
360 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
361
362 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
363 static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
364 {
365 ]b4_translate[
366 };
367
368 #if YYDEBUG
369 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
370 YYRHS. */
371 static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
372 {
373 ]b4_prhs[
374 };
375
376 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
377 static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
378 {
379 ]b4_rhs[
380 };
381
382 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
383 static const ]b4_int_type_for([b4_rline])[ yyrline[] =
384 {
385 ]b4_rline[
386 };
387 #endif
388
389 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
390 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
391 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
392 static const char *const yytname[] =
393 {
394 ]b4_tname[
395 };
396 #endif
397
398 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
399 static const ]b4_int_type_for([b4_r1])[ yyr1[] =
400 {
401 ]b4_r1[
402 };
403
404 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
405 static const ]b4_int_type_for([b4_r2])[ yyr2[] =
406 {
407 ]b4_r2[
408 };
409
410 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
411 static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
412 {
413 ]b4_dprec[
414 };
415
416 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
417 static const ]b4_int_type_for([b4_merger])[ yymerger[] =
418 {
419 ]b4_merger[
420 };
421
422 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
423 doesn't specify something else to do. Zero means the default is an
424 error. */
425 static const ]b4_int_type_for([b4_defact])[ yydefact[] =
426 {
427 ]b4_defact[
428 };
429
430 /* YYPDEFGOTO[NTERM-NUM]. */
431 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
432 {
433 ]b4_defgoto[
434 };
435
436 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
437 STATE-NUM. */
438 #define YYPACT_NINF ]b4_pact_ninf[
439 static const ]b4_int_type_for([b4_pact])[ yypact[] =
440 {
441 ]b4_pact[
442 };
443
444 /* YYPGOTO[NTERM-NUM]. */
445 static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
446 {
447 ]b4_pgoto[
448 };
449
450 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
451 positive, shift that token. If negative, reduce the rule which
452 number is the opposite. If zero, do what YYDEFACT says.
453 If YYTABLE_NINF, syntax error. */
454 #define YYTABLE_NINF ]b4_table_ninf[
455 static const ]b4_int_type_for([b4_table])[ yytable[] =
456 {
457 ]b4_table[
458 };
459
460 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
461 list of conflicting reductions corresponding to action entry for
462 state STATE-NUM in yytable. 0 means no conflicts. The list in
463 yyconfl is terminated by a rule number of 0. */
464 static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
465 {
466 ]b4_conflict_list_heads[
467 };
468
469 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
470 0, pointed into by YYCONFLP. */
471 ]dnl Do not use b4_int_type_for here, since there are places where
472 dnl pointers onto yyconfl are taken, which type is "short int *".
473 dnl We probably ought to introduce a type for confl.
474 [static const short int yyconfl[] =
475 {
476 ]b4_conflicting_rules[
477 };
478
479 static const ]b4_int_type_for([b4_check])[ yycheck[] =
480 {
481 ]b4_check[
482 };
483
484 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
485 symbol of state STATE-NUM. */
486 static const ]b4_int_type_for([b4_stos])[ yystos[] =
487 {
488 ]b4_stos[
489 };
490
491 \f
492 /* Prevent warning if -Wmissing-prototypes. */
493 ]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
494
495 /* Error token number */
496 #define YYTERROR 1
497
498 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
499 If N is 0, then set CURRENT to the empty location which ends
500 the previous symbol: RHS[0] (always defined). */
501
502 ]b4_location_if([[
503 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
504 #ifndef YYLLOC_DEFAULT
505 # define YYLLOC_DEFAULT(Current, Rhs, N) \
506 do \
507 if (YYID (N)) \
508 { \
509 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
510 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
511 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
512 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
513 } \
514 else \
515 { \
516 (Current).first_line = (Current).last_line = \
517 YYRHSLOC (Rhs, 0).last_line; \
518 (Current).first_column = (Current).last_column = \
519 YYRHSLOC (Rhs, 0).last_column; \
520 } \
521 while (YYID (0))
522
523 /* YY_LOCATION_PRINT -- Print the location on the stream.
524 This macro was not mandated originally: define only if we know
525 we won't break user code: when these are the locations we know. */
526
527 # define YY_LOCATION_PRINT(File, Loc) \
528 fprintf (File, "%d.%d-%d.%d", \
529 (Loc).first_line, (Loc).first_column, \
530 (Loc).last_line, (Loc).last_column)
531 #endif
532 ]],[
533 #ifndef YYLLOC_DEFAULT
534 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
535 #endif
536 ])[
537
538 #ifndef YY_LOCATION_PRINT
539 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
540 #endif
541
542
543 /* YYLEX -- calling `yylex' with the right arguments. */
544 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
545
546 ]b4_pure_if(
547 [
548 #undef yynerrs
549 #define yynerrs (yystackp->yyerrcnt)
550 #undef yychar
551 #define yychar (yystackp->yyrawchar)
552 #undef yylval
553 #define yylval (yystackp->yyval)
554 #undef yylloc
555 #define yylloc (yystackp->yyloc)
556 m4_if(b4_prefix[], [yy], [],
557 [#define b4_prefix[]nerrs yynerrs
558 #define b4_prefix[]char yychar
559 #define b4_prefix[]lval yylval
560 #define b4_prefix[]lloc yylloc])],
561 [YYSTYPE yylval;
562
563 YYLTYPE yylloc;
564
565 int yynerrs;
566 int yychar;])[
567
568 static const int YYEOF = 0;
569 static const int YYEMPTY = -2;
570
571 typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
572
573 #define YYCHK(YYE) \
574 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
575 while (YYID (0))
576
577 #if YYDEBUG
578
579 # ifndef YYFPRINTF
580 # define YYFPRINTF fprintf
581 # endif
582
583 # define YYDPRINTF(Args) \
584 do { \
585 if (yydebug) \
586 YYFPRINTF Args; \
587 } while (YYID (0))
588
589 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def])[
590
591 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
592 do { \
593 if (yydebug) \
594 { \
595 YYFPRINTF (stderr, "%s ", Title); \
596 yy_symbol_print (stderr, Type, \
597 Value]b4_location_if([, Location])[]b4_user_args[); \
598 YYFPRINTF (stderr, "\n"); \
599 } \
600 } while (YYID (0))
601
602 /* Nonzero means print parse trace. It is left uninitialized so that
603 multiple parsers can coexist. */
604 int yydebug;
605
606 #else /* !YYDEBUG */
607
608 # define YYDPRINTF(Args)
609 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
610
611 #endif /* !YYDEBUG */
612
613 /* YYINITDEPTH -- initial size of the parser's stacks. */
614 #ifndef YYINITDEPTH
615 # define YYINITDEPTH ]b4_stack_depth_init[
616 #endif
617
618 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
619 if the built-in stack extension method is used).
620
621 Do not make this value too large; the results are undefined if
622 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
623 evaluated with infinite-precision integer arithmetic. */
624
625 #ifndef YYMAXDEPTH
626 # define YYMAXDEPTH ]b4_stack_depth_max[
627 #endif
628
629 /* Minimum number of free items on the stack allowed after an
630 allocation. This is to allow allocation and initialization
631 to be completed by functions that call yyexpandGLRStack before the
632 stack is expanded, thus insuring that all necessary pointers get
633 properly redirected to new data. */
634 #define YYHEADROOM 2
635
636 #ifndef YYSTACKEXPANDABLE
637 # if (! defined __cplusplus \
638 || (]b4_location_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
639 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
640 # define YYSTACKEXPANDABLE 1
641 # else
642 # define YYSTACKEXPANDABLE 0
643 # endif
644 #endif
645
646 #if YYSTACKEXPANDABLE
647 # define YY_RESERVE_GLRSTACK(Yystack) \
648 do { \
649 if (Yystack->yyspaceLeft < YYHEADROOM) \
650 yyexpandGLRStack (Yystack); \
651 } while (YYID (0))
652 #else
653 # define YY_RESERVE_GLRSTACK(Yystack) \
654 do { \
655 if (Yystack->yyspaceLeft < YYHEADROOM) \
656 yyMemoryExhausted (Yystack); \
657 } while (YYID (0))
658 #endif
659
660
661 #if YYERROR_VERBOSE
662
663 # ifndef yystpcpy
664 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
665 # define yystpcpy stpcpy
666 # else
667 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
668 YYDEST. */
669 static char *
670 yystpcpy (char *yydest, const char *yysrc)
671 {
672 char *yyd = yydest;
673 const char *yys = yysrc;
674
675 while ((*yyd++ = *yys++) != '\0')
676 continue;
677
678 return yyd - 1;
679 }
680 # endif
681 # endif
682
683 # ifndef yytnamerr
684 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
685 quotes and backslashes, so that it's suitable for yyerror. The
686 heuristic is that double-quoting is unnecessary unless the string
687 contains an apostrophe, a comma, or backslash (other than
688 backslash-backslash). YYSTR is taken from yytname. If YYRES is
689 null, do not copy; instead, return the length of what the result
690 would have been. */
691 static size_t
692 yytnamerr (char *yyres, const char *yystr)
693 {
694 if (*yystr == '"')
695 {
696 size_t yyn = 0;
697 char const *yyp = yystr;
698
699 for (;;)
700 switch (*++yyp)
701 {
702 case '\'':
703 case ',':
704 goto do_not_strip_quotes;
705
706 case '\\':
707 if (*++yyp != '\\')
708 goto do_not_strip_quotes;
709 /* Fall through. */
710 default:
711 if (yyres)
712 yyres[yyn] = *yyp;
713 yyn++;
714 break;
715
716 case '"':
717 if (yyres)
718 yyres[yyn] = '\0';
719 return yyn;
720 }
721 do_not_strip_quotes: ;
722 }
723
724 if (! yyres)
725 return strlen (yystr);
726
727 return yystpcpy (yyres, yystr) - yyres;
728 }
729 # endif
730
731 #endif /* !YYERROR_VERBOSE */
732
733 /** State numbers, as in LALR(1) machine */
734 typedef int yyStateNum;
735
736 /** Rule numbers, as in LALR(1) machine */
737 typedef int yyRuleNum;
738
739 /** Grammar symbol */
740 typedef short int yySymbol;
741
742 /** Item references, as in LALR(1) machine */
743 typedef short int yyItemNum;
744
745 typedef struct yyGLRState yyGLRState;
746 typedef struct yyGLRStateSet yyGLRStateSet;
747 typedef struct yySemanticOption yySemanticOption;
748 typedef union yyGLRStackItem yyGLRStackItem;
749 typedef struct yyGLRStack yyGLRStack;
750
751 struct yyGLRState {
752 /** Type tag: always true. */
753 yybool yyisState;
754 /** Type tag for yysemantics. If true, yysval applies, otherwise
755 * yyfirstVal applies. */
756 yybool yyresolved;
757 /** Number of corresponding LALR(1) machine state. */
758 yyStateNum yylrState;
759 /** Preceding state in this stack */
760 yyGLRState* yypred;
761 /** Source position of the first token produced by my symbol */
762 size_t yyposn;
763 union {
764 /** First in a chain of alternative reductions producing the
765 * non-terminal corresponding to this state, threaded through
766 * yynext. */
767 yySemanticOption* yyfirstVal;
768 /** Semantic value for this state. */
769 YYSTYPE yysval;
770 } yysemantics;
771 /** Source location for this state. */
772 YYLTYPE yyloc;
773 };
774
775 struct yyGLRStateSet {
776 yyGLRState** yystates;
777 /** During nondeterministic operation, yylookaheadNeeds tracks which
778 * stacks have actually needed the current lookahead. During deterministic
779 * operation, yylookaheadNeeds[0] is not maintained since it would merely
780 * duplicate yychar != YYEMPTY. */
781 yybool* yylookaheadNeeds;
782 size_t yysize, yycapacity;
783 };
784
785 struct yySemanticOption {
786 /** Type tag: always false. */
787 yybool yyisState;
788 /** Rule number for this reduction */
789 yyRuleNum yyrule;
790 /** The last RHS state in the list of states to be reduced. */
791 yyGLRState* yystate;
792 /** The lookahead for this reduction. */
793 int yyrawchar;
794 YYSTYPE yyval;
795 YYLTYPE yyloc;
796 /** Next sibling in chain of options. To facilitate merging,
797 * options are chained in decreasing order by address. */
798 yySemanticOption* yynext;
799 };
800
801 /** Type of the items in the GLR stack. The yyisState field
802 * indicates which item of the union is valid. */
803 union yyGLRStackItem {
804 yyGLRState yystate;
805 yySemanticOption yyoption;
806 };
807
808 struct yyGLRStack {
809 int yyerrState;
810 ]b4_location_if([[ /* To compute the location of the error token. */
811 yyGLRStackItem yyerror_range[3];]])[
812 ]b4_pure_if(
813 [
814 int yyerrcnt;
815 int yyrawchar;
816 YYSTYPE yyval;
817 YYLTYPE yyloc;
818 ])[
819 YYJMP_BUF yyexception_buffer;
820 yyGLRStackItem* yyitems;
821 yyGLRStackItem* yynextFree;
822 size_t yyspaceLeft;
823 yyGLRState* yysplitPoint;
824 yyGLRState* yylastDeleted;
825 yyGLRStateSet yytops;
826 };
827
828 #if YYSTACKEXPANDABLE
829 static void yyexpandGLRStack (yyGLRStack* yystackp);
830 #endif
831
832 static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
833 __attribute__ ((__noreturn__));
834 static void
835 yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
836 {
837 if (yymsg != NULL)
838 yyerror (]b4_yyerror_args[yymsg);
839 YYLONGJMP (yystackp->yyexception_buffer, 1);
840 }
841
842 static void yyMemoryExhausted (yyGLRStack* yystackp)
843 __attribute__ ((__noreturn__));
844 static void
845 yyMemoryExhausted (yyGLRStack* yystackp)
846 {
847 YYLONGJMP (yystackp->yyexception_buffer, 2);
848 }
849
850 #if YYDEBUG || YYERROR_VERBOSE
851 /** A printable representation of TOKEN. */
852 static inline const char*
853 yytokenName (yySymbol yytoken)
854 {
855 if (yytoken == YYEMPTY)
856 return "";
857
858 return yytname[yytoken];
859 }
860 #endif
861
862 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
863 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
864 * containing the pointer to the next state in the chain. */
865 static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
866 static void
867 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
868 {
869 yyGLRState* s;
870 int i;
871 s = yyvsp[yylow0].yystate.yypred;
872 for (i = yylow0-1; i >= yylow1; i -= 1)
873 {
874 YYASSERT (s->yyresolved);
875 yyvsp[i].yystate.yyresolved = yytrue;
876 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
877 yyvsp[i].yystate.yyloc = s->yyloc;
878 s = yyvsp[i].yystate.yypred = s->yypred;
879 }
880 }
881
882 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
883 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
884 * For convenience, always return YYLOW1. */
885 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
886 __attribute__ ((__unused__));
887 static inline int
888 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
889 {
890 if (!yynormal && yylow1 < *yylow)
891 {
892 yyfillin (yyvsp, *yylow, yylow1);
893 *yylow = yylow1;
894 }
895 return yylow1;
896 }
897
898 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
899 * and top stack item YYVSP. YYLVALP points to place to put semantic
900 * value ($$), and yylocp points to place for location information
901 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
902 * yyerr for YYERROR, yyabort for YYABORT. */
903 /*ARGSUSED*/ static YYRESULTTAG
904 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
905 YYSTYPE* yyvalp,
906 YYLTYPE* YYOPTIONAL_LOC (yylocp),
907 yyGLRStack* yystackp
908 ]b4_user_formals[)
909 {
910 yybool yynormal __attribute__ ((__unused__)) =
911 (yystackp->yysplitPoint == NULL);
912 int yylow;
913 ]b4_parse_param_use[]dnl
914 [# undef yyerrok
915 # define yyerrok (yystackp->yyerrState = 0)
916 # undef YYACCEPT
917 # define YYACCEPT return yyaccept
918 # undef YYABORT
919 # define YYABORT return yyabort
920 # undef YYERROR
921 # define YYERROR return yyerrok, yyerr
922 # undef YYRECOVERING
923 # define YYRECOVERING (yystackp->yyerrState != 0)
924 # undef yyclearin
925 # define yyclearin (yychar = YYEMPTY)
926 # undef YYFILL
927 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
928 # undef YYBACKUP
929 # define YYBACKUP(Token, Value) \
930 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
931 yyerrok, yyerr
932
933 yylow = 1;
934 if (yyrhslen == 0)
935 *yyvalp = yyval_default;
936 else
937 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
938 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
939 ]b4_location_if([[ yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
940 ]])[
941 switch (yyn)
942 {
943 ]b4_actions
944 /* Line __line__ of glr.c. */
945 b4_syncline([@oline@], [@ofile@])[
946 default: break;
947 }
948
949 return yyok;
950 # undef yyerrok
951 # undef YYABORT
952 # undef YYACCEPT
953 # undef YYERROR
954 # undef YYBACKUP
955 # undef yyclearin
956 # undef YYRECOVERING
957 }
958 \f
959
960 /*ARGSUSED*/ static void
961 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
962 {
963 YYUSE (yy0);
964 YYUSE (yy1);
965
966 switch (yyn)
967 {
968 ]b4_mergers[
969 default: break;
970 }
971 }
972
973 /* Bison grammar-table manipulation. */
974
975 ]b4_yydestruct_generate([b4_c_ansi_function_def])[
976
977 /** Number of symbols composing the right hand side of rule #RULE. */
978 static inline int
979 yyrhsLength (yyRuleNum yyrule)
980 {
981 return yyr2[yyrule];
982 }
983
984 static void
985 yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
986 {
987 if (yys->yyresolved)
988 yydestruct (yymsg, yystos[yys->yylrState],
989 &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[);
990 else
991 {
992 #if YYDEBUG
993 if (yydebug)
994 {
995 if (yys->yysemantics.yyfirstVal)
996 YYFPRINTF (stderr, "%s unresolved ", yymsg);
997 else
998 YYFPRINTF (stderr, "%s incomplete ", yymsg);
999 yy_symbol_print (stderr, yystos[yys->yylrState],
1000 NULL]b4_location_if([, &yys->yyloc])[]b4_user_args[);
1001 YYFPRINTF (stderr, "\n");
1002 }
1003 #endif
1004
1005 if (yys->yysemantics.yyfirstVal)
1006 {
1007 yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
1008 yyGLRState *yyrh;
1009 int yyn;
1010 for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
1011 yyn > 0;
1012 yyrh = yyrh->yypred, yyn -= 1)
1013 yydestroyGLRState (yymsg, yyrh]b4_user_args[);
1014 }
1015 }
1016 }
1017
1018 /** Left-hand-side symbol for rule #RULE. */
1019 static inline yySymbol
1020 yylhsNonterm (yyRuleNum yyrule)
1021 {
1022 return yyr1[yyrule];
1023 }
1024
1025 #define yyis_pact_ninf(yystate) \
1026 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
1027 [0],
1028 [((yystate) == YYPACT_NINF)])[
1029
1030 /** True iff LR state STATE has only a default reduction (regardless
1031 * of token). */
1032 static inline yybool
1033 yyisDefaultedState (yyStateNum yystate)
1034 {
1035 return yyis_pact_ninf (yypact[yystate]);
1036 }
1037
1038 /** The default reduction for STATE, assuming it has one. */
1039 static inline yyRuleNum
1040 yydefaultAction (yyStateNum yystate)
1041 {
1042 return yydefact[yystate];
1043 }
1044
1045 #define yyis_table_ninf(yytable_value) \
1046 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1047 [YYID (0)],
1048 [((yytable_value) == YYTABLE_NINF)])[
1049
1050 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1051 * Result R means
1052 * R < 0: Reduce on rule -R.
1053 * R = 0: Error.
1054 * R > 0: Shift to state R.
1055 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1056 * conflicting reductions.
1057 */
1058 static inline void
1059 yygetLRActions (yyStateNum yystate, int yytoken,
1060 int* yyaction, const short int** yyconflicts)
1061 {
1062 int yyindex = yypact[yystate] + yytoken;
1063 if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
1064 {
1065 *yyaction = -yydefact[yystate];
1066 *yyconflicts = yyconfl;
1067 }
1068 else if (! yyis_table_ninf (yytable[yyindex]))
1069 {
1070 *yyaction = yytable[yyindex];
1071 *yyconflicts = yyconfl + yyconflp[yyindex];
1072 }
1073 else
1074 {
1075 *yyaction = 0;
1076 *yyconflicts = yyconfl + yyconflp[yyindex];
1077 }
1078 }
1079
1080 static inline yyStateNum
1081 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
1082 {
1083 int yyr;
1084 yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
1085 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
1086 return yytable[yyr];
1087 else
1088 return yydefgoto[yylhs - YYNTOKENS];
1089 }
1090
1091 static inline yybool
1092 yyisShiftAction (int yyaction)
1093 {
1094 return 0 < yyaction;
1095 }
1096
1097 static inline yybool
1098 yyisErrorAction (int yyaction)
1099 {
1100 return yyaction == 0;
1101 }
1102
1103 /* GLRStates */
1104
1105 /** Return a fresh GLRStackItem. Callers should call
1106 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1107 * headroom. */
1108
1109 static inline yyGLRStackItem*
1110 yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
1111 {
1112 yyGLRStackItem* yynewItem = yystackp->yynextFree;
1113 yystackp->yyspaceLeft -= 1;
1114 yystackp->yynextFree += 1;
1115 yynewItem->yystate.yyisState = yyisState;
1116 return yynewItem;
1117 }
1118
1119 /** Add a new semantic action that will execute the action for rule
1120 * RULENUM on the semantic values in RHS to the list of
1121 * alternative actions for STATE. Assumes that RHS comes from
1122 * stack #K of *STACKP. */
1123 static void
1124 yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
1125 yyGLRState* rhs, yyRuleNum yyrule)
1126 {
1127 yySemanticOption* yynewOption =
1128 &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
1129 yynewOption->yystate = rhs;
1130 yynewOption->yyrule = yyrule;
1131 if (yystackp->yytops.yylookaheadNeeds[yyk])
1132 {
1133 yynewOption->yyrawchar = yychar;
1134 yynewOption->yyval = yylval;
1135 yynewOption->yyloc = yylloc;
1136 }
1137 else
1138 yynewOption->yyrawchar = YYEMPTY;
1139 yynewOption->yynext = yystate->yysemantics.yyfirstVal;
1140 yystate->yysemantics.yyfirstVal = yynewOption;
1141
1142 YY_RESERVE_GLRSTACK (yystackp);
1143 }
1144
1145 /* GLRStacks */
1146
1147 /** Initialize SET to a singleton set containing an empty stack. */
1148 static yybool
1149 yyinitStateSet (yyGLRStateSet* yyset)
1150 {
1151 yyset->yysize = 1;
1152 yyset->yycapacity = 16;
1153 yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
1154 if (! yyset->yystates)
1155 return yyfalse;
1156 yyset->yystates[0] = NULL;
1157 yyset->yylookaheadNeeds =
1158 (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
1159 if (! yyset->yylookaheadNeeds)
1160 {
1161 YYFREE (yyset->yystates);
1162 return yyfalse;
1163 }
1164 return yytrue;
1165 }
1166
1167 static void yyfreeStateSet (yyGLRStateSet* yyset)
1168 {
1169 YYFREE (yyset->yystates);
1170 YYFREE (yyset->yylookaheadNeeds);
1171 }
1172
1173 /** Initialize STACK to a single empty stack, with total maximum
1174 * capacity for all stacks of SIZE. */
1175 static yybool
1176 yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
1177 {
1178 yystackp->yyerrState = 0;
1179 yynerrs = 0;
1180 yystackp->yyspaceLeft = yysize;
1181 yystackp->yyitems =
1182 (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
1183 if (!yystackp->yyitems)
1184 return yyfalse;
1185 yystackp->yynextFree = yystackp->yyitems;
1186 yystackp->yysplitPoint = NULL;
1187 yystackp->yylastDeleted = NULL;
1188 return yyinitStateSet (&yystackp->yytops);
1189 }
1190
1191
1192 #if YYSTACKEXPANDABLE
1193 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1194 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1195
1196 /** If STACK is expandable, extend it. WARNING: Pointers into the
1197 stack from outside should be considered invalid after this call.
1198 We always expand when there are 1 or fewer items left AFTER an
1199 allocation, so that we can avoid having external pointers exist
1200 across an allocation. */
1201 static void
1202 yyexpandGLRStack (yyGLRStack* yystackp)
1203 {
1204 yyGLRStackItem* yynewItems;
1205 yyGLRStackItem* yyp0, *yyp1;
1206 size_t yysize, yynewSize;
1207 size_t yyn;
1208 yysize = yystackp->yynextFree - yystackp->yyitems;
1209 if (YYMAXDEPTH - YYHEADROOM < yysize)
1210 yyMemoryExhausted (yystackp);
1211 yynewSize = 2*yysize;
1212 if (YYMAXDEPTH < yynewSize)
1213 yynewSize = YYMAXDEPTH;
1214 yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
1215 if (! yynewItems)
1216 yyMemoryExhausted (yystackp);
1217 for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
1218 0 < yyn;
1219 yyn -= 1, yyp0 += 1, yyp1 += 1)
1220 {
1221 *yyp1 = *yyp0;
1222 if (*(yybool *) yyp0)
1223 {
1224 yyGLRState* yys0 = &yyp0->yystate;
1225 yyGLRState* yys1 = &yyp1->yystate;
1226 if (yys0->yypred != NULL)
1227 yys1->yypred =
1228 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
1229 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)
1230 yys1->yysemantics.yyfirstVal =
1231 YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
1232 }
1233 else
1234 {
1235 yySemanticOption* yyv0 = &yyp0->yyoption;
1236 yySemanticOption* yyv1 = &yyp1->yyoption;
1237 if (yyv0->yystate != NULL)
1238 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
1239 if (yyv0->yynext != NULL)
1240 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
1241 }
1242 }
1243 if (yystackp->yysplitPoint != NULL)
1244 yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
1245 yystackp->yysplitPoint, yystate);
1246
1247 for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
1248 if (yystackp->yytops.yystates[yyn] != NULL)
1249 yystackp->yytops.yystates[yyn] =
1250 YYRELOC (yystackp->yyitems, yynewItems,
1251 yystackp->yytops.yystates[yyn], yystate);
1252 YYFREE (yystackp->yyitems);
1253 yystackp->yyitems = yynewItems;
1254 yystackp->yynextFree = yynewItems + yysize;
1255 yystackp->yyspaceLeft = yynewSize - yysize;
1256 }
1257 #endif
1258
1259 static void
1260 yyfreeGLRStack (yyGLRStack* yystackp)
1261 {
1262 YYFREE (yystackp->yyitems);
1263 yyfreeStateSet (&yystackp->yytops);
1264 }
1265
1266 /** Assuming that S is a GLRState somewhere on STACK, update the
1267 * splitpoint of STACK, if needed, so that it is at least as deep as
1268 * S. */
1269 static inline void
1270 yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
1271 {
1272 if (yystackp->yysplitPoint != NULL && yystackp->yysplitPoint > yys)
1273 yystackp->yysplitPoint = yys;
1274 }
1275
1276 /** Invalidate stack #K in STACK. */
1277 static inline void
1278 yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
1279 {
1280 if (yystackp->yytops.yystates[yyk] != NULL)
1281 yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
1282 yystackp->yytops.yystates[yyk] = NULL;
1283 }
1284
1285 /** Undelete the last stack that was marked as deleted. Can only be
1286 done once after a deletion, and only when all other stacks have
1287 been deleted. */
1288 static void
1289 yyundeleteLastStack (yyGLRStack* yystackp)
1290 {
1291 if (yystackp->yylastDeleted == NULL || yystackp->yytops.yysize != 0)
1292 return;
1293 yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
1294 yystackp->yytops.yysize = 1;
1295 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
1296 yystackp->yylastDeleted = NULL;
1297 }
1298
1299 static inline void
1300 yyremoveDeletes (yyGLRStack* yystackp)
1301 {
1302 size_t yyi, yyj;
1303 yyi = yyj = 0;
1304 while (yyj < yystackp->yytops.yysize)
1305 {
1306 if (yystackp->yytops.yystates[yyi] == NULL)
1307 {
1308 if (yyi == yyj)
1309 {
1310 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
1311 }
1312 yystackp->yytops.yysize -= 1;
1313 }
1314 else
1315 {
1316 yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
1317 /* In the current implementation, it's unnecessary to copy
1318 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1319 yyremoveDeletes returns, the parser immediately either enters
1320 deterministic operation or shifts a token. However, it doesn't
1321 hurt, and the code might evolve to need it. */
1322 yystackp->yytops.yylookaheadNeeds[yyj] =
1323 yystackp->yytops.yylookaheadNeeds[yyi];
1324 if (yyj != yyi)
1325 {
1326 YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
1327 (unsigned long int) yyi, (unsigned long int) yyj));
1328 }
1329 yyj += 1;
1330 }
1331 yyi += 1;
1332 }
1333 }
1334
1335 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1336 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1337 static inline void
1338 yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1339 size_t yyposn,
1340 YYSTYPE* yyvalp, YYLTYPE* yylocp)
1341 {
1342 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1343
1344 yynewState->yylrState = yylrState;
1345 yynewState->yyposn = yyposn;
1346 yynewState->yyresolved = yytrue;
1347 yynewState->yypred = yystackp->yytops.yystates[yyk];
1348 yynewState->yysemantics.yysval = *yyvalp;
1349 yynewState->yyloc = *yylocp;
1350 yystackp->yytops.yystates[yyk] = yynewState;
1351
1352 YY_RESERVE_GLRSTACK (yystackp);
1353 }
1354
1355 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1356 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1357 * semantic value of YYRHS under the action for YYRULE. */
1358 static inline void
1359 yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1360 size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule)
1361 {
1362 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1363
1364 yynewState->yylrState = yylrState;
1365 yynewState->yyposn = yyposn;
1366 yynewState->yyresolved = yyfalse;
1367 yynewState->yypred = yystackp->yytops.yystates[yyk];
1368 yynewState->yysemantics.yyfirstVal = NULL;
1369 yystackp->yytops.yystates[yyk] = yynewState;
1370
1371 /* Invokes YY_RESERVE_GLRSTACK. */
1372 yyaddDeferredAction (yystackp, yyk, yynewState, rhs, yyrule);
1373 }
1374
1375 /** Pop the symbols consumed by reduction #RULE from the top of stack
1376 * #K of STACK, and perform the appropriate semantic action on their
1377 * semantic values. Assumes that all ambiguities in semantic values
1378 * have been previously resolved. Set *VALP to the resulting value,
1379 * and *LOCP to the computed location (if any). Return value is as
1380 * for userAction. */
1381 static inline YYRESULTTAG
1382 yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1383 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1384 {
1385 int yynrhs = yyrhsLength (yyrule);
1386
1387 if (yystackp->yysplitPoint == NULL)
1388 {
1389 /* Standard special case: single stack. */
1390 yyGLRStackItem* rhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
1391 YYASSERT (yyk == 0);
1392 yystackp->yynextFree -= yynrhs;
1393 yystackp->yyspaceLeft += yynrhs;
1394 yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
1395 return yyuserAction (yyrule, yynrhs, rhs,
1396 yyvalp, yylocp, yystackp]b4_user_args[);
1397 }
1398 else
1399 {
1400 /* At present, doAction is never called in nondeterministic
1401 * mode, so this branch is never taken. It is here in
1402 * anticipation of a future feature that will allow immediate
1403 * evaluation of selected actions in nondeterministic mode. */
1404 int yyi;
1405 yyGLRState* yys;
1406 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1407 yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
1408 = yystackp->yytops.yystates[yyk];]b4_location_if([[
1409 if (yynrhs == 0)
1410 /* Set default location. */
1411 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
1412 for (yyi = 0; yyi < yynrhs; yyi += 1)
1413 {
1414 yys = yys->yypred;
1415 YYASSERT (yys);
1416 }
1417 yyupdateSplit (yystackp, yys);
1418 yystackp->yytops.yystates[yyk] = yys;
1419 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1420 yyvalp, yylocp, yystackp]b4_user_args[);
1421 }
1422 }
1423
1424 #if !YYDEBUG
1425 # define YY_REDUCE_PRINT(Args)
1426 #else
1427 # define YY_REDUCE_PRINT(Args) \
1428 do { \
1429 if (yydebug) \
1430 yy_reduce_print Args; \
1431 } while (YYID (0))
1432
1433 /*----------------------------------------------------------.
1434 | Report that the RULE is going to be reduced on stack #K. |
1435 `----------------------------------------------------------*/
1436
1437 /*ARGSUSED*/ static inline void
1438 yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1439 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1440 {
1441 int yynrhs = yyrhsLength (yyrule);
1442 yybool yynormal __attribute__ ((__unused__)) =
1443 (yystackp->yysplitPoint == NULL);
1444 yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
1445 int yylow = 1;
1446 int yyi;
1447 YYUSE (yyvalp);
1448 YYUSE (yylocp);
1449 ]b4_parse_param_use[]dnl
1450 [ YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
1451 (unsigned long int) yyk, yyrule - 1,
1452 (unsigned long int) yyrline[yyrule]);
1453 /* The symbols being reduced. */
1454 for (yyi = 0; yyi < yynrhs; yyi++)
1455 {
1456 fprintf (stderr, " $%d = ", yyi + 1);
1457 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1458 &]b4_rhs_value(yynrhs, yyi + 1)[
1459 ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
1460 b4_user_args[);
1461 fprintf (stderr, "\n");
1462 }
1463 }
1464 #endif
1465
1466 /** Pop items off stack #K of STACK according to grammar rule RULE,
1467 * and push back on the resulting nonterminal symbol. Perform the
1468 * semantic action associated with RULE and store its value with the
1469 * newly pushed state, if FORCEEVAL or if STACK is currently
1470 * unambiguous. Otherwise, store the deferred semantic action with
1471 * the new state. If the new state would have an identical input
1472 * position, LR state, and predecessor to an existing state on the stack,
1473 * it is identified with that existing state, eliminating stack #K from
1474 * the STACK. In this case, the (necessarily deferred) semantic value is
1475 * added to the options for the existing state's semantic value.
1476 */
1477 static inline YYRESULTTAG
1478 yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1479 yybool yyforceEval]b4_user_formals[)
1480 {
1481 size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
1482
1483 if (yyforceEval || yystackp->yysplitPoint == NULL)
1484 {
1485 YYSTYPE yysval;
1486 YYLTYPE yyloc;
1487
1488 YY_REDUCE_PRINT ((yystackp, yyk, yyrule, &yysval, &yyloc]b4_user_args[));
1489 YYCHK (yydoAction (yystackp, yyk, yyrule, &yysval,
1490 &yyloc]b4_user_args[));
1491 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
1492 yyglrShift (yystackp, yyk,
1493 yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
1494 yylhsNonterm (yyrule)),
1495 yyposn, &yysval, &yyloc);
1496 }
1497 else
1498 {
1499 size_t yyi;
1500 int yyn;
1501 yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
1502 yyStateNum yynewLRState;
1503
1504 for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1505 0 < yyn; yyn -= 1)
1506 {
1507 yys = yys->yypred;
1508 YYASSERT (yys);
1509 }
1510 yyupdateSplit (yystackp, yys);
1511 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1512 YYDPRINTF ((stderr,
1513 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1514 (unsigned long int) yyk, yyrule - 1, yynewLRState));
1515 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
1516 if (yyi != yyk && yystackp->yytops.yystates[yyi] != NULL)
1517 {
1518 yyGLRState* yyp, *yysplit = yystackp->yysplitPoint;
1519 yyp = yystackp->yytops.yystates[yyi];
1520 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1521 {
1522 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1523 {
1524 yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
1525 yymarkStackDeleted (yystackp, yyk);
1526 YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
1527 (unsigned long int) yyk,
1528 (unsigned long int) yyi));
1529 return yyok;
1530 }
1531 yyp = yyp->yypred;
1532 }
1533 }
1534 yystackp->yytops.yystates[yyk] = yys;
1535 yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
1536 }
1537 return yyok;
1538 }
1539
1540 static size_t
1541 yysplitStack (yyGLRStack* yystackp, size_t yyk)
1542 {
1543 if (yystackp->yysplitPoint == NULL)
1544 {
1545 YYASSERT (yyk == 0);
1546 yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
1547 }
1548 if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
1549 {
1550 yyGLRState** yynewStates;
1551 yybool* yynewLookaheadNeeds;
1552
1553 yynewStates = NULL;
1554
1555 if (yystackp->yytops.yycapacity
1556 > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
1557 yyMemoryExhausted (yystackp);
1558 yystackp->yytops.yycapacity *= 2;
1559
1560 yynewStates =
1561 (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
1562 (yystackp->yytops.yycapacity
1563 * sizeof yynewStates[0]));
1564 if (yynewStates == NULL)
1565 yyMemoryExhausted (yystackp);
1566 yystackp->yytops.yystates = yynewStates;
1567
1568 yynewLookaheadNeeds =
1569 (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
1570 (yystackp->yytops.yycapacity
1571 * sizeof yynewLookaheadNeeds[0]));
1572 if (yynewLookaheadNeeds == NULL)
1573 yyMemoryExhausted (yystackp);
1574 yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
1575 }
1576 yystackp->yytops.yystates[yystackp->yytops.yysize]
1577 = yystackp->yytops.yystates[yyk];
1578 yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
1579 = yystackp->yytops.yylookaheadNeeds[yyk];
1580 yystackp->yytops.yysize += 1;
1581 return yystackp->yytops.yysize-1;
1582 }
1583
1584 /** True iff Y0 and Y1 represent identical options at the top level.
1585 * That is, they represent the same rule applied to RHS symbols
1586 * that produce the same terminal symbols. */
1587 static yybool
1588 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1589 {
1590 if (yyy0->yyrule == yyy1->yyrule)
1591 {
1592 yyGLRState *yys0, *yys1;
1593 int yyn;
1594 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1595 yyn = yyrhsLength (yyy0->yyrule);
1596 yyn > 0;
1597 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1598 if (yys0->yyposn != yys1->yyposn)
1599 return yyfalse;
1600 return yytrue;
1601 }
1602 else
1603 return yyfalse;
1604 }
1605
1606 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1607 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1608 static void
1609 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1610 {
1611 yyGLRState *yys0, *yys1;
1612 int yyn;
1613 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1614 yyn = yyrhsLength (yyy0->yyrule);
1615 yyn > 0;
1616 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1617 {
1618 if (yys0 == yys1)
1619 break;
1620 else if (yys0->yyresolved)
1621 {
1622 yys1->yyresolved = yytrue;
1623 yys1->yysemantics.yysval = yys0->yysemantics.yysval;
1624 }
1625 else if (yys1->yyresolved)
1626 {
1627 yys0->yyresolved = yytrue;
1628 yys0->yysemantics.yysval = yys1->yysemantics.yysval;
1629 }
1630 else
1631 {
1632 yySemanticOption** yyz0p;
1633 yySemanticOption* yyz1;
1634 yyz0p = &yys0->yysemantics.yyfirstVal;
1635 yyz1 = yys1->yysemantics.yyfirstVal;
1636 while (YYID (yytrue))
1637 {
1638 if (yyz1 == *yyz0p || yyz1 == NULL)
1639 break;
1640 else if (*yyz0p == NULL)
1641 {
1642 *yyz0p = yyz1;
1643 break;
1644 }
1645 else if (*yyz0p < yyz1)
1646 {
1647 yySemanticOption* yyz = *yyz0p;
1648 *yyz0p = yyz1;
1649 yyz1 = yyz1->yynext;
1650 (*yyz0p)->yynext = yyz;
1651 }
1652 yyz0p = &(*yyz0p)->yynext;
1653 }
1654 yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
1655 }
1656 }
1657 }
1658
1659 /** Y0 and Y1 represent two possible actions to take in a given
1660 * parsing state; return 0 if no combination is possible,
1661 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1662 static int
1663 yypreference (yySemanticOption* y0, yySemanticOption* y1)
1664 {
1665 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1666 int p0 = yydprec[r0], p1 = yydprec[r1];
1667
1668 if (p0 == p1)
1669 {
1670 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1671 return 0;
1672 else
1673 return 1;
1674 }
1675 if (p0 == 0 || p1 == 0)
1676 return 0;
1677 if (p0 < p1)
1678 return 3;
1679 if (p1 < p0)
1680 return 2;
1681 return 0;
1682 }
1683
1684 static YYRESULTTAG yyresolveValue (yyGLRState* yys,
1685 yyGLRStack* yystackp]b4_user_formals[);
1686
1687
1688 /** Resolve the previous N states starting at and including state S. If result
1689 * != yyok, some states may have been left unresolved possibly with empty
1690 * semantic option chains. Regardless of whether result = yyok, each state
1691 * has been left with consistent data so that yydestroyGLRState can be invoked
1692 * if necessary. */
1693 static YYRESULTTAG
1694 yyresolveStates (yyGLRState* yys, int yyn,
1695 yyGLRStack* yystackp]b4_user_formals[)
1696 {
1697 if (0 < yyn)
1698 {
1699 YYASSERT (yys->yypred);
1700 YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
1701 if (! yys->yyresolved)
1702 YYCHK (yyresolveValue (yys, yystackp]b4_user_args[));
1703 }
1704 return yyok;
1705 }
1706
1707 /** Resolve the states for the RHS of OPT, perform its user action, and return
1708 * the semantic value and location. Regardless of whether result = yyok, all
1709 * RHS states have been destroyed (assuming the user action destroys all RHS
1710 * semantic values if invoked). */
1711 static YYRESULTTAG
1712 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
1713 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1714 {
1715 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1716 int yynrhs;
1717 int yychar_current;
1718 YYSTYPE yylval_current;
1719 YYLTYPE yylloc_current;
1720 YYRESULTTAG yyflag;
1721
1722 yynrhs = yyrhsLength (yyopt->yyrule);
1723 yyflag = yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
1724 if (yyflag != yyok)
1725 {
1726 yyGLRState *yys;
1727 for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
1728 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
1729 return yyflag;
1730 }
1731
1732 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_location_if([[
1733 if (yynrhs == 0)
1734 /* Set default location. */
1735 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
1736 yychar_current = yychar;
1737 yylval_current = yylval;
1738 yylloc_current = yylloc;
1739 yychar = yyopt->yyrawchar;
1740 yylval = yyopt->yyval;
1741 yylloc = yyopt->yyloc;
1742 yyflag = yyuserAction (yyopt->yyrule, yynrhs,
1743 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1744 yyvalp, yylocp, yystackp]b4_user_args[);
1745 yychar = yychar_current;
1746 yylval = yylval_current;
1747 yylloc = yylloc_current;
1748 return yyflag;
1749 }
1750
1751 #if YYDEBUG
1752 static void
1753 yyreportTree (yySemanticOption* yyx, int yyindent)
1754 {
1755 int yynrhs = yyrhsLength (yyx->yyrule);
1756 int yyi;
1757 yyGLRState* yys;
1758 yyGLRState* yystates[YYMAXRHS];
1759 yyGLRState yyleftmost_state;
1760
1761 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1762 yystates[yyi] = yys;
1763 if (yys == NULL)
1764 {
1765 yyleftmost_state.yyposn = 0;
1766 yystates[0] = &yyleftmost_state;
1767 }
1768 else
1769 yystates[0] = yys;
1770
1771 if (yyx->yystate->yyposn < yys->yyposn + 1)
1772 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1773 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1774 yyx->yyrule);
1775 else
1776 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1777 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1778 yyx->yyrule, (unsigned long int) (yys->yyposn + 1),
1779 (unsigned long int) yyx->yystate->yyposn);
1780 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1781 {
1782 if (yystates[yyi]->yyresolved)
1783 {
1784 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1785 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1786 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
1787 else
1788 YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
1789 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1790 (unsigned long int) (yystates[yyi - 1]->yyposn + 1),
1791 (unsigned long int) yystates[yyi]->yyposn);
1792 }
1793 else
1794 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1795 }
1796 }
1797 #endif
1798
1799 /*ARGSUSED*/ static YYRESULTTAG
1800 yyreportAmbiguity (yySemanticOption* yyx0,
1801 yySemanticOption* yyx1]b4_pure_formals[)
1802 {
1803 YYUSE (yyx0);
1804 YYUSE (yyx1);
1805
1806 #if YYDEBUG
1807 YYFPRINTF (stderr, "Ambiguity detected.\n");
1808 YYFPRINTF (stderr, "Option 1,\n");
1809 yyreportTree (yyx0, 2);
1810 YYFPRINTF (stderr, "\nOption 2,\n");
1811 yyreportTree (yyx1, 2);
1812 YYFPRINTF (stderr, "\n");
1813 #endif
1814
1815 yyerror (]b4_yyerror_args[YY_("syntax is ambiguous"));
1816 return yyabort;
1817 }
1818
1819 /** Starting at and including state S1, resolve the location for each of the
1820 * previous N1 states that is unresolved. The first semantic option of a state
1821 * is always chosen. */
1822 static void
1823 yyresolveLocations (yyGLRState* yys1, int yyn1,
1824 yyGLRStack *yystackp]b4_user_formals[)
1825 {
1826 if (0 < yyn1)
1827 {
1828 yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
1829 if (!yys1->yyresolved)
1830 {
1831 yySemanticOption *yyoption;
1832 yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
1833 int yynrhs;
1834 int yychar_current;
1835 YYSTYPE yylval_current;
1836 YYLTYPE yylloc_current;
1837 yyoption = yys1->yysemantics.yyfirstVal;
1838 YYASSERT (yyoption != NULL);
1839 yynrhs = yyrhsLength (yyoption->yyrule);
1840 if (yynrhs > 0)
1841 {
1842 yyGLRState *yys;
1843 int yyn;
1844 yyresolveLocations (yyoption->yystate, yynrhs,
1845 yystackp]b4_user_args[);
1846 for (yys = yyoption->yystate, yyn = yynrhs;
1847 yyn > 0;
1848 yys = yys->yypred, yyn -= 1)
1849 yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
1850 }
1851 else
1852 {
1853 yyGLRState *yyprevious = yyoption->yystate;
1854 YYASSERT (yyprevious->yyresolved);
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_location_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;
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 look-ahead. */
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_location_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_location_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_location_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_location_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_location_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_location_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_location_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_location_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_location_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_location_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 return yyresult;
2535 }
2536
2537 /* DEBUGGING ONLY */
2538 #ifdef YYDEBUG
2539 static void yypstack (yyGLRStack* yystackp, size_t yyk)
2540 __attribute__ ((__unused__));
2541 static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
2542
2543 static void
2544 yy_yypstack (yyGLRState* yys)
2545 {
2546 if (yys->yypred)
2547 {
2548 yy_yypstack (yys->yypred);
2549 fprintf (stderr, " -> ");
2550 }
2551 fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long int) yys->yyposn);
2552 }
2553
2554 static void
2555 yypstates (yyGLRState* yyst)
2556 {
2557 if (yyst == NULL)
2558 fprintf (stderr, "<null>");
2559 else
2560 yy_yypstack (yyst);
2561 fprintf (stderr, "\n");
2562 }
2563
2564 static void
2565 yypstack (yyGLRStack* yystackp, size_t yyk)
2566 {
2567 yypstates (yystackp->yytops.yystates[yyk]);
2568 }
2569
2570 #define YYINDEX(YYX) \
2571 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2572
2573
2574 static void
2575 yypdumpstack (yyGLRStack* yystackp)
2576 {
2577 yyGLRStackItem* yyp;
2578 size_t yyi;
2579 for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
2580 {
2581 fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - yystackp->yyitems));
2582 if (*(yybool *) yyp)
2583 {
2584 fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2585 yyp->yystate.yyresolved, yyp->yystate.yylrState,
2586 (unsigned long int) yyp->yystate.yyposn,
2587 (long int) YYINDEX (yyp->yystate.yypred));
2588 if (! yyp->yystate.yyresolved)
2589 fprintf (stderr, ", firstVal: %ld",
2590 (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
2591 }
2592 else
2593 {
2594 fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",
2595 yyp->yyoption.yyrule,
2596 (long int) YYINDEX (yyp->yyoption.yystate),
2597 (long int) YYINDEX (yyp->yyoption.yynext));
2598 }
2599 fprintf (stderr, "\n");
2600 }
2601 fprintf (stderr, "Tops:");
2602 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
2603 fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi,
2604 (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
2605 fprintf (stderr, "\n");
2606 }
2607 #endif
2608 ]
2609
2610 b4_epilogue
2611 m4_if(b4_defines_flag, 0, [],
2612 [@output @output_header_name@
2613 b4_copyright([Skeleton interface for Bison GLR parsers in C],
2614 [2002, 2003, 2004, 2005, 2006])
2615 [
2616 /* As a special exception, you may create a larger work that contains
2617 part or all of the Bison parser skeleton and distribute that work
2618 under terms of your choice, so long as that work isn't itself a
2619 parser generator using the skeleton or a modified version thereof
2620 as a parser skeleton. Alternatively, if you modify or redistribute
2621 the parser skeleton itself, you may (at your option) remove this
2622 special exception, which will cause the skeleton and the resulting
2623 Bison output files to be licensed under the GNU General Public
2624 License without this special exception.
2625
2626 This special exception was added by the Free Software Foundation in
2627 version 2.2 of Bison. */
2628 ]
2629
2630 b4_shared_declarations
2631
2632 extern YYSTYPE b4_prefix[]lval;
2633
2634 b4_location_if([b4_pure_if([],
2635 [extern YYLTYPE b4_prefix[]lloc;])
2636 ])
2637 ])