function Ar = rev_fsa(A) % Ar is the reverse fsa of A % both are of type nfsa if empty_fsa(A) % degenerate special case Ar = A; return end % make a new initial state, which epsilon-transitions % to the final states of A nq = length(A.Q); Ar.Q = 1:(nq+1); Ar.q0 = nq+1; Ar.F = [A.q0]; Ar.ALF = A.ALF; Ar = init_ndelta(Ar); %for q=A.F Ar = set_ndelta(Ar,Ar.q0,repmat(['@'],length(A.F),1),{A.F}); %end for q=A.Q [pp,ss] = get_ndparents(A,q); us = unique(ss); for s=us x = find(ss==s); R = pp(x); Ar = set_ndelta(Ar,[q],[s],{R}); end end Ar = prune_eps(Ar); Ar = remove_unreachable(Ar); return