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