1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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.
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.
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
22 ## ---------------- ##
24 ## ---------------- ##
27 m4_define_default([b4_stack_depth_max
], [10000])
28 m4_define_default([b4_stack_depth_init
], [200])
32 ## ------------------------ ##
33 ## Pure/impure interfaces. ##
34 ## ------------------------ ##
39 # The possible parse-params formal arguments preceded by a comma.
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
)])])
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
)))
59 # Optional effective arguments passed to yyerror: user args plus yylloc, and
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
), ])])
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
), ])])
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
])
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
])
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
])
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
])
102 ## ----------------- ##
103 ## Semantic Values. ##
104 ## ----------------- ##
107 # b4_lhs_value([TYPE])
108 # --------------------
109 # Expansion of $<TYPE>$.
110 m4_define([b4_lhs_value
],
111 [((*yyvalp
)[]m4_ifval([$
1], [.$
1]))])
114 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
115 # --------------------------------------
116 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
118 m4_define([b4_rhs_value
],
119 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL ($
2 - $
1)@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3]))])
130 m4_define([b4_lhs_location
],
134 # b4_rhs_location(RULE-LENGTH, NUM)
135 # ---------------------------------
136 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
138 m4_define([b4_rhs_location
],
139 [(((yyGLRStackItem
const *)yyvsp
)@
{YYFILL ($
2 - $
1)@
}.yystate
.yyloc
)])
147 # We do want M4 expansion after # for CPP macros.
150 @output @output_parser_name@
151 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
152 [2002, 2003, 2004, 2005])
154 /* This is the parser code for GLR (Generalized LR) parser. */
158 m4_if(b4_prefix
[], [yy
], [],
159 [/* Substitute the variable and function names. */
160 #define yyparse b4_prefix[]parse
161 #define yylex b4_prefix[]lex
162 #define yyerror b4_prefix[]error
163 #define yylval b4_prefix[]lval
164 #define yychar b4_prefix[]char
165 #define yydebug b4_prefix[]debug
166 #define yynerrs b4_prefix[]nerrs
167 #define yylloc b4_prefix[]lloc])
169 dnl
# b4_shared_declarations
170 dnl
# ----------------------
171 dnl
# Declaration that might either go into the header (if --defines)
172 dnl
# or open coded in the parser body.
173 m4_define([b4_shared_declarations
],
174 [b4_token_enums(b4_tokens
)[
176 /* Copy the first part of user declarations. */
179 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
180 ]m4_ifdef([b4_stype
],
181 [b4_syncline([b4_stype_line
], [b4_file_name
])
182 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
183 /* Line __line__ of glr.c. */
184 b4_syncline([@oline@
], [@ofile@
])],
185 [typedef int YYSTYPE
;])[
186 # define YYSTYPE_IS_DECLARED 1
187 # define YYSTYPE_IS_TRIVIAL 1
190 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
191 typedef struct YYLTYPE
202 # define YYLTYPE_IS_DECLARED 1
203 # define YYLTYPE_IS_TRIVIAL 1
207 m4_if(b4_defines_flag
, 0,
208 [b4_shared_declarations
],
209 [#include @output_header_name@])[
211 /* Enabling traces. */
213 # define YYDEBUG ]b4_debug[
216 /* Enabling verbose error messages. */
217 #ifdef YYERROR_VERBOSE
218 # undef YYERROR_VERBOSE
219 # define YYERROR_VERBOSE 1
221 # define YYERROR_VERBOSE ]b4_error_verbose[
224 /* Enabling the token table. */
225 #ifndef YYTOKEN_TABLE
226 # define YYTOKEN_TABLE ]b4_token_table[
229 /* Default (constant) value used for initialization for null
230 right-hand sides. Unlike the standard yacc.c template,
231 here we set the default value of $$ to a zeroed-out value.
232 Since the default value is undefined, this behavior is
233 technically correct. */
234 static YYSTYPE yyval_default
;
236 /* Copy the second part of user declarations. */
239 ]/* Line __line__ of glr.c. */
240 b4_syncline([@oline@
], [@ofile@
])
250 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
251 # define YY_(msgid) dgettext ("bison-runtime", msgid)
255 # define YY_(msgid) msgid
259 /* Suppress unused-variable warnings by "using" E. */
260 #define YYUSE(e) do {;} while (/*CONSTCOND*/ yyfalse && (e))
266 # define YYMALLOC malloc
269 # define YYREALLOC realloc
272 #define YYSIZEMAX ((size_t) -1)
277 typedef unsigned char yybool
;
284 # define YYJMP_BUF jmp_buf
285 # define YYSETJMP(env) setjmp (env)
286 # define YYLONGJMP(env, val) longjmp (env, val)
293 #ifndef __attribute__
294 /* This feature is available in gcc versions 2.5 and later. */
295 # if (!defined (__GNUC__) || __GNUC__ < 2 \
296 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
297 # define __attribute__(Spec) /* empty */
301 ]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[
303 # define YYOPTIONAL_LOC(Name) /* empty */
305 # define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
309 # define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
312 /* YYFINAL -- State number of the termination state. */
313 #define YYFINAL ]b4_final_state_number[
314 /* YYLAST -- Last index in YYTABLE. */
315 #define YYLAST ]b4_last[
317 /* YYNTOKENS -- Number of terminals. */
318 #define YYNTOKENS ]b4_tokens_number[
319 /* YYNNTS -- Number of nonterminals. */
320 #define YYNNTS ]b4_nterms_number[
321 /* YYNRULES -- Number of rules. */
322 #define YYNRULES ]b4_rules_number[
323 /* YYNRULES -- Number of states. */
324 #define YYNSTATES ]b4_states_number[
325 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
326 #define YYMAXRHS ]b4_r2_max[
327 /* YYMAXLEFT -- Maximum number of symbols to the left of a handle
328 accessed by $0, $-1, etc., in any rule. */
329 #define YYMAXLEFT ]b4_max_left_semantic_context[
331 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
332 #define YYUNDEFTOK ]b4_undef_token_number[
333 #define YYMAXUTOK ]b4_user_token_number_max[
335 #define YYTRANSLATE(YYX) \
336 ((YYX <= 0) ? YYEOF : \
337 (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
339 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
340 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
346 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
348 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
353 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
354 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
359 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
360 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
366 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
367 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
368 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
369 static const char *const yytname
[] =
375 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
376 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
381 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
382 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
387 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
388 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
393 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
394 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
399 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
400 doesn't specify something else to do. Zero means the default is an
402 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
407 /* YYPDEFGOTO[NTERM-NUM]. */
408 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
413 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
415 #define YYPACT_NINF ]b4_pact_ninf[
416 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
421 /* YYPGOTO[NTERM-NUM]. */
422 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
427 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
428 positive, shift that token. If negative, reduce the rule which
429 number is the opposite. If zero, do what YYDEFACT says.
430 If YYTABLE_NINF, syntax error. */
431 #define YYTABLE_NINF ]b4_table_ninf[
432 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
437 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
438 list of conflicting reductions corresponding to action entry for
439 state STATE-NUM in yytable. 0 means no conflicts. The list in
440 yyconfl is terminated by a rule number of 0. */
441 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
443 ]b4_conflict_list_heads
[
446 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
447 0, pointed into by YYCONFLP. */
448 ]dnl Do
not use b4_int_type_for here
, since there are places where
449 dnl pointers onto yyconfl are taken
, which type is
"short int *".
450 dnl We probably ought to introduce a type
for confl
.
451 [static const short int yyconfl
[] =
453 ]b4_conflicting_rules
[
456 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
461 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
462 symbol of state STATE-NUM. */
463 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
469 /* Prevent warning if -Wmissing-prototypes. */
470 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
472 /* Error token number */
475 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
476 If N is 0, then set CURRENT to the empty location which ends
477 the previous symbol: RHS[0] (always defined). */
480 #define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
481 #ifndef YYLLOC_DEFAULT
482 # define YYLLOC_DEFAULT(Current, Rhs, N) \
486 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
487 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
488 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
489 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
493 (Current).first_line = (Current).last_line = \
494 YYRHSLOC (Rhs, 0).last_line; \
495 (Current).first_column = (Current).last_column = \
496 YYRHSLOC (Rhs, 0).last_column; \
498 while (/*CONSTCOND*/ 0)
500 /* YY_LOCATION_PRINT -- Print the location on the stream.
501 This macro was not mandated originally: define only if we know
502 we won't break user code: when these are the locations we know. */
504 # define YY_LOCATION_PRINT(File, Loc) \
505 fprintf (File, "%d.%d-%d.%d", \
506 (Loc).first_line, (Loc).first_column, \
507 (Loc).last_line, (Loc).last_column)
510 #ifndef YYLLOC_DEFAULT
511 # define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
515 #ifndef YY_LOCATION_PRINT
516 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
520 /* YYLEX -- calling `yylex' with the right arguments. */
521 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
526 #define yynerrs (yystack->yyerrcnt)
528 #define yychar (yystack->yyrawchar)],
536 static const int YYEOF
= 0;
537 static const int YYEMPTY
= -2;
539 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
542 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
543 while (/*CONSTCOND*/ 0)
547 #if ! defined (YYFPRINTF)
548 # define YYFPRINTF fprintf
551 # define YYDPRINTF(Args) \
555 } while (/*CONSTCOND*/ 0)
557 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
559 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
563 YYFPRINTF (stderr, "%s ", Title); \
564 yysymprint (stderr, \
565 Type, Value]b4_location_if([, Location])[]b4_user_args[); \
566 YYFPRINTF (stderr, "\n"); \
568 } while (/*CONSTCOND*/ 0)
570 /* Nonzero means print parse trace. It is left uninitialized so that
571 multiple parsers can coexist. */
576 # define YYDPRINTF(Args)
577 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
579 #endif /* !YYDEBUG */
581 /* YYINITDEPTH -- initial size of the parser's stacks. */
583 # define YYINITDEPTH ]b4_stack_depth_init[
586 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
587 if the built-in stack extension method is used).
589 Do not make this value too large; the results are undefined if
590 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
591 evaluated with infinite-precision integer arithmetic. */
594 # define YYMAXDEPTH ]b4_stack_depth_max[
597 /* Minimum number of free items on the stack allowed after an
598 allocation. This is to allow allocation and initialization
599 to be completed by functions that call yyexpandGLRStack before the
600 stack is expanded, thus insuring that all necessary pointers get
601 properly redirected to new data. */
604 #ifndef YYSTACKEXPANDABLE
605 # if (! defined (__cplusplus) \
606 || (]b4_location_if([[defined (YYLTYPE_IS_TRIVIAL) && YYLTYPE_IS_TRIVIAL \
607 && ]])[defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))
608 # define YYSTACKEXPANDABLE 1
610 # define YYSTACKEXPANDABLE 0
614 #if YYSTACKEXPANDABLE
615 # define YY_RESERVE_GLRSTACK(Yystack) \
617 if (Yystack->yyspaceLeft < YYHEADROOM) \
618 yyexpandGLRStack (Yystack); \
619 } while (/*CONSTCOND*/ 0)
621 # define YY_RESERVE_GLRSTACK(Yystack) \
623 if (Yystack->yyspaceLeft < YYHEADROOM) \
624 yyMemoryExhausted (Yystack); \
625 } while (/*CONSTCOND*/ 0)
632 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
633 # define yystpcpy stpcpy
635 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
638 yystpcpy (char *yydest
, const char *yysrc
)
641 const char *yys
= yysrc
;
643 while ((*yyd
++ = *yys
++) != '\0')
652 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
653 quotes and backslashes, so that it's suitable for yyerror. The
654 heuristic is that double-quoting is unnecessary unless the string
655 contains an apostrophe, a comma, or backslash (other than
656 backslash-backslash). YYSTR is taken from yytname. If YYRES is
657 null, do not copy; instead, return the length of what the result
660 yytnamerr (char *yyres
, const char *yystr
)
665 char const *yyp
= yystr
;
672 goto do_not_strip_quotes
;
676 goto do_not_strip_quotes
;
689 do_not_strip_quotes
: ;
693 return strlen (yystr
);
695 return yystpcpy (yyres
, yystr
) - yyres
;
699 #endif /* !YYERROR_VERBOSE */
701 /** State numbers, as in LALR(1) machine */
702 typedef int yyStateNum
;
704 /** Rule numbers, as in LALR(1) machine */
705 typedef int yyRuleNum
;
707 /** Grammar symbol */
708 typedef short int yySymbol
;
710 /** Item references, as in LALR(1) machine */
711 typedef short int yyItemNum
;
713 typedef struct yyGLRState yyGLRState
;
714 typedef struct yySemanticOption yySemanticOption
;
715 typedef union yyGLRStackItem yyGLRStackItem
;
716 typedef struct yyGLRStack yyGLRStack
;
717 typedef struct yyGLRStateSet yyGLRStateSet
;
720 /** Type tag: always true. */
722 /** Type tag for yysemantics. If true, yysval applies, otherwise
723 * yyfirstVal applies. */
725 /** Number of corresponding LALR(1) machine state. */
726 yyStateNum yylrState
;
727 /** Preceding state in this stack */
729 /** Source position of the first token produced by my symbol */
732 /** First in a chain of alternative reductions producing the
733 * non-terminal corresponding to this state, threaded through
735 yySemanticOption
* yyfirstVal
;
736 /** Semantic value for this state. */
739 /** Source location for this state. */
743 struct yyGLRStateSet
{
744 yyGLRState
** yystates
;
745 size_t yysize
, yycapacity
;
748 struct yySemanticOption
{
749 /** Type tag: always false. */
751 /** Rule number for this reduction */
753 /** The last RHS state in the list of states to be reduced. */
755 /** Next sibling in chain of options. To facilitate merging,
756 * options are chained in decreasing order by address. */
757 yySemanticOption
* yynext
;
760 /** Type of the items in the GLR stack. The yyisState field
761 * indicates which item of the union is valid. */
762 union yyGLRStackItem
{
764 yySemanticOption yyoption
;
769 ]b4_location_if([[ /* To compute the location of the error token. */
770 yyGLRStackItem yyerror_range
[3];]])[
777 YYJMP_BUF yyexception_buffer
;
778 yyGLRStackItem
* yyitems
;
779 yyGLRStackItem
* yynextFree
;
781 yyGLRState
* yysplitPoint
;
782 yyGLRState
* yylastDeleted
;
783 yyGLRStateSet yytops
;
786 #if YYSTACKEXPANDABLE
787 static void yyexpandGLRStack (yyGLRStack
* yystack
);
790 static void yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yymsg
)
791 __attribute__ ((__noreturn__
));
793 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yymsg
)
796 yyerror (]b4_yyerror_args
[yymsg
);
797 YYLONGJMP (yystack
->yyexception_buffer
, 1);
800 static void yyMemoryExhausted (yyGLRStack
* yystack
)
801 __attribute__ ((__noreturn__
));
803 yyMemoryExhausted (yyGLRStack
* yystack
)
805 YYLONGJMP (yystack
->yyexception_buffer
, 2);
808 #if YYDEBUG || YYERROR_VERBOSE
809 /** A printable representation of TOKEN. */
810 static inline const char*
811 yytokenName (yySymbol yytoken
)
813 if (yytoken
== YYEMPTY
)
816 return yytname
[yytoken
];
820 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
821 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
822 * containing the pointer to the next state in the chain. */
823 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
825 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
829 s
= yyvsp
[yylow0
].yystate
.yypred
;
830 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
832 YYASSERT (s
->yyresolved
);
833 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
834 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
835 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
836 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
840 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
841 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
842 * For convenience, always return YYLOW1. */
843 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
844 __attribute__ ((__unused__
));
846 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
848 if (!yynormal
&& yylow1
< *yylow
)
850 yyfillin (yyvsp
, *yylow
, yylow1
);
856 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
857 * and top stack item YYVSP. YYLVALP points to place to put semantic
858 * value ($$), and yylocp points to place for location information
859 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
860 * yyerr for YYERROR, yyabort for YYABORT. */
862 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
864 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
868 yybool yynormal
__attribute__ ((__unused__
)) =
869 (yystack
->yysplitPoint
== NULL
);
873 # define yyerrok (yystack->yyerrState = 0)
875 # define YYACCEPT return yyaccept
877 # define YYABORT return yyabort
879 # define YYERROR return yyerrok, yyerr
881 # define YYRECOVERING (yystack->yyerrState != 0)
883 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
885 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
887 # define YYBACKUP(Token, Value) \
888 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
893 *yyvalp
= yyval_default
;
895 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
896 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
897 ]b4_location_if([[ yystack
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
913 /* Line __line__ of glr.c. */
914 b4_syncline([@oline@
], [@ofile@
])
919 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
931 /* Bison grammar-table manipulation. */
933 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
935 /** Number of symbols composing the right hand side of rule #RULE. */
937 yyrhsLength (yyRuleNum yyrule
)
943 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
946 yydestruct (yymsg
, yystos
[yys
->yylrState
],
947 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
953 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
954 yysymprint (stderr
, yystos
[yys
->yylrState
],
955 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
956 YYFPRINTF (stderr
, "\n");
960 if (yys
->yysemantics
.yyfirstVal
)
962 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
965 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
967 yyrh
= yyrh
->yypred
, yyn
-= 1)
968 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
973 /** Left-hand-side symbol for rule #RULE. */
974 static inline yySymbol
975 yylhsNonterm (yyRuleNum yyrule
)
980 #define yyis_pact_ninf(yystate) \
981 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
983 [((yystate
) == YYPACT_NINF
)])[
985 /** True iff LR state STATE has only a default reduction (regardless
988 yyisDefaultedState (yyStateNum yystate
)
990 return yyis_pact_ninf (yypact
[yystate
]);
993 /** The default reduction for STATE, assuming it has one. */
994 static inline yyRuleNum
995 yydefaultAction (yyStateNum yystate
)
997 return yydefact
[yystate
];
1000 #define yyis_table_ninf(yytable_value) \
1001 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1003 [((yytable_value
) == YYTABLE_NINF
)])[
1005 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1007 * R < 0: Reduce on rule -R.
1009 * R > 0: Shift to state R.
1010 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1011 * conflicting reductions.
1014 yygetLRActions (yyStateNum yystate
, int yytoken
,
1015 int* yyaction
, const short int** yyconflicts
)
1017 int yyindex
= yypact
[yystate
] + yytoken
;
1018 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1020 *yyaction
= -yydefact
[yystate
];
1021 *yyconflicts
= yyconfl
;
1023 else if (! yyis_table_ninf (yytable
[yyindex
]))
1025 *yyaction
= yytable
[yyindex
];
1026 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1031 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1035 static inline yyStateNum
1036 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1039 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1040 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1041 return yytable
[yyr
];
1043 return yydefgoto
[yylhs
- YYNTOKENS
];
1046 static inline yybool
1047 yyisShiftAction (int yyaction
)
1049 return 0 < yyaction
;
1052 static inline yybool
1053 yyisErrorAction (int yyaction
)
1055 return yyaction
== 0;
1060 /** Return a fresh GLRStackItem. Callers should call
1061 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1064 static inline yyGLRStackItem
*
1065 yynewGLRStackItem (yyGLRStack
* yystack
, yybool yyisState
)
1067 yyGLRStackItem
* yynewItem
= yystack
->yynextFree
;
1068 yystack
->yyspaceLeft
-= 1;
1069 yystack
->yynextFree
+= 1;
1070 yynewItem
->yystate
.yyisState
= yyisState
;
1075 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
1076 yyGLRState
* rhs
, yyRuleNum yyrule
)
1078 yySemanticOption
* yynewOption
=
1079 &yynewGLRStackItem (yystack
, yyfalse
)->yyoption
;
1080 yynewOption
->yystate
= rhs
;
1081 yynewOption
->yyrule
= yyrule
;
1082 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1083 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1085 YY_RESERVE_GLRSTACK (yystack
);
1090 /** Initialize SET to a singleton set containing an empty stack. */
1092 yyinitStateSet (yyGLRStateSet
* yyset
)
1095 yyset
->yycapacity
= 16;
1096 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1097 if (! yyset
->yystates
)
1099 yyset
->yystates
[0] = NULL
;
1103 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1105 YYFREE (yyset
->yystates
);
1108 /** Initialize STACK to a single empty stack, with total maximum
1109 * capacity for all stacks of SIZE. */
1111 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
1113 yystack
->yyerrState
= 0;
1115 yystack
->yyspaceLeft
= yysize
;
1117 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystack
->yynextFree
[0]);
1118 if (!yystack
->yyitems
)
1120 yystack
->yynextFree
= yystack
->yyitems
;
1121 yystack
->yysplitPoint
= NULL
;
1122 yystack
->yylastDeleted
= NULL
;
1123 return yyinitStateSet (&yystack
->yytops
);
1127 #if YYSTACKEXPANDABLE
1128 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1129 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1131 /** If STACK is expandable, extend it. WARNING: Pointers into the
1132 stack from outside should be considered invalid after this call.
1133 We always expand when there are 1 or fewer items left AFTER an
1134 allocation, so that we can avoid having external pointers exist
1135 across an allocation. */
1137 yyexpandGLRStack (yyGLRStack
* yystack
)
1139 yyGLRStackItem
* yynewItems
;
1140 yyGLRStackItem
* yyp0
, *yyp1
;
1141 size_t yysize
, yynewSize
;
1143 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
1144 if (YYMAXDEPTH
<= yysize
)
1145 yyMemoryExhausted (yystack
);
1146 yynewSize
= 2*yysize
;
1147 if (YYMAXDEPTH
< yynewSize
)
1148 yynewSize
= YYMAXDEPTH
;
1149 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1151 yyMemoryExhausted (yystack
);
1152 for (yyp0
= yystack
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1154 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1157 if (*(yybool
*) yyp0
)
1159 yyGLRState
* yys0
= &yyp0
->yystate
;
1160 yyGLRState
* yys1
= &yyp1
->yystate
;
1161 if (yys0
->yypred
!= NULL
)
1163 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1164 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1165 yys1
->yysemantics
.yyfirstVal
=
1166 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1170 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1171 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1172 if (yyv0
->yystate
!= NULL
)
1173 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1174 if (yyv0
->yynext
!= NULL
)
1175 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1178 if (yystack
->yysplitPoint
!= NULL
)
1179 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewItems
,
1180 yystack
->yysplitPoint
, yystate
);
1182 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
1183 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
1184 yystack
->yytops
.yystates
[yyn
] =
1185 YYRELOC (yystack
->yyitems
, yynewItems
,
1186 yystack
->yytops
.yystates
[yyn
], yystate
);
1187 YYFREE (yystack
->yyitems
);
1188 yystack
->yyitems
= yynewItems
;
1189 yystack
->yynextFree
= yynewItems
+ yysize
;
1190 yystack
->yyspaceLeft
= yynewSize
- yysize
;
1195 yyfreeGLRStack (yyGLRStack
* yystack
)
1197 YYFREE (yystack
->yyitems
);
1198 yyfreeStateSet (&yystack
->yytops
);
1201 /** Assuming that S is a GLRState somewhere on STACK, update the
1202 * splitpoint of STACK, if needed, so that it is at least as deep as
1205 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
1207 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
1208 yystack
->yysplitPoint
= yys
;
1211 /** Invalidate stack #K in STACK. */
1213 yymarkStackDeleted (yyGLRStack
* yystack
, size_t yyk
)
1215 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1216 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
1217 yystack
->yytops
.yystates
[yyk
] = NULL
;
1220 /** Undelete the last stack that was marked as deleted. Can only be
1221 done once after a deletion, and only when all other stacks have
1224 yyundeleteLastStack (yyGLRStack
* yystack
)
1226 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
1228 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
1229 yystack
->yytops
.yysize
= 1;
1230 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1231 yystack
->yylastDeleted
= NULL
;
1235 yyremoveDeletes (yyGLRStack
* yystack
)
1239 while (yyj
< yystack
->yytops
.yysize
)
1241 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
1245 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1247 yystack
->yytops
.yysize
-= 1;
1251 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
1254 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1255 (unsigned long int) yyi
, (unsigned long int) yyj
));
1263 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1264 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1266 yyglrShift (yyGLRStack
* yystack
, size_t yyk
, yyStateNum yylrState
,
1268 YYSTYPE yysval
, YYLTYPE
* yylocp
)
1270 yyGLRState
* yynewState
= &yynewGLRStackItem (yystack
, yytrue
)->yystate
;
1272 yynewState
->yylrState
= yylrState
;
1273 yynewState
->yyposn
= yyposn
;
1274 yynewState
->yyresolved
= yytrue
;
1275 yynewState
->yypred
= yystack
->yytops
.yystates
[yyk
];
1276 yynewState
->yysemantics
.yysval
= yysval
;
1277 yynewState
->yyloc
= *yylocp
;
1278 yystack
->yytops
.yystates
[yyk
] = yynewState
;
1280 YY_RESERVE_GLRSTACK (yystack
);
1283 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1284 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1285 * semantic value of YYRHS under the action for YYRULE. */
1287 yyglrShiftDefer (yyGLRStack
* yystack
, size_t yyk
, yyStateNum yylrState
,
1288 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1290 yyGLRState
* yynewState
= &yynewGLRStackItem (yystack
, yytrue
)->yystate
;
1292 yynewState
->yylrState
= yylrState
;
1293 yynewState
->yyposn
= yyposn
;
1294 yynewState
->yyresolved
= yyfalse
;
1295 yynewState
->yypred
= yystack
->yytops
.yystates
[yyk
];
1296 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1297 yystack
->yytops
.yystates
[yyk
] = yynewState
;
1299 /* Invokes YY_RESERVE_GLRSTACK. */
1300 yyaddDeferredAction (yystack
, yynewState
, rhs
, yyrule
);
1303 /** Pop the symbols consumed by reduction #RULE from the top of stack
1304 * #K of STACK, and perform the appropriate semantic action on their
1305 * semantic values. Assumes that all ambiguities in semantic values
1306 * have been previously resolved. Set *VALP to the resulting value,
1307 * and *LOCP to the computed location (if any). Return value is as
1308 * for userAction. */
1309 static inline YYRESULTTAG
1310 yydoAction (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1311 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1313 int yynrhs
= yyrhsLength (yyrule
);
1315 if (yystack
->yysplitPoint
== NULL
)
1317 /* Standard special case: single stack. */
1318 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1319 YYASSERT (yyk
== 0);
1320 yystack
->yynextFree
-= yynrhs
;
1321 yystack
->yyspaceLeft
+= yynrhs
;
1322 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1323 return yyuserAction (yyrule
, yynrhs
, rhs
,
1324 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1328 /* At present, doAction is never called in nondeterministic
1329 * mode, so this branch is never taken. It is here in
1330 * anticipation of a future feature that will allow immediate
1331 * evaluation of selected actions in nondeterministic mode. */
1334 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1335 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1336 = yystack
->yytops
.yystates
[yyk
];]b4_location_if([[
1338 /* Set default location. */
1339 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1340 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1345 yyupdateSplit (yystack
, yys
);
1346 yystack
->yytops
.yystates
[yyk
] = yys
;
1347 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1348 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1353 # define YY_REDUCE_PRINT(Args)
1355 # define YY_REDUCE_PRINT(Args) \
1358 yy_reduce_print Args; \
1359 } while (/*CONSTCOND*/ 0)
1361 /*----------------------------------------------------------.
1362 | Report that the RULE is going to be reduced on stack #K. |
1363 `----------------------------------------------------------*/
1366 yy_reduce_print (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1367 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1369 int yynrhs
= yyrhsLength (yyrule
);
1370 yybool yynormal
__attribute__ ((__unused__
)) =
1371 (yystack
->yysplitPoint
== NULL
);
1372 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1375 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1376 (unsigned long int) yyk
, yyrule
- 1,
1377 (unsigned long int) yyrline
[yyrule
]);
1378 /* Print the symbols being reduced, and their result. */
1379 //for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
1380 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1382 fprintf (stderr
, " $%d = ", yyi
);
1383 yysymprint (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1384 &]b4_rhs_value(yynrhs
, yyi
)[
1385 ]b4_location_if([, &]b4_rhs_location(yynrhs
, yyi
))[]dnl
1387 fprintf (stderr
, "\n");
1392 /** Pop items off stack #K of STACK according to grammar rule RULE,
1393 * and push back on the resulting nonterminal symbol. Perform the
1394 * semantic action associated with RULE and store its value with the
1395 * newly pushed state, if FORCEEVAL or if STACK is currently
1396 * unambiguous. Otherwise, store the deferred semantic action with
1397 * the new state. If the new state would have an identical input
1398 * position, LR state, and predecessor to an existing state on the stack,
1399 * it is identified with that existing state, eliminating stack #K from
1400 * the STACK. In this case, the (necessarily deferred) semantic value is
1401 * added to the options for the existing state's semantic value.
1403 static inline YYRESULTTAG
1404 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1405 yybool yyforceEval
]b4_user_formals
[)
1407 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1409 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1414 YY_REDUCE_PRINT ((yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1415 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1416 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1417 yyglrShift (yystack
, yyk
,
1418 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1419 yylhsNonterm (yyrule
)),
1420 yyposn
, yysval
, &yyloc
);
1426 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1427 yyStateNum yynewLRState
;
1429 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1435 yyupdateSplit (yystack
, yys
);
1436 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1438 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1439 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1440 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1441 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1443 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1444 yyp
= yystack
->yytops
.yystates
[yyi
];
1445 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1447 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1449 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1450 yymarkStackDeleted (yystack
, yyk
);
1451 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1452 (unsigned long int) yyk
,
1453 (unsigned long int) yyi
));
1459 yystack
->yytops
.yystates
[yyk
] = yys
;
1460 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1466 yysplitStack (yyGLRStack
* yystack
, size_t yyk
)
1468 if (yystack
->yysplitPoint
== NULL
)
1470 YYASSERT (yyk
== 0);
1471 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1473 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1475 yyGLRState
** yynewStates
;
1476 if (! ((yystack
->yytops
.yycapacity
1477 <= (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1479 (yyGLRState
**) YYREALLOC (yystack
->yytops
.yystates
,
1480 ((yystack
->yytops
.yycapacity
*= 2)
1481 * sizeof yynewStates
[0])))))
1482 yyMemoryExhausted (yystack
);
1483 yystack
->yytops
.yystates
= yynewStates
;
1485 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1486 = yystack
->yytops
.yystates
[yyk
];
1487 yystack
->yytops
.yysize
+= 1;
1488 return yystack
->yytops
.yysize
-1;
1491 /** True iff Y0 and Y1 represent identical options at the top level.
1492 * That is, they represent the same rule applied to RHS symbols
1493 * that produce the same terminal symbols. */
1495 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1497 if (yyy0
->yyrule
== yyy1
->yyrule
)
1499 yyGLRState
*yys0
, *yys1
;
1501 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1502 yyn
= yyrhsLength (yyy0
->yyrule
);
1504 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1505 if (yys0
->yyposn
!= yys1
->yyposn
)
1513 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1514 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1516 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1518 yyGLRState
*yys0
, *yys1
;
1520 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1521 yyn
= yyrhsLength (yyy0
->yyrule
);
1523 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1527 else if (yys0
->yyresolved
)
1529 yys1
->yyresolved
= yytrue
;
1530 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1532 else if (yys1
->yyresolved
)
1534 yys0
->yyresolved
= yytrue
;
1535 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1539 yySemanticOption
** yyz0p
;
1540 yySemanticOption
* yyz1
;
1541 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1542 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1545 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1547 else if (*yyz0p
== NULL
)
1552 else if (*yyz0p
< yyz1
)
1554 yySemanticOption
* yyz
= *yyz0p
;
1556 yyz1
= yyz1
->yynext
;
1557 (*yyz0p
)->yynext
= yyz
;
1559 yyz0p
= &(*yyz0p
)->yynext
;
1561 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1566 /** Y0 and Y1 represent two possible actions to take in a given
1567 * parsing state; return 0 if no combination is possible,
1568 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1570 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1572 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1573 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1577 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1582 if (p0
== 0 || p1
== 0)
1591 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1592 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1593 YYLTYPE
* yylocp
]b4_user_formals
[);
1596 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1601 YYASSERT (yys
->yypred
);
1602 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1605 if (! yys
->yyresolved
)
1607 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1608 &yys
->yysemantics
.yysval
, &yys
->yyloc
1612 yys
->yyresolved
= yytrue
;
1619 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1620 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1622 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1625 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1626 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1627 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_location_if([[
1629 /* Set default location. */
1630 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1631 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1632 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1633 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1638 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1640 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1643 yyGLRState
* yystates
[YYMAXRHS
];
1644 yyGLRState yyleftmost_state
;
1646 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1647 yystates
[yyi
] = yys
;
1650 yyleftmost_state
.yyposn
= 0;
1651 yystates
[0] = &yyleftmost_state
;
1656 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1657 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1658 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1661 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1662 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1663 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1664 (unsigned long int) yyx
->yystate
->yyposn
);
1665 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1667 if (yystates
[yyi
]->yyresolved
)
1669 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1670 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1671 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1673 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1674 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1675 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1676 (unsigned long int) yystates
[yyi
]->yyposn
);
1679 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1684 static void yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1685 yyGLRStack
* yystack
]b4_pure_formals
[)
1686 __attribute__ ((__noreturn__
));
1688 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1689 yyGLRStack
* yystack
]b4_pure_formals
[)
1695 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1696 YYFPRINTF (stderr
, "Option 1,\n");
1697 yyreportTree (yyx0
, 2);
1698 YYFPRINTF (stderr
, "\nOption 2,\n");
1699 yyreportTree (yyx1
, 2);
1700 YYFPRINTF (stderr
, "\n");
1702 yyFail (yystack
][]b4_pure_args
[, YY_("syntax is ambiguous"));
1706 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1707 * actions, and return the result. */
1709 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1710 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1712 yySemanticOption
* yybest
;
1713 yySemanticOption
** yypp
;
1716 yybest
= yyoptionList
;
1718 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1720 yySemanticOption
* yyp
= *yypp
;
1722 if (yyidenticalOptions (yybest
, yyp
))
1724 yymergeOptionSets (yybest
, yyp
);
1725 *yypp
= yyp
->yynext
;
1729 switch (yypreference (yybest
, yyp
))
1732 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1744 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1745 but some compilers complain if the default case is
1749 yypp
= &yyp
->yynext
;
1755 yySemanticOption
* yyp
;
1756 int yyprec
= yydprec
[yybest
->yyrule
];
1757 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1758 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1760 if (yyprec
== yydprec
[yyp
->yyrule
])
1764 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1765 yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1771 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1775 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1777 if (yystack
->yysplitPoint
!= NULL
)
1782 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1783 yys
!= yystack
->yysplitPoint
;
1784 yys
= yys
->yypred
, yyn
+= 1)
1786 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1793 yycompressStack (yyGLRStack
* yystack
)
1795 yyGLRState
* yyp
, *yyq
, *yyr
;
1797 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1800 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1801 yyp
!= yystack
->yysplitPoint
;
1802 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1805 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1806 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1807 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1808 yystack
->yysplitPoint
= NULL
;
1809 yystack
->yylastDeleted
= NULL
;
1813 yystack
->yynextFree
->yystate
= *yyr
;
1815 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1816 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1817 yystack
->yynextFree
+= 1;
1818 yystack
->yyspaceLeft
-= 1;
1823 yyprocessOneStack (yyGLRStack
* yystack
, size_t yyk
,
1824 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1828 const short int* yyconflicts
;
1830 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1832 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1834 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1835 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1836 (unsigned long int) yyk
, yystate
));
1838 YYASSERT (yystate
!= YYFINAL
);
1840 if (yyisDefaultedState (yystate
))
1842 yyrule
= yydefaultAction (yystate
);
1845 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1846 (unsigned long int) yyk
));
1847 yymarkStackDeleted (yystack
, yyk
);
1850 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1854 if (*yytokenp
== YYEMPTY
)
1856 YYDPRINTF ((stderr
, "Reading a token: "));
1858 *yytokenp
= YYTRANSLATE (yychar
);
1859 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1861 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1863 while (*yyconflicts
!= 0)
1865 size_t yynewStack
= yysplitStack (yystack
, yyk
);
1866 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1867 (unsigned long int) yynewStack
,
1868 (unsigned long int) yyk
));
1869 YYCHK (yyglrReduce (yystack
, yynewStack
,
1870 *yyconflicts
, yyfalse
]b4_user_args
[));
1871 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1872 yylvalp
, yyllocp
]b4_pure_args
[));
1876 if (yyisShiftAction (yyaction
))
1878 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yyk
));
1879 YY_SYMBOL_PRINT ("shifting", *yytokenp
, yylvalp
, yyllocp
);
1880 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1882 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
1883 (unsigned long int) yyk
,
1884 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1887 else if (yyisErrorAction (yyaction
))
1889 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1890 (unsigned long int) yyk
));
1891 yymarkStackDeleted (yystack
, yyk
);
1895 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_user_args
[));
1902 yyreportSyntaxError (yyGLRStack
* yystack
,
1903 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1908 if (yystack
->yyerrState
== 0)
1911 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1913 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1914 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1916 size_t yysize0
= yytnamerr (NULL
, yytokenName (*yytokenp
));
1917 size_t yysize
= yysize0
;
1919 yybool yysize_overflow
= yyfalse
;
1921 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1922 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1926 static char const yyunexpected
[] = "syntax error, unexpected %s";
1927 static char const yyexpecting
[] = ", expecting %s";
1928 static char const yyor
[] = " or %s";
1929 char yyformat
[sizeof yyunexpected
1930 + sizeof yyexpecting
- 1
1931 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1932 * (sizeof yyor
- 1))];
1933 char const *yyprefix
= yyexpecting
;
1935 /* Start YYX at -YYN if negative to avoid negative indexes in
1937 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1939 /* Stay within bounds of both yycheck and yytname. */
1940 int yychecklim
= YYLAST
- yyn
;
1941 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1944 yyarg
[0] = yytokenName (*yytokenp
);
1945 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1947 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1948 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1950 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1954 yyformat
[sizeof yyunexpected
- 1] = '\0';
1957 yyarg
[yycount
++] = yytokenName (yyx
);
1958 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
1959 yysize_overflow
|= yysize1
< yysize
;
1961 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1965 yyf
= YY_(yyformat
);
1966 yysize1
= yysize
+ strlen (yyf
);
1967 yysize_overflow
|= yysize1
< yysize
;
1970 if (!yysize_overflow
)
1971 yymsg
= (char *) YYMALLOC (yysize
);
1977 while ((*yyp
= *yyf
))
1979 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1981 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1990 yyerror (]b4_lyyerror_args
[yymsg
);
1995 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
1996 yyMemoryExhausted (yystack
);
2000 #endif /* YYERROR_VERBOSE */
2001 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2006 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
2007 YYLVALP, and YYLLOCP point to the syntactic category, semantic
2008 value, and location of the look-ahead. */
2010 yyrecoverSyntaxError (yyGLRStack
* yystack
,
2012 YYLTYPE
* YYOPTIONAL_LOC (yyllocp
)
2015 yySymbol
* const yytokenp
= yystack
->yytokenp
;
2019 if (yystack
->yyerrState
== 3)
2020 /* We just shifted the error token and (perhaps) took some
2021 reductions. Skip tokens until we can proceed. */
2024 if (*yytokenp
== YYEOF
)
2025 yyFail (yystack
][]b4_lpure_args
[, NULL
);
2026 if (*yytokenp
!= YYEMPTY
)
2028 /* We throw away the lookahead, but the error range
2029 of the shifted error token must take it into account. */
2030 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
2031 yyGLRStackItem yyerror_range
[3];
2032 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2033 yyerror_range
[2].yystate
.yyloc
= *yyllocp
;
2034 YYLLOC_DEFAULT (yys
->yyloc
, yyerror_range
, 2);]])[
2035 yydestruct ("Error: discarding",
2036 *yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[]b4_user_args
[);
2038 YYDPRINTF ((stderr
, "Reading a token: "));
2040 *yytokenp
= YYTRANSLATE (yychar
);
2041 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
2042 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
2043 if (yyis_pact_ninf (yyj
))
2046 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
2048 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
2051 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2055 /* Reduce to one stack. */
2056 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
2057 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
2059 if (yyk
>= yystack
->yytops
.yysize
)
2060 yyFail (yystack
][]b4_lpure_args
[, NULL
);
2061 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
2062 yymarkStackDeleted (yystack
, yyk
);
2063 yyremoveDeletes (yystack
);
2064 yycompressStack (yystack
);
2066 /* Now pop stack until we find a state that shifts the error token. */
2067 yystack
->yyerrState
= 3;
2068 while (yystack
->yytops
.yystates
[0] != NULL
)
2070 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
2071 yyj
= yypact
[yys
->yylrState
];
2072 if (! yyis_pact_ninf (yyj
))
2075 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2076 && yyisShiftAction (yytable
[yyj
]))
2078 /* Shift the error token having adjusted its location. */
2079 YYLTYPE yyerrloc
;]b4_location_if([[
2080 yystack
->yyerror_range
[2].yystate
.yyloc
= *yyllocp
;
2081 YYLLOC_DEFAULT (yyerrloc
, yystack
->yyerror_range
, 2);]])[
2082 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2083 yylvalp
, &yyerrloc
);
2084 yyglrShift (yystack
, 0, yytable
[yyj
],
2085 yys
->yyposn
, *yylvalp
, &yyerrloc
);
2086 yys
= yystack
->yytops
.yystates
[0];
2090 ]b4_location_if([[ yystack
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2091 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2092 yystack
->yytops
.yystates
[0] = yys
->yypred
;
2093 yystack
->yynextFree
-= 1;
2094 yystack
->yyspaceLeft
+= 1;
2096 if (yystack
->yytops
.yystates
[0] == NULL
)
2097 yyFail (yystack
][]b4_lpure_args
[, NULL
);
2100 #define YYCHK1(YYE) \
2110 goto yyuser_error; \
2114 } while (/*CONSTCOND*/ 0)
2121 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2132 #define yychar (yystack.yyrawchar)
2135 YYSTYPE
* const yylvalp
= &yylval
;
2136 YYLTYPE
* const yyllocp
= &yylloc
;
2138 YYDPRINTF ((stderr
, "Starting parse\n"));
2141 yylval
= yyval_default
;
2143 #if YYLTYPE_IS_TRIVIAL
2144 yylloc
.first_line
= yylloc
.last_line
= 1;
2145 yylloc
.first_column
= yylloc
.last_column
= 0;
2148 m4_ifdef([b4_initial_action
], [
2149 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2150 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2151 /* User initialization code. */
2153 m4_popdef([b4_dollar_dollar
])dnl
2154 m4_popdef([b4_at_dollar
])dnl
2155 /* Line __line__ of glr.c. */
2156 b4_syncline([@oline@
], [@ofile@
])])dnl
2158 if (! yyinitGLRStack (&yystack
, YYINITDEPTH
))
2159 goto yyexhaustedlab
;
2160 switch (YYSETJMP (yystack
.yyexception_buffer
))
2163 case 1: goto yyabortlab
;
2164 case 2: goto yyexhaustedlab
;
2165 default: goto yybuglab
;
2167 yystack
.yytokenp
= &yytoken
;
2168 yyglrShift (&yystack
, 0, 0, 0, yylval
, &yylloc
);
2173 /* For efficiency, we have two loops, the first of which is
2174 specialized to deterministic operation (single stack, no
2175 potential ambiguity). */
2181 const short int* yyconflicts
;
2183 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2184 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2185 if (yystate
== YYFINAL
)
2187 if (yyisDefaultedState (yystate
))
2189 yyrule
= yydefaultAction (yystate
);
2192 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= *yyllocp
;]])[
2193 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
2196 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2200 if (yytoken
== YYEMPTY
)
2202 YYDPRINTF ((stderr
, "Reading a token: "));
2204 yytoken
= YYTRANSLATE (yychar
);
2205 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylvalp
, yyllocp
);
2207 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2208 if (*yyconflicts
!= 0)
2210 if (yyisShiftAction (yyaction
))
2212 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylvalp
, yyllocp
);
2213 if (yytoken
!= YYEOF
)
2216 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
2217 if (0 < yystack
.yyerrState
)
2218 yystack
.yyerrState
-= 1;
2220 else if (yyisErrorAction (yyaction
))
2222 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= *yyllocp
;]])[
2223 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
2227 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2234 size_t yyn
= yystack
.yytops
.yysize
;
2235 for (yys
= 0; yys
< yyn
; yys
+= 1)
2236 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
2237 yylvalp
, yyllocp
]b4_lpure_args
[));
2240 yyremoveDeletes (&yystack
);
2241 if (yystack
.yytops
.yysize
== 0)
2243 yyundeleteLastStack (&yystack
);
2244 if (yystack
.yytops
.yysize
== 0)
2245 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2246 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2247 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2248 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= *yyllocp
;]])[
2249 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
2252 else if (yystack
.yytops
.yysize
== 1)
2254 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2255 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2256 yycompressStack (&yystack
);
2262 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
2263 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2279 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2284 if (yytoken
!= YYEOF
&& yytoken
!= YYEMPTY
)
2285 yydestruct ("Cleanup: discarding lookahead",
2286 yytoken
, yylvalp
]b4_location_if([, yyllocp
])[]b4_user_args
[);
2288 /* If the stack is well-formed, pop the stack until it is empty,
2289 destroying its entries as we go. But free the stack regardless
2290 of whether it is well-formed. */
2291 if (yystack
.yyitems
)
2293 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2297 yyGLRState
*yys
= yystates
[0];
2298 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2299 )[ yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2300 yystates
[0] = yys
->yypred
;
2301 yystack
.yynextFree
-= 1;
2302 yystack
.yyspaceLeft
+= 1;
2304 yyfreeGLRStack (&yystack
);
2310 /* DEBUGGING ONLY */
2312 static void yypstack (yyGLRStack
* yystack
, size_t yyk
)
2313 __attribute__ ((__unused__
));
2314 static void yypdumpstack (yyGLRStack
* yystack
) __attribute__ ((__unused__
));
2317 yy_yypstack (yyGLRState
* yys
)
2321 yy_yypstack (yys
->yypred
);
2322 fprintf (stderr
, " -> ");
2324 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2328 yypstates (yyGLRState
* yyst
)
2331 fprintf (stderr
, "<null>");
2334 fprintf (stderr
, "\n");
2338 yypstack (yyGLRStack
* yystack
, size_t yyk
)
2340 yypstates (yystack
->yytops
.yystates
[yyk
]);
2343 #define YYINDEX(YYX) \
2344 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
2348 yypdumpstack (yyGLRStack
* yystack
)
2350 yyGLRStackItem
* yyp
;
2352 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
2354 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystack
->yyitems
));
2355 if (*(yybool
*) yyp
)
2357 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2358 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2359 (unsigned long int) yyp
->yystate
.yyposn
,
2360 (long int) YYINDEX (yyp
->yystate
.yypred
));
2361 if (! yyp
->yystate
.yyresolved
)
2362 fprintf (stderr
, ", firstVal: %ld",
2363 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2367 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2368 yyp
->yyoption
.yyrule
,
2369 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2370 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2372 fprintf (stderr
, "\n");
2374 fprintf (stderr
, "Tops:");
2375 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
2376 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2377 (long int) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
2378 fprintf (stderr
, "\n");
2384 m4_if(b4_defines_flag
, 0, [],
2385 [@output @output_header_name@
2386 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
2387 [2002, 2003, 2004, 2005])
2389 b4_shared_declarations
2391 extern YYSTYPE b4_prefix
[]lval
;
2393 b4_location_if([b4_pure_if([],
2394 [extern YYLTYPE b4_prefix
[]lloc
;])