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