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