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