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