annotate Implab/Automaton/RegularExpressions/RegularDFADefinition.cs @ 165:e227e78d72e4 ref20160224

DFA refactoring
author cin
date Mon, 29 Feb 2016 02:02:17 +0300
parents ec35731ae299
children 54270c2f29f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
1 using System;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
2
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
3 namespace Implab.Automaton.RegularExpressions {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
4 public class RegularDFADefinition<TInput, TTag> : DFATransitionTable<TTag>, IDFATransitionTable<TTag> {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
5
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
6 readonly IAlphabet<TInput> m_alphabet;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
7
165
e227e78d72e4 DFA refactoring
cin
parents: 164
diff changeset
8 public RegularDFADefinition(IAlphabet<TInput> alphabet) {
164
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
9 Safe.ArgumentNotNull(alphabet, "aplhabet");
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
10
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
11 m_alphabet = alphabet;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
12 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
13
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
14
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
15 public IAlphabet<TInput> InputAlphabet {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
16 get {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
17 return m_alphabet;
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
18 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
19 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
20
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
21 protected override DFAStateDescriptior<TTag>[] ConstructTransitionTable() {
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
22 if (InputAlphabet.Count != m_alphabet.Count)
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
23 throw new InvalidOperationException("The alphabet doesn't match the transition table");
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
24
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
25 return base.ConstructTransitionTable();
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
26 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
27
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
28 /// <summary>
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
29 /// Optimize the specified alphabet.
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
30 /// </summary>
165
e227e78d72e4 DFA refactoring
cin
parents: 164
diff changeset
31 /// <param name = "dfaTable"></param>
164
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
32 /// <param name="alphabet">Пустой алфавит, который будет зполнен в процессе оптимизации.</param>
165
e227e78d72e4 DFA refactoring
cin
parents: 164
diff changeset
33 public void Optimize(IDFATableBuilder<TTag> dfaTable, IAlphabetBuilder<TInput> alphabet) {
164
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
34 Safe.ArgumentNotNull(alphabet, "alphabet");
165
e227e78d72e4 DFA refactoring
cin
parents: 164
diff changeset
35 Safe.ArgumentNotNull(dfaTable, "dfaTable");
164
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
36
165
e227e78d72e4 DFA refactoring
cin
parents: 164
diff changeset
37 Optimize(dfaTable, InputAlphabet, alphabet, new DummyAlphabet(StateCount), new MapAlphabet<int>());
164
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
38 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
39
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
40
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
41 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
42 }
ec35731ae299 Almost complete DFA refactoring
cin
parents:
diff changeset
43