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