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