* NEWS: Document when yyparse started to return 2.
[bison.git] / data / lalr1.cc
1451 / 1451 (100%)
CommitLineData
a75c057f1m4_divert(-1)
b47217152
60491a943# C++ skeleton for Bison
b4721715
PE
4
5# Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
60491a94
AD
6
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
0fb669f9
PE
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20# 02110-1301 USA
60491a9421
66d30cd4
AD
22## ---------------- ##
23## Default values. ##
24## ---------------- ##
25
99880de5
AD
26# Default parser class name.
27m4_define_default([b4_parser_class_name], [parser])
66d30cd4
AD
28
29
30
31## ----------------- ##
32## Semantic Values. ##
33## ----------------- ##
34
35
82b6cb3f
AD
36# b4_lhs_value([TYPE])
37# --------------------
38# Expansion of $<TYPE>$.
39m4_define([b4_lhs_value],
bc82c5a540[(yyval[]m4_ifval([$1], [.$1]))])
82b6cb3f
AD
41
42
43# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
44# --------------------------------------
45# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
46# symbols on RHS.
47m4_define([b4_rhs_value],
bc82c5a548[(yysemantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3]))])
82b6cb3f49
99880de550m4_define_default([b4_location_type], [location])
b47dbebe51m4_define_default([b4_filename_type], [std::string])
82b6cb3f
AD
52
53# b4_lhs_location()
54# -----------------
55# Expansion of @$.
56m4_define([b4_lhs_location],
bc82c5a557[(yyloc)])
82b6cb3f
AD
58
59
60# b4_rhs_location(RULE-LENGTH, NUM)
61# ---------------------------------
62# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
63# on RHS.
64m4_define([b4_rhs_location],
bc82c5a565[(yylocation_stack_@{m4_eval([$1 - $2])@})])
82b6cb3f
AD
66
67
caf37a36
ADL
68# b4_parse_param_decl
69# -------------------
6dde1c82
AD
70# Extra formal arguments of the constructor.
71# Change the parameter names from "foo" into "foo_yyarg", so that
72# there is no collision bw the user chosen attribute name, and the
73# argument name in the constructor.
caf37a3674m4_define([b4_parse_param_decl],
6dde1c8275[m4_ifset([b4_parse_param],
a3cb624876 [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
6dde1c82
AD
77
78m4_define([b4_parse_param_decl_1],
79[$1_yyarg])
80
81
caf37a36
ADL
82
83# b4_parse_param_cons
84# -------------------
6dde1c8285# Extra initialisations of the constructor.
caf37a36
ADL
86m4_define([b4_parse_param_cons],
87 [m4_ifset([b4_parse_param],
88 [,
89 b4_cc_constructor_calls(b4_parse_param)])])
90m4_define([b4_cc_constructor_calls],
91 [m4_map_sep([b4_cc_constructor_call], [,
92 ], [$@])])
93m4_define([b4_cc_constructor_call],
6dde1c8294 [$2 ($2_yyarg)])
caf37a36
ADL
95
96# b4_parse_param_vars
97# -------------------
6dde1c8298# Extra instance variables.
caf37a36
ADL
99m4_define([b4_parse_param_vars],
100 [m4_ifset([b4_parse_param],
101 [
102 /* User arguments. */
103b4_cc_var_decls(b4_parse_param)])])
104m4_define([b4_cc_var_decls],
105 [m4_map_sep([b4_cc_var_decl], [
106], [$@])])
107m4_define([b4_cc_var_decl],
108 [ $1;])
109
a5eb1ed2110
111
b526ee61
AD
112# We do want M4 expansion after # for CPP macros.
113m4_changecom()
98254360114m4_divert(0)dnl
b61c6978
PE
115m4_if(b4_defines_flag, 0, [],
116[@output @output_header_name@
fb8135fa117b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
010f91c3118 [2002, 2003, 2004, 2005])[
c5e3e510
AD
119/* FIXME: This is wrong, we want computed header guards.
120 I don't know why the macros are missing now. :( */
121#ifndef PARSER_HEADER_H
122# define PARSER_HEADER_H
2b548aa6123
8d69a1a3124#include <string>
717be197125#include <iostream>
50997c6e126
4162fa07127/* Using locations. */
c5e3e510128#define YYLSP_NEEDED ]b4_locations_flag[
4162fa07129
d390b02b
AD
130namespace yy
131{
132 class position;
133 class location;
134}
135
c5e3e510136]b4_token_defines(b4_tokens)[
17acead5137
0dd1580a138/* Copy the first part of user declarations. */
c5e3e510139]b4_pre_prologue[
4162fa07140
996b1c7e141]/* Line __line__ of lalr1.cc. */
c5e3e510142b4_syncline([@oline@], [@ofile@])[
e96c9728143
9a0d8bec
AD
144#include "stack.hh"
145#include "location.hh"
146
69e2658b
RA
147/* Enabling traces. */
148#ifndef YYDEBUG
c5e3e510149# define YYDEBUG ]b4_debug[
69e2658b
RA
150#endif
151
141f5793
PE
152/* Enabling verbose error messages. */
153#ifdef YYERROR_VERBOSE
154# undef YYERROR_VERBOSE
155# define YYERROR_VERBOSE 1
156#else
c5e3e510157# define YYERROR_VERBOSE ]b4_error_verbose[
69e2658b
RA
158#endif
159
141f5793
PE
160/* Enabling the token table. */
161#ifndef YYTOKEN_TABLE
162# define YYTOKEN_TABLE ]b4_token_table[
163#endif
164
be3d9d42165#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
c5e3e510166]m4_ifdef([b4_stype],
48b16bbc167[b4_syncline([b4_stype_line], [b4_file_name])
be3d9d42168union YYSTYPE b4_stype;
996b1c7e169/* Line __line__ of lalr1.cc. */
6ad762a8170b4_syncline([@oline@], [@ofile@])],
be3d9d42
AD
171[typedef int YYSTYPE;])[
172# define yystype YYSTYPE /* obsolescent; will be withdrawn */
173# define YYSTYPE_IS_DECLARED 1
174# define YYSTYPE_IS_TRIVIAL 1
98254360
RA
175#endif
176
0dd1580a177/* Copy the second part of user declarations. */
c5e3e510178]b4_post_prologue[
0dd1580a179
996b1c7e180]/* Line __line__ of lalr1.cc. */
c5e3e510181b4_syncline([@oline@], [@ofile@])[
b4a20338
AD
182/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
183 If N is 0, then set CURRENT to the empty location which ends
184 the previous symbol: RHS[0] (always defined). */
3fc16193185
374f5a14186#ifndef YYLLOC_DEFAULT
b4a20338
AD
187# define YYLLOC_DEFAULT(Current, Rhs, N) \
188do { \
189 if (N) \
190 { \
191 (Current).begin = (Rhs)[1].begin; \
192 (Current).end = (Rhs)[N].end; \
193 } \
194 else \
195 { \
196 (Current).begin = (Current).end = (Rhs)[0].end; \
197 } \
3fc16193198} while (0)
374f5a14
RA
199#endif
200
2b548aa6
RA
201namespace yy
202{
c5e3e510203 class ]b4_parser_class_name[;
3f3eed27204
f85a5e6f205 template <typename P>
99880de5206 struct traits
2b548aa6
RA
207 {
208 };
209
f85a5e6f210 template <>
99880de5211 struct traits<]b4_parser_class_name[>
2b548aa6212 {
99880de5
AD
213 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
214 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
215 typedef int state_type;
216 typedef YYSTYPE semantic_type;
217 typedef ]b4_location_type[ location_type;
2b548aa6
RA
218 };
219}
220
221namespace yy
222{
efeed023223 /// A Bison parser.
07fed891224 class ]b4_parser_class_name[
2b548aa6225 {
617a8f12226 /// Symbol semantic values.
e019c247227 typedef traits<]b4_parser_class_name[>::semantic_type semantic_type;
617a8f12228 /// Symbol locations.
e019c247229 typedef traits<]b4_parser_class_name[>::location_type location_type;
2b548aa6230
e019c247231 public:
efeed023232 /// Build a parser object.
a3cb6248
AD
233 ]b4_parser_class_name[ (]b4_parse_param_decl[) :
234 yydebug_ (false),
9a1e9989235 yycdebug_ (&std::cerr)]b4_parse_param_cons[
50997c6e236 {
237 }
238
c5e3e510239 virtual ~]b4_parser_class_name[ ()
2b548aa6240 {
241 }
242
f69a4142
AD
243 /// Parse.
244 /// \returns 0 iff parsing succeeded.
e019c247245 virtual int parse ();
2b548aa6246
f69a4142247 /// The current debugging stream.
9a1e9989
AD
248 std::ostream& debug_stream () const;
249 /// Set the current debugging stream.
250 void set_debug_stream (std::ostream &);
251
a3cb6248
AD
252 /// Type for debugging levels.
253 typedef int debug_level_type;
254 /// The current debugging level.
255 debug_level_type debug_level () const;
256 /// Set the current debugging level.
257 void set_debug_level (debug_level_type l);
258
2b548aa6259 private:
3f3eed27260
f69a4142261 /// Call the scanner.
2e1f5829262 virtual void yylex_ ();
efeed023
AD
263
264 /// Report a syntax error.
265 /// \param loc where the syntax error is found.
266 /// \param msg a description of the syntax error.
99880de5267 virtual void error (const location_type& loc, const std::string& msg);
efeed023
AD
268
269 /// Generate an error message, and invoke error.
f69a4142270 virtual void yyreport_syntax_error_ ();
efeed023271
a5eb1ed2272#if YYDEBUG
f69a4142
AD
273 /// \brief Report a symbol on the debug stream.
274 /// \param yytype The token type.
275 /// \param yyvaluep Its semantic value.
276 /// \param yylocationp Its location.
277 virtual void yysymprint_ (int yytype,
99880de5
AD
278 const semantic_type* yyvaluep,
279 const location_type* yylocationp);
a5eb1ed2
AD
280#endif /* ! YYDEBUG */
281
4bb2bc3f282
e019c247
AD
283 /// State numbers.
284 typedef traits<]b4_parser_class_name[>::state_type state_type;
285 /// State stack type.
286 typedef stack<state_type> state_stack_type;
287 /// Semantic value stack type.
288 typedef stack<semantic_type> semantic_stack_type;
289 /// location stack type.
290 typedef stack<location_type> location_stack_type;
291
f69a4142292 /// The state stack.
e019c247293 state_stack_type yystate_stack_;
f69a4142294 /// The semantic value stack.
e019c247295 semantic_stack_type yysemantic_stack_;
f69a4142296 /// The location stack.
e019c247297 location_stack_type yylocation_stack_;
2b548aa6298
e019c247
AD
299 /// Internal symbol numbers.
300 typedef traits<]b4_parser_class_name[>::token_number_type token_number_type;
2b548aa6301 /* Tables. */
efeed023302 /// For a state, the index in \a yytable_ of its portion.
617a8f12
AD
303 static const ]b4_int_type_for([b4_pact])[ yypact_[];
304 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
efeed023
AD
305
306 /// For a state, default rule to reduce.
307 /// Unless\a yytable_ specifies something else to do.
308 /// Zero means the default is an error.
617a8f12309 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
efeed023310
617a8f12
AD
311 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
312 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
efeed023
AD
313
314 /// What to do in a state.
315 /// \a yytable_[yypact_[s]]: what to do in state \a s.
316 /// - if positive, shift that token.
317 /// - if negative, reduce the rule which number is the opposite.
318 /// - if zero, do what YYDEFACT says.
617a8f12
AD
319 static const ]b4_int_type_for([b4_table])[ yytable_[];
320 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
efeed023321
617a8f12322 static const ]b4_int_type_for([b4_check])[ yycheck_[];
efeed023
AD
323
324 /// For a state, its accessing symbol.
617a8f12325 static const ]b4_int_type_for([b4_stos])[ yystos_[];
efeed023
AD
326
327 /// For a rule, its LHS.
617a8f12328 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
efeed023329 /// For a rule, its RHS length.
617a8f12330 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
69e2658b331
141f5793332#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
efeed023333 /// For a symbol, its name in clear.
9e0876fb
PE
334 static const char* const yytname_[];
335#endif
336
337#if YYERROR_VERBOSE
338 /// Convert the symbol name \a n to a form suitable for a diagnostic.
339 virtual std::string yytnamerr_ (const char *n);
69e2658b340#endif
2b548aa6341
69e2658b342#if YYDEBUG
e019c247
AD
343 /// A type to store symbol numbers and -1.
344 typedef traits<]b4_parser_class_name[>::rhs_number_type rhs_number_type;
617a8f12345 /// A `-1'-separated list of the rules' RHS.
99880de5346 static const rhs_number_type yyrhs_[];
617a8f12
AD
347 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
348 static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
349 /// For each rule, its source line number.
350 static const ]b4_int_type_for([b4_rline])[ yyrline_[];
351 /// For each scanner token number, its symbol number.
352 static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
efeed023
AD
353 /// Report on the debug stream that the rule \a r is going to be reduced.
354 virtual void yyreduce_print_ (int r);
355 /// Print the state stack on the debug stream.
f69a4142356 virtual void yystack_print_ ();
69e2658b357#endif
2b548aa6358
f69a4142359 /// Convert a scanner token number to a symbol number.
99880de5360 inline token_number_type yytranslate_ (int token);
f69a4142
AD
361
362 /// \brief Reclaim the memory associated to a symbol.
363 /// \param yymsg Why this token is reclaimed.
364 /// \param yytype The symbol type.
365 /// \param yyvaluep Its semantic value.
366 /// \param yylocationp Its location.
367 inline void yydestruct_ (const char* yymsg,
368 int yytype,
99880de5
AD
369 semantic_type* yyvaluep,
370 location_type* yylocationp);
2b548aa6371
52d5733f372 /// Pop \a n symbols the three stacks.
f69a4142373 inline void yypop_ (unsigned int n = 1);
52d5733f374
762a801e375 /* Constants. */
617a8f12376 static const int yyeof_;
39912f52377 /* LAST_ -- Last index in TABLE_. */
617a8f12
AD
378 static const int yylast_;
379 static const int yynnts_;
380 static const int yyempty_;
381 static const int yyfinal_;
382 static const int yyterror_;
383 static const int yyerrcode_;
384 static const int yyntokens_;
385 static const unsigned int yyuser_token_number_max_;
99880de5386 static const token_number_type yyundef_token_;
2b548aa6
RA
387
388 /* State. */
617a8f12
AD
389 int yyn_;
390 int yylen_;
391 int yystate_;
4bb2bc3f392
a08460b0393 /* Error handling. */
617a8f12
AD
394 int yynerrs_;
395 int yyerrstatus_;
a08460b0396
717be197397 /* Debugging. */
a3cb6248398 int yydebug_;
9a1e9989399 std::ostream* yycdebug_;
717be197400
8dd162d3401 /* Look-ahead and look-ahead in internal form. */
617a8f12
AD
402 int yylooka_;
403 int yyilooka_;
4bb2bc3f404
451364ed405 /// Semantic value of the look-ahead.
99880de5406 semantic_type yylval;
451364ed407 /// Location of the look-ahead.
99880de5408 location_type yylloc;
3fc16193409 /// The locations where the error started and ended.
99880de5410 location yyerror_range_[2];
8d69a1a3411
451364ed412 /// $$.
99880de5413 semantic_type yyval;
451364ed414 /// @@$.
99880de5415 location_type yyloc;
caf37a36416]b4_parse_param_vars[
2b548aa6
RA
417 };
418}
419
c5e3e510420#endif /* ! defined PARSER_HEADER_H */]
b61c6978421])dnl
6ad762a8422@output @output_parser_name@
fb8135fa423b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
010f91c3424 [2002, 2003, 2004, 2005])
c5b95ccf
AD
425m4_if(b4_prefix[], [yy], [],
426[
427// Take the name prefix into account.
428#define yylex b4_prefix[]lex])
429m4_if(b4_defines_flag, 0, [],
430[
431#include @output_header_name@])[
50997c6e432
30757c8c
PE
433#ifndef YY_
434# if YYENABLE_NLS
435# if ENABLE_NLS
436# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
437# define YY_(msgid) dgettext ("bison-runtime", msgid)
438# endif
439# endif
440# ifndef YY_
441# define YY_(msgid) msgid
442# endif
989b5b8e
AD
443#endif
444
a3cb6248445/* A pseudo ostream that takes yydebug_ into account. */
9a1e9989446# define YYCDEBUG \
a3cb6248447 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
9a1e9989
AD
448 (*yycdebug_)
449
2b548aa6450/* Enable debugging if requested. */
50997c6e451#if YYDEBUG
284acc8b452
453# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
454do { \
a3cb6248455 if (yydebug_) \
284acc8b456 { \
9a1e9989457 *yycdebug_ << (Title) << ' '; \
f69a4142458 yysymprint_ ((Type), (Value), (Location)); \
9a1e9989459 *yycdebug_ << std::endl; \
284acc8b
AD
460 } \
461} while (0)
462
5348bfbe
AD
463# define YY_REDUCE_PRINT(Rule) \
464do { \
a3cb6248465 if (yydebug_) \
f69a4142466 yyreduce_print_ (Rule); \
5348bfbe467} while (0)
284acc8b468
25f66e1a
AD
469# define YY_STACK_PRINT() \
470do { \
a3cb6248471 if (yydebug_) \
f69a4142472 yystack_print_ (); \
25f66e1a473} while (0)
284acc8b474
2b548aa6475#else /* !YYDEBUG */
284acc8b476
477# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
5348bfbe478# define YY_REDUCE_PRINT(Rule)
25f66e1a479# define YY_STACK_PRINT()
284acc8b480
2b548aa6
RA
481#endif /* !YYDEBUG */
482
60a777aa
AD
483#define YYACCEPT goto yyacceptlab
484#define YYABORT goto yyabortlab
47301314485#define YYERROR goto yyerrorlab
60a777aa486
9e0876fb
PE
487#if YYERROR_VERBOSE
488
489/* Return YYSTR after stripping away unnecessary quotes and
490 backslashes, so that it's suitable for yyerror. The heuristic is
491 that double-quoting is unnecessary unless the string contains an
492 apostrophe, a comma, or backslash (other than backslash-backslash).
493 YYSTR is taken from yytname. */
494std::string
495yy::]b4_parser_class_name[::yytnamerr_ (const char *yystr)
496{
497 if (*yystr == '"')
498 {
499 std::string yyr = "";
500 char const *yyp = yystr;
501
502 for (;;)
503 switch (*++yyp)
504 {
505 case '\'':
506 case ',':
507 goto do_not_strip_quotes;
508
509 case '\\':
510 if (*++yyp != '\\')
511 goto do_not_strip_quotes;
512 /* Fall through. */
513 default:
514 yyr += *yyp;
515 break;
516
517 case '"':
518 return yyr;
519 }
520 do_not_strip_quotes: ;
521 }
522
523 return yystr;
524}
525
526#endif
527
a5eb1ed2528#if YYDEBUG
a0e68930
AD
529/*--------------------------------.
530| Print this symbol on YYOUTPUT. |
531`--------------------------------*/
532
533void
f69a4142534yy::]b4_parser_class_name[::yysymprint_ (int yytype,
99880de5535 const semantic_type* yyvaluep, const location_type* yylocationp)
a0e68930
AD
536{
537 /* Pacify ``unused variable'' warnings. */
538 (void) yyvaluep;
539 (void) yylocationp;
9a1e9989
AD
540 /* Backward compatibility, but should be removed eventually. */
541 std::ostream& cdebug_ = *yycdebug_;
c1f8f16a542 (void) cdebug_;
a0e68930543
617a8f12544 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
9e0876fb545 << ' ' << yytname_[yytype] << " ("
9a1e9989546 << *yylocationp << ": ";
a0e68930
AD
547 switch (yytype)
548 {
549]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
550[ default:
551 break;
552 }
9a1e9989553 *yycdebug_ << ')';
a0e68930554}
a5eb1ed2555#endif /* ! YYDEBUG */
a0e68930
AD
556
557void
f69a4142558yy::]b4_parser_class_name[::yydestruct_ (const char* yymsg,
99880de5559 int yytype, semantic_type* yyvaluep, location_type* yylocationp)
a0e68930
AD
560{
561 /* Pacify ``unused variable'' warnings. */
895789c6562 (void) yymsg;
a0e68930
AD
563 (void) yyvaluep;
564 (void) yylocationp;
565
566 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
567
568 switch (yytype)
569 {
570]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
571 default:
572 break;
573 }
574}
60a777aa575
52d5733f576void
f69a4142577yy::]b4_parser_class_name[::yypop_ (unsigned int n)
52d5733f578{
617a8f12
AD
579 yystate_stack_.pop (n);
580 yysemantic_stack_.pop (n);
581 yylocation_stack_.pop (n);
52d5733f
AD
582}
583
9a1e9989
AD
584std::ostream&
585yy::]b4_parser_class_name[::debug_stream () const
586{
587 return *yycdebug_;
588}
589
590void
591yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o)
592{
593 yycdebug_ = &o;
594}
595
596
a3cb6248
AD
597yy::]b4_parser_class_name[::debug_level_type
598yy::]b4_parser_class_name[::debug_level () const
599{
600 return yydebug_;
601}
602
603void
604yy::]b4_parser_class_name[::set_debug_level (debug_level_type l)
605{
606 yydebug_ = l;
607}
608
609
e019c247610int
c5e3e510611yy::]b4_parser_class_name[::parse ()
2b548aa6612{
ad745863
PE
613 int yyresult_;
614
30757c8c615 YYCDEBUG << "Starting parse" << std::endl;
451364ed616
617a8f12
AD
617 yynerrs_ = 0;
618 yyerrstatus_ = 0;
4bb2bc3f619
451364ed620 /* Start. */
617a8f12
AD
621 yystate_ = 0;
622 yylooka_ = yyempty_;
451364ed
AD
623
624]m4_ifdef([b4_initial_action], [
99880de5
AD
625m4_pushdef([b4_at_dollar], [yylloc])dnl
626m4_pushdef([b4_dollar_dollar], [yylval])dnl
451364ed
AD
627 /* User initialization code. */
628 b4_initial_action
629m4_popdef([b4_dollar_dollar])dnl
630m4_popdef([b4_at_dollar])dnl
631/* Line __line__ of yacc.c. */
632b4_syncline([@oline@], [@ofile@])])dnl
633
634[ /* Initialize the stacks. The initial state will be pushed in
3ae831b4
AD
635 yynewstate, since the latter expects the semantical and the
636 location values to have been already stored, initialize these
637 stacks with a primary value. */
e019c247
AD
638 yystate_stack_ = state_stack_type (0);
639 yysemantic_stack_ = semantic_stack_type (0);
640 yylocation_stack_ = location_stack_type (0);
99880de5
AD
641 yysemantic_stack_.push (yylval);
642 yylocation_stack_.push (yylloc);
2b548aa6
RA
643
644 /* New state. */
52d5733f645yynewstate:
617a8f12646 yystate_stack_.push (yystate_);
30757c8c647 YYCDEBUG << "Entering state " << yystate_ << std::endl;
50997c6e648 goto yybackup;
2b548aa6
RA
649
650 /* Backup. */
52d5733f651yybackup:
2b548aa6652
8dd162d3653 /* Try to take a decision without look-ahead. */
617a8f12
AD
654 yyn_ = yypact_[yystate_];
655 if (yyn_ == yypact_ninf_)
2b548aa6
RA
656 goto yydefault;
657
8dd162d3658 /* Read a look-ahead token. */
617a8f12659 if (yylooka_ == yyempty_)
2e1f5829660 yylex_ ();
2b548aa6
RA
661
662 /* Convert token to internal form. */
617a8f12663 if (yylooka_ <= yyeof_)
2b548aa6664 {
617a8f12665 yylooka_ = yyilooka_ = yyeof_;
30757c8c666 YYCDEBUG << "Now at end of input." << std::endl;
2b548aa6
RA
667 }
668 else
669 {
617a8f12670 yyilooka_ = yytranslate_ (yylooka_);
30757c8c671 YY_SYMBOL_PRINT ("Next token is", yyilooka_, &yylval, &yylloc);
2b548aa6
RA
672 }
673
a5eb1ed2674 /* If the proper action on seeing token ILOOKA_ is to reduce or to
47301314675 detect an error, take that action. */
617a8f12
AD
676 yyn_ += yyilooka_;
677 if (yyn_ < 0 || yylast_ < yyn_ || yycheck_[yyn_] != yyilooka_)
2b548aa6
RA
678 goto yydefault;
679
680 /* Reduce or error. */
617a8f12
AD
681 yyn_ = yytable_[yyn_];
682 if (yyn_ < 0)
2b548aa6683 {
617a8f12684 if (yyn_ == yytable_ninf_)
2b548aa6
RA
685 goto yyerrlab;
686 else
687 {
617a8f12688 yyn_ = -yyn_;
2b548aa6
RA
689 goto yyreduce;
690 }
691 }
617a8f12692 else if (yyn_ == 0)
2b548aa6693 goto yyerrlab;
a75c057f694
2b548aa6695 /* Accept? */
617a8f12696 if (yyn_ == yyfinal_)
2b548aa6
RA
697 goto yyacceptlab;
698
8dd162d3699 /* Shift the look-ahead token. */
30757c8c700 YY_SYMBOL_PRINT ("Shifting", yyilooka_, &yylval, &yylloc);
2b548aa6
RA
701
702 /* Discard the token being shifted unless it is eof. */
617a8f12
AD
703 if (yylooka_ != yyeof_)
704 yylooka_ = yyempty_;
2b548aa6705
99880de5
AD
706 yysemantic_stack_.push (yylval);
707 yylocation_stack_.push (yylloc);
8d69a1a3
RA
708
709 /* Count tokens shifted since error; after three, turn off error
710 status. */
617a8f12
AD
711 if (yyerrstatus_)
712 --yyerrstatus_;
8d69a1a3713
617a8f12714 yystate_ = yyn_;
2b548aa6
RA
715 goto yynewstate;
716
47301314
AD
717/*-----------------------------------------------------------.
718| yydefault -- do the default action for the current state. |
719`-----------------------------------------------------------*/
52d5733f720yydefault:
617a8f12
AD
721 yyn_ = yydefact_[yystate_];
722 if (yyn_ == 0)
2b548aa6723 goto yyerrlab;
50997c6e724 goto yyreduce;
2b548aa6725
47301314
AD
726/*-----------------------------.
727| yyreduce -- Do a reduction. |
728`-----------------------------*/
52d5733f729yyreduce:
617a8f12730 yylen_ = yyr2_[yyn_];
47301314
AD
731 /* If LEN_ is nonzero, implement the default value of the action:
732 `$$ = $1'. Otherwise, use the top of the stack.
733
734 Otherwise, the following line sets YYVAL to garbage.
735 This behavior is undocumented and Bison
736 users should not rely upon it. */
617a8f12
AD
737 if (yylen_)
738 yyval = yysemantic_stack_[yylen_ - 1];
50997c6e739 else
617a8f12740 yyval = yysemantic_stack_[0];
2b548aa6741
b4a20338742 {
e019c247743 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen_);
617a8f12744 YYLLOC_DEFAULT (yyloc, slice, yylen_);
b4a20338745 }
617a8f12
AD
746 YY_REDUCE_PRINT (yyn_);
747 switch (yyn_)
45119f04748 {
c5e3e510749 ]b4_actions[
95f22ad2750 default: break;
45119f04751 }
a75c057f752
996b1c7e753]/* Line __line__ of lalr1.cc. */
c5e3e510754b4_syncline([@oline@], [@ofile@])[
06446ccf755
617a8f12756 yypop_ (yylen_);
2b548aa6757
25f66e1a758 YY_STACK_PRINT ();
a75c057f759
617a8f12
AD
760 yysemantic_stack_.push (yyval);
761 yylocation_stack_.push (yyloc);
2b548aa6
RA
762
763 /* Shift the result of the reduction. */
617a8f12
AD
764 yyn_ = yyr1_[yyn_];
765 yystate_ = yypgoto_[yyn_ - yyntokens_] + yystate_stack_[0];
766 if (0 <= yystate_ && yystate_ <= yylast_
767 && yycheck_[yystate_] == yystate_stack_[0])
768 yystate_ = yytable_[yystate_];
2b548aa6769 else
617a8f12770 yystate_ = yydefgoto_[yyn_ - yyntokens_];
2b548aa6
RA
771 goto yynewstate;
772
47301314
AD
773/*------------------------------------.
774| yyerrlab -- here on detecting error |
775`------------------------------------*/
284acc8b776yyerrlab:
4bb2bc3f777 /* If not already recovering from an error, report this error. */
f69a4142778 yyreport_syntax_error_ ();
a75c057f779
99880de5780 yyerror_range_[0] = yylloc;
617a8f12781 if (yyerrstatus_ == 3)
762a801e782 {
8dd162d3783 /* If just tried and failed to reuse look-ahead token after an
762a801e
RA
784 error, discard it. */
785
617a8f12786 if (yylooka_ <= yyeof_)
47301314787 {
258b75ca788 /* Return failure if at end of input. */
617a8f12789 if (yylooka_ == yyeof_)
258b75ca790 YYABORT;
47301314
AD
791 }
792 else
793 {
30757c8c794 yydestruct_ ("Error: discarding", yyilooka_, &yylval, &yylloc);
617a8f12795 yylooka_ = yyempty_;
47301314796 }
762a801e
RA
797 }
798
8dd162d3799 /* Else will try to reuse look-ahead token after shifting the error
762a801e800 token. */
47301314
AD
801 goto yyerrlab1;
802
803
804/*---------------------------------------------------.
805| yyerrorlab -- error raised explicitly by YYERROR. |
806`---------------------------------------------------*/
807yyerrorlab:
808
b4721715
PE
809 /* Pacify compilers like GCC when the user code never invokes
810 YYERROR and the label yyerrorlab therefore never appears in user
811 code. */
812 if (false)
258b75ca813 goto yyerrorlab;
62b6aef9814
617a8f12
AD
815 yyerror_range_[0] = yylocation_stack_[yylen_ - 1];
816 yypop_ (yylen_);
817 yystate_ = yystate_stack_[0];
47301314818 goto yyerrlab1;
762a801e819
47301314
AD
820/*-------------------------------------------------------------.
821| yyerrlab1 -- common code for both syntax error and YYERROR. |
822`-------------------------------------------------------------*/
823yyerrlab1:
617a8f12824 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
762a801e825
769b430f
AD
826 for (;;)
827 {
617a8f12
AD
828 yyn_ = yypact_[yystate_];
829 if (yyn_ != yypact_ninf_)
769b430f830 {
617a8f12
AD
831 yyn_ += yyterror_;
832 if (0 <= yyn_ && yyn_ <= yylast_ && yycheck_[yyn_] == yyterror_)
769b430f833 {
617a8f12
AD
834 yyn_ = yytable_[yyn_];
835 if (0 < yyn_)
769b430f
AD
836 break;
837 }
838 }
839
840 /* Pop the current state because it cannot handle the error token. */
617a8f12841 if (yystate_stack_.height () == 1)
47301314842 YYABORT;
762a801e843
617a8f12844 yyerror_range_[0] = yylocation_stack_[0];
30757c8c845 yydestruct_ ("Error: popping",
617a8f12
AD
846 yystos_[yystate_],
847 &yysemantic_stack_[0], &yylocation_stack_[0]);
f69a4142848 yypop_ ();
617a8f12849 yystate_ = yystate_stack_[0];
25f66e1a850 YY_STACK_PRINT ();
762a801e851 }
852
617a8f12853 if (yyn_ == yyfinal_)
762a801e
RA
854 goto yyacceptlab;
855
99880de5
AD
856 yyerror_range_[1] = yylloc;
857 // Using YYLLOC is tempting, but would change the location of
3fc16193858 // the look-ahead. YYLOC is available though.
617a8f12859 YYLLOC_DEFAULT (yyloc, yyerror_range_ - 1, 2);
99880de5860 yysemantic_stack_.push (yylval);
617a8f12861 yylocation_stack_.push (yyloc);
762a801e862
1576d44d863 /* Shift the error token. */
30757c8c864 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn_],
617a8f12865 &yysemantic_stack_[0], &yylocation_stack_[0]);
1576d44d866
617a8f12867 yystate_ = yyn_;
762a801e
RA
868 goto yynewstate;
869
2b548aa6870 /* Accept. */
284acc8b871yyacceptlab:
ad745863
PE
872 yyresult_ = 0;
873 goto yyreturn;
762a801e
RA
874
875 /* Abort. */
284acc8b876yyabortlab:
ad745863
PE
877 yyresult_ = 1;
878 goto yyreturn;
879
880yyreturn:
881 if (yylooka_ != yyeof_ && yylooka_ != yyempty_)
dd5f2af2882 yydestruct_ ("Cleanup: discarding lookahead", yyilooka_, &yylval, &yylloc);
258b75ca
PE
883
884 while (yystate_stack_.height () != 1)
885 {
dd5f2af2886 yydestruct_ ("Cleanup: popping",
258b75ca
PE
887 yystos_[yystate_stack_[0]],
888 &yysemantic_stack_[0],
889 &yylocation_stack_[0]);
890 yypop_ ();
891 }
892
ad745863893 return yyresult_;
2b548aa6
RA
894}
895
69e2658b896void
2e1f5829897yy::]b4_parser_class_name[::yylex_ ()
69e2658b898{
30757c8c899 YYCDEBUG << "Reading a token: ";
99be0235
AD
900 yylooka_ = ]b4_c_function_call([yylex], [int],
901[[YYSTYPE*], [&yylval]][]dnl
902b4_location_if([, [[location*], [&yylloc]]])dnl
903m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
69e2658b
RA
904}
905
f69a4142906// Generate an error message, and invoke error.
a08460b0907void
f69a4142908yy::]b4_parser_class_name[::yyreport_syntax_error_ ()
a08460b0
AD
909{
910 /* If not already recovering from an error, report this error. */
617a8f12911 if (!yyerrstatus_)
a08460b0912 {
617a8f12913 ++yynerrs_;
efeed023914 std::string message;
a08460b0915#if YYERROR_VERBOSE
617a8f12
AD
916 yyn_ = yypact_[yystate_];
917 if (yypact_ninf_ < yyn_ && yyn_ < yylast_)
a08460b0918 {
fd19f271
AD
919 /* Start YYX at -YYN if negative to avoid negative indexes in
920 YYCHECK. */
921 int yyxbegin = yyn_ < 0 ? -yyn_ : 0;
922
923 /* Stay within bounds of both yycheck and yytname. */
924 int yychecklim = yylast_ - yyn_;
925 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
926 int count = 0;
927 for (int x = yyxbegin; x < yyxend; ++x)
928 if (yycheck_[x + yyn_] == x && x != yyterror_)
929 ++count;
930
30757c8c
PE
931 // FIXME: This method of building the message is not compatible
932 // with internationalization. It should work like yacc.c does it.
933 // That is, first build a string that looks like this:
934 // "syntax error, unexpected %s or %s or %s"
935 // Then, invoke YY_ on this string.
936 // Finally, use the string as a format to output
9e0876fb937 // yytname_[yyilooka_], etc.
30757c8c
PE
938 // Until this gets fixed, this message appears in English only.
939 message = "syntax error, unexpected ";
9e0876fb940 message += yytnamerr_ (yytname_[yyilooka_]);
fd19f271
AD
941 if (count < 5)
942 {
943 count = 0;
944 for (int x = yyxbegin; x < yyxend; ++x)
945 if (yycheck_[x + yyn_] == x && x != yyterror_)
946 {
30757c8c947 message += (!count++) ? ", expecting " : " or ";
9e0876fb948 message += yytnamerr_ (yytname_[x]);
04098407949 }
fd19f271950 }
a08460b0
AD
951 }
952 else
953#endif
30757c8c954 message = YY_("syntax error");
99880de5955 error (yylloc, message);
a08460b0
AD
956 }
957}
958
5348bfbe959
c5e3e510960/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2b548aa6961 STATE-NUM. */
617a8f12962const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
c5e3e510963const ]b4_int_type_for([b4_pact])[
617a8f12964yy::]b4_parser_class_name[::yypact_[] =
2b548aa6965{
c5e3e510966 ]b4_pact[
2b548aa6
RA
967};
968
c5e3e510969/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
2b548aa6
RA
970 doesn't specify something else to do. Zero means the default is an
971 error. */
c5e3e510972const ]b4_int_type_for([b4_defact])[
617a8f12973yy::]b4_parser_class_name[::yydefact_[] =
2b548aa6974{
c5e3e510975 ]b4_defact[
2b548aa6
RA
976};
977
c5e3e510
AD
978/* YYPGOTO[NTERM-NUM]. */
979const ]b4_int_type_for([b4_pgoto])[
617a8f12980yy::]b4_parser_class_name[::yypgoto_[] =
2b548aa6981{
c5e3e510982 ]b4_pgoto[
2b548aa6
RA
983};
984
c5e3e510
AD
985/* YYDEFGOTO[NTERM-NUM]. */
986const ]b4_int_type_for([b4_defgoto])[
617a8f12987yy::]b4_parser_class_name[::yydefgoto_[] =
2b548aa6988{
c5e3e510989 ]b4_defgoto[
2b548aa6
RA
990};
991
c5e3e510992/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2b548aa6
RA
993 positive, shift that token. If negative, reduce the rule which
994 number is the opposite. If zero, do what YYDEFACT says. */
617a8f12995const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
c5e3e510996const ]b4_int_type_for([b4_table])[
617a8f12997yy::]b4_parser_class_name[::yytable_[] =
2b548aa6998{
c5e3e510999 ]b4_table[
2b548aa6
RA
1000};
1001
1002/* YYCHECK. */
c5e3e5101003const ]b4_int_type_for([b4_check])[
617a8f121004yy::]b4_parser_class_name[::yycheck_[] =
2b548aa61005{
c5e3e5101006 ]b4_check[
2b548aa6
RA
1007};
1008
c5e3e5101009/* STOS_[STATE-NUM] -- The (internal number of the) accessing
769b430f1010 symbol of state STATE-NUM. */
c5e3e5101011const ]b4_int_type_for([b4_stos])[
617a8f121012yy::]b4_parser_class_name[::yystos_[] =
769b430f1013{
c5e3e5101014 ]b4_stos[
769b430f
AD
1015};
1016
45d5982f1017#if YYDEBUG
617a8f121018/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
769b430f1019 to YYLEX-NUM. */
c5e3e5101020const ]b4_int_type_for([b4_toknum])[
617a8f121021yy::]b4_parser_class_name[::yytoken_number_[] =
769b430f1022{
c5e3e5101023 ]b4_toknum[
769b430f
AD
1024};
1025#endif
1026
c5e3e510
AD
1027/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1028const ]b4_int_type_for([b4_r1])[
617a8f121029yy::]b4_parser_class_name[::yyr1_[] =
2b548aa61030{
c5e3e5101031 ]b4_r1[
2b548aa6
RA
1032};
1033
c5e3e510
AD
1034/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1035const ]b4_int_type_for([b4_r2])[
617a8f121036yy::]b4_parser_class_name[::yyr2_[] =
2b548aa61037{
c5e3e5101038 ]b4_r2[
2b548aa6
RA
1039};
1040
141f57931041#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
c5e3e5101042/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
617a8f121043 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
2b548aa61044const char*
9e0876fb1045const yy::]b4_parser_class_name[::yytname_[] =
2b548aa61046{
c5e3e5101047 ]b4_tname[
2b548aa61048};
69e2658b1049#endif
2b548aa61050
69e2658b1051#if YYDEBUG
2b548aa61052/* YYRHS -- A `-1'-separated list of the rules' RHS. */
99880de51053const yy::]b4_parser_class_name[::rhs_number_type
617a8f121054yy::]b4_parser_class_name[::yyrhs_[] =
2b548aa61055{
c5e3e5101056 ]b4_rhs[
2b548aa6
RA
1057};
1058
c5e3e5101059/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2b548aa61060 YYRHS. */
c5e3e5101061const ]b4_int_type_for([b4_prhs])[
617a8f121062yy::]b4_parser_class_name[::yyprhs_[] =
2b548aa61063{
c5e3e5101064 ]b4_prhs[
2b548aa6
RA
1065};
1066
617a8f121067/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
c5e3e5101068const ]b4_int_type_for([b4_rline])[
617a8f121069yy::]b4_parser_class_name[::yyrline_[] =
69e2658b1070{
c5e3e5101071 ]b4_rline[
69e2658b1072};
5348bfbe1073
617a8f121074// Print the state stack on the debug stream.
25f66e1a1075void
f69a41421076yy::]b4_parser_class_name[::yystack_print_ ()
25f66e1a1077{
30757c8c1078 *yycdebug_ << "Stack now";
e019c2471079 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
617a8f121080 i != yystate_stack_.end (); ++i)
9a1e9989
AD
1081 *yycdebug_ << ' ' << *i;
1082 *yycdebug_ << std::endl;
25f66e1a
AD
1083}
1084
617a8f121085// Report on the debug stream that the rule \a yyrule is going to be reduced.
5348bfbe1086void
f69a41421087yy::]b4_parser_class_name[::yyreduce_print_ (int yyrule)
5348bfbe1088{
617a8f121089 unsigned int yylno = yyrline_[yyrule];
5348bfbe1090 /* Print the symbols being reduced, and their result. */
30757c8c
PE
1091 *yycdebug_ << "Reducing stack by rule " << yyn_ - 1
1092 << " (line " << yylno << "), ";
617a8f12
AD
1093 for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyn_];
1094 0 <= yyrhs_[i]; ++i)
9e0876fb
PE
1095 *yycdebug_ << yytname_[yyrhs_[i]] << ' ';
1096 *yycdebug_ << "-> " << yytname_[yyr1_[yyn_]] << std::endl;
5348bfbe
AD
1097}
1098#endif // YYDEBUG
69e2658b1099
2b548aa61100/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
99880de51101yy::]b4_parser_class_name[::token_number_type
f69a41421102yy::]b4_parser_class_name[::yytranslate_ (int token)
2b548aa61103{
a75c057f1104 static
99880de51105 const token_number_type
1d4055aa1106 translate_table[] =
2b548aa61107 {
c5e3e5101108 ]b4_translate[
2b548aa61109 };
617a8f121110 if ((unsigned int) token <= yyuser_token_number_max_)
1d4055aa1111 return translate_table[token];
007a50a41112 else
617a8f121113 return yyundef_token_;
2b548aa6
RA
1114}
1115
617a8f12
AD
1116const int yy::]b4_parser_class_name[::yyeof_ = 0;
1117const int yy::]b4_parser_class_name[::yylast_ = ]b4_last[;
1118const int yy::]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1119const int yy::]b4_parser_class_name[::yyempty_ = -2;
1120const int yy::]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1121const int yy::]b4_parser_class_name[::yyterror_ = 1;
1122const int yy::]b4_parser_class_name[::yyerrcode_ = 256;
1123const int yy::]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1124
1125const unsigned int yy::]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
99880de51126const yy::]b4_parser_class_name[::token_number_type yy::]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
2b548aa61127
c5e3e5101128]b4_epilogue
21846f691129dnl
6ad762a81130@output stack.hh
010f91c31131b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[
982543601132
2b548aa6
RA
1133#ifndef BISON_STACK_HH
1134# define BISON_STACK_HH
1135
45119f041136#include <deque>
2b548aa6
RA
1137
1138namespace yy
1139{
f85a5e6f1140 template <class T, class S = std::deque<T> >
99880de51141 class stack
2b548aa6
RA
1142 {
1143 public:
1144
ecfe33e7
AD
1145 // Hide our reversed order.
1146 typedef typename S::reverse_iterator iterator;
1147 typedef typename S::const_reverse_iterator const_iterator;
2b548aa61148
99880de51149 stack () : seq_ ()
2b548aa6
RA
1150 {
1151 }
1152
99880de51153 stack (unsigned int n) : seq_ (n)
2b548aa6
RA
1154 {
1155 }
1156
1157 inline
1158 T&
779e7ceb1159 operator [] (unsigned int i)
2b548aa61160 {
1d4055aa1161 return seq_[i];
2b548aa6
RA
1162 }
1163
1164 inline
1165 const T&
779e7ceb1166 operator [] (unsigned int i) const
2b548aa61167 {
1d4055aa1168 return seq_[i];
2b548aa6
RA
1169 }
1170
1171 inline
1172 void
1173 push (const T& t)
1174 {
45119f041175 seq_.push_front (t);
2b548aa6
RA
1176 }
1177
1178 inline
1179 void
779e7ceb1180 pop (unsigned int n = 1)
2b548aa6
RA
1181 {
1182 for (; n; --n)
45119f041183 seq_.pop_front ();
2b548aa6
RA
1184 }
1185
762a801e1186 inline
779e7ceb1187 unsigned int
762a801e
RA
1188 height () const
1189 {
1190 return seq_.size ();
1191 }
1192
ecfe33e7
AD
1193 inline const_iterator begin () const { return seq_.rbegin (); }
1194 inline const_iterator end () const { return seq_.rend (); }
2b548aa6
RA
1195
1196 private:
1197
1198 S seq_;
1199 };
374f5a141200
e019c2471201 /// Present a slice of the top of a stack.
99880de5
AD
1202 template <class T, class S = stack<T> >
1203 class slice
374f5a14
RA
1204 {
1205 public:
1206
99880de51207 slice (const S& stack,
779e7ceb
PE
1208 unsigned int range) : stack_ (stack),
1209 range_ (range)
374f5a14
RA
1210 {
1211 }
1212
1213 inline
1214 const T&
779e7ceb1215 operator [] (unsigned int i) const
374f5a141216 {
1d4055aa1217 return stack_[range_ - i];
374f5a14
RA
1218 }
1219
1220 private:
1221
1222 const S& stack_;
779e7ceb1223 unsigned int range_;
374f5a141224 };
2b548aa6
RA
1225}
1226
c5e3e5101227#endif // not BISON_STACK_HH]
21846f691228dnl
5d0031161229@output position.hh
010f91c31230b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004, 2005])[
982543601231
5d003116
AD
1232/**
1233 ** \file position.hh
99880de51234 ** Define the position class.
5d003116
AD
1235 */
1236
1237#ifndef BISON_POSITION_HH
1238# define BISON_POSITION_HH
2b548aa61239
7548fed2
AD
1240# include <iostream>
1241# include <string>
1242
2b548aa6
RA
1243namespace yy
1244{
99880de5
AD
1245 /// Abstract a position.
1246 class position
2b548aa61247 {
7548fed21248 public:
f69a41421249 /// Initial column number.
5d0031161250 static const unsigned int initial_column = 0;
f69a41421251 /// Initial line number.
5d003116
AD
1252 static const unsigned int initial_line = 1;
1253
1254 /** \name Ctor & dtor.
1255 ** \{ */
1256 public:
99880de5
AD
1257 /// Construct a position.
1258 position () :
b47dbebe1259 filename (0),
5d003116
AD
1260 line (initial_line),
1261 column (initial_column)
1262 {
1263 }
1264 /** \} */
1265
7548fed21266
5d003116
AD
1267 /** \name Line and Column related manipulators
1268 ** \{ */
1269 public:
f69a41421270 /// (line related) Advance to the COUNT next lines.
2ffbee0e1271 inline void lines (int count = 1)
5d003116
AD
1272 {
1273 column = initial_column;
2ffbee0e1274 line += count;
5d003116
AD
1275 }
1276
f69a41421277 /// (column related) Advance to the COUNT next columns.
2ffbee0e1278 inline void columns (int count = 1)
5d0031161279 {
f939fc12
AD
1280 int leftmost = initial_column;
1281 int current = column;
2ffbee0e
PE
1282 if (leftmost <= current + count)
1283 column += count;
2cdc240e
AD
1284 else
1285 column = initial_column;
5d003116
AD
1286 }
1287 /** \} */
1288
1289 public:
f69a41421290 /// File name to which this position refers.
b47dbebe1291 ]b4_filename_type[* filename;
f69a41421292 /// Current line number.
5d0031161293 unsigned int line;
f69a41421294 /// Current column number.
5d0031161295 unsigned int column;
2b548aa6
RA
1296 };
1297
99880de5
AD
1298 /// Add and assign a position.
1299 inline const position&
1300 operator+= (position& res, const int width)
5d003116
AD
1301 {
1302 res.columns (width);
1303 return res;
1304 }
1305
99880de5
AD
1306 /// Add two position objects.
1307 inline const position
1308 operator+ (const position& begin, const int width)
5d0031161309 {
99880de51310 position res = begin;
5d003116
AD
1311 return res += width;
1312 }
1313
99880de5
AD
1314 /// Add and assign a position.
1315 inline const position&
1316 operator-= (position& res, const int width)
5d003116
AD
1317 {
1318 return res += -width;
1319 }
1320
99880de5
AD
1321 /// Add two position objects.
1322 inline const position
1323 operator- (const position& begin, const int width)
5d003116
AD
1324 {
1325 return begin + -width;
1326 }
1327
1328 /** \brief Intercept output stream redirection.
1329 ** \param ostr the destination output stream
99880de51330 ** \param pos a reference to the position to redirect
5d0031161331 */
7548fed21332 inline std::ostream&
99880de51333 operator<< (std::ostream& ostr, const position& pos)
7548fed21334 {
b47dbebe
PE
1335 if (pos.filename)
1336 ostr << *pos.filename << ':';
5d0031161337 return ostr << pos.line << '.' << pos.column;
7548fed2
AD
1338 }
1339
5d003116
AD
1340}
1341#endif // not BISON_POSITION_HH]
1342@output location.hh
010f91c31343b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004, 2005])[
7548fed21344
5d003116
AD
1345/**
1346 ** \file location.hh
99880de51347 ** Define the location class.
5d0031161348 */
7548fed21349
5d003116
AD
1350#ifndef BISON_LOCATION_HH
1351# define BISON_LOCATION_HH
1352
1353# include <iostream>
1354# include <string>
1355# include "position.hh"
1356
1357namespace yy
1358{
1359
99880de5
AD
1360 /// Abstract a location.
1361 class location
2b548aa61362 {
5d003116
AD
1363 /** \name Ctor & dtor.
1364 ** \{ */
7548fed21365 public:
99880de51366 /// Construct a location.
e019c2471367 location () :
5d003116
AD
1368 begin (),
1369 end ()
1370 {
1371 }
1372 /** \} */
1373
1374
1375 /** \name Line and Column related manipulators
1376 ** \{ */
1377 public:
f69a41421378 /// Reset initial location to final location.
e019c2471379 inline void step ()
5d003116
AD
1380 {
1381 begin = end;
1382 }
1383
f69a41421384 /// Extend the current location to the COUNT next columns.
2ffbee0e1385 inline void columns (unsigned int count = 1)
5d0031161386 {
2ffbee0e1387 end += count;
5d003116
AD
1388 }
1389
f69a41421390 /// Extend the current location to the COUNT next lines.
2ffbee0e1391 inline void lines (unsigned int count = 1)
5d0031161392 {
2ffbee0e1393 end.lines (count);
5d003116
AD
1394 }
1395 /** \} */
1396
1397
1398 public:
f69a41421399 /// Beginning of the located region.
99880de51400 position begin;
f69a41421401 /// End of the located region.
99880de51402 position end;
2b548aa61403 };
7548fed21404
99880de5
AD
1405 /// Join two location objects to create a location.
1406 inline const location operator+ (const location& begin, const location& end)
5d0031161407 {
99880de51408 location res = begin;
5d003116
AD
1409 res.end = end.end;
1410 return res;
1411 }
1412
99880de5
AD
1413 /// Add two location objects.
1414 inline const location operator+ (const location& begin, unsigned int width)
5d0031161415 {
99880de51416 location res = begin;
5d003116
AD
1417 res.columns (width);
1418 return res;
1419 }
7548fed21420
99880de5
AD
1421 /// Add and assign a location.
1422 inline location& operator+= (location& res, unsigned int width)
5d003116
AD
1423 {
1424 res.columns (width);
1425 return res;
1426 }
1427
1428 /** \brief Intercept output stream redirection.
1429 ** \param ostr the destination output stream
99880de51430 ** \param loc a reference to the location to redirect
5d0031161431 **
2cdc240e1432 ** Avoid duplicate information.
5d0031161433 */
99880de51434 inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
7548fed21435 {
99880de51436 position last = loc.end - 1;
2cdc240e1437 ostr << loc.begin;
b47dbebe
PE
1438 if (last.filename
1439 && (!loc.begin.filename
1440 || *loc.begin.filename != *last.filename))
2cdc240e
AD
1441 ostr << '-' << last;
1442 else if (loc.begin.line != last.line)
1443 ostr << '-' << last.line << '.' << last.column;
1444 else if (loc.begin.column != last.column)
1445 ostr << '-' << last.column;
7548fed2
AD
1446 return ostr;
1447 }
1448
2b548aa6
RA
1449}
1450
c5e3e5101451#endif // not BISON_LOCATION_HH]