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