]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
4915caa245f55e49d035c5aa4bc9d9a6361929aa
[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 if (yychar <= yyeof_)
1287 {
1288 /* Return failure if at end of input. */
1289 if (yychar == yyeof_)
1290 YYABORT;
1291 }
1292 else
1293 {
1294 yy_destroy_ ("Error: discarding", yyla);
1295 yychar = yyempty_;
1296 }
1297 }
1298
1299 /* Else will try to reuse lookahead token after shifting the error
1300 token. */
1301 goto yyerrlab1;
1302
1303
1304 /*---------------------------------------------------.
1305 | yyerrorlab -- error raised explicitly by YYERROR. |
1306 `---------------------------------------------------*/
1307 yyerrorlab:
1308
1309 /* Pacify compilers like GCC when the user code never invokes
1310 YYERROR and the label yyerrorlab therefore never appears in user
1311 code. */
1312 if (false)
1313 goto yyerrorlab;
1314
1315 yyerror_range[0].location = yystack_[yylen - 1].location;
1316 /* Do not reclaim the symbols of the rule which action triggered
1317 this YYERROR. */
1318 yypop_ (yylen);
1319 yylen = 0;
1320 yystate = yystack_[0].state;
1321 goto yyerrlab1;
1322
1323 /*-------------------------------------------------------------.
1324 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1325 `-------------------------------------------------------------*/
1326 yyerrlab1:
1327 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
1328 {
1329 stack_symbol_type error_token;
1330 for (;;)
1331 {
1332 yyn = yypact_[yystate];
1333 if (yyn != yypact_ninf_)
1334 {
1335 yyn += yyterror_;
1336 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
1337 {
1338 yyn = yytable_[yyn];
1339 if (0 < yyn)
1340 break;
1341 }
1342 }
1343
1344 // Pop the current state because it cannot handle the error token.
1345 if (yystack_.size () == 1)
1346 YYABORT;
1347
1348 yyerror_range[0].location = yystack_[0].location;
1349 yy_destroy_ ("Error: popping", yystack_[0]);
1350 yypop_ ();
1351 yystate = yystack_[0].state;
1352 YY_STACK_PRINT ();
1353 }
1354
1355 yyerror_range[1].location = yyla.location;
1356 YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);
1357
1358 /* Shift the error token. */
1359 error_token.state = yystate = yyn;
1360 yypush_ ("Shifting", error_token);
1361 }
1362 goto yynewstate;
1363
1364 /* Accept. */
1365 yyacceptlab:
1366 yyresult = 0;
1367 goto yyreturn;
1368
1369 /* Abort. */
1370 yyabortlab:
1371 yyresult = 1;
1372 goto yyreturn;
1373
1374 yyreturn:
1375 if (yychar != yyempty_)
1376 yy_destroy_ ("Cleanup: discarding lookahead", yyla);
1377
1378 /* Do not reclaim the symbols of the rule which action triggered
1379 this YYABORT or YYACCEPT. */
1380 yypop_ (yylen);
1381 while (yystack_.size () != 1)
1382 {
1383 yy_destroy_ ("Cleanup: popping", yystack_[0]);
1384 yypop_ ();
1385 }
1386
1387 return yyresult;
1388 }
1389
1390 // Generate an error message.
1391 std::string
1392 ]b4_parser_class_name[::yysyntax_error_ (int yystate, int]dnl
1393 b4_error_verbose_if([ tok])[)
1394 {
1395 std::string res;
1396 YYUSE (yystate);
1397 #if YYERROR_VERBOSE
1398 int yyn = yypact_[yystate];
1399 if (yypact_ninf_ < yyn && yyn <= yylast_)
1400 {
1401 /* Start YYX at -YYN if negative to avoid negative indexes in
1402 YYCHECK. */
1403 int yyxbegin = yyn < 0 ? -yyn : 0;
1404
1405 /* Stay within bounds of both yycheck and yytname. */
1406 int yychecklim = yylast_ - yyn + 1;
1407 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1408 int count = 0;
1409 for (int x = yyxbegin; x < yyxend; ++x)
1410 if (yycheck_[x + yyn] == x && x != yyterror_)
1411 ++count;
1412
1413 // FIXME: This method of building the message is not compatible
1414 // with internationalization. It should work like yacc.c does it.
1415 // That is, first build a string that looks like this:
1416 // "syntax error, unexpected %s or %s or %s"
1417 // Then, invoke YY_ on this string.
1418 // Finally, use the string as a format to output
1419 // yytname_[tok], etc.
1420 // Until this gets fixed, this message appears in English only.
1421 res = "syntax error, unexpected ";
1422 res += yytnamerr_ (yytname_[tok]);
1423 if (count < 5)
1424 {
1425 count = 0;
1426 for (int x = yyxbegin; x < yyxend; ++x)
1427 if (yycheck_[x + yyn] == x && x != yyterror_)
1428 {
1429 res += (!count++) ? ", expecting " : " or ";
1430 res += yytnamerr_ (yytname_[x]);
1431 }
1432 }
1433 }
1434 else
1435 #endif
1436 res = YY_("syntax error");
1437 return res;
1438 }
1439
1440
1441 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1442 STATE-NUM. */
1443 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1444 ]b4_table_define([pact], [b4_pact])[;
1445
1446 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1447 doesn't specify something else to do. Zero means the default is an
1448 error. */
1449 ]b4_table_define([defact], [b4_defact])[;
1450
1451 /* YYPGOTO[NTERM-NUM]. */
1452 ]b4_table_define([pgoto], [b4_pgoto])[;
1453
1454 /* YYDEFGOTO[NTERM-NUM]. */
1455 ]b4_table_define([defgoto], [b4_defgoto])[;
1456
1457 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1458 positive, shift that token. If negative, reduce the rule which
1459 number is the opposite. If zero, do what YYDEFACT says. */
1460 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1461 ]b4_table_define([table], [b4_table])[;
1462
1463 /* YYCHECK. */
1464 ]b4_table_define([check], [b4_check])[;
1465
1466 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1467 symbol of state STATE-NUM. */
1468 ]b4_table_define([stos], [b4_stos])[;
1469
1470 #if YYDEBUG
1471 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1472 to YYLEX-NUM. */
1473 ]b4_table_define([token_number], [b4_toknum])[;
1474 #endif
1475
1476 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1477 ]b4_table_define([r1], [b4_r1])[;
1478
1479 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1480 ]b4_table_define([r2], [b4_r2])[;
1481
1482 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1483 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1484 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1485 const char*
1486 const ]b4_parser_class_name[::yytname_[] =
1487 {
1488 ]b4_tname[
1489 };
1490 #endif
1491
1492 #if YYDEBUG
1493 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1494 ]b4_table_define([rline], [b4_rline])[;
1495
1496 // Print the state stack on the debug stream.
1497 void
1498 ]b4_parser_class_name[::yystack_print_ ()
1499 {
1500 *yycdebug_ << "Stack now";
1501 for (stack_type::const_iterator
1502 i = yystack_.begin (),
1503 i_end = yystack_.end ();
1504 i != i_end; ++i)
1505 *yycdebug_ << ' ' << i->state;
1506 *yycdebug_ << std::endl;
1507 }
1508
1509 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1510 void
1511 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1512 {
1513 unsigned int yylno = yyrline_[yyrule];
1514 int yynrhs = yyr2_[yyrule];
1515 /* Print the symbols being reduced, and their result. */
1516 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1517 << " (line " << yylno << "):" << std::endl;
1518 /* The symbols being reduced. */
1519 for (int yyi = 0; yyi < yynrhs; yyi++)
1520 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1521 ]b4_rhs_data(yynrhs, yyi + 1)[);
1522 }
1523 #endif // YYDEBUG
1524
1525 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1526 ]b4_parser_class_name[::token_number_type
1527 ]b4_parser_class_name[::yytranslate_ (int t)
1528 {
1529 static
1530 const token_number_type
1531 translate_table[] =
1532 {
1533 ]b4_translate[
1534 };
1535 const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
1536 const token_number_type undef_token_ = ]b4_undef_token_number[;
1537
1538 if (static_cast<unsigned int> (t) <= user_token_number_max_)
1539 return translate_table[t];
1540 else
1541 return undef_token_;
1542 }
1543
1544 ]b4_namespace_close[
1545
1546 ]b4_epilogue[]dnl
1547 @output(b4_dir_prefix[]stack.hh@)@
1548 b4_copyright([Stack handling for Bison parsers in C++])[
1549
1550 #ifndef BISON_STACK_HH
1551 # define BISON_STACK_HH
1552
1553 #include <deque>
1554
1555 ]b4_namespace_open[
1556 template <class T, class S = std::deque<T> >
1557 class stack
1558 {
1559 public:
1560
1561 // Hide our reversed order.
1562 typedef typename S::reverse_iterator iterator;
1563 typedef typename S::const_reverse_iterator const_iterator;
1564
1565 stack () : seq_ ()
1566 {
1567 }
1568
1569 stack (unsigned int n) : seq_ (n)
1570 {
1571 }
1572
1573 inline
1574 T&
1575 operator [] (unsigned int i)
1576 {
1577 return seq_[i];
1578 }
1579
1580 inline
1581 const T&
1582 operator [] (unsigned int i) const
1583 {
1584 return seq_[i];
1585 }
1586
1587 inline
1588 void
1589 push (const T& t)
1590 {
1591 seq_.push_front (t);
1592 }
1593
1594 inline
1595 void
1596 pop (unsigned int n = 1)
1597 {
1598 for (; n; --n)
1599 seq_.pop_front ();
1600 }
1601
1602 inline
1603 typename S::size_type
1604 size () const
1605 {
1606 return seq_.size ();
1607 }
1608
1609 inline const_iterator begin () const { return seq_.rbegin (); }
1610 inline const_iterator end () const { return seq_.rend (); }
1611
1612 private:
1613 /// The wrapped container.
1614 S seq_;
1615 };
1616
1617 /// Present a slice of the top of a stack.
1618 template <class T, class S = stack<T> >
1619 class slice
1620 {
1621 public:
1622
1623 slice (const S& stack,
1624 unsigned int range) : stack_ (stack),
1625 range_ (range)
1626 {
1627 }
1628
1629 inline
1630 const T&
1631 operator [] (unsigned int i) const
1632 {
1633 return stack_[range_ - i];
1634 }
1635
1636 private:
1637
1638 const S& stack_;
1639 unsigned int range_;
1640 };
1641 ]b4_namespace_close[
1642
1643 #endif // not BISON_STACK_HH[]dnl
1644 ]
1645 m4_divert_pop(0)
1646 m4_popdef([b4_copyright_years])dnl