public override NFAModel ConvertAlternationCharSet(AlternationCharSetExpression exp) { NFAState head = new NFAState(); NFAState tail = new NFAState(); //build edges NFAModel charSetNfa = new NFAModel(); charSetNfa.AddState(head); HashSet <int> classesSet = new HashSet <int>(); foreach (var symbol in exp.CharSet) { int cclass = CompactCharSetManager.GetCompactClass(symbol); if (classesSet.Add(cclass)) { var symbolEdge = new NFAEdge(cclass, tail); head.AddEdge(symbolEdge); } } charSetNfa.AddState(tail); //add an empty entry edge charSetNfa.EntryEdge = new NFAEdge(head); charSetNfa.TailState = tail; return(charSetNfa); }
public void Build() { Debug.Assert(m_predicateList.Count == m_expFutureList.Count); if (m_predicateList.Count == 0) { return; } List<char>[] charSetList = new List<char>[m_predicateList.Count]; for (int j = 0; j < m_predicateList.Count; j++) { charSetList[j] = new List<char>(); } for (int i = Char.MinValue; i < Char.MaxValue; i++) { char c = (char)i; for (int j = 0; j < m_predicateList.Count; j++) { if (m_predicateList[j](c)) { charSetList[j].Add(c); } } } for (int j = 0; j < m_predicateList.Count; j++) { RegularExpression charSetExp = new AlternationCharSetExpression(charSetList[j]); m_expFutureList[j](charSetExp); } }
public abstract T ConvertAlternationCharSet(AlternationCharSetExpression exp);