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