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