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