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