annotate Implab/Automaton/EDFADefinition.cs @ 163:419aa51b04fd ref20160224

JSON moved to Formats namespace Working in RegularDFA
author cin
date Wed, 24 Feb 2016 20:12:52 +0300
parents 0526412bbb26
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
162
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
1 using Implab;
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
2 using System;
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
3
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
4 namespace Implab.Parsing {
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
5 public class EDFADefinition<T> : DFADefinition where T : struct, IConvertible {
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
6 readonly EnumAlphabet<T> m_alphabet;
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
7
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
8 public EnumAlphabet<T> Alphabet {
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
9 get { return m_alphabet; }
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
10 }
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
11
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
12 public EDFADefinition(EnumAlphabet<T> alphabet) : base(alphabet.Count) {
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
13 m_alphabet = alphabet;
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
14 }
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
15
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
16 public void DefineTransition(int s1, int s2, T input) {
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
17 DefineTransition(s1, s2, m_alphabet.Translate(input));
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
18 }
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
19
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
20 public EDFADefinition<T> Optimize() {
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
21
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
22 return (EDFADefinition<T>)Optimize(alphabet => new EDFADefinition<T>((EnumAlphabet<T>)alphabet), m_alphabet, new EnumAlphabet<T>());
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
23 }
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
24
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
25 public void PrintDFA() {
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
26 PrintDFA(m_alphabet);
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
27 }
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
28 }
0526412bbb26 DFA refactoring
cin
parents:
diff changeset
29 }