public function next()
    {
        $this->initialize();

        if (!empty($this->stack)) {
            $this->step++;
            $iterator = end($this->stack);

            if ($iterator->valid()) {
                $this->processStack($iterator, end($this->stackType));
                $iterator->next();
            } else {
                $this->popStack();
            }
        } else {
            $this->step = null;
        }
    }