IDFADefinition.cs
61 lines
| 2.2 KiB
| text/x-csharp
|
CSharpLexer
|
|
r55 | using System; | ||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| namespace Implab.Parsing { | ||||
| /// <summary> | ||||
|
|
r161 | /// Полностью описывает DFA автомат, его поведение, состояние и входные символы. | ||
|
|
r55 | /// </summary> | ||
|
|
r161 | /// <example> | ||
| /// class MyAutomaton { | ||||
| /// int m_current; | ||||
| /// readonly DFAStateDescriptor<string>[] m_automaton; | ||||
| /// readonly IAlphabet<MyCommands> m_commands; | ||||
| /// | ||||
| /// public MyAutomaton(IDFADefinition<MyCommands,MyStates,string> definition) { | ||||
| /// m_current = definition.StateAlphabet.Translate(MyStates.Initial); | ||||
| /// m_automaton = definition.GetTransitionTable(); | ||||
| /// m_commands = definition.InputAlphabet; | ||||
| /// } | ||||
| /// | ||||
| /// // defined a method which will move the automaton to the next state | ||||
| /// public void Move(MyCommands cmd) { | ||||
| /// // use transition map to determine the next state | ||||
| /// var next = m_automaton[m_current].transitions[m_commands.Translate(cmd)]; | ||||
| /// | ||||
| /// // validate that we aren't in the unreachable state | ||||
| /// if (next == DFAConst.UNREACHABLE_STATE) | ||||
| /// throw new InvalidOperationException("The specified command is invalid"); | ||||
| /// | ||||
| /// // if everything is ok | ||||
| /// m_current = next; | ||||
| /// } | ||||
| /// } | ||||
| /// </example> | ||||
| public interface IDFADefinition<TInput, TState, TTag> { | ||||
|
|
r55 | /// <summary> | ||
|
|
r161 | /// Алфавит входных символов | ||
|
|
r55 | /// </summary> | ||
|
|
r161 | /// <value>The input alphabet.</value> | ||
| IAlphabet<TInput> InputAlphabet { | ||||
| get; | ||||
| } | ||||
|
|
r55 | /// <summary> | ||
|
|
r161 | /// Алфавит состояний автомата | ||
|
|
r55 | /// </summary> | ||
|
|
r161 | /// <value>The state alphabet.</value> | ||
| IAlphabet<TState> StateAlphabet { | ||||
| get; | ||||
| } | ||||
|
|
r55 | /// <summary> | ||
|
|
r161 | /// Таблица переходов состояний автомата | ||
|
|
r55 | /// </summary> | ||
|
|
r161 | /// <returns>The transition table.</returns> | ||
| DFAStateDescriptior<TTag>[] GetTransitionTable(); | ||||
|
|
r55 | } | ||
| } | ||||
