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