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