function NFSA = str2nfsa(str,localf) % takes a string and returns the "brute-force" nfsa % that accepts it % 1. a NFSA is defined by % 2. an alphabet ALF % 3. a set of states Q % 4. a start state q0 % 5. a set of accepting states F \subste {1,2,3,...,Q} % 6. a function delta : (q,s) \mapsto Q' % where Q' \subset Q, s\in ALF_in; q'\in Q if ~exist('localf','var'), global ALF, localf = ALF; else, ALF = localf; end %remove the blank char!!! str = strrep(str,'@',''); NFSA.ALF = ['@' ALF]; % the character @ stands for the epsilon-char NFSA.Q = 1:length(str)+1; % the fewest number of states required NFSA.q0 = 1; NFSA.F = [NFSA.Q(end)]; NFSA = init_ndelta(NFSA); for j=1:length(str) q1 = j; Q2 = [j+1]; s = str(j); NFSA = set_ndelta(NFSA,[q1],[s],{Q2}); end return