function M3 = concat_nfsa(M1,M2) % M3 is the nfsa-concatenation of M1 and M2 % see str2nfsa.m for basic dfsa definitions M3 = M1; nQ1 = length(M1.Q); nQ2 = length(M2.Q); %nQ3 = nQ1 + nQ2 + 1; % wasteful nQ3 = nQ1 + nQ2; M3.Q = 1:nQ3; q_link = nQ1 + M2.q0; % the linking state M3.F = M2.F + nQ1; % make all the accept states of M1 point to q_link for q=M1.F R = nfsa_delta(M1,q,'@'); M3 = set_ndelta(M3,[q],['@'],{union(R,q_link)}); end %treat all states of M2 as incremented by nQ1 for q = M2.Q for s = M2.ALF R = nfsa_delta(M2,q,s); %M3 = set_ndelta(M3,[q+q_link],[s],{R+q_link}); %M3 = set_ndelta(M3,[q+q_link-1],[s],{R+q_link-1}); %no longer a new state M3 = set_ndelta(M3,[q+nQ1],[s],{R+nQ1}); %no longer a new state end end return