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