137 |
#include "location.hh" |
#include "location.hh" |
138 |
|
|
139 |
#include <string> |
#include <string> |
140 |
|
#include <iostream> |
141 |
|
|
142 |
/* Using locations. */ |
/* Using locations. */ |
143 |
#define YYLSP_NEEDED b4_locations_flag |
#define YYLSP_NEEDED b4_locations_flag |
229 |
b4_name (bool debug, |
b4_name (bool debug, |
230 |
LocationType initlocation[]b4_param) : |
LocationType initlocation[]b4_param) : |
231 |
b4_constructor[]debug_ (debug), |
b4_constructor[]debug_ (debug), |
232 |
|
cdebug_ (std::cerr), |
233 |
initlocation_ (initlocation) |
initlocation_ (initlocation) |
234 |
#else |
#else |
235 |
b4_name (bool debug[]b4_param) : |
b4_name (bool debug[]b4_param) : |
236 |
b4_constructor[]debug_ (debug) |
b4_constructor[]debug_ (debug), |
237 |
|
cdebug_ (std::cerr) |
238 |
#endif |
#endif |
239 |
{ |
{ |
240 |
} |
} |
300 |
/* State. */ |
/* State. */ |
301 |
int n_; |
int n_; |
302 |
int len_; |
int len_; |
|
int debug_; |
|
303 |
int state_; |
int state_; |
304 |
|
|
305 |
|
/* Debugging. */ |
306 |
|
int debug_; |
307 |
|
std::ostream &cdebug_; |
308 |
|
|
309 |
/* Lookahead and lookahead in internal form. */ |
/* Lookahead and lookahead in internal form. */ |
310 |
int looka_; |
int looka_; |
311 |
int ilooka_; |
int ilooka_; |
335 |
|
|
336 |
/* Enable debugging if requested. */ |
/* Enable debugging if requested. */ |
337 |
#if YYDEBUG |
#if YYDEBUG |
338 |
# include <cstdio> |
# define YYCDEBUG if (debug_) cdebug_ |
|
# define YYFPRINTF std::fprintf |
|
|
# define YYDPRINTF(Args) \ |
|
|
do { \ |
|
|
if (debug_) \ |
|
|
YYFPRINTF Args; \ |
|
|
} while (0) |
|
339 |
#else /* !YYDEBUG */ |
#else /* !YYDEBUG */ |
340 |
# define YYDPRINTF(Args) |
# define YYCDEBUG if (0) cdebug_ |
341 |
#endif /* !YYDEBUG */ |
#endif /* !YYDEBUG */ |
342 |
|
|
343 |
int |
int |
357 |
#if YYLSP_NEEDED |
#if YYLSP_NEEDED |
358 |
location = initlocation_; |
location = initlocation_; |
359 |
#endif |
#endif |
360 |
YYDPRINTF ((stderr, "Starting parse\n")); |
YYCDEBUG << "Starting parse" << std::endl; |
361 |
|
|
362 |
/* New state. */ |
/* New state. */ |
363 |
yynewstate: |
yynewstate: |
364 |
state_stack_.push (state_); |
state_stack_.push (state_); |
365 |
YYDPRINTF ((stderr, "Entering state %d\n", state_)); |
YYCDEBUG << "Entering state " << state_ << std::endl; |
366 |
goto yybackup; |
goto yybackup; |
367 |
|
|
368 |
/* Backup. */ |
/* Backup. */ |
376 |
/* Read a lookahead token. */ |
/* Read a lookahead token. */ |
377 |
if (looka_ == empty_) |
if (looka_ == empty_) |
378 |
{ |
{ |
379 |
YYDPRINTF ((stderr, "Reading a token: ")); |
YYCDEBUG << "Reading a token: "; |
380 |
lex_ (); |
lex_ (); |
381 |
} |
} |
382 |
|
|
385 |
{ |
{ |
386 |
looka_ = eof_; |
looka_ = eof_; |
387 |
ilooka_ = 0; |
ilooka_ = 0; |
388 |
YYDPRINTF ((stderr, "Now at end of input.\n")); |
YYCDEBUG << "Now at end of input." << std::endl; |
389 |
} |
} |
390 |
else |
else |
391 |
{ |
{ |
393 |
#if YYDEBUG |
#if YYDEBUG |
394 |
if (debug_) |
if (debug_) |
395 |
{ |
{ |
396 |
YYFPRINTF (stderr, "Next token is %d (%s", looka_, name_[[ilooka_]]); |
YYCDEBUG << "Next token is " << looka_ |
397 |
|
<< " (" << name_[[ilooka_]]; |
398 |
print_ (); |
print_ (); |
399 |
YYFPRINTF (stderr, ")\n"); |
YYCDEBUG << ')' << std::endl; |
400 |
} |
} |
401 |
#endif |
#endif |
402 |
} |
} |
425 |
goto yyacceptlab; |
goto yyacceptlab; |
426 |
|
|
427 |
/* Shift the lookahead token. */ |
/* Shift the lookahead token. */ |
428 |
YYDPRINTF ((stderr, "Shifting token %d (%s), ", looka_, name_[[ilooka_]])); |
YYCDEBUG << "Shifting token " << looka_ |
429 |
|
<< " (" << name_[[ilooka_]] << "), "; |
430 |
|
|
431 |
/* Discard the token being shifted unless it is eof. */ |
/* Discard the token being shifted unless it is eof. */ |
432 |
if (looka_ != eof_) |
if (looka_ != eof_) |
467 |
#if YYDEBUG |
#if YYDEBUG |
468 |
if (debug_) |
if (debug_) |
469 |
{ |
{ |
470 |
YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", n_ - 1, rline_[[n_]]); |
YYCDEBUG << "Reducing via rule " << n_ - 1 |
471 |
|
<< " (line " << rline_[[n_]] << "), "; |
472 |
for (b4_uint_type(b4_prhs_max) i = prhs_[[n_]]; |
for (b4_uint_type(b4_prhs_max) i = prhs_[[n_]]; |
473 |
rhs_[[i]] >= 0; ++i) |
rhs_[[i]] >= 0; ++i) |
474 |
YYFPRINTF (stderr, "%s ", name_[[rhs_[i]]]); |
YYCDEBUG << name_[[rhs_[i]]] << ' '; |
475 |
YYFPRINTF (stderr, "-> %s\n", name_[[r1_[n_]]]); |
YYCDEBUG << "-> " << name_[[r1_[n_]]] << std::endl; |
476 |
} |
} |
477 |
#endif |
#endif |
478 |
|
|
497 |
#if YYDEBUG |
#if YYDEBUG |
498 |
if (debug_) |
if (debug_) |
499 |
{ |
{ |
500 |
YYFPRINTF (stderr, "state stack now"); |
YYCDEBUG << "state stack now"; |
501 |
for (StateStack::ConstIterator i = state_stack_.begin (); |
for (StateStack::ConstIterator i = state_stack_.begin (); |
502 |
i != state_stack_.end (); ++i) |
i != state_stack_.end (); ++i) |
503 |
YYFPRINTF (stderr, " %d", *i); |
YYCDEBUG << ' ' << *i; |
504 |
YYFPRINTF (stderr, "\n"); |
YYCDEBUG << std::endl; |
505 |
} |
} |
506 |
#endif |
#endif |
507 |
|
|
564 |
/* Return failure if at end of input. */ |
/* Return failure if at end of input. */ |
565 |
if (looka_ == eof_) |
if (looka_ == eof_) |
566 |
goto yyabortlab; |
goto yyabortlab; |
567 |
YYDPRINTF ((stderr, "Discarding token %d (%s).\n", looka_, name_[[ilooka_]])); |
YYCDEBUG << "Discarding token " << looka_ |
568 |
|
<< " (" << name_[[ilooka_]] << ")." << std::endl; |
569 |
looka_ = empty_; |
looka_ = empty_; |
570 |
} |
} |
571 |
|
|
597 |
{ |
{ |
598 |
if (stos_[[state_]] < ntokens_) |
if (stos_[[state_]] < ntokens_) |
599 |
{ |
{ |
600 |
YYFPRINTF (stderr, "Error: popping token %d (%s", |
YYCDEBUG << "Error: popping token " |
601 |
token_number_[[stos_[state_]]], |
<< token_number_[[stos_[state_]]] |
602 |
name_[[stos_[state_]]]); |
<< " (" << name_[[stos_[state_]]]; |
603 |
# ifdef YYPRINT |
# ifdef YYPRINT |
604 |
YYPRINT (stderr, token_number_[[stos_[state_]]], |
YYPRINT (stderr, token_number_[[stos_[state_]]], |
605 |
semantic_stack_.top ()); |
semantic_stack_.top ()); |
606 |
# endif |
# endif |
607 |
YYFPRINTF (stderr, ")\n"); |
YYCDEBUG << ')' << std::endl; |
608 |
} |
} |
609 |
else |
else |
610 |
{ |
{ |
611 |
YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n", |
YYCDEBUG << "Error: popping nonterminal (" |
612 |
name_[[stos_[state_]]]); |
<< name_[[stos_[state_]]] << ')' << std::endl; |
613 |
} |
} |
614 |
} |
} |
615 |
#endif |
#endif |
621 |
#if YYDEBUG |
#if YYDEBUG |
622 |
if (debug_) |
if (debug_) |
623 |
{ |
{ |
624 |
YYFPRINTF (stderr, "Error: state stack now"); |
YYCDEBUG << "Error: state stack now"; |
625 |
for (StateStack::ConstIterator i = state_stack_.begin (); |
for (StateStack::ConstIterator i = state_stack_.begin (); |
626 |
i != state_stack_.end (); ++i) |
i != state_stack_.end (); ++i) |
627 |
YYFPRINTF (stderr, " %d", *i); |
YYCDEBUG << ' ' << *i; |
628 |
YYFPRINTF (stderr, "\n"); |
YYCDEBUG << std::endl; |
629 |
} |
} |
630 |
#endif |
#endif |
631 |
} |
} |
633 |
if (n_ == final_) |
if (n_ == final_) |
634 |
goto yyacceptlab; |
goto yyacceptlab; |
635 |
|
|
636 |
YYDPRINTF ((stderr, "Shifting error token, ")); |
YYCDEBUG << "Shifting error token, "; |
637 |
|
|
638 |
semantic_stack_.push (value); |
semantic_stack_.push (value); |
639 |
location_stack_.push (location); |
location_stack_.push (location); |