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