]> git.saurik.com Git - bison.git/blob - data/lalr1-fusion.cc
ca5da6a5adf95a23ed11292a19c32820b37b6499
[bison.git] / data / lalr1-fusion.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 # How the semantic value is extracted when using variants.
22 b4_variant_if([
23 # b4_symbol_value(VAL, [TYPE])
24 # ----------------------------
25 m4_define([b4_symbol_value],
26 [m4_ifval([$2],
27 [$1.as<$2>()],
28 [$1])])
29 ]) # b4_variant_if
30
31
32 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
33 # --------------------------------------
34 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
35 # symbols on RHS.
36 m4_define([b4_rhs_value],
37 [b4_symbol_value([yystack_@{($1) - ($2)@}.value], [$3])])
38
39 # b4_rhs_location(RULE-LENGTH, NUM)
40 # ---------------------------------
41 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
42 # on RHS.
43 m4_define([b4_rhs_location],
44 [(yystack_@{($1) - ($2)@}.location)])
45
46
47 # b4_symbol_actions(FILENAME, LINENO,
48 # SYMBOL-TAG, SYMBOL-NUM,
49 # SYMBOL-ACTION, SYMBOL-TYPENAME)
50 # -------------------------------------------------
51 # Same as in C, but using references instead of pointers.
52 m4_define([b4_symbol_actions],
53 [m4_pushdef([b4_dollar_dollar],
54 [b4_symbol_value([yyvalue], [$6])])dnl
55 m4_pushdef([b4_at_dollar], [yylocation])dnl
56 case $4: // $3
57 b4_syncline([$2], [$1])
58 $5;
59 b4_syncline([@oline@], [@ofile@])
60 break;
61 m4_popdef([b4_at_dollar])dnl
62 m4_popdef([b4_dollar_dollar])dnl
63 ])
64
65
66 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
67 # ----------------------------------------------------------
68 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
69 m4_define([b4_symbol_action_],
70 [m4_ifval($3,
71 [ case $2: // $1
72 b4_dollar_dollar($@);
73 break;
74 ])])
75
76
77 # b4_symbol_variant(YYTYPE, YYVAL, ACTION)
78 # ----------------------------------------
79 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
80 # YYTYPE.
81 m4_define([b4_symbol_variant],
82 [m4_pushdef([b4_dollar_dollar],
83 [$2.$3<$][3>()])dnl
84 switch ($1)
85 {
86 m4_map([b4_symbol_action_], m4_defn([b4_type_names]))
87 default:
88 break;
89 }
90 m4_popdef([b4_dollar_dollar])dnl
91 ])
92
93
94 # _b4_char_sizeof_counter
95 # -----------------------
96 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
97 m4_define([_b4_char_sizeof_counter],
98 [0])
99
100 # _b4_char_sizeof_dummy
101 # ---------------------
102 # At each call return a new C++ identifier.
103 m4_define([_b4_char_sizeof_dummy],
104 [m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl
105 dummy[]_b4_char_sizeof_counter])
106
107
108 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
109 # -------------------------------------------------------
110 # To be mapped on the list of type names to produce:
111 #
112 # char dummy1[sizeof(type_name_1)];
113 # char dummy2[sizeof(type_name_2)];
114 #
115 # for defined type names.
116 # $3 is doubly-quoted, do not quote it again.
117 m4_define([b4_char_sizeof],
118 [m4_ifval($3,
119 [
120 char _b4_char_sizeof_dummy@{sizeof($3)@}; // $1])dnl
121 ])
122
123
124 m4_define([b4_parser_class_name],
125 [b4_percent_define_get([[parser_class_name]])])
126
127 # The header is mandatory.
128 b4_defines_if([],
129 [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
130
131 # Backward compatibility.
132 m4_define([b4_location_constructors])
133 m4_include(b4_pkgdatadir/[location.cc])
134
135 # We do want M4 expansion after # for CPP macros.
136 m4_changecom()
137 m4_divert_push(0)dnl
138 b4_defines_if(
139 [@output(b4_spec_defines_file@)
140 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
141 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
142 dnl FIXME: This is wrong, we want computed header guards.
143 [
144 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
145
146 #ifndef PARSER_HEADER_H
147 # define PARSER_HEADER_H
148
149 ]b4_percent_code_get([[requires]])[
150
151 #include <string>
152 #include <iostream>
153 #include "stack.hh"
154
155 ]b4_namespace_open[
156 class position;
157 class location;
158 ]b4_variant_if(
159 [[
160 /// A char[S] buffer to store and retrieve objects.
161 ///
162 /// Sort of a variant, but does not keep track of the nature
163 /// of the stored data, since that knowledge is available
164 /// via the current state.
165 template <size_t S>
166 struct variant
167 {
168 /// Instantiate a \a T in here.
169 template <typename T>
170 inline void
171 build()
172 {
173 new (buffer) T;
174 }
175
176 /// Destroy the stored \a T.
177 template <typename T>
178 inline void
179 destroy()
180 {
181 reinterpret_cast<T&>(buffer).~T();
182 }
183
184 /// Accessor to a built \a T.
185 template <typename T>
186 inline T&
187 as()
188 {
189 return reinterpret_cast<T&>(buffer);
190 }
191
192 /// Const accessor to a built \a T (for %printer).
193 template <typename T>
194 inline const T&
195 as() const
196 {
197 return reinterpret_cast<const T&>(buffer);
198 }
199
200 /// A buffer large enough to store any of the semantic values.
201 char buffer[S];
202 };
203 ]])[
204 ]b4_namespace_close[
205
206 #include "location.hh"
207
208 /* Enabling traces. */
209 #ifndef YYDEBUG
210 # define YYDEBUG ]b4_debug_flag[
211 #endif
212
213 /* Enabling verbose error messages. */
214 #ifdef YYERROR_VERBOSE
215 # undef YYERROR_VERBOSE
216 # define YYERROR_VERBOSE 1
217 #else
218 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
219 #endif
220
221 /* Enabling the token table. */
222 #ifndef YYTOKEN_TABLE
223 # define YYTOKEN_TABLE ]b4_token_table[
224 #endif
225
226 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
227 If N is 0, then set CURRENT to the empty location which ends
228 the previous symbol: RHS[0] (always defined). */
229
230 #ifndef YYLLOC_DEFAULT
231 # define YYLLOC_DEFAULT(Current, Rhs, N) \
232 do { \
233 if (N) \
234 { \
235 (Current).begin = (Rhs)[1].location.begin; \
236 (Current).end = (Rhs)[N].location.end; \
237 } \
238 else \
239 { \
240 (Current).begin = (Current).end = (Rhs)[0].location.end; \
241 } \
242 } while (false)
243 #endif
244
245 ]b4_namespace_open[
246
247 /// A Bison parser.
248 class ]b4_parser_class_name[
249 {
250 public:
251 #ifndef YYSTYPE
252 ]b4_variant_if(
253 [ /// An auxiliary type to compute the largest semantic type.
254 union union_type
255 {]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[
256 };
257
258 /// Symbol semantic values.
259 typedef variant<sizeof(union_type)> semantic_type;],
260 [ /// Symbol semantic values.
261 m4_ifdef([b4_stype],
262 [ union semantic_type
263 {b4_user_stype
264 };],
265 [m4_if(b4_tag_seen_flag, 0,
266 [[ typedef int semantic_type;]],
267 [[ typedef YYSTYPE semantic_type;]])])])[
268 #else
269 typedef YYSTYPE semantic_type;
270 #endif
271 /// Symbol locations.
272 typedef ]b4_percent_define_get([[location_type]])[ location_type;
273 /// Tokens.
274 struct token
275 {
276 ]b4_token_enums(b4_tokens)[
277 };
278 /// Token type.
279 typedef token::yytokentype token_type;
280
281 /// Build a parser object.
282 ]b4_parser_class_name[ (]b4_parse_param_decl[);
283 virtual ~]b4_parser_class_name[ ();
284
285 /// Parse.
286 /// \returns 0 iff parsing succeeded.
287 virtual int parse ();
288
289 #if YYDEBUG
290 /// The current debugging stream.
291 std::ostream& debug_stream () const;
292 /// Set the current debugging stream.
293 void set_debug_stream (std::ostream &);
294
295 /// Type for debugging levels.
296 typedef int debug_level_type;
297 /// The current debugging level.
298 debug_level_type debug_level () const;
299 /// Set the current debugging level.
300 void set_debug_level (debug_level_type l);
301 #endif
302
303 private:
304 /// Report a syntax error.
305 /// \param loc where the syntax error is found.
306 /// \param msg a description of the syntax error.
307 virtual void error (const location_type& loc, const std::string& msg);
308
309 /// Generate an error message.
310 /// \param state the state where the error occurred.
311 /// \param tok the lookahead token.
312 virtual std::string yysyntax_error_ (int yystate]dnl
313 b4_error_verbose_if([, int tok])[);
314
315 #if YYDEBUG
316 /// \brief Report a symbol value on the debug stream.
317 /// \param yytype The token type.
318 /// \param yyvalue Its semantic value.
319 /// \param yylocation Its location.
320 virtual void yy_symbol_value_print_ (int yytype,
321 const semantic_type& yyvalue,
322 const location_type& yylocation);
323 /// \brief Report a symbol on the debug stream.
324 /// \param yytype The token type.
325 /// \param yyvalue Its semantic value.
326 /// \param yylocation Its location.
327 virtual void yy_symbol_print_ (int yytype,
328 const semantic_type& yyvalue,
329 const location_type& yylocation);
330 #endif
331
332 /// State numbers.
333 typedef int state_type;
334
335 /// Internal symbol numbers.
336 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
337 /* Tables. */
338 /// For a state, the index in \a yytable_ of its portion.
339 static const ]b4_int_type_for([b4_pact])[ yypact_[];
340 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
341
342 /// For a state, default rule to reduce.
343 /// Unless\a yytable_ specifies something else to do.
344 /// Zero means the default is an error.
345 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
346
347 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
348 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
349
350 /// What to do in a state.
351 /// \a yytable_[yypact_[s]]: what to do in state \a s.
352 /// - if positive, shift that token.
353 /// - if negative, reduce the rule which number is the opposite.
354 /// - if zero, do what YYDEFACT says.
355 static const ]b4_int_type_for([b4_table])[ yytable_[];
356 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
357
358 static const ]b4_int_type_for([b4_check])[ yycheck_[];
359
360 /// For a state, its accessing symbol.
361 static const ]b4_int_type_for([b4_stos])[ yystos_[];
362
363 /// For a rule, its LHS.
364 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
365 /// For a rule, its RHS length.
366 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
367
368 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
369 /// For a symbol, its name in clear.
370 static const char* const yytname_[];
371 #endif
372
373 #if YYERROR_VERBOSE
374 /// Convert the symbol name \a n to a form suitable for a diagnostic.
375 virtual std::string yytnamerr_ (const char *n);
376 #endif
377
378 #if YYDEBUG
379 /// A type to store symbol numbers and -1.
380 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
381 /// A `-1'-separated list of the rules' RHS.
382 static const rhs_number_type yyrhs_[];
383 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
384 static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
385 /// For each rule, its source line number.
386 static const ]b4_int_type_for([b4_rline])[ yyrline_[];
387 /// For each scanner token number, its symbol number.
388 static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
389 /// Report on the debug stream that the rule \a r is going to be reduced.
390 virtual void yy_reduce_print_ (int r);
391 /// Print the state stack on the debug stream.
392 virtual void yystack_print_ ();
393
394 /* Debugging. */
395 int yydebug_;
396 std::ostream* yycdebug_;
397 #endif
398
399 /// Convert a scanner token number \a t to a symbol number.
400 token_number_type yytranslate_ (int t);
401
402 /// \brief Reclaim the memory associated to a symbol.
403 /// \param yymsg Why this token is reclaimed.
404 /// \param yytype The symbol type.
405 /// \param yyvalue Its semantic value.
406 /// \param yylocation Its location.
407 inline void yydestruct_ (const char* yymsg,
408 int yytype,
409 semantic_type& yyvalue,
410 location_type& yylocation);
411
412 /// Element of the stack: a state and its attributes.
413 struct data_type
414 {
415 /// Default constructor.
416 data_type ();
417
418 /// Constructor.
419 data_type (state_type s, const semantic_type& v, const location_type& l);
420
421 /// The state.
422 state_type state;
423
424 /// The semantic value.
425 semantic_type value;
426
427 /// The location.
428 location_type location;
429 };
430
431 /// Stack type.
432 typedef stack<data_type> stack_type;
433
434 /// The stack.
435 stack_type yystack_;
436
437 /// Push a new state on the stack.
438 /// \warning the contents of \a v is stolen.
439 inline void yypush_ (state_type s,
440 semantic_type& v, const location_type& l);
441
442 /// Pop \a n symbols the three stacks.
443 inline void yypop_ (unsigned int n = 1);
444
445 /* Constants. */
446 static const int yyeof_;
447 /* LAST_ -- Last index in TABLE_. */
448 static const int yylast_;
449 static const int yynnts_;
450 static const int yyempty_;
451 static const int yyfinal_;
452 static const int yyterror_;
453 static const int yyerrcode_;
454 static const int yyntokens_;
455 static const unsigned int yyuser_token_number_max_;
456 static const token_number_type yyundef_token_;
457 ]b4_parse_param_vars[
458 };
459 ]b4_namespace_close[
460
461 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
462 [b4_token_defines(b4_tokens)
463
464 #ifndef YYSTYPE
465 /* Redirection for backward compatibility. */
466 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
467 #endif
468 ])
469 b4_percent_code_get([[provides]])[]dnl
470
471 [#endif /* ! defined PARSER_HEADER_H */]
472 ])dnl
473 @output(b4_parser_file_name@)
474 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
475 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
476 b4_percent_code_get([[top]])[]dnl
477 m4_if(b4_prefix, [yy], [],
478 [
479 // Take the name prefix into account.
480 #define yylex b4_prefix[]lex])[
481
482 /* First part of user declarations. */
483 ]b4_user_pre_prologue
484
485 b4_defines_if([[
486 #include "@basename(]b4_spec_defines_file[@)"]])[
487
488 /* User implementation prologue. */
489 ]b4_user_post_prologue
490 b4_percent_code_get[]dnl
491
492 [#ifndef YY_
493 # if YYENABLE_NLS
494 # if ENABLE_NLS
495 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
496 # define YY_(msgid) dgettext ("bison-runtime", msgid)
497 # endif
498 # endif
499 # ifndef YY_
500 # define YY_(msgid) msgid
501 # endif
502 #endif
503
504 /* Suppress unused-variable warnings by "using" E. */
505 #define YYUSE(e) ((void) (e))
506
507 /* Enable debugging if requested. */
508 #if YYDEBUG
509
510 /* A pseudo ostream that takes yydebug_ into account. */
511 # define YYCDEBUG if (yydebug_) (*yycdebug_)
512
513 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
514 do { \
515 if (yydebug_) \
516 { \
517 *yycdebug_ << Title << ' '; \
518 yy_symbol_print_ ((Type), (Value), (Location)); \
519 *yycdebug_ << std::endl; \
520 } \
521 } while (false)
522
523 # define YY_REDUCE_PRINT(Rule) \
524 do { \
525 if (yydebug_) \
526 yy_reduce_print_ (Rule); \
527 } while (false)
528
529 # define YY_STACK_PRINT() \
530 do { \
531 if (yydebug_) \
532 yystack_print_ (); \
533 } while (false)
534
535 #else /* !YYDEBUG */
536
537 # define YYCDEBUG if (false) std::cerr
538 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
539 # define YY_REDUCE_PRINT(Rule)
540 # define YY_STACK_PRINT()
541
542 #endif /* !YYDEBUG */
543
544 #define yyerrok (yyerrstatus_ = 0)
545 #define yyclearin (yychar = yyempty_)
546
547 #define YYACCEPT goto yyacceptlab
548 #define YYABORT goto yyabortlab
549 #define YYERROR goto yyerrorlab
550 #define YYRECOVERING() (!!yyerrstatus_)
551
552 ]b4_namespace_open[
553 #if YYERROR_VERBOSE
554
555 /* Return YYSTR after stripping away unnecessary quotes and
556 backslashes, so that it's suitable for yyerror. The heuristic is
557 that double-quoting is unnecessary unless the string contains an
558 apostrophe, a comma, or backslash (other than backslash-backslash).
559 YYSTR is taken from yytname. */
560 std::string
561 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
562 {
563 if (*yystr == '"')
564 {
565 std::string yyr = "";
566 char const *yyp = yystr;
567
568 for (;;)
569 switch (*++yyp)
570 {
571 case '\'':
572 case ',':
573 goto do_not_strip_quotes;
574
575 case '\\':
576 if (*++yyp != '\\')
577 goto do_not_strip_quotes;
578 /* Fall through. */
579 default:
580 yyr += *yyp;
581 break;
582
583 case '"':
584 return yyr;
585 }
586 do_not_strip_quotes: ;
587 }
588
589 return yystr;
590 }
591
592 #endif
593
594 /// Build a parser object.
595 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
596 :])[
597 #if YYDEBUG
598 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
599 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
600 #endif]b4_parse_param_cons[
601 {
602 }
603
604 ]b4_parser_class_name::~b4_parser_class_name[ ()
605 {
606 }
607
608 #if YYDEBUG
609 /*--------------------------------.
610 | Print this symbol on YYOUTPUT. |
611 `--------------------------------*/
612
613 inline void
614 ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
615 const semantic_type& yyvalue, const location_type& yylocation)
616 {
617 YYUSE (yylocation);
618 YYUSE (yyvalue);
619 switch (yytype)
620 {
621 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
622 [ default:
623 break;
624 }
625 }
626
627
628 void
629 ]b4_parser_class_name[::yy_symbol_print_ (int yytype,
630 const semantic_type& yyvalue, const location_type& yylocation)
631 {
632 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
633 << ' ' << yytname_[yytype] << " ("
634 << yylocation << ": ";
635 yy_symbol_value_print_ (yytype, yyvalue, yylocation);
636 *yycdebug_ << ')';
637 }
638 #endif
639
640 void
641 ]b4_parser_class_name[::yydestruct_ (const char* yymsg,
642 int yytype, semantic_type& yyvalue, location_type& yylocation)
643 {
644 YYUSE (yymsg);
645 YYUSE (yyvalue);
646 YYUSE (yylocation);
647
648 YY_SYMBOL_PRINT (yymsg, yytype, yyvalue, yylocation);
649
650 switch (yytype)
651 {
652 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
653 default:
654 break;
655 }
656 }
657
658 ]b4_parser_class_name[::data_type::data_type ()
659 : state()
660 , value()
661 , location()
662 {
663 }
664
665 ]b4_parser_class_name[::data_type::data_type (state_type s,
666 const semantic_type& v, const location_type& l)
667 : state(s)
668 , value(v)
669 , location(l)
670 {
671 }
672
673 void
674 ]b4_parser_class_name[::yypush_ (state_type s,
675 semantic_type& v, const location_type& l)
676 {
677 yystack_.push (data_type (s, v, l));
678 }
679
680 void
681 ]b4_parser_class_name[::yypop_ (unsigned int n)
682 {
683 yystack_.pop (n);
684 }
685
686 #if YYDEBUG
687 std::ostream&
688 ]b4_parser_class_name[::debug_stream () const
689 {
690 return *yycdebug_;
691 }
692
693 void
694 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
695 {
696 yycdebug_ = &o;
697 }
698
699
700 ]b4_parser_class_name[::debug_level_type
701 ]b4_parser_class_name[::debug_level () const
702 {
703 return yydebug_;
704 }
705
706 void
707 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
708 {
709 yydebug_ = l;
710 }
711 #endif
712
713 int
714 ]b4_parser_class_name[::parse ()
715 {
716 /// Lookahead and lookahead in internal form.
717 int yychar = yyempty_;
718 int yytoken = 0;
719
720 /* State. */
721 int yyn;
722 int yylen = 0;
723 int yystate = 0;
724
725 /* Error handling. */
726 int yynerrs_ = 0;
727 int yyerrstatus_ = 0;
728
729 /// Semantic value of the lookahead.
730 semantic_type yylval;
731 /// Location of the lookahead.
732 location_type yylloc;
733 /// The locations where the error started and ended.
734 data_type yyerror_range[2];
735
736 /// $$.
737 semantic_type yyval;
738 /// @@$.
739 location_type yyloc;
740
741 int yyresult;
742
743 YYCDEBUG << "Starting parse" << std::endl;
744
745 ]m4_ifdef([b4_initial_action], [
746 m4_pushdef([b4_at_dollar], [yylloc])dnl
747 m4_pushdef([b4_dollar_dollar], [yylval])dnl
748 /* User initialization code. */
749 b4_user_initial_action
750 m4_popdef([b4_dollar_dollar])dnl
751 m4_popdef([b4_at_dollar])])dnl
752
753 [ /* Initialize the stack. The initial state will be set in
754 yynewstate, since the latter expects the semantical and the
755 location values to have been already stored, initialize these
756 stacks with a primary value. */
757 yystack_ = stack_type (0);
758 yypush_ (yystate, yylval, yylloc);
759
760 // A new state was pushed on the stack.
761 // Invariant: yystate == yystack_[0].state, i.e.,
762 // yystate was just pushed onto the state stack.
763 yynewstate:
764 YYCDEBUG << "Entering state " << yystate << std::endl;
765
766 /* Accept? */
767 if (yystate == yyfinal_)
768 goto yyacceptlab;
769
770 goto yybackup;
771
772 /* Backup. */
773 yybackup:
774
775 /* Try to take a decision without lookahead. */
776 yyn = yypact_[yystate];
777 if (yyn == yypact_ninf_)
778 goto yydefault;
779
780 /* Read a lookahead token. */
781 if (yychar == yyempty_)
782 {
783 YYCDEBUG << "Reading a token: ";
784 yychar = ]b4_c_function_call([yylex], [int],
785 [[YYSTYPE*], [&yylval]][]dnl
786 b4_locations_if([, [[location*], [&yylloc]]])dnl
787 m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
788 }
789
790
791 /* Convert token to internal form. */
792 if (yychar <= yyeof_)
793 {
794 yychar = yytoken = yyeof_;
795 YYCDEBUG << "Now at end of input." << std::endl;
796 }
797 else
798 {
799 yytoken = yytranslate_ (yychar);
800 YY_SYMBOL_PRINT ("Next token is", yytoken, yylval, yylloc);
801 }
802
803 /* If the proper action on seeing token YYTOKEN is to reduce or to
804 detect an error, take that action. */
805 yyn += yytoken;
806 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
807 goto yydefault;
808
809 /* Reduce or error. */
810 yyn = yytable_[yyn];
811 if (yyn <= 0)
812 {
813 if (yyn == 0 || yyn == yytable_ninf_)
814 goto yyerrlab;
815 yyn = -yyn;
816 goto yyreduce;
817 }
818
819 /* Shift the lookahead token. */
820 YY_SYMBOL_PRINT ("Shifting", yytoken, yylval, yylloc);
821
822 /* Discard the token being shifted. */
823 yychar = yyempty_;
824
825 /* Count tokens shifted since error; after three, turn off error
826 status. */
827 if (yyerrstatus_)
828 --yyerrstatus_;
829
830 yystate = yyn;
831 yypush_ (yystate, yylval, yylloc);
832 goto yynewstate;
833
834 /*-----------------------------------------------------------.
835 | yydefault -- do the default action for the current state. |
836 `-----------------------------------------------------------*/
837 yydefault:
838 yyn = yydefact_[yystate];
839 if (yyn == 0)
840 goto yyerrlab;
841 goto yyreduce;
842
843 /*-----------------------------.
844 | yyreduce -- Do a reduction. |
845 `-----------------------------*/
846 yyreduce:
847 yylen = yyr2_[yyn];]b4_variant_if([
848 /* Variants are always initialized to an empty instance of the
849 correct type. The default $$=$1 rule is NOT applied when using
850 variants */
851 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yyval], [build])[],[
852 /* If YYLEN is nonzero, implement the default value of the action:
853 `$$ = $1'. Otherwise, use the top of the stack.
854
855 Otherwise, the following line sets YYVAL to garbage.
856 This behavior is undocumented and Bison
857 users should not rely upon it. */
858 if (yylen)
859 yyval = yystack_@{yylen - 1@}.value;
860 else
861 yyval = yystack_@{0@}.value;])[
862
863 {
864 slice<data_type, stack_type> slice (yystack_, yylen);
865 YYLLOC_DEFAULT (yyloc, slice, yylen);
866 }
867 YY_REDUCE_PRINT (yyn);
868 switch (yyn)
869 {
870 ]b4_user_actions[
871 default:
872 break;
873 }
874 YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], yyval, yyloc);
875
876 yypop_ (yylen);
877 yylen = 0;
878 YY_STACK_PRINT ();
879
880 /* Shift the result of the reduction. */
881 yyn = yyr1_[yyn];
882 yystate = yypgoto_[yyn - yyntokens_] + yystack_[0].state;
883 if (0 <= yystate && yystate <= yylast_
884 && yycheck_[yystate] == yystack_[0].state)
885 yystate = yytable_[yystate];
886 else
887 yystate = yydefgoto_[yyn - yyntokens_];
888 yypush_ (yystate, yyval, yyloc);
889 goto yynewstate;
890
891 /*------------------------------------.
892 | yyerrlab -- here on detecting error |
893 `------------------------------------*/
894 yyerrlab:
895 /* If not already recovering from an error, report this error. */
896 if (!yyerrstatus_)
897 {
898 ++yynerrs_;
899 error (yylloc, yysyntax_error_ (yystate]dnl
900 b4_error_verbose_if([, yytoken])[));
901 }
902
903 yyerror_range[0].location = yylloc;
904 if (yyerrstatus_ == 3)
905 {
906 /* If just tried and failed to reuse lookahead token after an
907 error, discard it. */
908
909 if (yychar <= yyeof_)
910 {
911 /* Return failure if at end of input. */
912 if (yychar == yyeof_)
913 YYABORT;
914 }
915 else
916 {
917 yydestruct_ ("Error: discarding", yytoken, yylval, yylloc);
918 yychar = yyempty_;
919 }
920 }
921
922 /* Else will try to reuse lookahead token after shifting the error
923 token. */
924 goto yyerrlab1;
925
926
927 /*---------------------------------------------------.
928 | yyerrorlab -- error raised explicitly by YYERROR. |
929 `---------------------------------------------------*/
930 yyerrorlab:
931
932 /* Pacify compilers like GCC when the user code never invokes
933 YYERROR and the label yyerrorlab therefore never appears in user
934 code. */
935 if (false)
936 goto yyerrorlab;
937
938 yyerror_range[0].location = yystack_[yylen - 1].location;
939 /* Do not reclaim the symbols of the rule which action triggered
940 this YYERROR. */
941 yypop_ (yylen);
942 yylen = 0;
943 yystate = yystack_[0].state;
944 goto yyerrlab1;
945
946 /*-------------------------------------------------------------.
947 | yyerrlab1 -- common code for both syntax error and YYERROR. |
948 `-------------------------------------------------------------*/
949 yyerrlab1:
950 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
951
952 for (;;)
953 {
954 yyn = yypact_[yystate];
955 if (yyn != yypact_ninf_)
956 {
957 yyn += yyterror_;
958 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
959 {
960 yyn = yytable_[yyn];
961 if (0 < yyn)
962 break;
963 }
964 }
965
966 // Pop the current state because it cannot handle the error token.
967 if (yystack_.size () == 1)
968 YYABORT;
969
970 yyerror_range[0].location = yystack_[0].location;
971 yydestruct_ ("Error: popping",
972 yystos_[yystate],
973 yystack_[0].value, yystack_[0].location);
974 yypop_ ();
975 yystate = yystack_[0].state;
976 YY_STACK_PRINT ();
977 }
978
979 yyerror_range[1].location = yylloc;
980 // Using YYLLOC is tempting, but would change the location of
981 // the lookahead. YYLOC is available though.
982 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
983
984 /* Shift the error token. */
985 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
986 yystack_[0].value, yystack_[0].location);
987
988 yystate = yyn;
989 yypush_ (yystate, yylval, yyloc);
990 goto yynewstate;
991
992 /* Accept. */
993 yyacceptlab:
994 yyresult = 0;
995 goto yyreturn;
996
997 /* Abort. */
998 yyabortlab:
999 yyresult = 1;
1000 goto yyreturn;
1001
1002 yyreturn:
1003 if (yychar != yyempty_)
1004 yydestruct_ ("Cleanup: discarding lookahead", yytoken, yylval, yylloc);
1005
1006 /* Do not reclaim the symbols of the rule which action triggered
1007 this YYABORT or YYACCEPT. */
1008 yypop_ (yylen);
1009 while (yystack_.size () != 1)
1010 {
1011 yydestruct_ ("Cleanup: popping",
1012 yystos_[yystack_[0].state],
1013 yystack_[0].value, yystack_[0].location);
1014 yypop_ ();
1015 }
1016
1017 return yyresult;
1018 }
1019
1020 // Generate an error message.
1021 std::string
1022 ]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl
1023 b4_error_verbose_if([, int tok])[)
1024 {
1025 std::string res;
1026 YYUSE (yystate);
1027 #if YYERROR_VERBOSE
1028 int yyn = yypact_[yystate];
1029 if (yypact_ninf_ < yyn && yyn <= yylast_)
1030 {
1031 /* Start YYX at -YYN if negative to avoid negative indexes in
1032 YYCHECK. */
1033 int yyxbegin = yyn < 0 ? -yyn : 0;
1034
1035 /* Stay within bounds of both yycheck and yytname. */
1036 int yychecklim = yylast_ - yyn + 1;
1037 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1038 int count = 0;
1039 for (int x = yyxbegin; x < yyxend; ++x)
1040 if (yycheck_[x + yyn] == x && x != yyterror_)
1041 ++count;
1042
1043 // FIXME: This method of building the message is not compatible
1044 // with internationalization. It should work like yacc.c does it.
1045 // That is, first build a string that looks like this:
1046 // "syntax error, unexpected %s or %s or %s"
1047 // Then, invoke YY_ on this string.
1048 // Finally, use the string as a format to output
1049 // yytname_[tok], etc.
1050 // Until this gets fixed, this message appears in English only.
1051 res = "syntax error, unexpected ";
1052 res += yytnamerr_ (yytname_[tok]);
1053 if (count < 5)
1054 {
1055 count = 0;
1056 for (int x = yyxbegin; x < yyxend; ++x)
1057 if (yycheck_[x + yyn] == x && x != yyterror_)
1058 {
1059 res += (!count++) ? ", expecting " : " or ";
1060 res += yytnamerr_ (yytname_[x]);
1061 }
1062 }
1063 }
1064 else
1065 #endif
1066 res = YY_("syntax error");
1067 return res;
1068 }
1069
1070
1071 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1072 STATE-NUM. */
1073 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1074 const ]b4_int_type_for([b4_pact])[
1075 ]b4_parser_class_name[::yypact_[] =
1076 {
1077 ]b4_pact[
1078 };
1079
1080 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1081 doesn't specify something else to do. Zero means the default is an
1082 error. */
1083 const ]b4_int_type_for([b4_defact])[
1084 ]b4_parser_class_name[::yydefact_[] =
1085 {
1086 ]b4_defact[
1087 };
1088
1089 /* YYPGOTO[NTERM-NUM]. */
1090 const ]b4_int_type_for([b4_pgoto])[
1091 ]b4_parser_class_name[::yypgoto_[] =
1092 {
1093 ]b4_pgoto[
1094 };
1095
1096 /* YYDEFGOTO[NTERM-NUM]. */
1097 const ]b4_int_type_for([b4_defgoto])[
1098 ]b4_parser_class_name[::yydefgoto_[] =
1099 {
1100 ]b4_defgoto[
1101 };
1102
1103 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1104 positive, shift that token. If negative, reduce the rule which
1105 number is the opposite. If zero, do what YYDEFACT says. */
1106 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1107 const ]b4_int_type_for([b4_table])[
1108 ]b4_parser_class_name[::yytable_[] =
1109 {
1110 ]b4_table[
1111 };
1112
1113 /* YYCHECK. */
1114 const ]b4_int_type_for([b4_check])[
1115 ]b4_parser_class_name[::yycheck_[] =
1116 {
1117 ]b4_check[
1118 };
1119
1120 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1121 symbol of state STATE-NUM. */
1122 const ]b4_int_type_for([b4_stos])[
1123 ]b4_parser_class_name[::yystos_[] =
1124 {
1125 ]b4_stos[
1126 };
1127
1128 #if YYDEBUG
1129 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1130 to YYLEX-NUM. */
1131 const ]b4_int_type_for([b4_toknum])[
1132 ]b4_parser_class_name[::yytoken_number_[] =
1133 {
1134 ]b4_toknum[
1135 };
1136 #endif
1137
1138 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1139 const ]b4_int_type_for([b4_r1])[
1140 ]b4_parser_class_name[::yyr1_[] =
1141 {
1142 ]b4_r1[
1143 };
1144
1145 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1146 const ]b4_int_type_for([b4_r2])[
1147 ]b4_parser_class_name[::yyr2_[] =
1148 {
1149 ]b4_r2[
1150 };
1151
1152 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1153 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1154 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1155 const char*
1156 const ]b4_parser_class_name[::yytname_[] =
1157 {
1158 ]b4_tname[
1159 };
1160 #endif
1161
1162 #if YYDEBUG
1163 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1164 const ]b4_parser_class_name[::rhs_number_type
1165 ]b4_parser_class_name[::yyrhs_[] =
1166 {
1167 ]b4_rhs[
1168 };
1169
1170 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1171 YYRHS. */
1172 const ]b4_int_type_for([b4_prhs])[
1173 ]b4_parser_class_name[::yyprhs_[] =
1174 {
1175 ]b4_prhs[
1176 };
1177
1178 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1179 const ]b4_int_type_for([b4_rline])[
1180 ]b4_parser_class_name[::yyrline_[] =
1181 {
1182 ]b4_rline[
1183 };
1184
1185 // Print the state stack on the debug stream.
1186 void
1187 ]b4_parser_class_name[::yystack_print_ ()
1188 {
1189 *yycdebug_ << "Stack now";
1190 for (stack_type::const_iterator
1191 i = yystack_.begin (),
1192 i_end = yystack_.end ();
1193 i != i_end; ++i)
1194 *yycdebug_ << ' ' << i->state;
1195 *yycdebug_ << std::endl;
1196 }
1197
1198 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1199 void
1200 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1201 {
1202 unsigned int yylno = yyrline_[yyrule];
1203 int yynrhs = yyr2_[yyrule];
1204 /* Print the symbols being reduced, and their result. */
1205 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1206 << " (line " << yylno << "):" << std::endl;
1207 /* The symbols being reduced. */
1208 for (int yyi = 0; yyi < yynrhs; yyi++)
1209 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1210 yyrhs_[yyprhs_[yyrule] + yyi],
1211 ]b4_rhs_value(yynrhs, yyi + 1)[,
1212 ]b4_rhs_location(yynrhs, yyi + 1)[);
1213 }
1214 #endif // YYDEBUG
1215
1216 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1217 ]b4_parser_class_name[::token_number_type
1218 ]b4_parser_class_name[::yytranslate_ (int t)
1219 {
1220 static
1221 const token_number_type
1222 translate_table[] =
1223 {
1224 ]b4_translate[
1225 };
1226 if ((unsigned int) t <= yyuser_token_number_max_)
1227 return translate_table[t];
1228 else
1229 return yyundef_token_;
1230 }
1231
1232 const int ]b4_parser_class_name[::yyeof_ = 0;
1233 const int ]b4_parser_class_name[::yylast_ = ]b4_last[;
1234 const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1235 const int ]b4_parser_class_name[::yyempty_ = -2;
1236 const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1237 const int ]b4_parser_class_name[::yyterror_ = 1;
1238 const int ]b4_parser_class_name[::yyerrcode_ = 256;
1239 const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1240
1241 const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1242 const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
1243
1244 ]b4_namespace_close[
1245
1246 ]b4_epilogue
1247 dnl
1248 @output(b4_dir_prefix[]stack.hh@)
1249 b4_copyright([Stack handling for Bison parsers in C++],
1250 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
1251
1252 #ifndef BISON_STACK_HH
1253 # define BISON_STACK_HH
1254
1255 #include <deque>
1256
1257 ]b4_namespace_open[
1258 template <class T, class S = std::deque<T> >
1259 class stack
1260 {
1261 public:
1262
1263 // Hide our reversed order.
1264 typedef typename S::reverse_iterator iterator;
1265 typedef typename S::const_reverse_iterator const_iterator;
1266
1267 stack () : seq_ ()
1268 {
1269 }
1270
1271 stack (unsigned int n) : seq_ (n)
1272 {
1273 }
1274
1275 inline
1276 T&
1277 operator [] (unsigned int i)
1278 {
1279 return seq_[i];
1280 }
1281
1282 inline
1283 const T&
1284 operator [] (unsigned int i) const
1285 {
1286 return seq_[i];
1287 }
1288
1289 inline
1290 void
1291 push (const T& t)
1292 {
1293 seq_.push_front (t);
1294 }
1295
1296 inline
1297 void
1298 pop (unsigned int n = 1)
1299 {
1300 for (; n; --n)
1301 seq_.pop_front ();
1302 }
1303
1304 inline
1305 typename S::size_type
1306 size () const
1307 {
1308 return seq_.size ();
1309 }
1310
1311 inline const_iterator begin () const { return seq_.rbegin (); }
1312 inline const_iterator end () const { return seq_.rend (); }
1313
1314 private:
1315 /// The wrapped container.
1316 S seq_;
1317 };
1318
1319 /// Present a slice of the top of a stack.
1320 template <class T, class S = stack<T> >
1321 class slice
1322 {
1323 public:
1324
1325 slice (const S& stack,
1326 unsigned int range) : stack_ (stack),
1327 range_ (range)
1328 {
1329 }
1330
1331 inline
1332 const T&
1333 operator [] (unsigned int i) const
1334 {
1335 return stack_[range_ - i];
1336 }
1337
1338 private:
1339
1340 const S& stack_;
1341 unsigned int range_;
1342 };
1343 ]b4_namespace_close[
1344
1345 #endif // not BISON_STACK_HH[]dnl
1346 ]
1347 m4_divert_pop(0)