c++: minor changes

* data/lalr1.cc: Fix oldish comment.
* data/stack.hh: Prefer typename for type names.
Use size() instead of duplicating it.
* examples/variant-11.yy, examples/variant.yy (yylex): Use int,
as this is the type of the semantic value.
This commit is contained in:
Akim Demaille
2018-10-22 08:18:54 +02:00
parent 73917e9e6f
commit 4b0efdeb28
6 changed files with 19 additions and 12 deletions

6
TODO
View File

@@ -1,4 +1,10 @@
* Short term * Short term
** C++
Move to int everywhere instead of unsigned? stack_size, etc. The parser
itself uses int (for yylen for instance), yet stack is based on size_t.
Maybe locations should also move to ints.
** Graphviz display code thoughts ** Graphviz display code thoughts
The code for the --graph option is over two files: print_graph, and The code for the --graph option is over two files: print_graph, and
graphviz. This is because Bison used to also produce VCG graphs, but since graphviz. This is because Bison used to also produce VCG graphs, but since

View File

@@ -359,7 +359,7 @@ m4_define([b4_shared_declarations],
/// \warning the contents of \a sym.value is stolen. /// \warning the contents of \a sym.value is stolen.
void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym); void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym);
/// Pop \a n symbols the three stacks. /// Pop \a n symbols from the stack.
void yypop_ (unsigned n = 1); void yypop_ (unsigned n = 1);
/// Constants. /// Constants.

View File

@@ -27,7 +27,7 @@ b4_defines_if([b4_required_version_if([302], [],
# --------------- # ---------------
m4_define([b4_stack_define], m4_define([b4_stack_define],
[[ /// A stack with random access from its top. [[ /// A stack with random access from its top.
template <class T, class S = std::vector<T> > template <typename T, typename S = std::vector<T> >
class stack class stack
{ {
public: public:
@@ -46,7 +46,7 @@ m4_define([b4_stack_define],
T& T&
operator[] (size_type i) operator[] (size_type i)
{ {
return seq_[seq_.size () - 1 - i]; return seq_[size () - 1 - i];
} }
/// Random access. /// Random access.
@@ -55,7 +55,7 @@ m4_define([b4_stack_define],
const T& const T&
operator[] (size_type i) const operator[] (size_type i) const
{ {
return seq_[seq_.size () - 1 - i]; return seq_[size () - 1 - i];
} }
/// Steal the contents of \a t. /// Steal the contents of \a t.
@@ -107,7 +107,7 @@ m4_define([b4_stack_define],
}; };
/// Present a slice of the top of a stack. /// Present a slice of the top of a stack.
template <class T, class S = stack<T> > template <typename T, typename S = stack<T> >
class slice class slice
{ {
public: public:

View File

@@ -11723,7 +11723,7 @@ The rules are simple. The driver is used to report errors.
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE)) if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
throw yy::parser::syntax_error (loc, "integer is out of range: " throw yy::parser::syntax_error (loc, "integer is out of range: "
+ std::string(yytext)); + std::string(yytext));
return yy::parser::make_NUMBER (n, loc); return yy::parser::make_NUMBER (int (n), loc);
@} @}
@end group @end group
@{id@} return yy::parser::make_IDENTIFIER (yytext, loc); @{id@} return yy::parser::make_IDENTIFIER (yytext, loc);

View File

@@ -124,10 +124,10 @@ namespace yy
parser::symbol_type parser::symbol_type
yylex () yylex ()
{ {
static auto count = 0u; static int count = 0;
const auto stage = count; const int stage = count;
++count; ++count;
auto loc = parser::location_type{nullptr, stage + 1, stage + 1}; auto loc = parser::location_type{nullptr, unsigned (stage + 1), unsigned (stage + 1)};
if (stage == 0) if (stage == 0)
return parser::make_TEXT (make_string_uptr ("I have numbers for you."), std::move (loc)); return parser::make_TEXT (make_string_uptr ("I have numbers for you."), std::move (loc));
else if (stage < max) else if (stage < max)

View File

@@ -114,9 +114,10 @@ namespace yy
parser::symbol_type parser::symbol_type
yylex () yylex ()
{ {
static int stage = -1; static int count = 0;
++stage; const int stage = count;
parser::location_type loc (nullptr, stage + 1, stage + 1); ++count;
parser::location_type loc (nullptr, unsigned (stage + 1), unsigned (stage + 1));
switch (stage) switch (stage)
{ {
case 0: case 0: