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