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