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