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 static void yyexpandGLRStack (yyGLRStack
* yystack
);
788 static void yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yymsg
)
789 __attribute__ ((__noreturn__
));
791 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yymsg
)
794 yyerror (]b4_yyerror_args
[yymsg
);
795 YYLONGJMP (yystack
->yyexception_buffer
, 1);
798 static void yyMemoryExhausted (yyGLRStack
* yystack
)
799 __attribute__ ((__noreturn__
));
801 yyMemoryExhausted (yyGLRStack
* yystack
)
803 YYLONGJMP (yystack
->yyexception_buffer
, 2);
806 #if YYDEBUG || YYERROR_VERBOSE
807 /** A printable representation of TOKEN. */
808 static inline const char*
809 yytokenName (yySymbol yytoken
)
811 if (yytoken
== YYEMPTY
)
814 return yytname
[yytoken
];
818 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
819 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
820 * containing the pointer to the next state in the chain. */
821 static void yyfillin (yyGLRStackItem
*, int, int) __attribute__ ((__unused__
));
823 yyfillin (yyGLRStackItem
*yyvsp
, int yylow0
, int yylow1
)
827 s
= yyvsp
[yylow0
].yystate
.yypred
;
828 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
830 YYASSERT (s
->yyresolved
);
831 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
832 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
833 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
834 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
838 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
839 * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
840 * For convenience, always return YYLOW1. */
841 static inline int yyfill (yyGLRStackItem
*, int *, int, yybool
)
842 __attribute__ ((__unused__
));
844 yyfill (yyGLRStackItem
*yyvsp
, int *yylow
, int yylow1
, yybool yynormal
)
846 if (!yynormal
&& yylow1
< *yylow
)
848 yyfillin (yyvsp
, *yylow
, yylow1
);
854 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
855 * and top stack item YYVSP. YYLVALP points to place to put semantic
856 * value ($$), and yylocp points to place for location information
857 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
858 * yyerr for YYERROR, yyabort for YYABORT. */
860 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
862 YYLTYPE
* YYOPTIONAL_LOC (yylocp
),
866 yybool yynormal
__attribute__ ((__unused__
)) =
867 (yystack
->yysplitPoint
== NULL
);
871 # define yyerrok (yystack->yyerrState = 0)
873 # define YYACCEPT return yyaccept
875 # define YYABORT return yyabort
877 # define YYERROR return yyerrok, yyerr
879 # define YYRECOVERING (yystack->yyerrState != 0)
881 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
883 # define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
885 # define YYBACKUP(Token, Value) \
886 return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
891 *yyvalp
= yyval_default
;
893 *yyvalp
= yyvsp
[YYFILL (1-yyrhslen
)].yystate
.yysemantics
.yysval
;
894 YYLLOC_DEFAULT (*yylocp
, yyvsp
- yyrhslen
, yyrhslen
);
895 ]b4_location_if([[ yystack
->yyerror_range
[1].yystate
.yyloc
= *yylocp
;
911 /* Line __line__ of glr.c. */
912 b4_syncline([@oline@
], [@ofile@
])
917 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
929 /* Bison grammar-table manipulation. */
931 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
933 /** Number of symbols composing the right hand side of rule #RULE. */
935 yyrhsLength (yyRuleNum yyrule
)
941 yydestroyGLRState (char const *yymsg
, yyGLRState
*yys
]b4_user_formals
[)
944 yydestruct (yymsg
, yystos
[yys
->yylrState
],
945 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
951 YYFPRINTF (stderr
, "%s unresolved ", yymsg
);
952 yysymprint (stderr
, yystos
[yys
->yylrState
],
953 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[]b4_user_args
[);
954 YYFPRINTF (stderr
, "\n");
958 if (yys
->yysemantics
.yyfirstVal
)
960 yySemanticOption
*yyoption
= yys
->yysemantics
.yyfirstVal
;
963 for (yyrh
= yyoption
->yystate
, yyn
= yyrhsLength (yyoption
->yyrule
);
965 yyrh
= yyrh
->yypred
, yyn
-= 1)
966 yydestroyGLRState (yymsg
, yyrh
]b4_user_args
[);
971 /** Left-hand-side symbol for rule #RULE. */
972 static inline yySymbol
973 yylhsNonterm (yyRuleNum yyrule
)
978 #define yyis_pact_ninf(yystate) \
979 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1],
981 [((yystate
) == YYPACT_NINF
)])[
983 /** True iff LR state STATE has only a default reduction (regardless
986 yyisDefaultedState (yyStateNum yystate
)
988 return yyis_pact_ninf (yypact
[yystate
]);
991 /** The default reduction for STATE, assuming it has one. */
992 static inline yyRuleNum
993 yydefaultAction (yyStateNum yystate
)
995 return yydefact
[yystate
];
998 #define yyis_table_ninf(yytable_value) \
999 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1],
1001 [((yytable_value
) == YYTABLE_NINF
)])[
1003 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
1005 * R < 0: Reduce on rule -R.
1007 * R > 0: Shift to state R.
1008 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
1009 * conflicting reductions.
1012 yygetLRActions (yyStateNum yystate
, int yytoken
,
1013 int* yyaction
, const short int** yyconflicts
)
1015 int yyindex
= yypact
[yystate
] + yytoken
;
1016 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
1018 *yyaction
= -yydefact
[yystate
];
1019 *yyconflicts
= yyconfl
;
1021 else if (! yyis_table_ninf (yytable
[yyindex
]))
1023 *yyaction
= yytable
[yyindex
];
1024 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1029 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
1033 static inline yyStateNum
1034 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
1037 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
1038 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
1039 return yytable
[yyr
];
1041 return yydefgoto
[yylhs
- YYNTOKENS
];
1044 static inline yybool
1045 yyisShiftAction (int yyaction
)
1047 return 0 < yyaction
;
1050 static inline yybool
1051 yyisErrorAction (int yyaction
)
1053 return yyaction
== 0;
1058 /** Return a fresh GLRStackItem. Callers should call
1059 * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
1062 static inline yyGLRStackItem
*
1063 yynewGLRStackItem (yyGLRStack
* yystack
, yybool yyisState
)
1065 yyGLRStackItem
* yynewItem
= yystack
->yynextFree
;
1066 yystack
->yyspaceLeft
-= 1;
1067 yystack
->yynextFree
+= 1;
1068 yynewItem
->yystate
.yyisState
= yyisState
;
1073 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
1074 yyGLRState
* rhs
, yyRuleNum yyrule
)
1076 yySemanticOption
* yynewOption
=
1077 &yynewGLRStackItem (yystack
, yyfalse
)->yyoption
;
1078 yynewOption
->yystate
= rhs
;
1079 yynewOption
->yyrule
= yyrule
;
1080 yynewOption
->yynext
= yystate
->yysemantics
.yyfirstVal
;
1081 yystate
->yysemantics
.yyfirstVal
= yynewOption
;
1083 YY_RESERVE_GLRSTACK (yystack
);
1088 /** Initialize SET to a singleton set containing an empty stack. */
1090 yyinitStateSet (yyGLRStateSet
* yyset
)
1093 yyset
->yycapacity
= 16;
1094 yyset
->yystates
= (yyGLRState
**) YYMALLOC (16 * sizeof yyset
->yystates
[0]);
1095 if (! yyset
->yystates
)
1097 yyset
->yystates
[0] = NULL
;
1101 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
1103 YYFREE (yyset
->yystates
);
1106 /** Initialize STACK to a single empty stack, with total maximum
1107 * capacity for all stacks of SIZE. */
1109 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
1111 yystack
->yyerrState
= 0;
1113 yystack
->yyspaceLeft
= yysize
;
1115 (yyGLRStackItem
*) YYMALLOC (yysize
* sizeof yystack
->yynextFree
[0]);
1116 if (!yystack
->yyitems
)
1118 yystack
->yynextFree
= yystack
->yyitems
;
1119 yystack
->yysplitPoint
= NULL
;
1120 yystack
->yylastDeleted
= NULL
;
1121 return yyinitStateSet (&yystack
->yytops
);
1125 #if YYSTACKEXPANDABLE
1126 # define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
1127 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
1129 /** If STACK is expandable, extend it. WARNING: Pointers into the
1130 stack from outside should be considered invalid after this call.
1131 We always expand when there are 1 or fewer items left AFTER an
1132 allocation, so that we can avoid having external pointers exist
1133 across an allocation. */
1135 yyexpandGLRStack (yyGLRStack
* yystack
)
1137 yyGLRStackItem
* yynewItems
;
1138 yyGLRStackItem
* yyp0
, *yyp1
;
1139 size_t yysize
, yynewSize
;
1141 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
1142 if (YYMAXDEPTH
<= yysize
)
1143 yyMemoryExhausted (yystack
);
1144 yynewSize
= 2*yysize
;
1145 if (YYMAXDEPTH
< yynewSize
)
1146 yynewSize
= YYMAXDEPTH
;
1147 yynewItems
= (yyGLRStackItem
*) YYMALLOC (yynewSize
* sizeof yynewItems
[0]);
1149 yyMemoryExhausted (yystack
);
1150 for (yyp0
= yystack
->yyitems
, yyp1
= yynewItems
, yyn
= yysize
;
1152 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
1155 if (*(yybool
*) yyp0
)
1157 yyGLRState
* yys0
= &yyp0
->yystate
;
1158 yyGLRState
* yys1
= &yyp1
->yystate
;
1159 if (yys0
->yypred
!= NULL
)
1161 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
1162 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
1163 yys1
->yysemantics
.yyfirstVal
=
1164 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
1168 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
1169 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
1170 if (yyv0
->yystate
!= NULL
)
1171 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
1172 if (yyv0
->yynext
!= NULL
)
1173 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
1176 if (yystack
->yysplitPoint
!= NULL
)
1177 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewItems
,
1178 yystack
->yysplitPoint
, yystate
);
1180 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
1181 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
1182 yystack
->yytops
.yystates
[yyn
] =
1183 YYRELOC (yystack
->yyitems
, yynewItems
,
1184 yystack
->yytops
.yystates
[yyn
], yystate
);
1185 YYFREE (yystack
->yyitems
);
1186 yystack
->yyitems
= yynewItems
;
1187 yystack
->yynextFree
= yynewItems
+ yysize
;
1188 yystack
->yyspaceLeft
= yynewSize
- yysize
;
1193 yyfreeGLRStack (yyGLRStack
* yystack
)
1195 YYFREE (yystack
->yyitems
);
1196 yyfreeStateSet (&yystack
->yytops
);
1199 /** Assuming that S is a GLRState somewhere on STACK, update the
1200 * splitpoint of STACK, if needed, so that it is at least as deep as
1203 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
1205 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
1206 yystack
->yysplitPoint
= yys
;
1209 /** Invalidate stack #K in STACK. */
1211 yymarkStackDeleted (yyGLRStack
* yystack
, size_t yyk
)
1213 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1214 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
1215 yystack
->yytops
.yystates
[yyk
] = NULL
;
1218 /** Undelete the last stack that was marked as deleted. Can only be
1219 done once after a deletion, and only when all other stacks have
1222 yyundeleteLastStack (yyGLRStack
* yystack
)
1224 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
1226 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
1227 yystack
->yytops
.yysize
= 1;
1228 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
1229 yystack
->yylastDeleted
= NULL
;
1233 yyremoveDeletes (yyGLRStack
* yystack
)
1237 while (yyj
< yystack
->yytops
.yysize
)
1239 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
1243 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
1245 yystack
->yytops
.yysize
-= 1;
1249 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
1252 YYDPRINTF ((stderr
, "Rename stack %lu -> %lu.\n",
1253 (unsigned long int) yyi
, (unsigned long int) yyj
));
1261 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1262 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1264 yyglrShift (yyGLRStack
* yystack
, size_t yyk
, yyStateNum yylrState
,
1266 YYSTYPE yysval
, YYLTYPE
* yylocp
)
1268 yyGLRState
* yynewState
= &yynewGLRStackItem (yystack
, yytrue
)->yystate
;
1270 yynewState
->yylrState
= yylrState
;
1271 yynewState
->yyposn
= yyposn
;
1272 yynewState
->yyresolved
= yytrue
;
1273 yynewState
->yypred
= yystack
->yytops
.yystates
[yyk
];
1274 yynewState
->yysemantics
.yysval
= yysval
;
1275 yynewState
->yyloc
= *yylocp
;
1276 yystack
->yytops
.yystates
[yyk
] = yynewState
;
1278 YY_RESERVE_GLRSTACK (yystack
);
1281 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1282 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1283 * semantic value of YYRHS under the action for YYRULE. */
1285 yyglrShiftDefer (yyGLRStack
* yystack
, size_t yyk
, yyStateNum yylrState
,
1286 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
)
1288 yyGLRState
* yynewState
= &yynewGLRStackItem (yystack
, yytrue
)->yystate
;
1290 yynewState
->yylrState
= yylrState
;
1291 yynewState
->yyposn
= yyposn
;
1292 yynewState
->yyresolved
= yyfalse
;
1293 yynewState
->yypred
= yystack
->yytops
.yystates
[yyk
];
1294 yynewState
->yysemantics
.yyfirstVal
= NULL
;
1295 yystack
->yytops
.yystates
[yyk
] = yynewState
;
1297 /* Invokes YY_RESERVE_GLRSTACK. */
1298 yyaddDeferredAction (yystack
, yynewState
, rhs
, yyrule
);
1301 /** Pop the symbols consumed by reduction #RULE from the top of stack
1302 * #K of STACK, and perform the appropriate semantic action on their
1303 * semantic values. Assumes that all ambiguities in semantic values
1304 * have been previously resolved. Set *VALP to the resulting value,
1305 * and *LOCP to the computed location (if any). Return value is as
1306 * for userAction. */
1307 static inline YYRESULTTAG
1308 yydoAction (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1309 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1311 int yynrhs
= yyrhsLength (yyrule
);
1313 if (yystack
->yysplitPoint
== NULL
)
1315 /* Standard special case: single stack. */
1316 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1317 YYASSERT (yyk
== 0);
1318 yystack
->yynextFree
-= yynrhs
;
1319 yystack
->yyspaceLeft
+= yynrhs
;
1320 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1321 return yyuserAction (yyrule
, yynrhs
, rhs
,
1322 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1326 /* At present, doAction is never called in nondeterministic
1327 * mode, so this branch is never taken. It is here in
1328 * anticipation of a future feature that will allow immediate
1329 * evaluation of selected actions in nondeterministic mode. */
1332 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1333 yys
= yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
1334 = yystack
->yytops
.yystates
[yyk
];]b4_location_if([[
1336 /* Set default location. */
1337 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yys
->yyloc
;]])[
1338 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1343 yyupdateSplit (yystack
, yys
);
1344 yystack
->yytops
.yystates
[yyk
] = yys
;
1345 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1346 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1351 # define YY_REDUCE_PRINT(Args)
1353 # define YY_REDUCE_PRINT(Args) \
1356 yy_reduce_print Args; \
1357 } while (/*CONSTCOND*/ 0)
1359 /*----------------------------------------------------------.
1360 | Report that the RULE is going to be reduced on stack #K. |
1361 `----------------------------------------------------------*/
1364 yy_reduce_print (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1365 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1367 int yynrhs
= yyrhsLength (yyrule
);
1368 yybool yynormal
__attribute__ ((__unused__
)) =
1369 (yystack
->yysplitPoint
== NULL
);
1370 yyGLRStackItem
* yyvsp
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1373 YYFPRINTF (stderr
, "Reducing stack %lu by rule %d (line %lu):\n",
1374 (unsigned long int) yyk
, yyrule
- 1,
1375 (unsigned long int) yyrline
[yyrule
]);
1376 /* Print the symbols being reduced, and their result. */
1377 //for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
1378 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1380 fprintf (stderr
, " $%d = ", yyi
);
1381 yysymprint (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
1382 &]b4_rhs_value(yynrhs
, yyi
)[
1383 ]b4_location_if([, &]b4_rhs_location(yynrhs
, yyi
))[]dnl
1385 fprintf (stderr
, "\n");
1390 /** Pop items off stack #K of STACK according to grammar rule RULE,
1391 * and push back on the resulting nonterminal symbol. Perform the
1392 * semantic action associated with RULE and store its value with the
1393 * newly pushed state, if FORCEEVAL or if STACK is currently
1394 * unambiguous. Otherwise, store the deferred semantic action with
1395 * the new state. If the new state would have an identical input
1396 * position, LR state, and predecessor to an existing state on the stack,
1397 * it is identified with that existing state, eliminating stack #K from
1398 * the STACK. In this case, the (necessarily deferred) semantic value is
1399 * added to the options for the existing state's semantic value.
1401 static inline YYRESULTTAG
1402 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1403 yybool yyforceEval
]b4_user_formals
[)
1405 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1407 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1412 YY_REDUCE_PRINT ((yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1413 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1414 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyrule
], &yysval
, &yyloc
);
1415 yyglrShift (yystack
, yyk
,
1416 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1417 yylhsNonterm (yyrule
)),
1418 yyposn
, yysval
, &yyloc
);
1424 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1425 yyStateNum yynewLRState
;
1427 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1433 yyupdateSplit (yystack
, yys
);
1434 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1436 "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
1437 (unsigned long int) yyk
, yyrule
- 1, yynewLRState
));
1438 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1439 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1441 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1442 yyp
= yystack
->yytops
.yystates
[yyi
];
1443 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1445 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1447 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1448 yymarkStackDeleted (yystack
, yyk
);
1449 YYDPRINTF ((stderr
, "Merging stack %lu into stack %lu.\n",
1450 (unsigned long int) yyk
,
1451 (unsigned long int) yyi
));
1457 yystack
->yytops
.yystates
[yyk
] = yys
;
1458 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1464 yysplitStack (yyGLRStack
* yystack
, size_t yyk
)
1466 if (yystack
->yysplitPoint
== NULL
)
1468 YYASSERT (yyk
== 0);
1469 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1471 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1473 yyGLRState
** yynewStates
;
1474 if (! ((yystack
->yytops
.yycapacity
1475 <= (YYSIZEMAX
/ (2 * sizeof yynewStates
[0])))
1477 (yyGLRState
**) YYREALLOC (yystack
->yytops
.yystates
,
1478 ((yystack
->yytops
.yycapacity
*= 2)
1479 * sizeof yynewStates
[0])))))
1480 yyMemoryExhausted (yystack
);
1481 yystack
->yytops
.yystates
= yynewStates
;
1483 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1484 = yystack
->yytops
.yystates
[yyk
];
1485 yystack
->yytops
.yysize
+= 1;
1486 return yystack
->yytops
.yysize
-1;
1489 /** True iff Y0 and Y1 represent identical options at the top level.
1490 * That is, they represent the same rule applied to RHS symbols
1491 * that produce the same terminal symbols. */
1493 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1495 if (yyy0
->yyrule
== yyy1
->yyrule
)
1497 yyGLRState
*yys0
, *yys1
;
1499 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1500 yyn
= yyrhsLength (yyy0
->yyrule
);
1502 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1503 if (yys0
->yyposn
!= yys1
->yyposn
)
1511 /** Assuming identicalOptions (Y0,Y1), destructively merge the
1512 * alternative semantic values for the RHS-symbols of Y1 and Y0. */
1514 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1516 yyGLRState
*yys0
, *yys1
;
1518 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1519 yyn
= yyrhsLength (yyy0
->yyrule
);
1521 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1525 else if (yys0
->yyresolved
)
1527 yys1
->yyresolved
= yytrue
;
1528 yys1
->yysemantics
.yysval
= yys0
->yysemantics
.yysval
;
1530 else if (yys1
->yyresolved
)
1532 yys0
->yyresolved
= yytrue
;
1533 yys0
->yysemantics
.yysval
= yys1
->yysemantics
.yysval
;
1537 yySemanticOption
** yyz0p
;
1538 yySemanticOption
* yyz1
;
1539 yyz0p
= &yys0
->yysemantics
.yyfirstVal
;
1540 yyz1
= yys1
->yysemantics
.yyfirstVal
;
1543 if (yyz1
== *yyz0p
|| yyz1
== NULL
)
1545 else if (*yyz0p
== NULL
)
1550 else if (*yyz0p
< yyz1
)
1552 yySemanticOption
* yyz
= *yyz0p
;
1554 yyz1
= yyz1
->yynext
;
1555 (*yyz0p
)->yynext
= yyz
;
1557 yyz0p
= &(*yyz0p
)->yynext
;
1559 yys1
->yysemantics
.yyfirstVal
= yys0
->yysemantics
.yyfirstVal
;
1564 /** Y0 and Y1 represent two possible actions to take in a given
1565 * parsing state; return 0 if no combination is possible,
1566 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1568 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1570 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1571 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1575 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1580 if (p0
== 0 || p1
== 0)
1589 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1590 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1591 YYLTYPE
* yylocp
]b4_user_formals
[);
1594 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1599 YYASSERT (yys
->yypred
);
1600 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1603 if (! yys
->yyresolved
)
1605 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1606 &yys
->yysemantics
.yysval
, &yys
->yyloc
1610 yys
->yyresolved
= yytrue
;
1617 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1618 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1620 yyGLRStackItem yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
+ 1];
1623 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1624 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1625 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
].yystate
.yypred
= yyopt
->yystate
;]b4_location_if([[
1627 /* Set default location. */
1628 yyrhsVals
[YYMAXRHS
+ YYMAXLEFT
- 1].yystate
.yyloc
= yyopt
->yystate
->yyloc
;]])[
1629 return yyuserAction (yyopt
->yyrule
, yynrhs
,
1630 yyrhsVals
+ YYMAXRHS
+ YYMAXLEFT
- 1,
1631 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1636 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1638 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1641 yyGLRState
* yystates
[YYMAXRHS
];
1642 yyGLRState yyleftmost_state
;
1644 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1645 yystates
[yyi
] = yys
;
1648 yyleftmost_state
.yyposn
= 0;
1649 yystates
[0] = &yyleftmost_state
;
1654 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1655 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1656 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1659 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
1660 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1661 yyx
->yyrule
, (unsigned long int) (yys
->yyposn
+ 1),
1662 (unsigned long int) yyx
->yystate
->yyposn
);
1663 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1665 if (yystates
[yyi
]->yyresolved
)
1667 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1668 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1669 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1671 YYFPRINTF (stderr
, "%*s%s <tokens %lu .. %lu>\n", yyindent
+2, "",
1672 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1673 (unsigned long int) (yystates
[yyi
- 1]->yyposn
+ 1),
1674 (unsigned long int) yystates
[yyi
]->yyposn
);
1677 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1682 static void yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1683 yyGLRStack
* yystack
]b4_pure_formals
[)
1684 __attribute__ ((__noreturn__
));
1686 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1687 yyGLRStack
* yystack
]b4_pure_formals
[)
1693 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1694 YYFPRINTF (stderr
, "Option 1,\n");
1695 yyreportTree (yyx0
, 2);
1696 YYFPRINTF (stderr
, "\nOption 2,\n");
1697 yyreportTree (yyx1
, 2);
1698 YYFPRINTF (stderr
, "\n");
1700 yyFail (yystack
][]b4_pure_args
[, YY_("syntax is ambiguous"));
1704 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1705 * actions, and return the result. */
1707 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1708 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1710 yySemanticOption
* yybest
;
1711 yySemanticOption
** yypp
;
1714 yybest
= yyoptionList
;
1716 for (yypp
= &yyoptionList
->yynext
; *yypp
!= NULL
; )
1718 yySemanticOption
* yyp
= *yypp
;
1720 if (yyidenticalOptions (yybest
, yyp
))
1722 yymergeOptionSets (yybest
, yyp
);
1723 *yypp
= yyp
->yynext
;
1727 switch (yypreference (yybest
, yyp
))
1730 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1742 /* This cannot happen so it is not worth a YYASSERT (yyfalse),
1743 but some compilers complain if the default case is
1747 yypp
= &yyp
->yynext
;
1753 yySemanticOption
* yyp
;
1754 int yyprec
= yydprec
[yybest
->yyrule
];
1755 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1756 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1758 if (yyprec
== yydprec
[yyp
->yyrule
])
1762 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1763 yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1769 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1773 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1775 if (yystack
->yysplitPoint
!= NULL
)
1780 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1781 yys
!= yystack
->yysplitPoint
;
1782 yys
= yys
->yypred
, yyn
+= 1)
1784 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1791 yycompressStack (yyGLRStack
* yystack
)
1793 yyGLRState
* yyp
, *yyq
, *yyr
;
1795 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1798 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1799 yyp
!= yystack
->yysplitPoint
;
1800 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1803 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1804 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1805 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1806 yystack
->yysplitPoint
= NULL
;
1807 yystack
->yylastDeleted
= NULL
;
1811 yystack
->yynextFree
->yystate
= *yyr
;
1813 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1814 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1815 yystack
->yynextFree
+= 1;
1816 yystack
->yyspaceLeft
-= 1;
1821 yyprocessOneStack (yyGLRStack
* yystack
, size_t yyk
,
1822 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1826 const short int* yyconflicts
;
1828 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1830 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1832 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1833 YYDPRINTF ((stderr
, "Stack %lu Entering state %d\n",
1834 (unsigned long int) yyk
, yystate
));
1836 YYASSERT (yystate
!= YYFINAL
);
1838 if (yyisDefaultedState (yystate
))
1840 yyrule
= yydefaultAction (yystate
);
1843 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1844 (unsigned long int) yyk
));
1845 yymarkStackDeleted (yystack
, yyk
);
1848 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_user_args
[));
1852 if (*yytokenp
== YYEMPTY
)
1854 YYDPRINTF ((stderr
, "Reading a token: "));
1856 *yytokenp
= YYTRANSLATE (yychar
);
1857 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1859 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1861 while (*yyconflicts
!= 0)
1863 size_t yynewStack
= yysplitStack (yystack
, yyk
);
1864 YYDPRINTF ((stderr
, "Splitting off stack %lu from %lu.\n",
1865 (unsigned long int) yynewStack
,
1866 (unsigned long int) yyk
));
1867 YYCHK (yyglrReduce (yystack
, yynewStack
,
1868 *yyconflicts
, yyfalse
]b4_user_args
[));
1869 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1870 yylvalp
, yyllocp
]b4_pure_args
[));
1874 if (yyisShiftAction (yyaction
))
1876 YYDPRINTF ((stderr
, "On stack %lu, ", (unsigned long int) yyk
));
1877 YY_SYMBOL_PRINT ("shifting", *yytokenp
, yylvalp
, yyllocp
);
1878 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1880 YYDPRINTF ((stderr
, "Stack %lu now in state #%d\n",
1881 (unsigned long int) yyk
,
1882 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1885 else if (yyisErrorAction (yyaction
))
1887 YYDPRINTF ((stderr
, "Stack %lu dies.\n",
1888 (unsigned long int) yyk
));
1889 yymarkStackDeleted (yystack
, yyk
);
1893 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_user_args
[));
1900 yyreportSyntaxError (yyGLRStack
* yystack
,
1901 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1906 if (yystack
->yyerrState
== 0)
1909 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1911 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1912 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1914 size_t yysize0
= yytnamerr (NULL
, yytokenName (*yytokenp
));
1915 size_t yysize
= yysize0
;
1917 yybool yysize_overflow
= yyfalse
;
1919 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1920 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1924 static char const yyunexpected
[] = "syntax error, unexpected %s";
1925 static char const yyexpecting
[] = ", expecting %s";
1926 static char const yyor
[] = " or %s";
1927 char yyformat
[sizeof yyunexpected
1928 + sizeof yyexpecting
- 1
1929 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1930 * (sizeof yyor
- 1))];
1931 char const *yyprefix
= yyexpecting
;
1933 /* Start YYX at -YYN if negative to avoid negative indexes in
1935 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1937 /* Stay within bounds of both yycheck and yytname. */
1938 int yychecklim
= YYLAST
- yyn
;
1939 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1942 yyarg
[0] = yytokenName (*yytokenp
);
1943 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1945 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1946 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1948 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1952 yyformat
[sizeof yyunexpected
- 1] = '\0';
1955 yyarg
[yycount
++] = yytokenName (yyx
);
1956 yysize1
= yysize
+ yytnamerr (NULL
, yytokenName (yyx
));
1957 yysize_overflow
|= yysize1
< yysize
;
1959 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1963 yyf
= YY_(yyformat
);
1964 yysize1
= yysize
+ strlen (yyf
);
1965 yysize_overflow
|= yysize1
< yysize
;
1968 if (!yysize_overflow
)
1969 yymsg
= (char *) YYMALLOC (yysize
);
1975 while ((*yyp
= *yyf
))
1977 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1979 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1988 yyerror (]b4_lyyerror_args
[yymsg
);
1993 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
1994 yyMemoryExhausted (yystack
);
1998 #endif /* YYERROR_VERBOSE */
1999 yyerror (]b4_lyyerror_args
[YY_("syntax error"));
2004 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
2005 YYLVALP, and YYLLOCP point to the syntactic category, semantic
2006 value, and location of the look-ahead. */
2008 yyrecoverSyntaxError (yyGLRStack
* yystack
,
2010 YYLTYPE
* YYOPTIONAL_LOC (yyllocp
)
2013 yySymbol
* const yytokenp
= yystack
->yytokenp
;
2017 if (yystack
->yyerrState
== 3)
2018 /* We just shifted the error token and (perhaps) took some
2019 reductions. Skip tokens until we can proceed. */
2022 if (*yytokenp
== YYEOF
)
2023 yyFail (yystack
][]b4_lpure_args
[, NULL
);
2024 if (*yytokenp
!= YYEMPTY
)
2026 /* We throw away the lookahead, but the error range
2027 of the shifted error token must take it into account. */
2028 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
2029 yyGLRStackItem yyerror_range
[3];
2030 yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;
2031 yyerror_range
[2].yystate
.yyloc
= *yyllocp
;
2032 YYLLOC_DEFAULT (yys
->yyloc
, yyerror_range
, 2);]])[
2033 yydestruct ("Error: discarding",
2034 *yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[]b4_user_args
[);
2036 YYDPRINTF ((stderr
, "Reading a token: "));
2038 *yytokenp
= YYTRANSLATE (yychar
);
2039 YY_SYMBOL_PRINT ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
2040 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
2041 if (yyis_pact_ninf (yyj
))
2044 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
2046 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
2049 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
2053 /* Reduce to one stack. */
2054 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
2055 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
2057 if (yyk
>= yystack
->yytops
.yysize
)
2058 yyFail (yystack
][]b4_lpure_args
[, NULL
);
2059 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
2060 yymarkStackDeleted (yystack
, yyk
);
2061 yyremoveDeletes (yystack
);
2062 yycompressStack (yystack
);
2064 /* Now pop stack until we find a state that shifts the error token. */
2065 yystack
->yyerrState
= 3;
2066 while (yystack
->yytops
.yystates
[0] != NULL
)
2068 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
2069 yyj
= yypact
[yys
->yylrState
];
2070 if (! yyis_pact_ninf (yyj
))
2073 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
2074 && yyisShiftAction (yytable
[yyj
]))
2076 /* Shift the error token having adjusted its location. */
2077 YYLTYPE yyerrloc
;]b4_location_if([[
2078 yystack
->yyerror_range
[2].yystate
.yyloc
= *yyllocp
;
2079 YYLLOC_DEFAULT (yyerrloc
, yystack
->yyerror_range
, 2);]])[
2080 YY_SYMBOL_PRINT ("Shifting", yystos
[yytable
[yyj
]],
2081 yylvalp
, &yyerrloc
);
2082 yyglrShift (yystack
, 0, yytable
[yyj
],
2083 yys
->yyposn
, *yylvalp
, &yyerrloc
);
2084 yys
= yystack
->yytops
.yystates
[0];
2088 ]b4_location_if([[ yystack
->yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]])[
2089 yydestroyGLRState ("Error: popping", yys
]b4_user_args
[);
2090 yystack
->yytops
.yystates
[0] = yys
->yypred
;
2091 yystack
->yynextFree
-= 1;
2092 yystack
->yyspaceLeft
+= 1;
2094 if (yystack
->yytops
.yystates
[0] == NULL
)
2095 yyFail (yystack
][]b4_lpure_args
[, NULL
);
2098 #define YYCHK1(YYE) \
2108 goto yyuser_error; \
2112 } while (/*CONSTCOND*/ 0)
2119 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
2130 #define yychar (yystack.yyrawchar)
2133 YYSTYPE
* const yylvalp
= &yylval
;
2134 YYLTYPE
* const yyllocp
= &yylloc
;
2136 YYDPRINTF ((stderr
, "Starting parse\n"));
2139 yylval
= yyval_default
;
2141 #if YYLTYPE_IS_TRIVIAL
2142 yylloc
.first_line
= yylloc
.last_line
= 1;
2143 yylloc
.first_column
= yylloc
.last_column
= 0;
2146 m4_ifdef([b4_initial_action
], [
2147 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
2148 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
2149 /* User initialization code. */
2151 m4_popdef([b4_dollar_dollar
])dnl
2152 m4_popdef([b4_at_dollar
])dnl
2153 /* Line __line__ of glr.c. */
2154 b4_syncline([@oline@
], [@ofile@
])])dnl
2156 if (! yyinitGLRStack (&yystack
, YYINITDEPTH
))
2157 goto yyexhaustedlab
;
2158 switch (YYSETJMP (yystack
.yyexception_buffer
))
2161 case 1: goto yyabortlab
;
2162 case 2: goto yyexhaustedlab
;
2163 default: goto yybuglab
;
2165 yystack
.yytokenp
= &yytoken
;
2166 yyglrShift (&yystack
, 0, 0, 0, yylval
, &yylloc
);
2171 /* For efficiency, we have two loops, the first of which is
2172 specialized to deterministic operation (single stack, no
2173 potential ambiguity). */
2179 const short int* yyconflicts
;
2181 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
2182 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
2183 if (yystate
== YYFINAL
)
2185 if (yyisDefaultedState (yystate
))
2187 yyrule
= yydefaultAction (yystate
);
2190 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= *yyllocp
;]])[
2191 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
2194 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_user_args
[));
2198 if (yytoken
== YYEMPTY
)
2200 YYDPRINTF ((stderr
, "Reading a token: "));
2202 yytoken
= YYTRANSLATE (yychar
);
2203 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylvalp
, yyllocp
);
2205 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
2206 if (*yyconflicts
!= 0)
2208 if (yyisShiftAction (yyaction
))
2210 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylvalp
, yyllocp
);
2211 if (yytoken
!= YYEOF
)
2214 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
2215 if (0 < yystack
.yyerrState
)
2216 yystack
.yyerrState
-= 1;
2218 else if (yyisErrorAction (yyaction
))
2220 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= *yyllocp
;]])[
2221 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
2225 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_user_args
[));
2232 size_t yyn
= yystack
.yytops
.yysize
;
2233 for (yys
= 0; yys
< yyn
; yys
+= 1)
2234 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
2235 yylvalp
, yyllocp
]b4_lpure_args
[));
2238 yyremoveDeletes (&yystack
);
2239 if (yystack
.yytops
.yysize
== 0)
2241 yyundeleteLastStack (&yystack
);
2242 if (yystack
.yytops
.yysize
== 0)
2243 yyFail (&yystack
][]b4_lpure_args
[, YY_("syntax error"));
2244 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2245 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2246 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= *yyllocp
;]])[
2247 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
2250 else if (yystack
.yytops
.yysize
== 1)
2252 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
2253 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
2254 yycompressStack (&yystack
);
2260 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
2261 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
2277 yyerror (]b4_lyyerror_args
[YY_("memory exhausted"));
2282 if (yytoken
!= YYEOF
&& yytoken
!= YYEMPTY
)
2283 yydestruct ("Cleanup: discarding lookahead",
2284 yytoken
, yylvalp
]b4_location_if([, yyllocp
])[]b4_user_args
[);
2286 /* If the stack is well-formed, pop the stack until it is empty,
2287 destroying its entries as we go. But free the stack regardless
2288 of whether it is well-formed. */
2289 if (yystack
.yyitems
)
2291 yyGLRState
** yystates
= yystack
.yytops
.yystates
;
2295 yyGLRState
*yys
= yystates
[0];
2296 ]b4_location_if([[ yystack
.yyerror_range
[1].yystate
.yyloc
= yys
->yyloc
;]]
2297 )[ yydestroyGLRState ("Cleanup: popping", yys
]b4_user_args
[);
2298 yystates
[0] = yys
->yypred
;
2299 yystack
.yynextFree
-= 1;
2300 yystack
.yyspaceLeft
+= 1;
2302 yyfreeGLRStack (&yystack
);
2308 /* DEBUGGING ONLY */
2310 static void yypstack (yyGLRStack
* yystack
, size_t yyk
)
2311 __attribute__ ((__unused__
));
2312 static void yypdumpstack (yyGLRStack
* yystack
) __attribute__ ((__unused__
));
2315 yy_yypstack (yyGLRState
* yys
)
2319 yy_yypstack (yys
->yypred
);
2320 fprintf (stderr
, " -> ");
2322 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long int) yys
->yyposn
);
2326 yypstates (yyGLRState
* yyst
)
2329 fprintf (stderr
, "<null>");
2332 fprintf (stderr
, "\n");
2336 yypstack (yyGLRStack
* yystack
, size_t yyk
)
2338 yypstates (yystack
->yytops
.yystates
[yyk
]);
2341 #define YYINDEX(YYX) \
2342 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
2346 yypdumpstack (yyGLRStack
* yystack
)
2348 yyGLRStackItem
* yyp
;
2350 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
2352 fprintf (stderr
, "%3lu. ", (unsigned long int) (yyp
- yystack
->yyitems
));
2353 if (*(yybool
*) yyp
)
2355 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
2356 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
2357 (unsigned long int) yyp
->yystate
.yyposn
,
2358 (long int) YYINDEX (yyp
->yystate
.yypred
));
2359 if (! yyp
->yystate
.yyresolved
)
2360 fprintf (stderr
, ", firstVal: %ld",
2361 (long int) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
2365 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
2366 yyp
->yyoption
.yyrule
,
2367 (long int) YYINDEX (yyp
->yyoption
.yystate
),
2368 (long int) YYINDEX (yyp
->yyoption
.yynext
));
2370 fprintf (stderr
, "\n");
2372 fprintf (stderr
, "Tops:");
2373 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
2374 fprintf (stderr
, "%lu: %ld; ", (unsigned long int) yyi
,
2375 (long int) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
2376 fprintf (stderr
, "\n");
2382 m4_if(b4_defines_flag
, 0, [],
2383 [@output @output_header_name@
2384 b4_copyright([Skeleton parser
for GLR parsing with Bison
],
2385 [2002, 2003, 2004, 2005])
2387 b4_shared_declarations
2389 extern YYSTYPE b4_prefix
[]lval
;
2391 b4_location_if([b4_pure_if([],
2392 [extern YYLTYPE b4_prefix
[]lloc
;])