diff --git a/src/A3t.cpp b/src/A3t.cpp index 4d5e1bdf8..9fef6a42c 100644 --- a/src/A3t.cpp +++ b/src/A3t.cpp @@ -76,6 +76,16 @@ void A3t::initialize (int argc, const char** argv) } } +//////////////////////////////////////////////////////////////////////////////// +void A3t::clear () +{ + delete _tree; + + _tree = new Tree ("root"); + if (! _tree) + throw std::string ("Failed to allocate memory for parse tree."); +} + //////////////////////////////////////////////////////////////////////////////// // Add an arg for every word from std::cin. // @@ -514,11 +524,12 @@ Tree* A3t::captureFirst (const std::string& arg) t->_trunk = _tree; std::vector ::iterator i = _tree->_branches.begin (); - i++; // Walk past the binary. + if (i != _tree->_branches.end ()) + i++; // Walk past the binary. _tree->_branches.insert (i, t); - findCommand (); + findCommand (); return t; } diff --git a/src/A3t.h b/src/A3t.h index b92a9231e..8a050890b 100644 --- a/src/A3t.h +++ b/src/A3t.h @@ -38,6 +38,7 @@ public: A3t (); ~A3t (); void initialize (int, const char**); + void clear (); void appendStdin (); Tree* tree (); Tree* parse ();