##// END OF EJS Templates
sync
cin -
r166:b84cdbe82e7f ref20160224
parent child
Show More
@@ -1,33 +1,33
1 using System;
1 using System;
2
2
3 namespace Implab.Automaton {
3 namespace Implab.Automaton {
4 struct AutomatonTransition : IEquatable<AutomatonTransition> {
4 public struct AutomatonTransition : IEquatable<AutomatonTransition> {
5 public readonly int s1;
5 public readonly int s1;
6 public readonly int s2;
6 public readonly int s2;
7 public readonly int edge;
7 public readonly int edge;
8
8
9 public AutomatonTransition(int s1, int s2, int edge) {
9 public AutomatonTransition(int s1, int s2, int edge) {
10 this.s1 = s1;
10 this.s1 = s1;
11 this.s2 = s2;
11 this.s2 = s2;
12 this.edge = edge;
12 this.edge = edge;
13 }
13 }
14
14
15
15
16 #region IEquatable implementation
16 #region IEquatable implementation
17 public bool Equals(AutomatonTransition other) {
17 public bool Equals(AutomatonTransition other) {
18 return other.s1 == s1 && other.s2 == s2 && other.edge == edge ;
18 return other.s1 == s1 && other.s2 == s2 && other.edge == edge ;
19 }
19 }
20 #endregion
20 #endregion
21
21
22 public override bool Equals(object obj) {
22 public override bool Equals(object obj) {
23 if (obj is AutomatonTransition)
23 if (obj is AutomatonTransition)
24 return Equals((AutomatonTransition)obj);
24 return Equals((AutomatonTransition)obj);
25 return base.Equals(obj);
25 return base.Equals(obj);
26 }
26 }
27
27
28 public override int GetHashCode() {
28 public override int GetHashCode() {
29 return s1 + s2 + edge;
29 return s1 + s2 + edge;
30 }
30 }
31 }
31 }
32 }
32 }
33
33
@@ -1,59 +1,59
1 using System.Collections.Generic;
1 using System.Collections.Generic;
2
2
3
3
4 namespace Implab.Automaton {
4 namespace Implab.Automaton {
5 /// <summary>
5 /// <summary>
6 /// Полностью описывает DFA автомат, его поведение, состояние и входные символы.
6 /// Полностью описывает DFA автомат, его поведение, состояние и входные символы.
7 /// </summary>
7 /// </summary>
8 /// <example>
8 /// <example>
9 /// class MyAutomaton {
9 /// class MyAutomaton {
10 /// int m_current;
10 /// int m_current;
11 /// readonly DFAStateDescriptor<string>[] m_automaton;
11 /// readonly DFAStateDescriptor<string>[] m_automaton;
12 /// readonly IAlphabet<MyCommands> m_commands;
12 /// readonly IAlphabet<MyCommands> m_commands;
13 ///
13 ///
14 /// public MyAutomaton(IDFADefinition&lt;MyCommands,MyStates,string&gt; definition) {
14 /// public MyAutomaton(IDFADefinition&lt;MyCommands,MyStates,string&gt; definition) {
15 /// m_current = definition.StateAlphabet.Translate(MyStates.Initial);
15 /// m_current = definition.StateAlphabet.Translate(MyStates.Initial);
16 /// m_automaton = definition.GetTransitionTable();
16 /// m_automaton = definition.GetTransitionTable();
17 /// m_commands = definition.InputAlphabet;
17 /// m_commands = definition.InputAlphabet;
18 /// }
18 /// }
19 ///
19 ///
20 /// // defined a method which will move the automaton to the next state
20 /// // defined a method which will move the automaton to the next state
21 /// public void Move(MyCommands cmd) {
21 /// public void Move(MyCommands cmd) {
22 /// // use transition map to determine the next state
22 /// // use transition map to determine the next state
23 /// var next = m_automaton[m_current].transitions[m_commands.Translate(cmd)];
23 /// var next = m_automaton[m_current].transitions[m_commands.Translate(cmd)];
24 ///
24 ///
25 /// // validate that we aren't in the unreachable state
25 /// // validate that we aren't in the unreachable state
26 /// if (next == DFAConst.UNREACHABLE_STATE)
26 /// if (next == DFAConst.UNREACHABLE_STATE)
27 /// throw new InvalidOperationException("The specified command is invalid");
27 /// throw new InvalidOperationException("The specified command is invalid");
28 ///
28 ///
29 /// // if everything is ok
29 /// // if everything is ok
30 /// m_current = next;
30 /// m_current = next;
31 /// }
31 /// }
32 /// }
32 /// }
33 /// </example>
33 /// </example>
34 public interface IDFATable {
34 public interface IDFATable : IEnumerable<AutomatonTransition> {
35 /// <summary>
35 /// <summary>
36 /// Таблица переходов состояний автомата
36 /// Таблица переходов состояний автомата
37 /// </summary>
37 /// </summary>
38 /// <returns>The transition table.</returns>
38 /// <returns>The transition table.</returns>
39 DFAStateDescriptior[] GetTransitionTable();
39 DFAStateDescriptior[] GetTransitionTable();
40
40
41 int StateCount {
41 int StateCount {
42 get;
42 get;
43 }
43 }
44
44
45 int AlphabetSize {
45 int AlphabetSize {
46 get;
46 get;
47 }
47 }
48
48
49 int InitialState {
49 int InitialState {
50 get;
50 get;
51 }
51 }
52
52
53 bool IsFinalState(int s);
53 bool IsFinalState(int s);
54
54
55 IEnumerable<int> FinalStates {
55 IEnumerable<int> FinalStates {
56 get;
56 get;
57 }
57 }
58 }
58 }
59 }
59 }
General Comments 0
You need to be logged in to leave comments. Login now