compute_reachable_state Function

private pure function compute_reachable_state(automaton, curr) result(state_set)

This function calculates a set of possible NFA states from the current DFA state.

It scans through the NFA states and finds the set of reachable states excluding ε-transitions.

Arguments

Type IntentOptional Attributes Name
type(automaton_t), intent(in) :: automaton
integer, intent(in) :: curr

Return Value type(nfa_state_set_t)


Source Code

   pure function compute_reachable_state(automaton, curr) result(state_set)
      use :: forgex_nfa_node_m, only: nfa_state_node_t, nfa_transition_t
      implicit none
      type(automaton_t), intent(in) :: automaton
      integer, intent(in) :: curr
      type(nfa_state_set_t) :: state_set

      type(nfa_state_set_t) :: current_set
      type(nfa_state_node_t) :: n_node
      type(nfa_transition_t) :: n_tra
      integer :: i, j, k

      call init_state_set(state_set, automaton%nfa%nfa_top)

      if (.not. allocated(automaton%dfa%nodes(curr)%nfa_set%vec)) return

      current_set = automaton%dfa%nodes(curr)%nfa_set

      outer: do i = 1, automaton%nfa%nfa_top

         if (check_nfa_state(current_set, i)) then
            n_node = automaton%nfa%nodes(i)
            if (.not. allocated(n_node%forward)) cycle

            middle: do j = 1, n_node%forward_top
               n_tra = n_node%forward(j)
               do k = 1, n_tra%c_top
                  if (n_tra%dst /= NFA_NULL_TRANSITION) then
                     call add_nfa_state(state_set, n_node%forward(j)%dst)
                  end if
               end do
            end do middle
         end if
      end do outer
   end function compute_reachable_state