m4_divert(-1)
-# b4_token_defines(TOKEN-NAME, TOKEN-NUMBER)
-# ------------------------------------------
+# b4_sint_type(MAX)
+# -----------------
+# Return the smallest signed int type able to handle the number MAX.
+m4_define([b4_sint_type],
+[m4_if(m4_eval([$1 <= 127]), [1], [signed char],
+ m4_eval([$1 <= 32767]), [1], [signed short],
+ [signed int])])
+
+
+# b4_uint_type(MAX)
+# -----------------
+# Return the smallest unsigned int type able to handle the number MAX.
+m4_define([b4_uint_type],
+[m4_if(m4_eval([$1 <= 255]), [1], [unsigned char],
+ m4_eval([$1 <= 65535]), [1], [unsigned short],
+ [unsigned int])])
+
+
+# b4_lhs_value([TYPE])
+# --------------------
+# Expansion of $<TYPE>$.
+m4_define([b4_lhs_value],
+[yyval[]m4_ifval([$1], [.$1])])
+
+
+# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
+# --------------------------------------
+# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
+# symbols on RHS.
+m4_define([b4_rhs_value],
+[semantic_stack_@<:@m4_eval([$1 - $2])@:>@m4_ifval([$3], [.$3])])
+
+
+# b4_lhs_location()
+# -----------------
+# Expansion of @$.
+m4_define([b4_lhs_location],
+[yyloc])
+
+
+# b4_rhs_location(RULE-LENGTH, NUM)
+# ---------------------------------
+# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
+# on RHS.
+m4_define([b4_rhs_location],
+[location_stack_@<:@m4_eval([$1 - $2])@:>@])
+
+
+# b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
+# -----------------------------------------
# Output the definition of this token as #define.
m4_define([b4_token_define],
[#define $1 $2
/* Using locations. */
#define YYLSP_NEEDED b4_locations_flag
-b4_prologue
+/* Copy the first part of user declarations. */
+b4_pre_prologue
/* Tokens. */
b4_token_defines(b4_tokens)
# define YYSTYPE yystype
#endif
+/* Copy the second part of user declarations. */
+b4_post_prologue
+
+#line __oline__ "__ofile__"
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
Current.last_line = Rhs[[N]].last_line; \
template < >
struct Traits< b4_name >
{
+ typedef b4_uint_type(b4_translate_max) TokenNumberType;
+ typedef b4_sint_type(b4_rhs_max) RhsNumberType;
typedef int StateType;
typedef yystype SemanticType;
typedef b4_ltype LocationType;
{
public:
- typedef Traits< b4_name >::StateType StateType;
- typedef Traits< b4_name >::SemanticType SemanticType;
- typedef Traits< b4_name >::LocationType LocationType;
+ typedef Traits< b4_name >::TokenNumberType TokenNumberType;
+ typedef Traits< b4_name >::RhsNumberType RhsNumberType;
+ typedef Traits< b4_name >::StateType StateType;
+ typedef Traits< b4_name >::SemanticType SemanticType;
+ typedef Traits< b4_name >::LocationType LocationType;
typedef Stack< StateType > StateStack;
typedef Stack< SemanticType > SemanticStack;
static const short defgoto_[[]];
static const short table_[[]];
static const short check_[[]];
- static const short r1_[[]];
- static const short r2_[[]];
+ static const b4_uint_type(b4_r1_max) r1_[[]];
+ static const b4_uint_type(b4_r2_max) r2_[[]];
#if YYDEBUG || YYERROR_VERBOSE
static const char* const name_[[]];
/* More tables, for debugging. */
#if YYDEBUG
- static const short rhs_[[]];
- static const short prhs_[[]];
- static const short rline_[[]];
+ static const RhsNumberType rhs_[[]];
+ static const b4_uint_type(b4_prhs_max) prhs_[[]];
+ static const b4_uint_type(b4_rline_max) rline_[[]];
#endif
/* Even more tables. */
- static inline char translate_ (int token);
+ static inline TokenNumberType translate_ (int token);
/* Constants. */
static const int eof_;
static const int errcode_;
static const int ntokens_;
static const int initdepth_;
- static const unsigned maxtok_;
+ static const unsigned user_token_number_max_;
+ static const TokenNumberType undef_token_;
/* State. */
int n_;
semantic_stack_ = SemanticStack (1);
location_stack_ = LocationStack (1);
- /* Reserve initial space. The C parser needed that, but is it really
- useful here? */
- state_stack_.reserve (initdepth_);
- semantic_stack_.reserve (initdepth_);
- location_stack_.reserve (initdepth_);
-
/* Start. */
state_ = 0;
looka_ = empty_;
len_ = r2_[[n_]];
if (len_)
{
- yyval = semantic_stack_[[1 - len_]];
- yyloc = location_stack_[[1 - len_]];
+ yyval = semantic_stack_[[len_ - 1]];
+ yyloc = location_stack_[[len_ - 1]];
}
else
{
if (debug_)
{
YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", n_ - 1, rline_[[n_]]);
- for (unsigned i = prhs_[[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_]]]);
YYLLOC_DEFAULT (yyloc, slice, len_);
}
- {
- SemanticStack& yyvsp (semantic_stack_);
- LocationStack& yylsp (location_stack_);
+ switch (n_)
+ {
+ b4_actions
+ }
- switch (n_)
- {
- b4_actions
- }
- }
+/* Line __line__ of __file__. */
+#line __oline__ "__ofile__"
state_stack_.pop (len_);
semantic_stack_.pop (len_);
};
/* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
-const short
+const b4_uint_type(b4_r1_max)
yy::b4_name::r1_[[]] =
{
b4_r1
};
/* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
-const short
+const b4_uint_type(b4_r2_max)
yy::b4_name::r2_[[]] =
{
b4_r2
#if YYDEBUG
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-const short
+const yy::b4_name::RhsNumberType
yy::b4_name::rhs_[[]] =
{
b4_rhs
/* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
-const short
+const b4_uint_type(b4_prhs_max)
yy::b4_name::prhs_[[]] =
{
b4_prhs
};
/* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
-const short
+const b4_uint_type(b4_rline_max)
yy::b4_name::rline_[[]] =
{
b4_rline
#endif
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
-char
+yy::b4_name::TokenNumberType
yy::b4_name::translate_ (int token)
{
static
- const char
+ const TokenNumberType
translate_[[]] =
{
b4_translate
};
- return ((unsigned)(token) <= maxtok_ ? translate_[[token]] : nsym_);
+ if ((unsigned) token <= user_token_number_max_)
+ return translate_[[token]];
+ else
+ return undef_token_;
}
const int yy::b4_name::eof_ = 0;
const int yy::b4_name::ntokens_ = b4_ntokens;
const int yy::b4_name::initdepth_ = b4_initdepth;
-const unsigned yy::b4_name::maxtok_ = b4_maxtok;
+const unsigned yy::b4_name::user_token_number_max_ = b4_user_token_number_max;
+const yy::b4_name::TokenNumberType yy::b4_name::undef_token_ = b4_undef_token_number;
b4_epilogue
#ifndef BISON_STACK_HH
# define BISON_STACK_HH
-#include <vector>
+#include <deque>
namespace yy
{
- template < class T, class S = std::vector< T > >
+ template < class T, class S = std::deque< T > >
class Stack
{
public:
inline
T&
- operator [[]] (int index)
+ operator [[]] (unsigned index)
{
- return seq_[[height () - 1 + index]];
+ return seq_[[index]];
}
inline
const T&
- operator [[]] (int index) const
+ operator [[]] (unsigned index) const
{
- return seq_[[height () - 1 + index]];
+ return seq_[[index]];
}
inline
void
push (const T& t)
{
- seq_.push_back (t);
+ seq_.push_front (t);
}
inline
pop (unsigned n = 1)
{
for (; n; --n)
- seq_.pop_back ();
- }
-
- inline
- void
- reserve (unsigned n)
- {
- seq_.reserve (n);
+ seq_.pop_front ();
}
inline
const T&
operator [[]] (unsigned index) const
{
- return stack_[[index - range_]];
+ return stack_[[range_ - index]];
}
private: