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