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