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