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