private function validateDeterministicShiftReduce(
        array $finite,
        array $terminals,
        array $nonTerminals,
        Grammar $grammar
    ): void {
        if ($finite && $terminals) {
            $left_terminals = $grammar->getTerminals();
            foreach ($terminals as $item) {
                unset($left_terminals[$item->getExpected()->getName()]);
            }
            if (!$left_terminals) {
                throw new ConflictShiftReduceException(
                    array_merge($finite, $terminals, $nonTerminals)
                );
            }
        }
    }