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