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