function b = run_nfsa(NFSA,str) %function [b,B] = run_nfsa(NFSA,str) % B is the acceptance status of the string during the run % does the given NFSA accept str? % see str2nfsa.m for basic nfsa definitions % this is tricky because of epsilon-transitions % which allow potentially infinite loops % we take care of this by keeping track of a "state of the world" % WRLD(:,1) = position of automaton head on str (already read) % WRLD(:,2) = current state of automaton global WRLD %B = []; TQ = [0 NFSA.q0]; WRLD = TQ; while ~isempty(TQ); TQ = advance_head(NFSA,TQ,str); end % now deciding acceptance is easy: x=find(WRLD(:,1)==length(str)); y=WRLD(x,2); b=any(ismember(y,NFSA.F)); return function TQ1 = advance_head(NFSA,TQ,str) global WRLD TQ1=[]; for j=1:size(TQ,1) t = TQ(j,1); q = TQ(j,2); % all the states from epsilon-transitions: Re = nfsa_delta(NFSA,q,'@'); TQe = update_world(Re,t); % all the states from other transitions: TQs = []; if (t