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