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