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