1 # C++ skeleton for Bison
3 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 # Free Software Foundation, Inc.
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.
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.
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/>.
19 m4_include(b4_pkgdatadir
/[c
++.m4
])
21 # b4_table_define(TABLE-NAME, CONTENT)
22 # ------------------------------------
23 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
24 m4_define([b4_table_define
],
25 [const b4_int_type_for([$
2])
26 b4_parser_class_name::yy$
1_
[[]] =
32 # How the semantic value is extracted when using variants.
34 # b4_symbol_value(VAL, [TYPE])
35 # ----------------------------
36 m4_define([b4_symbol_value
],
43 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
44 # ----------------------------------------------------
45 m4_define([b4_assert_if
],
46 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
49 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
50 # --------------------------------------
51 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
53 m4_define([b4_rhs_value
],
54 [b4_symbol_value([yystack_@
{($
1) - ($
2)@
}.value
], [$
3])])
56 # b4_rhs_location(RULE-LENGTH, NUM)
57 # ---------------------------------
58 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
60 m4_define([b4_rhs_location
],
61 [yystack_@
{($
1) - ($
2)@
}.location
])
64 # b4_symbol_actions(FILENAME, LINENO,
65 # SYMBOL-TAG, SYMBOL-NUM,
66 # SYMBOL-ACTION, SYMBOL-TYPENAME)
67 # -------------------------------------------------
68 # Same as in C, but using references instead of pointers.
69 m4_define([b4_symbol_actions
],
70 [m4_pushdef([b4_dollar_dollar
],
71 [b4_symbol_value([yyvalue
], [$
6])])dnl
72 m4_pushdef([b4_at_dollar
], [yylocation
])dnl
74 b4_syncline([$
2], [$
1])
76 b4_syncline([@oline@
], [@ofile@
])
78 m4_popdef([b4_at_dollar
])dnl
79 m4_popdef([b4_dollar_dollar
])dnl
83 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
84 # ----------------------------------------------------------
85 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
86 m4_define([b4_symbol_action_
],
94 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
95 # ------------------------------------------------
96 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
98 m4_define([b4_symbol_variant
],
99 [m4_pushdef([b4_dollar_dollar
],
100 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
103 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
107 m4_popdef([b4_dollar_dollar
])dnl
111 # _b4_char_sizeof_counter
112 # -----------------------
113 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
114 m4_define([_b4_char_sizeof_counter
],
117 # _b4_char_sizeof_dummy
118 # ---------------------
119 # At each call return a new C++ identifier.
120 m4_define([_b4_char_sizeof_dummy
],
121 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
122 dummy
[]_b4_char_sizeof_counter
])
125 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
126 # -------------------------------------------------------
127 # To be mapped on the list of type names to produce:
129 # char dummy1[sizeof(type_name_1)];
130 # char dummy2[sizeof(type_name_2)];
132 # for defined type names.
133 # $3 is doubly-quoted, do not quote it again.
134 m4_define([b4_char_sizeof
],
137 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
141 m4_pushdef([b4_copyright_years
],
142 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
144 m4_define([b4_parser_class_name
],
145 [b4_percent_define_get([[parser_class_name]])])
147 # The header is mandatory.
149 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
151 # Backward compatibility.
152 m4_define([b4_location_constructors
])
153 m4_include(b4_pkgdatadir
/[location
.cc
])
155 # We do want M4 expansion after # for CPP macros.
159 [@
output(b4_spec_defines_file@
)@
160 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
161 dnl FIXME
: This is wrong
, we want computed header guards
.
163 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
165 #ifndef PARSER_HEADER_H
166 # define PARSER_HEADER_H
168 ]b4_percent_code_get([[requires]])[
170 ]b4_assert_if([#include <cassert>])[
180 /// A char[S] buffer to store and retrieve objects.
182 /// Sort of a variant, but does not keep track of the nature
183 /// of the stored data, since that knowledge is available
184 /// via the current state.
188 /// Whether something is contained.
191 /// Initially uninitialized.
196 /// Instantiate a \a T in here.
197 template <typename T
>
203 return *new (buffer
) T
;
206 /// Accessor to a built \a T.
207 template <typename T
>
212 return reinterpret_cast<T
&>(buffer
);
215 /// Const accessor to a built \a T (for %printer).
216 template <typename T
>
221 return reinterpret_cast<const T
&>(buffer
);
224 /// Swap the content with \a other.
225 template <typename T
>
227 swap(variant
<S
>& other
)
229 std::swap(as
<T
>(), other
.as
<T
>());
232 /// Assign the content of \a other to this.
233 /// Destroys \a other.
234 template <typename T
>
236 build(variant
<S
>& other
)
243 /// Destroy the stored \a T.
244 template <typename T
>
248 as
<T
>().~T();]b4_assert_if([
252 /// A buffer large enough to store any of the semantic values.
258 #include "location.hh"
260 /* Enabling traces. */
262 # define YYDEBUG ]b4_debug_flag[
265 /* Enabling verbose error messages. */
266 #ifdef YYERROR_VERBOSE
267 # undef YYERROR_VERBOSE
268 # define YYERROR_VERBOSE 1
270 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
273 /* Enabling the token table. */
274 #ifndef YYTOKEN_TABLE
275 # define YYTOKEN_TABLE ]b4_token_table[
278 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
279 If N is 0, then set CURRENT to the empty location which ends
280 the previous symbol: RHS[0] (always defined). */
282 #ifndef YYLLOC_DEFAULT
283 # define YYLLOC_DEFAULT(Current, Rhs, N) \
287 (Current).begin = (Rhs)[1].location.begin; \
288 (Current).end = (Rhs)[N].location.end; \
292 (Current).begin = (Current).end = (Rhs)[0].location.end; \
300 class ]b4_parser_class_name
[
305 [ /// An auxiliary type to compute the largest semantic type.
307 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
310 /// Symbol semantic values.
311 typedef variant
<sizeof(union_type
)> semantic_type
;],
312 [ /// Symbol semantic values.
314 [ union semantic_type
317 [m4_if(b4_tag_seen_flag
, 0,
318 [[ typedef int semantic_type
;]],
319 [[ typedef YYSTYPE semantic_type
;]])])])[
321 typedef YYSTYPE semantic_type
;
323 /// Symbol locations.
324 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
328 ]b4_token_enums(b4_tokens
)[
331 typedef token::yytokentype token_type
;
333 /// Build a parser object.
334 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
335 virtual ~]b4_parser_class_name
[ ();
338 /// \returns 0 iff parsing succeeded.
339 virtual int parse ();
342 /// The current debugging stream.
343 std::ostream
& debug_stream () const;
344 /// Set the current debugging stream.
345 void set_debug_stream (std::ostream
&);
347 /// Type for debugging levels.
348 typedef int debug_level_type
;
349 /// The current debugging level.
350 debug_level_type
debug_level () const;
351 /// Set the current debugging level.
352 void set_debug_level (debug_level_type l
);
356 /// Report a syntax error.
357 /// \param loc where the syntax error is found.
358 /// \param msg a description of the syntax error.
359 virtual void error (const location_type
& loc
, const std::string
& msg
);
361 /// Generate an error message.
362 /// \param state the state where the error occurred.
363 /// \param tok the lookahead token.
364 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
367 /// \brief Report a symbol value on the debug stream.
368 /// \param yytype The token type.
369 /// \param yyvalue Its semantic value.
370 /// \param yylocation Its location.
371 virtual void yy_symbol_value_print_ (int yytype
,
372 const semantic_type
& yyvalue
,
373 const location_type
& yylocation
);
374 /// \brief Report a symbol on the debug stream.
375 /// \param yytype The token type.
376 /// \param yyvalue Its semantic value.
377 /// \param yylocation Its location.
378 virtual void yy_symbol_print_ (int yytype
,
379 const semantic_type
& yyvalue
,
380 const location_type
& yylocation
);
384 typedef int state_type
;
386 /// Internal symbol numbers.
387 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
389 /// For a state, the index in \a yytable_ of its portion.
390 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
391 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
393 /// For a state, default rule to reduce.
394 /// Unless\a yytable_ specifies something else to do.
395 /// Zero means the default is an error.
396 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
398 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
399 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
401 /// What to do in a state.
402 /// \a yytable_[yypact_[s]]: what to do in state \a s.
403 /// - if positive, shift that token.
404 /// - if negative, reduce the rule which number is the opposite.
405 /// - if zero, do what YYDEFACT says.
406 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
407 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
409 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
411 /// For a state, its accessing symbol.
412 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
414 /// For a rule, its LHS.
415 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
416 /// For a rule, its RHS length.
417 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
419 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
420 /// For a symbol, its name in clear.
421 static const char* const yytname_
[];
425 /// Convert the symbol name \a n to a form suitable for a diagnostic.
426 virtual std::string
yytnamerr_ (const char *n
);
430 /// A `-1'-separated list of the rules' RHS.
431 static const ]b4_int_type_for([b4_rhs
])[ yyrhs_
[];
432 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
433 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
434 /// For each rule, its source line number.
435 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
436 /// For each scanner token number, its symbol number.
437 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
438 /// Report on the debug stream that the rule \a r is going to be reduced.
439 virtual void yy_reduce_print_ (int r
);
440 /// Print the state stack on the debug stream.
441 virtual void yystack_print_ ();
445 std::ostream
* yycdebug_
;
448 /// Convert a scanner token number \a t to a symbol number.
449 token_number_type
yytranslate_ (int t
);
451 /// \brief Reclaim the memory associated to a symbol.
452 /// \param yymsg Why this token is reclaimed.
453 /// If null, nothing is printed at all.
454 /// \param yytype The symbol type.
455 /// \param yyvalue Its semantic value.
456 /// \param yylocation Its location.
457 inline void yydestruct_ (const char* yymsg
,
459 semantic_type
& yyvalue
,
460 location_type
& yylocation
);
462 /// Element of the stack: a state and its attributes.
465 /// Default constructor.
469 data_type (state_type s
, const semantic_type
& v
, const location_type
& l
);
474 /// The semantic value.
478 location_type location
;
482 typedef stack
<data_type
> stack_type
;
487 /// Push a new state on the stack.
488 /// \param m a debug message to display
489 /// if null, no trace is output.
490 /// \param s the state entered
491 /// \param v semantic value
492 /// \param l location
493 /// \warning the contents of \a v is stolen.
494 inline void yypush_ (const char* m
, state_type s
,
495 semantic_type
& v
, const location_type
& l
);
497 /// Pop \a n symbols the three stacks.
498 inline void yypop_ (unsigned int n
= 1);
501 static const int yyeof_
;
502 /* LAST_ -- Last index in TABLE_. */
503 static const int yylast_
;
504 static const int yynnts_
;
505 static const int yyempty_
;
506 static const int yyfinal_
;
507 static const int yyterror_
;
508 static const int yyerrcode_
;
509 static const int yyntokens_
;
510 static const unsigned int yyuser_token_number_max_
;
511 static const token_number_type yyundef_token_
;
512 ]b4_parse_param_vars
[
516 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
517 [b4_token_defines(b4_tokens
)
520 /* Redirection for backward compatibility. */
521 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
524 b4_percent_code_get([[provides]])[]dnl
526 [#endif /* ! defined PARSER_HEADER_H */]
528 @
output(b4_parser_file_name@
)@
529 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
530 b4_percent_code_get([[top]])[]dnl
531 m4_if(b4_prefix
, [yy
], [],
533 // Take the name prefix into account.
534 #define yylex b4_prefix[]lex])[
536 /* First part of user declarations. */
537 ]b4_user_pre_prologue
540 #include "@basename(]b4_spec_defines_file[@)"]])[
542 /* User implementation prologue. */
543 ]b4_user_post_prologue
544 b4_percent_code_get
[]dnl
549 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
550 # define YY_(msgid) dgettext ("bison-runtime", msgid)
554 # define YY_(msgid) msgid
558 /* Suppress unused-variable warnings by "using" E. */
559 #define YYUSE(e) ((void) (e))
561 /* Enable debugging if requested. */
564 /* A pseudo ostream that takes yydebug_ into account. */
565 # define YYCDEBUG if (yydebug_) (*yycdebug_)
567 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
571 *yycdebug_ << Title << ' '; \
572 yy_symbol_print_ ((Type), (Value), (Location)); \
573 *yycdebug_ << std::endl; \
577 # define YY_REDUCE_PRINT(Rule) \
580 yy_reduce_print_ (Rule); \
583 # define YY_STACK_PRINT() \
591 # define YYCDEBUG if (false) std::cerr
592 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) static_cast<void>(0)
593 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
594 # define YY_STACK_PRINT() static_cast<void>(0)
596 #endif /* !YYDEBUG */
598 #define yyerrok (yyerrstatus_ = 0)
599 #define yyclearin (yychar = yyempty_)
601 #define YYACCEPT goto yyacceptlab
602 #define YYABORT goto yyabortlab
603 #define YYERROR goto yyerrorlab
604 #define YYRECOVERING() (!!yyerrstatus_)
609 /* Return YYSTR after stripping away unnecessary quotes and
610 backslashes, so that it's suitable for yyerror. The heuristic is
611 that double-quoting is unnecessary unless the string contains an
612 apostrophe, a comma, or backslash (other than backslash-backslash).
613 YYSTR is taken from yytname. */
615 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
619 std::string yyr
= "";
620 char const *yyp
= yystr
;
627 goto do_not_strip_quotes
;
631 goto do_not_strip_quotes
;
640 do_not_strip_quotes
: ;
648 /// Build a parser object.
649 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
652 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
653 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
654 #endif]b4_parse_param_cons[
658 ]b4_parser_class_name::~b4_parser_class_name
[ ()
663 /*--------------------------------.
664 | Print this symbol on YYOUTPUT. |
665 `--------------------------------*/
668 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
669 const semantic_type
& yyvalue
, const location_type
& yylocation
)
675 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
683 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
684 const semantic_type
& yyvalue
, const location_type
& yylocation
)
686 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
687 << ' ' << yytname_
[yytype
] << " ("
688 << yylocation
<< ": ";
689 yy_symbol_value_print_ (yytype
, yyvalue
, yylocation
);
695 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
696 int yytype
, semantic_type
& yyvalue
, location_type
& yylocation
)
703 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvalue
, yylocation
);
708 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
714 b4_symbol_variant([[yytype]], [[yyvalue]], [[destroy]])])[
717 ]b4_parser_class_name
[::data_type::data_type ()
724 ]b4_parser_class_name
[::data_type::data_type (state_type s
,
725 const semantic_type
& v
, const location_type
& l
)
733 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
734 semantic_type
& v
, const location_type
& l
)
737 YY_SYMBOL_PRINT (m
, yystos_
[s
], v
, l
);
739 [[ yystack_
.push (data_type (s
, semantic_type(), l
));
740 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]], [build
], [v
])],
741 [ yystack_
.push (data_type (s
, v
, l
));])[
745 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
752 ]b4_parser_class_name
[::debug_stream () const
758 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
764 ]b4_parser_class_name
[::debug_level_type
765 ]b4_parser_class_name
[::debug_level () const
771 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
778 ]b4_parser_class_name
[::parse ()
780 /// Lookahead and lookahead in internal form.
781 int yychar
= yyempty_
;
789 /* Error handling. */
791 int yyerrstatus_
= 0;
793 /// Semantic value of the lookahead.
794 semantic_type yylval
;
795 /// Location of the lookahead.
796 location_type yylloc
;
797 /// The locations where the error started and ended.
798 data_type yyerror_range
[2];
807 YYCDEBUG
<< "Starting parse" << std::endl
;
809 ]m4_ifdef([b4_initial_action
], [
810 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
811 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
812 /* User initialization code. */
813 b4_user_initial_action
814 m4_popdef([b4_dollar_dollar
])dnl
815 m4_popdef([b4_at_dollar
])])dnl
817 [ /* Initialize the stack. The initial state will be set in
818 yynewstate, since the latter expects the semantical and the
819 location values to have been already stored, initialize these
820 stacks with a primary value. */
821 yystack_
= stack_type (0);
822 yypush_ (0, yystate
, yylval
, yylloc
);
824 // A new state was pushed on the stack.
825 // Invariant: yystate == yystack_[0].state, i.e.,
826 // yystate was just pushed onto the state stack.
828 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
831 if (yystate
== yyfinal_
)
839 /* Try to take a decision without lookahead. */
840 yyn
= yypact_
[yystate
];
841 if (yyn
== yypact_ninf_
)
844 /* Read a lookahead token. */
845 if (yychar
== yyempty_
)
847 YYCDEBUG
<< "Reading a token: ";
848 yychar
= ]b4_c_function_call([yylex
], [int],
849 [[YYSTYPE
*], [&yylval
]][]dnl
850 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
851 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
855 /* Convert token to internal form. */
856 if (yychar
<= yyeof_
)
858 yychar
= yytoken
= yyeof_
;
859 YYCDEBUG
<< "Now at end of input." << std::endl
;
863 yytoken
= yytranslate_ (yychar
);
864 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylval
, yylloc
);
867 /* If the proper action on seeing token YYTOKEN is to reduce or to
868 detect an error, take that action. */
870 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
873 /* Reduce or error. */
877 if (yyn
== 0 || yyn
== yytable_ninf_
)
883 /* Discard the token being shifted. */
886 /* Count tokens shifted since error; after three, turn off error
891 /* Shift the lookahead token. */
893 yypush_ ("Shifting", yystate
, yylval
, yylloc
);
896 /*-----------------------------------------------------------.
897 | yydefault -- do the default action for the current state. |
898 `-----------------------------------------------------------*/
900 yyn
= yydefact_
[yystate
];
905 /*-----------------------------.
906 | yyreduce -- Do a reduction. |
907 `-----------------------------*/
909 yylen
= yyr2_
[yyn
];]b4_variant_if([
910 /* Variants are always initialized to an empty instance of the
911 correct type. The default $$=$1 rule is NOT applied when using
913 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yyval
], [build
])[],[
914 /* If YYLEN is nonzero, implement the default value of the action:
915 `$$ = $1'. Otherwise, use the top of the stack.
917 Otherwise, the following line sets YYVAL to garbage.
918 This behavior is undocumented and Bison
919 users should not rely upon it. */
921 yyval
= yystack_@
{yylen
- 1@
}.value
;
923 yyval
= yystack_@
{0@
}.value
;])[
925 // Compute the default @@$.
927 slice
<data_type
, stack_type
> slice (yystack_
, yylen
);
928 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
931 // Perform the reduction.
932 YY_REDUCE_PRINT (yyn
);
939 YY_SYMBOL_PRINT ("-> $$ =", yyr1_
[yyn
], yyval
, yyloc
);
941 // Destroy the lhs symbols.
942 for (int i
= 0; i
< yylen
; ++i
)
943 // Destroy a variant which value may have be swapped with yyval.
944 // The value of yyval (hence maybe one of these lhs symbols)
945 // depends on what does the default contruction for this type.
946 // In the case of pointers for instance, nothing is done, so the
947 // value is junk. Therefore do not try to report the content in
948 // the debug trace, it's junk. Hence yymsg = 0. Besides, that
949 // keeps exactly the same traces as with the other Bison
952 yystos_
[yystack_
[i
].state
],
953 yystack_
[i
].value
, yystack_
[i
].location
);]])[
959 /* Shift the result of the reduction. */
961 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[0].state
;
962 if (0 <= yystate
&& yystate
<= yylast_
963 && yycheck_
[yystate
] == yystack_
[0].state
)
964 yystate
= yytable_
[yystate
];
966 yystate
= yydefgoto_
[yyn
- yyntokens_
];
967 yypush_ (0, yystate
, yyval
, yyloc
);
970 /*------------------------------------.
971 | yyerrlab -- here on detecting error |
972 `------------------------------------*/
974 /* If not already recovering from an error, report this error. */
978 error (yylloc
, yysyntax_error_ (yystate
, yytoken
));
981 yyerror_range
[0].location
= yylloc
;
982 if (yyerrstatus_
== 3)
984 /* If just tried and failed to reuse lookahead token after an
985 error, discard it. */
987 if (yychar
<= yyeof_
)
989 /* Return failure if at end of input. */
990 if (yychar
== yyeof_
)
995 yydestruct_ ("Error: discarding", yytoken
, yylval
, yylloc
);
1000 /* Else will try to reuse lookahead token after shifting the error
1005 /*---------------------------------------------------.
1006 | yyerrorlab -- error raised explicitly by YYERROR. |
1007 `---------------------------------------------------*/
1010 /* Pacify compilers like GCC when the user code never invokes
1011 YYERROR and the label yyerrorlab therefore never appears in user
1016 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1017 /* Do not reclaim the symbols of the rule which action triggered
1021 yystate
= yystack_
[0].state
;
1024 /*-------------------------------------------------------------.
1025 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1026 `-------------------------------------------------------------*/
1028 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1032 yyn
= yypact_
[yystate
];
1033 if (yyn
!= yypact_ninf_
)
1036 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1038 yyn
= yytable_
[yyn
];
1044 // Pop the current state because it cannot handle the error token.
1045 if (yystack_
.size () == 1)
1048 yyerror_range
[0].location
= yystack_
[0].location
;
1049 yydestruct_ ("Error: popping",
1051 yystack_
[0].value
, yystack_
[0].location
);
1053 yystate
= yystack_
[0].state
;
1057 yyerror_range
[1].location
= yylloc
;
1058 // Using YYLLOC is tempting, but would change the location of
1059 // the lookahead. YYLOC is available though.
1060 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
1062 /* Shift the error token. */
1064 yypush_ ("Shifting", yystate
, yylval
, yyloc
);
1078 if (yychar
!= yyempty_
)
1079 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, yylval
, yylloc
);
1081 /* Do not reclaim the symbols of the rule which action triggered
1082 this YYABORT or YYACCEPT. */
1084 while (yystack_
.size () != 1)
1086 yydestruct_ ("Cleanup: popping",
1087 yystos_
[yystack_
[0].state
],
1088 yystack_
[0].value
, yystack_
[0].location
);
1095 // Generate an error message.
1097 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1098 b4_error_verbose_if([ tok
])[)
1103 int yyn
= yypact_
[yystate
];
1104 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1106 /* Start YYX at -YYN if negative to avoid negative indexes in
1108 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1110 /* Stay within bounds of both yycheck and yytname. */
1111 int yychecklim
= yylast_
- yyn
+ 1;
1112 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1114 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1115 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1118 // FIXME: This method of building the message is not compatible
1119 // with internationalization. It should work like yacc.c does it.
1120 // That is, first build a string that looks like this:
1121 // "syntax error, unexpected %s or %s or %s"
1122 // Then, invoke YY_ on this string.
1123 // Finally, use the string as a format to output
1124 // yytname_[tok], etc.
1125 // Until this gets fixed, this message appears in English only.
1126 res
= "syntax error, unexpected ";
1127 res
+= yytnamerr_ (yytname_
[tok
]);
1131 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1132 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1134 res
+= (!count
++) ? ", expecting " : " or ";
1135 res
+= yytnamerr_ (yytname_
[x
]);
1141 res
= YY_("syntax error");
1146 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1148 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1149 ]b4_table_define([pact
], [b4_pact
])[;
1151 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1152 doesn't specify something else to do. Zero means the default is an
1154 ]b4_table_define([defact
], [b4_defact
])[;
1156 /* YYPGOTO[NTERM-NUM]. */
1157 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1159 /* YYDEFGOTO[NTERM-NUM]. */
1160 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1162 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1163 positive, shift that token. If negative, reduce the rule which
1164 number is the opposite. If zero, do what YYDEFACT says. */
1165 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1166 ]b4_table_define([table
], [b4_table
])[;
1169 ]b4_table_define([check
], [b4_check
])[;
1171 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1172 symbol of state STATE-NUM. */
1173 ]b4_table_define([stos
], [b4_stos
])[;
1176 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1178 ]b4_table_define([token_number
], [b4_toknum
])[;
1181 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1182 ]b4_table_define([r1
], [b4_r1
])[;
1184 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1185 ]b4_table_define([r2
], [b4_r2
])[;
1187 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1188 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1189 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1191 const ]b4_parser_class_name
[::yytname_
[] =
1198 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1199 ]b4_table_define([rhs
], [b4_rhs
])[;
1201 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1203 ]b4_table_define([prhs
], [b4_prhs
])[;
1205 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1206 ]b4_table_define([rline
], [b4_rline
])[;
1208 // Print the state stack on the debug stream.
1210 ]b4_parser_class_name
[::yystack_print_ ()
1212 *yycdebug_
<< "Stack now";
1213 for (stack_type::const_iterator
1214 i
= yystack_
.begin (),
1215 i_end
= yystack_
.end ();
1217 *yycdebug_
<< ' ' << i
->state
;
1218 *yycdebug_
<< std::endl
;
1221 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1223 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1225 unsigned int yylno
= yyrline_
[yyrule
];
1226 int yynrhs
= yyr2_
[yyrule
];
1227 /* Print the symbols being reduced, and their result. */
1228 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1229 << " (line " << yylno
<< "):" << std::endl
;
1230 /* The symbols being reduced. */
1231 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1232 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1233 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1234 ]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1235 ]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1239 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1240 ]b4_parser_class_name
[::token_number_type
1241 ]b4_parser_class_name
[::yytranslate_ (int t
)
1244 const token_number_type
1249 if ((unsigned int) t
<= yyuser_token_number_max_
)
1250 return translate_table
[t
];
1252 return yyundef_token_
;
1255 const int ]b4_parser_class_name
[::yyeof_
= 0;
1256 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1257 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1258 const int ]b4_parser_class_name
[::yyempty_
= -2;
1259 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1260 const int ]b4_parser_class_name
[::yyterror_
= 1;
1261 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1262 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1264 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1265 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1267 ]b4_namespace_close
[
1270 @
output(b4_dir_prefix
[]stack
.hh@
)@
1271 b4_copyright([Stack handling
for Bison parsers in C
++])[
1273 #ifndef BISON_STACK_HH
1274 # define BISON_STACK_HH
1279 template <class T
, class S
= std::deque
<T
> >
1284 // Hide our reversed order.
1285 typedef typename
S::reverse_iterator iterator
;
1286 typedef typename
S::const_reverse_iterator const_iterator
;
1292 stack (unsigned int n
) : seq_ (n
)
1298 operator [] (unsigned int i
)
1305 operator [] (unsigned int i
) const
1314 seq_
.push_front (t
);
1319 pop (unsigned int n
= 1)
1326 typename
S::size_type
1329 return seq_
.size ();
1332 inline const_iterator
begin () const { return seq_
.rbegin (); }
1333 inline const_iterator
end () const { return seq_
.rend (); }
1336 /// The wrapped container.
1340 /// Present a slice of the top of a stack.
1341 template <class T
, class S
= stack
<T
> >
1346 slice (const S
& stack
,
1347 unsigned int range
) : stack_ (stack
),
1354 operator [] (unsigned int i
) const
1356 return stack_
[range_
- i
];
1362 unsigned int range_
;
1364 ]b4_namespace_close
[
1366 #endif // not BISON_STACK_HH[]dnl
1369 m4_popdef([b4_copyright_years
])dnl