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