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