]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
Regenerate.
[bison.git] / data / lalr1.cc
CommitLineData
a75c057f 1m4_divert(-1)
b4721715 2
60491a94 3# 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
60491a94 21
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],
bc82c5a5 40[(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],
bc82c5a5 48[(yysemantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3]))])
82b6cb3f 49
99880de5 50m4_define_default([b4_location_type], [location])
9a0d8bec 51m4_define_default([b4_filename_type], [std::string])
82b6cb3f
AD
52
53# b4_lhs_location()
54# -----------------
55# Expansion of @$.
56m4_define([b4_lhs_location],
bc82c5a5 57[(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],
bc82c5a5 65[(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.
caf37a36 74m4_define([b4_parse_param_decl],
6dde1c82 75[m4_ifset([b4_parse_param],
a3cb6248 76 [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# -------------------
6dde1c82 85# 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],
6dde1c82 94 [$2 ($2_yyarg)])
caf37a36
ADL
95
96# b4_parse_param_vars
97# -------------------
6dde1c82 98# 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
a5eb1ed2 110
a5eb1ed2 111
b526ee61
AD
112# We do want M4 expansion after # for CPP macros.
113m4_changecom()
98254360 114m4_divert(0)dnl
b61c6978
PE
115m4_if(b4_defines_flag, 0, [],
116[@output @output_header_name@
fb8135fa 117b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
010f91c3 118 [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
2b548aa6 123
8d69a1a3 124#include <string>
717be197 125#include <iostream>
50997c6e 126
4162fa07 127/* Using locations. */
c5e3e510 128#define YYLSP_NEEDED ]b4_locations_flag[
4162fa07 129
d390b02b
AD
130namespace yy
131{
132 class position;
133 class location;
134}
135
c5e3e510 136]b4_token_defines(b4_tokens)[
17acead5 137
0dd1580a 138/* Copy the first part of user declarations. */
c5e3e510 139]b4_pre_prologue[
4162fa07 140
996b1c7e 141]/* Line __line__ of lalr1.cc. */
c5e3e510 142b4_syncline([@oline@], [@ofile@])[
e96c9728 143
9a0d8bec
AD
144#include "stack.hh"
145#include "location.hh"
146
69e2658b
RA
147/* Enabling traces. */
148#ifndef YYDEBUG
c5e3e510 149# define YYDEBUG ]b4_debug[
69e2658b
RA
150#endif
151
152/* Enabling verbose error message. */
153#ifndef YYERROR_VERBOSE
c5e3e510 154# define YYERROR_VERBOSE ]b4_error_verbose[
69e2658b
RA
155#endif
156
be3d9d42 157#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
c5e3e510 158]m4_ifdef([b4_stype],
437c2d80 159[b4_syncline([b4_stype_line], [b4_filename])
be3d9d42 160union YYSTYPE b4_stype;
996b1c7e 161/* Line __line__ of lalr1.cc. */
6ad762a8 162b4_syncline([@oline@], [@ofile@])],
be3d9d42
AD
163[typedef int YYSTYPE;])[
164# define yystype YYSTYPE /* obsolescent; will be withdrawn */
165# define YYSTYPE_IS_DECLARED 1
166# define YYSTYPE_IS_TRIVIAL 1
98254360
RA
167#endif
168
0dd1580a 169/* Copy the second part of user declarations. */
c5e3e510 170]b4_post_prologue[
0dd1580a 171
996b1c7e 172]/* Line __line__ of lalr1.cc. */
c5e3e510 173b4_syncline([@oline@], [@ofile@])[
b4a20338
AD
174/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
175 If N is 0, then set CURRENT to the empty location which ends
176 the previous symbol: RHS[0] (always defined). */
3fc16193 177
374f5a14 178#ifndef YYLLOC_DEFAULT
b4a20338
AD
179# define YYLLOC_DEFAULT(Current, Rhs, N) \
180do { \
181 if (N) \
182 { \
183 (Current).begin = (Rhs)[1].begin; \
184 (Current).end = (Rhs)[N].end; \
185 } \
186 else \
187 { \
188 (Current).begin = (Current).end = (Rhs)[0].end; \
189 } \
3fc16193 190} while (0)
374f5a14
RA
191#endif
192
2b548aa6
RA
193namespace yy
194{
c5e3e510 195 class ]b4_parser_class_name[;
3f3eed27 196
f85a5e6f 197 template <typename P>
99880de5 198 struct traits
2b548aa6
RA
199 {
200 };
201
f85a5e6f 202 template <>
99880de5 203 struct traits<]b4_parser_class_name[>
2b548aa6 204 {
99880de5
AD
205 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
206 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
207 typedef int state_type;
208 typedef YYSTYPE semantic_type;
209 typedef ]b4_location_type[ location_type;
2b548aa6
RA
210 };
211}
212
2b548aa6
RA
213namespace yy
214{
efeed023 215 /// A Bison parser.
07fed891 216 class ]b4_parser_class_name[
2b548aa6 217 {
617a8f12 218 /// Symbol semantic values.
e019c247 219 typedef traits<]b4_parser_class_name[>::semantic_type semantic_type;
617a8f12 220 /// Symbol locations.
e019c247 221 typedef traits<]b4_parser_class_name[>::location_type location_type;
2b548aa6 222
e019c247 223 public:
efeed023 224 /// Build a parser object.
a3cb6248
AD
225 ]b4_parser_class_name[ (]b4_parse_param_decl[) :
226 yydebug_ (false),
9a1e9989 227 yycdebug_ (&std::cerr)]b4_parse_param_cons[
50997c6e 228 {
50997c6e
RA
229 }
230
c5e3e510 231 virtual ~]b4_parser_class_name[ ()
2b548aa6 232 {
2b548aa6
RA
233 }
234
f69a4142
AD
235 /// Parse.
236 /// \returns 0 iff parsing succeeded.
e019c247 237 virtual int parse ();
2b548aa6 238
f69a4142 239 /// The current debugging stream.
9a1e9989
AD
240 std::ostream& debug_stream () const;
241 /// Set the current debugging stream.
242 void set_debug_stream (std::ostream &);
243
a3cb6248
AD
244 /// Type for debugging levels.
245 typedef int debug_level_type;
246 /// The current debugging level.
247 debug_level_type debug_level () const;
248 /// Set the current debugging level.
249 void set_debug_level (debug_level_type l);
250
2b548aa6 251 private:
3f3eed27 252
f69a4142 253 /// Call the scanner.
2e1f5829 254 virtual void yylex_ ();
efeed023
AD
255
256 /// Report a syntax error.
257 /// \param loc where the syntax error is found.
258 /// \param msg a description of the syntax error.
99880de5 259 virtual void error (const location_type& loc, const std::string& msg);
efeed023
AD
260
261 /// Generate an error message, and invoke error.
f69a4142 262 virtual void yyreport_syntax_error_ ();
efeed023 263
a5eb1ed2 264#if YYDEBUG
f69a4142
AD
265 /// \brief Report a symbol on the debug stream.
266 /// \param yytype The token type.
267 /// \param yyvaluep Its semantic value.
268 /// \param yylocationp Its location.
269 virtual void yysymprint_ (int yytype,
99880de5
AD
270 const semantic_type* yyvaluep,
271 const location_type* yylocationp);
a5eb1ed2
AD
272#endif /* ! YYDEBUG */
273
4bb2bc3f 274
e019c247
AD
275 /// State numbers.
276 typedef traits<]b4_parser_class_name[>::state_type state_type;
277 /// State stack type.
278 typedef stack<state_type> state_stack_type;
279 /// Semantic value stack type.
280 typedef stack<semantic_type> semantic_stack_type;
281 /// location stack type.
282 typedef stack<location_type> location_stack_type;
283
f69a4142 284 /// The state stack.
e019c247 285 state_stack_type yystate_stack_;
f69a4142 286 /// The semantic value stack.
e019c247 287 semantic_stack_type yysemantic_stack_;
f69a4142 288 /// The location stack.
e019c247 289 location_stack_type yylocation_stack_;
2b548aa6 290
e019c247
AD
291 /// Internal symbol numbers.
292 typedef traits<]b4_parser_class_name[>::token_number_type token_number_type;
2b548aa6 293 /* Tables. */
efeed023 294 /// For a state, the index in \a yytable_ of its portion.
617a8f12
AD
295 static const ]b4_int_type_for([b4_pact])[ yypact_[];
296 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
efeed023
AD
297
298 /// For a state, default rule to reduce.
299 /// Unless\a yytable_ specifies something else to do.
300 /// Zero means the default is an error.
617a8f12 301 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
efeed023 302
617a8f12
AD
303 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
304 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
efeed023
AD
305
306 /// What to do in a state.
307 /// \a yytable_[yypact_[s]]: what to do in state \a s.
308 /// - if positive, shift that token.
309 /// - if negative, reduce the rule which number is the opposite.
310 /// - if zero, do what YYDEFACT says.
617a8f12
AD
311 static const ]b4_int_type_for([b4_table])[ yytable_[];
312 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
efeed023 313
617a8f12 314 static const ]b4_int_type_for([b4_check])[ yycheck_[];
efeed023
AD
315
316 /// For a state, its accessing symbol.
617a8f12 317 static const ]b4_int_type_for([b4_stos])[ yystos_[];
efeed023
AD
318
319 /// For a rule, its LHS.
617a8f12 320 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
efeed023 321 /// For a rule, its RHS length.
617a8f12 322 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
69e2658b
RA
323
324#if YYDEBUG || YYERROR_VERBOSE
efeed023 325 /// For a symbol, its name in clear.
617a8f12 326 static const char* const yyname_[];
69e2658b 327#endif
2b548aa6 328
69e2658b 329#if YYDEBUG
e019c247
AD
330 /// A type to store symbol numbers and -1.
331 typedef traits<]b4_parser_class_name[>::rhs_number_type rhs_number_type;
617a8f12 332 /// A `-1'-separated list of the rules' RHS.
99880de5 333 static const rhs_number_type yyrhs_[];
617a8f12
AD
334 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
335 static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
336 /// For each rule, its source line number.
337 static const ]b4_int_type_for([b4_rline])[ yyrline_[];
338 /// For each scanner token number, its symbol number.
339 static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
efeed023
AD
340 /// Report on the debug stream that the rule \a r is going to be reduced.
341 virtual void yyreduce_print_ (int r);
342 /// Print the state stack on the debug stream.
f69a4142 343 virtual void yystack_print_ ();
69e2658b 344#endif
2b548aa6 345
f69a4142 346 /// Convert a scanner token number to a symbol number.
99880de5 347 inline token_number_type yytranslate_ (int token);
f69a4142
AD
348
349 /// \brief Reclaim the memory associated to a symbol.
350 /// \param yymsg Why this token is reclaimed.
351 /// \param yytype The symbol type.
352 /// \param yyvaluep Its semantic value.
353 /// \param yylocationp Its location.
354 inline void yydestruct_ (const char* yymsg,
355 int yytype,
99880de5
AD
356 semantic_type* yyvaluep,
357 location_type* yylocationp);
2b548aa6 358
52d5733f 359 /// Pop \a n symbols the three stacks.
f69a4142 360 inline void yypop_ (unsigned int n = 1);
52d5733f 361
762a801e 362 /* Constants. */
617a8f12 363 static const int yyeof_;
39912f52 364 /* LAST_ -- Last index in TABLE_. */
617a8f12
AD
365 static const int yylast_;
366 static const int yynnts_;
367 static const int yyempty_;
368 static const int yyfinal_;
369 static const int yyterror_;
370 static const int yyerrcode_;
371 static const int yyntokens_;
372 static const unsigned int yyuser_token_number_max_;
99880de5 373 static const token_number_type yyundef_token_;
2b548aa6
RA
374
375 /* State. */
617a8f12
AD
376 int yyn_;
377 int yylen_;
378 int yystate_;
4bb2bc3f 379
a08460b0 380 /* Error handling. */
617a8f12
AD
381 int yynerrs_;
382 int yyerrstatus_;
a08460b0 383
717be197 384 /* Debugging. */
a3cb6248 385 int yydebug_;
9a1e9989 386 std::ostream* yycdebug_;
717be197 387
8dd162d3 388 /* Look-ahead and look-ahead in internal form. */
617a8f12
AD
389 int yylooka_;
390 int yyilooka_;
4bb2bc3f 391
451364ed 392 /// Semantic value of the look-ahead.
99880de5 393 semantic_type yylval;
451364ed 394 /// Location of the look-ahead.
99880de5 395 location_type yylloc;
3fc16193 396 /// The locations where the error started and ended.
99880de5 397 location yyerror_range_[2];
8d69a1a3 398
451364ed 399 /// $$.
99880de5 400 semantic_type yyval;
451364ed 401 /// @@$.
99880de5 402 location_type yyloc;
caf37a36 403]b4_parse_param_vars[
2b548aa6
RA
404 };
405}
406
c5e3e510 407#endif /* ! defined PARSER_HEADER_H */]
b61c6978 408])dnl
6ad762a8 409@output @output_parser_name@
fb8135fa 410b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
010f91c3 411 [2002, 2003, 2004, 2005])
c5b95ccf
AD
412m4_if(b4_prefix[], [yy], [],
413[
414// Take the name prefix into account.
415#define yylex b4_prefix[]lex])
416m4_if(b4_defines_flag, 0, [],
417[
418#include @output_header_name@])[
50997c6e 419
989b5b8e
AD
420/* INFRINGES ON USER NAME SPACE */
421#ifndef _
422# define _(msgid) msgid
423#endif
424
a3cb6248 425/* A pseudo ostream that takes yydebug_ into account. */
9a1e9989 426# define YYCDEBUG \
a3cb6248 427 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
9a1e9989
AD
428 (*yycdebug_)
429
2b548aa6 430/* Enable debugging if requested. */
50997c6e 431#if YYDEBUG
284acc8b 432
284acc8b
AD
433# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
434do { \
a3cb6248 435 if (yydebug_) \
284acc8b 436 { \
9a1e9989 437 *yycdebug_ << (Title) << ' '; \
f69a4142 438 yysymprint_ ((Type), (Value), (Location)); \
9a1e9989 439 *yycdebug_ << std::endl; \
284acc8b
AD
440 } \
441} while (0)
442
5348bfbe
AD
443# define YY_REDUCE_PRINT(Rule) \
444do { \
a3cb6248 445 if (yydebug_) \
f69a4142 446 yyreduce_print_ (Rule); \
5348bfbe 447} while (0)
284acc8b 448
25f66e1a
AD
449# define YY_STACK_PRINT() \
450do { \
a3cb6248 451 if (yydebug_) \
f69a4142 452 yystack_print_ (); \
25f66e1a 453} while (0)
284acc8b 454
2b548aa6 455#else /* !YYDEBUG */
284acc8b 456
284acc8b 457# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
5348bfbe 458# define YY_REDUCE_PRINT(Rule)
25f66e1a 459# define YY_STACK_PRINT()
284acc8b 460
2b548aa6
RA
461#endif /* !YYDEBUG */
462
60a777aa
AD
463#define YYACCEPT goto yyacceptlab
464#define YYABORT goto yyabortlab
47301314 465#define YYERROR goto yyerrorlab
60a777aa 466
a5eb1ed2 467#if YYDEBUG
a0e68930
AD
468/*--------------------------------.
469| Print this symbol on YYOUTPUT. |
470`--------------------------------*/
471
472void
f69a4142 473yy::]b4_parser_class_name[::yysymprint_ (int yytype,
99880de5 474 const semantic_type* yyvaluep, const location_type* yylocationp)
a0e68930
AD
475{
476 /* Pacify ``unused variable'' warnings. */
477 (void) yyvaluep;
478 (void) yylocationp;
9a1e9989
AD
479 /* Backward compatibility, but should be removed eventually. */
480 std::ostream& cdebug_ = *yycdebug_;
c1f8f16a 481 (void) cdebug_;
a0e68930 482
617a8f12
AD
483 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
484 << ' ' << yyname_[yytype] << " ("
9a1e9989 485 << *yylocationp << ": ";
a0e68930
AD
486 switch (yytype)
487 {
488]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
489[ default:
490 break;
491 }
9a1e9989 492 *yycdebug_ << ')';
a0e68930 493}
a5eb1ed2 494#endif /* ! YYDEBUG */
a0e68930
AD
495
496void
f69a4142 497yy::]b4_parser_class_name[::yydestruct_ (const char* yymsg,
99880de5 498 int yytype, semantic_type* yyvaluep, location_type* yylocationp)
a0e68930
AD
499{
500 /* Pacify ``unused variable'' warnings. */
895789c6 501 (void) yymsg;
a0e68930
AD
502 (void) yyvaluep;
503 (void) yylocationp;
504
a0e68930
AD
505 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
506
507 switch (yytype)
508 {
509]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
510 default:
511 break;
512 }
513}
60a777aa 514
52d5733f 515void
f69a4142 516yy::]b4_parser_class_name[::yypop_ (unsigned int n)
52d5733f 517{
617a8f12
AD
518 yystate_stack_.pop (n);
519 yysemantic_stack_.pop (n);
520 yylocation_stack_.pop (n);
52d5733f
AD
521}
522
9a1e9989
AD
523std::ostream&
524yy::]b4_parser_class_name[::debug_stream () const
525{
526 return *yycdebug_;
527}
528
529void
530yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o)
531{
532 yycdebug_ = &o;
533}
534
535
a3cb6248
AD
536yy::]b4_parser_class_name[::debug_level_type
537yy::]b4_parser_class_name[::debug_level () const
538{
539 return yydebug_;
540}
541
542void
543yy::]b4_parser_class_name[::set_debug_level (debug_level_type l)
544{
545 yydebug_ = l;
546}
547
548
e019c247 549int
c5e3e510 550yy::]b4_parser_class_name[::parse ()
2b548aa6 551{
ad745863
PE
552 int yyresult_;
553
989b5b8e 554 YYCDEBUG << _("Starting parse") << std::endl;
451364ed 555
617a8f12
AD
556 yynerrs_ = 0;
557 yyerrstatus_ = 0;
4bb2bc3f 558
451364ed 559 /* Start. */
617a8f12
AD
560 yystate_ = 0;
561 yylooka_ = yyempty_;
451364ed
AD
562
563]m4_ifdef([b4_initial_action], [
99880de5
AD
564m4_pushdef([b4_at_dollar], [yylloc])dnl
565m4_pushdef([b4_dollar_dollar], [yylval])dnl
451364ed
AD
566 /* User initialization code. */
567 b4_initial_action
568m4_popdef([b4_dollar_dollar])dnl
569m4_popdef([b4_at_dollar])dnl
570/* Line __line__ of yacc.c. */
571b4_syncline([@oline@], [@ofile@])])dnl
572
573[ /* Initialize the stacks. The initial state will be pushed in
3ae831b4
AD
574 yynewstate, since the latter expects the semantical and the
575 location values to have been already stored, initialize these
576 stacks with a primary value. */
e019c247
AD
577 yystate_stack_ = state_stack_type (0);
578 yysemantic_stack_ = semantic_stack_type (0);
579 yylocation_stack_ = location_stack_type (0);
99880de5
AD
580 yysemantic_stack_.push (yylval);
581 yylocation_stack_.push (yylloc);
2b548aa6
RA
582
583 /* New state. */
52d5733f 584yynewstate:
617a8f12 585 yystate_stack_.push (yystate_);
989b5b8e 586 YYCDEBUG << _("Entering state ") << yystate_ << std::endl;
50997c6e 587 goto yybackup;
2b548aa6
RA
588
589 /* Backup. */
52d5733f 590yybackup:
2b548aa6 591
8dd162d3 592 /* Try to take a decision without look-ahead. */
617a8f12
AD
593 yyn_ = yypact_[yystate_];
594 if (yyn_ == yypact_ninf_)
2b548aa6
RA
595 goto yydefault;
596
8dd162d3 597 /* Read a look-ahead token. */
617a8f12 598 if (yylooka_ == yyempty_)
2e1f5829 599 yylex_ ();
2b548aa6
RA
600
601 /* Convert token to internal form. */
617a8f12 602 if (yylooka_ <= yyeof_)
2b548aa6 603 {
617a8f12 604 yylooka_ = yyilooka_ = yyeof_;
989b5b8e 605 YYCDEBUG << _("Now at end of input.") << std::endl;
2b548aa6
RA
606 }
607 else
608 {
617a8f12 609 yyilooka_ = yytranslate_ (yylooka_);
989b5b8e 610 YY_SYMBOL_PRINT (_("Next token is"), yyilooka_, &yylval, &yylloc);
2b548aa6
RA
611 }
612
a5eb1ed2 613 /* If the proper action on seeing token ILOOKA_ is to reduce or to
47301314 614 detect an error, take that action. */
617a8f12
AD
615 yyn_ += yyilooka_;
616 if (yyn_ < 0 || yylast_ < yyn_ || yycheck_[yyn_] != yyilooka_)
2b548aa6
RA
617 goto yydefault;
618
619 /* Reduce or error. */
617a8f12
AD
620 yyn_ = yytable_[yyn_];
621 if (yyn_ < 0)
2b548aa6 622 {
617a8f12 623 if (yyn_ == yytable_ninf_)
2b548aa6
RA
624 goto yyerrlab;
625 else
626 {
617a8f12 627 yyn_ = -yyn_;
2b548aa6
RA
628 goto yyreduce;
629 }
630 }
617a8f12 631 else if (yyn_ == 0)
2b548aa6 632 goto yyerrlab;
a75c057f 633
2b548aa6 634 /* Accept? */
617a8f12 635 if (yyn_ == yyfinal_)
2b548aa6
RA
636 goto yyacceptlab;
637
8dd162d3 638 /* Shift the look-ahead token. */
989b5b8e 639 YY_SYMBOL_PRINT (_("Shifting"), yyilooka_, &yylval, &yylloc);
2b548aa6
RA
640
641 /* Discard the token being shifted unless it is eof. */
617a8f12
AD
642 if (yylooka_ != yyeof_)
643 yylooka_ = yyempty_;
2b548aa6 644
99880de5
AD
645 yysemantic_stack_.push (yylval);
646 yylocation_stack_.push (yylloc);
8d69a1a3
RA
647
648 /* Count tokens shifted since error; after three, turn off error
649 status. */
617a8f12
AD
650 if (yyerrstatus_)
651 --yyerrstatus_;
8d69a1a3 652
617a8f12 653 yystate_ = yyn_;
2b548aa6
RA
654 goto yynewstate;
655
47301314
AD
656/*-----------------------------------------------------------.
657| yydefault -- do the default action for the current state. |
658`-----------------------------------------------------------*/
52d5733f 659yydefault:
617a8f12
AD
660 yyn_ = yydefact_[yystate_];
661 if (yyn_ == 0)
2b548aa6 662 goto yyerrlab;
50997c6e 663 goto yyreduce;
2b548aa6 664
47301314
AD
665/*-----------------------------.
666| yyreduce -- Do a reduction. |
667`-----------------------------*/
52d5733f 668yyreduce:
617a8f12 669 yylen_ = yyr2_[yyn_];
47301314
AD
670 /* If LEN_ is nonzero, implement the default value of the action:
671 `$$ = $1'. Otherwise, use the top of the stack.
672
673 Otherwise, the following line sets YYVAL to garbage.
674 This behavior is undocumented and Bison
675 users should not rely upon it. */
617a8f12
AD
676 if (yylen_)
677 yyval = yysemantic_stack_[yylen_ - 1];
50997c6e 678 else
617a8f12 679 yyval = yysemantic_stack_[0];
2b548aa6 680
b4a20338 681 {
e019c247 682 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen_);
617a8f12 683 YYLLOC_DEFAULT (yyloc, slice, yylen_);
b4a20338 684 }
617a8f12
AD
685 YY_REDUCE_PRINT (yyn_);
686 switch (yyn_)
45119f04 687 {
c5e3e510 688 ]b4_actions[
95f22ad2 689 default: break;
45119f04 690 }
a75c057f 691
996b1c7e 692]/* Line __line__ of lalr1.cc. */
c5e3e510 693b4_syncline([@oline@], [@ofile@])[
06446ccf 694
617a8f12 695 yypop_ (yylen_);
2b548aa6 696
25f66e1a 697 YY_STACK_PRINT ();
a75c057f 698
617a8f12
AD
699 yysemantic_stack_.push (yyval);
700 yylocation_stack_.push (yyloc);
2b548aa6
RA
701
702 /* Shift the result of the reduction. */
617a8f12
AD
703 yyn_ = yyr1_[yyn_];
704 yystate_ = yypgoto_[yyn_ - yyntokens_] + yystate_stack_[0];
705 if (0 <= yystate_ && yystate_ <= yylast_
706 && yycheck_[yystate_] == yystate_stack_[0])
707 yystate_ = yytable_[yystate_];
2b548aa6 708 else
617a8f12 709 yystate_ = yydefgoto_[yyn_ - yyntokens_];
2b548aa6
RA
710 goto yynewstate;
711
47301314
AD
712/*------------------------------------.
713| yyerrlab -- here on detecting error |
714`------------------------------------*/
284acc8b 715yyerrlab:
4bb2bc3f 716 /* If not already recovering from an error, report this error. */
f69a4142 717 yyreport_syntax_error_ ();
a75c057f 718
99880de5 719 yyerror_range_[0] = yylloc;
617a8f12 720 if (yyerrstatus_ == 3)
762a801e 721 {
8dd162d3 722 /* If just tried and failed to reuse look-ahead token after an
762a801e
RA
723 error, discard it. */
724
725 /* Return failure if at end of input. */
617a8f12 726 if (yylooka_ <= yyeof_)
47301314
AD
727 {
728 /* If at end of input, pop the error token,
729 then the rest of the stack, then return failure. */
617a8f12 730 if (yylooka_ == yyeof_)
47301314
AD
731 for (;;)
732 {
617a8f12 733 yyerror_range_[0] = yylocation_stack_[0];
f69a4142 734 yypop_ ();
617a8f12 735 if (yystate_stack_.height () == 1)
47301314 736 YYABORT;
989b5b8e 737 yydestruct_ (_("Error: popping"),
617a8f12
AD
738 yystos_[yystate_stack_[0]],
739 &yysemantic_stack_[0],
740 &yylocation_stack_[0]);
47301314
AD
741 }
742 }
743 else
744 {
989b5b8e 745 yydestruct_ (_("Error: discarding"), yyilooka_, &yylval, &yylloc);
617a8f12 746 yylooka_ = yyempty_;
47301314 747 }
762a801e
RA
748 }
749
8dd162d3 750 /* Else will try to reuse look-ahead token after shifting the error
762a801e 751 token. */
47301314
AD
752 goto yyerrlab1;
753
754
755/*---------------------------------------------------.
756| yyerrorlab -- error raised explicitly by YYERROR. |
757`---------------------------------------------------*/
758yyerrorlab:
759
b4721715
PE
760 /* Pacify compilers like GCC when the user code never invokes
761 YYERROR and the label yyerrorlab therefore never appears in user
762 code. */
763 if (false)
62b6aef9 764 goto yyerrorlab;
62b6aef9 765
617a8f12
AD
766 yyerror_range_[0] = yylocation_stack_[yylen_ - 1];
767 yypop_ (yylen_);
768 yystate_ = yystate_stack_[0];
47301314 769 goto yyerrlab1;
762a801e 770
47301314
AD
771/*-------------------------------------------------------------.
772| yyerrlab1 -- common code for both syntax error and YYERROR. |
773`-------------------------------------------------------------*/
774yyerrlab1:
617a8f12 775 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
762a801e 776
769b430f
AD
777 for (;;)
778 {
617a8f12
AD
779 yyn_ = yypact_[yystate_];
780 if (yyn_ != yypact_ninf_)
769b430f 781 {
617a8f12
AD
782 yyn_ += yyterror_;
783 if (0 <= yyn_ && yyn_ <= yylast_ && yycheck_[yyn_] == yyterror_)
769b430f 784 {
617a8f12
AD
785 yyn_ = yytable_[yyn_];
786 if (0 < yyn_)
769b430f
AD
787 break;
788 }
789 }
790
791 /* Pop the current state because it cannot handle the error token. */
617a8f12 792 if (yystate_stack_.height () == 1)
47301314 793 YYABORT;
762a801e 794
617a8f12 795 yyerror_range_[0] = yylocation_stack_[0];
989b5b8e 796 yydestruct_ (_("Error: popping"),
617a8f12
AD
797 yystos_[yystate_],
798 &yysemantic_stack_[0], &yylocation_stack_[0]);
f69a4142 799 yypop_ ();
617a8f12 800 yystate_ = yystate_stack_[0];
25f66e1a 801 YY_STACK_PRINT ();
762a801e 802 }
762a801e 803
617a8f12 804 if (yyn_ == yyfinal_)
762a801e
RA
805 goto yyacceptlab;
806
99880de5
AD
807 yyerror_range_[1] = yylloc;
808 // Using YYLLOC is tempting, but would change the location of
3fc16193 809 // the look-ahead. YYLOC is available though.
617a8f12 810 YYLLOC_DEFAULT (yyloc, yyerror_range_ - 1, 2);
99880de5 811 yysemantic_stack_.push (yylval);
617a8f12 812 yylocation_stack_.push (yyloc);
762a801e 813
1576d44d 814 /* Shift the error token. */
989b5b8e 815 YY_SYMBOL_PRINT (_("Shifting"), yystos_[yyn_],
617a8f12 816 &yysemantic_stack_[0], &yylocation_stack_[0]);
1576d44d 817
617a8f12 818 yystate_ = yyn_;
762a801e
RA
819 goto yynewstate;
820
2b548aa6 821 /* Accept. */
284acc8b 822yyacceptlab:
ad745863
PE
823 yyresult_ = 0;
824 goto yyreturn;
762a801e
RA
825
826 /* Abort. */
284acc8b 827yyabortlab:
ad745863
PE
828 yyresult_ = 1;
829 goto yyreturn;
830
831yyreturn:
832 if (yylooka_ != yyeof_ && yylooka_ != yyempty_)
989b5b8e 833 yydestruct_ (_("Error: discarding lookahead"), yyilooka_, &yylval, &yylloc);
ad745863 834 return yyresult_;
2b548aa6
RA
835}
836
69e2658b 837void
2e1f5829 838yy::]b4_parser_class_name[::yylex_ ()
69e2658b 839{
989b5b8e 840 YYCDEBUG << _("Reading a token: ");
99be0235
AD
841 yylooka_ = ]b4_c_function_call([yylex], [int],
842[[YYSTYPE*], [&yylval]][]dnl
843b4_location_if([, [[location*], [&yylloc]]])dnl
844m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
69e2658b
RA
845}
846
f69a4142 847// Generate an error message, and invoke error.
a08460b0 848void
f69a4142 849yy::]b4_parser_class_name[::yyreport_syntax_error_ ()
a08460b0
AD
850{
851 /* If not already recovering from an error, report this error. */
617a8f12 852 if (!yyerrstatus_)
a08460b0 853 {
617a8f12 854 ++yynerrs_;
efeed023 855 std::string message;
a08460b0 856#if YYERROR_VERBOSE
617a8f12
AD
857 yyn_ = yypact_[yystate_];
858 if (yypact_ninf_ < yyn_ && yyn_ < yylast_)
a08460b0 859 {
fd19f271
AD
860 /* Start YYX at -YYN if negative to avoid negative indexes in
861 YYCHECK. */
862 int yyxbegin = yyn_ < 0 ? -yyn_ : 0;
863
864 /* Stay within bounds of both yycheck and yytname. */
865 int yychecklim = yylast_ - yyn_;
866 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
867 int count = 0;
868 for (int x = yyxbegin; x < yyxend; ++x)
869 if (yycheck_[x + yyn_] == x && x != yyterror_)
870 ++count;
871
989b5b8e 872 message = _("syntax error, unexpected ");
617a8f12 873 message += yyname_[yyilooka_];
fd19f271
AD
874 if (count < 5)
875 {
876 count = 0;
877 for (int x = yyxbegin; x < yyxend; ++x)
878 if (yycheck_[x + yyn_] == x && x != yyterror_)
879 {
989b5b8e 880 message += (!count++) ? _(", expecting ") : _(" or ");
fd19f271
AD
881 message += yyname_[x];
882 }
883 }
a08460b0
AD
884 }
885 else
886#endif
989b5b8e 887 message = _("syntax error");
99880de5 888 error (yylloc, message);
a08460b0
AD
889 }
890}
891
5348bfbe 892
c5e3e510 893/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2b548aa6 894 STATE-NUM. */
617a8f12 895const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
c5e3e510 896const ]b4_int_type_for([b4_pact])[
617a8f12 897yy::]b4_parser_class_name[::yypact_[] =
2b548aa6 898{
c5e3e510 899 ]b4_pact[
2b548aa6
RA
900};
901
c5e3e510 902/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
2b548aa6
RA
903 doesn't specify something else to do. Zero means the default is an
904 error. */
c5e3e510 905const ]b4_int_type_for([b4_defact])[
617a8f12 906yy::]b4_parser_class_name[::yydefact_[] =
2b548aa6 907{
c5e3e510 908 ]b4_defact[
2b548aa6
RA
909};
910
c5e3e510
AD
911/* YYPGOTO[NTERM-NUM]. */
912const ]b4_int_type_for([b4_pgoto])[
617a8f12 913yy::]b4_parser_class_name[::yypgoto_[] =
2b548aa6 914{
c5e3e510 915 ]b4_pgoto[
2b548aa6
RA
916};
917
c5e3e510
AD
918/* YYDEFGOTO[NTERM-NUM]. */
919const ]b4_int_type_for([b4_defgoto])[
617a8f12 920yy::]b4_parser_class_name[::yydefgoto_[] =
2b548aa6 921{
c5e3e510 922 ]b4_defgoto[
2b548aa6
RA
923};
924
c5e3e510 925/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2b548aa6
RA
926 positive, shift that token. If negative, reduce the rule which
927 number is the opposite. If zero, do what YYDEFACT says. */
617a8f12 928const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
c5e3e510 929const ]b4_int_type_for([b4_table])[
617a8f12 930yy::]b4_parser_class_name[::yytable_[] =
2b548aa6 931{
c5e3e510 932 ]b4_table[
2b548aa6
RA
933};
934
935/* YYCHECK. */
c5e3e510 936const ]b4_int_type_for([b4_check])[
617a8f12 937yy::]b4_parser_class_name[::yycheck_[] =
2b548aa6 938{
c5e3e510 939 ]b4_check[
2b548aa6
RA
940};
941
c5e3e510 942/* STOS_[STATE-NUM] -- The (internal number of the) accessing
769b430f 943 symbol of state STATE-NUM. */
c5e3e510 944const ]b4_int_type_for([b4_stos])[
617a8f12 945yy::]b4_parser_class_name[::yystos_[] =
769b430f 946{
c5e3e510 947 ]b4_stos[
769b430f
AD
948};
949
45d5982f 950#if YYDEBUG
617a8f12 951/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
769b430f 952 to YYLEX-NUM. */
c5e3e510 953const ]b4_int_type_for([b4_toknum])[
617a8f12 954yy::]b4_parser_class_name[::yytoken_number_[] =
769b430f 955{
c5e3e510 956 ]b4_toknum[
769b430f
AD
957};
958#endif
959
c5e3e510
AD
960/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
961const ]b4_int_type_for([b4_r1])[
617a8f12 962yy::]b4_parser_class_name[::yyr1_[] =
2b548aa6 963{
c5e3e510 964 ]b4_r1[
2b548aa6
RA
965};
966
c5e3e510
AD
967/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
968const ]b4_int_type_for([b4_r2])[
617a8f12 969yy::]b4_parser_class_name[::yyr2_[] =
2b548aa6 970{
c5e3e510 971 ]b4_r2[
2b548aa6
RA
972};
973
69e2658b 974#if YYDEBUG || YYERROR_VERBOSE
c5e3e510 975/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
617a8f12 976 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
2b548aa6 977const char*
617a8f12 978const yy::]b4_parser_class_name[::yyname_[] =
2b548aa6 979{
c5e3e510 980 ]b4_tname[
2b548aa6 981};
69e2658b 982#endif
2b548aa6 983
69e2658b 984#if YYDEBUG
2b548aa6 985/* YYRHS -- A `-1'-separated list of the rules' RHS. */
99880de5 986const yy::]b4_parser_class_name[::rhs_number_type
617a8f12 987yy::]b4_parser_class_name[::yyrhs_[] =
2b548aa6 988{
c5e3e510 989 ]b4_rhs[
2b548aa6
RA
990};
991
c5e3e510 992/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2b548aa6 993 YYRHS. */
c5e3e510 994const ]b4_int_type_for([b4_prhs])[
617a8f12 995yy::]b4_parser_class_name[::yyprhs_[] =
2b548aa6 996{
c5e3e510 997 ]b4_prhs[
2b548aa6
RA
998};
999
617a8f12 1000/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
c5e3e510 1001const ]b4_int_type_for([b4_rline])[
617a8f12 1002yy::]b4_parser_class_name[::yyrline_[] =
69e2658b 1003{
c5e3e510 1004 ]b4_rline[
69e2658b 1005};
5348bfbe 1006
617a8f12 1007// Print the state stack on the debug stream.
25f66e1a 1008void
f69a4142 1009yy::]b4_parser_class_name[::yystack_print_ ()
25f66e1a 1010{
989b5b8e 1011 *yycdebug_ << _("Stack now");
e019c247 1012 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
617a8f12 1013 i != yystate_stack_.end (); ++i)
9a1e9989
AD
1014 *yycdebug_ << ' ' << *i;
1015 *yycdebug_ << std::endl;
25f66e1a
AD
1016}
1017
617a8f12 1018// Report on the debug stream that the rule \a yyrule is going to be reduced.
5348bfbe 1019void
f69a4142 1020yy::]b4_parser_class_name[::yyreduce_print_ (int yyrule)
5348bfbe 1021{
617a8f12 1022 unsigned int yylno = yyrline_[yyrule];
5348bfbe 1023 /* Print the symbols being reduced, and their result. */
989b5b8e
AD
1024 *yycdebug_ << _("Reducing stack by rule ") << yyn_ - 1
1025 << " (" << _("line") << ' ' << yylno << "), ";
617a8f12
AD
1026 for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyn_];
1027 0 <= yyrhs_[i]; ++i)
1028 *yycdebug_ << yyname_[yyrhs_[i]] << ' ';
1029 *yycdebug_ << "-> " << yyname_[yyr1_[yyn_]] << std::endl;
5348bfbe
AD
1030}
1031#endif // YYDEBUG
69e2658b 1032
2b548aa6 1033/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
99880de5 1034yy::]b4_parser_class_name[::token_number_type
f69a4142 1035yy::]b4_parser_class_name[::yytranslate_ (int token)
2b548aa6 1036{
a75c057f 1037 static
99880de5 1038 const token_number_type
1d4055aa 1039 translate_table[] =
2b548aa6 1040 {
c5e3e510 1041 ]b4_translate[
2b548aa6 1042 };
617a8f12 1043 if ((unsigned int) token <= yyuser_token_number_max_)
1d4055aa 1044 return translate_table[token];
007a50a4 1045 else
617a8f12 1046 return yyundef_token_;
2b548aa6
RA
1047}
1048
617a8f12
AD
1049const int yy::]b4_parser_class_name[::yyeof_ = 0;
1050const int yy::]b4_parser_class_name[::yylast_ = ]b4_last[;
1051const int yy::]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1052const int yy::]b4_parser_class_name[::yyempty_ = -2;
1053const int yy::]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1054const int yy::]b4_parser_class_name[::yyterror_ = 1;
1055const int yy::]b4_parser_class_name[::yyerrcode_ = 256;
1056const int yy::]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1057
1058const unsigned int yy::]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
99880de5 1059const yy::]b4_parser_class_name[::token_number_type yy::]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
2b548aa6 1060
c5e3e510 1061]b4_epilogue
21846f69 1062dnl
6ad762a8 1063@output stack.hh
010f91c3 1064b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[
98254360 1065
2b548aa6
RA
1066#ifndef BISON_STACK_HH
1067# define BISON_STACK_HH
1068
45119f04 1069#include <deque>
2b548aa6
RA
1070
1071namespace yy
1072{
f85a5e6f 1073 template <class T, class S = std::deque<T> >
99880de5 1074 class stack
2b548aa6
RA
1075 {
1076 public:
1077
ecfe33e7
AD
1078 // Hide our reversed order.
1079 typedef typename S::reverse_iterator iterator;
1080 typedef typename S::const_reverse_iterator const_iterator;
2b548aa6 1081
99880de5 1082 stack () : seq_ ()
2b548aa6
RA
1083 {
1084 }
1085
99880de5 1086 stack (unsigned int n) : seq_ (n)
2b548aa6
RA
1087 {
1088 }
1089
1090 inline
1091 T&
779e7ceb 1092 operator [] (unsigned int i)
2b548aa6 1093 {
1d4055aa 1094 return seq_[i];
2b548aa6
RA
1095 }
1096
1097 inline
1098 const T&
779e7ceb 1099 operator [] (unsigned int i) const
2b548aa6 1100 {
1d4055aa 1101 return seq_[i];
2b548aa6
RA
1102 }
1103
1104 inline
1105 void
1106 push (const T& t)
1107 {
45119f04 1108 seq_.push_front (t);
2b548aa6
RA
1109 }
1110
1111 inline
1112 void
779e7ceb 1113 pop (unsigned int n = 1)
2b548aa6
RA
1114 {
1115 for (; n; --n)
45119f04 1116 seq_.pop_front ();
2b548aa6
RA
1117 }
1118
762a801e 1119 inline
779e7ceb 1120 unsigned int
762a801e
RA
1121 height () const
1122 {
1123 return seq_.size ();
1124 }
1125
ecfe33e7
AD
1126 inline const_iterator begin () const { return seq_.rbegin (); }
1127 inline const_iterator end () const { return seq_.rend (); }
2b548aa6
RA
1128
1129 private:
1130
1131 S seq_;
1132 };
374f5a14 1133
e019c247 1134 /// Present a slice of the top of a stack.
99880de5
AD
1135 template <class T, class S = stack<T> >
1136 class slice
374f5a14
RA
1137 {
1138 public:
1139
99880de5 1140 slice (const S& stack,
779e7ceb
PE
1141 unsigned int range) : stack_ (stack),
1142 range_ (range)
374f5a14
RA
1143 {
1144 }
1145
1146 inline
1147 const T&
779e7ceb 1148 operator [] (unsigned int i) const
374f5a14 1149 {
1d4055aa 1150 return stack_[range_ - i];
374f5a14
RA
1151 }
1152
1153 private:
1154
1155 const S& stack_;
779e7ceb 1156 unsigned int range_;
374f5a14 1157 };
2b548aa6
RA
1158}
1159
c5e3e510 1160#endif // not BISON_STACK_HH]
21846f69 1161dnl
5d003116 1162@output position.hh
010f91c3 1163b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004, 2005])[
98254360 1164
5d003116
AD
1165/**
1166 ** \file position.hh
99880de5 1167 ** Define the position class.
5d003116
AD
1168 */
1169
1170#ifndef BISON_POSITION_HH
1171# define BISON_POSITION_HH
2b548aa6 1172
7548fed2
AD
1173# include <iostream>
1174# include <string>
1175
2b548aa6
RA
1176namespace yy
1177{
99880de5
AD
1178 /// Abstract a position.
1179 class position
2b548aa6 1180 {
7548fed2 1181 public:
f69a4142 1182 /// Initial column number.
5d003116 1183 static const unsigned int initial_column = 0;
f69a4142 1184 /// Initial line number.
5d003116
AD
1185 static const unsigned int initial_line = 1;
1186
1187 /** \name Ctor & dtor.
1188 ** \{ */
1189 public:
99880de5
AD
1190 /// Construct a position.
1191 position () :
9a0d8bec 1192 filename (0),
5d003116
AD
1193 line (initial_line),
1194 column (initial_column)
1195 {
1196 }
1197 /** \} */
1198
7548fed2 1199
5d003116
AD
1200 /** \name Line and Column related manipulators
1201 ** \{ */
1202 public:
f69a4142 1203 /// (line related) Advance to the COUNT next lines.
2ffbee0e 1204 inline void lines (int count = 1)
5d003116
AD
1205 {
1206 column = initial_column;
2ffbee0e 1207 line += count;
5d003116
AD
1208 }
1209
f69a4142 1210 /// (column related) Advance to the COUNT next columns.
2ffbee0e 1211 inline void columns (int count = 1)
5d003116 1212 {
f939fc12
AD
1213 int leftmost = initial_column;
1214 int current = column;
2ffbee0e
PE
1215 if (leftmost <= current + count)
1216 column += count;
2cdc240e
AD
1217 else
1218 column = initial_column;
5d003116
AD
1219 }
1220 /** \} */
1221
1222 public:
f69a4142 1223 /// File name to which this position refers.
9a0d8bec 1224 ]b4_filename_type[* filename;
f69a4142 1225 /// Current line number.
5d003116 1226 unsigned int line;
f69a4142 1227 /// Current column number.
5d003116 1228 unsigned int column;
2b548aa6
RA
1229 };
1230
99880de5
AD
1231 /// Add and assign a position.
1232 inline const position&
1233 operator+= (position& res, const int width)
5d003116
AD
1234 {
1235 res.columns (width);
1236 return res;
1237 }
1238
99880de5
AD
1239 /// Add two position objects.
1240 inline const position
1241 operator+ (const position& begin, const int width)
5d003116 1242 {
99880de5 1243 position res = begin;
5d003116
AD
1244 return res += width;
1245 }
1246
99880de5
AD
1247 /// Add and assign a position.
1248 inline const position&
1249 operator-= (position& res, const int width)
5d003116
AD
1250 {
1251 return res += -width;
1252 }
1253
99880de5
AD
1254 /// Add two position objects.
1255 inline const position
1256 operator- (const position& begin, const int width)
5d003116
AD
1257 {
1258 return begin + -width;
1259 }
1260
1261 /** \brief Intercept output stream redirection.
1262 ** \param ostr the destination output stream
99880de5 1263 ** \param pos a reference to the position to redirect
5d003116 1264 */
7548fed2 1265 inline std::ostream&
99880de5 1266 operator<< (std::ostream& ostr, const position& pos)
7548fed2 1267 {
9a0d8bec
AD
1268 if (pos.filename)
1269 ostr << *pos.filename << ':';
5d003116 1270 return ostr << pos.line << '.' << pos.column;
7548fed2
AD
1271 }
1272
5d003116
AD
1273}
1274#endif // not BISON_POSITION_HH]
1275@output location.hh
010f91c3 1276b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004, 2005])[
7548fed2 1277
5d003116
AD
1278/**
1279 ** \file location.hh
99880de5 1280 ** Define the location class.
5d003116 1281 */
7548fed2 1282
5d003116
AD
1283#ifndef BISON_LOCATION_HH
1284# define BISON_LOCATION_HH
1285
1286# include <iostream>
1287# include <string>
1288# include "position.hh"
1289
1290namespace yy
1291{
1292
99880de5
AD
1293 /// Abstract a location.
1294 class location
2b548aa6 1295 {
5d003116
AD
1296 /** \name Ctor & dtor.
1297 ** \{ */
7548fed2 1298 public:
99880de5 1299 /// Construct a location.
e019c247 1300 location () :
5d003116
AD
1301 begin (),
1302 end ()
1303 {
1304 }
1305 /** \} */
1306
1307
1308 /** \name Line and Column related manipulators
1309 ** \{ */
1310 public:
f69a4142 1311 /// Reset initial location to final location.
e019c247 1312 inline void step ()
5d003116
AD
1313 {
1314 begin = end;
1315 }
1316
f69a4142 1317 /// Extend the current location to the COUNT next columns.
2ffbee0e 1318 inline void columns (unsigned int count = 1)
5d003116 1319 {
2ffbee0e 1320 end += count;
5d003116
AD
1321 }
1322
f69a4142 1323 /// Extend the current location to the COUNT next lines.
2ffbee0e 1324 inline void lines (unsigned int count = 1)
5d003116 1325 {
2ffbee0e 1326 end.lines (count);
5d003116
AD
1327 }
1328 /** \} */
1329
1330
1331 public:
f69a4142 1332 /// Beginning of the located region.
99880de5 1333 position begin;
f69a4142 1334 /// End of the located region.
99880de5 1335 position end;
2b548aa6 1336 };
7548fed2 1337
99880de5
AD
1338 /// Join two location objects to create a location.
1339 inline const location operator+ (const location& begin, const location& end)
5d003116 1340 {
99880de5 1341 location res = begin;
5d003116
AD
1342 res.end = end.end;
1343 return res;
1344 }
1345
99880de5
AD
1346 /// Add two location objects.
1347 inline const location operator+ (const location& begin, unsigned int width)
5d003116 1348 {
99880de5 1349 location res = begin;
5d003116
AD
1350 res.columns (width);
1351 return res;
1352 }
7548fed2 1353
99880de5
AD
1354 /// Add and assign a location.
1355 inline location& operator+= (location& res, unsigned int width)
5d003116
AD
1356 {
1357 res.columns (width);
1358 return res;
1359 }
1360
1361 /** \brief Intercept output stream redirection.
1362 ** \param ostr the destination output stream
99880de5 1363 ** \param loc a reference to the location to redirect
5d003116 1364 **
2cdc240e 1365 ** Avoid duplicate information.
5d003116 1366 */
99880de5 1367 inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
7548fed2 1368 {
99880de5 1369 position last = loc.end - 1;
2cdc240e 1370 ostr << loc.begin;
9a0d8bec
AD
1371 if (last.filename
1372 && (!loc.begin.filename
1373 || *loc.begin.filename != *last.filename))
2cdc240e
AD
1374 ostr << '-' << last;
1375 else if (loc.begin.line != last.line)
1376 ostr << '-' << last.line << '.' << last.column;
1377 else if (loc.begin.column != last.column)
1378 ostr << '-' << last.column;
7548fed2
AD
1379 return ostr;
1380 }
1381
2b548aa6
RA
1382}
1383
c5e3e510 1384#endif // not BISON_LOCATION_HH]