]> git.saurik.com Git - bison.git/blob - data/lalr1.cc
* data/glr.c: Comment changes.
[bison.git] / data / lalr1.cc
1 m4_divert(-1)
2
3 # C++ skeleton for Bison
4
5 # Copyright (C) 2002, 2003, 2004, 2005 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 m4_include(b4_pkgdatadir/[location.cc])
24
25 # We do want M4 expansion after # for CPP macros.
26 m4_changecom()
27 m4_divert(0)dnl
28 m4_if(b4_defines_flag, 0, [],
29 [@output @output_header_name@
30 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
31 [2002, 2003, 2004, 2005])
32 dnl FIXME: This is wrong, we want computed header guards.
33 [
34 #ifndef PARSER_HEADER_H
35 # define PARSER_HEADER_H
36
37 #include <string>
38 #include <iostream>
39 #include "stack.hh"
40
41 namespace yy
42 {
43 class position;
44 class location;
45 }
46
47 /* First part of user declarations. */
48 ]b4_pre_prologue[
49
50 ]/* Line __line__ of lalr1.cc. */
51 b4_syncline([@oline@], [@ofile@])[
52
53 ]dnl Include location.hh here: it might depend on headers included above.
54 [#include "location.hh"
55
56 /* Enabling traces. */
57 #ifndef YYDEBUG
58 # define YYDEBUG ]b4_debug[
59 #endif
60
61 /* Enabling verbose error messages. */
62 #ifdef YYERROR_VERBOSE
63 # undef YYERROR_VERBOSE
64 # define YYERROR_VERBOSE 1
65 #else
66 # define YYERROR_VERBOSE ]b4_error_verbose[
67 #endif
68
69 /* Enabling the token table. */
70 #ifndef YYTOKEN_TABLE
71 # define YYTOKEN_TABLE ]b4_token_table[
72 #endif
73
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). */
77
78 #ifndef YYLLOC_DEFAULT
79 # define YYLLOC_DEFAULT(Current, Rhs, N) \
80 do { \
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 } \
90 } while (false)
91 #endif
92
93 namespace yy
94 {
95
96 /// A Bison parser.
97 class ]b4_parser_class_name[
98 {
99 public:
100 /// Symbol semantic values.
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. */
106 b4_syncline([@oline@], [@ofile@])],
107 [ typedef int semantic_type;])[
108 #else
109 typedef YYSTYPE semantic_type;
110 #endif
111 /// Symbol locations.
112 typedef ]b4_location_type[ location_type;
113 /// Tokens.
114 struct token
115 {
116 ]b4_token_enums(b4_tokens)[
117 };
118
119 /// Build a parser object.
120 ]b4_parser_class_name[ (]b4_parse_param_decl[) :
121 yydebug_ (false),
122 yycdebug_ (&std::cerr)]b4_parse_param_cons[
123 {
124 }
125
126 virtual ~]b4_parser_class_name[ ()
127 {
128 }
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 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,
164 const semantic_type* yyvaluep,
165 const location_type* yylocationp);
166 #endif /* ! YYDEBUG */
167
168
169 /// State numbers.
170 typedef int state_type;
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
178 /// The state stack.
179 state_stack_type yystate_stack_;
180 /// The semantic value stack.
181 semantic_stack_type yysemantic_stack_;
182 /// The location stack.
183 location_stack_type yylocation_stack_;
184
185 /// Internal symbol numbers.
186 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
187 /* Tables. */
188 /// For a state, the index in \a yytable_ of its portion.
189 static const ]b4_int_type_for([b4_pact])[ yypact_[];
190 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
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.
195 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
196
197 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
198 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
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.
205 static const ]b4_int_type_for([b4_table])[ yytable_[];
206 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
207
208 static const ]b4_int_type_for([b4_check])[ yycheck_[];
209
210 /// For a state, its accessing symbol.
211 static const ]b4_int_type_for([b4_stos])[ yystos_[];
212
213 /// For a rule, its LHS.
214 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
215 /// For a rule, its RHS length.
216 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
217
218 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
219 /// For a symbol, its name in clear.
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);
226 #endif
227
228 #if YYDEBUG
229 /// A type to store symbol numbers and -1.
230 typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
231 /// A `-1'-separated list of the rules' RHS.
232 static const rhs_number_type yyrhs_[];
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_[];
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.
242 virtual void yystack_print_ ();
243 #endif
244
245 /// Convert a scanner token number to a symbol number.
246 inline token_number_type yytranslate_ (int token);
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,
255 semantic_type* yyvaluep,
256 location_type* yylocationp);
257
258 /// Pop \a n symbols the three stacks.
259 inline void yypop_ (unsigned int n = 1);
260
261 /* Constants. */
262 static const int yyeof_;
263 /* LAST_ -- Last index in TABLE_. */
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_;
272 static const token_number_type yyundef_token_;
273
274 /* Debugging. */
275 int yydebug_;
276 std::ostream* yycdebug_;
277
278 ]b4_parse_param_vars[
279 };
280 }
281
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 ])[
290 #endif /* ! defined PARSER_HEADER_H */]
291 ])dnl
292 @output @output_parser_name@
293 b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
294 [2002, 2003, 2004, 2005])
295 m4_if(b4_prefix[], [yy], [],
296 [
297 // Take the name prefix into account.
298 #define yylex b4_prefix[]lex])
299 m4_if(b4_defines_flag, 0, [],
300 [
301 #include @output_header_name@])[
302
303 /* User implementation prologue. */
304 ]b4_post_prologue[
305
306 ]/* Line __line__ of lalr1.cc. */
307 b4_syncline([@oline@], [@ofile@])[
308
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
319 #endif
320
321 /* Suppress unused-variable warnings by "using" E. */
322 #define YYUSE(e) do {;} while (false && (e))
323
324 /* A pseudo ostream that takes yydebug_ into account. */
325 # define YYCDEBUG \
326 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
327 (*yycdebug_)
328
329 /* Enable debugging if requested. */
330 #if YYDEBUG
331
332 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
333 do { \
334 if (yydebug_) \
335 { \
336 *yycdebug_ << (Title) << ' '; \
337 yysymprint_ ((Type), (Value), (Location)); \
338 *yycdebug_ << std::endl; \
339 } \
340 } while (false)
341
342 # define YY_REDUCE_PRINT(Rule) \
343 do { \
344 if (yydebug_) \
345 yyreduce_print_ (Rule); \
346 } while (false)
347
348 # define YY_STACK_PRINT() \
349 do { \
350 if (yydebug_) \
351 yystack_print_ (); \
352 } while (false)
353
354 #else /* !YYDEBUG */
355
356 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
357 # define YY_REDUCE_PRINT(Rule)
358 # define YY_STACK_PRINT()
359
360 #endif /* !YYDEBUG */
361
362 #define YYACCEPT goto yyacceptlab
363 #define YYABORT goto yyabortlab
364 #define YYERROR goto yyerrorlab
365
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. */
373 std::string
374 yy::]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
407 #if YYDEBUG
408 /*--------------------------------.
409 | Print this symbol on YYOUTPUT. |
410 `--------------------------------*/
411
412 void
413 yy::]b4_parser_class_name[::yysymprint_ (int yytype,
414 const semantic_type* yyvaluep, const location_type* yylocationp)
415 {
416 /* Backward compatibility, but should be removed eventually. */
417 std::ostream& cdebug_ = *yycdebug_;
418
419 YYUSE (!&cdebug_);
420 YYUSE (yylocationp);
421 YYUSE (yyvaluep);
422
423 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
424 << ' ' << yytname_[yytype] << " ("
425 << *yylocationp << ": ";
426 switch (yytype)
427 {
428 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
429 [ default:
430 break;
431 }
432 *yycdebug_ << ')';
433 }
434 #endif /* ! YYDEBUG */
435
436 void
437 yy::]b4_parser_class_name[::yydestruct_ (const char* yymsg,
438 int yytype, semantic_type* yyvaluep, location_type* yylocationp)
439 {
440 YYUSE (yylocationp);
441 YYUSE (yymsg);
442 YYUSE (yyvaluep);
443
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 }
453
454 void
455 yy::]b4_parser_class_name[::yypop_ (unsigned int n)
456 {
457 yystate_stack_.pop (n);
458 yysemantic_stack_.pop (n);
459 yylocation_stack_.pop (n);
460 }
461
462 std::ostream&
463 yy::]b4_parser_class_name[::debug_stream () const
464 {
465 return *yycdebug_;
466 }
467
468 void
469 yy::]b4_parser_class_name[::set_debug_stream (std::ostream& o)
470 {
471 yycdebug_ = &o;
472 }
473
474
475 yy::]b4_parser_class_name[::debug_level_type
476 yy::]b4_parser_class_name[::debug_level () const
477 {
478 return yydebug_;
479 }
480
481 void
482 yy::]b4_parser_class_name[::set_debug_level (debug_level_type l)
483 {
484 yydebug_ = l;
485 }
486
487
488 int
489 yy::]b4_parser_class_name[::parse ()
490 {
491 /// Look-ahead and look-ahead in internal form.
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;
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
516 int yyresult;
517
518 YYCDEBUG << "Starting parse" << std::endl;
519
520 ]m4_ifdef([b4_initial_action], [
521 m4_pushdef([b4_at_dollar], [yylloc])dnl
522 m4_pushdef([b4_dollar_dollar], [yylval])dnl
523 /* User initialization code. */
524 b4_initial_action
525 m4_popdef([b4_dollar_dollar])dnl
526 m4_popdef([b4_at_dollar])dnl
527 /* Line __line__ of yacc.c. */
528 b4_syncline([@oline@], [@ofile@])])dnl
529
530 [ /* Initialize the stacks. The initial state will be pushed in
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. */
534 yystate_stack_ = state_stack_type (0);
535 yysemantic_stack_ = semantic_stack_type (0);
536 yylocation_stack_ = location_stack_type (0);
537 yysemantic_stack_.push (yylval);
538 yylocation_stack_.push (yylloc);
539
540 /* New state. */
541 yynewstate:
542 yystate_stack_.push (yystate);
543 YYCDEBUG << "Entering state " << yystate << std::endl;
544 goto yybackup;
545
546 /* Backup. */
547 yybackup:
548
549 /* Try to take a decision without look-ahead. */
550 yyn = yypact_[yystate];
551 if (yyn == yypact_ninf_)
552 goto yydefault;
553
554 /* Read a look-ahead token. */
555 if (yychar == yyempty_)
556 {
557 YYCDEBUG << "Reading a token: ";
558 yychar = ]b4_c_function_call([yylex], [int],
559 [[YYSTYPE*], [&yylval]][]dnl
560 b4_location_if([, [[location*], [&yylloc]]])dnl
561 m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
562 }
563
564
565 /* Convert token to internal form. */
566 if (yychar <= yyeof_)
567 {
568 yychar = yytoken = yyeof_;
569 YYCDEBUG << "Now at end of input." << std::endl;
570 }
571 else
572 {
573 yytoken = yytranslate_ (yychar);
574 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
575 }
576
577 /* If the proper action on seeing token YYTOKEN is to reduce or to
578 detect an error, take that action. */
579 yyn += yytoken;
580 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
581 goto yydefault;
582
583 /* Reduce or error. */
584 yyn = yytable_[yyn];
585 if (yyn <= 0)
586 {
587 if (yyn == 0 || yyn == yytable_ninf_)
588 goto yyerrlab;
589 yyn = -yyn;
590 goto yyreduce;
591 }
592
593 /* Accept? */
594 if (yyn == yyfinal_)
595 goto yyacceptlab;
596
597 /* Shift the look-ahead token. */
598 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
599
600 /* Discard the token being shifted unless it is eof. */
601 if (yychar != yyeof_)
602 yychar = yyempty_;
603
604 yysemantic_stack_.push (yylval);
605 yylocation_stack_.push (yylloc);
606
607 /* Count tokens shifted since error; after three, turn off error
608 status. */
609 if (yyerrstatus_)
610 --yyerrstatus_;
611
612 yystate = yyn;
613 goto yynewstate;
614
615 /*-----------------------------------------------------------.
616 | yydefault -- do the default action for the current state. |
617 `-----------------------------------------------------------*/
618 yydefault:
619 yyn = yydefact_[yystate];
620 if (yyn == 0)
621 goto yyerrlab;
622 goto yyreduce;
623
624 /*-----------------------------.
625 | yyreduce -- Do a reduction. |
626 `-----------------------------*/
627 yyreduce:
628 yylen = yyr2_[yyn];
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. */
635 if (yylen)
636 yyval = yysemantic_stack_[yylen - 1];
637 else
638 yyval = yysemantic_stack_[0];
639
640 {
641 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
642 YYLLOC_DEFAULT (yyloc, slice, yylen);
643 }
644 YY_REDUCE_PRINT (yyn);
645 switch (yyn)
646 {
647 ]b4_actions[
648 default: break;
649 }
650
651 ]/* Line __line__ of lalr1.cc. */
652 b4_syncline([@oline@], [@ofile@])[
653
654 yypop_ (yylen);
655
656 YY_STACK_PRINT ();
657
658 yysemantic_stack_.push (yyval);
659 yylocation_stack_.push (yyloc);
660
661 /* Shift the result of the reduction. */
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];
667 else
668 yystate = yydefgoto_[yyn - yyntokens_];
669 goto yynewstate;
670
671 /*------------------------------------.
672 | yyerrlab -- here on detecting error |
673 `------------------------------------*/
674 yyerrlab:
675 /* If not already recovering from an error, report this error. */
676 if (!yyerrstatus_)
677 {
678 ++yynerrs_;
679 error (yylloc, yysyntax_error_ (yystate]dnl
680 b4_error_verbose_if([, yytoken])[));
681 }
682
683 yyerror_range[0] = yylloc;
684 if (yyerrstatus_ == 3)
685 {
686 /* If just tried and failed to reuse look-ahead token after an
687 error, discard it. */
688
689 if (yychar <= yyeof_)
690 {
691 /* Return failure if at end of input. */
692 if (yychar == yyeof_)
693 YYABORT;
694 }
695 else
696 {
697 yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
698 yychar = yyempty_;
699 }
700 }
701
702 /* Else will try to reuse look-ahead token after shifting the error
703 token. */
704 goto yyerrlab1;
705
706
707 /*---------------------------------------------------.
708 | yyerrorlab -- error raised explicitly by YYERROR. |
709 `---------------------------------------------------*/
710 yyerrorlab:
711
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)
716 goto yyerrorlab;
717
718 yyerror_range[0] = yylocation_stack_[yylen - 1];
719 yypop_ (yylen);
720 yystate = yystate_stack_[0];
721 goto yyerrlab1;
722
723 /*-------------------------------------------------------------.
724 | yyerrlab1 -- common code for both syntax error and YYERROR. |
725 `-------------------------------------------------------------*/
726 yyerrlab1:
727 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
728
729 for (;;)
730 {
731 yyn = yypact_[yystate];
732 if (yyn != yypact_ninf_)
733 {
734 yyn += yyterror_;
735 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
736 {
737 yyn = yytable_[yyn];
738 if (0 < yyn)
739 break;
740 }
741 }
742
743 /* Pop the current state because it cannot handle the error token. */
744 if (yystate_stack_.height () == 1)
745 YYABORT;
746
747 yyerror_range[0] = yylocation_stack_[0];
748 yydestruct_ ("Error: popping",
749 yystos_[yystate],
750 &yysemantic_stack_[0], &yylocation_stack_[0]);
751 yypop_ ();
752 yystate = yystate_stack_[0];
753 YY_STACK_PRINT ();
754 }
755
756 if (yyn == yyfinal_)
757 goto yyacceptlab;
758
759 yyerror_range[1] = yylloc;
760 // Using YYLLOC is tempting, but would change the location of
761 // the look-ahead. YYLOC is available though.
762 YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);
763 yysemantic_stack_.push (yylval);
764 yylocation_stack_.push (yyloc);
765
766 /* Shift the error token. */
767 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
768 &yysemantic_stack_[0], &yylocation_stack_[0]);
769
770 yystate = yyn;
771 goto yynewstate;
772
773 /* Accept. */
774 yyacceptlab:
775 yyresult = 0;
776 goto yyreturn;
777
778 /* Abort. */
779 yyabortlab:
780 yyresult = 1;
781 goto yyreturn;
782
783 yyreturn:
784 if (yychar != yyeof_ && yychar != yyempty_)
785 yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
786
787 while (yystate_stack_.height () != 1)
788 {
789 yydestruct_ ("Cleanup: popping",
790 yystos_[yystate_stack_[0]],
791 &yysemantic_stack_[0],
792 &yylocation_stack_[0]);
793 yypop_ ();
794 }
795
796 return yyresult;
797 }
798
799 // Generate an error message.
800 std::string
801 yy::]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl
802 b4_error_verbose_if([, int tok])[)
803 {
804 std::string res;
805 #if YYERROR_VERBOSE
806 int yyn = yypact_[yystate];
807 if (yypact_ninf_ < yyn && yyn < yylast_)
808 {
809 /* Start YYX at -YYN if negative to avoid negative indexes in
810 YYCHECK. */
811 int yyxbegin = yyn < 0 ? -yyn : 0;
812
813 /* Stay within bounds of both yycheck and yytname. */
814 int yychecklim = yylast_ - yyn;
815 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
816 int count = 0;
817 for (int x = yyxbegin; x < yyxend; ++x)
818 if (yycheck_[x + yyn] == x && x != yyterror_)
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;
834 for (int x = yyxbegin; x < yyxend; ++x)
835 if (yycheck_[x + yyn] == x && x != yyterror_)
836 {
837 res += (!count++) ? ", expecting " : " or ";
838 res += yytnamerr_ (yytname_[x]);
839 }
840 }
841 }
842 else
843 #endif
844 res = YY_("syntax error");
845 return res;
846 }
847
848
849 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
850 STATE-NUM. */
851 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
852 const ]b4_int_type_for([b4_pact])[
853 yy::]b4_parser_class_name[::yypact_[] =
854 {
855 ]b4_pact[
856 };
857
858 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
859 doesn't specify something else to do. Zero means the default is an
860 error. */
861 const ]b4_int_type_for([b4_defact])[
862 yy::]b4_parser_class_name[::yydefact_[] =
863 {
864 ]b4_defact[
865 };
866
867 /* YYPGOTO[NTERM-NUM]. */
868 const ]b4_int_type_for([b4_pgoto])[
869 yy::]b4_parser_class_name[::yypgoto_[] =
870 {
871 ]b4_pgoto[
872 };
873
874 /* YYDEFGOTO[NTERM-NUM]. */
875 const ]b4_int_type_for([b4_defgoto])[
876 yy::]b4_parser_class_name[::yydefgoto_[] =
877 {
878 ]b4_defgoto[
879 };
880
881 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
882 positive, shift that token. If negative, reduce the rule which
883 number is the opposite. If zero, do what YYDEFACT says. */
884 const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
885 const ]b4_int_type_for([b4_table])[
886 yy::]b4_parser_class_name[::yytable_[] =
887 {
888 ]b4_table[
889 };
890
891 /* YYCHECK. */
892 const ]b4_int_type_for([b4_check])[
893 yy::]b4_parser_class_name[::yycheck_[] =
894 {
895 ]b4_check[
896 };
897
898 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
899 symbol of state STATE-NUM. */
900 const ]b4_int_type_for([b4_stos])[
901 yy::]b4_parser_class_name[::yystos_[] =
902 {
903 ]b4_stos[
904 };
905
906 #if YYDEBUG
907 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
908 to YYLEX-NUM. */
909 const ]b4_int_type_for([b4_toknum])[
910 yy::]b4_parser_class_name[::yytoken_number_[] =
911 {
912 ]b4_toknum[
913 };
914 #endif
915
916 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
917 const ]b4_int_type_for([b4_r1])[
918 yy::]b4_parser_class_name[::yyr1_[] =
919 {
920 ]b4_r1[
921 };
922
923 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
924 const ]b4_int_type_for([b4_r2])[
925 yy::]b4_parser_class_name[::yyr2_[] =
926 {
927 ]b4_r2[
928 };
929
930 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
931 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
932 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
933 const char*
934 const yy::]b4_parser_class_name[::yytname_[] =
935 {
936 ]b4_tname[
937 };
938 #endif
939
940 #if YYDEBUG
941 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
942 const yy::]b4_parser_class_name[::rhs_number_type
943 yy::]b4_parser_class_name[::yyrhs_[] =
944 {
945 ]b4_rhs[
946 };
947
948 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
949 YYRHS. */
950 const ]b4_int_type_for([b4_prhs])[
951 yy::]b4_parser_class_name[::yyprhs_[] =
952 {
953 ]b4_prhs[
954 };
955
956 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
957 const ]b4_int_type_for([b4_rline])[
958 yy::]b4_parser_class_name[::yyrline_[] =
959 {
960 ]b4_rline[
961 };
962
963 // Print the state stack on the debug stream.
964 void
965 yy::]b4_parser_class_name[::yystack_print_ ()
966 {
967 *yycdebug_ << "Stack now";
968 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
969 i != yystate_stack_.end (); ++i)
970 *yycdebug_ << ' ' << *i;
971 *yycdebug_ << std::endl;
972 }
973
974 // Report on the debug stream that the rule \a yyrule is going to be reduced.
975 void
976 yy::]b4_parser_class_name[::yyreduce_print_ (int yyrule)
977 {
978 unsigned int yylno = yyrline_[yyrule];
979 /* Print the symbols being reduced, and their result. */
980 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
981 << " (line " << yylno << "), ";
982 for (]b4_int_type_for([b4_prhs])[ i = yyprhs_[yyrule];
983 0 <= yyrhs_[i]; ++i)
984 *yycdebug_ << yytname_[yyrhs_[i]] << ' ';
985 *yycdebug_ << "-> " << yytname_[yyr1_[yyrule]] << std::endl;
986 }
987 #endif // YYDEBUG
988
989 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
990 yy::]b4_parser_class_name[::token_number_type
991 yy::]b4_parser_class_name[::yytranslate_ (int token)
992 {
993 static
994 const token_number_type
995 translate_table[] =
996 {
997 ]b4_translate[
998 };
999 if ((unsigned int) token <= yyuser_token_number_max_)
1000 return translate_table[token];
1001 else
1002 return yyundef_token_;
1003 }
1004
1005 const int yy::]b4_parser_class_name[::yyeof_ = 0;
1006 const int yy::]b4_parser_class_name[::yylast_ = ]b4_last[;
1007 const int yy::]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
1008 const int yy::]b4_parser_class_name[::yyempty_ = -2;
1009 const int yy::]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
1010 const int yy::]b4_parser_class_name[::yyterror_ = 1;
1011 const int yy::]b4_parser_class_name[::yyerrcode_ = 256;
1012 const int yy::]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
1013
1014 const unsigned int yy::]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
1015 const yy::]b4_parser_class_name[::token_number_type yy::]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
1016
1017 ]b4_epilogue
1018 dnl
1019 @output b4_dir_prefix[]stack.hh
1020 b4_copyright([stack handling for Bison C++ parsers], [2002, 2003, 2004, 2005])[
1021
1022 #ifndef BISON_STACK_HH
1023 # define BISON_STACK_HH
1024
1025 #include <deque>
1026
1027 namespace yy
1028 {
1029 template <class T, class S = std::deque<T> >
1030 class stack
1031 {
1032 public:
1033
1034 // Hide our reversed order.
1035 typedef typename S::reverse_iterator iterator;
1036 typedef typename S::const_reverse_iterator const_iterator;
1037
1038 stack () : seq_ ()
1039 {
1040 }
1041
1042 stack (unsigned int n) : seq_ (n)
1043 {
1044 }
1045
1046 inline
1047 T&
1048 operator [] (unsigned int i)
1049 {
1050 return seq_[i];
1051 }
1052
1053 inline
1054 const T&
1055 operator [] (unsigned int i) const
1056 {
1057 return seq_[i];
1058 }
1059
1060 inline
1061 void
1062 push (const T& t)
1063 {
1064 seq_.push_front (t);
1065 }
1066
1067 inline
1068 void
1069 pop (unsigned int n = 1)
1070 {
1071 for (; n; --n)
1072 seq_.pop_front ();
1073 }
1074
1075 inline
1076 unsigned int
1077 height () const
1078 {
1079 return seq_.size ();
1080 }
1081
1082 inline const_iterator begin () const { return seq_.rbegin (); }
1083 inline const_iterator end () const { return seq_.rend (); }
1084
1085 private:
1086
1087 S seq_;
1088 };
1089
1090 /// Present a slice of the top of a stack.
1091 template <class T, class S = stack<T> >
1092 class slice
1093 {
1094 public:
1095
1096 slice (const S& stack,
1097 unsigned int range) : stack_ (stack),
1098 range_ (range)
1099 {
1100 }
1101
1102 inline
1103 const T&
1104 operator [] (unsigned int i) const
1105 {
1106 return stack_[range_ - i];
1107 }
1108
1109 private:
1110
1111 const S& stack_;
1112 unsigned int range_;
1113 };
1114 }
1115
1116 #endif // not BISON_STACK_HH]
1117 m4_divert(-1)