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