1 m4_divert(-1) -*- YYC
-*-
5 # Return the smallest signed int type able to handle the number MAX.
6 m4_define([b4_sint_type
],
7 [m4_if(m4_eval([$
1 <= 127]), [1], [signed char],
8 m4_eval([$
1 <= 32767]), [1], [signed short],
13 # Return the smallest unsigned int type able to handle the number MAX.
14 m4_define([b4_uint_type
],
15 [m4_if(m4_eval([$
1 <= 255]), [1], [unsigned char],
16 m4_eval([$
1 <= 65535]), [1], [unsigned short],
20 # b4_lhs_value([TYPE])
21 # --------------------
22 # Expansion of $<TYPE>$.
23 m4_define([b4_lhs_value
],
24 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
27 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
28 # --------------------------------------
29 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
31 m4_define([b4_rhs_value
],
32 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
40 # b4_location_if(IF-TRUE, IF-FALSE)
41 # ---------------------------------
42 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
43 m4_define([b4_location_if
],
44 [m4_if(b4_locations_flag
, [1],
52 m4_define([b4_lhs_location
],
56 # b4_rhs_location(RULE-LENGTH, NUM)
57 # ---------------------------------
58 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
60 m4_define([b4_rhs_location
],
61 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
69 # b4_pure_if(IF-TRUE, IF-FALSE)
70 # -----------------------------
71 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
72 m4_define([b4_pure_if
],
78 ## ------------------- ##
79 ## Output file names. ##
80 ## ------------------- ##
82 m4_define_default([b4_input_suffix
], [.y
])
84 m4_define_default([b4_output_parser_suffix
],
85 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
87 m4_define_default([b4_output_parser_name
],
88 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
91 m4_define_default([b4_output_header_suffix
],
92 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
94 m4_define_default([b4_output_header_name
],
95 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
97 m4_define_default([b4_header_guard
],
98 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
99 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
102 ## ------------------------- ##
103 ## Assigning token numbers. ##
104 ## ------------------------- ##
106 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
107 # -----------------------------------------
108 # Output the definition of this token as #define.
109 m4_define([b4_token_define
],
114 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
115 # ---------------------------------------
116 # Output the definition of this token as an enum.
117 m4_define([b4_token_enum
],
121 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
122 # -------------------------------------------------------
123 # Output the definition of the tokens (if there are) as enums and #define.
124 m4_define([b4_token_defines
],
125 [m4_if([$@
], [[]], [],
128 # if defined (__STDC__) || defined (__cplusplus)
129 /* Put the tokens into the symbol table, so that GDB and other debuggers
132 m4_map_sep([ b4_token_enum
], [,
137 /* POSIX requires `int' for tokens in interfaces. */
138 # define YYTOKENTYPE int
139 #endif /* !YYTOKENTYPE */
140 m4_map([b4_token_define
], [$@
])
146 #output "b4_output_parser_name"
147 [/* Skeleton parser for GLR parsing with Bison,
148 Copyright (C) 2002 Free Software Foundation, Inc.
150 This program is free software; you can redistribute it and/or modify
151 it under the terms of the GNU General Public License as published by
152 the Free Software Foundation; either version 2, or (at your option)
155 This program is distributed in the hope that it will be useful,
156 but WITHOUT ANY WARRANTY; without even the implied warranty of
157 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
158 GNU General Public License for more details.
160 You should have received a copy of the GNU General Public License
161 along with this program; if not, write to the Free Software
162 Foundation, Inc., 59 Temple Place - Suite 330,
163 Boston, MA 02111-1307, USA. */
165 /* As a special exception, when this file is copied by Bison into a
166 Bison output file, you may use that output file without restriction.
167 This special exception was added by the Free Software Foundation
168 in version 1.24 of Bison. */
170 /* This is the parser code for GLR (Generalized LR) parser. */
172 /* FIXME: minimize these */
179 /* Identify Bison output. */
183 #define YYPURE ]b4_pure[
185 /* Using locations. */
186 #define YYLSP_NEEDED ]b4_locations_flag[
188 ]m4_if(b4_prefix
[], [yy
], [],
189 [/* If NAME_PREFIX is specified substitute the variables and functions
191 #define yyparse b4_prefix[]parse
192 #define yylex b4_prefix[]lex
193 #define yyerror b4_prefix[]error
194 #define yylval b4_prefix[]lval
195 #define yychar b4_prefix[]char
196 #define yydebug b4_prefix[]debug
197 #define yynerrs b4_prefix[]nerrs
198 b4_location_if([#define yylloc b4_prefix[]lloc])])
200 /* Copy the first part of user declarations. */
203 b4_token_defines(b4_tokens
)[
205 /* Enabling traces. */
207 # define YYDEBUG ]b4_debug[
210 /* Enabling verbose error messages. */
211 #ifdef YYERROR_VERBOSE
212 # undef YYERROR_VERBOSE
213 # define YYERROR_VERBOSE 1
215 # define YYERROR_VERBOSE ]b4_error_verbose[
219 ]m4_ifdef([b4_stype
],
220 [#line b4_stype_line "b4_filename"
221 typedef union b4_stype yystype
;
222 /* Line __line__ of __file__. */
223 #line __oline__ "__ofile__"],
224 [typedef int yystype
;])[
225 # define YYSTYPE yystype
226 # define YYSTYPE_IS_TRIVIAL 1
230 typedef struct yyltype
236 int yylast_column
;])[
238 # define YYLTYPE ]b4_ltype[
239 # define YYLTYPE_IS_TRIVIAL 1
242 /* Default (constant) values used for initialization for null
243 right-hand sides. Unlike the standard bison.simple template,
244 here we set the default values of the $$ and $@ to zeroed-out
245 values. Since the default value of these quantities is undefined,
246 this behavior is technically correct. */
247 static YYSTYPE yyval_default
;
248 static YYLTYPE yyloc_default
;
250 /* Copy the second part of user declarations. */
253 ]/* Line __line__ of __file__. */
254 #line __oline__ "__ofile__"
256 #if ! defined (__cplusplus)
262 #if ! defined (yy__GNUC__)
266 /* YYFINAL -- State number of the termination state. */
267 #define YYFINAL ]b4_final[
268 #define YYFLAG ]b4_flag[
269 #define YYLAST ]b4_last[
271 /* YYNTOKENS -- Number of terminals. */
272 #define YYNTOKENS ]b4_ntokens[
273 /* YYNNTS -- Number of nonterminals. */
274 #define YYNNTS ]b4_nnts[
275 /* YYNRULES -- Number of rules. */
276 #define YYNRULES ]b4_nrules[
277 /* YYNRULES -- Number of states. */
278 #define YYNSTATES ]b4_nstates[
279 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
280 #define YYMAXRHS ]b4_r2_max[
282 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
283 #define YYUNDEFTOK ]b4_undef_token_number[
284 #define YYMAXUTOK ]b4_user_token_number_max[
286 #define YYTRANSLATE(YYX) \
287 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
289 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
290 static const ]b4_uint_type(b4_translate_max
)[ yytranslate
[] =
296 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
298 static const ]b4_uint_type(b4_prhs_max
)[ yyprhs
[] =
303 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
304 static const ]b4_sint_type(b4_rhs_max
)[ yyrhs
[] =
309 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
310 static const ]b4_uint_type(b4_rline_max
)[ yyrline
[] =
316 #if (YYDEBUG) || YYERROR_VERBOSE
317 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
318 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
319 static const char *const yytname
[] =
324 #define yytname_size (sizeof (yytname) / sizeof (yytname[0]))
327 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
328 static const ]b4_uint_type(b4_r1_max
)[ yyr1
[] =
333 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
334 static const ]b4_uint_type(b4_r2_max
)[ yyr2
[] =
339 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
340 static const short yydprec
[] =
345 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
346 static const short yymerger
[] =
351 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
352 doesn't specify something else to do. Zero means the default is an
354 static const short yydefact
[] =
359 /* YYPGOTO[NTERM-NUM]. */
360 static const short yydefgoto
[] =
365 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
367 static const short yypact
[] =
372 /* YYPGOTO[NTERM-NUM]. */
373 static const short yypgoto
[] =
378 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
379 positive, shift that token. If negative, reduce the rule which
380 number is the opposite. If zero, do what YYDEFACT says. */
381 static const short yytable
[] =
386 /* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list
387 of conflicting reductions corresponding to action entry for state
388 STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
389 is terminated by a rule number of 0. */
390 static const short yyconflp
[] =
392 ]b4_conflict_list_heads
[
395 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
396 by 0, pointed into by YYCONFLP. */
397 static const short yyconfl
[] =
399 ]b4_conflicting_rules
[
402 static const short yycheck
[] =
408 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
409 into yyparse. The argument should have type void *.
410 It should actually point to an object.
411 Grammar actions can access the variable by casting it
412 to the proper pointer type. */
415 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
416 #else /* !YYPARSE_PARAM */
417 # define YYPARSE_PARAM_ARG void
418 #endif /* !YYPARSE_PARAM */
420 /* Prevent warning if -Wstrict-prototypes. */
422 # ifdef YYPARSE_PARAM
423 int yyparse (void *);
429 /* Error token number */
432 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
435 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
437 #ifndef YYLLOC_DEFAULT
438 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
439 yyCurrent.yyfirst_line = YYRHSLOC(yyRhs,1).yyfirst_line; \
440 yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \
441 yyCurrent.yylast_line = YYRHSLOC(yyRhs,YYN).yylast_line; \
442 yyCurrent.yylast_column = YYRHSLOC(yyRhs,YYN).yylast_column;
445 /* YYLEX -- calling `yylex' with the right arguments. */
450 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
452 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
454 [#define YYLEX yylex ()])
459 #define yynerrs (yystack->yyerrcnt)
461 #define yychar (yystack->yyrawchar)],
469 static const int YYEOF
= 0;
470 static const int YYEMPTY
= -2;
472 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
475 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
480 #if ! defined (YYFPRINTF)
481 # define YYFPRINTF fprintf
484 # define YYDPRINTF(Args) \
489 /* Nonzero means print parse trace. It is left uninitialized so that
490 multiple parsers can coexist. */
493 # define YYDPRINTF(Args)
494 #endif /* !YYDEBUG */
496 /* YYINITDEPTH -- initial size of the parser's stacks. */
498 # define YYINITDEPTH ]b4_initdepth[
501 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
502 if the built-in stack extension method is used).
504 Do not make this value too large; the results are undefined if
505 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
506 evaluated with infinite-precision integer arithmetic. */
513 # define YYMAXDEPTH ]b4_maxdepth[
516 /* Minimum number of free items on the stack allowed after an
517 allocation. This is to allow allocation and initialization
518 to be completed by functions that call expandGLRStack before the
519 stack is expanded, thus insuring that all necessary pointers get
520 properly redirected to new data. */
523 #if ! defined (YYSTACKEXPANDABLE) \
524 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
525 #define YYSTACKEXPANDABLE 1
527 #define YYSTACKEXPANDABLE 0
530 /** State numbers, as in LALR(1) machine */
531 typedef int yyStateNum
;
533 /** Rule numbers, as in LALR(1) machine */
534 typedef int yyRuleNum
;
536 /** Grammar symbol */
537 typedef short yySymbol
;
539 /** Item references, as in LALR(1) machine */
540 typedef short yyItemNum
;
542 typedef struct yyGLRState yyGLRState
;
543 typedef struct yySemanticOption yySemanticOption
;
544 typedef union yyGLRStackItem yyGLRStackItem
;
545 typedef struct yyGLRStack yyGLRStack
;
546 typedef struct yyGLRStateSet yyGLRStateSet
;
551 yyStateNum yylrState
;
555 yySemanticOption
* yyfirstVal
;
561 struct yyGLRStateSet
{
562 yyGLRState
** yystates
;
563 size_t yysize
, yycapacity
;
566 struct yySemanticOption
{
570 yySemanticOption
* yynext
;
573 union yyGLRStackItem
{
575 yySemanticOption yyoption
;
587 jmp_buf yyexception_buffer
;
588 yyGLRStackItem
* yyitems
;
589 yyGLRStackItem
* yynextFree
;
591 yyGLRState
* yysplitPoint
;
592 yyGLRState
* yylastDeleted
;
593 yyGLRStateSet yytops
;
596 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
597 static void yyexpandGLRStack (yyGLRStack
* yystack
);
598 static void yyfreeGLRStack (yyGLRStack
* yystack
);
601 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
603 if (yyformat
!= NULL
)
607 va_start (yyap
, yyformat
);
608 yystack
->yyerrflag
= 1;
609 vsprintf (yymsg
, yyformat
, yyap
);
612 longjmp (yystack
->yyexception_buffer
, 1);
615 #if YYDEBUG || YYERROR_VERBOSE
616 /** A printable representation of TOKEN. Valid until next call to
618 static inline const char*
619 yytokenName (yySymbol yytoken
)
621 return yytname
[yytoken
];
625 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
626 * and top stack item YYVSP. YYLVALP points to place to put semantic
627 * value ($$), and yylocp points to place for location information
628 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
629 * yyerr for YYERROR, yyabort for YYABORT. */
631 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
632 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
636 *yyvalp
= yyval_default
;
637 *yylocp
= yyloc_default
;
641 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
642 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
645 # define yyval (*yyvalp)
647 # define yyerrok (yystack->yyerrState = 0)
649 # define YYACCEPT return yyaccept
651 # define YYABORT return yyabort
653 # define YYERROR return yyerr
655 # define YYRECOVERING (yystack->yyerrState != 0)
657 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
659 # define YYBACKUP(Token, Value) \
661 yyerror ("syntax error: cannot back up"); \
680 /* Line __line__ of __file__. */
681 #line __oline__ "__ofile__"
686 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
688 YYSTYPE yyval
= *yy0
;
696 /* Bison grammar-table manipulation */
698 /** Number of symbols composing the right hand side of rule #RULE. */
700 yyrhsLength (yyRuleNum yyrule
)
705 /** Left-hand-side symbol for rule #RULE. */
706 static inline yySymbol
707 yylhsNonterm (yyRuleNum yyrule
)
712 /** True iff LR state STATE has only a default reduction (regardless
715 yyisDefaultedState (yyStateNum yystate
)
717 return yypact
[yystate
] == YYFLAG
;
720 /** The default reduction for STATE, assuming it has one. */
721 static inline yyRuleNum
722 yydefaultAction (yyStateNum yystate
)
724 return yydefact
[yystate
];
727 /** Set *ACTION to the action to take in STATE on seeing TOKEN.
729 * R < 0: Reduce on rule -R.
731 * R > 0: Shift to state R.
732 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
733 * conflicting reductions.
736 yygetLRActions (yyStateNum yystate
, int yytoken
,
737 int* yyaction
, const short** yyconflicts
)
739 int yyindex
= yypact
[yystate
] + yytoken
;
740 if (yyindex
< 0 || yyindex
> YYLAST
|| yycheck
[yyindex
] != yytoken
)
742 *yyaction
= -yydefact
[yystate
];
743 *yyconflicts
= yyconfl
;
747 *yyaction
= yytable
[yyindex
];
748 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
752 static inline yyStateNum
753 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
756 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
757 if (yyr
>= 0 && yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
760 return yydefgoto
[yylhs
- YYNTOKENS
];
764 yyisShiftAction (int yyaction
)
770 yyisErrorAction (int yyaction
)
772 return yyaction
== 0 || yyaction
== YYFLAG
;
777 /** True iff the semantic value of the edge leading to STATE is
780 yyhasResolvedValue (yyGLRState
* yystate
)
782 return yystate
->yyresolved
;
785 void yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
786 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
788 yySemanticOption
* yynewItem
;
789 yynewItem
= &yystack
->yynextFree
->yyoption
;
790 yystack
->yyspaceLeft
-= 1;
791 yystack
->yynextFree
+= 1;
792 yynewItem
->yyisState
= yyfalse
;
793 yynewItem
->yystate
= yyrhs
;
794 yynewItem
->yyrule
= yyrule
;
795 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
796 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
797 if (yystack
->yyspaceLeft
< YYHEADROOM
)
798 yyexpandGLRStack (yystack
);
803 /** Initialize SET to a singleton set containing an empty stack. */
805 yyinitStateSet (yyGLRStateSet
* yyset
)
808 yyset
->yycapacity
= 16;
809 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
810 yyset
->yystates
[0] = NULL
;
813 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
815 free (yyset
->yystates
);
818 /** Initialize STACK to a single empty stack, with total maximum
819 * capacity for all stacks of SIZE. */
821 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
823 yystack
->yyerrflag
= 0;
824 yystack
->yyerrState
= 0;
826 yystack
->yyspaceLeft
= yysize
;
827 yystack
->yynextFree
= yystack
->yyitems
=
828 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
829 yystack
->yysplitPoint
= NULL
;
830 yystack
->yylastDeleted
= NULL
;
831 yyinitStateSet (&yystack
->yytops
);
834 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
835 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
837 /** If STACK is expandable, extend it. WARNING: Pointers into the
838 stack from outside should be considered invalid after this call.
839 We always expand when there are 1 or fewer items left AFTER an
840 allocation, so that we can avoid having external pointers exist
841 across an allocation. */
843 yyexpandGLRStack (yyGLRStack
* yystack
)
845 #if YYSTACKEXPANDABLE
846 yyGLRStack yynewStack
;
847 yyGLRStackItem
* yyp0
, *yyp1
;
848 size_t yysize
, yynewSize
;
850 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
851 if (yysize
>= YYMAXDEPTH
)
852 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
853 yynewSize
= 2*yysize
;
854 if (yynewSize
> YYMAXDEPTH
)
855 yynewSize
= YYMAXDEPTH
;
856 yyinitGLRStack (&yynewStack
, yynewSize
);
857 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
859 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
864 yyGLRState
* yys0
= &yyp0
->yystate
;
865 yyGLRState
* yys1
= &yyp1
->yystate
;
866 if (yys0
->yypred
!= NULL
)
868 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
869 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
870 yys1
->yysemantics
.yyfirstVal
=
871 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
875 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
876 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
877 if (yyv0
->yystate
!= NULL
)
878 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
879 if (yyv0
->yynext
!= NULL
)
880 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
883 if (yystack
->yysplitPoint
!= NULL
)
884 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
885 yystack
->yysplitPoint
, yystate
);
887 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
888 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
889 yystack
->yytops
.yystates
[yyn
] =
890 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
891 yystack
->yytops
.yystates
[yyn
], yystate
);
892 free (yystack
->yyitems
);
893 yystack
->yyitems
= yynewStack
.yyitems
;
894 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
895 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
899 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
905 yyfreeGLRStack (yyGLRStack
* yystack
)
907 free (yystack
->yyitems
);
908 yyfreeStateSet (&yystack
->yytops
);
911 /** Assuming that S is a GLRState somewhere on STACK, update the
912 * splitpoint of STACK, if needed, so that it is at least as deep as
915 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
917 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
918 yystack
->yysplitPoint
= yys
;
921 /** Invalidate stack #K in STACK. */
923 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
925 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
926 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
927 yystack
->yytops
.yystates
[yyk
] = NULL
;
930 /** Undelete the last stack that was marked as deleted. Can only be
931 done once after a deletion, and only when all other stacks have
934 yyundeleteLastStack (yyGLRStack
* yystack
)
936 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
938 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
939 yystack
->yytops
.yysize
= 1;
940 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
941 yystack
->yylastDeleted
= NULL
;
945 yyremoveDeletes (yyGLRStack
* yystack
)
949 while (yyj
< yystack
->yytops
.yysize
)
951 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
953 if (YYDEBUG
&& yyi
== yyj
)
954 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
955 yystack
->yytops
.yysize
-= 1;
959 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
961 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
968 /** Shift to a new state on stack #K of STACK, corresponding to LR state
969 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
971 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
972 YYSTYPE yysval
, YYLTYPE
* yylocp
)
974 yyGLRStackItem
* yynewItem
;
976 yynewItem
= yystack
->yynextFree
;
977 yystack
->yynextFree
+= 1;
978 yystack
->yyspaceLeft
-= 1;
979 yynewItem
->yystate
.yyisState
= yytrue
;
980 yynewItem
->yystate
.yylrState
= yylrState
;
981 yynewItem
->yystate
.yyposn
= yyposn
;
982 yynewItem
->yystate
.yyresolved
= yytrue
;
983 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
984 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
985 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
986 yynewItem
->yystate
.yyloc
= *yylocp
;
987 if (yystack
->yyspaceLeft
< YYHEADROOM
)
988 yyexpandGLRStack (yystack
);
991 /** Shift to a new state on stack #K of STACK, to a new state
992 * corresponding to LR state LRSTATE, at input position POSN, with
993 * the (unresolved) semantic value of RHS under the action for RULE. */
995 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
996 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
998 yyGLRStackItem
* yynewItem
;
1000 yynewItem
= yystack
->yynextFree
;
1001 yynewItem
->yystate
.yyisState
= yytrue
;
1002 yynewItem
->yystate
.yylrState
= yylrState
;
1003 yynewItem
->yystate
.yyposn
= yyposn
;
1004 yynewItem
->yystate
.yyresolved
= yyfalse
;
1005 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1006 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1007 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1008 yystack
->yynextFree
+= 1;
1009 yystack
->yyspaceLeft
-= 1;
1010 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, yyrhs
, yyrule
);
1013 /** Pop the symbols consumed by reduction #RULE from the top of stack
1014 * #K of STACK, and perform the appropriate semantic action on their
1015 * semantic values. Assumes that all ambiguities in semantic values
1016 * have been previously resolved. Set *VALP to the resulting value,
1017 * and *LOCP to the computed location (if any). Return value is as
1018 * for userAction. */
1020 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1021 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1023 int yynrhs
= yyrhsLength (yyrule
);
1025 if (yystack
->yysplitPoint
== NULL
)
1027 /* Standard special case: single stack. */
1028 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1030 yystack
->yynextFree
-= yynrhs
;
1031 yystack
->yyspaceLeft
+= yynrhs
;
1032 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1035 *yyvalp
= yyval_default
;
1036 *yylocp
= yyloc_default
;
1040 *yyvalp
= yyrhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1041 *yylocp
= yyrhs
[1-yynrhs
].yystate
.yyloc
;
1043 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yyvalp
, yylocp
, yystack
);
1049 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1050 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1051 yyi
-= 1, yys
= yys
->yypred
)
1053 assert (yys
->yypred
!= NULL
);
1054 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1055 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1056 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1058 yyupdateSplit (yystack
, yys
);
1059 yystack
->yytops
.yystates
[yyk
] = yys
;
1062 *yyvalp
= yyval_default
;
1063 *yylocp
= yyloc_default
;
1067 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1068 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1070 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1071 yyvalp
, yylocp
, yystack
);
1075 /** Pop items off stack #K of STACK according to grammar rule RULE,
1076 * and push back on the resulting nonterminal symbol. Perform the
1077 * semantic action associated with RULE and store its value with the
1078 * newly pushed state, if FORCEEVAL or if STACK is currently
1079 * unambiguous. Otherwise, store the deferred semantic action with
1080 * the new state. If the new state would have an identical input
1081 * position, LR state, and predecessor to an existing state on the stack,
1082 * it is identified with that existing state, eliminating stack #K from
1083 * the STACK. In this case, the (necessarily deferred) semantic value is
1084 * added to the options for the existing state's semantic value.
1086 static inline YYRESULTTAG
1087 yyglrReduce (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
, bool yyforceEval
)
1089 int yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1091 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1096 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1097 yyglrShift (yystack
, yyk
,
1098 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1099 yylhsNonterm (yyrule
)),
1100 yyposn
, yysval
, &yyloc
);
1101 YYDPRINTF ((stderr
, "Reduced stack %d by rule #%d. Now in state %d.\n",
1102 yyk
, yyrule
-1, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1107 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1108 yyStateNum yynewLRState
;
1110 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1114 assert (yys
!= NULL
);
1116 yyupdateSplit (yystack
, yys
);
1117 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1119 "Reduced stack %d by rule #%d; action deferred. "
1120 "Now in state %d.\n",
1121 yyk
, yyrule
-1, yynewLRState
));
1122 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1123 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1125 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1126 yyp
= yystack
->yytops
.yystates
[yyi
];
1127 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1129 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1131 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1132 yymarkStackDeleted (yystack
, yyk
);
1133 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1140 yystack
->yytops
.yystates
[yyk
] = yys
;
1141 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1147 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1149 if (yystack
->yysplitPoint
== NULL
)
1152 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1154 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1156 yystack
->yytops
.yycapacity
*= 2;
1157 yystack
->yytops
.yystates
=
1158 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1159 yystack
->yytops
.yycapacity
1160 * sizeof (yyGLRState
*));
1162 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1163 = yystack
->yytops
.yystates
[yyk
];
1164 yystack
->yytops
.yysize
+= 1;
1165 return yystack
->yytops
.yysize
-1;
1168 /** True iff Y0 and Y1 represent identical options at the top level.
1169 * That is, they represent the same rule applied to RHS symbols
1170 * that produce the same terminal symbols. */
1172 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1174 if (yyy0
->yyrule
== yyy1
->yyrule
)
1176 yyGLRState
*yys0
, *yys1
;
1178 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1179 yyn
= yyrhsLength (yyy0
->yyrule
);
1181 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1182 if (yys0
->yyposn
!= yys1
->yyposn
)
1190 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1191 * alternative semantic values for the RHS-symbols of Y1 into the
1192 * corresponding semantic value sets of the symbols of Y0. */
1194 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1196 yyGLRState
*yys0
, *yys1
;
1198 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1199 yyn
= yyrhsLength (yyy0
->yyrule
);
1201 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1204 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1206 yySemanticOption
* yyz
;
1207 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1210 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1214 /** Y0 and Y1 represent two possible actions to take in a given
1215 * parsing state; return 0 if no combination is possible,
1216 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1218 yypreference (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1220 yyRuleNum yyr0
= yyy0
->yyrule
, yyr1
= yyy1
->yyrule
;
1221 int yyp0
= yydprec
[yyr0
], yyp1
= yydprec
[yyr1
];
1225 if (yymerger
[yyr0
] == 0 || yymerger
[yyr0
] != yymerger
[yyr1
])
1230 if (yyp0
== 0 || yyp1
== 0)
1239 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1240 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1244 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1249 assert (yys
->yypred
!= NULL
);
1250 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1253 if (! yys
->yyresolved
)
1255 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1256 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1259 yys
->yyresolved
= yytrue
;
1266 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1267 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1269 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1273 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1274 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1275 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1276 yyi
-= 1, yys
= yys
->yypred
)
1278 assert (yys
->yypred
!= NULL
);
1279 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1280 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1281 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1283 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1284 yyvalp
, yylocp
, yystack
);
1288 static yyGLRState YYLEFTMOST_STATE
= { 0, NULL
, -1, 0, { NULL
} };
1290 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1292 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1295 yyGLRState
* yystates
[YYMAXRHS
];
1297 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1298 yystates
[yyi
] = yys
;
1300 yystates
[0] = &YYLEFTMOST_STATE
;
1304 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1305 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1306 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1309 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1310 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1311 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1312 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1314 if (yystates
[yyi
]->yyresolved
)
1316 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1317 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1318 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1320 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1321 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1322 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1325 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1331 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1332 yyGLRStack
* yystack
)
1335 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1336 YYFPRINTF (stderr
, "Option 1,\n");
1337 yyreportTree (yyx0
, 2);
1338 YYFPRINTF (stderr
, "\nOption 2,\n");
1339 yyreportTree (yyx1
, 2);
1340 YYFPRINTF (stderr
, "\n");
1342 yyFail (yystack
, "ambiguity detected");
1346 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1347 * actions, and return the result. */
1349 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1350 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1352 yySemanticOption
* yybest
;
1353 yySemanticOption
* yyp
;
1356 yybest
= yyoptionList
;
1358 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1360 if (yyidenticalOptions (yybest
, yyp
))
1361 yymergeOptionSets (yybest
, yyp
);
1363 switch (yypreference (yybest
, yyp
))
1366 yyreportAmbiguity (yybest
, yyp
, yystack
);
1382 int yyprec
= yydprec
[yybest
->yyrule
];
1383 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1384 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1386 if (yyprec
== yydprec
[yyp
->yyrule
])
1390 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1391 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1397 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1401 yyresolveStack (yyGLRStack
* yystack
)
1403 if (yystack
->yysplitPoint
!= NULL
)
1408 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1409 yys
!= yystack
->yysplitPoint
;
1410 yys
= yys
->yypred
, yyn
+= 1)
1412 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1418 yycompressStack (yyGLRStack
* yystack
)
1420 yyGLRState
* yyp
, *yyq
, *yyr
;
1422 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1425 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1426 yyp
!= yystack
->yysplitPoint
;
1427 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1430 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1431 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1432 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1433 yystack
->yysplitPoint
= NULL
;
1434 yystack
->yylastDeleted
= NULL
;
1438 yystack
->yynextFree
->yystate
= *yyr
;
1440 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1441 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1442 yystack
->yynextFree
+= 1;
1443 yystack
->yyspaceLeft
-= 1;
1448 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1449 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1452 const short* yyconflicts
;
1454 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1456 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1458 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1460 assert (yystate
!= YYFINAL
);
1461 if (yyisDefaultedState (yystate
))
1463 yyrule
= yydefaultAction (yystate
);
1466 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1467 yymarkStackDeleted (yystack
, yyk
);
1470 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1474 if (*yytokenp
== YYEMPTY
)
1477 *yytokenp
= YYTRANSLATE(yychar
);
1478 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1480 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1482 while (*yyconflicts
!= 0)
1484 int yynewStack
= yysplitStack (yystack
, yyk
);
1485 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1487 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1488 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1493 if (yyisShiftAction (yyaction
))
1495 YYDPRINTF ((stderr
, "Shifted token %s on stack %d, ",
1496 yytokenName (*yytokenp
), yyk
));
1497 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1498 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1499 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1502 else if (yyisErrorAction (yyaction
))
1504 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1505 yymarkStackDeleted (yystack
, yyk
);
1509 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1516 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1518 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1520 if (yystack
->yyerrState
== 0)
1523 int yyn
, yyx
, yycount
, yysize
;
1527 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1528 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
1531 /* Start YYX at -YYN if negative to avoid negative indexes in
1533 yysize
= sizeof ("parse error, unexpected ")
1534 + strlen (yytokenName (*yytokenp
));
1535 yyprefix
= ", expecting ";
1536 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1538 if (yycheck
[yyx
+ yyn
] == yyx
)
1539 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1540 yycount
+= 1, yyprefix
= " or ";
1541 yymsg
= yyp
= (char*) malloc (yysize
);
1542 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1543 yytokenName (*yytokenp
));
1546 yyprefix
= ", expecting ";
1547 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1548 if (yycheck
[yyx
+ yyn
] == yyx
)
1550 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1559 yyerror ("parse error");
1564 /* Recover from a syntax error on STACK, assuming that TOKENP,
1565 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1566 value, and location of the lookahead.
1567 NOTE: This uses the panic-mode recovery algorithm described in the
1568 Bison documentation, which differs from what is in bison.simple.
1569 Specifically, this routine performs no reductions before shifting
1572 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1574 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1577 if (yystack
->yyerrState
== 0)
1578 yystack
->yyerrState
= 3;
1579 else if (yystack
->yyerrState
== 3)
1581 /* We just shifted the error token and (perhaps) took some
1582 reductions. Skip tokens until we can proceed. */
1584 if (*yytokenp
== YYEOF
)
1585 yyFail (yystack
, NULL
);
1586 if (*yytokenp
!= YYEMPTY
)
1587 YYDPRINTF ((stderr
, "Discarding token %s\n",
1588 yytokenName (*yytokenp
)));
1590 *yytokenp
= YYTRANSLATE (yychar
);
1591 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1592 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1594 /* Something's not right; we shouldn't be here */
1595 yyFail (yystack
, NULL
);
1597 if (yyj
< 0 || yyj
> YYLAST
|| yycheck
[yyj
] != *yytokenp
)
1599 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1602 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYFLAG
)
1607 /* Reduce to one stack */
1608 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1609 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1611 if (yyk
>= yystack
->yytops
.yysize
)
1612 yyFail (yystack
, NULL
);
1613 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1614 yymarkStackDeleted (yystack
, yyk
);
1615 yyremoveDeletes (yystack
);
1616 yycompressStack (yystack
);
1618 /* Now pop stack until we find a state that shifts the error token. */
1619 while (yystack
->yytops
.yystates
[0] != NULL
)
1621 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1622 if (yyj
!= YYFLAG
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1623 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1625 yyglrShift (yystack
, 0, yytable
[yyj
],
1626 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1629 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1630 yystack
->yynextFree
-= 1;
1631 yystack
->yyspaceLeft
+= 1;
1633 if (yystack
->yytops
.yystates
[0] == NULL
)
1634 yyFail (yystack
, NULL
);
1637 #define YYCHK1(YYE) \
1643 yystack.yyerrflag = 1; \
1646 yystack.yyerrflag = 0; \
1649 goto yyuser_error; \
1654 yyparse (YYPARSE_PARAM_ARG
)
1664 #define yychar (yystack.yyrawchar)
1667 YYSTYPE
* const yylvalp
= &yylval
;
1668 YYLTYPE
* const yyllocp
= &yylloc
;
1670 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1671 yystack
.yytokenp
= &yytoken
;
1673 if (setjmp (yystack
.yyexception_buffer
) != 0)
1676 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1682 /* For efficiency, we have two loops, of which the first of which
1683 * is specialized to deterministic operation (single stack, no
1684 * potential ambiguity). */
1691 const short* yyconflicts
;
1693 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1694 if (yystate
== YYFINAL
)
1696 if (yyisDefaultedState (yystate
))
1698 yyrule
= yydefaultAction (yystate
);
1701 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1704 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1708 if (yytoken
== YYEMPTY
)
1711 yytoken
= YYTRANSLATE (yychar
);
1712 YYDPRINTF ((stderr
, "Read token %s\n",
1713 yytokenName (yytoken
)));
1715 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1716 if (*yyconflicts
!= 0)
1718 if (yyisShiftAction (yyaction
))
1720 YYDPRINTF ((stderr
, "Shifted token %s. ",
1721 yytokenName (yytoken
)));
1722 if (yytoken
!= YYEOF
)
1725 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1726 if (yystack
.yyerrState
> 0)
1727 yystack
.yyerrState
-= 1;
1728 YYDPRINTF ((stderr
, "Now in state #%d\n",
1729 yystack
.yytops
.yystates
[0]->yylrState
));
1731 else if (yyisErrorAction (yyaction
))
1733 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1737 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1744 int yyn
= yystack
.yytops
.yysize
;
1745 for (yys
= 0; yys
< yyn
; yys
+= 1)
1746 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1750 yyremoveDeletes (&yystack
);
1751 if (yystack
.yytops
.yysize
== 0)
1753 yyundeleteLastStack (&yystack
);
1754 if (yystack
.yytops
.yysize
== 0)
1755 yyFail (&yystack
, "parse error");
1756 YYCHK1 (yyresolveStack (&yystack
));
1757 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1758 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1761 else if (yystack
.yytops
.yysize
== 1)
1763 YYCHK1 (yyresolveStack (&yystack
));
1764 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1765 yycompressStack (&yystack
);
1771 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1772 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1777 yyfreeGLRStack (&yystack
);
1778 return yystack
.yyerrflag
;
1781 /* DEBUGGING ONLY */
1784 yypstates (yyGLRState
* yyst
)
1786 void yy_yypstack (yyGLRState
* yys
)
1788 if (yys
->yypred
== NULL
)
1789 fprintf (stderr
, "%d@%d", yys
->yylrState
, yys
->yyposn
);
1792 yy_yypstack (yys
->yypred
);
1793 fprintf (stderr
, " -> %d@%d", yys
->yylrState
, yys
->yyposn
);
1798 fprintf (stderr
, "<null>");
1801 fprintf (stderr
, "\n");
1805 yypstack (yyGLRStack
* yystack
, int yyk
)
1807 yypstates (yystack
->yytops
.yystates
[yyk
]);
1810 #define YYINDEX(YYX) \
1811 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1815 yypdumpstack (yyGLRStack
* yystack
)
1817 yyGLRStackItem
* yyp
;
1819 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1821 fprintf (stderr
, "%3d. ", yyp
- yystack
->yyitems
);
1824 fprintf (stderr
, "Res: %d, LR State: %d, posn: %d, pred: %d",
1825 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1826 yyp
->yystate
.yyposn
,
1827 YYINDEX(yyp
->yystate
.yypred
));
1828 if (! yyp
->yystate
.yyresolved
)
1829 fprintf (stderr
, ", firstVal: %d",
1830 YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1834 fprintf (stderr
, "Option. rule: %d, state: %d, next: %d",
1835 yyp
->yyoption
.yyrule
, YYINDEX (yyp
->yyoption
.yystate
),
1836 YYINDEX (yyp
->yyoption
.yynext
));
1838 fprintf (stderr
, "\n");
1840 fprintf (stderr
, "Tops:");
1841 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1842 fprintf (stderr
, "%d: %d; ", yyi
, YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1843 fprintf (stderr
, "\n");
1849 m4_if(b4_defines_flag
, 0, [],
1850 [#output "b4_output_header_name"
1851 #ifndef b4_header_guard
1852 # define b4_header_guard
1854 b4_token_defines(b4_tokens
)
1857 m4_ifdef([b4_stype
],
1858 [#line b4_stype_line "b4_filename"
1859 typedef union b4_stype yystype
;
1860 /* Line __line__ of __file__. */
1861 #line __oline__ "__ofile__"],
1862 [typedef int yystype
;])
1863 # define YYSTYPE yystype
1867 [extern YYSTYPE b4_prefix
[]lval
;])
1871 typedef struct yyltype
1878 # define YYLTYPE yyltype
1882 [extern YYLTYPE b4_prefix
[]lloc
;])
1884 #endif /* not b4_header_guard */