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