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