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