## Default values. ##
## ---------------- ##
-# Stack parameters.
-m4_define_default([b4_stack_depth_init], [200])
-
# Default Parser class name.
m4_define_default([b4_parser_class_name], [Parser])
b4_syncline([@oline@], [@ofile@])[
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
- Current.last_line = Rhs[N].last_line; \
- Current.last_column = Rhs[N].last_column;
+ Current.end = Rhs[N].end;
#endif
namespace yy
static const int terror_;
static const int errcode_;
static const int ntokens_;
- static const int initdepth_;
static const unsigned user_token_number_max_;
static const TokenNumberType undef_token_;
# define YYCDEBUG if (0) cdebug_
#endif /* !YYDEBUG */
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrlab1
+
+
int
yy::]b4_parser_class_name[::parse ()
{
#if YYDEBUG
if (debug_)
{
+ // Short files will use "unsigned char" for line numbers,
+ // in which case they will be output as character litterals
+ // by "<<".
YYCDEBUG << "Reducing via rule " << n_ - 1
- << " (line " << rline_[n_] << "), ";
+ << " (line " << static_cast <unsigned> (rline_[n_]) << "), ";
for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
0 <= rhs_[i]; ++i)
YYCDEBUG << name_[rhs_[i]] << ' ';
}
goto yyerrlab1;
- /* Error raised explicitly by an action. */
+
+ /*----------------------------------------------------.
+ | yyerrlab1 -- error raised explicitly by an action. |
+ `----------------------------------------------------*/
yyerrlab1:
if (errstatus == 3)
{
/* Return failure if at end of input. */
if (looka_ == eof_)
goto yyabortlab;
+#if YYDEBUG
YYCDEBUG << "Discarding token " << looka_
- << " (" << name_[ilooka_] << ")." << std::endl;
+ << " (" << name_[ilooka_] << ")." << std::endl;
+#endif
looka_ = empty_;
}
const int yy::]b4_parser_class_name[::terror_ = 1;
const int yy::]b4_parser_class_name[::errcode_ = 256;
const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[;
-const int yy::]b4_parser_class_name[::initdepth_ = ]b4_stack_depth_init[;
const unsigned yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[;
const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[;
]b4_epilogue
dnl
@output stack.hh
-b4_copyright([2002, 2003])[
+b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003])[
#ifndef BISON_STACK_HH
# define BISON_STACK_HH
#endif // not BISON_STACK_HH]
dnl
@output location.hh
-b4_copyright([2002, 2003])[
+b4_copyright([Location class for Bison C++ parsers], [2002, 2003])[
#ifndef BISON_LOCATION_HH
# define BISON_LOCATION_HH
+# include <iostream>
+# include <string>
+
namespace yy
{
- struct Position
+ class Position
{
+ public:
+ Position ()
+ : filename (), line (1), column (0)
+ {}
+
+ std::string filename;
int line;
int column;
};
- struct Location
+ inline std::ostream&
+ operator<< (std::ostream& ostr, const Position& pos)
{
- Position first;
- Position last;
+ if (pos.filename != "")
+ ostr << pos.filename << ':';
+ ostr << pos.line << '.' << pos.column;
+ return ostr;
+ }
+
+ inline Position
+ operator- (const Position& pos, int col)
+ {
+ Position res (pos);
+ res.column -= col;
+ return res;
+ }
+
+
+ class Location
+ {
+ public:
+ Position begin;
+ Position end;
};
+
+ /* Don't issue twice the line number when the location is on a single
+ line. */
+
+ inline std::ostream&
+ operator<< (std::ostream& ostr, const Location& pos)
+ {
+ ostr << pos.begin;
+ if (pos.begin.filename != pos.end.filename)
+ ostr << '-' << pos.end - 1;
+ else if (pos.begin.line != pos.end.line)
+ ostr << '-' << pos.end.line << '.' << pos.end.column - 1;
+ else if (pos.begin.column != pos.end.column - 1)
+ ostr << '-' << pos.end.column - 1;
+ return ostr;
+ }
+
}
#endif // not BISON_LOCATION_HH]