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