]> git.saurik.com Git - bison.git/blob - data/glr.c
glr.c: minor refactoring.
[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 ## Declarations. ##
159 ## -------------- ##
160
161 # b4_shared_declarations
162 # ----------------------
163 # Declaration that might either go into the header (if --defines)
164 # or open coded in the parser body.
165 m4_define([b4_shared_declarations],
166 [b4_percent_code_get([[requires]])[]dnl
167
168 b4_token_enums(b4_tokens)
169
170 [#ifndef YYSTYPE
171 ]m4_ifdef([b4_stype],
172 [[typedef union ]b4_union_name[
173 {
174 ]b4_user_stype[
175 } YYSTYPE;
176 # define YYSTYPE_IS_TRIVIAL 1]],
177 [m4_if(b4_tag_seen_flag, 0,
178 [[typedef int YYSTYPE;
179 # define YYSTYPE_IS_TRIVIAL 1]])])[
180 #endif
181 ]b4_locations_if([[
182 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
183 typedef struct YYLTYPE
184 {
185 int first_line;
186 int first_column;
187 int last_line;
188 int last_column;
189 } YYLTYPE;
190 # define YYLTYPE_IS_DECLARED 1
191 # define YYLTYPE_IS_TRIVIAL 1
192 #endif
193 ]])[
194 ]b4_percent_code_get([[provides]])[]dnl
195 ])
196
197
198 ## -------------- ##
199 ## Output files. ##
200 ## -------------- ##
201
202 # We do want M4 expansion after # for CPP macros.
203 m4_changecom()
204 m4_divert_push(0)dnl
205 @output(b4_parser_file_name@)@
206 b4_copyright([Skeleton implementation for Bison GLR parsers in C],
207 [2002-2012])
208 [
209 /* C GLR parser skeleton written by Paul Hilfinger. */
210
211 ]b4_identification
212
213 b4_percent_code_get([[top]])[]dnl
214 m4_if(b4_prefix, [yy], [],
215 [/* Substitute the variable and function names. */
216 #define yyparse b4_prefix[]parse
217 #define yylex b4_prefix[]lex
218 #define yyerror b4_prefix[]error
219 #define yylval b4_prefix[]lval
220 #define yychar b4_prefix[]char
221 #define yydebug b4_prefix[]debug
222 #define yynerrs b4_prefix[]nerrs
223 #define yylloc b4_prefix[]lloc])[
224
225 /* Copy the first part of user declarations. */
226 ]b4_user_pre_prologue[
227
228 ]b4_null_define[
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;]b4_locations_if([[
570 YYLTYPE yylloc;]])[
571
572 int yynerrs;
573 int yychar;])[
574
575 static const int YYEOF = 0;
576 static const int YYEMPTY = -2;
577
578 typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
579
580 #define YYCHK(YYE) \
581 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
582 while (YYID (0))
583
584 #if YYDEBUG
585
586 # ifndef YYFPRINTF
587 # define YYFPRINTF fprintf
588 # endif
589
590 # define YYDPRINTF(Args) \
591 do { \
592 if (yydebug) \
593 YYFPRINTF Args; \
594 } while (YYID (0))
595
596 ]b4_yy_symbol_print_generate([b4_c_ansi_function_def])[
597
598 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
599 do { \
600 if (yydebug) \
601 { \
602 YYFPRINTF (stderr, "%s ", Title); \
603 yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
604 YYFPRINTF (stderr, "\n"); \
605 } \
606 } while (YYID (0))
607
608 /* Nonzero means print parse trace. It is left uninitialized so that
609 multiple parsers can coexist. */
610 int yydebug;
611
612 #else /* !YYDEBUG */
613
614 # define YYDPRINTF(Args)
615 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
616
617 #endif /* !YYDEBUG */
618
619 /* YYINITDEPTH -- initial size of the parser's stacks. */
620 #ifndef YYINITDEPTH
621 # define YYINITDEPTH ]b4_stack_depth_init[
622 #endif
623
624 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
625 if the built-in stack extension method is used).
626
627 Do not make this value too large; the results are undefined if
628 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
629 evaluated with infinite-precision integer arithmetic. */
630
631 #ifndef YYMAXDEPTH
632 # define YYMAXDEPTH ]b4_stack_depth_max[
633 #endif
634
635 /* Minimum number of free items on the stack allowed after an
636 allocation. This is to allow allocation and initialization
637 to be completed by functions that call yyexpandGLRStack before the
638 stack is expanded, thus insuring that all necessary pointers get
639 properly redirected to new data. */
640 #define YYHEADROOM 2
641
642 #ifndef YYSTACKEXPANDABLE
643 # if (! defined __cplusplus \
644 || (]b4_locations_if([[defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
645 && ]])[defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
646 # define YYSTACKEXPANDABLE 1
647 # else
648 # define YYSTACKEXPANDABLE 0
649 # endif
650 #endif
651
652 #if YYSTACKEXPANDABLE
653 # define YY_RESERVE_GLRSTACK(Yystack) \
654 do { \
655 if (Yystack->yyspaceLeft < YYHEADROOM) \
656 yyexpandGLRStack (Yystack); \
657 } while (YYID (0))
658 #else
659 # define YY_RESERVE_GLRSTACK(Yystack) \
660 do { \
661 if (Yystack->yyspaceLeft < YYHEADROOM) \
662 yyMemoryExhausted (Yystack); \
663 } while (YYID (0))
664 #endif
665
666
667 #if YYERROR_VERBOSE
668
669 # ifndef yystpcpy
670 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
671 # define yystpcpy stpcpy
672 # else
673 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
674 YYDEST. */
675 static char *
676 yystpcpy (char *yydest, const char *yysrc)
677 {
678 char *yyd = yydest;
679 const char *yys = yysrc;
680
681 while ((*yyd++ = *yys++) != '\0')
682 continue;
683
684 return yyd - 1;
685 }
686 # endif
687 # endif
688
689 # ifndef yytnamerr
690 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
691 quotes and backslashes, so that it's suitable for yyerror. The
692 heuristic is that double-quoting is unnecessary unless the string
693 contains an apostrophe, a comma, or backslash (other than
694 backslash-backslash). YYSTR is taken from yytname. If YYRES is
695 null, do not copy; instead, return the length of what the result
696 would have been. */
697 static size_t
698 yytnamerr (char *yyres, const char *yystr)
699 {
700 if (*yystr == '"')
701 {
702 size_t yyn = 0;
703 char const *yyp = yystr;
704
705 for (;;)
706 switch (*++yyp)
707 {
708 case '\'':
709 case ',':
710 goto do_not_strip_quotes;
711
712 case '\\':
713 if (*++yyp != '\\')
714 goto do_not_strip_quotes;
715 /* Fall through. */
716 default:
717 if (yyres)
718 yyres[yyn] = *yyp;
719 yyn++;
720 break;
721
722 case '"':
723 if (yyres)
724 yyres[yyn] = '\0';
725 return yyn;
726 }
727 do_not_strip_quotes: ;
728 }
729
730 if (! yyres)
731 return strlen (yystr);
732
733 return yystpcpy (yyres, yystr) - yyres;
734 }
735 # endif
736
737 #endif /* !YYERROR_VERBOSE */
738
739 /** State numbers, as in LALR(1) machine */
740 typedef int yyStateNum;
741
742 /** Rule numbers, as in LALR(1) machine */
743 typedef int yyRuleNum;
744
745 /** Grammar symbol */
746 typedef short int yySymbol;
747
748 /** Item references, as in LALR(1) machine */
749 typedef short int yyItemNum;
750
751 typedef struct yyGLRState yyGLRState;
752 typedef struct yyGLRStateSet yyGLRStateSet;
753 typedef struct yySemanticOption yySemanticOption;
754 typedef union yyGLRStackItem yyGLRStackItem;
755 typedef struct yyGLRStack yyGLRStack;
756
757 struct yyGLRState {
758 /** Type tag: always true. */
759 yybool yyisState;
760 /** Type tag for yysemantics. If true, yysval applies, otherwise
761 * yyfirstVal applies. */
762 yybool yyresolved;
763 /** Number of corresponding LALR(1) machine state. */
764 yyStateNum yylrState;
765 /** Preceding state in this stack */
766 yyGLRState* yypred;
767 /** Source position of the first token produced by my symbol */
768 size_t yyposn;
769 union {
770 /** First in a chain of alternative reductions producing the
771 * non-terminal corresponding to this state, threaded through
772 * yynext. */
773 yySemanticOption* yyfirstVal;
774 /** Semantic value for this state. */
775 YYSTYPE yysval;
776 } yysemantics;]b4_locations_if([[
777 /** Source location for this state. */
778 YYLTYPE yyloc;]])[
779 };
780
781 struct yyGLRStateSet {
782 yyGLRState** yystates;
783 /** During nondeterministic operation, yylookaheadNeeds tracks which
784 * stacks have actually needed the current lookahead. During deterministic
785 * operation, yylookaheadNeeds[0] is not maintained since it would merely
786 * duplicate yychar != YYEMPTY. */
787 yybool* yylookaheadNeeds;
788 size_t yysize, yycapacity;
789 };
790
791 struct yySemanticOption {
792 /** Type tag: always false. */
793 yybool yyisState;
794 /** Rule number for this reduction */
795 yyRuleNum yyrule;
796 /** The last RHS state in the list of states to be reduced. */
797 yyGLRState* yystate;
798 /** The lookahead for this reduction. */
799 int yyrawchar;
800 YYSTYPE yyval;]b4_locations_if([[
801 YYLTYPE yyloc;]])[
802 /** Next sibling in chain of options. To facilitate merging,
803 * options are chained in decreasing order by address. */
804 yySemanticOption* yynext;
805 };
806
807 /** Type of the items in the GLR stack. The yyisState field
808 * indicates which item of the union is valid. */
809 union yyGLRStackItem {
810 yyGLRState yystate;
811 yySemanticOption yyoption;
812 };
813
814 struct yyGLRStack {
815 int yyerrState;
816 ]b4_locations_if([[ /* To compute the location of the error token. */
817 yyGLRStackItem yyerror_range[3];]])[
818 ]b4_pure_if(
819 [
820 int yyerrcnt;
821 int yyrawchar;
822 YYSTYPE yyval;]b4_locations_if([[
823 YYLTYPE yyloc;]])[
824 ])[
825 YYJMP_BUF yyexception_buffer;
826 yyGLRStackItem* yyitems;
827 yyGLRStackItem* yynextFree;
828 size_t yyspaceLeft;
829 yyGLRState* yysplitPoint;
830 yyGLRState* yylastDeleted;
831 yyGLRStateSet yytops;
832 };
833
834 #if YYSTACKEXPANDABLE
835 static void yyexpandGLRStack (yyGLRStack* yystackp);
836 #endif
837
838 static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
839 __attribute__ ((__noreturn__));
840 static void
841 yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
842 {
843 if (yymsg != YY_NULL)
844 yyerror (]b4_yyerror_args[yymsg);
845 YYLONGJMP (yystackp->yyexception_buffer, 1);
846 }
847
848 static void yyMemoryExhausted (yyGLRStack* yystackp)
849 __attribute__ ((__noreturn__));
850 static void
851 yyMemoryExhausted (yyGLRStack* yystackp)
852 {
853 YYLONGJMP (yystackp->yyexception_buffer, 2);
854 }
855
856 #if YYDEBUG || YYERROR_VERBOSE
857 /** A printable representation of TOKEN. */
858 static inline const char*
859 yytokenName (yySymbol yytoken)
860 {
861 if (yytoken == YYEMPTY)
862 return "";
863
864 return yytname[yytoken];
865 }
866 #endif
867
868 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
869 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
870 * containing the pointer to the next state in the chain. */
871 static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
872 static void
873 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
874 {
875 int i;
876 yyGLRState *s = yyvsp[yylow0].yystate.yypred;
877 for (i = yylow0-1; i >= yylow1; i -= 1)
878 {
879 YYASSERT (s->yyresolved);
880 yyvsp[i].yystate.yyresolved = yytrue;
881 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;]b4_locations_if([[
882 yyvsp[i].yystate.yyloc = s->yyloc;]])[
883 s = yyvsp[i].yystate.yypred = s->yypred;
884 }
885 }
886
887 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
888 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
889 * For convenience, always return YYLOW1. */
890 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
891 __attribute__ ((__unused__));
892 static inline int
893 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
894 {
895 if (!yynormal && yylow1 < *yylow)
896 {
897 yyfillin (yyvsp, *yylow, yylow1);
898 *yylow = yylow1;
899 }
900 return yylow1;
901 }
902
903 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
904 * and top stack item YYVSP. YYLVALP points to place to put semantic
905 * value ($$), and yylocp points to place for location information
906 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
907 * yyerr for YYERROR, yyabort for YYABORT. */
908 /*ARGSUSED*/ static YYRESULTTAG
909 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
910 yyGLRStack* yystackp,
911 YYSTYPE* yyvalp]b4_locuser_formals[)
912 {
913 yybool yynormal __attribute__ ((__unused__)) =
914 (yystackp->yysplitPoint == YY_NULL);
915 int yylow;
916 ]b4_parse_param_use[]dnl
917 [# undef yyerrok
918 # define yyerrok (yystackp->yyerrState = 0)
919 # undef YYACCEPT
920 # define YYACCEPT return yyaccept
921 # undef YYABORT
922 # define YYABORT return yyabort
923 # undef YYERROR
924 # define YYERROR return yyerrok, yyerr
925 # undef YYRECOVERING
926 # define YYRECOVERING() (yystackp->yyerrState != 0)
927 # undef yyclearin
928 # define yyclearin (yychar = YYEMPTY)
929 # undef YYFILL
930 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
931 # undef YYBACKUP
932 # define YYBACKUP(Token, Value) \
933 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
934 yyerrok, yyerr
935
936 yylow = 1;
937 if (yyrhslen == 0)
938 *yyvalp = yyval_default;
939 else
940 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
941 YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
942 yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
943 ]])[
944 switch (yyn)
945 {
946 ]b4_user_actions[
947 default: break;
948 }
949
950 return yyok;
951 # undef yyerrok
952 # undef YYABORT
953 # undef YYACCEPT
954 # undef YYERROR
955 # undef YYBACKUP
956 # undef yyclearin
957 # undef YYRECOVERING
958 }
959 \f
960
961 /*ARGSUSED*/ static void
962 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
963 {
964 YYUSE (yy0);
965 YYUSE (yy1);
966
967 switch (yyn)
968 {
969 ]b4_mergers[
970 default: break;
971 }
972 }
973
974 /* Bison grammar-table manipulation. */
975
976 ]b4_yydestruct_generate([b4_c_ansi_function_def])[
977
978 /** Number of symbols composing the right hand side of rule #RULE. */
979 static inline int
980 yyrhsLength (yyRuleNum yyrule)
981 {
982 return yyr2[yyrule];
983 }
984
985 static void
986 yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
987 {
988 if (yys->yyresolved)
989 yydestruct (yymsg, yystos[yys->yylrState],
990 &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
991 else
992 {
993 #if YYDEBUG
994 if (yydebug)
995 {
996 if (yys->yysemantics.yyfirstVal)
997 YYFPRINTF (stderr, "%s unresolved ", yymsg);
998 else
999 YYFPRINTF (stderr, "%s incomplete ", yymsg);
1000 yy_symbol_print (stderr, yystos[yys->yylrState],
1001 YY_NULL]b4_locuser_args([&yys->yyloc])[);
1002 YYFPRINTF (stderr, "\n");
1003 }
1004 #endif
1005
1006 if (yys->yysemantics.yyfirstVal)
1007 {
1008 yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
1009 yyGLRState *yyrh;
1010 int yyn;
1011 for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
1012 yyn > 0;
1013 yyrh = yyrh->yypred, yyn -= 1)
1014 yydestroyGLRState (yymsg, yyrh]b4_user_args[);
1015 }
1016 }
1017 }
1018
1019 /** Left-hand-side symbol for rule #RULE. */
1020 static inline yySymbol
1021 yylhsNonterm (yyRuleNum yyrule)
1022 {
1023 return yyr1[yyrule];
1024 }
1025
1026 #define yypact_value_is_default(yystate) \
1027 ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
1028
1029 /** True iff LR state STATE has only a default reduction (regardless
1030 * of token). */
1031 static inline yybool
1032 yyisDefaultedState (yyStateNum yystate)
1033 {
1034 return yypact_value_is_default (yypact[yystate]);
1035 }
1036
1037 /** The default reduction for STATE, assuming it has one. */
1038 static inline yyRuleNum
1039 yydefaultAction (yyStateNum yystate)
1040 {
1041 return yydefact[yystate];
1042 }
1043
1044 #define yytable_value_is_error(yytable_value) \
1045 ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
1046
1047 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1048 * Result R means
1049 * R < 0: Reduce on rule -R.
1050 * R = 0: Error.
1051 * R > 0: Shift to state R.
1052 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1053 * conflicting reductions.
1054 */
1055 static inline void
1056 yygetLRActions (yyStateNum yystate, int yytoken,
1057 int* yyaction, const short int** yyconflicts)
1058 {
1059 int yyindex = yypact[yystate] + yytoken;
1060 if (yypact_value_is_default (yypact[yystate])
1061 || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
1062 {
1063 *yyaction = -yydefact[yystate];
1064 *yyconflicts = yyconfl;
1065 }
1066 else if (! yytable_value_is_error (yytable[yyindex]))
1067 {
1068 *yyaction = yytable[yyindex];
1069 *yyconflicts = yyconfl + yyconflp[yyindex];
1070 }
1071 else
1072 {
1073 *yyaction = 0;
1074 *yyconflicts = yyconfl + yyconflp[yyindex];
1075 }
1076 }
1077
1078 static inline yyStateNum
1079 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
1080 {
1081 int yyr;
1082 yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
1083 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
1084 return yytable[yyr];
1085 else
1086 return yydefgoto[yylhs - YYNTOKENS];
1087 }
1088
1089 static inline yybool
1090 yyisShiftAction (int yyaction)
1091 {
1092 return 0 < yyaction;
1093 }
1094
1095 static inline yybool
1096 yyisErrorAction (int yyaction)
1097 {
1098 return yyaction == 0;
1099 }
1100
1101 /* GLRStates */
1102
1103 /** Return a fresh GLRStackItem. Callers should call
1104 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1105 * headroom. */
1106
1107 static inline yyGLRStackItem*
1108 yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
1109 {
1110 yyGLRStackItem* yynewItem = yystackp->yynextFree;
1111 yystackp->yyspaceLeft -= 1;
1112 yystackp->yynextFree += 1;
1113 yynewItem->yystate.yyisState = yyisState;
1114 return yynewItem;
1115 }
1116
1117 /** Add a new semantic action that will execute the action for rule
1118 * RULENUM on the semantic values in RHS to the list of
1119 * alternative actions for STATE. Assumes that RHS comes from
1120 * stack #K of *STACKP. */
1121 static void
1122 yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
1123 yyGLRState* rhs, yyRuleNum yyrule)
1124 {
1125 yySemanticOption* yynewOption =
1126 &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
1127 yynewOption->yystate = rhs;
1128 yynewOption->yyrule = yyrule;
1129 if (yystackp->yytops.yylookaheadNeeds[yyk])
1130 {
1131 yynewOption->yyrawchar = yychar;
1132 yynewOption->yyval = yylval;]b4_locations_if([
1133 yynewOption->yyloc = yylloc;])[
1134 }
1135 else
1136 yynewOption->yyrawchar = YYEMPTY;
1137 yynewOption->yynext = yystate->yysemantics.yyfirstVal;
1138 yystate->yysemantics.yyfirstVal = yynewOption;
1139
1140 YY_RESERVE_GLRSTACK (yystackp);
1141 }
1142
1143 /* GLRStacks */
1144
1145 /** Initialize SET to a singleton set containing an empty stack. */
1146 static yybool
1147 yyinitStateSet (yyGLRStateSet* yyset)
1148 {
1149 yyset->yysize = 1;
1150 yyset->yycapacity = 16;
1151 yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
1152 if (! yyset->yystates)
1153 return yyfalse;
1154 yyset->yystates[0] = YY_NULL;
1155 yyset->yylookaheadNeeds =
1156 (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
1157 if (! yyset->yylookaheadNeeds)
1158 {
1159 YYFREE (yyset->yystates);
1160 return yyfalse;
1161 }
1162 return yytrue;
1163 }
1164
1165 static void yyfreeStateSet (yyGLRStateSet* yyset)
1166 {
1167 YYFREE (yyset->yystates);
1168 YYFREE (yyset->yylookaheadNeeds);
1169 }
1170
1171 /** Initialize STACK to a single empty stack, with total maximum
1172 * capacity for all stacks of SIZE. */
1173 static yybool
1174 yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
1175 {
1176 yystackp->yyerrState = 0;
1177 yynerrs = 0;
1178 yystackp->yyspaceLeft = yysize;
1179 yystackp->yyitems =
1180 (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
1181 if (!yystackp->yyitems)
1182 return yyfalse;
1183 yystackp->yynextFree = yystackp->yyitems;
1184 yystackp->yysplitPoint = YY_NULL;
1185 yystackp->yylastDeleted = YY_NULL;
1186 return yyinitStateSet (&yystackp->yytops);
1187 }
1188
1189
1190 #if YYSTACKEXPANDABLE
1191 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1192 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1193
1194 /** If STACK is expandable, extend it. WARNING: Pointers into the
1195 stack from outside should be considered invalid after this call.
1196 We always expand when there are 1 or fewer items left AFTER an
1197 allocation, so that we can avoid having external pointers exist
1198 across an allocation. */
1199 static void
1200 yyexpandGLRStack (yyGLRStack* yystackp)
1201 {
1202 yyGLRStackItem* yynewItems;
1203 yyGLRStackItem* yyp0, *yyp1;
1204 size_t yynewSize;
1205 size_t yyn;
1206 size_t yysize = yystackp->yynextFree - yystackp->yyitems;
1207 if (YYMAXDEPTH - YYHEADROOM < yysize)
1208 yyMemoryExhausted (yystackp);
1209 yynewSize = 2*yysize;
1210 if (YYMAXDEPTH < yynewSize)
1211 yynewSize = YYMAXDEPTH;
1212 yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
1213 if (! yynewItems)
1214 yyMemoryExhausted (yystackp);
1215 for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
1216 0 < yyn;
1217 yyn -= 1, yyp0 += 1, yyp1 += 1)
1218 {
1219 *yyp1 = *yyp0;
1220 if (*(yybool *) yyp0)
1221 {
1222 yyGLRState* yys0 = &yyp0->yystate;
1223 yyGLRState* yys1 = &yyp1->yystate;
1224 if (yys0->yypred != YY_NULL)
1225 yys1->yypred =
1226 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
1227 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULL)
1228 yys1->yysemantics.yyfirstVal =
1229 YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
1230 }
1231 else
1232 {
1233 yySemanticOption* yyv0 = &yyp0->yyoption;
1234 yySemanticOption* yyv1 = &yyp1->yyoption;
1235 if (yyv0->yystate != YY_NULL)
1236 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
1237 if (yyv0->yynext != YY_NULL)
1238 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
1239 }
1240 }
1241 if (yystackp->yysplitPoint != YY_NULL)
1242 yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
1243 yystackp->yysplitPoint, yystate);
1244
1245 for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
1246 if (yystackp->yytops.yystates[yyn] != YY_NULL)
1247 yystackp->yytops.yystates[yyn] =
1248 YYRELOC (yystackp->yyitems, yynewItems,
1249 yystackp->yytops.yystates[yyn], yystate);
1250 YYFREE (yystackp->yyitems);
1251 yystackp->yyitems = yynewItems;
1252 yystackp->yynextFree = yynewItems + yysize;
1253 yystackp->yyspaceLeft = yynewSize - yysize;
1254 }
1255 #endif
1256
1257 static void
1258 yyfreeGLRStack (yyGLRStack* yystackp)
1259 {
1260 YYFREE (yystackp->yyitems);
1261 yyfreeStateSet (&yystackp->yytops);
1262 }
1263
1264 /** Assuming that S is a GLRState somewhere on STACK, update the
1265 * splitpoint of STACK, if needed, so that it is at least as deep as
1266 * S. */
1267 static inline void
1268 yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
1269 {
1270 if (yystackp->yysplitPoint != YY_NULL && yystackp->yysplitPoint > yys)
1271 yystackp->yysplitPoint = yys;
1272 }
1273
1274 /** Invalidate stack #K in STACK. */
1275 static inline void
1276 yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
1277 {
1278 if (yystackp->yytops.yystates[yyk] != YY_NULL)
1279 yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
1280 yystackp->yytops.yystates[yyk] = YY_NULL;
1281 }
1282
1283 /** Undelete the last stack that was marked as deleted. Can only be
1284 done once after a deletion, and only when all other stacks have
1285 been deleted. */
1286 static void
1287 yyundeleteLastStack (yyGLRStack* yystackp)
1288 {
1289 if (yystackp->yylastDeleted == YY_NULL || yystackp->yytops.yysize != 0)
1290 return;
1291 yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
1292 yystackp->yytops.yysize = 1;
1293 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
1294 yystackp->yylastDeleted = YY_NULL;
1295 }
1296
1297 static inline void
1298 yyremoveDeletes (yyGLRStack* yystackp)
1299 {
1300 size_t yyi, yyj;
1301 yyi = yyj = 0;
1302 while (yyj < yystackp->yytops.yysize)
1303 {
1304 if (yystackp->yytops.yystates[yyi] == YY_NULL)
1305 {
1306 if (yyi == yyj)
1307 {
1308 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
1309 }
1310 yystackp->yytops.yysize -= 1;
1311 }
1312 else
1313 {
1314 yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
1315 /* In the current implementation, it's unnecessary to copy
1316 yystackp->yytops.yylookaheadNeeds[yyi] since, after
1317 yyremoveDeletes returns, the parser immediately either enters
1318 deterministic operation or shifts a token. However, it doesn't
1319 hurt, and the code might evolve to need it. */
1320 yystackp->yytops.yylookaheadNeeds[yyj] =
1321 yystackp->yytops.yylookaheadNeeds[yyi];
1322 if (yyj != yyi)
1323 {
1324 YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
1325 (unsigned long int) yyi, (unsigned long int) yyj));
1326 }
1327 yyj += 1;
1328 }
1329 yyi += 1;
1330 }
1331 }
1332
1333 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1334 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1335 static inline void
1336 yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1337 size_t yyposn,
1338 YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
1339 {
1340 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1341
1342 yynewState->yylrState = yylrState;
1343 yynewState->yyposn = yyposn;
1344 yynewState->yyresolved = yytrue;
1345 yynewState->yypred = yystackp->yytops.yystates[yyk];
1346 yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([
1347 yynewState->yyloc = *yylocp;])[
1348 yystackp->yytops.yystates[yyk] = yynewState;
1349
1350 YY_RESERVE_GLRSTACK (yystackp);
1351 }
1352
1353 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1354 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1355 * semantic value of YYRHS under the action for YYRULE. */
1356 static inline void
1357 yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
1358 size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule)
1359 {
1360 yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
1361
1362 yynewState->yylrState = yylrState;
1363 yynewState->yyposn = yyposn;
1364 yynewState->yyresolved = yyfalse;
1365 yynewState->yypred = yystackp->yytops.yystates[yyk];
1366 yynewState->yysemantics.yyfirstVal = YY_NULL;
1367 yystackp->yytops.yystates[yyk] = yynewState;
1368
1369 /* Invokes YY_RESERVE_GLRSTACK. */
1370 yyaddDeferredAction (yystackp, yyk, yynewState, rhs, yyrule);
1371 }
1372
1373 /** Pop the symbols consumed by reduction #RULE from the top of stack
1374 * #K of STACK, and perform the appropriate semantic action on their
1375 * semantic values. Assumes that all ambiguities in semantic values
1376 * have been previously resolved. Set *VALP to the resulting value,
1377 * and *LOCP to the computed location (if any). Return value is as
1378 * for userAction. */
1379 static inline YYRESULTTAG
1380 yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1381 YYSTYPE* yyvalp]b4_locuser_formals[)
1382 {
1383 int yynrhs = yyrhsLength (yyrule);
1384
1385 if (yystackp->yysplitPoint == YY_NULL)
1386 {
1387 /* Standard special case: single stack. */
1388 yyGLRStackItem* rhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
1389 YYASSERT (yyk == 0);
1390 yystackp->yynextFree -= yynrhs;
1391 yystackp->yyspaceLeft += yynrhs;
1392 yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
1393 return yyuserAction (yyrule, yynrhs, rhs, yystackp,
1394 yyvalp]b4_locuser_args[);
1395 }
1396 else
1397 {
1398 /* At present, doAction is never called in nondeterministic
1399 * mode, so this branch is never taken. It is here in
1400 * anticipation of a future feature that will allow immediate
1401 * evaluation of selected actions in nondeterministic mode. */
1402 int yyi;
1403 yyGLRState* yys;
1404 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1405 yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
1406 = yystackp->yytops.yystates[yyk];]b4_locations_if([[
1407 if (yynrhs == 0)
1408 /* Set default location. */
1409 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
1410 for (yyi = 0; yyi < yynrhs; yyi += 1)
1411 {
1412 yys = yys->yypred;
1413 YYASSERT (yys);
1414 }
1415 yyupdateSplit (yystackp, yys);
1416 yystackp->yytops.yystates[yyk] = yys;
1417 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1418 yystackp, yyvalp]b4_locuser_args[);
1419 }
1420 }
1421
1422 #if !YYDEBUG
1423 # define YY_REDUCE_PRINT(Args)
1424 #else
1425 # define YY_REDUCE_PRINT(Args) \
1426 do { \
1427 if (yydebug) \
1428 yy_reduce_print Args; \
1429 } while (YYID (0))
1430
1431 /*----------------------------------------------------------.
1432 | Report that the RULE is going to be reduced on stack #K. |
1433 `----------------------------------------------------------*/
1434
1435 /*ARGSUSED*/ static inline void
1436 yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1437 YYSTYPE* yyvalp]b4_locuser_formals[)
1438 {
1439 int yynrhs = yyrhsLength (yyrule);
1440 yybool yynormal __attribute__ ((__unused__)) =
1441 (yystackp->yysplitPoint == YY_NULL);
1442 yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
1443 int yylow = 1;
1444 int yyi;
1445 YYUSE (yyvalp);]b4_locations_if([
1446 YYUSE (yylocp);])[
1447 ]b4_parse_param_use[]dnl
1448 [ YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
1449 (unsigned long int) yyk, yyrule - 1,
1450 (unsigned long int) yyrline[yyrule]);
1451 /* The symbols being reduced. */
1452 for (yyi = 0; yyi < yynrhs; yyi++)
1453 {
1454 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1455 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1456 &]b4_rhs_value(yynrhs, yyi + 1)[
1457 ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
1458 b4_user_args[);
1459 YYFPRINTF (stderr, "\n");
1460 }
1461 }
1462 #endif
1463
1464 /** Pop items off stack #K of STACK according to grammar rule RULE,
1465 * and push back on the resulting nonterminal symbol. Perform the
1466 * semantic action associated with RULE and store its value with the
1467 * newly pushed state, if FORCEEVAL or if STACK is currently
1468 * unambiguous. Otherwise, store the deferred semantic action with
1469 * the new state. If the new state would have an identical input
1470 * position, LR state, and predecessor to an existing state on the stack,
1471 * it is identified with that existing state, eliminating stack #K from
1472 * the STACK. In this case, the (necessarily deferred) semantic value is
1473 * added to the options for the existing state's semantic value.
1474 */
1475 static inline YYRESULTTAG
1476 yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
1477 yybool yyforceEval]b4_user_formals[)
1478 {
1479 size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
1480
1481 if (yyforceEval || yystackp->yysplitPoint == YY_NULL)
1482 {
1483 YYSTYPE yysval;]b4_locations_if([
1484 YYLTYPE yyloc;])[
1485
1486 YY_REDUCE_PRINT ((yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[));
1487 YYCHK (yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[));
1488 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
1489 yyglrShift (yystackp, yyk,
1490 yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
1491 yylhsNonterm (yyrule)),
1492 yyposn, &yysval]b4_locations_if([, &yyloc])[);
1493 }
1494 else
1495 {
1496 size_t yyi;
1497 int yyn;
1498 yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
1499 yyStateNum yynewLRState;
1500
1501 for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1502 0 < yyn; yyn -= 1)
1503 {
1504 yys = yys->yypred;
1505 YYASSERT (yys);
1506 }
1507 yyupdateSplit (yystackp, yys);
1508 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1509 YYDPRINTF ((stderr,
1510 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1511 (unsigned long int) yyk, yyrule - 1, yynewLRState));
1512 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
1513 if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULL)
1514 {
1515 yyGLRState *yysplit = yystackp->yysplitPoint;
1516 yyGLRState *yyp = yystackp->yytops.yystates[yyi];
1517 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1518 {
1519 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1520 {
1521 yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
1522 yymarkStackDeleted (yystackp, yyk);
1523 YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
1524 (unsigned long int) yyk,
1525 (unsigned long int) yyi));
1526 return yyok;
1527 }
1528 yyp = yyp->yypred;
1529 }
1530 }
1531 yystackp->yytops.yystates[yyk] = yys;
1532 yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
1533 }
1534 return yyok;
1535 }
1536
1537 static size_t
1538 yysplitStack (yyGLRStack* yystackp, size_t yyk)
1539 {
1540 if (yystackp->yysplitPoint == YY_NULL)
1541 {
1542 YYASSERT (yyk == 0);
1543 yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
1544 }
1545 if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
1546 {
1547 yyGLRState** yynewStates;
1548 yybool* yynewLookaheadNeeds;
1549
1550 yynewStates = YY_NULL;
1551
1552 if (yystackp->yytops.yycapacity
1553 > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
1554 yyMemoryExhausted (yystackp);
1555 yystackp->yytops.yycapacity *= 2;
1556
1557 yynewStates =
1558 (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
1559 (yystackp->yytops.yycapacity
1560 * sizeof yynewStates[0]));
1561 if (yynewStates == YY_NULL)
1562 yyMemoryExhausted (yystackp);
1563 yystackp->yytops.yystates = yynewStates;
1564
1565 yynewLookaheadNeeds =
1566 (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
1567 (yystackp->yytops.yycapacity
1568 * sizeof yynewLookaheadNeeds[0]));
1569 if (yynewLookaheadNeeds == YY_NULL)
1570 yyMemoryExhausted (yystackp);
1571 yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
1572 }
1573 yystackp->yytops.yystates[yystackp->yytops.yysize]
1574 = yystackp->yytops.yystates[yyk];
1575 yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
1576 = yystackp->yytops.yylookaheadNeeds[yyk];
1577 yystackp->yytops.yysize += 1;
1578 return yystackp->yytops.yysize-1;
1579 }
1580
1581 /** True iff Y0 and Y1 represent identical options at the top level.
1582 * That is, they represent the same rule applied to RHS symbols
1583 * that produce the same terminal symbols. */
1584 static yybool
1585 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1586 {
1587 if (yyy0->yyrule == yyy1->yyrule)
1588 {
1589 yyGLRState *yys0, *yys1;
1590 int yyn;
1591 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1592 yyn = yyrhsLength (yyy0->yyrule);
1593 yyn > 0;
1594 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1595 if (yys0->yyposn != yys1->yyposn)
1596 return yyfalse;
1597 return yytrue;
1598 }
1599 else
1600 return yyfalse;
1601 }
1602
1603 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1604 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1605 static void
1606 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1607 {
1608 yyGLRState *yys0, *yys1;
1609 int yyn;
1610 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1611 yyn = yyrhsLength (yyy0->yyrule);
1612 yyn > 0;
1613 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1614 {
1615 if (yys0 == yys1)
1616 break;
1617 else if (yys0->yyresolved)
1618 {
1619 yys1->yyresolved = yytrue;
1620 yys1->yysemantics.yysval = yys0->yysemantics.yysval;
1621 }
1622 else if (yys1->yyresolved)
1623 {
1624 yys0->yyresolved = yytrue;
1625 yys0->yysemantics.yysval = yys1->yysemantics.yysval;
1626 }
1627 else
1628 {
1629 yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
1630 yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
1631 while (YYID (yytrue))
1632 {
1633 if (yyz1 == *yyz0p || yyz1 == YY_NULL)
1634 break;
1635 else if (*yyz0p == YY_NULL)
1636 {
1637 *yyz0p = yyz1;
1638 break;
1639 }
1640 else if (*yyz0p < yyz1)
1641 {
1642 yySemanticOption* yyz = *yyz0p;
1643 *yyz0p = yyz1;
1644 yyz1 = yyz1->yynext;
1645 (*yyz0p)->yynext = yyz;
1646 }
1647 yyz0p = &(*yyz0p)->yynext;
1648 }
1649 yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
1650 }
1651 }
1652 }
1653
1654 /** Y0 and Y1 represent two possible actions to take in a given
1655 * parsing state; return 0 if no combination is possible,
1656 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1657 static int
1658 yypreference (yySemanticOption* y0, yySemanticOption* y1)
1659 {
1660 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1661 int p0 = yydprec[r0], p1 = yydprec[r1];
1662
1663 if (p0 == p1)
1664 {
1665 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1666 return 0;
1667 else
1668 return 1;
1669 }
1670 if (p0 == 0 || p1 == 0)
1671 return 0;
1672 if (p0 < p1)
1673 return 3;
1674 if (p1 < p0)
1675 return 2;
1676 return 0;
1677 }
1678
1679 static YYRESULTTAG yyresolveValue (yyGLRState* yys,
1680 yyGLRStack* yystackp]b4_user_formals[);
1681
1682
1683 /** Resolve the previous N states starting at and including state S. If result
1684 * != yyok, some states may have been left unresolved possibly with empty
1685 * semantic option chains. Regardless of whether result = yyok, each state
1686 * has been left with consistent data so that yydestroyGLRState can be invoked
1687 * if necessary. */
1688 static YYRESULTTAG
1689 yyresolveStates (yyGLRState* yys, int yyn,
1690 yyGLRStack* yystackp]b4_user_formals[)
1691 {
1692 if (0 < yyn)
1693 {
1694 YYASSERT (yys->yypred);
1695 YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
1696 if (! yys->yyresolved)
1697 YYCHK (yyresolveValue (yys, yystackp]b4_user_args[));
1698 }
1699 return yyok;
1700 }
1701
1702 /** Resolve the states for the RHS of OPT, perform its user action, and return
1703 * the semantic value and location. Regardless of whether result = yyok, all
1704 * RHS states have been destroyed (assuming the user action destroys all RHS
1705 * semantic values if invoked). */
1706 static YYRESULTTAG
1707 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
1708 YYSTYPE* yyvalp]b4_locuser_formals[)
1709 {
1710 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1711 int yynrhs = yyrhsLength (yyopt->yyrule);
1712 YYRESULTTAG yyflag =
1713 yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
1714 if (yyflag != yyok)
1715 {
1716 yyGLRState *yys;
1717 for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
1718 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
1719 return yyflag;
1720 }
1721
1722 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[
1723 if (yynrhs == 0)
1724 /* Set default location. */
1725 yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
1726 {
1727 int yychar_current = yychar;
1728 YYSTYPE yylval_current = yylval;]b4_locations_if([
1729 YYLTYPE yylloc_current = yylloc;])[
1730 yychar = yyopt->yyrawchar;
1731 yylval = yyopt->yyval;]b4_locations_if([
1732 yylloc = yyopt->yyloc;])[
1733 yyflag = yyuserAction (yyopt->yyrule, yynrhs,
1734 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1735 yystackp, yyvalp]b4_locuser_args[);
1736 yychar = yychar_current;
1737 yylval = yylval_current;]b4_locations_if([
1738 yylloc = yylloc_current;])[
1739 }
1740 return yyflag;
1741 }
1742
1743 #if YYDEBUG
1744 static void
1745 yyreportTree (yySemanticOption* yyx, int yyindent)
1746 {
1747 int yynrhs = yyrhsLength (yyx->yyrule);
1748 int yyi;
1749 yyGLRState* yys;
1750 yyGLRState* yystates[1 + YYMAXRHS];
1751 yyGLRState yyleftmost_state;
1752
1753 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1754 yystates[yyi] = yys;
1755 if (yys == YY_NULL)
1756 {
1757 yyleftmost_state.yyposn = 0;
1758 yystates[0] = &yyleftmost_state;
1759 }
1760 else
1761 yystates[0] = yys;
1762
1763 if (yyx->yystate->yyposn < yys->yyposn + 1)
1764 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1765 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1766 yyx->yyrule - 1);
1767 else
1768 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1769 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1770 yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
1771 (unsigned long int) yyx->yystate->yyposn);
1772 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1773 {
1774 if (yystates[yyi]->yyresolved)
1775 {
1776 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1777 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1778 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
1779 else
1780 YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
1781 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1782 (unsigned long int) (yystates[yyi - 1]->yyposn + 1),
1783 (unsigned long int) yystates[yyi]->yyposn);
1784 }
1785 else
1786 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1787 }
1788 }
1789 #endif
1790
1791 /*ARGSUSED*/ static YYRESULTTAG
1792 yyreportAmbiguity (yySemanticOption* yyx0,
1793 yySemanticOption* yyx1]b4_pure_formals[)
1794 {
1795 YYUSE (yyx0);
1796 YYUSE (yyx1);
1797
1798 #if YYDEBUG
1799 YYFPRINTF (stderr, "Ambiguity detected.\n");
1800 YYFPRINTF (stderr, "Option 1,\n");
1801 yyreportTree (yyx0, 2);
1802 YYFPRINTF (stderr, "\nOption 2,\n");
1803 yyreportTree (yyx1, 2);
1804 YYFPRINTF (stderr, "\n");
1805 #endif
1806
1807 yyerror (]b4_yyerror_args[YY_("syntax is ambiguous"));
1808 return yyabort;
1809 }]b4_locations_if([[
1810
1811 /** Starting at and including state S1, resolve the location for each of the
1812 * previous N1 states that is unresolved. The first semantic option of a state
1813 * is always chosen. */
1814 static void
1815 yyresolveLocations (yyGLRState* yys1, int yyn1,
1816 yyGLRStack *yystackp]b4_user_formals[)
1817 {
1818 if (0 < yyn1)
1819 {
1820 yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
1821 if (!yys1->yyresolved)
1822 {
1823 yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
1824 int yynrhs;
1825 yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
1826 YYASSERT (yyoption != YY_NULL);
1827 yynrhs = yyrhsLength (yyoption->yyrule);
1828 if (yynrhs > 0)
1829 {
1830 yyGLRState *yys;
1831 int yyn;
1832 yyresolveLocations (yyoption->yystate, yynrhs,
1833 yystackp]b4_user_args[);
1834 for (yys = yyoption->yystate, yyn = yynrhs;
1835 yyn > 0;
1836 yys = yys->yypred, yyn -= 1)
1837 yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
1838 }
1839 else
1840 {
1841 /* Both yyresolveAction and yyresolveLocations traverse the GSS
1842 in reverse rightmost order. It is only necessary to invoke
1843 yyresolveLocations on a subforest for which yyresolveAction
1844 would have been invoked next had an ambiguity not been
1845 detected. Thus the location of the previous state (but not
1846 necessarily the previous state itself) is guaranteed to be
1847 resolved already. */
1848 yyGLRState *yyprevious = yyoption->yystate;
1849 yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
1850 }
1851 {
1852 int yychar_current = yychar;
1853 YYSTYPE yylval_current = yylval;
1854 YYLTYPE yylloc_current = yylloc;
1855 yychar = yyoption->yyrawchar;
1856 yylval = yyoption->yyval;
1857 yylloc = yyoption->yyloc;
1858 YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
1859 yychar = yychar_current;
1860 yylval = yylval_current;
1861 yylloc = yylloc_current;
1862 }
1863 }
1864 }
1865 }]])[
1866
1867 /** Resolve the ambiguity represented in state S, perform the indicated
1868 * actions, and set the semantic value of S. If result != yyok, the chain of
1869 * semantic options in S has been cleared instead or it has been left
1870 * unmodified except that redundant options may have been removed. Regardless
1871 * of whether result = yyok, S has been left with consistent data so that
1872 * yydestroyGLRState can be invoked if necessary. */
1873 static YYRESULTTAG
1874 yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
1875 {
1876 yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
1877 yySemanticOption* yybest = yyoptionList;
1878 yySemanticOption** yypp;
1879 yybool yymerge = yyfalse;
1880 YYSTYPE yysval;
1881 YYRESULTTAG yyflag;]b4_locations_if([
1882 YYLTYPE *yylocp = &yys->yyloc;])[
1883
1884 for (yypp = &yyoptionList->yynext; *yypp != YY_NULL; )
1885 {
1886 yySemanticOption* yyp = *yypp;
1887
1888 if (yyidenticalOptions (yybest, yyp))
1889 {
1890 yymergeOptionSets (yybest, yyp);
1891 *yypp = yyp->yynext;
1892 }
1893 else
1894 {
1895 switch (yypreference (yybest, yyp))
1896 {
1897 case 0:]b4_locations_if([[
1898 yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[
1899 return yyreportAmbiguity (yybest, yyp]b4_pure_args[);
1900 break;
1901 case 1:
1902 yymerge = yytrue;
1903 break;
1904 case 2:
1905 break;
1906 case 3:
1907 yybest = yyp;
1908 yymerge = yyfalse;
1909 break;
1910 default:
1911 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1912 but some compilers complain if the default case is
1913 omitted. */
1914 break;
1915 }
1916 yypp = &yyp->yynext;
1917 }
1918 }
1919
1920 if (yymerge)
1921 {
1922 yySemanticOption* yyp;
1923 int yyprec = yydprec[yybest->yyrule];
1924 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[);
1925 if (yyflag == yyok)
1926 for (yyp = yybest->yynext; yyp != YY_NULL; yyp = yyp->yynext)
1927 {
1928 if (yyprec == yydprec[yyp->yyrule])
1929 {
1930 YYSTYPE yysval_other;]b4_locations_if([
1931 YYLTYPE yydummy;])[
1932 yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[);
1933 if (yyflag != yyok)
1934 {
1935 yydestruct ("Cleanup: discarding incompletely merged value for",
1936 yystos[yys->yylrState],
1937 &yysval]b4_locuser_args[);
1938 break;
1939 }
1940 yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
1941 }
1942 }
1943 }
1944 else
1945 yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[);
1946
1947 if (yyflag == yyok)
1948 {
1949 yys->yyresolved = yytrue;
1950 yys->yysemantics.yysval = yysval;
1951 }
1952 else
1953 yys->yysemantics.yyfirstVal = YY_NULL;
1954 return yyflag;
1955 }
1956
1957 static YYRESULTTAG
1958 yyresolveStack (yyGLRStack* yystackp]b4_user_formals[)
1959 {
1960 if (yystackp->yysplitPoint != YY_NULL)
1961 {
1962 yyGLRState* yys;
1963 int yyn;
1964
1965 for (yyn = 0, yys = yystackp->yytops.yystates[0];
1966 yys != yystackp->yysplitPoint;
1967 yys = yys->yypred, yyn += 1)
1968 continue;
1969 YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
1970 ]b4_user_args[));
1971 }
1972 return yyok;
1973 }
1974
1975 static void
1976 yycompressStack (yyGLRStack* yystackp)
1977 {
1978 yyGLRState* yyp, *yyq, *yyr;
1979
1980 if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULL)
1981 return;
1982
1983 for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULL;
1984 yyp != yystackp->yysplitPoint;
1985 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1986 yyp->yypred = yyr;
1987
1988 yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
1989 yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
1990 yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
1991 yystackp->yysplitPoint = YY_NULL;
1992 yystackp->yylastDeleted = YY_NULL;
1993
1994 while (yyr != YY_NULL)
1995 {
1996 yystackp->yynextFree->yystate = *yyr;
1997 yyr = yyr->yypred;
1998 yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
1999 yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
2000 yystackp->yynextFree += 1;
2001 yystackp->yyspaceLeft -= 1;
2002 }
2003 }
2004
2005 static YYRESULTTAG
2006 yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
2007 size_t yyposn]b4_pure_formals[)
2008 {
2009 int yyaction;
2010 const short int* yyconflicts;
2011 yyRuleNum yyrule;
2012
2013 while (yystackp->yytops.yystates[yyk] != YY_NULL)
2014 {
2015 yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
2016 YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
2017 (unsigned long int) yyk, yystate));
2018
2019 YYASSERT (yystate != YYFINAL);
2020
2021 if (yyisDefaultedState (yystate))
2022 {
2023 yyrule = yydefaultAction (yystate);
2024 if (yyrule == 0)
2025 {
2026 YYDPRINTF ((stderr, "Stack %lu dies.\n",
2027 (unsigned long int) yyk));
2028 yymarkStackDeleted (yystackp, yyk);
2029 return yyok;
2030 }
2031 YYCHK (yyglrReduce (yystackp, yyk, yyrule, yyfalse]b4_user_args[));
2032 }
2033 else
2034 {
2035 yySymbol yytoken;
2036 yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
2037 if (yychar == YYEMPTY)
2038 {
2039 YYDPRINTF ((stderr, "Reading a token: "));
2040 yychar = YYLEX;
2041 }
2042
2043 if (yychar <= YYEOF)
2044 {
2045 yychar = yytoken = YYEOF;
2046 YYDPRINTF ((stderr, "Now at end of input.\n"));
2047 }
2048 else
2049 {
2050 yytoken = YYTRANSLATE (yychar);
2051 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2052 }
2053
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 return;
2091 #if ! YYERROR_VERBOSE
2092 yyerror (]b4_lyyerror_args[YY_("syntax error"));
2093 #else
2094 yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2095 size_t yysize0 = yytnamerr (YY_NULL, yytokenName (yytoken));
2096 size_t yysize = yysize0;
2097 size_t yysize1;
2098 yybool yysize_overflow = yyfalse;
2099 char* yymsg = YY_NULL;
2100 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
2101 /* Internationalized format string. */
2102 const char *yyformat = YY_NULL;
2103 /* Arguments of yyformat. */
2104 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
2105 /* Number of reported tokens (one for the "unexpected", one per
2106 "expected"). */
2107 int yycount = 0;
2108
2109 /* There are many possibilities here to consider:
2110 - If this state is a consistent state with a default action, then
2111 the only way this function was invoked is if the default action
2112 is an error action. In that case, don't check for expected
2113 tokens because there are none.
2114 - The only way there can be no lookahead present (in yychar) is if
2115 this state is a consistent state with a default action. Thus,
2116 detecting the absence of a lookahead is sufficient to determine
2117 that there is no unexpected or expected token to report. In that
2118 case, just report a simple "syntax error".
2119 - Don't assume there isn't a lookahead just because this state is a
2120 consistent state with a default action. There might have been a
2121 previous inconsistent state, consistent state with a non-default
2122 action, or user semantic action that manipulated yychar.
2123 - Of course, the expected token list depends on states to have
2124 correct lookahead information, and it depends on the parser not
2125 to perform extra reductions after fetching a lookahead from the
2126 scanner and before detecting a syntax error. Thus, state merging
2127 (from LALR or IELR) and default reductions corrupt the expected
2128 token list. However, the list is correct for canonical LR with
2129 one exception: it will still contain any token that will not be
2130 accepted due to an error action in a later state.
2131 */
2132 if (yytoken != YYEMPTY)
2133 {
2134 int yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
2135 yyarg[yycount++] = yytokenName (yytoken);
2136 if (!yypact_value_is_default (yyn))
2137 {
2138 /* Start YYX at -YYN if negative to avoid negative indexes in
2139 YYCHECK. In other words, skip the first -YYN actions for this
2140 state because they are default actions. */
2141 int yyxbegin = yyn < 0 ? -yyn : 0;
2142 /* Stay within bounds of both yycheck and yytname. */
2143 int yychecklim = YYLAST - yyn + 1;
2144 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
2145 int yyx;
2146 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
2147 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
2148 && !yytable_value_is_error (yytable[yyx + yyn]))
2149 {
2150 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
2151 {
2152 yycount = 1;
2153 yysize = yysize0;
2154 break;
2155 }
2156 yyarg[yycount++] = yytokenName (yyx);
2157 yysize1 = yysize + yytnamerr (YY_NULL, yytokenName (yyx));
2158 yysize_overflow |= yysize1 < yysize;
2159 yysize = yysize1;
2160 }
2161 }
2162 }
2163
2164 switch (yycount)
2165 {
2166 #define YYCASE_(N, S) \
2167 case N: \
2168 yyformat = S; \
2169 break
2170 YYCASE_(0, YY_("syntax error"));
2171 YYCASE_(1, YY_("syntax error, unexpected %s"));
2172 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
2173 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
2174 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
2175 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
2176 #undef YYCASE_
2177 }
2178
2179 yysize1 = yysize + strlen (yyformat);
2180 yysize_overflow |= yysize1 < yysize;
2181 yysize = yysize1;
2182
2183 if (!yysize_overflow)
2184 yymsg = (char *) YYMALLOC (yysize);
2185
2186 if (yymsg)
2187 {
2188 char *yyp = yymsg;
2189 int yyi = 0;
2190 while ((*yyp = *yyformat))
2191 {
2192 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
2193 {
2194 yyp += yytnamerr (yyp, yyarg[yyi++]);
2195 yyformat += 2;
2196 }
2197 else
2198 {
2199 yyp++;
2200 yyformat++;
2201 }
2202 }
2203 yyerror (]b4_lyyerror_args[yymsg);
2204 YYFREE (yymsg);
2205 }
2206 else
2207 {
2208 yyerror (]b4_lyyerror_args[YY_("syntax error"));
2209 yyMemoryExhausted (yystackp);
2210 }
2211 #endif /* YYERROR_VERBOSE */
2212 yynerrs += 1;
2213 }
2214
2215 /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
2216 yylval, and yylloc are the syntactic category, semantic value, and location
2217 of the lookahead. */
2218 /*ARGSUSED*/ static void
2219 yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
2220 {
2221 size_t yyk;
2222 int yyj;
2223
2224 if (yystackp->yyerrState == 3)
2225 /* We just shifted the error token and (perhaps) took some
2226 reductions. Skip tokens until we can proceed. */
2227 while (YYID (yytrue))
2228 {
2229 yySymbol yytoken;
2230 if (yychar == YYEOF)
2231 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
2232 if (yychar != YYEMPTY)
2233 {]b4_locations_if([[
2234 /* We throw away the lookahead, but the error range
2235 of the shifted error token must take it into account. */
2236 yyGLRState *yys = yystackp->yytops.yystates[0];
2237 yyGLRStackItem yyerror_range[3];
2238 yyerror_range[1].yystate.yyloc = yys->yyloc;
2239 yyerror_range[2].yystate.yyloc = yylloc;
2240 YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
2241 yytoken = YYTRANSLATE (yychar);
2242 yydestruct ("Error: discarding",
2243 yytoken, &yylval]b4_locuser_args([&yylloc])[);
2244 }
2245 YYDPRINTF ((stderr, "Reading a token: "));
2246 yychar = YYLEX;
2247 if (yychar <= YYEOF)
2248 {
2249 yychar = yytoken = YYEOF;
2250 YYDPRINTF ((stderr, "Now at end of input.\n"));
2251 }
2252 else
2253 {
2254 yytoken = YYTRANSLATE (yychar);
2255 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2256 }
2257 yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
2258 if (yypact_value_is_default (yyj))
2259 return;
2260 yyj += yytoken;
2261 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
2262 {
2263 if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
2264 return;
2265 }
2266 else if (! yytable_value_is_error (yytable[yyj]))
2267 return;
2268 }
2269
2270 /* Reduce to one stack. */
2271 for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
2272 if (yystackp->yytops.yystates[yyk] != YY_NULL)
2273 break;
2274 if (yyk >= yystackp->yytops.yysize)
2275 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
2276 for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
2277 yymarkStackDeleted (yystackp, yyk);
2278 yyremoveDeletes (yystackp);
2279 yycompressStack (yystackp);
2280
2281 /* Now pop stack until we find a state that shifts the error token. */
2282 yystackp->yyerrState = 3;
2283 while (yystackp->yytops.yystates[0] != YY_NULL)
2284 {
2285 yyGLRState *yys = yystackp->yytops.yystates[0];
2286 yyj = yypact[yys->yylrState];
2287 if (! yypact_value_is_default (yyj))
2288 {
2289 yyj += YYTERROR;
2290 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
2291 && yyisShiftAction (yytable[yyj]))
2292 {
2293 /* Shift the error token. */]b4_locations_if([[
2294 /* First adjust its location.*/
2295 YYLTYPE yyerrloc;
2296 yystackp->yyerror_range[2].yystate.yyloc = yylloc;
2297 YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
2298 YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
2299 &yylval, &yyerrloc);
2300 yyglrShift (yystackp, 0, yytable[yyj],
2301 yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
2302 yys = yystackp->yytops.yystates[0];
2303 break;
2304 }
2305 }]b4_locations_if([[
2306 yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
2307 if (yys->yypred != YY_NULL)
2308 yydestroyGLRState ("Error: popping", yys]b4_user_args[);
2309 yystackp->yytops.yystates[0] = yys->yypred;
2310 yystackp->yynextFree -= 1;
2311 yystackp->yyspaceLeft += 1;
2312 }
2313 if (yystackp->yytops.yystates[0] == YY_NULL)
2314 yyFail (yystackp][]b4_lpure_args[, YY_NULL);
2315 }
2316
2317 #define YYCHK1(YYE) \
2318 do { \
2319 switch (YYE) { \
2320 case yyok: \
2321 break; \
2322 case yyabort: \
2323 goto yyabortlab; \
2324 case yyaccept: \
2325 goto yyacceptlab; \
2326 case yyerr: \
2327 goto yyuser_error; \
2328 default: \
2329 goto yybuglab; \
2330 } \
2331 } while (YYID (0))
2332
2333
2334 /*----------.
2335 | yyparse. |
2336 `----------*/
2337
2338 ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[
2339 {
2340 int yyresult;
2341 yyGLRStack yystack;
2342 yyGLRStack* const yystackp = &yystack;
2343 size_t yyposn;
2344
2345 YYDPRINTF ((stderr, "Starting parse\n"));
2346
2347 yychar = YYEMPTY;
2348 yylval = yyval_default;
2349 ]b4_locations_if([
2350 #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
2351 yylloc.first_line = yylloc.last_line = ]b4_location_initial_line[;
2352 yylloc.first_column = yylloc.last_column = ]b4_location_initial_column[;
2353 #endif
2354 ])
2355 m4_ifdef([b4_initial_action], [
2356 m4_pushdef([b4_at_dollar], [yylloc])dnl
2357 m4_pushdef([b4_dollar_dollar], [yylval])dnl
2358 /* User initialization code. */
2359 b4_user_initial_action
2360 m4_popdef([b4_dollar_dollar])dnl
2361 m4_popdef([b4_at_dollar])])dnl
2362 [
2363 if (! yyinitGLRStack (yystackp, YYINITDEPTH))
2364 goto yyexhaustedlab;
2365 switch (YYSETJMP (yystack.yyexception_buffer))
2366 {
2367 case 0: break;
2368 case 1: goto yyabortlab;
2369 case 2: goto yyexhaustedlab;
2370 default: goto yybuglab;
2371 }
2372 yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[);
2373 yyposn = 0;
2374
2375 while (YYID (yytrue))
2376 {
2377 /* For efficiency, we have two loops, the first of which is
2378 specialized to deterministic operation (single stack, no
2379 potential ambiguity). */
2380 /* Standard mode */
2381 while (YYID (yytrue))
2382 {
2383 yyRuleNum yyrule;
2384 int yyaction;
2385 const short int* yyconflicts;
2386
2387 yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
2388 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2389 if (yystate == YYFINAL)
2390 goto yyacceptlab;
2391 if (yyisDefaultedState (yystate))
2392 {
2393 yyrule = yydefaultAction (yystate);
2394 if (yyrule == 0)
2395 {
2396 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2397 yyreportSyntaxError (&yystack]b4_user_args[);
2398 goto yyuser_error;
2399 }
2400 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
2401 }
2402 else
2403 {
2404 yySymbol yytoken;
2405 if (yychar == YYEMPTY)
2406 {
2407 YYDPRINTF ((stderr, "Reading a token: "));
2408 yychar = YYLEX;
2409 }
2410
2411 if (yychar <= YYEOF)
2412 {
2413 yychar = yytoken = YYEOF;
2414 YYDPRINTF ((stderr, "Now at end of input.\n"));
2415 }
2416 else
2417 {
2418 yytoken = YYTRANSLATE (yychar);
2419 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2420 }
2421
2422 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
2423 if (*yyconflicts != 0)
2424 break;
2425 if (yyisShiftAction (yyaction))
2426 {
2427 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2428 yychar = YYEMPTY;
2429 yyposn += 1;
2430 yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[);
2431 if (0 < yystack.yyerrState)
2432 yystack.yyerrState -= 1;
2433 }
2434 else if (yyisErrorAction (yyaction))
2435 {
2436 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2437 yyreportSyntaxError (&yystack]b4_user_args[);
2438 goto yyuser_error;
2439 }
2440 else
2441 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));
2442 }
2443 }
2444
2445 while (YYID (yytrue))
2446 {
2447 yySymbol yytoken_to_shift;
2448 size_t yys;
2449
2450 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2451 yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
2452
2453 /* yyprocessOneStack returns one of three things:
2454
2455 - An error flag. If the caller is yyprocessOneStack, it
2456 immediately returns as well. When the caller is finally
2457 yyparse, it jumps to an error label via YYCHK1.
2458
2459 - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
2460 (&yystack, yys), which sets the top state of yys to NULL. Thus,
2461 yyparse's following invocation of yyremoveDeletes will remove
2462 the stack.
2463
2464 - yyok, when ready to shift a token.
2465
2466 Except in the first case, yyparse will invoke yyremoveDeletes and
2467 then shift the next token onto all remaining stacks. This
2468 synchronization of the shift (that is, after all preceding
2469 reductions on all stacks) helps prevent double destructor calls
2470 on yylval in the event of memory exhaustion. */
2471
2472 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2473 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
2474 yyremoveDeletes (&yystack);
2475 if (yystack.yytops.yysize == 0)
2476 {
2477 yyundeleteLastStack (&yystack);
2478 if (yystack.yytops.yysize == 0)
2479 yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
2480 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2481 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2482 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
2483 yyreportSyntaxError (&yystack]b4_user_args[);
2484 goto yyuser_error;
2485 }
2486
2487 /* If any yyglrShift call fails, it will fail after shifting. Thus,
2488 a copy of yylval will already be on stack 0 in the event of a
2489 failure in the following loop. Thus, yychar is set to YYEMPTY
2490 before the loop to make sure the user destructor for yylval isn't
2491 called twice. */
2492 yytoken_to_shift = YYTRANSLATE (yychar);
2493 yychar = YYEMPTY;
2494 yyposn += 1;
2495 for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
2496 {
2497 int yyaction;
2498 const short int* yyconflicts;
2499 yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
2500 yygetLRActions (yystate, yytoken_to_shift, &yyaction,
2501 &yyconflicts);
2502 /* Note that yyconflicts were handled by yyprocessOneStack. */
2503 YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
2504 YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
2505 yyglrShift (&yystack, yys, yyaction, yyposn,
2506 &yylval]b4_locations_if([, &yylloc])[);
2507 YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
2508 (unsigned long int) yys,
2509 yystack.yytops.yystates[yys]->yylrState));
2510 }
2511
2512 if (yystack.yytops.yysize == 1)
2513 {
2514 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2515 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2516 yycompressStack (&yystack);
2517 break;
2518 }
2519 }
2520 continue;
2521 yyuser_error:
2522 yyrecoverSyntaxError (&yystack]b4_user_args[);
2523 yyposn = yystack.yytops.yystates[0]->yyposn;
2524 }
2525
2526 yyacceptlab:
2527 yyresult = 0;
2528 goto yyreturn;
2529
2530 yybuglab:
2531 YYASSERT (yyfalse);
2532 goto yyabortlab;
2533
2534 yyabortlab:
2535 yyresult = 1;
2536 goto yyreturn;
2537
2538 yyexhaustedlab:
2539 yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
2540 yyresult = 2;
2541 goto yyreturn;
2542
2543 yyreturn:
2544 if (yychar != YYEMPTY)
2545 yydestruct ("Cleanup: discarding lookahead",
2546 YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[);
2547
2548 /* If the stack is well-formed, pop the stack until it is empty,
2549 destroying its entries as we go. But free the stack regardless
2550 of whether it is well-formed. */
2551 if (yystack.yyitems)
2552 {
2553 yyGLRState** yystates = yystack.yytops.yystates;
2554 if (yystates)
2555 {
2556 size_t yysize = yystack.yytops.yysize;
2557 size_t yyk;
2558 for (yyk = 0; yyk < yysize; yyk += 1)
2559 if (yystates[yyk])
2560 {
2561 while (yystates[yyk])
2562 {
2563 yyGLRState *yys = yystates[yyk];
2564 ]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
2565 )[ if (yys->yypred != YY_NULL)
2566 yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
2567 yystates[yyk] = yys->yypred;
2568 yystack.yynextFree -= 1;
2569 yystack.yyspaceLeft += 1;
2570 }
2571 break;
2572 }
2573 }
2574 yyfreeGLRStack (&yystack);
2575 }
2576
2577 /* Make sure YYID is used. */
2578 return YYID (yyresult);
2579 }
2580
2581 /* DEBUGGING ONLY */
2582 #if YYDEBUG
2583 static void yypstack (yyGLRStack* yystackp, size_t yyk)
2584 __attribute__ ((__unused__));
2585 static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
2586
2587 static void
2588 yy_yypstack (yyGLRState* yys)
2589 {
2590 if (yys->yypred)
2591 {
2592 yy_yypstack (yys->yypred);
2593 YYFPRINTF (stderr, " -> ");
2594 }
2595 YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
2596 (unsigned long int) yys->yyposn);
2597 }
2598
2599 static void
2600 yypstates (yyGLRState* yyst)
2601 {
2602 if (yyst == YY_NULL)
2603 YYFPRINTF (stderr, "<null>");
2604 else
2605 yy_yypstack (yyst);
2606 YYFPRINTF (stderr, "\n");
2607 }
2608
2609 static void
2610 yypstack (yyGLRStack* yystackp, size_t yyk)
2611 {
2612 yypstates (yystackp->yytops.yystates[yyk]);
2613 }
2614
2615 #define YYINDEX(YYX) \
2616 ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
2617
2618
2619 static void
2620 yypdumpstack (yyGLRStack* yystackp)
2621 {
2622 yyGLRStackItem* yyp;
2623 size_t yyi;
2624 for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
2625 {
2626 YYFPRINTF (stderr, "%3lu. ",
2627 (unsigned long int) (yyp - yystackp->yyitems));
2628 if (*(yybool *) yyp)
2629 {
2630 YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2631 yyp->yystate.yyresolved, yyp->yystate.yylrState,
2632 (unsigned long int) yyp->yystate.yyposn,
2633 (long int) YYINDEX (yyp->yystate.yypred));
2634 if (! yyp->yystate.yyresolved)
2635 YYFPRINTF (stderr, ", firstVal: %ld",
2636 (long int) YYINDEX (yyp->yystate
2637 .yysemantics.yyfirstVal));
2638 }
2639 else
2640 {
2641 YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
2642 yyp->yyoption.yyrule - 1,
2643 (long int) YYINDEX (yyp->yyoption.yystate),
2644 (long int) YYINDEX (yyp->yyoption.yynext));
2645 }
2646 YYFPRINTF (stderr, "\n");
2647 }
2648 YYFPRINTF (stderr, "Tops:");
2649 for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
2650 YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
2651 (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
2652 YYFPRINTF (stderr, "\n");
2653 }
2654 #endif
2655 ]
2656
2657 b4_epilogue
2658 dnl
2659 dnl glr.cc produces its own header.
2660 dnl
2661 m4_if(b4_skeleton, ["glr.c"],
2662 [b4_defines_if(
2663 [@output(b4_spec_defines_file@)@
2664 b4_copyright([Skeleton interface for Bison GLR parsers in C],
2665 [2002-2012])
2666
2667 b4_shared_declarations
2668
2669 b4_pure_if([],
2670 [[extern YYSTYPE ]b4_prefix[lval;]])
2671
2672 b4_locations_if([b4_pure_if([],
2673 [extern YYLTYPE ]b4_prefix[lloc;])
2674 ])
2675 ])])
2676 m4_divert_pop(0)