]> git.saurik.com Git - bison.git/blame - data/lalr1-fusion.cc
Fix iteration type.
[bison.git] / data / lalr1-fusion.cc
CommitLineData
0e0ed236
AD
1# C++ skeleton for Bison
2
3# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4# Free Software Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19m4_include(b4_pkgdatadir/[c++.m4])
20
417b8004
AD
21# b4_table_define(TABLE-NAME, CONTENT)
22# ------------------------------------
23# Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
24m4_define([b4_table_define],
25[const b4_int_type_for([$2])
26 b4_parser_class_name::yy$1_[[]] =
27 {
28 $2
29 }dnl
30])
31
0e0ed236
AD
32# How the semantic value is extracted when using variants.
33b4_variant_if([
34 # b4_symbol_value(VAL, [TYPE])
35 # ----------------------------
36 m4_define([b4_symbol_value],
37 [m4_ifval([$2],
38 [$1.as<$2>()],
39 [$1])])
40]) # b4_variant_if
41
42
43# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
44# --------------------------------------
45# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
46# symbols on RHS.
47m4_define([b4_rhs_value],
48 [b4_symbol_value([yystack_@{($1) - ($2)@}.value], [$3])])
49
50# b4_rhs_location(RULE-LENGTH, NUM)
51# ---------------------------------
52# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
53# on RHS.
54m4_define([b4_rhs_location],
55[(yystack_@{($1) - ($2)@}.location)])
56
57
58# b4_symbol_actions(FILENAME, LINENO,
59# SYMBOL-TAG, SYMBOL-NUM,
60# SYMBOL-ACTION, SYMBOL-TYPENAME)
61# -------------------------------------------------
62# Same as in C, but using references instead of pointers.
63m4_define([b4_symbol_actions],
64[m4_pushdef([b4_dollar_dollar],
65 [b4_symbol_value([yyvalue], [$6])])dnl
66m4_pushdef([b4_at_dollar], [yylocation])dnl
67 case $4: // $3
68b4_syncline([$2], [$1])
69 $5;
70b4_syncline([@oline@], [@ofile@])
71 break;
72m4_popdef([b4_at_dollar])dnl
73m4_popdef([b4_dollar_dollar])dnl
74])
75
76
77# b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
78# ----------------------------------------------------------
79# Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
80m4_define([b4_symbol_action_],
81[m4_ifval($3,
82[ case $2: // $1
83 b4_dollar_dollar($@);
84 break;
85])])
86
87
88# b4_symbol_variant(YYTYPE, YYVAL, ACTION)
89# ----------------------------------------
90# Run some ACTION ("build", or "destroy") on YYVAL of symbol type
91# YYTYPE.
92m4_define([b4_symbol_variant],
93[m4_pushdef([b4_dollar_dollar],
94 [$2.$3<$][3>()])dnl
95 switch ($1)
96 {
97m4_map([b4_symbol_action_], m4_defn([b4_type_names]))
98 default:
99 break;
100 }
101m4_popdef([b4_dollar_dollar])dnl
102])
103
104
105# _b4_char_sizeof_counter
106# -----------------------
107# A counter used by _b4_char_sizeof_dummy to create fresh symbols.
108m4_define([_b4_char_sizeof_counter],
109[0])
110
111# _b4_char_sizeof_dummy
112# ---------------------
113# At each call return a new C++ identifier.
114m4_define([_b4_char_sizeof_dummy],
115[m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl
116dummy[]_b4_char_sizeof_counter])
117
118
119# b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
120# -------------------------------------------------------
121# To be mapped on the list of type names to produce:
122#
123# char dummy1[sizeof(type_name_1)];
124# char dummy2[sizeof(type_name_2)];
125#
126# for defined type names.
127# $3 is doubly-quoted, do not quote it again.
128m4_define([b4_char_sizeof],
129[m4_ifval($3,
130[
131 char _b4_char_sizeof_dummy@{sizeof($3)@}; // $1])dnl
132])
133
134
135m4_define([b4_parser_class_name],
136 [b4_percent_define_get([[parser_class_name]])])
137
138# The header is mandatory.
139b4_defines_if([],
140 [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
141
142# Backward compatibility.
143m4_define([b4_location_constructors])
144m4_include(b4_pkgdatadir/[location.cc])
145
146# We do want M4 expansion after # for CPP macros.
147m4_changecom()
148m4_divert_push(0)dnl
149b4_defines_if(
150[@output(b4_spec_defines_file@)
151b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
152 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
153dnl FIXME: This is wrong, we want computed header guards.
154[
155/* C++ LALR(1) parser skeleton written by Akim Demaille. */
156
157#ifndef PARSER_HEADER_H
158# define PARSER_HEADER_H
159
160]b4_percent_code_get([[requires]])[
161
162#include <string>
163#include <iostream>
164#include "stack.hh"
165
166]b4_namespace_open[
167 class position;
168 class location;
83243c24
AD
169]b4_variant_if(
170[[
0e0ed236
AD
171 /// A char[S] buffer to store and retrieve objects.
172 ///
173 /// Sort of a variant, but does not keep track of the nature
174 /// of the stored data, since that knowledge is available
175 /// via the current state.
176 template <size_t S>
177 struct variant
178 {
179 /// Instantiate a \a T in here.
180 template <typename T>
8b9c89fb 181 inline T&
0e0ed236
AD
182 build()
183 {
8b9c89fb 184 return *new (buffer) T;
0e0ed236
AD
185 }
186
187 /// Destroy the stored \a T.
188 template <typename T>
189 inline void
190 destroy()
191 {
192 reinterpret_cast<T&>(buffer).~T();
193 }
194
195 /// Accessor to a built \a T.
196 template <typename T>
197 inline T&
198 as()
199 {
200 return reinterpret_cast<T&>(buffer);
201 }
202
203 /// Const accessor to a built \a T (for %printer).
204 template <typename T>
205 inline const T&
206 as() const
207 {
208 return reinterpret_cast<const T&>(buffer);
209 }
210
211 /// A buffer large enough to store any of the semantic values.
212 char buffer[S];
213 };
83243c24 214]])[
0e0ed236
AD
215]b4_namespace_close[
216
217#include "location.hh"
218
219/* Enabling traces. */
220#ifndef YYDEBUG
221# define YYDEBUG ]b4_debug_flag[
222#endif
223
224/* Enabling verbose error messages. */
225#ifdef YYERROR_VERBOSE
226# undef YYERROR_VERBOSE
227# define YYERROR_VERBOSE 1
228#else
229# define YYERROR_VERBOSE ]b4_error_verbose_flag[
230#endif
231
232/* Enabling the token table. */
233#ifndef YYTOKEN_TABLE
234# define YYTOKEN_TABLE ]b4_token_table[
235#endif
236
237/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
238 If N is 0, then set CURRENT to the empty location which ends
239 the previous symbol: RHS[0] (always defined). */
240
241#ifndef YYLLOC_DEFAULT
242# define YYLLOC_DEFAULT(Current, Rhs, N) \
243do { \
244 if (N) \
245 { \
246 (Current).begin = (Rhs)[1].location.begin; \
247 (Current).end = (Rhs)[N].location.end; \
248 } \
249 else \
250 { \
251 (Current).begin = (Current).end = (Rhs)[0].location.end; \
252 } \
253} while (false)
254#endif
255
256]b4_namespace_open[
257
258 /// A Bison parser.
259 class ]b4_parser_class_name[
260 {
261 public:
262#ifndef YYSTYPE
263]b4_variant_if(
264[ /// An auxiliary type to compute the largest semantic type.
265 union union_type
266 {]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[
267 };
268
269 /// Symbol semantic values.
270 typedef variant<sizeof(union_type)> semantic_type;],
271[ /// Symbol semantic values.
272m4_ifdef([b4_stype],
273[ union semantic_type
274 {b4_user_stype
275 };],
276[m4_if(b4_tag_seen_flag, 0,
277[[ typedef int semantic_type;]],
278[[ typedef YYSTYPE semantic_type;]])])])[
279#else
280 typedef YYSTYPE semantic_type;
281#endif
282 /// Symbol locations.
283 typedef ]b4_percent_define_get([[location_type]])[ location_type;
284 /// Tokens.
285 struct token
286 {
287 ]b4_token_enums(b4_tokens)[
288 };
289 /// Token type.
290 typedef token::yytokentype token_type;
291
292 /// Build a parser object.
293 ]b4_parser_class_name[ (]b4_parse_param_decl[);
294 virtual ~]b4_parser_class_name[ ();
295
296 /// Parse.
297 /// \returns 0 iff parsing succeeded.
298 virtual int parse ();
299
300#if YYDEBUG
301 /// The current debugging stream.
302 std::ostream& debug_stream () const;
303 /// Set the current debugging stream.
304 void set_debug_stream (std::ostream &);
305
306 /// Type for debugging levels.
307 typedef int debug_level_type;
308 /// The current debugging level.
309 debug_level_type debug_level () const;
310 /// Set the current debugging level.
311 void set_debug_level (debug_level_type l);
312#endif
313
314 private:
315 /// Report a syntax error.
316 /// \param loc where the syntax error is found.
317 /// \param msg a description of the syntax error.
318 virtual void error (const location_type& loc, const std::string& msg);
319
320 /// Generate an error message.
321 /// \param state the state where the error occurred.
322 /// \param tok the lookahead token.
d7f4d823 323 virtual std::string yysyntax_error_ (int yystate, int tok);
0e0ed236
AD
324
325#if YYDEBUG
326 /// \brief Report a symbol value on the debug stream.
327 /// \param yytype The token type.
328 /// \param yyvalue Its semantic value.
329 /// \param yylocation Its location.
330 virtual void yy_symbol_value_print_ (int yytype,
331 const semantic_type& yyvalue,
332 const location_type& yylocation);
333 /// \brief Report a symbol on the debug stream.
334 /// \param yytype The token type.
335 /// \param yyvalue Its semantic value.
336 /// \param yylocation Its location.
337 virtual void yy_symbol_print_ (int yytype,
338 const semantic_type& yyvalue,
339 const location_type& yylocation);
340#endif
341
342 /// State numbers.
343 typedef int state_type;
344
345 /// Internal symbol numbers.
346 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
347 /* Tables. */
348 /// For a state, the index in \a yytable_ of its portion.
349 static const ]b4_int_type_for([b4_pact])[ yypact_[];
350 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
351
352 /// For a state, default rule to reduce.
353 /// Unless\a yytable_ specifies something else to do.
354 /// Zero means the default is an error.
355 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
356
357 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
358 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
359
360 /// What to do in a state.
361 /// \a yytable_[yypact_[s]]: what to do in state \a s.
362 /// - if positive, shift that token.
363 /// - if negative, reduce the rule which number is the opposite.
364 /// - if zero, do what YYDEFACT says.
365 static const ]b4_int_type_for([b4_table])[ yytable_[];
366 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
367
368 static const ]b4_int_type_for([b4_check])[ yycheck_[];
369
370 /// For a state, its accessing symbol.
371 static const ]b4_int_type_for([b4_stos])[ yystos_[];
372
373 /// For a rule, its LHS.
374 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
375 /// For a rule, its RHS length.
376 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
377
378#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
379 /// For a symbol, its name in clear.
380 static const char* const yytname_[];
381#endif
382
383#if YYERROR_VERBOSE
384 /// Convert the symbol name \a n to a form suitable for a diagnostic.
385 virtual std::string yytnamerr_ (const char *n);
386#endif
387
388#if YYDEBUG
389 /// A type to store symbol numbers and -1.
390 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
391 /// A `-1'-separated list of the rules' RHS.
392 static const rhs_number_type yyrhs_[];
393 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
394 static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
395 /// For each rule, its source line number.
396 static const ]b4_int_type_for([b4_rline])[ yyrline_[];
397 /// For each scanner token number, its symbol number.
398 static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
399 /// Report on the debug stream that the rule \a r is going to be reduced.
400 virtual void yy_reduce_print_ (int r);
401 /// Print the state stack on the debug stream.
402 virtual void yystack_print_ ();
403
404 /* Debugging. */
405 int yydebug_;
406 std::ostream* yycdebug_;
407#endif
408
409 /// Convert a scanner token number \a t to a symbol number.
410 token_number_type yytranslate_ (int t);
411
412 /// \brief Reclaim the memory associated to a symbol.
413 /// \param yymsg Why this token is reclaimed.
414 /// \param yytype The symbol type.
415 /// \param yyvalue Its semantic value.
416 /// \param yylocation Its location.
417 inline void yydestruct_ (const char* yymsg,
418 int yytype,
419 semantic_type& yyvalue,
420 location_type& yylocation);
421
422 /// Element of the stack: a state and its attributes.
423 struct data_type
424 {
425 /// Default constructor.
426 data_type ();
427
428 /// Constructor.
429 data_type (state_type s, const semantic_type& v, const location_type& l);
430
431 /// The state.
432 state_type state;
433
434 /// The semantic value.
435 semantic_type value;
436
437 /// The location.
438 location_type location;
439 };
440
441 /// Stack type.
442 typedef stack<data_type> stack_type;
443
444 /// The stack.
445 stack_type yystack_;
446
447 /// Push a new state on the stack.
448 /// \warning the contents of \a v is stolen.
449 inline void yypush_ (state_type s,
450 semantic_type& v, const location_type& l);
451
452 /// Pop \a n symbols the three stacks.
453 inline void yypop_ (unsigned int n = 1);
454
455 /* Constants. */
456 static const int yyeof_;
457 /* LAST_ -- Last index in TABLE_. */
458 static const int yylast_;
459 static const int yynnts_;
460 static const int yyempty_;
461 static const int yyfinal_;
462 static const int yyterror_;
463 static const int yyerrcode_;
464 static const int yyntokens_;
465 static const unsigned int yyuser_token_number_max_;
466 static const token_number_type yyundef_token_;
467]b4_parse_param_vars[
468 };
469]b4_namespace_close[
470
471]b4_percent_define_flag_if([[global_tokens_and_yystype]],
472[b4_token_defines(b4_tokens)
473
474#ifndef YYSTYPE
475 /* Redirection for backward compatibility. */
476# define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
477#endif
478])
479b4_percent_code_get([[provides]])[]dnl
480
481[#endif /* ! defined PARSER_HEADER_H */]
482])dnl
483@output(b4_parser_file_name@)
484b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
485 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
486b4_percent_code_get([[top]])[]dnl
487m4_if(b4_prefix, [yy], [],
488[
489// Take the name prefix into account.
490#define yylex b4_prefix[]lex])[
491
492/* First part of user declarations. */
493]b4_user_pre_prologue
494
495b4_defines_if([[
496#include "@basename(]b4_spec_defines_file[@)"]])[
497
498/* User implementation prologue. */
499]b4_user_post_prologue
500b4_percent_code_get[]dnl
501
502[#ifndef YY_
503# if YYENABLE_NLS
504# if ENABLE_NLS
505# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
506# define YY_(msgid) dgettext ("bison-runtime", msgid)
507# endif
508# endif
509# ifndef YY_
510# define YY_(msgid) msgid
511# endif
512#endif
513
514/* Suppress unused-variable warnings by "using" E. */
515#define YYUSE(e) ((void) (e))
516
517/* Enable debugging if requested. */
518#if YYDEBUG
519
520/* A pseudo ostream that takes yydebug_ into account. */
521# define YYCDEBUG if (yydebug_) (*yycdebug_)
522
523# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
524do { \
525 if (yydebug_) \
526 { \
527 *yycdebug_ << Title << ' '; \
528 yy_symbol_print_ ((Type), (Value), (Location)); \
529 *yycdebug_ << std::endl; \
530 } \
531} while (false)
532
533# define YY_REDUCE_PRINT(Rule) \
534do { \
535 if (yydebug_) \
536 yy_reduce_print_ (Rule); \
537} while (false)
538
539# define YY_STACK_PRINT() \
540do { \
541 if (yydebug_) \
542 yystack_print_ (); \
543} while (false)
544
545#else /* !YYDEBUG */
546
547# define YYCDEBUG if (false) std::cerr
548# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
549# define YY_REDUCE_PRINT(Rule)
550# define YY_STACK_PRINT()
551
552#endif /* !YYDEBUG */
553
554#define yyerrok (yyerrstatus_ = 0)
555#define yyclearin (yychar = yyempty_)
556
557#define YYACCEPT goto yyacceptlab
558#define YYABORT goto yyabortlab
559#define YYERROR goto yyerrorlab
560#define YYRECOVERING() (!!yyerrstatus_)
561
562]b4_namespace_open[
563#if YYERROR_VERBOSE
564
565 /* Return YYSTR after stripping away unnecessary quotes and
566 backslashes, so that it's suitable for yyerror. The heuristic is
567 that double-quoting is unnecessary unless the string contains an
568 apostrophe, a comma, or backslash (other than backslash-backslash).
569 YYSTR is taken from yytname. */
570 std::string
571 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
572 {
573 if (*yystr == '"')
574 {
575 std::string yyr = "";
576 char const *yyp = yystr;
577
578 for (;;)
579 switch (*++yyp)
580 {
581 case '\'':
582 case ',':
583 goto do_not_strip_quotes;
584
585 case '\\':
586 if (*++yyp != '\\')
587 goto do_not_strip_quotes;
588 /* Fall through. */
589 default:
590 yyr += *yyp;
591 break;
592
593 case '"':
594 return yyr;
595 }
596 do_not_strip_quotes: ;
597 }
598
599 return yystr;
600 }
601
602#endif
603
604 /// Build a parser object.
605 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
606 :])[
607#if YYDEBUG
608 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
609 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
610#endif]b4_parse_param_cons[
611 {
612 }
613
614 ]b4_parser_class_name::~b4_parser_class_name[ ()
615 {
616 }
617
618#if YYDEBUG
619 /*--------------------------------.
620 | Print this symbol on YYOUTPUT. |
621 `--------------------------------*/
622
623 inline void
624 ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
625 const semantic_type& yyvalue, const location_type& yylocation)
626 {
627 YYUSE (yylocation);
628 YYUSE (yyvalue);
629 switch (yytype)
630 {
631 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
632[ default:
633 break;
634 }
635 }
636
637
638 void
639 ]b4_parser_class_name[::yy_symbol_print_ (int yytype,
640 const semantic_type& yyvalue, const location_type& yylocation)
641 {
642 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
643 << ' ' << yytname_[yytype] << " ("
644 << yylocation << ": ";
645 yy_symbol_value_print_ (yytype, yyvalue, yylocation);
646 *yycdebug_ << ')';
647 }
648#endif
649
650 void
651 ]b4_parser_class_name[::yydestruct_ (const char* yymsg,
652 int yytype, semantic_type& yyvalue, location_type& yylocation)
653 {
654 YYUSE (yymsg);
655 YYUSE (yyvalue);
656 YYUSE (yylocation);
657
658 YY_SYMBOL_PRINT (yymsg, yytype, yyvalue, yylocation);
659
660 switch (yytype)
661 {
662 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
663 default:
664 break;
665 }
666 }
667
668 ]b4_parser_class_name[::data_type::data_type ()
669 : state()
670 , value()
671 , location()
672 {
673 }
674
675 ]b4_parser_class_name[::data_type::data_type (state_type s,
676 const semantic_type& v, const location_type& l)
677 : state(s)
678 , value(v)
679 , location(l)
680 {
681 }
682
683 void
684 ]b4_parser_class_name[::yypush_ (state_type s,
685 semantic_type& v, const location_type& l)
686 {
687 yystack_.push (data_type (s, v, l));
688 }
689
690 void
691 ]b4_parser_class_name[::yypop_ (unsigned int n)
692 {
693 yystack_.pop (n);
694 }
695
696#if YYDEBUG
697 std::ostream&
698 ]b4_parser_class_name[::debug_stream () const
699 {
700 return *yycdebug_;
701 }
702
703 void
704 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
705 {
706 yycdebug_ = &o;
707 }
708
709
710 ]b4_parser_class_name[::debug_level_type
711 ]b4_parser_class_name[::debug_level () const
712 {
713 return yydebug_;
714 }
715
716 void
717 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
718 {
719 yydebug_ = l;
720 }
721#endif
722
723 int
724 ]b4_parser_class_name[::parse ()
725 {
726 /// Lookahead and lookahead in internal form.
727 int yychar = yyempty_;
728 int yytoken = 0;
729
730 /* State. */
731 int yyn;
732 int yylen = 0;
733 int yystate = 0;
734
735 /* Error handling. */
736 int yynerrs_ = 0;
737 int yyerrstatus_ = 0;
738
739 /// Semantic value of the lookahead.
740 semantic_type yylval;
741 /// Location of the lookahead.
742 location_type yylloc;
743 /// The locations where the error started and ended.
744 data_type yyerror_range[2];
745
746 /// $$.
747 semantic_type yyval;
748 /// @@$.
749 location_type yyloc;
750
751 int yyresult;
752
753 YYCDEBUG << "Starting parse" << std::endl;
754
755]m4_ifdef([b4_initial_action], [
756m4_pushdef([b4_at_dollar], [yylloc])dnl
757m4_pushdef([b4_dollar_dollar], [yylval])dnl
758 /* User initialization code. */
759 b4_user_initial_action
760m4_popdef([b4_dollar_dollar])dnl
761m4_popdef([b4_at_dollar])])dnl
762
763 [ /* Initialize the stack. The initial state will be set in
764 yynewstate, since the latter expects the semantical and the
765 location values to have been already stored, initialize these
766 stacks with a primary value. */
767 yystack_ = stack_type (0);
768 yypush_ (yystate, yylval, yylloc);
769
770 // A new state was pushed on the stack.
771 // Invariant: yystate == yystack_[0].state, i.e.,
772 // yystate was just pushed onto the state stack.
773 yynewstate:
774 YYCDEBUG << "Entering state " << yystate << std::endl;
775
776 /* Accept? */
777 if (yystate == yyfinal_)
778 goto yyacceptlab;
779
780 goto yybackup;
781
782 /* Backup. */
783 yybackup:
784
785 /* Try to take a decision without lookahead. */
786 yyn = yypact_[yystate];
787 if (yyn == yypact_ninf_)
788 goto yydefault;
789
790 /* Read a lookahead token. */
791 if (yychar == yyempty_)
792 {
793 YYCDEBUG << "Reading a token: ";
794 yychar = ]b4_c_function_call([yylex], [int],
795 [[YYSTYPE*], [&yylval]][]dnl
796b4_locations_if([, [[location*], [&yylloc]]])dnl
797m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
798 }
799
800
801 /* Convert token to internal form. */
802 if (yychar <= yyeof_)
803 {
804 yychar = yytoken = yyeof_;
805 YYCDEBUG << "Now at end of input." << std::endl;
806 }
807 else
808 {
809 yytoken = yytranslate_ (yychar);
810 YY_SYMBOL_PRINT ("Next token is", yytoken, yylval, yylloc);
811 }
812
813 /* If the proper action on seeing token YYTOKEN is to reduce or to
814 detect an error, take that action. */
815 yyn += yytoken;
816 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
817 goto yydefault;
818
819 /* Reduce or error. */
820 yyn = yytable_[yyn];
821 if (yyn <= 0)
822 {
823 if (yyn == 0 || yyn == yytable_ninf_)
824 goto yyerrlab;
825 yyn = -yyn;
826 goto yyreduce;
827 }
828
829 /* Shift the lookahead token. */
830 YY_SYMBOL_PRINT ("Shifting", yytoken, yylval, yylloc);
831
832 /* Discard the token being shifted. */
833 yychar = yyempty_;
834
835 /* Count tokens shifted since error; after three, turn off error
836 status. */
837 if (yyerrstatus_)
838 --yyerrstatus_;
839
840 yystate = yyn;
841 yypush_ (yystate, yylval, yylloc);
842 goto yynewstate;
843
844 /*-----------------------------------------------------------.
845 | yydefault -- do the default action for the current state. |
846 `-----------------------------------------------------------*/
847 yydefault:
848 yyn = yydefact_[yystate];
849 if (yyn == 0)
850 goto yyerrlab;
851 goto yyreduce;
852
853 /*-----------------------------.
854 | yyreduce -- Do a reduction. |
855 `-----------------------------*/
856 yyreduce:
857 yylen = yyr2_[yyn];]b4_variant_if([
858 /* Variants are always initialized to an empty instance of the
859 correct type. The default $$=$1 rule is NOT applied when using
860 variants */
861 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yyval], [build])[],[
862 /* If YYLEN is nonzero, implement the default value of the action:
863 `$$ = $1'. Otherwise, use the top of the stack.
864
865 Otherwise, the following line sets YYVAL to garbage.
866 This behavior is undocumented and Bison
867 users should not rely upon it. */
868 if (yylen)
869 yyval = yystack_@{yylen - 1@}.value;
870 else
871 yyval = yystack_@{0@}.value;])[
872
f8a95c9c 873 // Compute the default @@$.
0e0ed236
AD
874 {
875 slice<data_type, stack_type> slice (yystack_, yylen);
876 YYLLOC_DEFAULT (yyloc, slice, yylen);
877 }
f8a95c9c
AD
878
879 // Perform the reduction.
0e0ed236
AD
880 YY_REDUCE_PRINT (yyn);
881 switch (yyn)
882 {
883 ]b4_user_actions[
884 default:
885 break;
886 }
887 YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], yyval, yyloc);
888
f8a95c9c
AD
889]b4_variant_if([
890 // Destroy the lhs symbols.
f0633174 891 for (int i = 0; i < yylen; ++i)
f8a95c9c
AD
892 {
893 b4_symbol_variant([[yystos_[yystack_@{i@}.state]]],
894 [[yystack_@{i@}.value]],
895 [[destroy]])
896 }])dnl
897[
0e0ed236
AD
898 yypop_ (yylen);
899 yylen = 0;
900 YY_STACK_PRINT ();
901
902 /* Shift the result of the reduction. */
903 yyn = yyr1_[yyn];
904 yystate = yypgoto_[yyn - yyntokens_] + yystack_[0].state;
905 if (0 <= yystate && yystate <= yylast_
906 && yycheck_[yystate] == yystack_[0].state)
907 yystate = yytable_[yystate];
908 else
909 yystate = yydefgoto_[yyn - yyntokens_];
910 yypush_ (yystate, yyval, yyloc);
911 goto yynewstate;
912
913 /*------------------------------------.
914 | yyerrlab -- here on detecting error |
915 `------------------------------------*/
916 yyerrlab:
917 /* If not already recovering from an error, report this error. */
918 if (!yyerrstatus_)
919 {
920 ++yynerrs_;
d7f4d823 921 error (yylloc, yysyntax_error_ (yystate, yytoken));
0e0ed236
AD
922 }
923
924 yyerror_range[0].location = yylloc;
925 if (yyerrstatus_ == 3)
926 {
927 /* If just tried and failed to reuse lookahead token after an
928 error, discard it. */
929
930 if (yychar <= yyeof_)
931 {
932 /* Return failure if at end of input. */
933 if (yychar == yyeof_)
934 YYABORT;
935 }
936 else
937 {
938 yydestruct_ ("Error: discarding", yytoken, yylval, yylloc);
939 yychar = yyempty_;
940 }
941 }
942
943 /* Else will try to reuse lookahead token after shifting the error
944 token. */
945 goto yyerrlab1;
946
947
948 /*---------------------------------------------------.
949 | yyerrorlab -- error raised explicitly by YYERROR. |
950 `---------------------------------------------------*/
951 yyerrorlab:
952
953 /* Pacify compilers like GCC when the user code never invokes
954 YYERROR and the label yyerrorlab therefore never appears in user
955 code. */
956 if (false)
957 goto yyerrorlab;
958
959 yyerror_range[0].location = yystack_[yylen - 1].location;
960 /* Do not reclaim the symbols of the rule which action triggered
961 this YYERROR. */
962 yypop_ (yylen);
963 yylen = 0;
964 yystate = yystack_[0].state;
965 goto yyerrlab1;
966
967 /*-------------------------------------------------------------.
968 | yyerrlab1 -- common code for both syntax error and YYERROR. |
969 `-------------------------------------------------------------*/
970 yyerrlab1:
971 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
972
973 for (;;)
974 {
975 yyn = yypact_[yystate];
976 if (yyn != yypact_ninf_)
977 {
978 yyn += yyterror_;
979 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
980 {
981 yyn = yytable_[yyn];
982 if (0 < yyn)
983 break;
984 }
985 }
986
987 // Pop the current state because it cannot handle the error token.
988 if (yystack_.size () == 1)
989 YYABORT;
990
991 yyerror_range[0].location = yystack_[0].location;
992 yydestruct_ ("Error: popping",
993 yystos_[yystate],
994 yystack_[0].value, yystack_[0].location);
995 yypop_ ();
996 yystate = yystack_[0].state;
997 YY_STACK_PRINT ();
998 }
999
1000 yyerror_range[1].location = yylloc;
1001 // Using YYLLOC is tempting, but would change the location of
1002 // the lookahead. YYLOC is available though.
1003 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
1004
1005 /* Shift the error token. */
1006 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
1007 yystack_[0].value, yystack_[0].location);
1008
1009 yystate = yyn;
1010 yypush_ (yystate, yylval, yyloc);
1011 goto yynewstate;
1012
1013 /* Accept. */
1014 yyacceptlab:
1015 yyresult = 0;
1016 goto yyreturn;
1017
1018 /* Abort. */
1019 yyabortlab:
1020 yyresult = 1;
1021 goto yyreturn;
1022
1023 yyreturn:
1024 if (yychar != yyempty_)
1025 yydestruct_ ("Cleanup: discarding lookahead", yytoken, yylval, yylloc);
1026
1027 /* Do not reclaim the symbols of the rule which action triggered
1028 this YYABORT or YYACCEPT. */
1029 yypop_ (yylen);
1030 while (yystack_.size () != 1)
1031 {
1032 yydestruct_ ("Cleanup: popping",
1033 yystos_[yystack_[0].state],
1034 yystack_[0].value, yystack_[0].location);
1035 yypop_ ();
1036 }
1037
1038 return yyresult;
1039 }
1040
1041 // Generate an error message.
1042 std::string
d7f4d823
AD
1043 ]b4_parser_class_name[::yysyntax_error_ (int yystate, int]dnl
1044b4_error_verbose_if([ tok])[)
0e0ed236
AD
1045 {
1046 std::string res;
1047 YYUSE (yystate);
1048#if YYERROR_VERBOSE
1049 int yyn = yypact_[yystate];
1050 if (yypact_ninf_ < yyn && yyn <= yylast_)
1051 {
1052 /* Start YYX at -YYN if negative to avoid negative indexes in
1053 YYCHECK. */
1054 int yyxbegin = yyn < 0 ? -yyn : 0;
1055
1056 /* Stay within bounds of both yycheck and yytname. */
1057 int yychecklim = yylast_ - yyn + 1;
1058 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1059 int count = 0;
1060 for (int x = yyxbegin; x < yyxend; ++x)
1061 if (yycheck_[x + yyn] == x && x != yyterror_)
1062 ++count;
1063
1064 // FIXME: This method of building the message is not compatible
1065 // with internationalization. It should work like yacc.c does it.
1066 // That is, first build a string that looks like this:
1067 // "syntax error, unexpected %s or %s or %s"
1068 // Then, invoke YY_ on this string.
1069 // Finally, use the string as a format to output
1070 // yytname_[tok], etc.
1071 // Until this gets fixed, this message appears in English only.
1072 res = "syntax error, unexpected ";
1073 res += yytnamerr_ (yytname_[tok]);
1074 if (count < 5)
1075 {
1076 count = 0;
1077 for (int x = yyxbegin; x < yyxend; ++x)
1078 if (yycheck_[x + yyn] == x && x != yyterror_)
1079 {
1080 res += (!count++) ? ", expecting " : " or ";
1081 res += yytnamerr_ (yytname_[x]);
1082 }
1083 }
1084 }
1085 else
1086#endif
1087 res = YY_("syntax error");
1088 return res;
1089 }
1090
1091
1092 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1093 STATE-NUM. */
1094 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
417b8004 1095 ]b4_table_define([pact], [b4_pact])[;
0e0ed236
AD
1096
1097 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1098 doesn't specify something else to do. Zero means the default is an
1099 error. */
417b8004 1100 ]b4_table_define([defact], [b4_defact])[;
0e0ed236
AD
1101
1102 /* YYPGOTO[NTERM-NUM]. */
417b8004 1103 ]b4_table_define([pgoto], [b4_pgoto])[;
0e0ed236
AD
1104
1105 /* YYDEFGOTO[NTERM-NUM]. */
417b8004 1106 ]b4_table_define([defgoto], [b4_defgoto])[;
0e0ed236
AD
1107
1108 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1109 positive, shift that token. If negative, reduce the rule which
1110 number is the opposite. If zero, do what YYDEFACT says. */
1111 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
417b8004 1112 ]b4_table_define([table], [b4_table])[;
0e0ed236
AD
1113
1114 /* YYCHECK. */
417b8004 1115 ]b4_table_define([check], [b4_check])[;
0e0ed236
AD
1116
1117 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1118 symbol of state STATE-NUM. */
417b8004 1119 ]b4_table_define([stos], [b4_stos])[;
0e0ed236
AD
1120
1121#if YYDEBUG
1122 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1123 to YYLEX-NUM. */
417b8004 1124 ]b4_table_define([token_number], [b4_toknum])[;
0e0ed236
AD
1125#endif
1126
1127 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
417b8004 1128 ]b4_table_define([r1], [b4_r1])[;
0e0ed236
AD
1129
1130 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
417b8004 1131 ]b4_table_define([r2], [b4_r2])[;
0e0ed236
AD
1132
1133#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1134 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1135 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1136 const char*
1137 const ]b4_parser_class_name[::yytname_[] =
1138 {
1a5246c6 1139 ]b4_tname[
0e0ed236
AD
1140 };
1141#endif
1142
1143#if YYDEBUG
1144 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1145 const ]b4_parser_class_name[::rhs_number_type
1146 ]b4_parser_class_name[::yyrhs_[] =
1147 {
1a5246c6 1148 ]b4_rhs[
0e0ed236
AD
1149 };
1150
1151 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1152 YYRHS. */
417b8004 1153 ]b4_table_define([prhs], [b4_prhs])[;
0e0ed236
AD
1154
1155 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
417b8004 1156 ]b4_table_define([rline], [b4_rline])[;
0e0ed236
AD
1157
1158 // Print the state stack on the debug stream.
1159 void
1160 ]b4_parser_class_name[::yystack_print_ ()
1161 {
1162 *yycdebug_ << "Stack now";
1163 for (stack_type::const_iterator
1164 i = yystack_.begin (),
1165 i_end = yystack_.end ();
1166 i != i_end; ++i)
1167 *yycdebug_ << ' ' << i->state;
1168 *yycdebug_ << std::endl;
1169 }
1170
1171 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1172 void
1173 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1174 {
1175 unsigned int yylno = yyrline_[yyrule];
1176 int yynrhs = yyr2_[yyrule];
1177 /* Print the symbols being reduced, and their result. */
1178 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1179 << " (line " << yylno << "):" << std::endl;
1180 /* The symbols being reduced. */
1181 for (int yyi = 0; yyi < yynrhs; yyi++)
1182 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1183 yyrhs_[yyprhs_[yyrule] + yyi],
1184 ]b4_rhs_value(yynrhs, yyi + 1)[,
1185 ]b4_rhs_location(yynrhs, yyi + 1)[);
1186 }
1187#endif // YYDEBUG
1188
1189 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1190 ]b4_parser_class_name[::token_number_type
1191 ]b4_parser_class_name[::yytranslate_ (int t)
1192 {
1193 static
1194 const token_number_type
1195 translate_table[] =
1196 {
1a5246c6 1197 ]b4_translate[
0e0ed236
AD
1198 };
1199 if ((unsigned int) t <= yyuser_token_number_max_)
1200 return translate_table[t];
1201 else
1202 return yyundef_token_;
1203 }
1204
1205 const int ]b4_parser_class_name[::yyeof_ = 0;
1206 const int ]b4_parser_class_name[::yylast_ = ]b4_last[;
1207 const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1208 const int ]b4_parser_class_name[::yyempty_ = -2;
1209 const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1210 const int ]b4_parser_class_name[::yyterror_ = 1;
1211 const int ]b4_parser_class_name[::yyerrcode_ = 256;
1212 const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1213
1214 const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1215 const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
1216
1217]b4_namespace_close[
1218
1219]b4_epilogue
1220dnl
1221@output(b4_dir_prefix[]stack.hh@)
1222b4_copyright([Stack handling for Bison parsers in C++],
1223 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
1224
1225#ifndef BISON_STACK_HH
1226# define BISON_STACK_HH
1227
1228#include <deque>
1229
1230]b4_namespace_open[
1231 template <class T, class S = std::deque<T> >
1232 class stack
1233 {
1234 public:
1235
1236 // Hide our reversed order.
1237 typedef typename S::reverse_iterator iterator;
1238 typedef typename S::const_reverse_iterator const_iterator;
1239
1240 stack () : seq_ ()
1241 {
1242 }
1243
1244 stack (unsigned int n) : seq_ (n)
1245 {
1246 }
1247
1248 inline
1249 T&
1250 operator [] (unsigned int i)
1251 {
1252 return seq_[i];
1253 }
1254
1255 inline
1256 const T&
1257 operator [] (unsigned int i) const
1258 {
1259 return seq_[i];
1260 }
1261
1262 inline
1263 void
1264 push (const T& t)
1265 {
1266 seq_.push_front (t);
1267 }
1268
1269 inline
1270 void
1271 pop (unsigned int n = 1)
1272 {
1273 for (; n; --n)
1274 seq_.pop_front ();
1275 }
1276
1277 inline
1278 typename S::size_type
1279 size () const
1280 {
1281 return seq_.size ();
1282 }
1283
1284 inline const_iterator begin () const { return seq_.rbegin (); }
1285 inline const_iterator end () const { return seq_.rend (); }
1286
1287 private:
1288 /// The wrapped container.
1289 S seq_;
1290 };
1291
1292 /// Present a slice of the top of a stack.
1293 template <class T, class S = stack<T> >
1294 class slice
1295 {
1296 public:
1297
1298 slice (const S& stack,
1299 unsigned int range) : stack_ (stack),
1300 range_ (range)
1301 {
1302 }
1303
1304 inline
1305 const T&
1306 operator [] (unsigned int i) const
1307 {
1308 return stack_[range_ - i];
1309 }
1310
1311 private:
1312
1313 const S& stack_;
1314 unsigned int range_;
1315 };
1316]b4_namespace_close[
1317
1318#endif // not BISON_STACK_HH[]dnl
1319]
1320m4_divert_pop(0)