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