]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
8c5b33450d19cc3006e9cc7ab7658743059cf1d6
[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 (yychar = yyempty_)
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 /// Coded type of the lookahead.
1084 int yychar = yyempty_;
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 (yychar == yyempty_)
1146 {
1147 YYCDEBUG << "Reading a token: ";
1148 yychar = ]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 }
1153
1154 /* Convert token to internal form. */
1155 if (yychar <= yyeof_)
1156 {
1157 yychar = yyla.type = yyeof_;
1158 YYCDEBUG << "Now at end of input." << std::endl;
1159 }
1160 else
1161 {
1162 yyla.type = yytranslate_ (yychar);
1163 YY_SYMBOL_PRINT ("Next token is", yyla);
1164 }
1165
1166 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1167 to detect an error, take that action. */
1168 yyn += yyla.type;
1169 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type)
1170 goto yydefault;
1171
1172 /* Reduce or error. */
1173 yyn = yytable_[yyn];
1174 if (yyn <= 0)
1175 {
1176 if (yyn == 0 || yyn == yytable_ninf_)
1177 goto yyerrlab;
1178 yyn = -yyn;
1179 goto yyreduce;
1180 }
1181
1182 /* Discard the token being shifted. */
1183 yychar = yyempty_;
1184
1185 /* Count tokens shifted since error; after three, turn off error
1186 status. */
1187 if (yyerrstatus_)
1188 --yyerrstatus_;
1189
1190 /* Shift the lookahead token. */
1191 yystate = yyn;
1192 yypush_ ("Shifting", yystate, yyla);
1193 goto yynewstate;
1194
1195 /*-----------------------------------------------------------.
1196 | yydefault -- do the default action for the current state. |
1197 `-----------------------------------------------------------*/
1198 yydefault:
1199 yyn = yydefact_[yystate];
1200 if (yyn == 0)
1201 goto yyerrlab;
1202 goto yyreduce;
1203
1204 /*-----------------------------.
1205 | yyreduce -- Do a reduction. |
1206 `-----------------------------*/
1207 yyreduce:
1208 yylen = yyr2_[yyn];]b4_variant_if([
1209 /* Variants are always initialized to an empty instance of the
1210 correct type. The default $$=$1 rule is NOT applied when using
1211 variants */
1212 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])[],[
1213 /* If YYLEN is nonzero, implement the default value of the action:
1214 `$$ = $1'. Otherwise, use the top of the stack.
1215
1216 Otherwise, the following line sets YYLHS.VALUE to garbage.
1217 This behavior is undocumented and Bison
1218 users should not rely upon it. */
1219 if (yylen)
1220 yylhs.value = yystack_@{yylen - 1@}.value;
1221 else
1222 yylhs.value = yystack_@{0@}.value;])[
1223
1224 // Compute the default @@$.
1225 {
1226 slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
1227 YYLLOC_DEFAULT (yylhs.location, slice, yylen);
1228 }
1229
1230 // Perform the reduction.
1231 YY_REDUCE_PRINT (yyn);
1232 switch (yyn)
1233 {
1234 ]b4_user_actions[
1235 default:
1236 break;
1237 }
1238 // Compute post-reduction state.
1239 yyn = yyr1_[yyn];
1240 yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state;
1241 if (0 <= yystate && yystate <= yylast_
1242 && yycheck_[yystate] == yystack_[yylen].state)
1243 yystate = yytable_[yystate];
1244 else
1245 yystate = yydefgoto_[yyn - yyntokens_];
1246 yylhs.state = yystate;
1247 YY_SYMBOL_PRINT ("-> $$ =", yylhs);
1248 ]b4_variant_if([[
1249 // Destroy the lhs symbols.
1250 for (int i = 0; i < yylen; ++i)
1251 // Destroy a variant which value may have be swapped with
1252 // yylhs.value. The value of yylhs.value (hence maybe one of
1253 // these lhs symbols) depends on what does the default
1254 // contruction for this type. In the case of pointers for
1255 // instance, nothing is done, so the value is junk. Therefore
1256 // do not try to report the content in the debug trace, it's
1257 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1258 // traces as with the other Bison skeletons.
1259 yy_destroy_ (0, yystack_[i]);]])[
1260
1261 yypop_ (yylen);
1262 yylen = 0;
1263 YY_STACK_PRINT ();
1264
1265 /* Shift the result of the reduction. */
1266 yypush_ (0, yylhs);
1267 goto yynewstate;
1268
1269 /*------------------------------------.
1270 | yyerrlab -- here on detecting error |
1271 `------------------------------------*/
1272 yyerrlab:
1273 /* If not already recovering from an error, report this error. */
1274 if (!yyerrstatus_)
1275 {
1276 ++yynerrs_;
1277 error (yyla.location, yysyntax_error_ (yystate, yyla.type));
1278 }
1279
1280 yyerror_range[0].location = yyla.location;
1281 if (yyerrstatus_ == 3)
1282 {
1283 /* If just tried and failed to reuse lookahead token after an
1284 error, discard it. */
1285
1286 /* Return failure if at end of input. */
1287 if (yychar == yyeof_)
1288 YYABORT;
1289 else
1290 {]b4_assert_if([
1291 // Previous version of this code was ready to handle
1292 // yychar == yyempty_ (actually yychar <= yyeof_). Can it
1293 // really be triggered?
1294 assert (yychar != yyempty_);])[
1295 yy_destroy_ ("Error: discarding", yyla);
1296 yychar = yyempty_;
1297 }
1298 }
1299
1300 /* Else will try to reuse lookahead token after shifting the error
1301 token. */
1302 goto yyerrlab1;
1303
1304
1305 /*---------------------------------------------------.
1306 | yyerrorlab -- error raised explicitly by YYERROR. |
1307 `---------------------------------------------------*/
1308 yyerrorlab:
1309
1310 /* Pacify compilers like GCC when the user code never invokes
1311 YYERROR and the label yyerrorlab therefore never appears in user
1312 code. */
1313 if (false)
1314 goto yyerrorlab;
1315
1316 yyerror_range[0].location = yystack_[yylen - 1].location;
1317 /* Do not reclaim the symbols of the rule which action triggered
1318 this YYERROR. */
1319 yypop_ (yylen);
1320 yylen = 0;
1321 yystate = yystack_[0].state;
1322 goto yyerrlab1;
1323
1324 /*-------------------------------------------------------------.
1325 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1326 `-------------------------------------------------------------*/
1327 yyerrlab1:
1328 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
1329 {
1330 stack_symbol_type error_token;
1331 for (;;)
1332 {
1333 yyn = yypact_[yystate];
1334 if (yyn != yypact_ninf_)
1335 {
1336 yyn += yyterror_;
1337 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
1338 {
1339 yyn = yytable_[yyn];
1340 if (0 < yyn)
1341 break;
1342 }
1343 }
1344
1345 // Pop the current state because it cannot handle the error token.
1346 if (yystack_.size () == 1)
1347 YYABORT;
1348
1349 yyerror_range[0].location = yystack_[0].location;
1350 yy_destroy_ ("Error: popping", yystack_[0]);
1351 yypop_ ();
1352 yystate = yystack_[0].state;
1353 YY_STACK_PRINT ();
1354 }
1355
1356 yyerror_range[1].location = yyla.location;
1357 YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);
1358
1359 /* Shift the error token. */
1360 error_token.state = yystate = yyn;
1361 yypush_ ("Shifting", error_token);
1362 }
1363 goto yynewstate;
1364
1365 /* Accept. */
1366 yyacceptlab:
1367 yyresult = 0;
1368 goto yyreturn;
1369
1370 /* Abort. */
1371 yyabortlab:
1372 yyresult = 1;
1373 goto yyreturn;
1374
1375 yyreturn:
1376 if (yychar != yyempty_)
1377 yy_destroy_ ("Cleanup: discarding lookahead", yyla);
1378
1379 /* Do not reclaim the symbols of the rule which action triggered
1380 this YYABORT or YYACCEPT. */
1381 yypop_ (yylen);
1382 while (yystack_.size () != 1)
1383 {
1384 yy_destroy_ ("Cleanup: popping", yystack_[0]);
1385 yypop_ ();
1386 }
1387
1388 return yyresult;
1389 }
1390
1391 // Generate an error message.
1392 std::string
1393 ]b4_parser_class_name[::yysyntax_error_ (int yystate, int]dnl
1394 b4_error_verbose_if([ tok])[)
1395 {
1396 std::string res;
1397 YYUSE (yystate);
1398 #if YYERROR_VERBOSE
1399 int yyn = yypact_[yystate];
1400 if (yypact_ninf_ < yyn && yyn <= yylast_)
1401 {
1402 /* Start YYX at -YYN if negative to avoid negative indexes in
1403 YYCHECK. */
1404 int yyxbegin = yyn < 0 ? -yyn : 0;
1405
1406 /* Stay within bounds of both yycheck and yytname. */
1407 int yychecklim = yylast_ - yyn + 1;
1408 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1409 int count = 0;
1410 for (int x = yyxbegin; x < yyxend; ++x)
1411 if (yycheck_[x + yyn] == x && x != yyterror_)
1412 ++count;
1413
1414 // FIXME: This method of building the message is not compatible
1415 // with internationalization. It should work like yacc.c does it.
1416 // That is, first build a string that looks like this:
1417 // "syntax error, unexpected %s or %s or %s"
1418 // Then, invoke YY_ on this string.
1419 // Finally, use the string as a format to output
1420 // yytname_[tok], etc.
1421 // Until this gets fixed, this message appears in English only.
1422 res = "syntax error, unexpected ";
1423 res += yytnamerr_ (yytname_[tok]);
1424 if (count < 5)
1425 {
1426 count = 0;
1427 for (int x = yyxbegin; x < yyxend; ++x)
1428 if (yycheck_[x + yyn] == x && x != yyterror_)
1429 {
1430 res += (!count++) ? ", expecting " : " or ";
1431 res += yytnamerr_ (yytname_[x]);
1432 }
1433 }
1434 }
1435 else
1436 #endif
1437 res = YY_("syntax error");
1438 return res;
1439 }
1440
1441
1442 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1443 STATE-NUM. */
1444 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1445 ]b4_table_define([pact], [b4_pact])[;
1446
1447 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1448 doesn't specify something else to do. Zero means the default is an
1449 error. */
1450 ]b4_table_define([defact], [b4_defact])[;
1451
1452 /* YYPGOTO[NTERM-NUM]. */
1453 ]b4_table_define([pgoto], [b4_pgoto])[;
1454
1455 /* YYDEFGOTO[NTERM-NUM]. */
1456 ]b4_table_define([defgoto], [b4_defgoto])[;
1457
1458 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1459 positive, shift that token. If negative, reduce the rule which
1460 number is the opposite. If zero, do what YYDEFACT says. */
1461 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1462 ]b4_table_define([table], [b4_table])[;
1463
1464 /* YYCHECK. */
1465 ]b4_table_define([check], [b4_check])[;
1466
1467 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1468 symbol of state STATE-NUM. */
1469 ]b4_table_define([stos], [b4_stos])[;
1470
1471 #if YYDEBUG
1472 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1473 to YYLEX-NUM. */
1474 ]b4_table_define([token_number], [b4_toknum])[;
1475 #endif
1476
1477 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1478 ]b4_table_define([r1], [b4_r1])[;
1479
1480 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1481 ]b4_table_define([r2], [b4_r2])[;
1482
1483 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1484 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1485 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1486 const char*
1487 const ]b4_parser_class_name[::yytname_[] =
1488 {
1489 ]b4_tname[
1490 };
1491 #endif
1492
1493 #if YYDEBUG
1494 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1495 ]b4_table_define([rline], [b4_rline])[;
1496
1497 // Print the state stack on the debug stream.
1498 void
1499 ]b4_parser_class_name[::yystack_print_ ()
1500 {
1501 *yycdebug_ << "Stack now";
1502 for (stack_type::const_iterator
1503 i = yystack_.begin (),
1504 i_end = yystack_.end ();
1505 i != i_end; ++i)
1506 *yycdebug_ << ' ' << i->state;
1507 *yycdebug_ << std::endl;
1508 }
1509
1510 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1511 void
1512 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1513 {
1514 unsigned int yylno = yyrline_[yyrule];
1515 int yynrhs = yyr2_[yyrule];
1516 /* Print the symbols being reduced, and their result. */
1517 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1518 << " (line " << yylno << "):" << std::endl;
1519 /* The symbols being reduced. */
1520 for (int yyi = 0; yyi < yynrhs; yyi++)
1521 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1522 ]b4_rhs_data(yynrhs, yyi + 1)[);
1523 }
1524 #endif // YYDEBUG
1525
1526 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1527 ]b4_parser_class_name[::token_number_type
1528 ]b4_parser_class_name[::yytranslate_ (int t)
1529 {
1530 static
1531 const token_number_type
1532 translate_table[] =
1533 {
1534 ]b4_translate[
1535 };
1536 const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
1537 const token_number_type undef_token_ = ]b4_undef_token_number[;
1538
1539 if (static_cast<unsigned int> (t) <= user_token_number_max_)
1540 return translate_table[t];
1541 else
1542 return undef_token_;
1543 }
1544
1545 ]b4_namespace_close[
1546
1547 ]b4_epilogue[]dnl
1548 @output(b4_dir_prefix[]stack.hh@)@
1549 b4_copyright([Stack handling for Bison parsers in C++])[
1550
1551 #ifndef BISON_STACK_HH
1552 # define BISON_STACK_HH
1553
1554 #include <deque>
1555
1556 ]b4_namespace_open[
1557 template <class T, class S = std::deque<T> >
1558 class stack
1559 {
1560 public:
1561
1562 // Hide our reversed order.
1563 typedef typename S::reverse_iterator iterator;
1564 typedef typename S::const_reverse_iterator const_iterator;
1565
1566 stack () : seq_ ()
1567 {
1568 }
1569
1570 stack (unsigned int n) : seq_ (n)
1571 {
1572 }
1573
1574 inline
1575 T&
1576 operator [] (unsigned int i)
1577 {
1578 return seq_[i];
1579 }
1580
1581 inline
1582 const T&
1583 operator [] (unsigned int i) const
1584 {
1585 return seq_[i];
1586 }
1587
1588 inline
1589 void
1590 push (const T& t)
1591 {
1592 seq_.push_front (t);
1593 }
1594
1595 inline
1596 void
1597 pop (unsigned int n = 1)
1598 {
1599 for (; n; --n)
1600 seq_.pop_front ();
1601 }
1602
1603 inline
1604 typename S::size_type
1605 size () const
1606 {
1607 return seq_.size ();
1608 }
1609
1610 inline const_iterator begin () const { return seq_.rbegin (); }
1611 inline const_iterator end () const { return seq_.rend (); }
1612
1613 private:
1614 /// The wrapped container.
1615 S seq_;
1616 };
1617
1618 /// Present a slice of the top of a stack.
1619 template <class T, class S = stack<T> >
1620 class slice
1621 {
1622 public:
1623
1624 slice (const S& stack,
1625 unsigned int range) : stack_ (stack),
1626 range_ (range)
1627 {
1628 }
1629
1630 inline
1631 const T&
1632 operator [] (unsigned int i) const
1633 {
1634 return stack_[range_ - i];
1635 }
1636
1637 private:
1638
1639 const S& stack_;
1640 unsigned int range_;
1641 };
1642 ]b4_namespace_close[
1643
1644 #endif // not BISON_STACK_HH[]dnl
1645 ]
1646 m4_divert_pop(0)
1647 m4_popdef([b4_copyright_years])dnl