]> git.saurik.com Git - bison.git/blob - data/glr.c
(yyexpandGLRStack, yyaddDeferredAction, yyexpandGLRStack):
[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 /* YYTNME[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 #endif /* !YYERROR_VERBOSE */
604
605 /** State numbers, as in LALR(1) machine */
606 typedef int yyStateNum;
607
608 /** Rule numbers, as in LALR(1) machine */
609 typedef int yyRuleNum;
610
611 /** Grammar symbol */
612 typedef short int yySymbol;
613
614 /** Item references, as in LALR(1) machine */
615 typedef short int yyItemNum;
616
617 typedef struct yyGLRState yyGLRState;
618 typedef struct yySemanticOption yySemanticOption;
619 typedef union yyGLRStackItem yyGLRStackItem;
620 typedef struct yyGLRStack yyGLRStack;
621 typedef struct yyGLRStateSet yyGLRStateSet;
622
623 struct yyGLRState {
624 /** Type tag: always true. */
625 yybool yyisState;
626 /** Type tag for yysemantics. If true, yysval applies, otherwise
627 * yyfirstVal applies. */
628 yybool yyresolved;
629 /** Number of corresponding LALR(1) machine state. */
630 yyStateNum yylrState;
631 /** Preceding state in this stack */
632 yyGLRState* yypred;
633 /** Source position of the first token produced by my symbol */
634 size_t yyposn;
635 union {
636 /** First in a chain of alternative reductions producing the
637 * non-terminal corresponding to this state, threaded through
638 * yynext. */
639 yySemanticOption* yyfirstVal;
640 /** Semantic value for this state. */
641 YYSTYPE yysval;
642 } yysemantics;
643 /** Source location for this state. */
644 YYLTYPE yyloc;
645 };
646
647 struct yyGLRStateSet {
648 yyGLRState** yystates;
649 size_t yysize, yycapacity;
650 };
651
652 struct yySemanticOption {
653 /** Type tag: always false. */
654 yybool yyisState;
655 /** Rule number for this reduction */
656 yyRuleNum yyrule;
657 /** The last RHS state in the list of states to be reduced. */
658 yyGLRState* yystate;
659 /** Next sibling in chain of options. To facilitate merging,
660 * options are chained in decreasing order by address. */
661 yySemanticOption* yynext;
662 };
663
664 /** Type of the items in the GLR stack. The yyisState field
665 * indicates which item of the union is valid. */
666 union yyGLRStackItem {
667 yyGLRState yystate;
668 yySemanticOption yyoption;
669 };
670
671 struct yyGLRStack {
672 int yyerrState;
673 ]b4_location_if([[ /* To compute the location of the error token. */
674 yyGLRStackItem yyerror_range[3];]])[
675 ]b4_pure_if(
676 [
677 int yyerrcnt;
678 int yyrawchar;
679 ])[
680 yySymbol* yytokenp;
681 jmp_buf yyexception_buffer;
682 yyGLRStackItem* yyitems;
683 yyGLRStackItem* yynextFree;
684 size_t yyspaceLeft;
685 yyGLRState* yysplitPoint;
686 yyGLRState* yylastDeleted;
687 yyGLRStateSet yytops;
688 };
689
690 static void yyexpandGLRStack (yyGLRStack* yystack);
691
692 static void
693 yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg)
694 {
695 if (yymsg != NULL)
696 yyerror (]b4_yyerror_args[yymsg);
697 longjmp (yystack->yyexception_buffer, 1);
698 }
699
700 static void
701 yyMemoryExhausted (yyGLRStack* yystack)
702 {
703 longjmp (yystack->yyexception_buffer, 2);
704 }
705
706 #if YYDEBUG || YYERROR_VERBOSE
707 /** A printable representation of TOKEN. */
708 static inline const char*
709 yytokenName (yySymbol yytoken)
710 {
711 if (yytoken == YYEMPTY)
712 return "";
713
714 return yytname[yytoken];
715 }
716 #endif
717
718 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
719 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
720 * containing the pointer to the next state in the chain. Assumes
721 * YYLOW1 < YYLOW0. */
722 static void yyfillin (yyGLRStackItem *, int, int) ATTRIBUTE_UNUSED;
723 static void
724 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
725 {
726 yyGLRState* s;
727 int i;
728 s = yyvsp[yylow0].yystate.yypred;
729 for (i = yylow0-1; i >= yylow1; i -= 1)
730 {
731 YYASSERT (s->yyresolved);
732 yyvsp[i].yystate.yyresolved = yytrue;
733 yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
734 yyvsp[i].yystate.yyloc = s->yyloc;
735 s = yyvsp[i].yystate.yypred = s->yypred;
736 }
737 }
738
739 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
740 YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
741 For convenience, always return YYLOW1. */
742 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
743 ATTRIBUTE_UNUSED;
744 static inline int
745 yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
746 {
747 if (!yynormal && yylow1 < *yylow)
748 {
749 yyfillin (yyvsp, *yylow, yylow1);
750 *yylow = yylow1;
751 }
752 return yylow1;
753 }
754
755 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
756 * and top stack item YYVSP. YYLVALP points to place to put semantic
757 * value ($$), and yylocp points to place for location information
758 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
759 * yyerr for YYERROR, yyabort for YYABORT. */
760 static YYRESULTTAG
761 yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
762 YYSTYPE* yyvalp,
763 YYLTYPE* YYOPTIONAL_LOC (yylocp),
764 yyGLRStack* yystack
765 ]b4_user_formals[)
766 {
767 yybool yynormal ATTRIBUTE_UNUSED = (yystack->yysplitPoint == NULL);
768 int yylow;
769
770 # undef yyerrok
771 # define yyerrok (yystack->yyerrState = 0)
772 # undef YYACCEPT
773 # define YYACCEPT return yyaccept
774 # undef YYABORT
775 # define YYABORT return yyabort
776 # undef YYERROR
777 # define YYERROR return yyerrok, yyerr
778 # undef YYRECOVERING
779 # define YYRECOVERING (yystack->yyerrState != 0)
780 # undef yyclearin
781 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
782 # undef YYFILL
783 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
784 # undef YYBACKUP
785 # define YYBACKUP(Token, Value) \
786 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
787 yyerrok, yyerr
788
789 yylow = 1;
790 if (yyrhslen == 0)
791 *yyvalp = yyval_default;
792 else
793 *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
794 YYLLOC_DEFAULT (*yylocp, yyvsp - yyrhslen, yyrhslen);
795 ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = *yylocp;
796 ]])
797 switch (yyn)
798 {
799 b4_actions
800 default: break;
801 }
802
803 return yyok;
804 # undef yyerrok
805 # undef YYABORT
806 # undef YYACCEPT
807 # undef YYERROR
808 # undef YYBACKUP
809 # undef yyclearin
810 # undef YYRECOVERING
811 /* Line __line__ of glr.c. */
812 b4_syncline([@oline@], [@ofile@])
813 }
814 \f
815
816 static void
817 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
818 {
819 /* `Use' the arguments. */
820 (void) yy0;
821 (void) yy1;
822
823 switch (yyn)
824 {
825 b4_mergers
826 default: break;
827 }
828 }
829 [
830 /* Bison grammar-table manipulation. */
831
832 ]b4_yydestruct_generate([b4_c_ansi_function_def])[
833
834 /** Number of symbols composing the right hand side of rule #RULE. */
835 static inline int
836 yyrhsLength (yyRuleNum yyrule)
837 {
838 return yyr2[yyrule];
839 }
840
841 /** Left-hand-side symbol for rule #RULE. */
842 static inline yySymbol
843 yylhsNonterm (yyRuleNum yyrule)
844 {
845 return yyr1[yyrule];
846 }
847
848 #define yyis_pact_ninf(yystate) \
849 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
850 0,
851 ((yystate) == YYPACT_NINF))[
852
853 /** True iff LR state STATE has only a default reduction (regardless
854 * of token). */
855 static inline yybool
856 yyisDefaultedState (yyStateNum yystate)
857 {
858 return yyis_pact_ninf (yypact[yystate]);
859 }
860
861 /** The default reduction for STATE, assuming it has one. */
862 static inline yyRuleNum
863 yydefaultAction (yyStateNum yystate)
864 {
865 return yydefact[yystate];
866 }
867
868 #define yyis_table_ninf(yytable_value) \
869 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
870 0,
871 ((yytable_value) == YYTABLE_NINF))[
872
873 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
874 * Result R means
875 * R < 0: Reduce on rule -R.
876 * R = 0: Error.
877 * R > 0: Shift to state R.
878 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
879 * conflicting reductions.
880 */
881 static inline void
882 yygetLRActions (yyStateNum yystate, int yytoken,
883 int* yyaction, const short int** yyconflicts)
884 {
885 int yyindex = yypact[yystate] + yytoken;
886 if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
887 {
888 *yyaction = -yydefact[yystate];
889 *yyconflicts = yyconfl;
890 }
891 else if (! yyis_table_ninf (yytable[yyindex]))
892 {
893 *yyaction = yytable[yyindex];
894 *yyconflicts = yyconfl + yyconflp[yyindex];
895 }
896 else
897 {
898 *yyaction = 0;
899 *yyconflicts = yyconfl + yyconflp[yyindex];
900 }
901 }
902
903 static inline yyStateNum
904 yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
905 {
906 int yyr;
907 yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
908 if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
909 return yytable[yyr];
910 else
911 return yydefgoto[yylhs - YYNTOKENS];
912 }
913
914 static inline yybool
915 yyisShiftAction (int yyaction)
916 {
917 return 0 < yyaction;
918 }
919
920 static inline yybool
921 yyisErrorAction (int yyaction)
922 {
923 return yyaction == 0;
924 }
925
926 /* GLRStates */
927
928 static void
929 yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
930 yyGLRState* rhs, yyRuleNum yyrule)
931 {
932 yySemanticOption* yynewItem;
933 yynewItem = &yystack->yynextFree->yyoption;
934 yystack->yyspaceLeft -= 1;
935 yystack->yynextFree += 1;
936 yynewItem->yyisState = yyfalse;
937 yynewItem->yystate = rhs;
938 yynewItem->yyrule = yyrule;
939 yynewItem->yynext = yystate->yysemantics.yyfirstVal;
940 yystate->yysemantics.yyfirstVal = yynewItem;
941 if (yystack->yyspaceLeft < YYHEADROOM)
942 yyexpandGLRStack (yystack);
943 }
944
945 /* GLRStacks */
946
947 /** Initialize SET to a singleton set containing an empty stack. */
948 static yybool
949 yyinitStateSet (yyGLRStateSet* yyset)
950 {
951 yyset->yysize = 1;
952 yyset->yycapacity = 16;
953 yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
954 if (! yyset->yystates)
955 return yyfalse;
956 yyset->yystates[0] = NULL;
957 return yytrue;
958 }
959
960 static void yyfreeStateSet (yyGLRStateSet* yyset)
961 {
962 YYFREE (yyset->yystates);
963 }
964
965 /** Initialize STACK to a single empty stack, with total maximum
966 * capacity for all stacks of SIZE. */
967 static yybool
968 yyinitGLRStack (yyGLRStack* yystack, size_t yysize)
969 {
970 yystack->yyerrState = 0;
971 yynerrs = 0;
972 yystack->yyspaceLeft = yysize;
973 yystack->yynextFree = yystack->yyitems =
974 (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystack->yynextFree[0]);
975 yystack->yysplitPoint = NULL;
976 yystack->yylastDeleted = NULL;
977 return yyinitStateSet (&yystack->yytops) && yystack->yyitems;
978 }
979
980 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
981 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
982
983 /** If STACK is expandable, extend it. WARNING: Pointers into the
984 stack from outside should be considered invalid after this call.
985 We always expand when there are 1 or fewer items left AFTER an
986 allocation, so that we can avoid having external pointers exist
987 across an allocation. */
988 static void
989 yyexpandGLRStack (yyGLRStack* yystack)
990 {
991 #if YYSTACKEXPANDABLE
992 yyGLRStackItem* yynewItems;
993 yyGLRStackItem* yyp0, *yyp1;
994 size_t yysize, yynewSize;
995 size_t yyn;
996 yysize = yystack->yynextFree - yystack->yyitems;
997 if (YYMAXDEPTH <= yysize)
998 yyMemoryExhausted (yystack);
999 yynewSize = 2*yysize;
1000 if (YYMAXDEPTH < yynewSize)
1001 yynewSize = YYMAXDEPTH;
1002 yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
1003 if (! yynewItems)
1004 yyMemoryExhausted (yystack);
1005 for (yyp0 = yystack->yyitems, yyp1 = yynewItems, yyn = yysize;
1006 0 < yyn;
1007 yyn -= 1, yyp0 += 1, yyp1 += 1)
1008 {
1009 *yyp1 = *yyp0;
1010 if (*(yybool *) yyp0)
1011 {
1012 yyGLRState* yys0 = &yyp0->yystate;
1013 yyGLRState* yys1 = &yyp1->yystate;
1014 if (yys0->yypred != NULL)
1015 yys1->yypred =
1016 YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
1017 if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)
1018 yys1->yysemantics.yyfirstVal =
1019 YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
1020 }
1021 else
1022 {
1023 yySemanticOption* yyv0 = &yyp0->yyoption;
1024 yySemanticOption* yyv1 = &yyp1->yyoption;
1025 if (yyv0->yystate != NULL)
1026 yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
1027 if (yyv0->yynext != NULL)
1028 yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
1029 }
1030 }
1031 if (yystack->yysplitPoint != NULL)
1032 yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewItems,
1033 yystack->yysplitPoint, yystate);
1034
1035 for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1)
1036 if (yystack->yytops.yystates[yyn] != NULL)
1037 yystack->yytops.yystates[yyn] =
1038 YYRELOC (yystack->yyitems, yynewItems,
1039 yystack->yytops.yystates[yyn], yystate);
1040 YYFREE (yystack->yyitems);
1041 yystack->yyitems = yynewItems;
1042 yystack->yynextFree = yynewItems + yysize;
1043 yystack->yyspaceLeft = yynewSize - yysize;
1044
1045 #else
1046 yyMemoryExhausted (yystack);
1047 #endif
1048 }
1049
1050 static void
1051 yyfreeGLRStack (yyGLRStack* yystack)
1052 {
1053 YYFREE (yystack->yyitems);
1054 yyfreeStateSet (&yystack->yytops);
1055 }
1056
1057 /** Assuming that S is a GLRState somewhere on STACK, update the
1058 * splitpoint of STACK, if needed, so that it is at least as deep as
1059 * S. */
1060 static inline void
1061 yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys)
1062 {
1063 if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys)
1064 yystack->yysplitPoint = yys;
1065 }
1066
1067 /** Invalidate stack #K in STACK. */
1068 static inline void
1069 yymarkStackDeleted (yyGLRStack* yystack, size_t yyk)
1070 {
1071 if (yystack->yytops.yystates[yyk] != NULL)
1072 yystack->yylastDeleted = yystack->yytops.yystates[yyk];
1073 yystack->yytops.yystates[yyk] = NULL;
1074 }
1075
1076 /** Undelete the last stack that was marked as deleted. Can only be
1077 done once after a deletion, and only when all other stacks have
1078 been deleted. */
1079 static void
1080 yyundeleteLastStack (yyGLRStack* yystack)
1081 {
1082 if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0)
1083 return;
1084 yystack->yytops.yystates[0] = yystack->yylastDeleted;
1085 yystack->yytops.yysize = 1;
1086 YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
1087 yystack->yylastDeleted = NULL;
1088 }
1089
1090 static inline void
1091 yyremoveDeletes (yyGLRStack* yystack)
1092 {
1093 size_t yyi, yyj;
1094 yyi = yyj = 0;
1095 while (yyj < yystack->yytops.yysize)
1096 {
1097 if (yystack->yytops.yystates[yyi] == NULL)
1098 {
1099 if (yyi == yyj)
1100 {
1101 YYDPRINTF ((stderr, "Removing dead stacks.\n"));
1102 }
1103 yystack->yytops.yysize -= 1;
1104 }
1105 else
1106 {
1107 yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi];
1108 if (yyj != yyi)
1109 {
1110 YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
1111 (unsigned long int) yyi, (unsigned long int) yyj));
1112 }
1113 yyj += 1;
1114 }
1115 yyi += 1;
1116 }
1117 }
1118
1119 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1120 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1121 static inline void
1122 yyglrShift (yyGLRStack* yystack, size_t yyk, yyStateNum yylrState,
1123 size_t yyposn,
1124 YYSTYPE yysval, YYLTYPE* yylocp)
1125 {
1126 yyGLRStackItem* yynewItem;
1127
1128 yynewItem = yystack->yynextFree;
1129 yystack->yynextFree += 1;
1130 yystack->yyspaceLeft -= 1;
1131 yynewItem->yystate.yyisState = yytrue;
1132 yynewItem->yystate.yylrState = yylrState;
1133 yynewItem->yystate.yyposn = yyposn;
1134 yynewItem->yystate.yyresolved = yytrue;
1135 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
1136 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
1137 yynewItem->yystate.yysemantics.yysval = yysval;
1138 yynewItem->yystate.yyloc = *yylocp;
1139 if (yystack->yyspaceLeft < YYHEADROOM)
1140 yyexpandGLRStack (yystack);
1141 }
1142
1143 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1144 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1145 * semantic value of YYRHS under the action for YYRULE. */
1146 static inline void
1147 yyglrShiftDefer (yyGLRStack* yystack, size_t yyk, yyStateNum yylrState,
1148 size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule)
1149 {
1150 yyGLRStackItem* yynewItem;
1151
1152 yynewItem = yystack->yynextFree;
1153 yynewItem->yystate.yyisState = yytrue;
1154 yynewItem->yystate.yylrState = yylrState;
1155 yynewItem->yystate.yyposn = yyposn;
1156 yynewItem->yystate.yyresolved = yyfalse;
1157 yynewItem->yystate.yypred = yystack->yytops.yystates[yyk];
1158 yynewItem->yystate.yysemantics.yyfirstVal = NULL;
1159 yystack->yytops.yystates[yyk] = &yynewItem->yystate;
1160 yystack->yynextFree += 1;
1161 yystack->yyspaceLeft -= 1;
1162 yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule);
1163 }
1164
1165 /** Pop the symbols consumed by reduction #RULE from the top of stack
1166 * #K of STACK, and perform the appropriate semantic action on their
1167 * semantic values. Assumes that all ambiguities in semantic values
1168 * have been previously resolved. Set *VALP to the resulting value,
1169 * and *LOCP to the computed location (if any). Return value is as
1170 * for userAction. */
1171 static inline YYRESULTTAG
1172 yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
1173 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1174 {
1175 int yynrhs = yyrhsLength (yyrule);
1176
1177 if (yystack->yysplitPoint == NULL)
1178 {
1179 /* Standard special case: single stack. */
1180 yyGLRStackItem* rhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
1181 YYASSERT (yyk == 0);
1182 yystack->yynextFree -= yynrhs;
1183 yystack->yyspaceLeft += yynrhs;
1184 yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate;
1185 return yyuserAction (yyrule, yynrhs, rhs,
1186 yyvalp, yylocp, yystack]b4_user_args[);
1187 }
1188 else
1189 {
1190 int yyi;
1191 yyGLRState* yys;
1192 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1193 yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
1194 = yystack->yytops.yystates[yyk];
1195 for (yyi = 0; yyi < yynrhs; yyi += 1)
1196 {
1197 yys = yys->yypred;
1198 YYASSERT (yys);
1199 }
1200 yyupdateSplit (yystack, yys);
1201 yystack->yytops.yystates[yyk] = yys;
1202 return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1203 yyvalp, yylocp, yystack]b4_user_args[);
1204 }
1205 }
1206
1207 #if !YYDEBUG
1208 # define YY_REDUCE_PRINT(K, Rule)
1209 #else
1210 # define YY_REDUCE_PRINT(K, Rule) \
1211 do { \
1212 if (yydebug) \
1213 yy_reduce_print (K, Rule); \
1214 } while (0)
1215
1216 /*----------------------------------------------------------.
1217 | Report that the RULE is going to be reduced on stack #K. |
1218 `----------------------------------------------------------*/
1219
1220 static inline void
1221 yy_reduce_print (size_t yyk, yyRuleNum yyrule)
1222 {
1223 int yyi;
1224 YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu), ",
1225 (unsigned long int) yyk, yyrule - 1,
1226 (unsigned long int) yyrline[yyrule]);
1227 /* Print the symbols being reduced, and their result. */
1228 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
1229 YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
1230 YYFPRINTF (stderr, "-> %s\n", yytokenName (yyr1[yyrule]));
1231 }
1232 #endif
1233
1234 /** Pop items off stack #K of STACK according to grammar rule RULE,
1235 * and push back on the resulting nonterminal symbol. Perform the
1236 * semantic action associated with RULE and store its value with the
1237 * newly pushed state, if FORCEEVAL or if STACK is currently
1238 * unambiguous. Otherwise, store the deferred semantic action with
1239 * the new state. If the new state would have an identical input
1240 * position, LR state, and predecessor to an existing state on the stack,
1241 * it is identified with that existing state, eliminating stack #K from
1242 * the STACK. In this case, the (necessarily deferred) semantic value is
1243 * added to the options for the existing state's semantic value.
1244 */
1245 static inline YYRESULTTAG
1246 yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
1247 yybool yyforceEval]b4_user_formals[)
1248 {
1249 size_t yyposn = yystack->yytops.yystates[yyk]->yyposn;
1250
1251 if (yyforceEval || yystack->yysplitPoint == NULL)
1252 {
1253 YYSTYPE yysval;
1254 YYLTYPE yyloc;
1255
1256 YY_REDUCE_PRINT (yyk, yyrule);
1257 YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[));
1258 yyglrShift (yystack, yyk,
1259 yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState,
1260 yylhsNonterm (yyrule)),
1261 yyposn, yysval, &yyloc);
1262 }
1263 else
1264 {
1265 size_t yyi;
1266 int yyn;
1267 yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];
1268 yyStateNum yynewLRState;
1269
1270 for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1271 0 < yyn; yyn -= 1)
1272 {
1273 yys = yys->yypred;
1274 YYASSERT (yys);
1275 }
1276 yyupdateSplit (yystack, yys);
1277 yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1278 YYDPRINTF ((stderr,
1279 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1280 (unsigned long int) yyk, yyrule - 1, yynewLRState));
1281 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
1282 if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL)
1283 {
1284 yyGLRState* yyp, *yysplit = yystack->yysplitPoint;
1285 yyp = yystack->yytops.yystates[yyi];
1286 while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1287 {
1288 if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1289 {
1290 yyaddDeferredAction (yystack, yyp, yys0, yyrule);
1291 yymarkStackDeleted (yystack, yyk);
1292 YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
1293 (unsigned long int) yyk,
1294 (unsigned long int) yyi));
1295 return yyok;
1296 }
1297 yyp = yyp->yypred;
1298 }
1299 }
1300 yystack->yytops.yystates[yyk] = yys;
1301 yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule);
1302 }
1303 return yyok;
1304 }
1305
1306 static size_t
1307 yysplitStack (yyGLRStack* yystack, size_t yyk)
1308 {
1309 if (yystack->yysplitPoint == NULL)
1310 {
1311 YYASSERT (yyk == 0);
1312 yystack->yysplitPoint = yystack->yytops.yystates[yyk];
1313 }
1314 if (yystack->yytops.yysize >= yystack->yytops.yycapacity)
1315 {
1316 yyGLRState** yynewStates;
1317 if (! ((yystack->yytops.yycapacity
1318 <= (YYSIZEMAX / (2 * sizeof yynewStates[0])))
1319 && (yynewStates =
1320 (yyGLRState**) YYREALLOC (yystack->yytops.yystates,
1321 ((yystack->yytops.yycapacity *= 2)
1322 * sizeof yynewStates[0])))))
1323 yyMemoryExhausted (yystack);
1324 yystack->yytops.yystates = yynewStates;
1325 }
1326 yystack->yytops.yystates[yystack->yytops.yysize]
1327 = yystack->yytops.yystates[yyk];
1328 yystack->yytops.yysize += 1;
1329 return yystack->yytops.yysize-1;
1330 }
1331
1332 /** True iff Y0 and Y1 represent identical options at the top level.
1333 * That is, they represent the same rule applied to RHS symbols
1334 * that produce the same terminal symbols. */
1335 static yybool
1336 yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1337 {
1338 if (yyy0->yyrule == yyy1->yyrule)
1339 {
1340 yyGLRState *yys0, *yys1;
1341 int yyn;
1342 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1343 yyn = yyrhsLength (yyy0->yyrule);
1344 yyn > 0;
1345 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1346 if (yys0->yyposn != yys1->yyposn)
1347 return yyfalse;
1348 return yytrue;
1349 }
1350 else
1351 return yyfalse;
1352 }
1353
1354 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1355 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1356 static void
1357 yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1358 {
1359 yyGLRState *yys0, *yys1;
1360 int yyn;
1361 for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1362 yyn = yyrhsLength (yyy0->yyrule);
1363 yyn > 0;
1364 yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1365 {
1366 if (yys0 == yys1)
1367 break;
1368 else if (yys0->yyresolved)
1369 {
1370 yys1->yyresolved = yytrue;
1371 yys1->yysemantics.yysval = yys0->yysemantics.yysval;
1372 }
1373 else if (yys1->yyresolved)
1374 {
1375 yys0->yyresolved = yytrue;
1376 yys0->yysemantics.yysval = yys1->yysemantics.yysval;
1377 }
1378 else
1379 {
1380 yySemanticOption** yyz0p;
1381 yySemanticOption* yyz1;
1382 yyz0p = &yys0->yysemantics.yyfirstVal;
1383 yyz1 = yys1->yysemantics.yyfirstVal;
1384 while (yytrue)
1385 {
1386 if (yyz1 == *yyz0p || yyz1 == NULL)
1387 break;
1388 else if (*yyz0p == NULL)
1389 {
1390 *yyz0p = yyz1;
1391 break;
1392 }
1393 else if (*yyz0p < yyz1)
1394 {
1395 yySemanticOption* yyz = *yyz0p;
1396 *yyz0p = yyz1;
1397 yyz1 = yyz1->yynext;
1398 (*yyz0p)->yynext = yyz;
1399 }
1400 yyz0p = &(*yyz0p)->yynext;
1401 }
1402 yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
1403 }
1404 }
1405 }
1406
1407 /** Y0 and Y1 represent two possible actions to take in a given
1408 * parsing state; return 0 if no combination is possible,
1409 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1410 static int
1411 yypreference (yySemanticOption* y0, yySemanticOption* y1)
1412 {
1413 yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
1414 int p0 = yydprec[r0], p1 = yydprec[r1];
1415
1416 if (p0 == p1)
1417 {
1418 if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
1419 return 0;
1420 else
1421 return 1;
1422 }
1423 if (p0 == 0 || p1 == 0)
1424 return 0;
1425 if (p0 < p1)
1426 return 3;
1427 if (p1 < p0)
1428 return 2;
1429 return 0;
1430 }
1431
1432 static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,
1433 yyGLRStack* yystack, YYSTYPE* yyvalp,
1434 YYLTYPE* yylocp]b4_user_formals[);
1435
1436 static YYRESULTTAG
1437 yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack]b4_user_formals[)
1438 {
1439 YYRESULTTAG yyflag;
1440 if (0 < yyn)
1441 {
1442 YYASSERT (yys->yypred);
1443 yyflag = yyresolveStates (yys->yypred, yyn-1, yystack]b4_user_args[);
1444 if (yyflag != yyok)
1445 return yyflag;
1446 if (! yys->yyresolved)
1447 {
1448 yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack,
1449 &yys->yysemantics.yysval, &yys->yyloc
1450 ]b4_user_args[);
1451 if (yyflag != yyok)
1452 return yyflag;
1453 yys->yyresolved = yytrue;
1454 }
1455 }
1456 return yyok;
1457 }
1458
1459 static YYRESULTTAG
1460 yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
1461 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1462 {
1463 yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
1464 int yynrhs;
1465
1466 yynrhs = yyrhsLength (yyopt->yyrule);
1467 YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[));
1468 yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;
1469 return yyuserAction (yyopt->yyrule, yynrhs,
1470 yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
1471 yyvalp, yylocp, yystack]b4_user_args[);
1472 }
1473
1474 #if YYDEBUG
1475 static void
1476 yyreportTree (yySemanticOption* yyx, int yyindent)
1477 {
1478 int yynrhs = yyrhsLength (yyx->yyrule);
1479 int yyi;
1480 yyGLRState* yys;
1481 yyGLRState* yystates[YYMAXRHS];
1482 yyGLRState yyleftmost_state;
1483
1484 for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
1485 yystates[yyi] = yys;
1486 if (yys == NULL)
1487 {
1488 yyleftmost_state.yyposn = 0;
1489 yystates[0] = &yyleftmost_state;
1490 }
1491 else
1492 yystates[0] = yys;
1493
1494 if (yyx->yystate->yyposn < yys->yyposn + 1)
1495 YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1496 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1497 yyx->yyrule);
1498 else
1499 YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1500 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1501 yyx->yyrule, (unsigned long int) (yys->yyposn + 1),
1502 (unsigned long int) yyx->yystate->yyposn);
1503 for (yyi = 1; yyi <= yynrhs; yyi += 1)
1504 {
1505 if (yystates[yyi]->yyresolved)
1506 {
1507 if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1508 YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
1509 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]));
1510 else
1511 YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
1512 yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1513 (unsigned long int) (yystates[yyi - 1]->yyposn + 1),
1514 (unsigned long int) yystates[yyi]->yyposn);
1515 }
1516 else
1517 yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1518 }
1519 }
1520 #endif
1521
1522 static void
1523 yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
1524 yyGLRStack* yystack]b4_pure_formals[)
1525 {
1526 /* `Unused' warnings. */
1527 (void) yyx0;
1528 (void) yyx1;
1529
1530 #if YYDEBUG
1531 YYFPRINTF (stderr, "Ambiguity detected.\n");
1532 YYFPRINTF (stderr, "Option 1,\n");
1533 yyreportTree (yyx0, 2);
1534 YYFPRINTF (stderr, "\nOption 2,\n");
1535 yyreportTree (yyx1, 2);
1536 YYFPRINTF (stderr, "\n");
1537 #endif
1538 yyFail (yystack][]b4_pure_args[, YY_("syntax is ambiguous"));
1539 }
1540
1541
1542 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1543 * actions, and return the result. */
1544 static YYRESULTTAG
1545 yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack,
1546 YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
1547 {
1548 yySemanticOption* yybest;
1549 yySemanticOption* yyp;
1550 yybool yymerge;
1551
1552 yybest = yyoptionList;
1553 yymerge = yyfalse;
1554 for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext)
1555 {
1556 if (yyidenticalOptions (yybest, yyp))
1557 yymergeOptionSets (yybest, yyp);
1558 else
1559 switch (yypreference (yybest, yyp))
1560 {
1561 case 0:
1562 yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[);
1563 break;
1564 case 1:
1565 yymerge = yytrue;
1566 break;
1567 case 2:
1568 break;
1569 case 3:
1570 yybest = yyp;
1571 yymerge = yyfalse;
1572 break;
1573 }
1574 }
1575
1576 if (yymerge)
1577 {
1578 int yyprec = yydprec[yybest->yyrule];
1579 YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[));
1580 for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)
1581 {
1582 if (yyprec == yydprec[yyp->yyrule])
1583 {
1584 YYSTYPE yyval1;
1585 YYLTYPE yydummy;
1586 YYCHK (yyresolveAction (yyp, yystack, &yyval1, &yydummy]b4_user_args[));
1587 yyuserMerge (yymerger[yyp->yyrule], yyvalp, &yyval1);
1588 }
1589 }
1590 return yyok;
1591 }
1592 else
1593 return yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[);
1594 }
1595
1596 static YYRESULTTAG
1597 yyresolveStack (yyGLRStack* yystack]b4_user_formals[)
1598 {
1599 if (yystack->yysplitPoint != NULL)
1600 {
1601 yyGLRState* yys;
1602 int yyn;
1603
1604 for (yyn = 0, yys = yystack->yytops.yystates[0];
1605 yys != yystack->yysplitPoint;
1606 yys = yys->yypred, yyn += 1)
1607 continue;
1608 YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack
1609 ]b4_user_args[));
1610 }
1611 return yyok;
1612 }
1613
1614 static void
1615 yycompressStack (yyGLRStack* yystack)
1616 {
1617 yyGLRState* yyp, *yyq, *yyr;
1618
1619 if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL)
1620 return;
1621
1622 for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;
1623 yyp != yystack->yysplitPoint;
1624 yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1625 yyp->yypred = yyr;
1626
1627 yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems;
1628 yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1;
1629 yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems;
1630 yystack->yysplitPoint = NULL;
1631 yystack->yylastDeleted = NULL;
1632
1633 while (yyr != NULL)
1634 {
1635 yystack->yynextFree->yystate = *yyr;
1636 yyr = yyr->yypred;
1637 yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate;
1638 yystack->yytops.yystates[0] = &yystack->yynextFree->yystate;
1639 yystack->yynextFree += 1;
1640 yystack->yyspaceLeft -= 1;
1641 }
1642 }
1643
1644 static YYRESULTTAG
1645 yyprocessOneStack (yyGLRStack* yystack, size_t yyk,
1646 size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp
1647 ]b4_pure_formals[)
1648 {
1649 int yyaction;
1650 const short int* yyconflicts;
1651 yyRuleNum yyrule;
1652 yySymbol* const yytokenp = yystack->yytokenp;
1653
1654 while (yystack->yytops.yystates[yyk] != NULL)
1655 {
1656 yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState;
1657 YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
1658 (unsigned long int) yyk, yystate));
1659
1660 YYASSERT (yystate != YYFINAL);
1661
1662 if (yyisDefaultedState (yystate))
1663 {
1664 yyrule = yydefaultAction (yystate);
1665 if (yyrule == 0)
1666 {
1667 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1668 (unsigned long int) yyk));
1669 yymarkStackDeleted (yystack, yyk);
1670 return yyok;
1671 }
1672 YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse]b4_user_args[));
1673 }
1674 else
1675 {
1676 if (*yytokenp == YYEMPTY)
1677 {
1678 YYDPRINTF ((stderr, "Reading a token: "));
1679 yychar = YYLEX;
1680 *yytokenp = YYTRANSLATE (yychar);
1681 YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);
1682 YYDPRINTF ((stderr, "\n"));
1683 }
1684 yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
1685
1686 while (*yyconflicts != 0)
1687 {
1688 size_t yynewStack = yysplitStack (yystack, yyk);
1689 YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
1690 (unsigned long int) yynewStack,
1691 (unsigned long int) yyk));
1692 YYCHK (yyglrReduce (yystack, yynewStack,
1693 *yyconflicts, yyfalse]b4_user_args[));
1694 YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,
1695 yylvalp, yyllocp]b4_pure_args[));
1696 yyconflicts += 1;
1697 }
1698
1699 if (yyisShiftAction (yyaction))
1700 {
1701 YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yyk));
1702 YY_SYMBOL_PRINT ("shifting", *yytokenp, yylvalp, yyllocp);
1703 yyglrShift (yystack, yyk, yyaction, yyposn+1,
1704 *yylvalp, yyllocp);
1705 YYDPRINTF ((stderr, ", now in state #%d\n",
1706 yystack->yytops.yystates[yyk]->yylrState));
1707 break;
1708 }
1709 else if (yyisErrorAction (yyaction))
1710 {
1711 YYDPRINTF ((stderr, "Stack %lu dies.\n",
1712 (unsigned long int) yyk));
1713 yymarkStackDeleted (yystack, yyk);
1714 break;
1715 }
1716 else
1717 YYCHK (yyglrReduce (yystack, yyk, -yyaction, yyfalse]b4_user_args[));
1718 }
1719 }
1720 return yyok;
1721 }
1722
1723 static void
1724 yyreportSyntaxError (yyGLRStack* yystack,
1725 YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
1726 {
1727 /* `Unused' warnings. */
1728 (void) yylvalp;
1729 (void) yyllocp;
1730
1731 if (yystack->yyerrState == 0)
1732 {
1733 #if YYERROR_VERBOSE
1734 yySymbol* const yytokenp = yystack->yytokenp;
1735 int yyn;
1736 yyn = yypact[yystack->yytops.yystates[0]->yylrState];
1737 if (YYPACT_NINF < yyn && yyn < YYLAST)
1738 {
1739 size_t yysize0 = strlen (yytokenName (*yytokenp));
1740 size_t yysize = yysize0;
1741 size_t yysize1;
1742 yybool yysize_overflow = yyfalse;
1743 char* yymsg = NULL;
1744 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1745 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1746 int yyx;
1747 char *yyfmt;
1748 char const *yyf;
1749 static char const yyunexpected[] = "syntax error, unexpected %s";
1750 static char const yyexpecting[] = ", expecting %s";
1751 static char const yyor[] = " or %s";
1752 char yyformat[sizeof yyunexpected
1753 + sizeof yyexpecting - 1
1754 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1755 * (sizeof yyor - 1))];
1756 char const *yyprefix = yyexpecting;
1757
1758 /* Start YYX at -YYN if negative to avoid negative indexes in
1759 YYCHECK. */
1760 int yyxbegin = yyn < 0 ? -yyn : 0;
1761
1762 /* Stay within bounds of both yycheck and yytname. */
1763 int yychecklim = YYLAST - yyn;
1764 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1765 int yycount = 1;
1766
1767 yyarg[0] = yytokenName (*yytokenp);
1768 yyfmt = yystpcpy (yyformat, yyunexpected);
1769
1770 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1771 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1772 {
1773 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1774 {
1775 yycount = 1;
1776 yysize = yysize0;
1777 yyformat[sizeof yyunexpected - 1] = '\0';
1778 break;
1779 }
1780 yyarg[yycount++] = yytokenName (yyx);
1781 yysize1 = yysize + strlen (yytokenName (yyx));
1782 yysize_overflow |= yysize1 < yysize;
1783 yysize = yysize1;
1784 yyfmt = yystpcpy (yyfmt, yyprefix);
1785 yyprefix = yyor;
1786 }
1787
1788 yyf = YY_(yyformat);
1789 yysize1 = yysize + strlen (yyf);
1790 yysize_overflow |= yysize1 < yysize;
1791 yysize = yysize1;
1792
1793 if (!yysize_overflow)
1794 yymsg = (char *) YYMALLOC (yysize);
1795
1796 if (yymsg)
1797 {
1798 char *yyp = yymsg;
1799 int yyi = 0;
1800 while ((*yyp = *yyf))
1801 {
1802 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1803 {
1804 yyp = yystpcpy (yyp, yyarg[yyi++]);
1805 yyf += 2;
1806 }
1807 else
1808 {
1809 yyp++;
1810 yyf++;
1811 }
1812 }
1813 yyerror (]b4_lyyerror_args[yymsg);
1814 YYFREE (yymsg);
1815 }
1816 else
1817 {
1818 yyerror (]b4_lyyerror_args[YY_("syntax error"));
1819 yyMemoryExhausted (yystack);
1820 }
1821 }
1822 else
1823 #endif /* YYERROR_VERBOSE */
1824 yyerror (]b4_lyyerror_args[YY_("syntax error"));
1825 yynerrs += 1;
1826 }
1827 }
1828
1829 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1830 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1831 value, and location of the look-ahead. */
1832 static void
1833 yyrecoverSyntaxError (yyGLRStack* yystack,
1834 YYSTYPE* yylvalp,
1835 YYLTYPE* YYOPTIONAL_LOC (yyllocp)
1836 ]b4_user_formals[)
1837 {
1838 yySymbol* const yytokenp = yystack->yytokenp;
1839 size_t yyk;
1840 int yyj;
1841
1842 if (yystack->yyerrState == 3)
1843 /* We just shifted the error token and (perhaps) took some
1844 reductions. Skip tokens until we can proceed. */
1845 while (yytrue)
1846 {
1847 if (*yytokenp == YYEOF)
1848 yyFail (yystack][]b4_lpure_args[, NULL);
1849 if (*yytokenp != YYEMPTY)
1850 {]b4_location_if([[
1851 /* We throw away the lookahead, but the error range
1852 of the shifted error token must take it into account. */
1853 yyGLRState *yys = yystack->yytops.yystates[0];
1854 yyGLRStackItem yyerror_range[3];
1855 yyerror_range[1].yystate.yyloc = yys->yyloc;
1856 yyerror_range[2].yystate.yyloc = *yyllocp;
1857 YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[
1858 yydestruct ("Error: discarding",
1859 *yytokenp, yylvalp]b4_location_if([, yyllocp])[);
1860 }
1861 YYDPRINTF ((stderr, "Reading a token: "));
1862 yychar = YYLEX;
1863 *yytokenp = YYTRANSLATE (yychar);
1864 YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);
1865 YYDPRINTF ((stderr, "\n"));
1866 yyj = yypact[yystack->yytops.yystates[0]->yylrState];
1867 if (yyis_pact_ninf (yyj))
1868 return;
1869 yyj += *yytokenp;
1870 if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp)
1871 {
1872 if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)
1873 return;
1874 }
1875 else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj]))
1876 return;
1877 }
1878
1879 /* Reduce to one stack. */
1880 for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1)
1881 if (yystack->yytops.yystates[yyk] != NULL)
1882 break;
1883 if (yyk >= yystack->yytops.yysize)
1884 yyFail (yystack][]b4_lpure_args[, NULL);
1885 for (yyk += 1; yyk < yystack->yytops.yysize; yyk += 1)
1886 yymarkStackDeleted (yystack, yyk);
1887 yyremoveDeletes (yystack);
1888 yycompressStack (yystack);
1889
1890 /* Now pop stack until we find a state that shifts the error token. */
1891 yystack->yyerrState = 3;
1892 while (yystack->yytops.yystates[0] != NULL)
1893 {
1894 yyGLRState *yys = yystack->yytops.yystates[0];
1895 yyj = yypact[yys->yylrState];
1896 if (! yyis_pact_ninf (yyj))
1897 {
1898 yyj += YYTERROR;
1899 if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
1900 && yyisShiftAction (yytable[yyj]))
1901 {
1902 /* Shift the error token having adjusted its location. */
1903 YYLTYPE yyerrloc;]b4_location_if([[
1904 yystack->yyerror_range[2].yystate.yyloc = *yyllocp;
1905 YYLLOC_DEFAULT (yyerrloc, yystack->yyerror_range, 2);]])[
1906 YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
1907 yylvalp, &yyerrloc);
1908 YYDPRINTF ((stderr, "\n"));
1909 yyglrShift (yystack, 0, yytable[yyj],
1910 yys->yyposn, *yylvalp, &yyerrloc);
1911 yys = yystack->yytops.yystates[0];
1912 break;
1913 }
1914 }
1915 ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
1916 yydestruct ("Error: popping",
1917 yystos[yys->yylrState],
1918 &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
1919 yystack->yytops.yystates[0] = yys->yypred;
1920 yystack->yynextFree -= 1;
1921 yystack->yyspaceLeft += 1;
1922 }
1923 if (yystack->yytops.yystates[0] == NULL)
1924 yyFail (yystack][]b4_lpure_args[, NULL);
1925 }
1926
1927 #define YYCHK1(YYE) \
1928 do { \
1929 switch (YYE) { \
1930 default: \
1931 break; \
1932 case yyabort: \
1933 goto yyabortlab; \
1934 case yyaccept: \
1935 goto yyacceptlab; \
1936 case yyerr: \
1937 goto yyuser_error; \
1938 } \
1939 } while (0)
1940
1941
1942 /*----------.
1943 | yyparse. |
1944 `----------*/
1945
1946 ]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[
1947 {
1948 int yyresult;
1949 yySymbol yytoken;
1950 yyGLRStack yystack;
1951 size_t yyposn;
1952 ]b4_pure_if(
1953 [
1954 YYSTYPE yylval;
1955 YYLTYPE yylloc;
1956 #undef yychar
1957 #define yychar (yystack.yyrawchar)
1958 ])[
1959
1960 YYSTYPE* const yylvalp = &yylval;
1961 YYLTYPE* const yyllocp = &yylloc;
1962
1963 YYDPRINTF ((stderr, "Starting parse\n"));
1964
1965 yytoken = YYEMPTY;
1966 yylval = yyval_default;
1967 ]b4_location_if([
1968 #if YYLTYPE_IS_TRIVIAL
1969 yylloc.first_line = yylloc.last_line = 1;
1970 yylloc.first_column = yylloc.last_column = 0;
1971 #endif
1972 ])
1973 m4_ifdef([b4_initial_action], [
1974 m4_pushdef([b4_at_dollar], [yylloc])dnl
1975 m4_pushdef([b4_dollar_dollar], [yylval])dnl
1976 /* User initialization code. */
1977 b4_initial_action
1978 m4_popdef([b4_dollar_dollar])dnl
1979 m4_popdef([b4_at_dollar])dnl
1980 /* Line __line__ of glr.c. */
1981 b4_syncline([@oline@], [@ofile@])])dnl
1982 [
1983 if (! yyinitGLRStack (&yystack, YYINITDEPTH))
1984 goto yyexhaustedlab;
1985 switch (setjmp (yystack.yyexception_buffer))
1986 {
1987 case 1: goto yyabortlab;
1988 case 2: goto yyexhaustedlab;
1989 }
1990 yystack.yytokenp = &yytoken;
1991 yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc);
1992 yyposn = 0;
1993
1994 while (yytrue)
1995 {
1996 /* For efficiency, we have two loops, the first of which is
1997 specialized to deterministic operation (single stack, no
1998 potential ambiguity). */
1999 /* Standard mode */
2000 while (yytrue)
2001 {
2002 yyRuleNum yyrule;
2003 int yyaction;
2004 const short int* yyconflicts;
2005
2006 yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
2007 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
2008 if (yystate == YYFINAL)
2009 goto yyacceptlab;
2010 if (yyisDefaultedState (yystate))
2011 {
2012 yyrule = yydefaultAction (yystate);
2013 if (yyrule == 0)
2014 {
2015 ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[
2016 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
2017 goto yyuser_error;
2018 }
2019 YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
2020 }
2021 else
2022 {
2023 if (yytoken == YYEMPTY)
2024 {
2025 YYDPRINTF ((stderr, "Reading a token: "));
2026 yychar = YYLEX;
2027 yytoken = YYTRANSLATE (yychar);
2028 YY_SYMBOL_PRINT ("Next token is", yytoken, yylvalp, yyllocp);
2029 YYDPRINTF ((stderr, "\n"));
2030 }
2031 yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
2032 if (*yyconflicts != 0)
2033 break;
2034 if (yyisShiftAction (yyaction))
2035 {
2036 YY_SYMBOL_PRINT ("Shifting", yytoken, yylvalp, yyllocp);
2037 YYDPRINTF ((stderr, "\n"));
2038 if (yytoken != YYEOF)
2039 yytoken = YYEMPTY;
2040 yyposn += 1;
2041 yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);
2042 if (0 < yystack.yyerrState)
2043 yystack.yyerrState -= 1;
2044 }
2045 else if (yyisErrorAction (yyaction))
2046 {
2047 ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[
2048 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
2049 goto yyuser_error;
2050 }
2051 else
2052 YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));
2053 }
2054 }
2055
2056 while (yytrue)
2057 {
2058 size_t yys;
2059 size_t yyn = yystack.yytops.yysize;
2060 for (yys = 0; yys < yyn; yys += 1)
2061 YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn,
2062 yylvalp, yyllocp]b4_lpure_args[));
2063 yytoken = YYEMPTY;
2064 yyposn += 1;
2065 yyremoveDeletes (&yystack);
2066 if (yystack.yytops.yysize == 0)
2067 {
2068 yyundeleteLastStack (&yystack);
2069 if (yystack.yytops.yysize == 0)
2070 yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
2071 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2072 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2073 ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[
2074 yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
2075 goto yyuser_error;
2076 }
2077 else if (yystack.yytops.yysize == 1)
2078 {
2079 YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
2080 YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
2081 yycompressStack (&yystack);
2082 break;
2083 }
2084 }
2085 continue;
2086 yyuser_error:
2087 yyrecoverSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
2088 yyposn = yystack.yytops.yystates[0]->yyposn;
2089 }
2090
2091 yyacceptlab:
2092 yyresult = 0;
2093 goto yyreturn;
2094
2095 yyabortlab:
2096 yyresult = 1;
2097 goto yyreturn;
2098
2099 yyexhaustedlab:
2100 yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
2101 yyresult = 2;
2102 /* Fall through. */
2103
2104 yyreturn:
2105 if (yytoken != YYEOF && yytoken != YYEMPTY)
2106 yydestruct ("Error: discarding lookahead",
2107 yytoken, yylvalp]b4_location_if([, yyllocp])[);
2108
2109 /* Now pop stack until empty, destroying its entries as we go. */
2110 while (yystack.yytops.yystates[0] != NULL)
2111 {
2112 yyGLRState *yys = yystack.yytops.yystates[0];
2113 ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
2114 yydestruct ("Error: popping",
2115 yystos[yys->yylrState],
2116 &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
2117 yystack.yytops.yystates[0] = yys->yypred;
2118 yystack.yynextFree -= 1;
2119 yystack.yyspaceLeft += 1;
2120 }
2121
2122 yyfreeGLRStack (&yystack);
2123 return yyresult;
2124 }
2125
2126 /* DEBUGGING ONLY */
2127 #ifdef YYDEBUG
2128 static void yypstack (yyGLRStack* yystack, size_t yyk) ATTRIBUTE_UNUSED;
2129 static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED;
2130
2131 static void
2132 yy_yypstack (yyGLRState* yys)
2133 {
2134 if (yys->yypred)
2135 {
2136 yy_yypstack (yys->yypred);
2137 fprintf (stderr, " -> ");
2138 }
2139 fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long int) yys->yyposn);
2140 }
2141
2142 static void
2143 yypstates (yyGLRState* yyst)
2144 {
2145 if (yyst == NULL)
2146 fprintf (stderr, "<null>");
2147 else
2148 yy_yypstack (yyst);
2149 fprintf (stderr, "\n");
2150 }
2151
2152 static void
2153 yypstack (yyGLRStack* yystack, size_t yyk)
2154 {
2155 yypstates (yystack->yytops.yystates[yyk]);
2156 }
2157
2158 #define YYINDEX(YYX) \
2159 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
2160
2161
2162 static void
2163 yypdumpstack (yyGLRStack* yystack)
2164 {
2165 yyGLRStackItem* yyp;
2166 size_t yyi;
2167 for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)
2168 {
2169 fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - yystack->yyitems));
2170 if (*(yybool *) yyp)
2171 {
2172 fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2173 yyp->yystate.yyresolved, yyp->yystate.yylrState,
2174 (unsigned long int) yyp->yystate.yyposn,
2175 (long int) YYINDEX (yyp->yystate.yypred));
2176 if (! yyp->yystate.yyresolved)
2177 fprintf (stderr, ", firstVal: %ld",
2178 (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
2179 }
2180 else
2181 {
2182 fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",
2183 yyp->yyoption.yyrule,
2184 (long int) YYINDEX (yyp->yyoption.yystate),
2185 (long int) YYINDEX (yyp->yyoption.yynext));
2186 }
2187 fprintf (stderr, "\n");
2188 }
2189 fprintf (stderr, "Tops:");
2190 for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
2191 fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi,
2192 (long int) YYINDEX (yystack->yytops.yystates[yyi]));
2193 fprintf (stderr, "\n");
2194 }
2195 #endif
2196 ]
2197
2198 b4_epilogue
2199 m4_if(b4_defines_flag, 0, [],
2200 [@output @output_header_name@
2201 b4_copyright([Skeleton parser for GLR parsing with Bison],
2202 [2002, 2003, 2004, 2005])
2203
2204 b4_token_defines(b4_tokens)
2205
2206 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
2207 m4_ifdef([b4_stype],
2208 [b4_syncline([b4_stype_line], [b4_filename])
2209 typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
2210 /* Line __line__ of glr.c. */
2211 b4_syncline([@oline@], [@ofile@])],
2212 [typedef int YYSTYPE;])
2213 # define YYSTYPE_IS_DECLARED 1
2214 # define YYSTYPE_IS_TRIVIAL 1
2215 #endif
2216
2217 b4_pure_if([],
2218 [extern YYSTYPE b4_prefix[]lval;])
2219
2220 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2221 typedef struct YYLTYPE
2222 {
2223 b4_location_if([
2224 int first_line;
2225 int first_column;
2226 int last_line;
2227 int last_column;
2228 ],[
2229 char yydummy;
2230 ])
2231 } YYLTYPE;
2232 # define YYLTYPE_IS_DECLARED 1
2233 # define YYLTYPE_IS_TRIVIAL 1
2234 #endif
2235
2236 b4_location_if([b4_pure_if([],
2237 [extern YYLTYPE b4_prefix[]lloc;])
2238 ])
2239 ])