comparison Implab/Automaton/RegularExpressions/RegularDFABuilder.cs @ 164:ec35731ae299 ref20160224

Almost complete DFA refactoring
author cin
date Thu, 25 Feb 2016 02:11:13 +0300
parents 419aa51b04fd
children e227e78d72e4
comparison
equal deleted inserted replaced
163:419aa51b04fd 164:ec35731ae299
120 m_lastpos = new HashSet<int>(new[] { m_idx }); 120 m_lastpos = new HashSet<int>(new[] { m_idx });
121 Followpos(m_idx); 121 Followpos(m_idx);
122 m_ends.Add(m_idx, token.Tag); 122 m_ends.Add(m_idx, token.Tag);
123 } 123 }
124 124
125 public void BuildDFA(IDFADefinitionBuilder<TTag> dfa) { 125 public void BuildDFA(IDFATransitionTableBuilder<TTag> dfa) {
126 Safe.ArgumentNotNull(dfa,"dfa"); 126 Safe.ArgumentNotNull(dfa,"dfa");
127 127
128 var states = new MapAlphabet<HashSet<int>>(new CustomEqualityComparer<HashSet<int>>( 128 var states = new MapAlphabet<HashSet<int>>(new CustomEqualityComparer<HashSet<int>>(
129 (x, y) => x.SetEquals(y), 129 (x, y) => x.SetEquals(y),
130 x => x.Sum(n => n.GetHashCode()) 130 x => x.Sum(n => n.GetHashCode())
131 )); 131 ));
132 132
133 var initialState = states.DefineSymbol(m_firstpos); 133 var initialState = states.DefineSymbol(m_firstpos);
134 134 dfa.SetInitialState(initialState);
135
135 var tags = GetStateTags(m_firstpos); 136 var tags = GetStateTags(m_firstpos);
136 if (tags != null && tags.Length > 0) 137 if (tags != null && tags.Length > 0)
137 dfa.MarkFinalState(initialState, tags); 138 dfa.MarkFinalState(initialState, tags);
138 139
139 var inputMax = m_indexes.Values.Max(); 140 var inputMax = m_indexes.Values.Max();