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