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