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