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