%not finished!! do this later -- requires nondeterminism function M = regexp2dfsa_s(str) % convert a simple (1 star height) regular expression to a DFSA % see str2dfsa.m for basic dfsa definitions global ALF return function DFSA = str2dfsa(str) % takes a string and returns the "brute-force" dfsa % that accepts it % 1. a DFSA is defined by % 2. an alphabet ALF % 3. a set of states Q % 4. the start state q0 % (-)5. the default state qd % (-) the "default" state, % (-) i.e., the state to which "undefined" transitions go % (-) it is not necessarily a reject state % (-) but it is absorbing % DON'T NEED NO DEFAULT STATE!! % 6. a set of accepting states F \subste {1,2,3,...,Q} % 7. a function delta : (q,s) \mapsto q' % where q\in Q, s\in ALF_in; q'\in Q global ALF %DFSA.ALF = unique(str); % the smallest alphabet required -- not a stable way DFSA.ALF = ALF; DFSA.Q = 1:length(str)+2; % the fewest number of states required DFSA.q0 = 1; %DFSA.qd = DFSA.Q(end); qd = DFSA.Q(end); DFSA.F = [DFSA.Q(end-1)]; qf = [DFSA.Q(end-1)]; DFSA = init_ddelta(DFSA); for j=1:length(str) q1 = j; q2 = j+1; %s = double(str(j)); s = str(j); DFSA = set_ddelta(DFSA,q1,s,q2); %for t=setdiff(double(DFSA.ALF),s) for t=setdiff(DFSA.ALF,s) DFSA = set_ddelta(DFSA,q1,t,qd); end end %for t=double(DFSA.ALF) for t=DFSA.ALF DFSA = set_ddelta(DFSA,qd,t,qd); DFSA = set_ddelta(DFSA,qf,t,qd); end return