comparison Implab/Automaton/RegularExpressions/RegularDFA.cs @ 183:4f82e0f161c3 ref20160224

fixed DFA optimization, JSON is fully functional
author cin
date Fri, 25 Mar 2016 02:49:02 +0300
parents 76e8f2ba12b8
children fa6cbf4d8841
comparison
equal deleted inserted replaced
182:76e8f2ba12b8 183:4f82e0f161c3
64 64
65 // make the alphabet for the new DFA 65 // make the alphabet for the new DFA
66 // skip all unclassified symbols 66 // skip all unclassified symbols
67 foreach (var pair in alphaMap.Where(x => x.Value != 0)) 67 foreach (var pair in alphaMap.Where(x => x.Value != 0))
68 alphabet.DefineClass(m_alphabet.GetSymbols(pair.Key), pair.Value); 68 alphabet.DefineClass(m_alphabet.GetSymbols(pair.Key), pair.Value);
69
70 var orig = ToString();
71 var opt = dfa.ToString();
72
73 return dfa; 69 return dfa;
74 } 70 }
75 71
76 protected override IEnumerable<HashSet<int>> GroupFinalStates() { 72 protected override IEnumerable<HashSet<int>> SplitFinalStates(IEnumerable<int> states) {
77 var arrayComparer = new CustomEqualityComparer<TTag[]>( 73 var arrayComparer = new CustomEqualityComparer<TTag[]>(
78 (x,y) => x.Length == y.Length && x.All(it => y.Contains(it)), 74 (x,y) => x.Length == y.Length && x.All(it => y.Contains(it)),
79 x => x.Sum(it => x.GetHashCode()) 75 x => x.Sum(it => x.GetHashCode())
80 ); 76 );
81 return FinalStates.GroupBy(x => m_tags[x], arrayComparer).Select(g => new HashSet<int>(g)); 77 return states.GroupBy(x => m_tags[x] ?? new TTag[0], arrayComparer).Select(g => new HashSet<int>(g));
82 } 78 }
83 79
84 public override string ToString() { 80 public override string ToString() {
85 var states = new MapAlphabet<string>(false, null); 81 var states = new MapAlphabet<string>(false, null);
86 82