Initial commit
This commit is contained in:
commit
19e609e3b0
7 changed files with 339 additions and 0 deletions
25
utils/operators.cpp
Normal file
25
utils/operators.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include "../turing.cpp"
|
||||
|
||||
/**
|
||||
* @brief Replaces provided string with appriopriate Turing::Instruction<char, char>
|
||||
* it takes 'l' character as a left move
|
||||
*/
|
||||
constexpr Turing::Instruction<char, char> operator ""_i (const char* txt, const size_t len) {
|
||||
char cS = *txt++;
|
||||
char cV = *txt++;
|
||||
char nS = *txt++;
|
||||
char nV = *txt++;
|
||||
Turing::Movement mv = *txt++ == 'l' ? Turing::Movement::left : Turing::Movement::right;
|
||||
return Turing::Instruction<char, char>(cS, cV, nS, nV, mv);
|
||||
};
|
||||
|
||||
// Replaces provided string with aprriopriate vector<char>
|
||||
const std::vector<char> operator ""_v (const char* txt, const size_t len) {
|
||||
auto rvalue = std::vector<char>(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
rvalue[i] = *txt++;
|
||||
}
|
||||
return rvalue;
|
||||
}
|
18
utils/print.cpp
Normal file
18
utils/print.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "../turing.cpp"
|
||||
|
||||
/**
|
||||
* @brief Prints debug-like information about provided machine
|
||||
*/
|
||||
template <typename S, typename V>
|
||||
void print(Turing::Machine<S, V>* machine) {
|
||||
machine->ensure();
|
||||
std::cout << "rc:" << machine->runCount << ", st:" << machine->getState() << '\n';
|
||||
for (int i = machine->getMemoryStart(); i < machine->getMemoryEnd(); i++)
|
||||
std::cout << (machine->at(i));
|
||||
std::cout << '\n';
|
||||
for (int i = machine->getMemoryStart(); i < machine->getPosition(); i++)
|
||||
std::cout << ' ';
|
||||
std::cout << "^\n\n";
|
||||
}
|
Reference in a new issue