-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTuringMachine.h
44 lines (35 loc) · 1.12 KB
/
TuringMachine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include "AbstractTuringMachine.h"
namespace trmch {
template<
class State = int,
class InputSymbol = char,
class TapeSymbol = char,
class Input = std::string,
class Tape = std::string>
class TuringMachine : public AbstractTuringMachine<State, InputSymbol, TapeSymbol, Input, Tape>
{
using NextStep = AbstractTuringMachine<>::NextStep;
public:
struct Transition {
State stateFrom;
TapeSymbol symbolOriginal;
NextStep nextStep;
};
TuringMachine(State q0, State qA, State qR, const std::vector<Transition>& deltaFunction)
: AbstractTuringMachine<>(q0, qA, qR),
m_deltaFunction(deltaFunction) {}
protected:
void oneStep(State currentState, TapeSymbol currentSymbol, NextStep& nextStep) const override {
for(const Transition& transition : m_deltaFunction)
{
if(transition.stateFrom == currentState && transition.symbolOriginal == currentSymbol)
{
nextStep = transition.nextStep;
}
}
}
private:
std::vector<Transition> m_deltaFunction;
};
}