162
|
1
|
|
2 namespace Implab.Automaton {
|
|
3 /// <summary>
|
|
4 /// Полностью описывает DFA автомат, его поведение, состояние и входные символы.
|
|
5 /// </summary>
|
|
6 /// <example>
|
|
7 /// class MyAutomaton {
|
|
8 /// int m_current;
|
|
9 /// readonly DFAStateDescriptor<string>[] m_automaton;
|
|
10 /// readonly IAlphabet<MyCommands> m_commands;
|
|
11 ///
|
|
12 /// public MyAutomaton(IDFADefinition<MyCommands,MyStates,string> definition) {
|
|
13 /// m_current = definition.StateAlphabet.Translate(MyStates.Initial);
|
|
14 /// m_automaton = definition.GetTransitionTable();
|
|
15 /// m_commands = definition.InputAlphabet;
|
|
16 /// }
|
|
17 ///
|
|
18 /// // defined a method which will move the automaton to the next state
|
|
19 /// public void Move(MyCommands cmd) {
|
|
20 /// // use transition map to determine the next state
|
|
21 /// var next = m_automaton[m_current].transitions[m_commands.Translate(cmd)];
|
|
22 ///
|
|
23 /// // validate that we aren't in the unreachable state
|
|
24 /// if (next == DFAConst.UNREACHABLE_STATE)
|
|
25 /// throw new InvalidOperationException("The specified command is invalid");
|
|
26 ///
|
|
27 /// // if everything is ok
|
|
28 /// m_current = next;
|
|
29 /// }
|
|
30 /// }
|
|
31 /// </example>
|
|
32 public interface IDFADefinition<TInput, TState, TTag> {
|
|
33 /// <summary>
|
|
34 /// Алфавит входных символов
|
|
35 /// </summary>
|
|
36 /// <value>The input alphabet.</value>
|
|
37 IAlphabet<TInput> InputAlphabet {
|
|
38 get;
|
|
39 }
|
|
40
|
|
41 /// <summary>
|
|
42 /// Алфавит состояний автомата
|
|
43 /// </summary>
|
|
44 /// <value>The state alphabet.</value>
|
|
45 IAlphabet<TState> StateAlphabet {
|
|
46 get;
|
|
47 }
|
|
48
|
|
49 /// <summary>
|
|
50 /// Таблица переходов состояний автомата
|
|
51 /// </summary>
|
|
52 /// <returns>The transition table.</returns>
|
|
53 DFAStateDescriptior<TTag>[] GetTransitionTable();
|
|
54
|
|
55 }
|
|
56 }
|