Exemplo n.º 1
0
    def union_nfa(self, nfa: NFA, unioning_state: State = None) -> None:
        """
        union_nfa
        Add a union from the last open group (or initial state) to existing NFA.

        :param nfa: The existing NFA.
        :param unioning_state: An optional state to union from (otherwise: last open group)
        """

        start_union = unioning_state if unioning_state else self.open_groups[-1]

        self.union_in_progress.append((start_union, self.last_state))
        logging.debug('Opening union: ' + str((start_union, self.last_state)))

        if start_union in nfa.accepting_states:
            nfa.accepting_states.remove(start_union)

        # If my open group is at the initial state, make a new state
        if start_union == nfa.initial_state:
            self.last_state = nfa.replace_initial()
        # Otherwise, connect a new epsilon path out of the
        # open group state for the other part of the union
        else:
            self.last_state = nfa.add_epsilon_connector(start_union)