]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
Dub symbol_type_base as a public type.
[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_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
23 # --------------------------------------------------------------
24 # Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT.
25 m4_define([b4_integral_parser_table_declare],
26 [m4_ifval([$3], [b4_c_comment([$3], [ ])
27 ])dnl
28 static const b4_int_type_for([$2]) yy$1_[[]];dnl
29 ])
30
31 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
32 # ---------------------------------------------
33 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
34 m4_define([b4_integral_parser_table_define],
35 [ const b4_int_type_for([$2])
36 b4_parser_class_name::yy$1_[[]] =
37 {
38 $2
39 };dnl
40 ])
41
42
43 # b4_symbol_value_template(VAL, [TYPE])
44 # -------------------------------------
45 # Same as b4_symbol_value, but used in a template method. It makes
46 # a difference when using variants.
47 m4_copy([b4_symbol_value], [b4_symbol_value_template])
48
49
50 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
51 # ----------------------------------------------------------------
52 m4_define([b4_lex_symbol_if],
53 [b4_percent_define_ifdef([[lex_symbol]], [$1], [$2])])
54
55
56 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
57 # ------------------------------------------------
58 m4_define([b4_assert_if],
59 [b4_percent_define_ifdef([[assert]], [$1], [$2])])
60
61
62 # b4_lhs_value([TYPE])
63 # --------------------
64 # Expansion of $<TYPE>$.
65 m4_define([b4_lhs_value],
66 [b4_symbol_value([yylhs.value], [$1])])
67
68
69 # b4_lhs_location()
70 # -----------------
71 # Expansion of @$.
72 m4_define([b4_lhs_location],
73 [yylhs.location])
74
75
76 # b4_rhs_data(RULE-LENGTH, NUM)
77 # -----------------------------
78 # Return the data corresponding to the symbol #NUM, where the current
79 # rule has RULE-LENGTH symbols on RHS.
80 m4_define([b4_rhs_data],
81 [yystack_@{b4_subtract($@)@}])
82
83
84 # b4_rhs_state(RULE-LENGTH, NUM)
85 # ------------------------------
86 # The state corresponding to the symbol #NUM, where the current
87 # rule has RULE-LENGTH symbols on RHS.
88 m4_define([b4_rhs_state],
89 [b4_rhs_data([$1], [$2]).state])
90
91
92 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
93 # --------------------------------------
94 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
95 # symbols on RHS.
96 m4_define([b4_rhs_value],
97 [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])])
98
99
100 # b4_rhs_location(RULE-LENGTH, NUM)
101 # ---------------------------------
102 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
103 # on RHS.
104 m4_define([b4_rhs_location],
105 [b4_rhs_data([$1], [$2]).location])
106
107
108 # b4_symbol_action(SYMBOL-NUM, KIND)
109 # ----------------------------------
110 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
111 # Same as in C, but using references instead of pointers.
112 m4_define([b4_symbol_action],
113 [b4_symbol_if([$1], [has_$2],
114 [m4_pushdef([b4_dollar_dollar],
115 [b4_symbol_value_template([yysym.value],
116 b4_symbol_if([$1], [has_type],
117 [b4_symbol([$1], [type])]))])dnl
118 m4_pushdef([b4_at_dollar], [yysym.location])dnl
119 b4_symbol_case_([$1])
120 b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
121 b4_symbol([$1], [$2])
122 b4_syncline([@oline@], [@ofile@])
123 break;
124
125 m4_popdef([b4_at_dollar])dnl
126 m4_popdef([b4_dollar_dollar])dnl
127 ])])
128
129 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
130 # -------------------------------------------------
131 # Declare the overloaded version of make_symbol for the (common) type of
132 # these SYMBOL-NUMBERS. Use at class-level.
133 m4_define([b4_symbol_constructor_declaration_],
134 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
135 [ static inline
136 symbol_type
137 make_[]b4_symbol_([$1], [id]) (dnl
138 b4_args(b4_symbol_if([$1], [has_type],
139 [const b4_symbol([$1], [type])& v]),
140 b4_locations_if([const location_type& l])));
141
142 ])])])
143
144
145 # b4_symbol_constructor_declarations
146 # ----------------------------------
147 # Declare symbol constructors for all the value types.
148 # Use at class-level.
149 m4_define([b4_symbol_constructor_declarations],
150 [b4_variant_if([
151 // Symbol constructors declarations.
152 b4_symbol_foreach([b4_symbol_constructor_declaration_])])])
153
154
155
156 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
157 # ------------------------------------------------
158 # Define symbol constructor for this SYMBOL-NUMBER.
159 m4_define([b4_symbol_constructor_definition_],
160 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
161 [ b4_parser_class_name::symbol_type
162 b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
163 b4_args(b4_symbol_if([$1], [has_type],
164 [const b4_symbol([$1], [type])& v]),
165 b4_locations_if([const location_type& l])))
166 {
167 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$1], [id]))],
168 b4_symbol_if([$1], [has_type], [v]),
169 b4_locations_if([l])));
170 }
171
172 ])])])
173
174
175 # b4_symbol_constructor_definitions
176 # ----------------------------------
177 # Define the overloaded versions of make_symbol for all the value types.
178 m4_define([b4_symbol_constructor_definitions],
179 [b4_variant_if([
180 // Implementation of make_symbol for each symbol type.
181 b4_symbol_foreach([b4_symbol_constructor_definition_])])])
182
183
184 # b4_yytranslate_definition
185 # -------------------------
186 # Define yytranslate_. Sometimes we want it in the header file,
187 # sometimes the cc file suffices.
188 m4_define([b4_yytranslate_definition],
189 [[ // Symbol number corresponding to token number t.
190 ]b4_parser_class_name[::token_number_type
191 ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type],
192 [int])[ t)
193 {
194 static
195 const token_number_type
196 translate_table[] =
197 {
198 ]b4_translate[
199 };
200 const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
201 const token_number_type undef_token_ = ]b4_undef_token_number[;
202
203 if (static_cast<int>(t) <= yyeof_)
204 return yyeof_;
205 else if (static_cast<unsigned int> (t) <= user_token_number_max_)
206 return translate_table[t];
207 else
208 return undef_token_;
209 }
210 ]])
211
212
213 m4_pushdef([b4_copyright_years],
214 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
215
216 m4_define([b4_parser_class_name],
217 [b4_percent_define_get([[parser_class_name]])])
218
219 # The header is mandatory.
220 b4_defines_if([],
221 [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
222
223 b4_locations_if(
224 [# Backward compatibility.
225 m4_define([b4_location_constructors])
226 m4_include(b4_pkgdatadir/[location.cc])])
227 m4_include(b4_pkgdatadir/[stack.hh])
228 b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])])
229
230 # We do want M4 expansion after # for CPP macros.
231 m4_changecom()
232 m4_divert_push(0)dnl
233 @output(b4_spec_defines_file@)@
234 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
235 dnl FIXME: This is wrong, we want computed header guards.
236 [
237 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
238
239 #ifndef PARSER_HEADER_H
240 # define PARSER_HEADER_H
241
242 ]b4_percent_code_get([[requires]])[
243
244 ]b4_assert_if([#include <cassert>])[
245 #include <string>
246 #include <iostream>
247 #include "stack.hh"
248
249 ]b4_namespace_open[
250 ]b4_locations_if([ class position;
251 class location;])[
252 ]b4_variant_if([b4_variant_definition])[
253 ]b4_namespace_close[
254
255 ]b4_locations_if([#include "location.hh"])[
256
257 /* Enabling traces. */
258 #ifndef YYDEBUG
259 # define YYDEBUG ]b4_debug_flag[
260 #endif
261
262 /* Enabling verbose error messages. */
263 #ifdef YYERROR_VERBOSE
264 # undef YYERROR_VERBOSE
265 # define YYERROR_VERBOSE 1
266 #else
267 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
268 #endif
269
270 /* Enabling the token table. */
271 #ifndef YYTOKEN_TABLE
272 # define YYTOKEN_TABLE ]b4_token_table[
273 #endif
274
275 ]b4_locations_if([dnl
276 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
277 If N is 0, then set CURRENT to the empty location which ends
278 the previous symbol: RHS[0] (always defined). */
279
280 #ifndef YYLLOC_DEFAULT
281 # define YYLLOC_DEFAULT(Current, Rhs, N) \
282 do { \
283 if (N) \
284 { \
285 (Current).begin = (Rhs)[1].location.begin; \
286 (Current).end = (Rhs)[N].location.end; \
287 } \
288 else \
289 { \
290 (Current).begin = (Current).end = (Rhs)[0].location.end; \
291 } \
292 } while (false)
293 #endif]])[
294
295 ]b4_namespace_open[
296
297 /// A Bison parser.
298 class ]b4_parser_class_name[
299 {
300 public:
301 ]b4_public_types_declare[
302 ]b4_symbol_constructor_declarations[
303 /// Build a parser object.
304 ]b4_parser_class_name[ (]b4_parse_param_decl[);
305 virtual ~]b4_parser_class_name[ ();
306
307 /// Parse.
308 /// \returns 0 iff parsing succeeded.
309 virtual int parse ();
310
311 #if YYDEBUG
312 /// The current debugging stream.
313 std::ostream& debug_stream () const;
314 /// Set the current debugging stream.
315 void set_debug_stream (std::ostream &);
316
317 /// Type for debugging levels.
318 typedef int debug_level_type;
319 /// The current debugging level.
320 debug_level_type debug_level () const;
321 /// Set the current debugging level.
322 void set_debug_level (debug_level_type l);
323 #endif
324
325 /// Report a syntax error.]b4_locations_if([
326 /// \param loc where the syntax error is found.])[
327 /// \param msg a description of the syntax error.
328 virtual void error (]b4_locations_if([const location_type& loc, ])[const std::string& msg);
329
330 private:
331 /// Generate an error message.
332 /// \param state the state where the error occurred.
333 /// \param tok the lookahead token.
334 virtual std::string yysyntax_error_ (int yystate, int tok);
335
336 /// State numbers.
337 typedef int state_type;
338
339 /// Internal symbol numbers.
340 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
341 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
342 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
343
344 /* Tables. */
345 ]b4_parser_tables_declare[
346
347 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
348 /// For a symbol, its name in clear.
349 static const char* const yytname_[];
350 #endif]b4_error_verbose_if([
351
352 /// Convert the symbol name \a n to a form suitable for a diagnostic.
353 static std::string yytnamerr_ (const char *n);])[
354
355 #if YYDEBUG
356 ]b4_integral_parser_table_declare([rline], [b4_rline],
357 [YYRLINE[YYN] -- Source line where rule number YYN was defined.])[
358 /// Report on the debug stream that the rule \a r is going to be reduced.
359 virtual void yy_reduce_print_ (int r);
360 /// Print the state stack on the debug stream.
361 virtual void yystack_print_ ();
362
363 /* Debugging. */
364 int yydebug_;
365 std::ostream* yycdebug_;
366 #endif
367
368 /// Convert a scanner token number \a t to a symbol number.
369 static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
370
371 #if YYDEBUG
372 /// \brief Display a symbol type, value and location.
373 /// \param yyo The output stream.
374 /// \param yysym The symbol.
375 template <typename Exact>
376 void yy_print_ (std::ostream& yyo,
377 const symbol_base_type<Exact>& yysym) const;
378 #endif
379
380 /// \brief Reclaim the memory associated to a symbol.
381 /// \param yymsg Why this token is reclaimed.
382 /// If null, print nothing.
383 /// \param s The symbol.
384 template <typename Exact>
385 inline void yy_destroy_ (const char* yymsg,
386 symbol_base_type<Exact>& yysym) const;
387
388 private:
389 /// Element of the stack: a state and its attributes.
390 struct stack_symbol_type : symbol_base_type<stack_symbol_type>
391 {
392 /// The parent class.
393 typedef symbol_base_type<stack_symbol_type> super_type;
394
395 /// Default constructor.
396 inline stack_symbol_type ();
397
398 /// Constructor.
399 inline stack_symbol_type (]b4_args([state_type s],
400 [const semantic_type& v],
401 b4_locations_if([const location_type& l]))[);
402
403 /// The state.
404 state_type state;
405
406 /// Return the type corresponding to this state.
407 inline int type_get_ () const;
408 };
409
410 /// Stack type.
411 typedef stack<stack_symbol_type> stack_type;
412
413 /// The stack.
414 stack_type yystack_;
415
416 /// Push a new state on the stack.
417 /// \param m a debug message to display
418 /// if null, no trace is output.
419 /// \param s the symbol
420 /// \warning the contents of \a s.value is stolen.
421 inline void yypush_ (const char* m, stack_symbol_type& s);
422
423 /// Push a new look ahead token on the state on the stack.
424 /// \param m a debug message to display
425 /// if null, no trace is output.
426 /// \param s the state
427 /// \param sym the symbol (for its value and location).
428 /// \warning the contents of \a s.value is stolen.
429 inline void yypush_ (const char* m, state_type s, symbol_type& sym);
430
431 /// Pop \a n symbols the three stacks.
432 inline void yypop_ (unsigned int n = 1);
433
434 /* Constants. */
435 enum
436 {
437 yyeof_ = 0,
438 yylast_ = ]b4_last[, //< Last index in yytable_.
439 yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols.
440 yyempty_ = -2,
441 yyfinal_ = ]b4_final_state_number[, //< Termination state number.
442 yyterror_ = 1,
443 yyerrcode_ = 256,
444 yyntokens_ = ]b4_tokens_number[, //< Number of tokens.
445 };
446
447 ]b4_parse_param_vars[
448 };
449
450 ]b4_lex_symbol_if([b4_yytranslate_definition
451 b4_public_types_define
452 b4_symbol_constructor_definitions])[
453 ]b4_namespace_close[
454
455 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
456 [b4_token_defines(b4_tokens)
457
458 #ifndef YYSTYPE
459 /* Redirection for backward compatibility. */
460 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
461 #endif
462 ])
463 b4_percent_code_get([[provides]])[]dnl
464
465 [#endif /* ! defined PARSER_HEADER_H */]
466 @output(b4_parser_file_name@)@
467 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
468 b4_percent_code_get([[top]])[]dnl
469 m4_if(b4_prefix, [yy], [],
470 [
471 // Take the name prefix into account.
472 #define yylex b4_prefix[]lex])[
473
474 /* First part of user declarations. */
475 ]b4_user_pre_prologue[
476
477 #include "@basename(]b4_spec_defines_file[@)"
478
479 /* User implementation prologue. */
480 ]b4_user_post_prologue
481 b4_percent_code_get[]dnl
482
483 [#ifndef YY_
484 # if YYENABLE_NLS
485 # if ENABLE_NLS
486 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
487 # define YY_(msgid) dgettext ("bison-runtime", msgid)
488 # endif
489 # endif
490 # ifndef YY_
491 # define YY_(msgid) msgid
492 # endif
493 #endif
494
495 /* Suppress unused-variable warnings by "using" E. */
496 #define YYUSE(e) ((void) (e))
497
498 /* Enable debugging if requested. */
499 #if YYDEBUG
500
501 /* A pseudo ostream that takes yydebug_ into account. */
502 # define YYCDEBUG if (yydebug_) (*yycdebug_)
503
504 # define YY_SYMBOL_PRINT(Title, Symbol) \
505 do { \
506 if (yydebug_) \
507 { \
508 *yycdebug_ << Title << ' '; \
509 yy_print_ (*yycdebug_, Symbol); \
510 *yycdebug_ << std::endl; \
511 } \
512 } while (false)
513
514 # define YY_REDUCE_PRINT(Rule) \
515 do { \
516 if (yydebug_) \
517 yy_reduce_print_ (Rule); \
518 } while (false)
519
520 # define YY_STACK_PRINT() \
521 do { \
522 if (yydebug_) \
523 yystack_print_ (); \
524 } while (false)
525
526 #else /* !YYDEBUG */
527
528 # define YYCDEBUG if (false) std::cerr
529 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
530 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
531 # define YY_STACK_PRINT() static_cast<void>(0)
532
533 #endif /* !YYDEBUG */
534
535 #define yyerrok (yyerrstatus_ = 0)
536 #define yyclearin (yyempty = true)
537
538 #define YYACCEPT goto yyacceptlab
539 #define YYABORT goto yyabortlab
540 #define YYERROR goto yyerrorlab
541 #define YYRECOVERING() (!!yyerrstatus_)
542
543 ]b4_namespace_open[]b4_error_verbose_if([[
544
545 /* Return YYSTR after stripping away unnecessary quotes and
546 backslashes, so that it's suitable for yyerror. The heuristic is
547 that double-quoting is unnecessary unless the string contains an
548 apostrophe, a comma, or backslash (other than backslash-backslash).
549 YYSTR is taken from yytname. */
550 std::string
551 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
552 {
553 if (*yystr == '"')
554 {
555 std::string yyr = "";
556 char const *yyp = yystr;
557
558 for (;;)
559 switch (*++yyp)
560 {
561 case '\'':
562 case ',':
563 goto do_not_strip_quotes;
564
565 case '\\':
566 if (*++yyp != '\\')
567 goto do_not_strip_quotes;
568 /* Fall through. */
569 default:
570 yyr += *yyp;
571 break;
572
573 case '"':
574 return yyr;
575 }
576 do_not_strip_quotes: ;
577 }
578
579 return yystr;
580 }
581 ]])[
582
583 /// Build a parser object.
584 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
585 :])[
586 #if YYDEBUG
587 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
588 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
589 #endif]b4_parse_param_cons[
590 {
591 }
592
593 ]b4_parser_class_name::~b4_parser_class_name[ ()
594 {
595 }
596
597
598 /*---------------.
599 | Symbol types. |
600 `---------------*/
601
602 ]b4_lex_symbol_if([], [b4_public_types_define
603 b4_symbol_constructor_definitions])[
604
605 // stack_symbol_type.
606 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
607 : super_type ()
608 , state ()
609 {
610 }
611
612 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (]b4_args(
613 [state_type s],
614 [const semantic_type& v],
615 b4_locations_if([const location_type& l]))[)
616 : super_type (v]b4_locations_if([, l])[)
617 , state (s)
618 {
619 }
620
621 int
622 ]b4_parser_class_name[::stack_symbol_type::type_get_ () const
623 {
624 return yystos_[state];
625 }
626
627
628 template <typename Exact>
629 void
630 ]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
631 symbol_base_type<Exact>& yysym) const
632 {
633 int yytype = yysym.type_get ();
634 YYUSE (yymsg);
635 if (yymsg)
636 YY_SYMBOL_PRINT (yymsg, yysym);
637
638 // User destructor.
639 switch (yytype)
640 {
641 ]b4_symbol_foreach([b4_symbol_destructor])dnl
642 [ default:
643 break;
644 }]b4_variant_if([
645
646 // Type destructor.
647 b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[
648 }
649
650 #if YYDEBUG
651 template <typename Exact>
652 void
653 ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
654 const symbol_base_type<Exact>& yysym) const
655 {
656 int yytype = yysym.type_get ();
657 yyo << (yytype < yyntokens_ ? "token" : "nterm")
658 << ' ' << yytname_[yytype] << " ("]b4_locations_if([
659 << yysym.location << ": "])[;
660 switch (yytype)
661 {
662 ]b4_symbol_foreach([b4_symbol_printer])dnl
663 [ default:
664 break;
665 }
666 yyo << ')';
667 }
668 #endif
669
670 void
671 ]b4_parser_class_name[::yypush_ (const char* m, state_type s,
672 symbol_type& sym)
673 {
674 if (m)
675 YY_SYMBOL_PRINT (m, sym);
676 ]b4_variant_if(
677 [[ yystack_.push (stack_symbol_type (]b4_args(
678 [s],
679 [semantic_type()],
680 b4_locations_if([sym.location]))[));
681 ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]],
682 [build], [sym.value])],
683 [[ yystack_.push (stack_symbol_type (]b4_args(
684 [s],
685 [sym.value],
686 b4_locations_if([sym.location]))[));]])[
687 }
688
689 void
690 ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s)
691 {
692 if (m)
693 YY_SYMBOL_PRINT (m, s);
694 ]b4_variant_if(
695 [[ yystack_.push (stack_symbol_type (]b4_args(
696 [s.state],
697 [semantic_type()],
698 b4_locations_if([s.location]))[));
699 ]b4_symbol_variant([[yystos_[s.state]]], [[yystack_[0].value]],
700 [build], [s.value])],
701 [ yystack_.push (s);])[
702 }
703
704 void
705 ]b4_parser_class_name[::yypop_ (unsigned int n)
706 {
707 yystack_.pop (n);
708 }
709
710 #if YYDEBUG
711 std::ostream&
712 ]b4_parser_class_name[::debug_stream () const
713 {
714 return *yycdebug_;
715 }
716
717 void
718 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
719 {
720 yycdebug_ = &o;
721 }
722
723
724 ]b4_parser_class_name[::debug_level_type
725 ]b4_parser_class_name[::debug_level () const
726 {
727 return yydebug_;
728 }
729
730 void
731 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
732 {
733 yydebug_ = l;
734 }
735 #endif
736
737 int
738 ]b4_parser_class_name[::parse ()
739 {
740 /// Whether yyla contains a lookahead.
741 bool yyempty = true;
742
743 /* State. */
744 int yyn;
745 int yylen = 0;
746 int yystate = 0;
747
748 /* Error handling. */
749 int yynerrs_ = 0;
750 int yyerrstatus_ = 0;
751
752 /// The lookahead symbol.
753 symbol_type yyla;]b4_locations_if([[
754
755 /// The locations where the error started and ended.
756 stack_symbol_type yyerror_range[2];]])[
757
758 /// $$ and @@$.
759 stack_symbol_type yylhs;
760
761 /// The return value of parse().
762 int yyresult;
763
764 YYCDEBUG << "Starting parse" << std::endl;
765
766 ]m4_ifdef([b4_initial_action], [
767 m4_pushdef([b4_at_dollar], [yyla.location])dnl
768 m4_pushdef([b4_dollar_dollar], [yyla.value])dnl
769 /* User initialization code. */
770 b4_user_initial_action
771 m4_popdef([b4_dollar_dollar])dnl
772 m4_popdef([b4_at_dollar])])dnl
773
774 [ /* Initialize the stack. The initial state will be set in
775 yynewstate, since the latter expects the semantical and the
776 location values to have been already stored, initialize these
777 stacks with a primary value. */
778 yystack_ = stack_type (0);
779 yypush_ (0, 0, yyla);
780
781 // A new state was pushed on the stack.
782 // Invariant: yystate == yystack_[0].state, i.e.,
783 // yystate was just pushed onto the state stack.
784 yynewstate:
785 YYCDEBUG << "Entering state " << yystate << std::endl;
786
787 /* Accept? */
788 if (yystate == yyfinal_)
789 goto yyacceptlab;
790
791 goto yybackup;
792
793 /* Backup. */
794 yybackup:
795
796 /* Try to take a decision without lookahead. */
797 yyn = yypact_[yystate];
798 if (yyn == yypact_ninf_)
799 goto yydefault;
800
801 /* Read a lookahead token. */
802 if (yyempty)
803 {
804 YYCDEBUG << "Reading a token: ";
805 ]b4_lex_symbol_if(
806 [ yyla = b4_c_function_call([yylex], [symbol_type],
807 m4_ifdef([b4_lex_param], b4_lex_param));],
808 [ yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
809 [[YYSTYPE*], [&yyla.value]][]dnl
810 b4_locations_if([, [[location*], [&yyla.location]]])dnl
811 m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
812 yyempty = false;
813 }
814 YY_SYMBOL_PRINT ("Next token is", yyla);
815
816 /* If the proper action on seeing token YYLA.TYPE is to reduce or
817 to detect an error, take that action. */
818 yyn += yyla.type;
819 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type)
820 goto yydefault;
821
822 /* Reduce or error. */
823 yyn = yytable_[yyn];
824 if (yyn <= 0)
825 {
826 if (yyn == 0 || yyn == yytable_ninf_)
827 goto yyerrlab;
828 yyn = -yyn;
829 goto yyreduce;
830 }
831
832 /* Discard the token being shifted. */
833 yyempty = true;
834
835 /* Count tokens shifted since error; after three, turn off error
836 status. */
837 if (yyerrstatus_)
838 --yyerrstatus_;
839
840 /* Shift the lookahead token. */
841 yystate = yyn;
842 yypush_ ("Shifting", yystate, yyla);
843 goto yynewstate;
844
845 /*-----------------------------------------------------------.
846 | yydefault -- do the default action for the current state. |
847 `-----------------------------------------------------------*/
848 yydefault:
849 yyn = yydefact_[yystate];
850 if (yyn == 0)
851 goto yyerrlab;
852 goto yyreduce;
853
854 /*-----------------------------.
855 | yyreduce -- Do a reduction. |
856 `-----------------------------*/
857 yyreduce:
858 yylen = yyr2_[yyn];]b4_variant_if([
859 /* Variants are always initialized to an empty instance of the
860 correct type. The default $$=$1 action is NOT applied when using
861 variants. */
862 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build]),[
863 /* If YYLEN is nonzero, implement the default value of the action:
864 `$$ = $1'. Otherwise, use the top of the stack.
865
866 Otherwise, the following line sets YYLHS.VALUE to garbage.
867 This behavior is undocumented and Bison
868 users should not rely upon it. */
869 if (yylen)
870 yylhs.value = yystack_@{yylen - 1@}.value;
871 else
872 yylhs.value = yystack_@{0@}.value;])[
873 ]b4_locations_if([dnl
874 [
875 // Compute the default @@$.
876 {
877 slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
878 YYLLOC_DEFAULT (yylhs.location, slice, yylen);
879 }]])[
880
881 // Perform the reduction.
882 YY_REDUCE_PRINT (yyn);
883 switch (yyn)
884 {
885 ]b4_user_actions[
886 default:
887 break;
888 }
889 // Compute post-reduction state.
890 yyn = yyr1_[yyn];
891 yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state;
892 if (0 <= yystate && yystate <= yylast_
893 && yycheck_[yystate] == yystack_[yylen].state)
894 yystate = yytable_[yystate];
895 else
896 yystate = yydefgoto_[yyn - yyntokens_];
897 yylhs.state = yystate;
898 YY_SYMBOL_PRINT ("-> $$ =", yylhs);
899 ]b4_variant_if([[
900 // Destroy the rhs symbols.
901 for (int i = 0; i < yylen; ++i)
902 // Destroy a variant which value may have been swapped with
903 // yylhs.value (for instance if the action was "std::swap($$,
904 // $1)"). The value of yylhs.value (hence possibly one of these
905 // rhs symbols) depends on the default contruction for this
906 // type. In the case of pointers for instance, no
907 // initialization is done, so the value is junk. Therefore do
908 // not try to report the value of symbols about to be destroyed
909 // in the debug trace, it's possibly junk. Hence yymsg = 0.
910 // Besides, that keeps exactly the same traces as with the other
911 // Bison skeletons.
912 yy_destroy_ (0, yystack_[i]);]])[
913
914 yypop_ (yylen);
915 yylen = 0;
916 YY_STACK_PRINT ();
917
918 /* Shift the result of the reduction. */
919 yypush_ (0, yylhs);
920 goto yynewstate;
921
922 /*--------------------------------------.
923 | yyerrlab -- here on detecting error. |
924 `--------------------------------------*/
925 yyerrlab:
926 /* If not already recovering from an error, report this error. */
927 if (!yyerrstatus_)
928 {
929 ++yynerrs_;
930 error (]b4_args(b4_locations_if([yyla.location]),
931 [yysyntax_error_ (yystate, yyla.type)])[);
932 }
933
934 ]b4_locations_if([[
935 yyerror_range[0].location = yyla.location;]])[
936 if (yyerrstatus_ == 3)
937 {
938 /* If just tried and failed to reuse lookahead token after an
939 error, discard it. */
940
941 /* Return failure if at end of input. */
942 if (yyla.type == yyeof_)
943 YYABORT;
944 else
945 {
946 yy_destroy_ ("Error: discarding", yyla);
947 yyempty = true;
948 }
949 }
950
951 /* Else will try to reuse lookahead token after shifting the error
952 token. */
953 goto yyerrlab1;
954
955
956 /*---------------------------------------------------.
957 | yyerrorlab -- error raised explicitly by YYERROR. |
958 `---------------------------------------------------*/
959 yyerrorlab:
960
961 /* Pacify compilers like GCC when the user code never invokes
962 YYERROR and the label yyerrorlab therefore never appears in user
963 code. */
964 if (false)
965 goto yyerrorlab;
966
967 ]b4_locations_if([[
968 yyerror_range[0].location = yystack_[yylen - 1].location;]])[
969 /* Do not reclaim the symbols of the rule which action triggered
970 this YYERROR. */
971 yypop_ (yylen);
972 yylen = 0;
973 yystate = yystack_[0].state;
974 goto yyerrlab1;
975
976 /*-------------------------------------------------------------.
977 | yyerrlab1 -- common code for both syntax error and YYERROR. |
978 `-------------------------------------------------------------*/
979 yyerrlab1:
980 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
981 {
982 stack_symbol_type error_token;
983 for (;;)
984 {
985 yyn = yypact_[yystate];
986 if (yyn != yypact_ninf_)
987 {
988 yyn += yyterror_;
989 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
990 {
991 yyn = yytable_[yyn];
992 if (0 < yyn)
993 break;
994 }
995 }
996
997 // Pop the current state because it cannot handle the error token.
998 if (yystack_.size () == 1)
999 YYABORT;
1000 ]b4_locations_if([[
1001 yyerror_range[0].location = yystack_[0].location;]])[
1002 yy_destroy_ ("Error: popping", yystack_[0]);
1003 yypop_ ();
1004 yystate = yystack_[0].state;
1005 YY_STACK_PRINT ();
1006 }
1007 ]b4_locations_if([[
1008 yyerror_range[1].location = yyla.location;
1009 YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);]])[
1010
1011 /* Shift the error token. */
1012 error_token.state = yystate = yyn;
1013 yypush_ ("Shifting", error_token);
1014 }
1015 goto yynewstate;
1016
1017 /* Accept. */
1018 yyacceptlab:
1019 yyresult = 0;
1020 goto yyreturn;
1021
1022 /* Abort. */
1023 yyabortlab:
1024 yyresult = 1;
1025 goto yyreturn;
1026
1027 yyreturn:
1028 if (!yyempty)
1029 yy_destroy_ ("Cleanup: discarding lookahead", yyla);
1030
1031 /* Do not reclaim the symbols of the rule which action triggered
1032 this YYABORT or YYACCEPT. */
1033 yypop_ (yylen);
1034 while (yystack_.size () != 1)
1035 {
1036 yy_destroy_ ("Cleanup: popping", yystack_[0]);
1037 yypop_ ();
1038 }
1039
1040 return yyresult;
1041 }
1042
1043 // Generate an error message.
1044 std::string
1045 ]b4_parser_class_name[::yysyntax_error_ (]dnl
1046 b4_error_verbose_if([int yystate, int yytoken],
1047 [int, int])[)
1048 {
1049 std::string yyres;]b4_error_verbose_if([[
1050 int yyn = yypact_[yystate];
1051 if (yypact_ninf_ < yyn && yyn <= yylast_)
1052 {
1053 /* Start YYX at -YYN if negative to avoid negative indexes in
1054 YYCHECK. */
1055 int yyxbegin = yyn < 0 ? -yyn : 0;
1056
1057 /* Stay within bounds of both yycheck and yytname. */
1058 int yychecklim = yylast_ - yyn + 1;
1059 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1060
1061 // Number of reported tokens (one for the "unexpected", one per
1062 // "expected").
1063 size_t yycount = 0;
1064 // Its maximum.
1065 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1066 // Arguments of yyformat.
1067 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1068 yyarg[yycount++] = yytname_[yytoken];
1069 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
1070 if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_)
1071 {
1072 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1073 {
1074 yycount = 1;
1075 break;
1076 }
1077 else
1078 yyarg[yycount++] = yytname_[yyx];
1079 }
1080
1081 char const* yyformat = 0;
1082 switch (yycount)
1083 {
1084 #define YYCASE_(N, S) \
1085 case N: \
1086 yyformat = S; \
1087 break
1088 YYCASE_(1, YY_("syntax error, unexpected %s"));
1089 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1090 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1091 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1092 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1093 #undef YYCASE_
1094 }
1095 // Argument number.
1096 size_t yyi = 0;
1097 for (char const* yyp = yyformat; *yyp; ++yyp)
1098 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
1099 {
1100 yyres += yytnamerr_ (yyarg[yyi++]);
1101 ++yyp;
1102 }
1103 else
1104 yyres += *yyp;
1105 }
1106 else
1107 ]])dnl
1108 [ yyres = YY_("syntax error");
1109 return yyres;
1110 }
1111
1112
1113 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1114
1115 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1116
1117 ]b4_parser_tables_define[
1118
1119 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1120 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1121 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1122 const char*
1123 const ]b4_parser_class_name[::yytname_[] =
1124 {
1125 ]b4_tname[
1126 };
1127 #endif
1128
1129 #if YYDEBUG
1130 ]b4_integral_parser_table_define([rline], [b4_rline])[
1131
1132 // Print the state stack on the debug stream.
1133 void
1134 ]b4_parser_class_name[::yystack_print_ ()
1135 {
1136 *yycdebug_ << "Stack now";
1137 for (stack_type::const_iterator
1138 i = yystack_.begin (),
1139 i_end = yystack_.end ();
1140 i != i_end; ++i)
1141 *yycdebug_ << ' ' << i->state;
1142 *yycdebug_ << std::endl;
1143 }
1144
1145 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1146 void
1147 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1148 {
1149 unsigned int yylno = yyrline_[yyrule];
1150 int yynrhs = yyr2_[yyrule];
1151 /* Print the symbols being reduced, and their result. */
1152 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1153 << " (line " << yylno << "):" << std::endl;
1154 /* The symbols being reduced. */
1155 for (int yyi = 0; yyi < yynrhs; yyi++)
1156 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1157 ]b4_rhs_data(yynrhs, yyi + 1)[);
1158 }
1159 #endif // YYDEBUG
1160
1161 ]b4_lex_symbol_if([], [b4_yytranslate_definition])[
1162 ]b4_namespace_close[
1163 ]b4_epilogue[]dnl
1164 m4_divert_pop(0)
1165 m4_popdef([b4_copyright_years])dnl