comparison Implab/Automaton/Scanner.cs @ 165:e227e78d72e4 ref20160224

DFA refactoring
author cin
date Mon, 29 Feb 2016 02:02:17 +0300
parents ec35731ae299
children 92d5278d1b10
comparison
equal deleted inserted replaced
164:ec35731ae299 165:e227e78d72e4
27 int m_initialState; 27 int m_initialState;
28 28
29 protected DFAStateDescriptior<TTag> m_currentState; 29 protected DFAStateDescriptior<TTag> m_currentState;
30 int m_previewCode; 30 int m_previewCode;
31 31
32 protected int m_tokenLen = 0; 32 protected int m_tokenLen;
33 protected int m_tokenOffset; 33 protected int m_tokenOffset;
34 34
35 protected char[] m_buffer; 35 protected char[] m_buffer;
36 protected int m_bufferSize; 36 protected int m_bufferSize;
37 protected int m_pointer; 37 protected int m_pointer;
140 do { 140 do {
141 nextState = m_currentState.transitions[m_previewCode]; 141 nextState = m_currentState.transitions[m_previewCode];
142 if (nextState == DFAConst.UNREACHABLE_STATE) { 142 if (nextState == DFAConst.UNREACHABLE_STATE) {
143 if (m_currentState.final) 143 if (m_currentState.final)
144 return true; 144 return true;
145 else 145
146 throw new ParserException( 146 throw new ParserException(
147 String.Format( 147 String.Format(
148 "Unexpected symbol '{0}', at pos {1}", 148 "Unexpected symbol '{0}', at pos {1}",
149 m_buffer[m_pointer], 149 m_buffer[m_pointer],
150 Position 150 Position
151 ) 151 )
152 ); 152 );
153 } else {
154 m_currentState = m_states[nextState];
155 m_tokenLen++;
156 } 153 }
154 m_currentState = m_states[nextState];
155 m_tokenLen++;
157 156
158 } while (Shift()); 157 } while (Shift());
159 158
160 // END OF DATA 159 // END OF DATA
161 if (!m_currentState.final) 160 if (!m_currentState.final)
218 /// Преключает внутренний ДКА на указанный, позволяет реализовать подобие захватывающей 217 /// Преключает внутренний ДКА на указанный, позволяет реализовать подобие захватывающей
219 /// группировки. 218 /// группировки.
220 /// </summary> 219 /// </summary>
221 /// <param name="states">Таблица состояний нового ДКА</param> 220 /// <param name="states">Таблица состояний нового ДКА</param>
222 /// <param name="alphabet">Таблица входных символов для нового ДКА</param> 221 /// <param name="alphabet">Таблица входных символов для нового ДКА</param>
222 /// <param name = "initialState"></param>
223 protected void Switch(DFAStateDescriptior<TTag>[] states, int[] alphabet, int initialState) { 223 protected void Switch(DFAStateDescriptior<TTag>[] states, int[] alphabet, int initialState) {
224 Safe.ArgumentNotNull(states, "dfa"); 224 Safe.ArgumentNotNull(states, "dfa");
225 225
226 m_defs.Push(new ScannerConfig { 226 m_defs.Push(new ScannerConfig {
227 states = m_states, 227 states = m_states,