lalr1.cc: use a vector for the symbol stack

* data/lalr1.cc: Adjust includes.
* data/stack.hh (push, pop): Use push_back and pop_back.
(operator []): Access vector from the end.
This commit is contained in:
Theophile Ranquet
2012-12-21 16:46:05 +01:00
parent 1dbaf37f5c
commit e7b26e942d
2 changed files with 7 additions and 7 deletions

View File

@@ -146,7 +146,7 @@ b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])])
m4_define([b4_shared_declarations], m4_define([b4_shared_declarations],
[b4_percent_code_get([[requires]])[ [b4_percent_code_get([[requires]])[
]b4_parse_assert_if([# include <cassert>])[ ]b4_parse_assert_if([# include <cassert>])[
# include <deque> # include <vector>
# include <iostream> # include <iostream>
# include <stdexcept> # include <stdexcept>
# include <string>]b4_defines_if([[ # include <string>]b4_defines_if([[

View File

@@ -21,7 +21,7 @@ m4_pushdef([b4_copyright_years],
# b4_stack_define # b4_stack_define
# --------------- # ---------------
m4_define([b4_stack_define], m4_define([b4_stack_define],
[[ template <class T, class S = std::deque<T> > [[ template <class T, class S = std::vector<T> >
class stack class stack
{ {
public: public:
@@ -43,21 +43,21 @@ m4_define([b4_stack_define],
T& T&
operator [] (unsigned int i) operator [] (unsigned int i)
{ {
return seq_[i]; return seq_[seq_.size () - 1 - i];
} }
inline inline
const T& const T&
operator [] (unsigned int i) const operator [] (unsigned int i) const
{ {
return seq_[i]; return seq_[seq_.size () - 1 - i];
} }
inline inline
void void
push (const T& t) push (const T& t)
{ {
seq_.push_front (t); seq_.push_back (t);
} }
inline inline
@@ -65,7 +65,7 @@ m4_define([b4_stack_define],
pop (unsigned int n = 1) pop (unsigned int n = 1)
{ {
for (; n; --n) for (; n; --n)
seq_.pop_front (); seq_.pop_back ();
} }
inline inline
@@ -129,7 +129,7 @@ b4_copyright([Stack handling for Bison parsers in C++])[
]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[ ]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
# include <deque> # include <vector>
]b4_namespace_open[ ]b4_namespace_open[
]b4_stack_define[ ]b4_stack_define[