function M2 = kleene_nfsa(M1) % M3 is the kleene-star of M1 % see str2nfsa.m for basic dfsa definitions M2 = M1; nQ1 = length(M1.Q); nQ2 = nQ1+1; M2.Q = 1:nQ2; M2.q0 = nQ2; M2.F = [nQ2]; %every accept state gets an epsilon-transition to nQ2 for q=M1.F R = nfsa_delta(M2,q,'@'); M2 = set_ndelta(M2,[q],['@'],{union(R,nQ2)}); end %M2 = set_ndelta(M2,[nQ2],['@'],{[M1.q0 nQ2]}); % don't need an eps-transition to yourself: M2 = set_ndelta(M2,[nQ2],['@'],{[M1.q0]}); return