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