Mercurial > pub > ImplabNet
comparison Implab/Parsing/DFADefinitionBase.cs @ 156:97fbbf816844 v2
Promises: SignalXXX methods merged into SignalHandler method.
Components: RunnableComponent In progress
| author | cin |
|---|---|
| date | Mon, 15 Feb 2016 04:22:15 +0300 |
| parents | c0bf853aa04f |
| children |
comparison
equal
deleted
inserted
replaced
| 155:037df317f126 | 156:97fbbf816844 |
|---|---|
| 13 public const int INITIAL_STATE = 1; | 13 public const int INITIAL_STATE = 1; |
| 14 public const int UNREACHEBLE_STATE = 0; | 14 public const int UNREACHEBLE_STATE = 0; |
| 15 | 15 |
| 16 DFAStateDescriptior[] m_statesArray; | 16 DFAStateDescriptior[] m_statesArray; |
| 17 | 17 |
| 18 public DFADefinitionBase() { | 18 protected DFADefinitionBase() { |
| 19 m_states = new List<DFAStateDescriptior>(); | 19 m_states = new List<DFAStateDescriptior>(); |
| 20 | 20 |
| 21 m_states.Add(new DFAStateDescriptior()); | 21 m_states.Add(new DFAStateDescriptior()); |
| 22 } | 22 } |
| 23 | 23 |
| 45 return index; | 45 return index; |
| 46 } | 46 } |
| 47 | 47 |
| 48 public int AddState(int[] tag) { | 48 public int AddState(int[] tag) { |
| 49 var index = m_states.Count; | 49 var index = m_states.Count; |
| 50 bool final = tag == null || tag.Length == 0 ? false : true; | 50 bool final = tag != null && tag.Length != 0; |
| 51 m_states.Add(new DFAStateDescriptior { | 51 m_states.Add(new DFAStateDescriptior { |
| 52 final = final, | 52 final = final, |
| 53 transitions = new int[AlphabetSize], | 53 transitions = new int[AlphabetSize], |
| 54 tag = final ? tag : null | 54 tag = final ? tag : null |
| 55 }); | 55 }); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 // строим карты соотвествия оптимальных состояний с оригинальными | 140 // строим карты соотвествия оптимальных состояний с оригинальными |
| 141 | 141 |
| 142 var initialState = optimalStates.Where(x => x.Contains(INITIAL_STATE)).Single(); | 142 var initialState = optimalStates.Single(x => x.Contains(INITIAL_STATE)); |
| 143 | 143 |
| 144 // карта получения оптимального состояния по соотвествующему ему простому состоянию | 144 // карта получения оптимального состояния по соотвествующему ему простому состоянию |
| 145 int[] reveseOptimalMap = new int[m_states.Count]; | 145 int[] reveseOptimalMap = new int[m_states.Count]; |
| 146 // карта с индексами оптимальных состояний | 146 // карта с индексами оптимальных состояний |
| 147 HashSet<int>[] optimalMap = new HashSet<int>[optimalStates.Count + 1]; | 147 HashSet<int>[] optimalMap = new HashSet<int>[optimalStates.Count + 1]; |
| 182 var classes = new Dictionary<int, HashSet<int>>(); | 182 var classes = new Dictionary<int, HashSet<int>>(); |
| 183 | 183 |
| 184 foreach (var term in A) { | 184 foreach (var term in A) { |
| 185 // ищем все переходы класса по символу term | 185 // ищем все переходы класса по символу term |
| 186 var s2 = reveseOptimalMap[ | 186 var s2 = reveseOptimalMap[ |
| 187 optimalMap[s].Select(x => m_states[x].transitions[term]) // все элементарные состояния, куда переходит класс s | 187 optimalMap[s].Select(x => m_states[x].transitions[term]).FirstOrDefault(x => x != 0) // первое допустимое элементарное состояние, если есть |
| 188 .Where(x => x != 0) // только допустимые | 188 ]; |
| 189 .FirstOrDefault() // первое допустимое элементарное состояние, если есть | |
| 190 ]; | |
| 191 | 189 |
| 192 HashSet<int> A2; | 190 HashSet<int> A2; |
| 193 if (!classes.TryGetValue(s2, out A2)) { | 191 if (!classes.TryGetValue(s2, out A2)) { |
| 194 A2 = new HashSet<int>(); | 192 A2 = new HashSet<int>(); |
| 195 newQueue.Enqueue(A2); | 193 newQueue.Enqueue(A2); |
