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)
204 #ifndef __attribute__
205 /* This feature is available in gcc versions 2.5 and later. */
206 # if !defined (__GNUC__) || __GNUC__ < 2 || \
207 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
208 # define __attribute__(Spec) /* empty */
212 #ifndef ATTRIBUTE_UNUSED
213 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
216 #if ! defined (__GNUC__)
220 /* YYFINAL -- State number of the termination state. */
221 #define YYFINAL ]b4_final_state_number[
222 #define YYFLAG ]b4_flag[
223 #define YYLAST ]b4_last[
225 /* YYNTOKENS -- Number of terminals. */
226 #define YYNTOKENS ]b4_tokens_number[
227 /* YYNNTS -- Number of nonterminals. */
228 #define YYNNTS ]b4_nterms_number[
229 /* YYNRULES -- Number of rules. */
230 #define YYNRULES ]b4_rules_number[
231 /* YYNRULES -- Number of states. */
232 #define YYNSTATES ]b4_states_number[
233 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
234 #define YYMAXRHS ]b4_r2_max[
236 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
237 #define YYUNDEFTOK ]b4_undef_token_number[
238 #define YYMAXUTOK ]b4_user_token_number_max[
240 #define YYTRANSLATE(YYX) \
241 ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
243 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
244 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
250 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
252 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
257 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
258 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
263 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
264 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
270 #if (YYDEBUG) || YYERROR_VERBOSE
271 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
272 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
273 static const char *const yytname
[] =
278 #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
281 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
282 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
287 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
288 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
293 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
294 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
299 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
300 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
305 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
306 doesn't specify something else to do. Zero means the default is an
308 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
313 /* YYPDEFGOTO[NTERM-NUM]. */
314 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
319 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
321 #define YYPACT_NINF ]b4_pact_ninf[
322 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
327 /* YYPGOTO[NTERM-NUM]. */
328 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
333 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
334 positive, shift that token. If negative, reduce the rule which
335 number is the opposite. If zero, do what YYDEFACT says. */
336 #define YYTABLE_NINF ]b4_table_ninf[
337 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
342 /* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list
343 of conflicting reductions corresponding to action entry for state
344 STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
345 is terminated by a rule number of 0. */
346 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
348 ]b4_conflict_list_heads
[
351 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
352 by 0, pointed into by YYCONFLP. */
353 ]dnl Do
not use b4_int_type_for here
, since there are places where
354 dnl pointers onto yyconfl are taken
, which type is
"short *".
355 dnl We probably ought to introduce a type
for confl
.
356 [static const short yyconfl
[] =
358 ]b4_conflicting_rules
[
361 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
367 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
368 into yyparse. The argument should have type void *.
369 It should actually point to an object.
370 Grammar actions can access the variable by casting it
371 to the proper pointer type. */
374 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
375 #else /* !YYPARSE_PARAM */
376 # define YYPARSE_PARAM_ARG void
377 #endif /* !YYPARSE_PARAM */
379 /* Prevent warning if -Wstrict-prototypes. */
381 # ifdef YYPARSE_PARAM
382 int yyparse (void *);
388 /* Error token number */
391 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
394 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
396 #ifndef YYLLOC_DEFAULT
397 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
398 yyCurrent.yyfirst_line = YYRHSLOC(yyRhs,1).yyfirst_line; \
399 yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \
400 yyCurrent.yylast_line = YYRHSLOC(yyRhs,YYN).yylast_line; \
401 yyCurrent.yylast_column = YYRHSLOC(yyRhs,YYN).yylast_column;
404 /* YYLEX -- calling `yylex' with the right arguments. */
409 # define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
411 # define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
413 [#define YYLEX yylex ()])
418 #define yynerrs (yystack->yyerrcnt)
420 #define yychar (yystack->yyrawchar)],
428 static const int YYEOF
= 0;
429 static const int YYEMPTY
= -2;
431 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
434 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
439 #if ! defined (YYFPRINTF)
440 # define YYFPRINTF fprintf
443 # define YYDPRINTF(Args) \
448 /* Nonzero means print parse trace. It is left uninitialized so that
449 multiple parsers can coexist. */
452 /* Avoid empty `if' bodies. */
453 # define YYDPRINTF(Args) {}
454 #endif /* !YYDEBUG */
456 /* YYINITDEPTH -- initial size of the parser's stacks. */
458 # define YYINITDEPTH ]b4_initdepth[
461 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
462 if the built-in stack extension method is used).
464 Do not make this value too large; the results are undefined if
465 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
466 evaluated with infinite-precision integer arithmetic. */
473 # define YYMAXDEPTH ]b4_maxdepth[
476 /* Minimum number of free items on the stack allowed after an
477 allocation. This is to allow allocation and initialization
478 to be completed by functions that call expandGLRStack before the
479 stack is expanded, thus insuring that all necessary pointers get
480 properly redirected to new data. */
483 #if ! defined (YYSTACKEXPANDABLE) \
484 && (! defined (__cplusplus) || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))
485 #define YYSTACKEXPANDABLE 1
487 #define YYSTACKEXPANDABLE 0
490 /** State numbers, as in LALR(1) machine */
491 typedef int yyStateNum
;
493 /** Rule numbers, as in LALR(1) machine */
494 typedef int yyRuleNum
;
496 /** Grammar symbol */
497 typedef short yySymbol
;
499 /** Item references, as in LALR(1) machine */
500 typedef short yyItemNum
;
502 typedef struct yyGLRState yyGLRState
;
503 typedef struct yySemanticOption yySemanticOption
;
504 typedef union yyGLRStackItem yyGLRStackItem
;
505 typedef struct yyGLRStack yyGLRStack
;
506 typedef struct yyGLRStateSet yyGLRStateSet
;
511 yyStateNum yylrState
;
515 yySemanticOption
* yyfirstVal
;
521 struct yyGLRStateSet
{
522 yyGLRState
** yystates
;
523 size_t yysize
, yycapacity
;
526 struct yySemanticOption
{
530 yySemanticOption
* yynext
;
533 union yyGLRStackItem
{
535 yySemanticOption yyoption
;
547 jmp_buf yyexception_buffer
;
548 yyGLRStackItem
* yyitems
;
549 yyGLRStackItem
* yynextFree
;
551 yyGLRState
* yysplitPoint
;
552 yyGLRState
* yylastDeleted
;
553 yyGLRStateSet yytops
;
556 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
557 static void yyexpandGLRStack (yyGLRStack
* yystack
);
558 static void yyfreeGLRStack (yyGLRStack
* yystack
);
561 yyFail (yyGLRStack
* yystack
, const char* yyformat
, ...)
563 if (yyformat
!= NULL
)
567 va_start (yyap
, yyformat
);
568 yystack
->yyerrflag
= 1;
569 vsprintf (yymsg
, yyformat
, yyap
);
572 longjmp (yystack
->yyexception_buffer
, 1);
575 #if YYDEBUG || YYERROR_VERBOSE
576 /** A printable representation of TOKEN. Valid until next call to
578 static inline const char*
579 yytokenName (yySymbol yytoken
)
581 return yytname
[yytoken
];
585 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
586 * and top stack item YYVSP. YYLVALP points to place to put semantic
587 * value ($$), and yylocp points to place for location information
588 * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
589 * yyerr for YYERROR, yyabort for YYABORT. */
591 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
592 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
)
594 /* Avoid `unused' warnings in there are no $n. */
599 *yyvalp
= yyval_default
;
600 *yylocp
= yyloc_default
;
604 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
605 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
608 # define yyval (*yyvalp)
610 # define yyerrok (yystack->yyerrState = 0)
612 # define YYACCEPT return yyaccept
614 # define YYABORT return yyabort
616 # define YYERROR return yyerr
618 # define YYRECOVERING (yystack->yyerrState != 0)
620 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
622 # define YYBACKUP(Token, Value) \
624 yyerror ("syntax error: cannot back up"); \
643 /* Line __line__ of __file__. */
644 #line __oline__ "__ofile__"
649 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
651 YYSTYPE yyval
= *yy0
;
652 /* `Use' the arguments. */
663 /* Bison grammar-table manipulation */
665 /** Number of symbols composing the right hand side of rule #RULE. */
667 yyrhsLength (yyRuleNum yyrule
)
672 /** Left-hand-side symbol for rule #RULE. */
673 static inline yySymbol
674 yylhsNonterm (yyRuleNum yyrule
)
679 /** True iff LR state STATE has only a default reduction (regardless
682 yyisDefaultedState (yyStateNum yystate
)
684 return yypact
[yystate
] == YYPACT_NINF
;
687 /** The default reduction for STATE, assuming it has one. */
688 static inline yyRuleNum
689 yydefaultAction (yyStateNum yystate
)
691 return yydefact
[yystate
];
694 /** Set *ACTION to the action to take in STATE on seeing TOKEN.
696 * R < 0: Reduce on rule -R.
698 * R > 0: Shift to state R.
699 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
700 * conflicting reductions.
703 yygetLRActions (yyStateNum yystate
, int yytoken
,
704 int* yyaction
, const short** yyconflicts
)
706 int yyindex
= yypact
[yystate
] + yytoken
;
707 if (yyindex
< 0 || yyindex
> YYLAST
|| yycheck
[yyindex
] != yytoken
)
709 *yyaction
= -yydefact
[yystate
];
710 *yyconflicts
= yyconfl
;
714 *yyaction
= yytable
[yyindex
];
715 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
719 static inline yyStateNum
720 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
723 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
724 if (yyr
>= 0 && yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
727 return yydefgoto
[yylhs
- YYNTOKENS
];
731 yyisShiftAction (int yyaction
)
737 yyisErrorAction (int yyaction
)
739 return yyaction
== 0 || yyaction
== YYPACT_NINF
;
744 /** True iff the semantic value of the edge leading to STATE is
747 yyhasResolvedValue (yyGLRState
* yystate
)
749 return yystate
->yyresolved
;
753 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
754 yyGLRState
* yyrhs
, yyRuleNum yyrule
)
756 yySemanticOption
* yynewItem
;
757 yynewItem
= &yystack
->yynextFree
->yyoption
;
758 yystack
->yyspaceLeft
-= 1;
759 yystack
->yynextFree
+= 1;
760 yynewItem
->yyisState
= yyfalse
;
761 yynewItem
->yystate
= yyrhs
;
762 yynewItem
->yyrule
= yyrule
;
763 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
764 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
765 if (yystack
->yyspaceLeft
< YYHEADROOM
)
766 yyexpandGLRStack (yystack
);
771 /** Initialize SET to a singleton set containing an empty stack. */
773 yyinitStateSet (yyGLRStateSet
* yyset
)
776 yyset
->yycapacity
= 16;
777 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
778 yyset
->yystates
[0] = NULL
;
781 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
783 free (yyset
->yystates
);
786 /** Initialize STACK to a single empty stack, with total maximum
787 * capacity for all stacks of SIZE. */
789 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
791 yystack
->yyerrflag
= 0;
792 yystack
->yyerrState
= 0;
794 yystack
->yyspaceLeft
= yysize
;
795 yystack
->yynextFree
= yystack
->yyitems
=
796 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
797 yystack
->yysplitPoint
= NULL
;
798 yystack
->yylastDeleted
= NULL
;
799 yyinitStateSet (&yystack
->yytops
);
802 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
803 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
805 /** If STACK is expandable, extend it. WARNING: Pointers into the
806 stack from outside should be considered invalid after this call.
807 We always expand when there are 1 or fewer items left AFTER an
808 allocation, so that we can avoid having external pointers exist
809 across an allocation. */
811 yyexpandGLRStack (yyGLRStack
* yystack
)
813 #if YYSTACKEXPANDABLE
814 yyGLRStack yynewStack
;
815 yyGLRStackItem
* yyp0
, *yyp1
;
816 size_t yysize
, yynewSize
;
818 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
819 if (yysize
>= YYMAXDEPTH
)
820 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
821 yynewSize
= 2*yysize
;
822 if (yynewSize
> YYMAXDEPTH
)
823 yynewSize
= YYMAXDEPTH
;
824 yyinitGLRStack (&yynewStack
, yynewSize
);
825 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
827 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
832 yyGLRState
* yys0
= &yyp0
->yystate
;
833 yyGLRState
* yys1
= &yyp1
->yystate
;
834 if (yys0
->yypred
!= NULL
)
836 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
837 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
838 yys1
->yysemantics
.yyfirstVal
=
839 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
843 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
844 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
845 if (yyv0
->yystate
!= NULL
)
846 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
847 if (yyv0
->yynext
!= NULL
)
848 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
851 if (yystack
->yysplitPoint
!= NULL
)
852 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
853 yystack
->yysplitPoint
, yystate
);
855 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
856 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
857 yystack
->yytops
.yystates
[yyn
] =
858 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
859 yystack
->yytops
.yystates
[yyn
], yystate
);
860 free (yystack
->yyitems
);
861 yystack
->yyitems
= yynewStack
.yyitems
;
862 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
863 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
867 yyFail (yystack
, "parsing stack overflow (%d items)", yysize
);
873 yyfreeGLRStack (yyGLRStack
* yystack
)
875 free (yystack
->yyitems
);
876 yyfreeStateSet (&yystack
->yytops
);
879 /** Assuming that S is a GLRState somewhere on STACK, update the
880 * splitpoint of STACK, if needed, so that it is at least as deep as
883 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
885 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
886 yystack
->yysplitPoint
= yys
;
889 /** Invalidate stack #K in STACK. */
891 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
893 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
894 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
895 yystack
->yytops
.yystates
[yyk
] = NULL
;
898 /** Undelete the last stack that was marked as deleted. Can only be
899 done once after a deletion, and only when all other stacks have
902 yyundeleteLastStack (yyGLRStack
* yystack
)
904 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
906 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
907 yystack
->yytops
.yysize
= 1;
908 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
909 yystack
->yylastDeleted
= NULL
;
913 yyremoveDeletes (yyGLRStack
* yystack
)
917 while (yyj
< yystack
->yytops
.yysize
)
919 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
922 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
923 yystack
->yytops
.yysize
-= 1;
927 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
929 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
936 /** Shift to a new state on stack #K of STACK, corresponding to LR state
937 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
939 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
940 YYSTYPE yysval
, YYLTYPE
* yylocp
)
942 yyGLRStackItem
* yynewItem
;
944 yynewItem
= yystack
->yynextFree
;
945 yystack
->yynextFree
+= 1;
946 yystack
->yyspaceLeft
-= 1;
947 yynewItem
->yystate
.yyisState
= yytrue
;
948 yynewItem
->yystate
.yylrState
= yylrState
;
949 yynewItem
->yystate
.yyposn
= yyposn
;
950 yynewItem
->yystate
.yyresolved
= yytrue
;
951 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
952 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
953 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
954 yynewItem
->yystate
.yyloc
= *yylocp
;
955 if (yystack
->yyspaceLeft
< YYHEADROOM
)
956 yyexpandGLRStack (yystack
);
959 /** Shift to a new state on stack #K of STACK, to a new state
960 * corresponding to LR state LRSTATE, at input position POSN, with
961 * the (unresolved) semantic value of RHS under the action for RULE. */
963 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
964 size_t yyposn
, yyGLRState
* yyrhs
, yyRuleNum yyrule
)
966 yyGLRStackItem
* yynewItem
;
968 yynewItem
= yystack
->yynextFree
;
969 yynewItem
->yystate
.yyisState
= yytrue
;
970 yynewItem
->yystate
.yylrState
= yylrState
;
971 yynewItem
->yystate
.yyposn
= yyposn
;
972 yynewItem
->yystate
.yyresolved
= yyfalse
;
973 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
974 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
975 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
976 yystack
->yynextFree
+= 1;
977 yystack
->yyspaceLeft
-= 1;
978 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, yyrhs
, yyrule
);
981 /** Pop the symbols consumed by reduction #RULE from the top of stack
982 * #K of STACK, and perform the appropriate semantic action on their
983 * semantic values. Assumes that all ambiguities in semantic values
984 * have been previously resolved. Set *VALP to the resulting value,
985 * and *LOCP to the computed location (if any). Return value is as
988 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
989 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
991 int yynrhs
= yyrhsLength (yyrule
);
993 if (yystack
->yysplitPoint
== NULL
)
995 /* Standard special case: single stack. */
996 yyGLRStackItem
* yyrhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
998 yystack
->yynextFree
-= yynrhs
;
999 yystack
->yyspaceLeft
+= yynrhs
;
1000 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1003 *yyvalp
= yyval_default
;
1004 *yylocp
= yyloc_default
;
1008 *yyvalp
= yyrhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1009 *yylocp
= yyrhs
[1-yynrhs
].yystate
.yyloc
;
1011 return yyuserAction (yyrule
, yynrhs
, yyrhs
, yyvalp
, yylocp
, yystack
);
1017 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1018 for (yyi
= yynrhs
-1, yys
= yystack
->yytops
.yystates
[yyk
]; yyi
>= 0;
1019 yyi
-= 1, yys
= yys
->yypred
)
1021 assert (yys
->yypred
!= NULL
);
1022 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1023 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1024 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1026 yyupdateSplit (yystack
, yys
);
1027 yystack
->yytops
.yystates
[yyk
] = yys
;
1030 *yyvalp
= yyval_default
;
1031 *yylocp
= yyloc_default
;
1035 *yyvalp
= yyrhsVals
[0].yystate
.yysemantics
.yysval
;
1036 *yylocp
= yyrhsVals
[0].yystate
.yyloc
;
1038 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1039 yyvalp
, yylocp
, yystack
);
1043 /** Pop items off stack #K of STACK according to grammar rule RULE,
1044 * and push back on the resulting nonterminal symbol. Perform the
1045 * semantic action associated with RULE and store its value with the
1046 * newly pushed state, if FORCEEVAL or if STACK is currently
1047 * unambiguous. Otherwise, store the deferred semantic action with
1048 * the new state. If the new state would have an identical input
1049 * position, LR state, and predecessor to an existing state on the stack,
1050 * it is identified with that existing state, eliminating stack #K from
1051 * the STACK. In this case, the (necessarily deferred) semantic value is
1052 * added to the options for the existing state's semantic value.
1054 static inline YYRESULTTAG
1055 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1058 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1060 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1065 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
));
1066 yyglrShift (yystack
, yyk
,
1067 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1068 yylhsNonterm (yyrule
)),
1069 yyposn
, yysval
, &yyloc
);
1070 YYDPRINTF ((stderr
, "Reduced stack %d by rule #%d. Now in state %d.\n",
1071 yyk
, yyrule
-1, yystack
->yytops
.yystates
[yyk
]->yylrState
));
1077 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1078 yyStateNum yynewLRState
;
1080 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1084 assert (yys
!= NULL
);
1086 yyupdateSplit (yystack
, yys
);
1087 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1089 "Reduced stack %d by rule #%d; action deferred. "
1090 "Now in state %d.\n",
1091 yyk
, yyrule
-1, yynewLRState
));
1092 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1093 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1095 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1096 yyp
= yystack
->yytops
.yystates
[yyi
];
1097 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1099 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1101 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
);
1102 yymarkStackDeleted (yystack
, yyk
);
1103 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1110 yystack
->yytops
.yystates
[yyk
] = yys
;
1111 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
);
1117 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1119 if (yystack
->yysplitPoint
== NULL
)
1122 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1124 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1126 yystack
->yytops
.yycapacity
*= 2;
1127 yystack
->yytops
.yystates
=
1128 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1129 yystack
->yytops
.yycapacity
1130 * sizeof (yyGLRState
*));
1132 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1133 = yystack
->yytops
.yystates
[yyk
];
1134 yystack
->yytops
.yysize
+= 1;
1135 return yystack
->yytops
.yysize
-1;
1138 /** True iff Y0 and Y1 represent identical options at the top level.
1139 * That is, they represent the same rule applied to RHS symbols
1140 * that produce the same terminal symbols. */
1142 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1144 if (yyy0
->yyrule
== yyy1
->yyrule
)
1146 yyGLRState
*yys0
, *yys1
;
1148 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1149 yyn
= yyrhsLength (yyy0
->yyrule
);
1151 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1152 if (yys0
->yyposn
!= yys1
->yyposn
)
1160 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1161 * alternative semantic values for the RHS-symbols of Y1 into the
1162 * corresponding semantic value sets of the symbols of Y0. */
1164 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1166 yyGLRState
*yys0
, *yys1
;
1168 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1169 yyn
= yyrhsLength (yyy0
->yyrule
);
1171 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1174 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1176 yySemanticOption
* yyz
;
1177 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1180 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1184 /** Y0 and Y1 represent two possible actions to take in a given
1185 * parsing state; return 0 if no combination is possible,
1186 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1188 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1190 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1191 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1195 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1200 if (p0
== 0 || p1
== 0)
1209 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1210 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1214 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
)
1219 assert (yys
->yypred
!= NULL
);
1220 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
);
1223 if (! yys
->yyresolved
)
1225 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1226 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1229 yys
->yyresolved
= yytrue
;
1236 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1237 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1239 yyGLRStackItem yyrhsVals
[YYMAXRHS
];
1243 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1244 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
));
1245 for (yyi
= yynrhs
-1, yys
= yyopt
->yystate
; yyi
>= 0;
1246 yyi
-= 1, yys
= yys
->yypred
)
1248 assert (yys
->yypred
!= NULL
);
1249 yyrhsVals
[yyi
].yystate
.yyresolved
= yytrue
;
1250 yyrhsVals
[yyi
].yystate
.yysemantics
.yysval
= yys
->yysemantics
.yysval
;
1251 yyrhsVals
[yyi
].yystate
.yyloc
= yys
->yyloc
;
1253 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ (yynrhs
-1),
1254 yyvalp
, yylocp
, yystack
);
1258 static yyGLRState YYLEFTMOST_STATE
= { 0, NULL
, -1, 0, { NULL
} };
1260 static void yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1262 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1265 yyGLRState
* yystates
[YYMAXRHS
];
1267 for (yyi
= yynrhs
, yys
= yyx
->yystate
; yyi
> 0; yyi
-= 1, yys
= yys
->yypred
)
1268 yystates
[yyi
] = yys
;
1270 yystates
[0] = &YYLEFTMOST_STATE
;
1274 if (yys
->yyposn
+1 > yyx
->yystate
->yyposn
)
1275 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1276 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1279 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1280 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1281 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1282 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1284 if (yystates
[yyi
]->yyresolved
)
1286 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1287 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1288 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1290 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1291 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1292 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1295 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1301 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1302 yyGLRStack
* yystack
)
1304 /* `Unused' warnings. */
1309 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1310 YYFPRINTF (stderr
, "Option 1,\n");
1311 yyreportTree (yyx0
, 2);
1312 YYFPRINTF (stderr
, "\nOption 2,\n");
1313 yyreportTree (yyx1
, 2);
1314 YYFPRINTF (stderr
, "\n");
1316 yyFail (yystack
, "ambiguity detected");
1320 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1321 * actions, and return the result. */
1323 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1324 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
)
1326 yySemanticOption
* yybest
;
1327 yySemanticOption
* yyp
;
1330 yybest
= yyoptionList
;
1332 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1334 if (yyidenticalOptions (yybest
, yyp
))
1335 yymergeOptionSets (yybest
, yyp
);
1337 switch (yypreference (yybest
, yyp
))
1340 yyreportAmbiguity (yybest
, yyp
, yystack
);
1356 int yyprec
= yydprec
[yybest
->yyrule
];
1357 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
));
1358 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1360 if (yyprec
== yydprec
[yyp
->yyrule
])
1364 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
));
1365 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1371 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
);
1375 yyresolveStack (yyGLRStack
* yystack
)
1377 if (yystack
->yysplitPoint
!= NULL
)
1382 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1383 yys
!= yystack
->yysplitPoint
;
1384 yys
= yys
->yypred
, yyn
+= 1)
1386 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
));
1392 yycompressStack (yyGLRStack
* yystack
)
1394 yyGLRState
* yyp
, *yyq
, *yyr
;
1396 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1399 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1400 yyp
!= yystack
->yysplitPoint
;
1401 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1404 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1405 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1406 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1407 yystack
->yysplitPoint
= NULL
;
1408 yystack
->yylastDeleted
= NULL
;
1412 yystack
->yynextFree
->yystate
= *yyr
;
1414 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1415 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1416 yystack
->yynextFree
+= 1;
1417 yystack
->yyspaceLeft
-= 1;
1422 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1423 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1426 const short* yyconflicts
;
1428 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1430 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1432 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1434 assert (yystate
!= YYFINAL
);
1435 if (yyisDefaultedState (yystate
))
1437 yyrule
= yydefaultAction (yystate
);
1440 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1441 yymarkStackDeleted (yystack
, yyk
);
1444 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
));
1448 if (*yytokenp
== YYEMPTY
)
1451 *yytokenp
= YYTRANSLATE(yychar
);
1452 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1454 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1456 while (*yyconflicts
!= 0)
1458 int yynewStack
= yysplitStack (yystack
, yyk
);
1459 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1461 YYCHK (yyglrReduce (yystack
, yynewStack
, *yyconflicts
, yyfalse
));
1462 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1467 if (yyisShiftAction (yyaction
))
1469 YYDPRINTF ((stderr
, "Shifted token %s on stack %d, ",
1470 yytokenName (*yytokenp
), yyk
));
1471 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1, *yylvalp
, yyllocp
);
1472 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1473 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1476 else if (yyisErrorAction (yyaction
))
1478 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1479 yymarkStackDeleted (yystack
, yyk
);
1483 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
));
1490 yyreportParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1492 /* `Unused' warnings. */
1496 if (yystack
->yyerrState
== 0)
1499 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1500 int yyn
, yyx
, yycount
, yysize
;
1501 const char* yyprefix
;
1504 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1505 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1508 /* Start YYX at -YYN if negative to avoid negative indexes in
1510 yysize
= sizeof ("parse error, unexpected ")
1511 + strlen (yytokenName (*yytokenp
));
1512 yyprefix
= ", expecting ";
1513 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
&& yycount
<= 5;
1515 if (yycheck
[yyx
+ yyn
] == yyx
)
1516 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
),
1517 yycount
+= 1, yyprefix
= " or ";
1518 yymsg
= yyp
= (char*) malloc (yysize
);
1519 yyp
+= sprintf (yyp
, "parse error, unexpected %s",
1520 yytokenName (*yytokenp
));
1523 yyprefix
= ", expecting ";
1524 for (yyx
= yyn
< 0 ? -yyn
: 0; yyx
< yytname_size
; yyx
+= 1)
1525 if (yycheck
[yyx
+ yyn
] == yyx
)
1527 yyp
+= sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1536 yyerror ("parse error");
1541 /* Recover from a syntax error on STACK, assuming that TOKENP,
1542 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1543 value, and location of the lookahead.
1544 NOTE: This uses the panic-mode recovery algorithm described in the
1545 Bison documentation, which differs from what is in bison.simple.
1546 Specifically, this routine performs no reductions before shifting
1549 yyrecoverParseError (yyGLRStack
* yystack
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
)
1551 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1555 if (yystack
->yyerrState
== 0)
1556 yystack
->yyerrState
= 3;
1557 else if (yystack
->yyerrState
== 3)
1559 /* We just shifted the error token and (perhaps) took some
1560 reductions. Skip tokens until we can proceed. */
1562 if (*yytokenp
== YYEOF
)
1563 yyFail (yystack
, NULL
);
1564 if (*yytokenp
!= YYEMPTY
)
1565 YYDPRINTF ((stderr
, "Discarding token %s\n",
1566 yytokenName (*yytokenp
)));
1568 *yytokenp
= YYTRANSLATE (yychar
);
1569 YYDPRINTF ((stderr
, "Read token %s\n", yytokenName (*yytokenp
)));
1570 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1571 if (yyj
== YYPACT_NINF
)
1572 /* Something's not right; we shouldn't be here */
1573 yyFail (yystack
, NULL
);
1575 if (yyj
< 0 || yyj
> YYLAST
|| yycheck
[yyj
] != *yytokenp
)
1577 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1580 else if (yytable
[yyj
] != 0 && yytable
[yyj
] != YYTABLE_NINF
)
1585 /* Reduce to one stack */
1586 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1587 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1589 if (yyk
>= yystack
->yytops
.yysize
)
1590 yyFail (yystack
, NULL
);
1591 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1592 yymarkStackDeleted (yystack
, yyk
);
1593 yyremoveDeletes (yystack
);
1594 yycompressStack (yystack
);
1596 /* Now pop stack until we find a state that shifts the error token. */
1597 while (yystack
->yytops
.yystates
[0] != NULL
)
1599 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
] + YYTERROR
;
1600 if (yyj
!= YYPACT_NINF
+ YYTERROR
&& yyj
>= 0 && yyj
<= YYLAST
&&
1601 yycheck
[yyj
] == YYTERROR
&& yyisShiftAction (yytable
[yyj
]))
1603 yyglrShift (yystack
, 0, yytable
[yyj
],
1604 yystack
->yytops
.yystates
[0]->yyposn
, *yylvalp
, yyllocp
);
1607 yystack
->yytops
.yystates
[0] = yystack
->yytops
.yystates
[0]->yypred
;
1608 yystack
->yynextFree
-= 1;
1609 yystack
->yyspaceLeft
+= 1;
1611 if (yystack
->yytops
.yystates
[0] == NULL
)
1612 yyFail (yystack
, NULL
);
1615 #define YYCHK1(YYE) \
1621 yystack.yyerrflag = 1; \
1624 yystack.yyerrflag = 0; \
1627 goto yyuser_error; \
1632 yyparse (YYPARSE_PARAM_ARG
)
1642 #define yychar (yystack.yyrawchar)
1645 YYSTYPE
* const yylvalp
= &yylval
;
1646 YYLTYPE
* const yyllocp
= &yylloc
;
1648 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1649 yystack
.yytokenp
= &yytoken
;
1651 if (setjmp (yystack
.yyexception_buffer
) != 0)
1654 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
);
1660 /* For efficiency, we have two loops, of which the first of which
1661 * is specialized to deterministic operation (single stack, no
1662 * potential ambiguity). */
1669 const short* yyconflicts
;
1671 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1672 if (yystate
== YYFINAL
)
1674 if (yyisDefaultedState (yystate
))
1676 yyrule
= yydefaultAction (yystate
);
1679 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1682 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
));
1686 if (yytoken
== YYEMPTY
)
1689 yytoken
= YYTRANSLATE (yychar
);
1690 YYDPRINTF ((stderr
, "Read token %s\n",
1691 yytokenName (yytoken
)));
1693 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1694 if (*yyconflicts
!= 0)
1696 if (yyisShiftAction (yyaction
))
1698 YYDPRINTF ((stderr
, "Shifted token %s. ",
1699 yytokenName (yytoken
)));
1700 if (yytoken
!= YYEOF
)
1703 yyglrShift (&yystack
, 0, yyaction
, yyposn
, yylval
, yyllocp
);
1704 if (yystack
.yyerrState
> 0)
1705 yystack
.yyerrState
-= 1;
1706 YYDPRINTF ((stderr
, "Now in state #%d\n",
1707 yystack
.yytops
.yystates
[0]->yylrState
));
1709 else if (yyisErrorAction (yyaction
))
1711 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1715 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
));
1722 int yyn
= yystack
.yytops
.yysize
;
1723 for (yys
= 0; yys
< yyn
; yys
+= 1)
1724 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1728 yyremoveDeletes (&yystack
);
1729 if (yystack
.yytops
.yysize
== 0)
1731 yyundeleteLastStack (&yystack
);
1732 if (yystack
.yytops
.yysize
== 0)
1733 yyFail (&yystack
, "parse error");
1734 YYCHK1 (yyresolveStack (&yystack
));
1735 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1736 yyreportParseError (&yystack
, yylvalp
, yyllocp
);
1739 else if (yystack
.yytops
.yysize
== 1)
1741 YYCHK1 (yyresolveStack (&yystack
));
1742 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1743 yycompressStack (&yystack
);
1749 yyrecoverParseError (&yystack
, yylvalp
, yyllocp
);
1750 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1755 yyfreeGLRStack (&yystack
);
1756 return yystack
.yyerrflag
;
1759 /* DEBUGGING ONLY */
1760 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1761 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1764 yypstates (yyGLRState
* yyst
)
1767 yy_yypstack (yyGLRState
* yys
)
1769 if (yys
->yypred
== NULL
)
1770 fprintf (stderr
, "%d@%d", yys
->yylrState
, yys
->yyposn
);
1773 yy_yypstack (yys
->yypred
);
1774 fprintf (stderr
, " -> %d@%d", yys
->yylrState
, yys
->yyposn
);
1779 fprintf (stderr
, "<null>");
1782 fprintf (stderr
, "\n");
1786 yypstack (yyGLRStack
* yystack
, int yyk
)
1788 yypstates (yystack
->yytops
.yystates
[yyk
]);
1791 #define YYINDEX(YYX) \
1792 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1796 yypdumpstack (yyGLRStack
* yystack
)
1798 yyGLRStackItem
* yyp
;
1800 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1802 fprintf (stderr
, "%3d. ", yyp
- yystack
->yyitems
);
1805 fprintf (stderr
, "Res: %d, LR State: %d, posn: %d, pred: %d",
1806 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1807 yyp
->yystate
.yyposn
,
1808 YYINDEX(yyp
->yystate
.yypred
));
1809 if (! yyp
->yystate
.yyresolved
)
1810 fprintf (stderr
, ", firstVal: %d",
1811 YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1815 fprintf (stderr
, "Option. rule: %d, state: %d, next: %d",
1816 yyp
->yyoption
.yyrule
, YYINDEX (yyp
->yyoption
.yystate
),
1817 YYINDEX (yyp
->yyoption
.yynext
));
1819 fprintf (stderr
, "\n");
1821 fprintf (stderr
, "Tops:");
1822 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1823 fprintf (stderr
, "%d: %d; ", yyi
, YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1824 fprintf (stderr
, "\n");
1830 m4_if(b4_defines_flag
, 0, [],
1831 [#output "b4_output_header_name"
1832 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002])
1833 #ifndef b4_header_guard
1834 # define b4_header_guard
1836 b4_token_defines(b4_tokens
)
1839 m4_ifdef([b4_stype
],
1840 [#line b4_stype_line "b4_filename"
1841 typedef union b4_stype yystype
;
1842 /* Line __line__ of __file__. */
1843 #line __oline__ "__ofile__"],
1844 [typedef int yystype
;])
1845 # define YYSTYPE yystype
1849 [extern YYSTYPE b4_prefix
[]lval
;])
1853 typedef struct yyltype
1860 # define YYLTYPE yyltype
1864 [extern YYLTYPE b4_prefix
[]lloc
;])
1866 #endif /* not b4_header_guard */