//tested public DFAState E_closure(int e) { var newstate = new DFAState(); foreach (var x in edges) { if (x.statement == e) { newstate.AddState(x.lead); } } return(newstate); }
//Todo: need faster public void CreateDFAModel() { var finalNFA = new NFAModel(); var tmpState = new NFAState(0); finalNFA.entryEdge = new NFAEdge(tmpState); var index = 1; foreach (var regex in regexCollection) { var x = regex.NFAModel; tmpState.AddEdge(x.entryEdge); index = x.RenameStates(index); } //make first dfaset DFAState first = new DFAState(tmpState); int id = 0; first.Id = id++; DFAList.Add(first); for (int i = 0; i < DFAList.Count; i++) { var list = new List <int>(); //possible move foreach (var x in DFAList[i].Edges) { if (!list.Contains(x.statement)) { list.Add(x.statement); } } foreach (var x in list) { var lead = DFAList[i].E_closure(x); var have = false; foreach (var u in DFAList) { if (u.isEqual(lead)) { DFAList[i].LeadTo(u, x); have = true; break; } } if (have) { continue; } lead.Id = id++; DFAList[i].LeadTo(lead, x); DFAList.Add(lead); } } //change priority here for (int i = regexCollection.Count - 1; i >= 0; i--) { var op = regexCollection[i]; var nfa = op.NFAModel; foreach (var x in DFAList) { if (x.Contains(nfa.tailState)) { x.isEndState = true; x.describtion = op.Describtion; x.index = op.Index; } } } }
public void LeadTo(DFAState s, int e) { lead.Add(new DFAEdge(s, e)); }
public DFAState(DFAState s) { states = new List <NFAState>(s.states); edges = new List <NFAEdge>(s.edges); }
public bool isEqual(DFAState s) { return(states.Except(s.states).Count() == 0 && s.states.Except(states).Count() == 0); }
public DFAEdge(DFAState state, int statement) { lead = state; this.statement = statement; }
public DFAEdge(DFAState state) { lead = state; }