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