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