1 m4_divert(-1) -*- C
-*-
3 # GLR skeleton for Bison
4 # Copyright (C) 2002, 2003 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 ## ---------------- ##
24 ## ---------------- ##
27 m4_define_default([b4_stack_depth_max
], [10000])
28 m4_define_default([b4_stack_depth_init
], [200])
32 ## ------------------------ ##
33 ## Pure/impure interfaces. ##
34 ## ------------------------ ##
39 # Accumule in b4_lex_param all the yylex arguments.
40 # Yes, this is quite ugly...
41 m4_define([b4_lex_param
],
42 m4_dquote(b4_pure_if([[[[YYSTYPE
*]], [[yylvalp]]][]dnl
43 b4_location_if([, [[YYLTYPE
*], [yyllocp
]]])])dnl
44 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)))
49 m4_define([b4_user_formals
],
50 [m4_ifset([b4_parse_param
], [, b4_c_ansi_formals(b4_parse_param
)])])
55 # Arguments passed to yyerror: user args plus yylloc.
56 m4_define([b4_yyerror_args
],
57 [b4_pure_if([b4_location_if([yylocp
, ])])dnl
58 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
63 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
64 m4_define([b4_lyyerror_args
],
65 [b4_pure_if([b4_location_if([yyllocp
, ])])dnl
66 m4_ifset([b4_parse_param
], [b4_c_args(b4_parse_param
), ])])
71 # Arguments needed by yyerror: user args plus yylloc.
72 m4_define([b4_pure_args
],
73 [b4_pure_if([b4_location_if([, yylocp
])])[]b4_user_args
])
78 # Arguments passed to yyerror: user formals plus yyllocp.
79 m4_define([b4_pure_formals
],
80 [b4_pure_if([b4_location_if([, YYLTYPE
*yylocp
])])[]b4_user_formals
])
85 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
86 m4_define([b4_lpure_args
],
87 [b4_pure_if([b4_location_if([, yyllocp
])])[]b4_user_args
])
92 # Same as above, but on the lookahead, hence yyllocp instead of yylocp.
93 m4_define([b4_lpure_formals
],
94 [b4_pure_if([b4_location_if([YYLTYPE
*yyllocp
])])[]b4_user_formals
])
97 ## ----------------- ##
98 ## Semantic Values. ##
99 ## ----------------- ##
102 # b4_lhs_value([TYPE])
103 # --------------------
104 # Expansion of $<TYPE>$.
105 m4_define([b4_lhs_value
],
106 [(*yyvalp
)[]m4_ifval([$
1], [.$
1])])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [yyvsp@
{YYFILL (m4_eval([$
2 - $
1]))@
}.yystate
.yysemantics
.yysval
[]m4_ifval([$
3], [.$
3])])
125 m4_define([b4_lhs_location
],
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
133 m4_define([b4_rhs_location
],
134 [yyvsp@
{YYFILL (m4_eval([$
2 - $
1]))@
}.yystate
.yyloc
])
136 # We do want M4 expansion after # for CPP macros.
139 @output @output_parser_name@
140 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
142 /* This is the parser code for GLR (Generalized LR) parser. */
151 m4_if(b4_prefix
[], [yy
], [],
152 [/* If NAME_PREFIX is specified substitute the variables and functions
154 #define yyparse b4_prefix[]parse
155 #define yylex b4_prefix[]lex
156 #define yyerror b4_prefix[]error
157 #define yylval b4_prefix[]lval
158 #define yychar b4_prefix[]char
159 #define yydebug b4_prefix[]debug
160 #define yynerrs b4_prefix[]nerrs
161 b4_location_if([#define yylloc b4_prefix[]lloc])])
163 b4_token_defines(b4_tokens
)
165 /* Copy the first part of user declarations. */
168 /* Enabling traces. */
170 # define YYDEBUG ]b4_debug[
173 /* Enabling verbose error messages. */
174 #ifdef YYERROR_VERBOSE
175 # undef YYERROR_VERBOSE
176 # define YYERROR_VERBOSE 1
178 # define YYERROR_VERBOSE ]b4_error_verbose[
181 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
182 ]m4_ifdef([b4_stype
],
183 [b4_syncline([b4_stype_line
], [b4_filename
])
184 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
185 /* Line __line__ of glr.c. */
186 b4_syncline([@oline@
], [@ofile@
])],
187 [typedef int YYSTYPE
;])[
188 # define YYSTYPE_IS_DECLARED 1
189 # define YYSTYPE_IS_TRIVIAL 1
192 #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
193 typedef struct YYLTYPE
200 # define YYLTYPE_IS_DECLARED 1
201 # define YYLTYPE_IS_TRIVIAL 1
204 /* Default (constant) values used for initialization for null
205 right-hand sides. Unlike the standard yacc.c template,
206 here we set the default values of $$ and $@@ to zeroed-out
207 values. Since the default value of these quantities is undefined,
208 this behavior is technically correct. */
209 static YYSTYPE yyval_default
;
210 static YYLTYPE yyloc_default
;
212 /* Copy the second part of user declarations. */
215 ]/* Line __line__ of glr.c. */
216 b4_syncline([@oline@
], [@ofile@
])
221 typedef unsigned char yybool
;
230 #ifndef __attribute__
231 /* This feature is available in gcc versions 2.5 and later. */
232 # if !defined (__GNUC__) || __GNUC__ < 2 || \
233 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
234 # define __attribute__(Spec) /* empty */
238 #ifndef ATTRIBUTE_UNUSED
239 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
242 /* YYFINAL -- State number of the termination state. */
243 #define YYFINAL ]b4_final_state_number[
244 /* YYLAST -- Last index in YYTABLE. */
245 #define YYLAST ]b4_last[
247 /* YYNTOKENS -- Number of terminals. */
248 #define YYNTOKENS ]b4_tokens_number[
249 /* YYNNTS -- Number of nonterminals. */
250 #define YYNNTS ]b4_nterms_number[
251 /* YYNRULES -- Number of rules. */
252 #define YYNRULES ]b4_rules_number[
253 /* YYNRULES -- Number of states. */
254 #define YYNSTATES ]b4_states_number[
255 /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
256 #define YYMAXRHS ]b4_r2_max[
258 /* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
259 #define YYUNDEFTOK ]b4_undef_token_number[
260 #define YYMAXUTOK ]b4_user_token_number_max[
262 #define YYTRANSLATE(YYX) \
263 ((YYX <= 0) ? YYEOF : \
264 (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
266 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
267 static const ]b4_int_type_for([b4_translate
])[ yytranslate
[] =
273 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
275 static const ]b4_int_type_for([b4_prhs
])[ yyprhs
[] =
280 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
281 static const ]b4_int_type_for([b4_rhs
])[ yyrhs
[] =
286 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
287 static const ]b4_int_type_for([b4_rline
])[ yyrline
[] =
293 #if (YYDEBUG) || YYERROR_VERBOSE
294 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
295 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
296 static const char *const yytname
[] =
302 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
303 static const ]b4_int_type_for([b4_r1
])[ yyr1
[] =
308 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
309 static const ]b4_int_type_for([b4_r2
])[ yyr2
[] =
314 /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
315 static const ]b4_int_type_for([b4_dprec
])[ yydprec
[] =
320 /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
321 static const ]b4_int_type_for([b4_merger
])[ yymerger
[] =
326 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
327 doesn't specify something else to do. Zero means the default is an
329 static const ]b4_int_type_for([b4_defact
])[ yydefact
[] =
334 /* YYPDEFGOTO[NTERM-NUM]. */
335 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto
[] =
340 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
342 #define YYPACT_NINF ]b4_pact_ninf[
343 static const ]b4_int_type_for([b4_pact
])[ yypact
[] =
348 /* YYPGOTO[NTERM-NUM]. */
349 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto
[] =
354 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
355 positive, shift that token. If negative, reduce the rule which
356 number is the opposite. If zero, do what YYDEFACT says.
357 If YYTABLE_NINF, syntax error. */
358 #define YYTABLE_NINF ]b4_table_ninf[
359 static const ]b4_int_type_for([b4_table
])[ yytable
[] =
364 /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
365 list of conflicting reductions corresponding to action entry for
366 state STATE-NUM in yytable. 0 means no conflicts. The list in
367 yyconfl is terminated by a rule number of 0. */
368 static const ]b4_int_type_for([b4_conflict_list_heads
])[ yyconflp
[] =
370 ]b4_conflict_list_heads
[
373 /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
374 0, pointed into by YYCONFLP. */
375 ]dnl Do
not use b4_int_type_for here
, since there are places where
376 dnl pointers onto yyconfl are taken
, which type is
"short *".
377 dnl We probably ought to introduce a type
for confl
.
378 [static const short yyconfl
[] =
380 ]b4_conflicting_rules
[
383 static const ]b4_int_type_for([b4_check
])[ yycheck
[] =
388 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
389 symbol of state STATE-NUM. */
390 static const ]b4_int_type_for([b4_stos
])[ yystos
[] =
396 /* Prevent warning if -Wmissing-prototypes. */
397 ]b4_c_ansi_function_decl([yyparse
], [int], b4_parse_param
)[
399 /* Error token number */
402 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
405 #define YYRHSLOC(yyRhs,YYK) (yyRhs[YYK].yystate.yyloc)
407 #ifndef YYLLOC_DEFAULT
408 # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
409 yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
410 yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
411 yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
412 yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
415 /* YYLEX -- calling `yylex' with the right arguments. */
416 #define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
421 #define yynerrs (yystack->yyerrcnt)
423 #define yychar (yystack->yyrawchar)],
431 static const int YYEOF
= 0;
432 static const int YYEMPTY
= -2;
434 typedef enum { yyok
, yyaccept
, yyabort
, yyerr
} YYRESULTTAG
;
437 do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \
442 #if ! defined (YYFPRINTF)
443 # define YYFPRINTF fprintf
446 # define YYDPRINTF(Args) \
452 ]b4_yysymprint_generate([b4_c_ansi_function_def
])[
454 # define YYDSYMPRINT(Args) \
460 # define YYDSYMPRINTF(Title, Token, Value, Location) \
464 YYFPRINTF (stderr, "%s ", Title); \
465 yysymprint (stderr, \
466 Token, Value]b4_location_if([, Location])[); \
467 YYFPRINTF (stderr, "\n"); \
471 /* Nonzero means print parse trace. It is left uninitialized so that
472 multiple parsers can coexist. */
477 /* Avoid empty `if' bodies. */
478 # define YYDPRINTF(Args)
479 # define YYDSYMPRINT(Args)
480 # define YYDSYMPRINTF(Title, Token, Value, Location)
482 #endif /* !YYDEBUG */
484 /* YYINITDEPTH -- initial size of the parser's stacks. */
486 # define YYINITDEPTH ]b4_stack_depth_init[
489 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
490 if the built-in stack extension method is used).
492 Do not make this value too large; the results are undefined if
493 SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
494 evaluated with infinite-precision integer arithmetic. */
501 # define YYMAXDEPTH ]b4_stack_depth_max[
504 /* Minimum number of free items on the stack allowed after an
505 allocation. This is to allow allocation and initialization
506 to be completed by functions that call expandGLRStack before the
507 stack is expanded, thus insuring that all necessary pointers get
508 properly redirected to new data. */
511 #if (! defined (YYSTACKEXPANDABLE) \
512 && (! defined (__cplusplus) \
513 || (]b4_location_if([YYLTYPE_IS_TRIVIAL && ])[YYSTYPE_IS_TRIVIAL)))
514 #define YYSTACKEXPANDABLE 1
516 #define YYSTACKEXPANDABLE 0
519 /** State numbers, as in LALR(1) machine */
520 typedef int yyStateNum
;
522 /** Rule numbers, as in LALR(1) machine */
523 typedef int yyRuleNum
;
525 /** Grammar symbol */
526 typedef short yySymbol
;
528 /** Item references, as in LALR(1) machine */
529 typedef short yyItemNum
;
531 typedef struct yyGLRState yyGLRState
;
532 typedef struct yySemanticOption yySemanticOption
;
533 typedef union yyGLRStackItem yyGLRStackItem
;
534 typedef struct yyGLRStack yyGLRStack
;
535 typedef struct yyGLRStateSet yyGLRStateSet
;
540 yyStateNum yylrState
;
544 yySemanticOption
* yyfirstVal
;
550 struct yyGLRStateSet
{
551 yyGLRState
** yystates
;
552 size_t yysize
, yycapacity
;
555 struct yySemanticOption
{
559 yySemanticOption
* yynext
;
562 union yyGLRStackItem
{
564 yySemanticOption yyoption
;
576 jmp_buf yyexception_buffer
;
577 yyGLRStackItem
* yyitems
;
578 yyGLRStackItem
* yynextFree
;
580 yyGLRState
* yysplitPoint
;
581 yyGLRState
* yylastDeleted
;
582 yyGLRStateSet yytops
;
585 static void yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
);
586 static void yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[);
587 static void yyfreeGLRStack (yyGLRStack
* yystack
);
590 yyFail (yyGLRStack
* yystack
]b4_pure_formals
[, const char* yyformat
, ...)
592 yystack
->yyerrflag
= 1;
593 if (yyformat
!= NULL
)
597 va_start (yyap
, yyformat
);
598 vsprintf (yymsg
, yyformat
, yyap
);
599 yyerror (]b4_yyerror_args
[yymsg
);
601 longjmp (yystack
->yyexception_buffer
, 1);
604 #if YYDEBUG || YYERROR_VERBOSE
605 /** A printable representation of TOKEN. Valid until next call to
607 static inline const char*
608 yytokenName (yySymbol yytoken
)
610 return yytname
[yytoken
];
614 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
615 * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
616 * containing the pointer to the next state in the chain. Assumes
617 * YYLOW1 < YYLOW0. For convenience, returns YYLOW1. */
619 yyfill (yyGLRStackItem
* yyvsp
, int yylow0
, int yylow1
)
623 s
= yyvsp
[yylow0
].yystate
.yypred
;
624 for (i
= yylow0
-1; i
>= yylow1
; i
-= 1)
628 yyvsp
[i
].yystate
.yyresolved
= yytrue
;
629 yyvsp
[i
].yystate
.yysemantics
.yysval
= s
->yysemantics
.yysval
;
630 yyvsp
[i
].yystate
.yyloc
= s
->yyloc
;
631 s
= yyvsp
[i
].yystate
.yypred
= s
->yypred
;
636 /** Perform user action for rule number YYN, with RHS length YYRHSLEN,
637 * and top stack item YYVSP. YYLVALP points to place to put semantic
638 * value ($$), and yylocp points to place for location information
639 * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
640 * yyerr for YYERROR, yyabort for YYABORT. */
642 yyuserAction (yyRuleNum yyn
, int yyrhslen
, yyGLRStackItem
* yyvsp
,
643 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
, yyGLRStack
* yystack
646 int yynormal
= (yystack
->yysplitPoint
== NULL
);
651 *yyvalp
= yyval_default
;
652 *yylocp
= yyloc_default
;
656 *yyvalp
= yyvsp
[1-yyrhslen
].yystate
.yysemantics
.yysval
;
657 *yylocp
= yyvsp
[1-yyrhslen
].yystate
.yyloc
;
660 # define yyerrok (yystack->yyerrState = 0)
662 # define YYACCEPT return yyaccept
664 # define YYABORT return yyabort
666 # define YYERROR return yyerr
668 # define YYRECOVERING (yystack->yyerrState != 0)
670 # define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
673 ((yynormal || yylow <= (N)) ? (N) : (yylow = yyfill (yyvsp, yylow, N)))
675 # define YYBACKUP(Token, Value) \
677 yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
696 /* Line __line__ of glr.c. */
697 b4_syncline([@oline@
], [@ofile@
])
702 yyuserMerge (int yyn
, YYSTYPE
* yy0
, YYSTYPE
* yy1
)
704 YYSTYPE yyval
= *yy0
;
705 /* `Use' the arguments. */
716 /* Bison grammar-table manipulation. */
718 ]b4_yydestruct_generate([b4_c_ansi_function_def
])[
720 /** Number of symbols composing the right hand side of rule #RULE. */
722 yyrhsLength (yyRuleNum yyrule
)
727 /** Left-hand-side symbol for rule #RULE. */
728 static inline yySymbol
729 yylhsNonterm (yyRuleNum yyrule
)
734 #define yyis_pact_ninf(yystate) \
735 ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
737 ((yystate
) == YYPACT_NINF
))[
739 /** True iff LR state STATE has only a default reduction (regardless
742 yyisDefaultedState (yyStateNum yystate
)
744 return yyis_pact_ninf (yypact
[yystate
]);
747 /** The default reduction for STATE, assuming it has one. */
748 static inline yyRuleNum
749 yydefaultAction (yyStateNum yystate
)
751 return yydefact
[yystate
];
754 #define yyis_table_ninf(yytable_value) \
755 ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
757 ((yytable_value
) == YYTABLE_NINF
))[
759 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
761 * R < 0: Reduce on rule -R.
763 * R > 0: Shift to state R.
764 * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
765 * conflicting reductions.
768 yygetLRActions (yyStateNum yystate
, int yytoken
,
769 int* yyaction
, const short** yyconflicts
)
771 int yyindex
= yypact
[yystate
] + yytoken
;
772 if (yyindex
< 0 || YYLAST
< yyindex
|| yycheck
[yyindex
] != yytoken
)
774 *yyaction
= -yydefact
[yystate
];
775 *yyconflicts
= yyconfl
;
777 else if (! yyis_table_ninf (yytable
[yyindex
]))
779 *yyaction
= yytable
[yyindex
];
780 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
785 *yyconflicts
= yyconfl
+ yyconflp
[yyindex
];
789 static inline yyStateNum
790 yyLRgotoState (yyStateNum yystate
, yySymbol yylhs
)
793 yyr
= yypgoto
[yylhs
- YYNTOKENS
] + yystate
;
794 if (0 <= yyr
&& yyr
<= YYLAST
&& yycheck
[yyr
] == yystate
)
797 return yydefgoto
[yylhs
- YYNTOKENS
];
801 yyisShiftAction (int yyaction
)
807 yyisErrorAction (int yyaction
)
809 return yyaction
== 0;
815 yyaddDeferredAction (yyGLRStack
* yystack
, yyGLRState
* yystate
,
816 yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
818 yySemanticOption
* yynewItem
;
819 yynewItem
= &yystack
->yynextFree
->yyoption
;
820 yystack
->yyspaceLeft
-= 1;
821 yystack
->yynextFree
+= 1;
822 yynewItem
->yyisState
= yyfalse
;
823 yynewItem
->yystate
= rhs
;
824 yynewItem
->yyrule
= yyrule
;
825 yynewItem
->yynext
= yystate
->yysemantics
.yyfirstVal
;
826 yystate
->yysemantics
.yyfirstVal
= yynewItem
;
827 if (yystack
->yyspaceLeft
< YYHEADROOM
)
828 yyexpandGLRStack (yystack
]b4_pure_args
[);
833 /** Initialize SET to a singleton set containing an empty stack. */
835 yyinitStateSet (yyGLRStateSet
* yyset
)
838 yyset
->yycapacity
= 16;
839 yyset
->yystates
= (yyGLRState
**) malloc (16 * sizeof (yyset
->yystates
[0]));
840 yyset
->yystates
[0] = NULL
;
843 static void yyfreeStateSet (yyGLRStateSet
* yyset
)
845 free (yyset
->yystates
);
848 /** Initialize STACK to a single empty stack, with total maximum
849 * capacity for all stacks of SIZE. */
851 yyinitGLRStack (yyGLRStack
* yystack
, size_t yysize
)
853 yystack
->yyerrflag
= 0;
854 yystack
->yyerrState
= 0;
856 yystack
->yyspaceLeft
= yysize
;
857 yystack
->yynextFree
= yystack
->yyitems
=
858 (yyGLRStackItem
*) malloc (yysize
* sizeof (yystack
->yynextFree
[0]));
859 yystack
->yysplitPoint
= NULL
;
860 yystack
->yylastDeleted
= NULL
;
861 yyinitStateSet (&yystack
->yytops
);
864 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
865 &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
867 /** If STACK is expandable, extend it. WARNING: Pointers into the
868 stack from outside should be considered invalid after this call.
869 We always expand when there are 1 or fewer items left AFTER an
870 allocation, so that we can avoid having external pointers exist
871 across an allocation. */
873 yyexpandGLRStack (yyGLRStack
* yystack
]b4_pure_formals
[)
875 #if YYSTACKEXPANDABLE
876 yyGLRStack yynewStack
;
877 yyGLRStackItem
* yyp0
, *yyp1
;
878 size_t yysize
, yynewSize
;
880 yysize
= yystack
->yynextFree
- yystack
->yyitems
;
881 if (YYMAXDEPTH
<= yysize
)
882 yyFail (yystack
][]b4_pure_args
[, "parser stack overflow");
883 yynewSize
= 2*yysize
;
884 if (YYMAXDEPTH
< yynewSize
)
885 yynewSize
= YYMAXDEPTH
;
886 yyinitGLRStack (&yynewStack
, yynewSize
);
887 for (yyp0
= yystack
->yyitems
, yyp1
= yynewStack
.yyitems
, yyn
= yysize
;
889 yyn
-= 1, yyp0
+= 1, yyp1
+= 1)
892 if (*(yybool
*) yyp0
)
894 yyGLRState
* yys0
= &yyp0
->yystate
;
895 yyGLRState
* yys1
= &yyp1
->yystate
;
896 if (yys0
->yypred
!= NULL
)
898 YYRELOC (yyp0
, yyp1
, yys0
->yypred
, yystate
);
899 if (! yys0
->yyresolved
&& yys0
->yysemantics
.yyfirstVal
!= NULL
)
900 yys1
->yysemantics
.yyfirstVal
=
901 YYRELOC(yyp0
, yyp1
, yys0
->yysemantics
.yyfirstVal
, yyoption
);
905 yySemanticOption
* yyv0
= &yyp0
->yyoption
;
906 yySemanticOption
* yyv1
= &yyp1
->yyoption
;
907 if (yyv0
->yystate
!= NULL
)
908 yyv1
->yystate
= YYRELOC (yyp0
, yyp1
, yyv0
->yystate
, yystate
);
909 if (yyv0
->yynext
!= NULL
)
910 yyv1
->yynext
= YYRELOC (yyp0
, yyp1
, yyv0
->yynext
, yyoption
);
913 if (yystack
->yysplitPoint
!= NULL
)
914 yystack
->yysplitPoint
= YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
915 yystack
->yysplitPoint
, yystate
);
917 for (yyn
= 0; yyn
< yystack
->yytops
.yysize
; yyn
+= 1)
918 if (yystack
->yytops
.yystates
[yyn
] != NULL
)
919 yystack
->yytops
.yystates
[yyn
] =
920 YYRELOC (yystack
->yyitems
, yynewStack
.yyitems
,
921 yystack
->yytops
.yystates
[yyn
], yystate
);
922 free (yystack
->yyitems
);
923 yystack
->yyitems
= yynewStack
.yyitems
;
924 yystack
->yynextFree
= yynewStack
.yynextFree
+ yysize
;
925 yystack
->yyspaceLeft
= yynewStack
.yyspaceLeft
- yysize
;
929 yyFail (yystack
][]b4_lpure_args
[, "parser stack overflow");
934 yyfreeGLRStack (yyGLRStack
* yystack
)
936 free (yystack
->yyitems
);
937 yyfreeStateSet (&yystack
->yytops
);
940 /** Assuming that S is a GLRState somewhere on STACK, update the
941 * splitpoint of STACK, if needed, so that it is at least as deep as
944 yyupdateSplit (yyGLRStack
* yystack
, yyGLRState
* yys
)
946 if (yystack
->yysplitPoint
!= NULL
&& yystack
->yysplitPoint
> yys
)
947 yystack
->yysplitPoint
= yys
;
950 /** Invalidate stack #K in STACK. */
952 yymarkStackDeleted (yyGLRStack
* yystack
, int yyk
)
954 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
955 yystack
->yylastDeleted
= yystack
->yytops
.yystates
[yyk
];
956 yystack
->yytops
.yystates
[yyk
] = NULL
;
959 /** Undelete the last stack that was marked as deleted. Can only be
960 done once after a deletion, and only when all other stacks have
963 yyundeleteLastStack (yyGLRStack
* yystack
)
965 if (yystack
->yylastDeleted
== NULL
|| yystack
->yytops
.yysize
!= 0)
967 yystack
->yytops
.yystates
[0] = yystack
->yylastDeleted
;
968 yystack
->yytops
.yysize
= 1;
969 YYDPRINTF ((stderr
, "Restoring last deleted stack as stack #0.\n"));
970 yystack
->yylastDeleted
= NULL
;
974 yyremoveDeletes (yyGLRStack
* yystack
)
978 while (yyj
< yystack
->yytops
.yysize
)
980 if (yystack
->yytops
.yystates
[yyi
] == NULL
)
984 YYDPRINTF ((stderr
, "Removing dead stacks.\n"));
986 yystack
->yytops
.yysize
-= 1;
990 yystack
->yytops
.yystates
[yyj
] = yystack
->yytops
.yystates
[yyi
];
993 YYDPRINTF ((stderr
, "Rename stack %d -> %d.\n", yyi
, yyj
));
1001 /** Shift to a new state on stack #K of STACK, corresponding to LR state
1002 * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
1004 yyglrShift (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
, size_t yyposn
,
1005 YYSTYPE yysval
, YYLTYPE
* yylocp
]b4_user_formals
[)
1007 yyGLRStackItem
* yynewItem
;
1009 yynewItem
= yystack
->yynextFree
;
1010 yystack
->yynextFree
+= 1;
1011 yystack
->yyspaceLeft
-= 1;
1012 yynewItem
->yystate
.yyisState
= yytrue
;
1013 yynewItem
->yystate
.yylrState
= yylrState
;
1014 yynewItem
->yystate
.yyposn
= yyposn
;
1015 yynewItem
->yystate
.yyresolved
= yytrue
;
1016 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1017 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1018 yynewItem
->yystate
.yysemantics
.yysval
= yysval
;
1019 yynewItem
->yystate
.yyloc
= *yylocp
;
1020 if (yystack
->yyspaceLeft
< YYHEADROOM
)
1021 yyexpandGLRStack (yystack
]b4_pure_args
[);
1024 /** Shift stack #K of YYSTACK, to a new state corresponding to LR
1025 * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
1026 * semantic value of YYRHS under the action for YYRULE. */
1028 yyglrShiftDefer (yyGLRStack
* yystack
, int yyk
, yyStateNum yylrState
,
1029 size_t yyposn
, yyGLRState
* rhs
, yyRuleNum yyrule
]b4_pure_formals
[)
1031 yyGLRStackItem
* yynewItem
;
1033 yynewItem
= yystack
->yynextFree
;
1034 yynewItem
->yystate
.yyisState
= yytrue
;
1035 yynewItem
->yystate
.yylrState
= yylrState
;
1036 yynewItem
->yystate
.yyposn
= yyposn
;
1037 yynewItem
->yystate
.yyresolved
= yyfalse
;
1038 yynewItem
->yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1039 yynewItem
->yystate
.yysemantics
.yyfirstVal
= NULL
;
1040 yystack
->yytops
.yystates
[yyk
] = &yynewItem
->yystate
;
1041 yystack
->yynextFree
+= 1;
1042 yystack
->yyspaceLeft
-= 1;
1043 yyaddDeferredAction (yystack
, &yynewItem
->yystate
, rhs
, yyrule
]b4_pure_args
[);
1046 /** Pop the symbols consumed by reduction #RULE from the top of stack
1047 * #K of STACK, and perform the appropriate semantic action on their
1048 * semantic values. Assumes that all ambiguities in semantic values
1049 * have been previously resolved. Set *VALP to the resulting value,
1050 * and *LOCP to the computed location (if any). Return value is as
1051 * for userAction. */
1052 static inline YYRESULTTAG
1053 yydoAction (yyGLRStack
* yystack
, int yyk
, yyRuleNum yyrule
,
1054 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1056 int yynrhs
= yyrhsLength (yyrule
);
1058 if (yystack
->yysplitPoint
== NULL
)
1060 /* Standard special case: single stack. */
1061 yyGLRStackItem
* rhs
= (yyGLRStackItem
*) yystack
->yytops
.yystates
[yyk
];
1064 yystack
->yynextFree
-= yynrhs
;
1065 yystack
->yyspaceLeft
+= yynrhs
;
1066 yystack
->yytops
.yystates
[0] = & yystack
->yynextFree
[-1].yystate
;
1069 *yyvalp
= yyval_default
;
1070 *yylocp
= yyloc_default
;
1074 *yyvalp
= rhs
[1-yynrhs
].yystate
.yysemantics
.yysval
;
1075 *yylocp
= rhs
[1-yynrhs
].yystate
.yyloc
;
1077 return yyuserAction (yyrule
, yynrhs
, rhs
,
1078 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1084 yyGLRStackItem yyrhsVals
[YYMAXRHS
+1];
1085 yys
= yyrhsVals
[YYMAXRHS
].yystate
.yypred
= yystack
->yytops
.yystates
[yyk
];
1086 for (yyi
= 0; yyi
< yynrhs
; yyi
+= 1)
1092 yyupdateSplit (yystack
, yys
);
1093 yystack
->yytops
.yystates
[yyk
] = yys
;
1096 *yyvalp
= yyval_default
;
1097 *yylocp
= yyloc_default
;
1101 *yyvalp
= yyrhsVals
[1].yystate
.yysemantics
.yysval
;
1102 *yylocp
= yyrhsVals
[1].yystate
.yyloc
;
1104 return yyuserAction (yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
- 1,
1105 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1110 # define YY_REDUCE_PRINT(K, Rule)
1112 # define YY_REDUCE_PRINT(K, Rule) \
1115 yy_reduce_print (K, Rule); \
1118 /*----------------------------------------------------------.
1119 | Report that the RULE is going to be reduced on stack #K. |
1120 `----------------------------------------------------------*/
1123 yy_reduce_print (size_t yyk
, yyRuleNum yyrule
)
1126 unsigned int yylineno
= yyrline
[yyrule
];
1127 YYFPRINTF (stderr
, "Reducing stack %d by rule %d (line %u), ",
1128 yyk
, yyrule
- 1, yylineno
);
1129 /* Print the symbols being reduced, and their result. */
1130 for (yyi
= yyprhs
[yyrule
]; 0 <= yyrhs
[yyi
]; yyi
++)
1131 YYFPRINTF (stderr
, "%s ", yytokenName (yyrhs
[yyi
]));
1132 YYFPRINTF (stderr
, "-> %s\n", yytokenName (yyr1
[yyrule
]));
1136 /** Pop items off stack #K of STACK according to grammar rule RULE,
1137 * and push back on the resulting nonterminal symbol. Perform the
1138 * semantic action associated with RULE and store its value with the
1139 * newly pushed state, if FORCEEVAL or if STACK is currently
1140 * unambiguous. Otherwise, store the deferred semantic action with
1141 * the new state. If the new state would have an identical input
1142 * position, LR state, and predecessor to an existing state on the stack,
1143 * it is identified with that existing state, eliminating stack #K from
1144 * the STACK. In this case, the (necessarily deferred) semantic value is
1145 * added to the options for the existing state's semantic value.
1147 static inline YYRESULTTAG
1148 yyglrReduce (yyGLRStack
* yystack
, size_t yyk
, yyRuleNum yyrule
,
1149 yybool yyforceEval
]b4_pure_formals
[)
1151 size_t yyposn
= yystack
->yytops
.yystates
[yyk
]->yyposn
;
1153 if (yyforceEval
|| yystack
->yysplitPoint
== NULL
)
1158 YY_REDUCE_PRINT (yyk
, yyrule
);
1159 YYCHK (yydoAction (yystack
, yyk
, yyrule
, &yysval
, &yyloc
]b4_user_args
[));
1160 yyglrShift (yystack
, yyk
,
1161 yyLRgotoState (yystack
->yytops
.yystates
[yyk
]->yylrState
,
1162 yylhsNonterm (yyrule
)),
1163 yyposn
, yysval
, &yyloc
]b4_user_args
[);
1169 yyGLRState
* yys
, *yys0
= yystack
->yytops
.yystates
[yyk
];
1170 yyStateNum yynewLRState
;
1172 for (yys
= yystack
->yytops
.yystates
[yyk
], yyn
= yyrhsLength (yyrule
);
1179 yyupdateSplit (yystack
, yys
);
1180 yynewLRState
= yyLRgotoState (yys
->yylrState
, yylhsNonterm (yyrule
));
1182 "Reduced stack %d by rule #%d; action deferred. "
1183 "Now in state %d.\n",
1184 yyk
, yyrule
-1, yynewLRState
));
1185 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1186 if (yyi
!= yyk
&& yystack
->yytops
.yystates
[yyi
] != NULL
)
1188 yyGLRState
* yyp
, *yysplit
= yystack
->yysplitPoint
;
1189 yyp
= yystack
->yytops
.yystates
[yyi
];
1190 while (yyp
!= yys
&& yyp
!= yysplit
&& yyp
->yyposn
>= yyposn
)
1192 if (yyp
->yylrState
== yynewLRState
&& yyp
->yypred
== yys
)
1194 yyaddDeferredAction (yystack
, yyp
, yys0
, yyrule
]b4_pure_args
[);
1195 yymarkStackDeleted (yystack
, yyk
);
1196 YYDPRINTF ((stderr
, "Merging stack %d into stack %d.\n",
1203 yystack
->yytops
.yystates
[yyk
] = yys
;
1204 yyglrShiftDefer (yystack
, yyk
, yynewLRState
, yyposn
, yys0
, yyrule
]b4_pure_args
[);
1210 yysplitStack (yyGLRStack
* yystack
, int yyk
)
1212 if (yystack
->yysplitPoint
== NULL
)
1216 yystack
->yysplitPoint
= yystack
->yytops
.yystates
[yyk
];
1218 if (yystack
->yytops
.yysize
>= yystack
->yytops
.yycapacity
)
1220 yystack
->yytops
.yycapacity
*= 2;
1221 yystack
->yytops
.yystates
=
1222 (yyGLRState
**) realloc (yystack
->yytops
.yystates
,
1223 yystack
->yytops
.yycapacity
1224 * sizeof (yyGLRState
*));
1226 yystack
->yytops
.yystates
[yystack
->yytops
.yysize
]
1227 = yystack
->yytops
.yystates
[yyk
];
1228 yystack
->yytops
.yysize
+= 1;
1229 return yystack
->yytops
.yysize
-1;
1232 /** True iff Y0 and Y1 represent identical options at the top level.
1233 * That is, they represent the same rule applied to RHS symbols
1234 * that produce the same terminal symbols. */
1236 yyidenticalOptions (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1238 if (yyy0
->yyrule
== yyy1
->yyrule
)
1240 yyGLRState
*yys0
, *yys1
;
1242 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1243 yyn
= yyrhsLength (yyy0
->yyrule
);
1245 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1246 if (yys0
->yyposn
!= yys1
->yyposn
)
1254 /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1255 * alternative semantic values for the RHS-symbols of Y1 into the
1256 * corresponding semantic value sets of the symbols of Y0. */
1258 yymergeOptionSets (yySemanticOption
* yyy0
, yySemanticOption
* yyy1
)
1260 yyGLRState
*yys0
, *yys1
;
1262 for (yys0
= yyy0
->yystate
, yys1
= yyy1
->yystate
,
1263 yyn
= yyrhsLength (yyy0
->yyrule
);
1265 yys0
= yys0
->yypred
, yys1
= yys1
->yypred
, yyn
-= 1)
1268 else if (! yys0
->yyresolved
&& ! yys1
->yyresolved
)
1270 yySemanticOption
* yyz
;
1271 for (yyz
= yys0
->yysemantics
.yyfirstVal
; yyz
->yynext
!= NULL
;
1274 yyz
->yynext
= yys1
->yysemantics
.yyfirstVal
;
1278 /** Y0 and Y1 represent two possible actions to take in a given
1279 * parsing state; return 0 if no combination is possible,
1280 * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
1282 yypreference (yySemanticOption
* y0
, yySemanticOption
* y1
)
1284 yyRuleNum r0
= y0
->yyrule
, r1
= y1
->yyrule
;
1285 int p0
= yydprec
[r0
], p1
= yydprec
[r1
];
1289 if (yymerger
[r0
] == 0 || yymerger
[r0
] != yymerger
[r1
])
1294 if (p0
== 0 || p1
== 0)
1303 static YYRESULTTAG
yyresolveValue (yySemanticOption
* yyoptionList
,
1304 yyGLRStack
* yystack
, YYSTYPE
* yyvalp
,
1305 YYLTYPE
* yylocp
]b4_user_formals
[);
1308 yyresolveStates (yyGLRState
* yys
, int yyn
, yyGLRStack
* yystack
]b4_user_formals
[)
1313 if (yys
->yypred
== NULL
)
1315 yyflag
= yyresolveStates (yys
->yypred
, yyn
-1, yystack
]b4_user_args
[);
1318 if (! yys
->yyresolved
)
1320 yyflag
= yyresolveValue (yys
->yysemantics
.yyfirstVal
, yystack
,
1321 &yys
->yysemantics
.yysval
, &yys
->yyloc
1325 yys
->yyresolved
= yytrue
;
1332 yyresolveAction (yySemanticOption
* yyopt
, yyGLRStack
* yystack
,
1333 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1335 yyGLRStackItem yyrhsVals
[YYMAXRHS
+1];
1338 yynrhs
= yyrhsLength (yyopt
->yyrule
);
1339 YYCHK (yyresolveStates (yyopt
->yystate
, yynrhs
, yystack
]b4_user_args
[));
1340 yyrhsVals
[YYMAXRHS
].yystate
.yypred
= yyopt
->yystate
;
1341 return yyuserAction (yyopt
->yyrule
, yynrhs
, yyrhsVals
+ YYMAXRHS
- 1,
1342 yyvalp
, yylocp
, yystack
]b4_user_args
[);
1347 yyreportTree (yySemanticOption
* yyx
, int yyindent
)
1349 int yynrhs
= yyrhsLength (yyx
->yyrule
);
1352 yyGLRState
* yystates
[YYMAXRHS
];
1353 yyGLRState yyleftmost_state
;
1355 for (yyi
= yynrhs
, yys
= yyx
->yystate
; 0 < yyi
; yyi
-= 1, yys
= yys
->yypred
)
1356 yystates
[yyi
] = yys
;
1359 yyleftmost_state
.yyposn
= 0;
1360 yystates
[0] = &yyleftmost_state
;
1365 if (yyx
->yystate
->yyposn
< yys
->yyposn
+ 1)
1366 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, empty>\n",
1367 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1370 YYFPRINTF (stderr
, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1371 yyindent
, "", yytokenName (yylhsNonterm (yyx
->yyrule
)),
1372 yyx
->yyrule
, yys
->yyposn
+1, yyx
->yystate
->yyposn
);
1373 for (yyi
= 1; yyi
<= yynrhs
; yyi
+= 1)
1375 if (yystates
[yyi
]->yyresolved
)
1377 if (yystates
[yyi
-1]->yyposn
+1 > yystates
[yyi
]->yyposn
)
1378 YYFPRINTF (stderr
, "%*s%s <empty>\n", yyindent
+2, "",
1379 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]));
1381 YYFPRINTF (stderr
, "%*s%s <tokens %d .. %d>\n", yyindent
+2, "",
1382 yytokenName (yyrhs
[yyprhs
[yyx
->yyrule
]+yyi
-1]),
1383 yystates
[yyi
-1]->yyposn
+1, yystates
[yyi
]->yyposn
);
1386 yyreportTree (yystates
[yyi
]->yysemantics
.yyfirstVal
, yyindent
+2);
1392 yyreportAmbiguity (yySemanticOption
* yyx0
, yySemanticOption
* yyx1
,
1393 yyGLRStack
* yystack
]b4_pure_formals
[)
1395 /* `Unused' warnings. */
1400 YYFPRINTF (stderr
, "Ambiguity detected.\n");
1401 YYFPRINTF (stderr
, "Option 1,\n");
1402 yyreportTree (yyx0
, 2);
1403 YYFPRINTF (stderr
, "\nOption 2,\n");
1404 yyreportTree (yyx1
, 2);
1405 YYFPRINTF (stderr
, "\n");
1407 yyFail (yystack
][]b4_pure_args
[, "ambiguity detected");
1411 /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1412 * actions, and return the result. */
1414 yyresolveValue (yySemanticOption
* yyoptionList
, yyGLRStack
* yystack
,
1415 YYSTYPE
* yyvalp
, YYLTYPE
* yylocp
]b4_user_formals
[)
1417 yySemanticOption
* yybest
;
1418 yySemanticOption
* yyp
;
1421 yybest
= yyoptionList
;
1423 for (yyp
= yyoptionList
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1425 if (yyidenticalOptions (yybest
, yyp
))
1426 yymergeOptionSets (yybest
, yyp
);
1428 switch (yypreference (yybest
, yyp
))
1431 yyreportAmbiguity (yybest
, yyp
, yystack
]b4_pure_args
[);
1447 int yyprec
= yydprec
[yybest
->yyrule
];
1448 YYCHK (yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[));
1449 for (yyp
= yybest
->yynext
; yyp
!= NULL
; yyp
= yyp
->yynext
)
1451 if (yyprec
== yydprec
[yyp
->yyrule
])
1455 YYCHK (yyresolveAction (yyp
, yystack
, &yyval1
, &yydummy
]b4_user_args
[));
1456 *yyvalp
= yyuserMerge (yymerger
[yyp
->yyrule
], yyvalp
, &yyval1
);
1462 return yyresolveAction (yybest
, yystack
, yyvalp
, yylocp
]b4_user_args
[);
1466 yyresolveStack (yyGLRStack
* yystack
]b4_user_formals
[)
1468 if (yystack
->yysplitPoint
!= NULL
)
1473 for (yyn
= 0, yys
= yystack
->yytops
.yystates
[0];
1474 yys
!= yystack
->yysplitPoint
;
1475 yys
= yys
->yypred
, yyn
+= 1)
1477 YYCHK (yyresolveStates (yystack
->yytops
.yystates
[0], yyn
, yystack
1484 yycompressStack (yyGLRStack
* yystack
)
1486 yyGLRState
* yyp
, *yyq
, *yyr
;
1488 if (yystack
->yytops
.yysize
!= 1 || yystack
->yysplitPoint
== NULL
)
1491 for (yyp
= yystack
->yytops
.yystates
[0], yyq
= yyp
->yypred
, yyr
= NULL
;
1492 yyp
!= yystack
->yysplitPoint
;
1493 yyr
= yyp
, yyp
= yyq
, yyq
= yyp
->yypred
)
1496 yystack
->yyspaceLeft
+= yystack
->yynextFree
- yystack
->yyitems
;
1497 yystack
->yynextFree
= ((yyGLRStackItem
*) yystack
->yysplitPoint
) + 1;
1498 yystack
->yyspaceLeft
-= yystack
->yynextFree
- yystack
->yyitems
;
1499 yystack
->yysplitPoint
= NULL
;
1500 yystack
->yylastDeleted
= NULL
;
1504 yystack
->yynextFree
->yystate
= *yyr
;
1506 yystack
->yynextFree
->yystate
.yypred
= & yystack
->yynextFree
[-1].yystate
;
1507 yystack
->yytops
.yystates
[0] = &yystack
->yynextFree
->yystate
;
1508 yystack
->yynextFree
+= 1;
1509 yystack
->yyspaceLeft
-= 1;
1514 yyprocessOneStack (yyGLRStack
* yystack
, int yyk
,
1515 size_t yyposn
, YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
1519 const short* yyconflicts
;
1521 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1523 while (yystack
->yytops
.yystates
[yyk
] != NULL
)
1525 yyStateNum yystate
= yystack
->yytops
.yystates
[yyk
]->yylrState
;
1526 YYDPRINTF ((stderr
, "Stack %d Entering state %d\n", yyk
, yystate
));
1528 if (yystate
== YYFINAL
)
1530 if (yyisDefaultedState (yystate
))
1532 yyrule
= yydefaultAction (yystate
);
1535 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1536 yymarkStackDeleted (yystack
, yyk
);
1539 YYCHK (yyglrReduce (yystack
, yyk
, yyrule
, yyfalse
]b4_lpure_args
[));
1543 if (*yytokenp
== YYEMPTY
)
1545 YYDPRINTF ((stderr
, "Reading a token: "));
1547 *yytokenp
= YYTRANSLATE (yychar
);
1548 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1550 yygetLRActions (yystate
, *yytokenp
, &yyaction
, &yyconflicts
);
1552 while (*yyconflicts
!= 0)
1554 int yynewStack
= yysplitStack (yystack
, yyk
);
1555 YYDPRINTF ((stderr
, "Splitting off stack %d from %d.\n",
1557 YYCHK (yyglrReduce (yystack
, yynewStack
,
1558 *yyconflicts
, yyfalse
]b4_lpure_args
[));
1559 YYCHK (yyprocessOneStack (yystack
, yynewStack
, yyposn
,
1560 yylvalp
, yyllocp
]b4_user_args
[));
1564 if (yyisShiftAction (yyaction
))
1566 YYDPRINTF ((stderr
, "Shifting token %s on stack %d, ",
1567 yytokenName (*yytokenp
), yyk
));
1568 yyglrShift (yystack
, yyk
, yyaction
, yyposn
+1,
1569 *yylvalp
, yyllocp
]b4_user_args
[);
1570 YYDPRINTF ((stderr
, "which is now in state #%d\n",
1571 yystack
->yytops
.yystates
[yyk
]->yylrState
));
1574 else if (yyisErrorAction (yyaction
))
1576 YYDPRINTF ((stderr
, "Stack %d dies.\n", yyk
));
1577 yymarkStackDeleted (yystack
, yyk
);
1581 YYCHK (yyglrReduce (yystack
, yyk
, -yyaction
, yyfalse
]b4_lpure_args
[));
1588 yyreportSyntaxError (yyGLRStack
* yystack
,
1589 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1591 /* `Unused' warnings. */
1595 if (yystack
->yyerrState
== 0)
1598 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1600 const char* yyprefix
;
1601 yyn
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1602 if (YYPACT_NINF
< yyn
&& yyn
< YYLAST
)
1608 /* Start YYX at -YYN if negative to avoid negative indexes in
1610 int yyxbase
= yyn
< 0 ? -yyn
: 0;
1612 /* Stay within bounds of both yycheck and yytname. */
1613 int yychecklim
= YYLAST
- yyn
;
1614 int yynsyms
= sizeof (yytname
) / sizeof (yytname
[0]);
1615 int yyxlim
= yychecklim
< yynsyms
? yychecklim
: yynsyms
;
1618 yyprefix
= ", expecting ";
1619 for (yyx
= yyxbase
; yyx
< yyxlim
&& yycount
< 5; yyx
+= 1)
1620 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1622 yysize
+= strlen (yytokenName (yyx
)) + strlen (yyprefix
);
1631 yysize
+= (sizeof ("syntax error, unexpected ")
1632 + strlen (yytokenName (*yytokenp
)));
1633 yymsg
= (char*) malloc (yysize
);
1637 sprintf (yyp
, "syntax error, unexpected %s",
1638 yytokenName (*yytokenp
));
1639 yyp
+= strlen (yyp
);
1642 yyprefix
= ", expecting ";
1643 for (yyx
= yyxbase
; yyx
< yyxlim
; yyx
+= 1)
1644 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1646 sprintf (yyp
, "%s%s", yyprefix
, yytokenName (yyx
));
1647 yyp
+= strlen (yyp
);
1651 yyerror (]b4_lyyerror_args
[yymsg
);
1655 yyerror (]b4_lyyerror_args
["syntax error; also virtual memory exhausted");
1658 #endif /* YYERROR_VERBOSE */
1659 yyerror (]b4_lyyerror_args
["syntax error");
1664 /* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
1665 YYLVALP, and YYLLOCP point to the syntactic category, semantic
1666 value, and location of the lookahead. */
1668 yyrecoverSyntaxError (yyGLRStack
* yystack
,
1669 YYSTYPE
* yylvalp
, YYLTYPE
* yyllocp
]b4_user_formals
[)
1671 yySymbol
* const yytokenp
= yystack
->yytokenp
;
1675 if (yystack
->yyerrState
== 0)
1676 yystack
->yyerrState
= 3;
1677 else if (yystack
->yyerrState
== 3)
1678 /* We just shifted the error token and (perhaps) took some
1679 reductions. Skip tokens until we can proceed. */
1682 if (*yytokenp
== YYEOF
)
1684 /* Now pop stack until we find a state that shifts the
1686 while (yystack
->yytops
.yystates
[0] != NULL
)
1688 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1689 YYDSYMPRINTF ("Error: popping",
1690 yystos
[yys
->yylrState
],
1691 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1692 yydestruct (yystos
[yys
->yylrState
],
1693 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1694 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1695 yystack
->yynextFree
-= 1;
1696 yystack
->yyspaceLeft
+= 1;
1698 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1700 if (*yytokenp
!= YYEMPTY
)
1702 YYDSYMPRINTF ("Error: discarding", *yytokenp
, yylvalp
, yyllocp
);
1703 yydestruct (*yytokenp
, yylvalp
]b4_location_if([, yyllocp
])[);
1705 YYDPRINTF ((stderr
, "Reading a token: "));
1707 *yytokenp
= YYTRANSLATE (yychar
);
1708 YYDSYMPRINTF ("Next token is", *yytokenp
, yylvalp
, yyllocp
);
1709 yyj
= yypact
[yystack
->yytops
.yystates
[0]->yylrState
];
1710 if (yyis_pact_ninf (yyj
))
1711 /* Something's not right; we shouldn't be here. */
1712 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1714 if (yyj
< 0 || YYLAST
< yyj
|| yycheck
[yyj
] != *yytokenp
)
1716 if (yydefact
[yystack
->yytops
.yystates
[0]->yylrState
] != 0)
1719 else if (yytable
[yyj
] != 0 && ! yyis_table_ninf (yytable
[yyj
]))
1723 /* Reduce to one stack. */
1724 for (yyk
= 0; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1725 if (yystack
->yytops
.yystates
[yyk
] != NULL
)
1727 if (yyk
>= yystack
->yytops
.yysize
)
1728 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1729 for (yyk
+= 1; yyk
< yystack
->yytops
.yysize
; yyk
+= 1)
1730 yymarkStackDeleted (yystack
, yyk
);
1731 yyremoveDeletes (yystack
);
1732 yycompressStack (yystack
);
1734 /* Now pop stack until we find a state that shifts the error token. */
1735 while (yystack
->yytops
.yystates
[0] != NULL
)
1737 yyGLRState
*yys
= yystack
->yytops
.yystates
[0];
1738 yyj
= yypact
[yys
->yylrState
];
1739 if (! yyis_pact_ninf (yyj
))
1742 if (0 <= yyj
&& yyj
<= YYLAST
&& yycheck
[yyj
] == YYTERROR
1743 && yyisShiftAction (yytable
[yyj
]))
1745 YYDPRINTF ((stderr
, "Shifting error token, "));
1746 yyglrShift (yystack
, 0, yytable
[yyj
],
1747 yys
->yyposn
, *yylvalp
, yyllocp
]b4_user_args
[);
1751 YYDSYMPRINTF ("Error: popping",
1752 yystos
[yys
->yylrState
],
1753 &yys
->yysemantics
.yysval
, &yys
->yyloc
);
1754 yydestruct (yystos
[yys
->yylrState
],
1755 &yys
->yysemantics
.yysval
]b4_location_if([, &yys
->yyloc
])[);
1756 yystack
->yytops
.yystates
[0] = yys
->yypred
;
1757 yystack
->yynextFree
-= 1;
1758 yystack
->yyspaceLeft
+= 1;
1760 if (yystack
->yytops
.yystates
[0] == NULL
)
1761 yyFail (yystack
][]b4_lpure_args
[, NULL
);
1764 #define YYCHK1(YYE) \
1770 yystack.yyerrflag = 1; \
1773 yystack.yyerrflag = 0; \
1776 goto yyuser_error; \
1785 ]b4_c_ansi_function_def([yyparse
], [int], b4_parse_param
)[
1795 #define yychar (yystack.yyrawchar)
1798 YYSTYPE
* const yylvalp
= &yylval
;
1799 YYLTYPE
* const yyllocp
= &yylloc
;
1801 yyinitGLRStack (&yystack
, YYINITDEPTH
);
1802 yystack
.yytokenp
= &yytoken
;
1804 YYDPRINTF ((stderr
, "Starting parse\n"));
1806 if (setjmp (yystack
.yyexception_buffer
) != 0)
1809 yyglrShift (&yystack
, 0, 0, 0, yyval_default
, &yyloc_default
]b4_user_args
[);
1815 /* For efficiency, we have two loops, the first of which is
1816 specialized to deterministic operation (single stack, no
1817 potential ambiguity). */
1823 const short* yyconflicts
;
1825 yyStateNum yystate
= yystack
.yytops
.yystates
[0]->yylrState
;
1826 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1827 if (yystate
== YYFINAL
)
1829 if (yyisDefaultedState (yystate
))
1831 yyrule
= yydefaultAction (yystate
);
1834 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1837 YYCHK1 (yyglrReduce (&yystack
, 0, yyrule
, yytrue
]b4_lpure_args
[));
1841 if (yytoken
== YYEMPTY
)
1843 YYDPRINTF ((stderr
, "Reading a token: "));
1845 yytoken
= YYTRANSLATE (yychar
);
1846 YYDSYMPRINTF ("Next token is", yytoken
, yylvalp
, yyllocp
);
1848 yygetLRActions (yystate
, yytoken
, &yyaction
, &yyconflicts
);
1849 if (*yyconflicts
!= 0)
1851 if (yyisShiftAction (yyaction
))
1853 YYDPRINTF ((stderr
, "Shifting token %s, ",
1854 yytokenName (yytoken
)));
1855 if (yytoken
!= YYEOF
)
1858 yyglrShift (&yystack
, 0, yyaction
, yyposn
,
1859 yylval
, yyllocp
]b4_user_args
[);
1860 if (0 < yystack
.yyerrState
)
1861 yystack
.yyerrState
-= 1;
1863 else if (yyisErrorAction (yyaction
))
1865 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1869 YYCHK1 (yyglrReduce (&yystack
, 0, -yyaction
, yytrue
]b4_lpure_args
[));
1876 int yyn
= yystack
.yytops
.yysize
;
1877 for (yys
= 0; yys
< yyn
; yys
+= 1)
1878 YYCHK1 (yyprocessOneStack (&yystack
, yys
, yyposn
,
1879 yylvalp
, yyllocp
]b4_user_args
[));
1882 yyremoveDeletes (&yystack
);
1883 if (yystack
.yytops
.yysize
== 0)
1885 yyundeleteLastStack (&yystack
);
1886 if (yystack
.yytops
.yysize
== 0)
1887 yyFail (&yystack
][]b4_lpure_args
[, "syntax error");
1888 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1889 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1890 yyreportSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1893 else if (yystack
.yytops
.yysize
== 1)
1895 YYCHK1 (yyresolveStack (&yystack
]b4_user_args
[));
1896 YYDPRINTF ((stderr
, "Returning to deterministic operation.\n"));
1897 yycompressStack (&yystack
);
1903 yyrecoverSyntaxError (&yystack
, yylvalp
, yyllocp
]b4_user_args
[);
1904 yyposn
= yystack
.yytops
.yystates
[0]->yyposn
;
1909 yyfreeGLRStack (&yystack
);
1910 return yystack
.yyerrflag
;
1913 /* DEBUGGING ONLY */
1914 static void yypstack (yyGLRStack
* yystack
, int yyk
) ATTRIBUTE_UNUSED
;
1915 static void yypdumpstack (yyGLRStack
* yystack
) ATTRIBUTE_UNUSED
;
1918 yy_yypstack (yyGLRState
* yys
)
1922 yy_yypstack (yys
->yypred
);
1923 fprintf (stderr
, " -> ");
1925 fprintf (stderr
, "%d@@%lu", yys
->yylrState
, (unsigned long) yys
->yyposn
);
1929 yypstates (yyGLRState
* yyst
)
1932 fprintf (stderr
, "<null>");
1935 fprintf (stderr
, "\n");
1939 yypstack (yyGLRStack
* yystack
, int yyk
)
1941 yypstates (yystack
->yytops
.yystates
[yyk
]);
1944 #define YYINDEX(YYX) \
1945 ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
1949 yypdumpstack (yyGLRStack
* yystack
)
1951 yyGLRStackItem
* yyp
;
1953 for (yyp
= yystack
->yyitems
; yyp
< yystack
->yynextFree
; yyp
+= 1)
1955 fprintf (stderr
, "%3lu. ", (unsigned long) (yyp
- yystack
->yyitems
));
1956 if (*(yybool
*) yyp
)
1958 fprintf (stderr
, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
1959 yyp
->yystate
.yyresolved
, yyp
->yystate
.yylrState
,
1960 (unsigned long) yyp
->yystate
.yyposn
,
1961 (long) YYINDEX (yyp
->yystate
.yypred
));
1962 if (! yyp
->yystate
.yyresolved
)
1963 fprintf (stderr
, ", firstVal: %ld",
1964 (long) YYINDEX (yyp
->yystate
.yysemantics
.yyfirstVal
));
1968 fprintf (stderr
, "Option. rule: %d, state: %ld, next: %ld",
1969 yyp
->yyoption
.yyrule
,
1970 (long) YYINDEX (yyp
->yyoption
.yystate
),
1971 (long) YYINDEX (yyp
->yyoption
.yynext
));
1973 fprintf (stderr
, "\n");
1975 fprintf (stderr
, "Tops:");
1976 for (yyi
= 0; yyi
< yystack
->yytops
.yysize
; yyi
+= 1)
1977 fprintf (stderr
, "%lu: %ld; ", (unsigned long) yyi
,
1978 (long) YYINDEX (yystack
->yytops
.yystates
[yyi
]));
1979 fprintf (stderr
, "\n");
1984 m4_if(b4_defines_flag
, 0, [],
1985 [@output @output_header_name@
1986 b4_copyright([Skeleton parser
for GLR parsing with Bison
], [2002, 2003])
1988 b4_token_defines(b4_tokens
)
1990 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
1991 m4_ifdef([b4_stype
],
1992 [b4_syncline([b4_stype_line
], [b4_filename
])
1993 typedef union m4_bregexp(b4_stype
, [^{], [YYSTYPE
])b4_stype YYSTYPE
;
1994 /* Line __line__ of glr.c. */
1995 b4_syncline([@oline@
], [@ofile@
])],
1996 [typedef int YYSTYPE
;])
1997 # define YYSTYPE_IS_DECLARED 1
1998 # define YYSTYPE_IS_TRIVIAL 1
2002 [extern YYSTYPE b4_prefix
[]lval
;])
2005 [#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)
2006 typedef struct YYLTYPE
2013 # define YYLTYPE_IS_DECLARED 1
2014 # define YYLTYPE_IS_TRIVIAL 1
2018 [extern YYLTYPE b4_prefix
[]lloc
;])