automaton__print_dfa Subroutine

private subroutine automaton__print_dfa(self, uni)

This subroutine prints DFA states and transitions to a given unit number.

Type Bound

automaton_t

Arguments

Type IntentOptional Attributes Name
class(automaton_t), intent(in) :: self
integer(kind=int32), intent(in) :: uni

Source Code

   subroutine automaton__print_dfa(self, uni)
      use :: forgex_nfa_state_set_m, only: print_nfa_state_set
      use :: forgex_lazy_dfa_node_m, only: dfa_transition_t
      implicit none
      class(automaton_t), intent(in) :: self
      integer(int32), intent(in) :: uni

      type(segment_t), allocatable :: segments(:)
      type(dfa_transition_t) :: p
      integer(int32) :: i, j, k

      do i = 1, self%dfa%dfa_top -1

         if (self%dfa%nodes(i)%accepted) then
            write(uni, '(i4,a, a)', advance='no') i, 'A', ": "
         else
            write(uni, '(i4,a, a)', advance='no') i, ' ', ": "
         end if

         do j = 1, self%dfa%nodes(i)%get_tra_top()

            if (allocated(segments)) deallocate(segments)
            call self%dfa%nodes(i)%transition(j)%c%cube2seg(segments)

            if (allocated(segments)) then
               do k = 1, size(segments, dim=1)
                  write(uni, '(a, a, i0, 1x)', advance='no') segments(k)%print(), '=>', self%dfa%nodes(i)%transition(j)%dst
               end do
            end if

         end do
         write(uni, *) ""
      end do

      do i = 1, self%dfa%dfa_top - 1
         if (self%dfa%nodes(i)%accepted) then
            write(uni, '(a, i4, a)', advance='no') "state ", i, 'A = ( '
         else
            write(uni, '(a, i4, a)', advance='no') "state ", i, '  = ( '
         end if

         call print_nfa_state_set(self%dfa%nodes(i)%nfa_set, self%nfa%top, uni)

         write(uni,'(a)') ")"
      end do
   end subroutine automaton__print_dfa