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