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