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