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