1 m4_divert(-1) -*- C
-*-
4 # GLR skeleton for Bison
5 # Copyright (C) 2002 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 # b4_lhs_value([TYPE])
23 # --------------------
24 # Expansion of $<TYPE>$.
25 m4_define([b4_lhs_value
],
26 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
29 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
30 # --------------------------------------
31 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
33 m4_define([b4_rhs_value
],
34 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
42 # b4_location_if(IF-TRUE, IF-FALSE)
43 # ---------------------------------
44 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
45 m4_define([b4_location_if
],
46 [m4_if(b4_locations_flag
, [1],
54 m4_define([b4_lhs_location
],
58 # b4_rhs_location(RULE-LENGTH, NUM)
59 # ---------------------------------
60 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
62 m4_define([b4_rhs_location
],
63 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
.yystate
.yyloc
])
71 # b4_pure_if(IF-TRUE, IF-FALSE)
72 # -----------------------------
73 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
74 m4_define([b4_pure_if
],
80 ## ------------------- ##
81 ## Output file names. ##
82 ## ------------------- ##
84 m4_define_default([b4_input_suffix
], [.y
])
86 m4_define_default([b4_output_parser_suffix
],
87 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
89 m4_define_default([b4_output_parser_name
],
90 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
93 m4_define_default([b4_output_header_suffix
],
94 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
96 m4_define_default([b4_output_header_name
],
97 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
99 m4_define_default([b4_header_guard
],
100 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
101 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
105 #output "b4_output_parser_name"
106 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
108 /* This is the parser code for GLR (Generalized LR) parser. */
110 /* FIXME: minimize these */
117 /* Identify Bison output. */
121 #define YYPURE ]b4_pure[
123 /* Using locations. */
124 #define YYLSP_NEEDED ]b4_locations_flag[
126 ]m4_if(b4_prefix
[], [yy
], [],
127 [/* If NAME_PREFIX is specified substitute the variables and functions
129 #define yyparse b4_prefix[]parse
130 #define yylex b4_prefix[]lex
131 #define yyerror b4_prefix[]error
132 #define yylval b4_prefix[]lval
133 #define yychar b4_prefix[]char
134 #define yydebug b4_prefix[]debug
135 #define yynerrs b4_prefix[]nerrs
136 b4_location_if([#define yylloc b4_prefix[]lloc])])
138 /* Copy the first part of user declarations. */
141 b4_token_defines(b4_tokens
)[
143 /* Enabling traces. */
145 # define YYDEBUG ]b4_debug[
148 /* Enabling verbose error messages. */
149 #ifdef YYERROR_VERBOSE
150 # undef YYERROR_VERBOSE
151 # define YYERROR_VERBOSE 1
153 # define YYERROR_VERBOSE ]b4_error_verbose[
157 ]m4_ifdef([b4_stype
],
158 [#line b4_stype_line "b4_filename"
159 typedef union b4_stype yystype
;
160 /* Line __line__ of __file__. */
161 #line __oline__ "__ofile__"],
162 [typedef int yystype
;])[
163 # define YYSTYPE yystype
164 # define YYSTYPE_IS_TRIVIAL 1
168 typedef struct yyltype
174 int yylast_column
;])[
176 # define YYLTYPE ]b4_ltype[
177 # define YYLTYPE_IS_TRIVIAL 1
180 /* Default (constant) values used for initialization for null
181 right-hand sides. Unlike the standard bison.simple template,
182 here we set the default values of the $$ and $@ to zeroed-out
183 values. Since the default value of these quantities is undefined,
184 this behavior is technically correct. */
185 static YYSTYPE yyval_default
;
186 static YYLTYPE yyloc_default
;
188 /* Copy the second part of user declarations. */
191 ]/* Line __line__ of __file__. */
192 #line __oline__ "__ofile__"
194 #if ! defined (__cplusplus)
200 #if ! defined (yy__GNUC__)
204 /* YYFINAL -- State number of the termination state. */
205 #define YYFINAL ]b4_final[
206 #define YYFLAG ]b4_flag[
207 #define YYLAST ]b4_last[
209 /* YYNTOKENS -- Number of terminals. */
210 #define YYNTOKENS ]b4_ntokens[
211 /* YYNNTS -- Number of nonterminals. */
212 #define YYNNTS ]b4_nnts[
213 /* YYNRULES -- Number of rules. */
214 #define YYNRULES ]b4_nrules[
215 /* YYNRULES -- Number of states. */
216 #define YYNSTATES ]b4_nstates[
217 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
218 #define YYMAXRHS ]b4_r2_max[
220 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
221 #define YYUNDEFTOK ]b4_undef_token_number[
222 #define YYMAXUTOK ]b4_user_token_number_max[
224 #define YYTRANSLATE(YYX) \
225 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
227 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
228 static const ]b4_uint_type(b4_translate_max
)[ yytranslate
[] =
234 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
236 static const ]b4_uint_type(b4_prhs_max
)[ yyprhs
[] =
241 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
242 static const ]b4_sint_type(b4_rhs_max
)[ yyrhs
[] =
247 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
248 static const ]b4_uint_type(b4_rline_max
)[ yyrline
[] =
254 #if (YYDEBUG) || YYERROR_VERBOSE
255 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
256 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
257 static const char *const yytname
[] =
262 #define yytname_size (sizeof (yytname) / sizeof (yytname[0]))
265 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
266 static const ]b4_uint_type(b4_r1_max
)[ yyr1
[] =
271 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
272 static const ]b4_uint_type(b4_r2_max
)[ yyr2
[] =
277 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
278 static const short yydprec
[] =
283 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
284 static const short yymerger
[] =
289 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
290 doesn't specify something else to do. Zero means the default is an
292 static const short yydefact
[] =
297 /* YYPGOTO[NTERM-NUM]. */
298 static const short yydefgoto
[] =
303 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
305 static const short yypact
[] =
310 /* YYPGOTO[NTERM-NUM]. */
311 static const short yypgoto
[] =
316 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
317 positive, shift that token. If negative, reduce the rule which
318 number is the opposite. If zero, do what YYDEFACT says. */
319 static const short yytable
[] =
324 /* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list
325 of conflicting reductions corresponding to action entry for state
326 STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
327 is terminated by a rule number of 0. */
328 static const short yyconflp
[] =
330 ]b4_conflict_list_heads
[
333 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
334 by 0, pointed into by YYCONFLP. */
335 static const short yyconfl
[] =
337 ]b4_conflicting_rules
[
340 static const short yycheck
[] =
346 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
347 into yyparse. The argument should have type void *.
348 It should actually point to an object.
349 Grammar actions can access the variable by casting it
350 to the proper pointer type. */
353 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
354 #else /* !YYPARSE_PARAM */
355 # define YYPARSE_PARAM_ARG void
356 #endif /* !YYPARSE_PARAM */
358 /* Prevent warning if -Wstrict-prototypes. */
360 # ifdef YYPARSE_PARAM
361 int yyparse (void *);
367 /* Error token number */
370 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
373 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
375 #ifndef YYLLOC_DEFAULT
376 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
377 yyCurrent.yyfirst_line = YYRHSLOC(yyRhs,1).yyfirst_line; \
378 yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \
379 yyCurrent.yylast_line = YYRHSLOC(yyRhs,YYN).yylast_line; \
380 yyCurrent.yylast_column = YYRHSLOC(yyRhs,YYN).yylast_column;
383 /* YYLEX -- calling `yylex' with the right arguments. */
388 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
390 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
392 [#define YYLEX yylex ()])
397 #define yynerrs (yystack->yyerrcnt)
399 #define yychar (yystack->yyrawchar)],
407 static const int YYEOF
= 0;
408 static const int YYEMPTY
= -2;
410 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
413 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
418 #if ! defined (YYFPRINTF)
419 # define YYFPRINTF fprintf
422 # define YYDPRINTF(Args) \
427 /* Nonzero means print parse trace. It is left uninitialized so that
428 multiple parsers can coexist. */
431 # define YYDPRINTF(Args)
432 #endif /* !YYDEBUG */
434 /* YYINITDEPTH -- initial size of the parser's stacks. */
436 # define YYINITDEPTH ]b4_initdepth[
439 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
440 if the built-in stack extension method is used).
442 Do not make this value too large; the results are undefined if
443 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
444 evaluated with infinite-precision integer arithmetic. */
451 # define YYMAXDEPTH ]b4_maxdepth[
454 /* Minimum number of free items on the stack allowed after an
455 allocation. This is to allow allocation and initialization
456 to be completed by functions that call expandGLRStack before the
457 stack is expanded, thus insuring that all necessary pointers get
458 properly redirected to new data. */
461 #if ! defined (YYSTACKEXPANDABLE) \
462 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
463 #define YYSTACKEXPANDABLE 1
465 #define YYSTACKEXPANDABLE 0
468 /** State numbers, as in LALR(1) machine */
469 typedef int yyStateNum
;
471 /** Rule numbers, as in LALR(1) machine */
472 typedef int yyRuleNum
;
474 /** Grammar symbol */
475 typedef short yySymbol
;
477 /** Item references, as in LALR(1) machine */
478 typedef short yyItemNum
;
480 typedef struct yyGLRState yyGLRState
;
481 typedef struct yySemanticOption yySemanticOption
;
482 typedef union yyGLRStackItem yyGLRStackItem
;
483 typedef struct yyGLRStack yyGLRStack
;
484 typedef struct yyGLRStateSet yyGLRStateSet
;
489 yyStateNum yylrState
;
493 yySemanticOption
* yyfirstVal
;
499 struct yyGLRStateSet
{
500 yyGLRState
** yystates
;
501 size_t yysize
, yycapacity
;
504 struct yySemanticOption
{
508 yySemanticOption
* yynext
;
511 union yyGLRStackItem
{
513 yySemanticOption yyoption
;
525 jmp_buf yyexception_buffer
;
526 yyGLRStackItem
* yyitems
;
527 yyGLRStackItem
* yynextFree
;
529 yyGLRState
* yysplitPoint
;
530 yyGLRState
* yylastDeleted
;
531 yyGLRStateSet yytops
;
534 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
535 static void yyexpandGLRStack (yyGLRStack
* yystack
);
536 static void yyfreeGLRStack (yyGLRStack
* yystack
);
539 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
541 if (yyformat
!= NULL
)
545 va_start (yyap
, yyformat
);
546 yystack
->yyerrflag
= 1;
547 vsprintf (yymsg
, yyformat
, yyap
);
550 longjmp (yystack
->yyexception_buffer
, 1);
553 #if YYDEBUG || YYERROR_VERBOSE
554 /** A printable representation of TOKEN. Valid until next call to
556 static inline const char*
557 yytokenName (yySymbol yytoken
)
559 return yytname
[yytoken
];
563 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
564 * and top stack item YYVSP. YYLVALP points to place to put semantic
565 * value ($$), and yylocp points to place for location information
566 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
567 * yyerr for YYERROR, yyabort for YYABORT. */
569 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
570 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
574 *yyvalp
= yyval_default
;
575 *yylocp
= yyloc_default
;
579 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
580 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
583 # define yyval (*yyvalp)
585 # define yyerrok (yystack->yyerrState = 0)
587 # define YYACCEPT return yyaccept
589 # define YYABORT return yyabort
591 # define YYERROR return yyerr
593 # define YYRECOVERING (yystack->yyerrState != 0)
595 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
597 # define YYBACKUP(Token, Value) \
599 yyerror ("syntax error: cannot back up"); \
618 /* Line __line__ of __file__. */
619 #line __oline__ "__ofile__"
624 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
626 YYSTYPE yyval
= *yy0
;
634 /* Bison grammar-table manipulation */
636 /** Number of symbols composing the right hand side of rule #RULE. */
638 yyrhsLength (yyRuleNum yyrule
)
643 /** Left-hand-side symbol for rule #RULE. */
644 static inline yySymbol
645 yylhsNonterm (yyRuleNum yyrule
)
650 /** True iff LR state STATE has only a default reduction (regardless
653 yyisDefaultedState (yyStateNum yystate
)
655 return yypact
[yystate
] == YYFLAG
;
658 /** The default reduction for STATE, assuming it has one. */
659 static inline yyRuleNum
660 yydefaultAction (yyStateNum yystate
)
662 return yydefact
[yystate
];
665 /** Set *ACTION to the action to take in STATE on seeing TOKEN.
667 * R < 0: Reduce on rule -R.
669 * R > 0: Shift to state R.
670 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
671 * conflicting reductions.
674 yygetLRActions (yyStateNum yystate
, int yytoken
,
675 int* yyaction
, const short** yyconflicts
)
677 int yyindex
= yypact
[yystate
] + yytoken
;
678 if (yyindex
< 0 || yyindex
> YYLAST
|| yycheck
[yyindex
] != yytoken
)
680 *yyaction
= -yydefact
[yystate
];
681 *yyconflicts
= yyconfl
;
685 *yyaction
= yytable
[yyindex
];
686 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
690 static inline yyStateNum
691 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
694 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
695 if (yyr
>= 0 && yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
698 return yydefgoto
[yylhs
- YYNTOKENS
];
702 yyisShiftAction (int yyaction
)
708 yyisErrorAction (int yyaction
)
710 return yyaction
== 0 || yyaction
== YYFLAG
;
715 /** True iff the semantic value of the edge leading to STATE is
718 yyhasResolvedValue (yyGLRState
* yystate
)
720 return yystate
->yyresolved
;
723 void yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
724 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
726 yySemanticOption
* yynewItem
;
727 yynewItem
= &yystack
->yynextFree
->yyoption
;
728 yystack
->yyspaceLeft
-= 1;
729 yystack
->yynextFree
+= 1;
730 yynewItem
->yyisState
= yyfalse
;
731 yynewItem
->yystate
= yyrhs
;
732 yynewItem
->yyrule
= yyrule
;
733 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
734 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
735 if (yystack
->yyspaceLeft
< YYHEADROOM
)
736 yyexpandGLRStack (yystack
);
741 /** Initialize SET to a singleton set containing an empty stack. */
743 yyinitStateSet (yyGLRStateSet
* yyset
)
746 yyset
->yycapacity
= 16;
747 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
748 yyset
->yystates
[0] = NULL
;
751 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
753 free (yyset
->yystates
);
756 /** Initialize STACK to a single empty stack, with total maximum
757 * capacity for all stacks of SIZE. */
759 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
761 yystack
->yyerrflag
= 0;
762 yystack
->yyerrState
= 0;
764 yystack
->yyspaceLeft
= yysize
;
765 yystack
->yynextFree
= yystack
->yyitems
=
766 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
767 yystack
->yysplitPoint
= NULL
;
768 yystack
->yylastDeleted
= NULL
;
769 yyinitStateSet (&yystack
->yytops
);
772 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
773 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
775 /** If STACK is expandable, extend it. WARNING: Pointers into the
776 stack from outside should be considered invalid after this call.
777 We always expand when there are 1 or fewer items left AFTER an
778 allocation, so that we can avoid having external pointers exist
779 across an allocation. */
781 yyexpandGLRStack (yyGLRStack
* yystack
)
783 #if YYSTACKEXPANDABLE
784 yyGLRStack yynewStack
;
785 yyGLRStackItem
* yyp0
, *yyp1
;
786 size_t yysize
, yynewSize
;
788 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
789 if (yysize
>= YYMAXDEPTH
)
790 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
791 yynewSize
= 2*yysize
;
792 if (yynewSize
> YYMAXDEPTH
)
793 yynewSize
= YYMAXDEPTH
;
794 yyinitGLRStack (&yynewStack
, yynewSize
);
795 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
797 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
802 yyGLRState
* yys0
= &yyp0
->yystate
;
803 yyGLRState
* yys1
= &yyp1
->yystate
;
804 if (yys0
->yypred
!= NULL
)
806 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
807 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
808 yys1
->yysemantics
.yyfirstVal
=
809 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
813 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
814 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
815 if (yyv0
->yystate
!= NULL
)
816 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
817 if (yyv0
->yynext
!= NULL
)
818 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
821 if (yystack
->yysplitPoint
!= NULL
)
822 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
823 yystack
->yysplitPoint
, yystate
);
825 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
826 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
827 yystack
->yytops
.yystates
[yyn
] =
828 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
829 yystack
->yytops
.yystates
[yyn
], yystate
);
830 free (yystack
->yyitems
);
831 yystack
->yyitems
= yynewStack
.yyitems
;
832 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
833 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
837 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
843 yyfreeGLRStack (yyGLRStack
* yystack
)
845 free (yystack
->yyitems
);
846 yyfreeStateSet (&yystack
->yytops
);
849 /** Assuming that S is a GLRState somewhere on STACK, update the
850 * splitpoint of STACK, if needed, so that it is at least as deep as
853 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
855 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
856 yystack
->yysplitPoint
= yys
;
859 /** Invalidate stack #K in STACK. */
861 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
863 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
864 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
865 yystack
->yytops
.yystates
[yyk
] = NULL
;
868 /** Undelete the last stack that was marked as deleted. Can only be
869 done once after a deletion, and only when all other stacks have
872 yyundeleteLastStack (yyGLRStack
* yystack
)
874 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
876 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
877 yystack
->yytops
.yysize
= 1;
878 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
879 yystack
->yylastDeleted
= NULL
;
883 yyremoveDeletes (yyGLRStack
* yystack
)
887 while (yyj
< yystack
->yytops
.yysize
)
889 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
891 if (YYDEBUG
&& yyi
== yyj
)
892 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
893 yystack
->yytops
.yysize
-= 1;
897 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
899 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
906 /** Shift to a new state on stack #K of STACK, corresponding to LR state
907 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
909 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
910 YYSTYPE yysval
, YYLTYPE
* yylocp
)
912 yyGLRStackItem
* yynewItem
;
914 yynewItem
= yystack
->yynextFree
;
915 yystack
->yynextFree
+= 1;
916 yystack
->yyspaceLeft
-= 1;
917 yynewItem
->yystate
.yyisState
= yytrue
;
918 yynewItem
->yystate
.yylrState
= yylrState
;
919 yynewItem
->yystate
.yyposn
= yyposn
;
920 yynewItem
->yystate
.yyresolved
= yytrue
;
921 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
922 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
923 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
924 yynewItem
->yystate
.yyloc
= *yylocp
;
925 if (yystack
->yyspaceLeft
< YYHEADROOM
)
926 yyexpandGLRStack (yystack
);
929 /** Shift to a new state on stack #K of STACK, to a new state
930 * corresponding to LR state LRSTATE, at input position POSN, with
931 * the (unresolved) semantic value of RHS under the action for RULE. */
933 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
934 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
936 yyGLRStackItem
* yynewItem
;
938 yynewItem
= yystack
->yynextFree
;
939 yynewItem
->yystate
.yyisState
= yytrue
;
940 yynewItem
->yystate
.yylrState
= yylrState
;
941 yynewItem
->yystate
.yyposn
= yyposn
;
942 yynewItem
->yystate
.yyresolved
= yyfalse
;
943 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
944 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
945 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
946 yystack
->yynextFree
+= 1;
947 yystack
->yyspaceLeft
-= 1;
948 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, yyrhs
, yyrule
);
951 /** Pop the symbols consumed by reduction #RULE from the top of stack
952 * #K of STACK, and perform the appropriate semantic action on their
953 * semantic values. Assumes that all ambiguities in semantic values
954 * have been previously resolved. Set *VALP to the resulting value,
955 * and *LOCP to the computed location (if any). Return value is as
958 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
959 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
961 int yynrhs
= yyrhsLength (yyrule
);
963 if (yystack
->yysplitPoint
== NULL
)
965 /* Standard special case: single stack. */
966 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
968 yystack
->yynextFree
-= yynrhs
;
969 yystack
->yyspaceLeft
+= yynrhs
;
970 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
973 *yyvalp
= yyval_default
;
974 *yylocp
= yyloc_default
;
978 *yyvalp
= yyrhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
979 *yylocp
= yyrhs
[1-yynrhs
].yystate
.yyloc
;
981 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yyvalp
, yylocp
, yystack
);
987 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
988 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
989 yyi
-= 1, yys
= yys
->yypred
)
991 assert (yys
->yypred
!= NULL
);
992 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
993 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
994 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
996 yyupdateSplit (yystack
, yys
);
997 yystack
->yytops
.yystates
[yyk
] = yys
;
1000 *yyvalp
= yyval_default
;
1001 *yylocp
= yyloc_default
;
1005 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1006 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1008 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1009 yyvalp
, yylocp
, yystack
);
1013 /** Pop items off stack #K of STACK according to grammar rule RULE,
1014 * and push back on the resulting nonterminal symbol. Perform the
1015 * semantic action associated with RULE and store its value with the
1016 * newly pushed state, if FORCEEVAL or if STACK is currently
1017 * unambiguous. Otherwise, store the deferred semantic action with
1018 * the new state. If the new state would have an identical input
1019 * position, LR state, and predecessor to an existing state on the stack,
1020 * it is identified with that existing state, eliminating stack #K from
1021 * the STACK. In this case, the (necessarily deferred) semantic value is
1022 * added to the options for the existing state's semantic value.
1024 static inline YYRESULTTAG
1025 yyglrReduce (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
, bool yyforceEval
)
1027 int yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1029 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1034 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1035 yyglrShift (yystack
, yyk
,
1036 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1037 yylhsNonterm (yyrule
)),
1038 yyposn
, yysval
, &yyloc
);
1039 YYDPRINTF ((stderr
, "Reduced stack %d by rule #%d. Now in state %d.\n",
1040 yyk
, yyrule
-1, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1045 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1046 yyStateNum yynewLRState
;
1048 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1052 assert (yys
!= NULL
);
1054 yyupdateSplit (yystack
, yys
);
1055 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1057 "Reduced stack %d by rule #%d; action deferred. "
1058 "Now in state %d.\n",
1059 yyk
, yyrule
-1, yynewLRState
));
1060 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1061 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1063 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1064 yyp
= yystack
->yytops
.yystates
[yyi
];
1065 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1067 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1069 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1070 yymarkStackDeleted (yystack
, yyk
);
1071 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1078 yystack
->yytops
.yystates
[yyk
] = yys
;
1079 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1085 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1087 if (yystack
->yysplitPoint
== NULL
)
1090 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1092 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1094 yystack
->yytops
.yycapacity
*= 2;
1095 yystack
->yytops
.yystates
=
1096 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1097 yystack
->yytops
.yycapacity
1098 * sizeof (yyGLRState
*));
1100 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1101 = yystack
->yytops
.yystates
[yyk
];
1102 yystack
->yytops
.yysize
+= 1;
1103 return yystack
->yytops
.yysize
-1;
1106 /** True iff Y0 and Y1 represent identical options at the top level.
1107 * That is, they represent the same rule applied to RHS symbols
1108 * that produce the same terminal symbols. */
1110 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1112 if (yyy0
->yyrule
== yyy1
->yyrule
)
1114 yyGLRState
*yys0
, *yys1
;
1116 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1117 yyn
= yyrhsLength (yyy0
->yyrule
);
1119 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1120 if (yys0
->yyposn
!= yys1
->yyposn
)
1128 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1129 * alternative semantic values for the RHS-symbols of Y1 into the
1130 * corresponding semantic value sets of the symbols of Y0. */
1132 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1134 yyGLRState
*yys0
, *yys1
;
1136 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1137 yyn
= yyrhsLength (yyy0
->yyrule
);
1139 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1142 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1144 yySemanticOption
* yyz
;
1145 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1148 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1152 /** Y0 and Y1 represent two possible actions to take in a given
1153 * parsing state; return 0 if no combination is possible,
1154 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1156 yypreference (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1158 yyRuleNum yyr0
= yyy0
->yyrule
, yyr1
= yyy1
->yyrule
;
1159 int yyp0
= yydprec
[yyr0
], yyp1
= yydprec
[yyr1
];
1163 if (yymerger
[yyr0
] == 0 || yymerger
[yyr0
] != yymerger
[yyr1
])
1168 if (yyp0
== 0 || yyp1
== 0)
1177 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1178 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1182 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1187 assert (yys
->yypred
!= NULL
);
1188 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1191 if (! yys
->yyresolved
)
1193 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1194 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1197 yys
->yyresolved
= yytrue
;
1204 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1205 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1207 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1211 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1212 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1213 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1214 yyi
-= 1, yys
= yys
->yypred
)
1216 assert (yys
->yypred
!= NULL
);
1217 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1218 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1219 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1221 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1222 yyvalp
, yylocp
, yystack
);
1226 static yyGLRState YYLEFTMOST_STATE
= { 0, NULL
, -1, 0, { NULL
} };
1228 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1230 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1233 yyGLRState
* yystates
[YYMAXRHS
];
1235 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1236 yystates
[yyi
] = yys
;
1238 yystates
[0] = &YYLEFTMOST_STATE
;
1242 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1243 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1244 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1247 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1248 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1249 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1250 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1252 if (yystates
[yyi
]->yyresolved
)
1254 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1255 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1256 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1258 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1259 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1260 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1263 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1269 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1270 yyGLRStack
* yystack
)
1273 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1274 YYFPRINTF (stderr
, "Option 1,\n");
1275 yyreportTree (yyx0
, 2);
1276 YYFPRINTF (stderr
, "\nOption 2,\n");
1277 yyreportTree (yyx1
, 2);
1278 YYFPRINTF (stderr
, "\n");
1280 yyFail (yystack
, "ambiguity detected");
1284 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1285 * actions, and return the result. */
1287 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1288 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1290 yySemanticOption
* yybest
;
1291 yySemanticOption
* yyp
;
1294 yybest
= yyoptionList
;
1296 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1298 if (yyidenticalOptions (yybest
, yyp
))
1299 yymergeOptionSets (yybest
, yyp
);
1301 switch (yypreference (yybest
, yyp
))
1304 yyreportAmbiguity (yybest
, yyp
, yystack
);
1320 int yyprec
= yydprec
[yybest
->yyrule
];
1321 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1322 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1324 if (yyprec
== yydprec
[yyp
->yyrule
])
1328 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1329 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1335 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1339 yyresolveStack (yyGLRStack
* yystack
)
1341 if (yystack
->yysplitPoint
!= NULL
)
1346 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1347 yys
!= yystack
->yysplitPoint
;
1348 yys
= yys
->yypred
, yyn
+= 1)
1350 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1356 yycompressStack (yyGLRStack
* yystack
)
1358 yyGLRState
* yyp
, *yyq
, *yyr
;
1360 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1363 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1364 yyp
!= yystack
->yysplitPoint
;
1365 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1368 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1369 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1370 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1371 yystack
->yysplitPoint
= NULL
;
1372 yystack
->yylastDeleted
= NULL
;
1376 yystack
->yynextFree
->yystate
= *yyr
;
1378 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1379 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1380 yystack
->yynextFree
+= 1;
1381 yystack
->yyspaceLeft
-= 1;
1386 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1387 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1390 const short* yyconflicts
;
1392 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1394 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1396 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1398 assert (yystate
!= YYFINAL
);
1399 if (yyisDefaultedState (yystate
))
1401 yyrule
= yydefaultAction (yystate
);
1404 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1405 yymarkStackDeleted (yystack
, yyk
);
1408 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1412 if (*yytokenp
== YYEMPTY
)
1415 *yytokenp
= YYTRANSLATE(yychar
);
1416 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1418 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1420 while (*yyconflicts
!= 0)
1422 int yynewStack
= yysplitStack (yystack
, yyk
);
1423 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1425 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1426 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1431 if (yyisShiftAction (yyaction
))
1433 YYDPRINTF ((stderr
, "Shifted token %s on stack %d, ",
1434 yytokenName (*yytokenp
), yyk
));
1435 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1436 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1437 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1440 else if (yyisErrorAction (yyaction
))
1442 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1443 yymarkStackDeleted (yystack
, yyk
);
1447 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1454 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1456 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1458 if (yystack
->yyerrState
== 0)
1461 int yyn
, yyx
, yycount
, yysize
;
1465 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1466 if (yyn
> YYFLAG
&& yyn
< YYLAST
)
1469 /* Start YYX at -YYN if negative to avoid negative indexes in
1471 yysize
= sizeof ("parse error, unexpected ")
1472 + strlen (yytokenName (*yytokenp
));
1473 yyprefix
= ", expecting ";
1474 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1476 if (yycheck
[yyx
+ yyn
] == yyx
)
1477 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1478 yycount
+= 1, yyprefix
= " or ";
1479 yymsg
= yyp
= (char*) malloc (yysize
);
1480 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1481 yytokenName (*yytokenp
));
1484 yyprefix
= ", expecting ";
1485 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1486 if (yycheck
[yyx
+ yyn
] == yyx
)
1488 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1497 yyerror ("parse error");
1502 /* Recover from a syntax error on STACK, assuming that TOKENP,
1503 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1504 value, and location of the lookahead.
1505 NOTE: This uses the panic-mode recovery algorithm described in the
1506 Bison documentation, which differs from what is in bison.simple.
1507 Specifically, this routine performs no reductions before shifting
1510 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1512 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1515 if (yystack
->yyerrState
== 0)
1516 yystack
->yyerrState
= 3;
1517 else if (yystack
->yyerrState
== 3)
1519 /* We just shifted the error token and (perhaps) took some
1520 reductions. Skip tokens until we can proceed. */
1522 if (*yytokenp
== YYEOF
)
1523 yyFail (yystack
, NULL
);
1524 if (*yytokenp
!= YYEMPTY
)
1525 YYDPRINTF ((stderr
, "Discarding token %s\n",
1526 yytokenName (*yytokenp
)));
1528 *yytokenp
= YYTRANSLATE (yychar
);
1529 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1530 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1532 /* Something's not right; we shouldn't be here */
1533 yyFail (yystack
, NULL
);
1535 if (yyj
< 0 || yyj
> YYLAST
|| yycheck
[yyj
] != *yytokenp
)
1537 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1540 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYFLAG
)
1545 /* Reduce to one stack */
1546 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1547 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1549 if (yyk
>= yystack
->yytops
.yysize
)
1550 yyFail (yystack
, NULL
);
1551 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1552 yymarkStackDeleted (yystack
, yyk
);
1553 yyremoveDeletes (yystack
);
1554 yycompressStack (yystack
);
1556 /* Now pop stack until we find a state that shifts the error token. */
1557 while (yystack
->yytops
.yystates
[0] != NULL
)
1559 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1560 if (yyj
!= YYFLAG
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1561 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1563 yyglrShift (yystack
, 0, yytable
[yyj
],
1564 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1567 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1568 yystack
->yynextFree
-= 1;
1569 yystack
->yyspaceLeft
+= 1;
1571 if (yystack
->yytops
.yystates
[0] == NULL
)
1572 yyFail (yystack
, NULL
);
1575 #define YYCHK1(YYE) \
1581 yystack.yyerrflag = 1; \
1584 yystack.yyerrflag = 0; \
1587 goto yyuser_error; \
1592 yyparse (YYPARSE_PARAM_ARG
)
1602 #define yychar (yystack.yyrawchar)
1605 YYSTYPE
* const yylvalp
= &yylval
;
1606 YYLTYPE
* const yyllocp
= &yylloc
;
1608 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1609 yystack
.yytokenp
= &yytoken
;
1611 if (setjmp (yystack
.yyexception_buffer
) != 0)
1614 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1620 /* For efficiency, we have two loops, of which the first of which
1621 * is specialized to deterministic operation (single stack, no
1622 * potential ambiguity). */
1629 const short* yyconflicts
;
1631 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1632 if (yystate
== YYFINAL
)
1634 if (yyisDefaultedState (yystate
))
1636 yyrule
= yydefaultAction (yystate
);
1639 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1642 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1646 if (yytoken
== YYEMPTY
)
1649 yytoken
= YYTRANSLATE (yychar
);
1650 YYDPRINTF ((stderr
, "Read token %s\n",
1651 yytokenName (yytoken
)));
1653 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1654 if (*yyconflicts
!= 0)
1656 if (yyisShiftAction (yyaction
))
1658 YYDPRINTF ((stderr
, "Shifted token %s. ",
1659 yytokenName (yytoken
)));
1660 if (yytoken
!= YYEOF
)
1663 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1664 if (yystack
.yyerrState
> 0)
1665 yystack
.yyerrState
-= 1;
1666 YYDPRINTF ((stderr
, "Now in state #%d\n",
1667 yystack
.yytops
.yystates
[0]->yylrState
));
1669 else if (yyisErrorAction (yyaction
))
1671 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1675 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1682 int yyn
= yystack
.yytops
.yysize
;
1683 for (yys
= 0; yys
< yyn
; yys
+= 1)
1684 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1688 yyremoveDeletes (&yystack
);
1689 if (yystack
.yytops
.yysize
== 0)
1691 yyundeleteLastStack (&yystack
);
1692 if (yystack
.yytops
.yysize
== 0)
1693 yyFail (&yystack
, "parse error");
1694 YYCHK1 (yyresolveStack (&yystack
));
1695 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1696 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1699 else if (yystack
.yytops
.yysize
== 1)
1701 YYCHK1 (yyresolveStack (&yystack
));
1702 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1703 yycompressStack (&yystack
);
1709 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1710 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1715 yyfreeGLRStack (&yystack
);
1716 return yystack
.yyerrflag
;
1719 /* DEBUGGING ONLY */
1722 yypstates (yyGLRState
* yyst
)
1724 void yy_yypstack (yyGLRState
* yys
)
1726 if (yys
->yypred
== NULL
)
1727 fprintf (stderr
, "%d@%d", yys
->yylrState
, yys
->yyposn
);
1730 yy_yypstack (yys
->yypred
);
1731 fprintf (stderr
, " -> %d@%d", yys
->yylrState
, yys
->yyposn
);
1736 fprintf (stderr
, "<null>");
1739 fprintf (stderr
, "\n");
1743 yypstack (yyGLRStack
* yystack
, int yyk
)
1745 yypstates (yystack
->yytops
.yystates
[yyk
]);
1748 #define YYINDEX(YYX) \
1749 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1753 yypdumpstack (yyGLRStack
* yystack
)
1755 yyGLRStackItem
* yyp
;
1757 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1759 fprintf (stderr
, "%3d. ", yyp
- yystack
->yyitems
);
1762 fprintf (stderr
, "Res: %d, LR State: %d, posn: %d, pred: %d",
1763 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1764 yyp
->yystate
.yyposn
,
1765 YYINDEX(yyp
->yystate
.yypred
));
1766 if (! yyp
->yystate
.yyresolved
)
1767 fprintf (stderr
, ", firstVal: %d",
1768 YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1772 fprintf (stderr
, "Option. rule: %d, state: %d, next: %d",
1773 yyp
->yyoption
.yyrule
, YYINDEX (yyp
->yyoption
.yystate
),
1774 YYINDEX (yyp
->yyoption
.yynext
));
1776 fprintf (stderr
, "\n");
1778 fprintf (stderr
, "Tops:");
1779 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1780 fprintf (stderr
, "%d: %d; ", yyi
, YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1781 fprintf (stderr
, "\n");
1787 m4_if(b4_defines_flag
, 0, [],
1788 [#output "b4_output_header_name"
1789 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1790 #ifndef b4_header_guard
1791 # define b4_header_guard
1793 b4_token_defines(b4_tokens
)
1796 m4_ifdef([b4_stype
],
1797 [#line b4_stype_line "b4_filename"
1798 typedef union b4_stype yystype
;
1799 /* Line __line__ of __file__. */
1800 #line __oline__ "__ofile__"],
1801 [typedef int yystype
;])
1802 # define YYSTYPE yystype
1806 [extern YYSTYPE b4_prefix
[]lval
;])
1810 typedef struct yyltype
1817 # define YYLTYPE yyltype
1821 [extern YYLTYPE b4_prefix
[]lloc
;])
1823 #endif /* not b4_header_guard */