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_rhs_value(RULE-LENGTH, NUM, [TYPE])
44 # --------------------------------------
45 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
47 m4_define([b4_rhs_value
],
48 [b4_symbol_value([yystack_@
{($
1) - ($
2)@
}.value
], [$
3])])
50 # b4_rhs_location(RULE-LENGTH, NUM)
51 # ---------------------------------
52 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
54 m4_define([b4_rhs_location
],
55 [yystack_@
{($
1) - ($
2)@
}.location
])
58 # b4_symbol_actions(FILENAME, LINENO,
59 # SYMBOL-TAG, SYMBOL-NUM,
60 # SYMBOL-ACTION, SYMBOL-TYPENAME)
61 # -------------------------------------------------
62 # Same as in C, but using references instead of pointers.
63 m4_define([b4_symbol_actions
],
64 [m4_pushdef([b4_dollar_dollar
],
65 [b4_symbol_value([yyvalue
], [$
6])])dnl
66 m4_pushdef([b4_at_dollar
], [yylocation
])dnl
68 b4_syncline([$
2], [$
1])
70 b4_syncline([@oline@
], [@ofile@
])
72 m4_popdef([b4_at_dollar
])dnl
73 m4_popdef([b4_dollar_dollar
])dnl
77 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
78 # ----------------------------------------------------------
79 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
80 m4_define([b4_symbol_action_
],
88 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
89 # ------------------------------------------------
90 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
92 m4_define([b4_symbol_variant
],
93 [m4_pushdef([b4_dollar_dollar
],
94 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
97 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
101 m4_popdef([b4_dollar_dollar
])dnl
105 # _b4_char_sizeof_counter
106 # -----------------------
107 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
108 m4_define([_b4_char_sizeof_counter
],
111 # _b4_char_sizeof_dummy
112 # ---------------------
113 # At each call return a new C++ identifier.
114 m4_define([_b4_char_sizeof_dummy
],
115 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
116 dummy
[]_b4_char_sizeof_counter
])
119 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
120 # -------------------------------------------------------
121 # To be mapped on the list of type names to produce:
123 # char dummy1[sizeof(type_name_1)];
124 # char dummy2[sizeof(type_name_2)];
126 # for defined type names.
127 # $3 is doubly-quoted, do not quote it again.
128 m4_define([b4_char_sizeof
],
131 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
135 m4_pushdef([b4_copyright_years
],
136 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
138 m4_define([b4_parser_class_name
],
139 [b4_percent_define_get([[parser_class_name]])])
141 # The header is mandatory.
143 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
145 # Backward compatibility.
146 m4_define([b4_location_constructors
])
147 m4_include(b4_pkgdatadir
/[location
.cc
])
149 # We do want M4 expansion after # for CPP macros.
153 [@
output(b4_spec_defines_file@
)@
154 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
155 dnl FIXME
: This is wrong
, we want computed header guards
.
157 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
159 #ifndef PARSER_HEADER_H
160 # define PARSER_HEADER_H
162 ]b4_percent_code_get([[requires]])[
173 /// A char[S] buffer to store and retrieve objects.
175 /// Sort of a variant, but does not keep track of the nature
176 /// of the stored data, since that knowledge is available
177 /// via the current state.
181 /// Instantiate a \a T in here.
182 template <typename T
>
186 return *new (buffer
) T
;
189 /// Accessor to a built \a T.
190 template <typename T
>
194 return reinterpret_cast<T
&>(buffer
);
197 /// Const accessor to a built \a T (for %printer).
198 template <typename T
>
202 return reinterpret_cast<const T
&>(buffer
);
205 /// Swap the content with \a other.
206 template <typename T
>
208 swap(variant
<S
>& other
)
210 std::swap(as
<T
>(), other
.as
<T
>());
213 /// Assign the content of \a other to this.
214 /// Destroys \a other.
215 template <typename T
>
217 build(variant
<S
>& other
)
223 /// Destroy the stored \a T.
224 template <typename T
>
231 /// A buffer large enough to store any of the semantic values.
237 #include "location.hh"
239 /* Enabling traces. */
241 # define YYDEBUG ]b4_debug_flag[
244 /* Enabling verbose error messages. */
245 #ifdef YYERROR_VERBOSE
246 # undef YYERROR_VERBOSE
247 # define YYERROR_VERBOSE 1
249 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
252 /* Enabling the token table. */
253 #ifndef YYTOKEN_TABLE
254 # define YYTOKEN_TABLE ]b4_token_table[
257 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
258 If N is 0, then set CURRENT to the empty location which ends
259 the previous symbol: RHS[0] (always defined). */
261 #ifndef YYLLOC_DEFAULT
262 # define YYLLOC_DEFAULT(Current, Rhs, N) \
266 (Current).begin = (Rhs)[1].location.begin; \
267 (Current).end = (Rhs)[N].location.end; \
271 (Current).begin = (Current).end = (Rhs)[0].location.end; \
279 class ]b4_parser_class_name
[
284 [ /// An auxiliary type to compute the largest semantic type.
286 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
289 /// Symbol semantic values.
290 typedef variant
<sizeof(union_type
)> semantic_type
;],
291 [ /// Symbol semantic values.
293 [ union semantic_type
296 [m4_if(b4_tag_seen_flag
, 0,
297 [[ typedef int semantic_type
;]],
298 [[ typedef YYSTYPE semantic_type
;]])])])[
300 typedef YYSTYPE semantic_type
;
302 /// Symbol locations.
303 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
307 ]b4_token_enums(b4_tokens
)[
310 typedef token::yytokentype token_type
;
312 /// Build a parser object.
313 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
314 virtual ~]b4_parser_class_name
[ ();
317 /// \returns 0 iff parsing succeeded.
318 virtual int parse ();
321 /// The current debugging stream.
322 std::ostream
& debug_stream () const;
323 /// Set the current debugging stream.
324 void set_debug_stream (std::ostream
&);
326 /// Type for debugging levels.
327 typedef int debug_level_type
;
328 /// The current debugging level.
329 debug_level_type
debug_level () const;
330 /// Set the current debugging level.
331 void set_debug_level (debug_level_type l
);
335 /// Report a syntax error.
336 /// \param loc where the syntax error is found.
337 /// \param msg a description of the syntax error.
338 virtual void error (const location_type
& loc
, const std::string
& msg
);
340 /// Generate an error message.
341 /// \param state the state where the error occurred.
342 /// \param tok the lookahead token.
343 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
346 /// \brief Report a symbol value on the debug stream.
347 /// \param yytype The token type.
348 /// \param yyvalue Its semantic value.
349 /// \param yylocation Its location.
350 virtual void yy_symbol_value_print_ (int yytype
,
351 const semantic_type
& yyvalue
,
352 const location_type
& yylocation
);
353 /// \brief Report a symbol on the debug stream.
354 /// \param yytype The token type.
355 /// \param yyvalue Its semantic value.
356 /// \param yylocation Its location.
357 virtual void yy_symbol_print_ (int yytype
,
358 const semantic_type
& yyvalue
,
359 const location_type
& yylocation
);
363 typedef int state_type
;
365 /// Internal symbol numbers.
366 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
368 /// For a state, the index in \a yytable_ of its portion.
369 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
370 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
372 /// For a state, default rule to reduce.
373 /// Unless\a yytable_ specifies something else to do.
374 /// Zero means the default is an error.
375 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
377 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
378 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
380 /// What to do in a state.
381 /// \a yytable_[yypact_[s]]: what to do in state \a s.
382 /// - if positive, shift that token.
383 /// - if negative, reduce the rule which number is the opposite.
384 /// - if zero, do what YYDEFACT says.
385 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
386 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
388 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
390 /// For a state, its accessing symbol.
391 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
393 /// For a rule, its LHS.
394 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
395 /// For a rule, its RHS length.
396 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
398 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
399 /// For a symbol, its name in clear.
400 static const char* const yytname_
[];
404 /// Convert the symbol name \a n to a form suitable for a diagnostic.
405 virtual std::string
yytnamerr_ (const char *n
);
409 /// A `-1'-separated list of the rules' RHS.
410 static const ]b4_int_type_for([b4_rhs
])[ yyrhs_
[];
411 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
412 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
413 /// For each rule, its source line number.
414 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
415 /// For each scanner token number, its symbol number.
416 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
417 /// Report on the debug stream that the rule \a r is going to be reduced.
418 virtual void yy_reduce_print_ (int r
);
419 /// Print the state stack on the debug stream.
420 virtual void yystack_print_ ();
424 std::ostream
* yycdebug_
;
427 /// Convert a scanner token number \a t to a symbol number.
428 token_number_type
yytranslate_ (int t
);
430 /// \brief Reclaim the memory associated to a symbol.
431 /// \param yymsg Why this token is reclaimed.
432 /// \param yytype The symbol type.
433 /// \param yyvalue Its semantic value.
434 /// \param yylocation Its location.
435 inline void yydestruct_ (const char* yymsg
,
437 semantic_type
& yyvalue
,
438 location_type
& yylocation
);
440 /// Element of the stack: a state and its attributes.
443 /// Default constructor.
447 data_type (state_type s
, const semantic_type
& v
, const location_type
& l
);
452 /// The semantic value.
456 location_type location
;
460 typedef stack
<data_type
> stack_type
;
465 /// Push a new state on the stack.
466 /// \warning the contents of \a v is stolen.
467 inline void yypush_ (state_type s
,
468 semantic_type
& v
, const location_type
& l
);
470 /// Pop \a n symbols the three stacks.
471 inline void yypop_ (unsigned int n
= 1);
474 static const int yyeof_
;
475 /* LAST_ -- Last index in TABLE_. */
476 static const int yylast_
;
477 static const int yynnts_
;
478 static const int yyempty_
;
479 static const int yyfinal_
;
480 static const int yyterror_
;
481 static const int yyerrcode_
;
482 static const int yyntokens_
;
483 static const unsigned int yyuser_token_number_max_
;
484 static const token_number_type yyundef_token_
;
485 ]b4_parse_param_vars
[
489 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
490 [b4_token_defines(b4_tokens
)
493 /* Redirection for backward compatibility. */
494 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
497 b4_percent_code_get([[provides]])[]dnl
499 [#endif /* ! defined PARSER_HEADER_H */]
501 @
output(b4_parser_file_name@
)@
502 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
503 b4_percent_code_get([[top]])[]dnl
504 m4_if(b4_prefix
, [yy
], [],
506 // Take the name prefix into account.
507 #define yylex b4_prefix[]lex])[
509 /* First part of user declarations. */
510 ]b4_user_pre_prologue
513 #include "@basename(]b4_spec_defines_file[@)"]])[
515 /* User implementation prologue. */
516 ]b4_user_post_prologue
517 b4_percent_code_get
[]dnl
522 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
523 # define YY_(msgid) dgettext ("bison-runtime", msgid)
527 # define YY_(msgid) msgid
531 /* Suppress unused-variable warnings by "using" E. */
532 #define YYUSE(e) ((void) (e))
534 /* Enable debugging if requested. */
537 /* A pseudo ostream that takes yydebug_ into account. */
538 # define YYCDEBUG if (yydebug_) (*yycdebug_)
540 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
544 *yycdebug_ << Title << ' '; \
545 yy_symbol_print_ ((Type), (Value), (Location)); \
546 *yycdebug_ << std::endl; \
550 # define YY_REDUCE_PRINT(Rule) \
553 yy_reduce_print_ (Rule); \
556 # define YY_STACK_PRINT() \
564 # define YYCDEBUG if (false) std::cerr
565 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
566 # define YY_REDUCE_PRINT(Rule)
567 # define YY_STACK_PRINT()
569 #endif /* !YYDEBUG */
571 #define yyerrok (yyerrstatus_ = 0)
572 #define yyclearin (yychar = yyempty_)
574 #define YYACCEPT goto yyacceptlab
575 #define YYABORT goto yyabortlab
576 #define YYERROR goto yyerrorlab
577 #define YYRECOVERING() (!!yyerrstatus_)
582 /* Return YYSTR after stripping away unnecessary quotes and
583 backslashes, so that it's suitable for yyerror. The heuristic is
584 that double-quoting is unnecessary unless the string contains an
585 apostrophe, a comma, or backslash (other than backslash-backslash).
586 YYSTR is taken from yytname. */
588 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
592 std::string yyr
= "";
593 char const *yyp
= yystr
;
600 goto do_not_strip_quotes
;
604 goto do_not_strip_quotes
;
613 do_not_strip_quotes
: ;
621 /// Build a parser object.
622 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
625 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
626 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
627 #endif]b4_parse_param_cons[
631 ]b4_parser_class_name::~b4_parser_class_name
[ ()
636 /*--------------------------------.
637 | Print this symbol on YYOUTPUT. |
638 `--------------------------------*/
641 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
642 const semantic_type
& yyvalue
, const location_type
& yylocation
)
648 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
656 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
657 const semantic_type
& yyvalue
, const location_type
& yylocation
)
659 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
660 << ' ' << yytname_
[yytype
] << " ("
661 << yylocation
<< ": ";
662 yy_symbol_value_print_ (yytype
, yyvalue
, yylocation
);
668 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
669 int yytype
, semantic_type
& yyvalue
, location_type
& yylocation
)
675 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvalue
, yylocation
);
679 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
685 ]b4_parser_class_name
[::data_type::data_type ()
692 ]b4_parser_class_name
[::data_type::data_type (state_type s
,
693 const semantic_type
& v
, const location_type
& l
)
701 ]b4_parser_class_name
[::yypush_ (state_type s
,
702 semantic_type
& v
, const location_type
& l
)
705 [[ yystack_
.push (data_type (s
, semantic_type(), l
));
706 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]], [build
], [v
])],
707 [ yystack_
.push (data_type (s
, v
, l
));])[
711 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
718 ]b4_parser_class_name
[::debug_stream () const
724 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
730 ]b4_parser_class_name
[::debug_level_type
731 ]b4_parser_class_name
[::debug_level () const
737 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
744 ]b4_parser_class_name
[::parse ()
746 /// Lookahead and lookahead in internal form.
747 int yychar
= yyempty_
;
755 /* Error handling. */
757 int yyerrstatus_
= 0;
759 /// Semantic value of the lookahead.
760 semantic_type yylval
;
761 /// Location of the lookahead.
762 location_type yylloc
;
763 /// The locations where the error started and ended.
764 data_type yyerror_range
[2];
773 YYCDEBUG
<< "Starting parse" << std::endl
;
775 ]m4_ifdef([b4_initial_action
], [
776 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
777 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
778 /* User initialization code. */
779 b4_user_initial_action
780 m4_popdef([b4_dollar_dollar
])dnl
781 m4_popdef([b4_at_dollar
])])dnl
783 [ /* Initialize the stack. The initial state will be set in
784 yynewstate, since the latter expects the semantical and the
785 location values to have been already stored, initialize these
786 stacks with a primary value. */
787 yystack_
= stack_type (0);
788 yypush_ (yystate
, yylval
, yylloc
);
790 // A new state was pushed on the stack.
791 // Invariant: yystate == yystack_[0].state, i.e.,
792 // yystate was just pushed onto the state stack.
794 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
797 if (yystate
== yyfinal_
)
805 /* Try to take a decision without lookahead. */
806 yyn
= yypact_
[yystate
];
807 if (yyn
== yypact_ninf_
)
810 /* Read a lookahead token. */
811 if (yychar
== yyempty_
)
813 YYCDEBUG
<< "Reading a token: ";
814 yychar
= ]b4_c_function_call([yylex
], [int],
815 [[YYSTYPE
*], [&yylval
]][]dnl
816 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
817 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
821 /* Convert token to internal form. */
822 if (yychar
<= yyeof_
)
824 yychar
= yytoken
= yyeof_
;
825 YYCDEBUG
<< "Now at end of input." << std::endl
;
829 yytoken
= yytranslate_ (yychar
);
830 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylval
, yylloc
);
833 /* If the proper action on seeing token YYTOKEN is to reduce or to
834 detect an error, take that action. */
836 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
839 /* Reduce or error. */
843 if (yyn
== 0 || yyn
== yytable_ninf_
)
849 /* Shift the lookahead token. */
850 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylval
, yylloc
);
852 /* Discard the token being shifted. */
855 /* Count tokens shifted since error; after three, turn off error
861 yypush_ (yystate
, yylval
, yylloc
);
864 /*-----------------------------------------------------------.
865 | yydefault -- do the default action for the current state. |
866 `-----------------------------------------------------------*/
868 yyn
= yydefact_
[yystate
];
873 /*-----------------------------.
874 | yyreduce -- Do a reduction. |
875 `-----------------------------*/
877 yylen
= yyr2_
[yyn
];]b4_variant_if([
878 /* Variants are always initialized to an empty instance of the
879 correct type. The default $$=$1 rule is NOT applied when using
881 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yyval
], [build
])[],[
882 /* If YYLEN is nonzero, implement the default value of the action:
883 `$$ = $1'. Otherwise, use the top of the stack.
885 Otherwise, the following line sets YYVAL to garbage.
886 This behavior is undocumented and Bison
887 users should not rely upon it. */
889 yyval
= yystack_@
{yylen
- 1@
}.value
;
891 yyval
= yystack_@
{0@
}.value
;])[
893 // Compute the default @@$.
895 slice
<data_type
, stack_type
> slice (yystack_
, yylen
);
896 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
899 // Perform the reduction.
900 YY_REDUCE_PRINT (yyn
);
907 YY_SYMBOL_PRINT ("-> $$ =", yyr1_
[yyn
], yyval
, yyloc
);
910 // Destroy the lhs symbols.
911 for (int i
= 0; i
< yylen
; ++i
)
913 b4_symbol_variant([[yystos_
[yystack_@
{i@
}.state
]]],
914 [[yystack_@
{i@
}.value
]],
922 /* Shift the result of the reduction. */
924 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[0].state
;
925 if (0 <= yystate
&& yystate
<= yylast_
926 && yycheck_
[yystate
] == yystack_
[0].state
)
927 yystate
= yytable_
[yystate
];
929 yystate
= yydefgoto_
[yyn
- yyntokens_
];
930 yypush_ (yystate
, yyval
, yyloc
);
933 /*------------------------------------.
934 | yyerrlab -- here on detecting error |
935 `------------------------------------*/
937 /* If not already recovering from an error, report this error. */
941 error (yylloc
, yysyntax_error_ (yystate
, yytoken
));
944 yyerror_range
[0].location
= yylloc
;
945 if (yyerrstatus_
== 3)
947 /* If just tried and failed to reuse lookahead token after an
948 error, discard it. */
950 if (yychar
<= yyeof_
)
952 /* Return failure if at end of input. */
953 if (yychar
== yyeof_
)
958 yydestruct_ ("Error: discarding", yytoken
, yylval
, yylloc
);
963 /* Else will try to reuse lookahead token after shifting the error
968 /*---------------------------------------------------.
969 | yyerrorlab -- error raised explicitly by YYERROR. |
970 `---------------------------------------------------*/
973 /* Pacify compilers like GCC when the user code never invokes
974 YYERROR and the label yyerrorlab therefore never appears in user
979 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
980 /* Do not reclaim the symbols of the rule which action triggered
984 yystate
= yystack_
[0].state
;
987 /*-------------------------------------------------------------.
988 | yyerrlab1 -- common code for both syntax error and YYERROR. |
989 `-------------------------------------------------------------*/
991 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
995 yyn
= yypact_
[yystate
];
996 if (yyn
!= yypact_ninf_
)
999 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1001 yyn
= yytable_
[yyn
];
1007 // Pop the current state because it cannot handle the error token.
1008 if (yystack_
.size () == 1)
1011 yyerror_range
[0].location
= yystack_
[0].location
;
1012 yydestruct_ ("Error: popping",
1014 yystack_
[0].value
, yystack_
[0].location
);
1016 yystate
= yystack_
[0].state
;
1020 yyerror_range
[1].location
= yylloc
;
1021 // Using YYLLOC is tempting, but would change the location of
1022 // the lookahead. YYLOC is available though.
1023 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
1025 /* Shift the error token. */
1026 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
1027 yystack_
[0].value
, yystack_
[0].location
);
1030 yypush_ (yystate
, yylval
, yyloc
);
1044 if (yychar
!= yyempty_
)
1045 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, yylval
, yylloc
);
1047 /* Do not reclaim the symbols of the rule which action triggered
1048 this YYABORT or YYACCEPT. */
1050 while (yystack_
.size () != 1)
1052 yydestruct_ ("Cleanup: popping",
1053 yystos_
[yystack_
[0].state
],
1054 yystack_
[0].value
, yystack_
[0].location
);
1061 // Generate an error message.
1063 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1064 b4_error_verbose_if([ tok
])[)
1069 int yyn
= yypact_
[yystate
];
1070 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1072 /* Start YYX at -YYN if negative to avoid negative indexes in
1074 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1076 /* Stay within bounds of both yycheck and yytname. */
1077 int yychecklim
= yylast_
- yyn
+ 1;
1078 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1080 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1081 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1084 // FIXME: This method of building the message is not compatible
1085 // with internationalization. It should work like yacc.c does it.
1086 // That is, first build a string that looks like this:
1087 // "syntax error, unexpected %s or %s or %s"
1088 // Then, invoke YY_ on this string.
1089 // Finally, use the string as a format to output
1090 // yytname_[tok], etc.
1091 // Until this gets fixed, this message appears in English only.
1092 res
= "syntax error, unexpected ";
1093 res
+= yytnamerr_ (yytname_
[tok
]);
1097 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1098 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1100 res
+= (!count
++) ? ", expecting " : " or ";
1101 res
+= yytnamerr_ (yytname_
[x
]);
1107 res
= YY_("syntax error");
1112 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1114 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1115 ]b4_table_define([pact
], [b4_pact
])[;
1117 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1118 doesn't specify something else to do. Zero means the default is an
1120 ]b4_table_define([defact
], [b4_defact
])[;
1122 /* YYPGOTO[NTERM-NUM]. */
1123 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1125 /* YYDEFGOTO[NTERM-NUM]. */
1126 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1128 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1129 positive, shift that token. If negative, reduce the rule which
1130 number is the opposite. If zero, do what YYDEFACT says. */
1131 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1132 ]b4_table_define([table
], [b4_table
])[;
1135 ]b4_table_define([check
], [b4_check
])[;
1137 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1138 symbol of state STATE-NUM. */
1139 ]b4_table_define([stos
], [b4_stos
])[;
1142 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1144 ]b4_table_define([token_number
], [b4_toknum
])[;
1147 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1148 ]b4_table_define([r1
], [b4_r1
])[;
1150 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1151 ]b4_table_define([r2
], [b4_r2
])[;
1153 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1154 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1155 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1157 const ]b4_parser_class_name
[::yytname_
[] =
1164 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1165 ]b4_table_define([rhs
], [b4_rhs
])[;
1167 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1169 ]b4_table_define([prhs
], [b4_prhs
])[;
1171 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1172 ]b4_table_define([rline
], [b4_rline
])[;
1174 // Print the state stack on the debug stream.
1176 ]b4_parser_class_name
[::yystack_print_ ()
1178 *yycdebug_
<< "Stack now";
1179 for (stack_type::const_iterator
1180 i
= yystack_
.begin (),
1181 i_end
= yystack_
.end ();
1183 *yycdebug_
<< ' ' << i
->state
;
1184 *yycdebug_
<< std::endl
;
1187 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1189 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1191 unsigned int yylno
= yyrline_
[yyrule
];
1192 int yynrhs
= yyr2_
[yyrule
];
1193 /* Print the symbols being reduced, and their result. */
1194 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1195 << " (line " << yylno
<< "):" << std::endl
;
1196 /* The symbols being reduced. */
1197 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1198 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1199 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1200 ]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1201 ]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1205 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1206 ]b4_parser_class_name
[::token_number_type
1207 ]b4_parser_class_name
[::yytranslate_ (int t
)
1210 const token_number_type
1215 if ((unsigned int) t
<= yyuser_token_number_max_
)
1216 return translate_table
[t
];
1218 return yyundef_token_
;
1221 const int ]b4_parser_class_name
[::yyeof_
= 0;
1222 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1223 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1224 const int ]b4_parser_class_name
[::yyempty_
= -2;
1225 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1226 const int ]b4_parser_class_name
[::yyterror_
= 1;
1227 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1228 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1230 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1231 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1233 ]b4_namespace_close
[
1236 @
output(b4_dir_prefix
[]stack
.hh@
)@
1237 b4_copyright([Stack handling
for Bison parsers in C
++])[
1239 #ifndef BISON_STACK_HH
1240 # define BISON_STACK_HH
1245 template <class T
, class S
= std::deque
<T
> >
1250 // Hide our reversed order.
1251 typedef typename
S::reverse_iterator iterator
;
1252 typedef typename
S::const_reverse_iterator const_iterator
;
1258 stack (unsigned int n
) : seq_ (n
)
1264 operator [] (unsigned int i
)
1271 operator [] (unsigned int i
) const
1280 seq_
.push_front (t
);
1285 pop (unsigned int n
= 1)
1292 typename
S::size_type
1295 return seq_
.size ();
1298 inline const_iterator
begin () const { return seq_
.rbegin (); }
1299 inline const_iterator
end () const { return seq_
.rend (); }
1302 /// The wrapped container.
1306 /// Present a slice of the top of a stack.
1307 template <class T
, class S
= stack
<T
> >
1312 slice (const S
& stack
,
1313 unsigned int range
) : stack_ (stack
),
1320 operator [] (unsigned int i
) const
1322 return stack_
[range_
- i
];
1328 unsigned int range_
;
1330 ]b4_namespace_close
[
1332 #endif // not BISON_STACK_HH[]dnl
1335 m4_popdef([b4_copyright_years
])dnl