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