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