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