diff --git a/src/parser/Tree.cpp b/src/parser/Tree.cpp index a6e77490f..c7956c455 100644 --- a/src/parser/Tree.cpp +++ b/src/parser/Tree.cpp @@ -76,10 +76,14 @@ Tree* Tree::operator[] (const int branch) } //////////////////////////////////////////////////////////////////////////////// -void Tree::addBranch (Tree* branch) +Tree* Tree::addBranch (Tree* branch) { + if (! branch) + throw "Failed to allocate memory for parse tree."; + branch->_trunk = this; _branches.push_back (branch); + return branch; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/parser/Tree.h b/src/parser/Tree.h index 6ef10b36e..fae8ebfd1 100644 --- a/src/parser/Tree.h +++ b/src/parser/Tree.h @@ -42,7 +42,7 @@ public: Tree& operator= (const Tree&); Tree* operator[] (const int); - void addBranch (Tree*); + Tree* addBranch (Tree*); void removeBranch (Tree*); void replaceBranch (Tree*, Tree*); int branches ();