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