#include "location.hh"
#include <string>
+#include <iostream>
/* Using locations. */
#define YYLSP_NEEDED b4_locations_flag
b4_name (bool debug,
LocationType initlocation[]b4_param) :
b4_constructor[]debug_ (debug),
+ cdebug_ (std::cerr),
initlocation_ (initlocation)
#else
b4_name (bool debug[]b4_param) :
- b4_constructor[]debug_ (debug)
+ b4_constructor[]debug_ (debug),
+ cdebug_ (std::cerr)
#endif
{
}
/* State. */
int n_;
int len_;
- int debug_;
int state_;
+ /* Debugging. */
+ int debug_;
+ std::ostream &cdebug_;
+
/* Lookahead and lookahead in internal form. */
int looka_;
int ilooka_;
/* Enable debugging if requested. */
#if YYDEBUG
-# include <cstdio>
-# define YYFPRINTF std::fprintf
-# define YYDPRINTF(Args) \
-do { \
- if (debug_) \
- YYFPRINTF Args; \
-} while (0)
+# define YYCDEBUG if (debug_) cdebug_
#else /* !YYDEBUG */
-# define YYDPRINTF(Args)
+# define YYCDEBUG if (0) cdebug_
#endif /* !YYDEBUG */
int
#if YYLSP_NEEDED
location = initlocation_;
#endif
- YYDPRINTF ((stderr, "Starting parse\n"));
+ YYCDEBUG << "Starting parse" << std::endl;
/* New state. */
yynewstate:
state_stack_.push (state_);
- YYDPRINTF ((stderr, "Entering state %d\n", state_));
+ YYCDEBUG << "Entering state " << state_ << std::endl;
goto yybackup;
/* Backup. */
/* Read a lookahead token. */
if (looka_ == empty_)
{
- YYDPRINTF ((stderr, "Reading a token: "));
+ YYCDEBUG << "Reading a token: ";
lex_ ();
}
{
looka_ = eof_;
ilooka_ = 0;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
+ YYCDEBUG << "Now at end of input." << std::endl;
}
else
{
#if YYDEBUG
if (debug_)
{
- YYFPRINTF (stderr, "Next token is %d (%s", looka_, name_[[ilooka_]]);
+ YYCDEBUG << "Next token is " << looka_
+ << " (" << name_[[ilooka_]];
print_ ();
- YYFPRINTF (stderr, ")\n");
+ YYCDEBUG << ')' << std::endl;
}
#endif
}
goto yyacceptlab;
/* Shift the lookahead token. */
- YYDPRINTF ((stderr, "Shifting token %d (%s), ", looka_, name_[[ilooka_]]));
+ YYCDEBUG << "Shifting token " << looka_
+ << " (" << name_[[ilooka_]] << "), ";
/* Discard the token being shifted unless it is eof. */
if (looka_ != eof_)
#if YYDEBUG
if (debug_)
{
- YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", n_ - 1, rline_[[n_]]);
+ YYCDEBUG << "Reducing via rule " << n_ - 1
+ << " (line " << rline_[[n_]] << "), ";
for (b4_uint_type(b4_prhs_max) i = prhs_[[n_]];
rhs_[[i]] >= 0; ++i)
- YYFPRINTF (stderr, "%s ", name_[[rhs_[i]]]);
- YYFPRINTF (stderr, "-> %s\n", name_[[r1_[n_]]]);
+ YYCDEBUG << name_[[rhs_[i]]] << ' ';
+ YYCDEBUG << "-> " << name_[[r1_[n_]]] << std::endl;
}
#endif
#if YYDEBUG
if (debug_)
{
- YYFPRINTF (stderr, "state stack now");
+ YYCDEBUG << "state stack now";
for (StateStack::ConstIterator i = state_stack_.begin ();
i != state_stack_.end (); ++i)
- YYFPRINTF (stderr, " %d", *i);
- YYFPRINTF (stderr, "\n");
+ YYCDEBUG << ' ' << *i;
+ YYCDEBUG << std::endl;
}
#endif
/* Return failure if at end of input. */
if (looka_ == eof_)
goto yyabortlab;
- YYDPRINTF ((stderr, "Discarding token %d (%s).\n", looka_, name_[[ilooka_]]));
+ YYCDEBUG << "Discarding token " << looka_
+ << " (" << name_[[ilooka_]] << ")." << std::endl;
looka_ = empty_;
}
{
if (stos_[[state_]] < ntokens_)
{
- YYFPRINTF (stderr, "Error: popping token %d (%s",
- token_number_[[stos_[state_]]],
- name_[[stos_[state_]]]);
+ YYCDEBUG << "Error: popping token "
+ << token_number_[[stos_[state_]]]
+ << " (" << name_[[stos_[state_]]];
# ifdef YYPRINT
YYPRINT (stderr, token_number_[[stos_[state_]]],
semantic_stack_.top ());
# endif
- YYFPRINTF (stderr, ")\n");
+ YYCDEBUG << ')' << std::endl;
}
else
{
- YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n",
- name_[[stos_[state_]]]);
+ YYCDEBUG << "Error: popping nonterminal ("
+ << name_[[stos_[state_]]] << ')' << std::endl;
}
}
#endif
#if YYDEBUG
if (debug_)
{
- YYFPRINTF (stderr, "Error: state stack now");
+ YYCDEBUG << "Error: state stack now";
for (StateStack::ConstIterator i = state_stack_.begin ();
i != state_stack_.end (); ++i)
- YYFPRINTF (stderr, " %d", *i);
- YYFPRINTF (stderr, "\n");
+ YYCDEBUG << ' ' << *i;
+ YYCDEBUG << std::endl;
}
#endif
}
if (n_ == final_)
goto yyacceptlab;
- YYDPRINTF ((stderr, "Shifting error token, "));
+ YYCDEBUG << "Shifting error token, ";
semantic_stack_.push (value);
location_stack_.push (location);