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