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