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