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