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