private function collectTopStackNodes()
    {
        $nodes = [];

        while (!$this->stack->isEmpty() && $this->stack->top() instanceof Node) {
            array_unshift($nodes, $this->stack->pop());
        }

        return $nodes;
    }