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