|
TuringSim
C++ framework to simulate abstract computing models
|
3 #include <utils/visitor.h>
4 #include <state/mConfiguration/mConfiguration.h>
5 #include <transition/Turing/localTuringMachineTransition.h>
23 typename NodeStateType_,
29 std::shared_ptr<const State::MConfiguration::MConfiguration<NodeStateType_>>,
31 MConfigurationTuringMachineTransitionApplyHelper<NodeStateType_>,
34 typedef std::shared_ptr<const State::MConfiguration::MConfiguration<NodeStateType_>> StateType_;
84 #pragma clang diagnostic push
85 #pragma clang diagnostic ignored "-Wunused-parameter"
103 #pragma clang diagnostic pop
134 typedef std::variant<MovementInstruction, EraseInstruction, WriteInstruction>
Instruction;
143 template <
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
144 friend std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const MovementInstruction& mi) {
145 os <<
"move(" << mi.movement <<
")";
150 #pragma clang diagnostic push
151 #pragma clang diagnostic ignored "-Wunused-parameter"
159 template <
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
160 friend std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const EraseInstruction& ei) {
164 #pragma clang diagnostic pop
173 template <
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
174 friend std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os,
const WriteInstruction& wi) {
175 os <<
"write(" << wi.symbol <<
")";
186 template <
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
191 [&os](
const MovementInstruction& mi) {
194 [&os](
const EraseInstruction& ei) {
197 [&os](
const WriteInstruction& wi) {
236 [&tape](
const MovementInstruction& m) ->
void { tape.move(m.movement); },
237 [&tape](
const EraseInstruction& ) ->
void { tape.erase(); },
238 [&tape](
const WriteInstruction& w) ->
void { tape.write(w.symbol); },
251 const MovementInstruction& mi = std::get<MovementInstruction>(i);
252 if (mi.movement == StorageType::Movement::HALT) {
257 catch (std::bad_variant_access) {
Base class for Turing machine transitions that works with m-configurations.
MConfigurationTuringMachineTransitionApplyHelper< T > ApplyHelperType
The type of apply helpers.
Visitor(Ts...) -> Visitor< Ts... >
The deduction guide for Visitor, useless since C++20.
bool operator<(const MovementInstruction &other) const
Less than comparison. Strong ordering.
Movement movement
The movement to execute.
bool operator<(const WriteInstruction &other) const
Less than comparison. Strong ordering.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const WriteInstruction &wi)
Debug printer for write instructions.
Transitions for Turing machines.
virtual ~MConfigurationTuringMachineTransition() override=default
The default virtual destructor.
MConfigurationTuringMachineTransition()=default
The default constructor.
StorageType_::Movement Movement
The type of movement on the tape.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const MovementInstruction &mi)
Debug printer for movement instructions.
StateType_ StateType
The type of states.
MConfigurationTuringMachineTransition(const MConfigurationTuringMachineTransition &)=default
The default copy constructor.
ApplyHelperType_ ApplyHelperType
The type of apply helpers.
ApplyHelperType SubstitutionType
The type of substitutions, same as apply helper.
std::integral_constant< bool, hasHalfTape > HasHalfTape
Whether the tape is a half-tape or a full tape.
StorageType_::Movement Movement
The type of movement on the tape.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const Instruction &i)
Debug printer for instructions.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const EraseInstruction &ei)
Debug printer for erase instructions.
bool operator==(const WriteInstruction &other) const
Equality comparison.
bool operator==(const EraseInstruction &other) const
Equality comparison.
MConfigurationTuringMachineTransition & operator=(MConfigurationTuringMachineTransition &&)=default
The default move assignment operator.
bool operator!=(const WriteInstruction &other) const
Un-equality comparison.
MConfigurationTuringMachineTransition(MConfigurationTuringMachineTransition &&)=default
The default move constructor.
bool operator!=(const EraseInstruction &other) const
Un-equality comparison.
std::variant< MovementInstruction, EraseInstruction, WriteInstruction > Instruction
either a MovementInstruction, a EraseInstruction or a WriteInstruction.
void run_instruction(StorageType &tape, const Instruction &instruction) const
Run a single instruction given a tape.
SymbolType_ SymbolType
The type of symbols on the tape.
SymbolType symbol
The symbol to write.
bool operator<(const EraseInstruction &other) const
Less than comparison. Strong ordering.
MConfigurationTuringMachineTransition & operator=(const MConfigurationTuringMachineTransition &)=default
The default copy assignment operator.
An instruction that erases the current symbol.
bool operator!=(const MovementInstruction &other) const
Un-equality comparison.
StorageType_ StorageType
The type of storage.
SymbolType_ SymbolType
The type of symbols on the tape.
void run_instructions(StorageType &tape, bool &running, const std::vector< Instruction > &instructions) const
Run a vector of instructions.
bool operator==(const MovementInstruction &other) const
Equality comparison.
An instruction that writes a symbol on the tape..
An instruction that performs a move on the tape.
std::map< T, std::shared_ptr< const State::MConfiguration::MConfiguration< T > >> MConfigurationTuringMachineTransitionApplyHelper
The helper of MConfigurationTuringMachineTransition<T, _, _>
Memory::TapeLike< hasHalfTape, T > StorageType
The type of storage.
NodeStateType_ NodeStateType
The type of the nodes in the m-configurations.
Base class for Turing machine transitions that only reads the current symbol on the tape to decide if...