/
Machine.h
73 lines (61 loc) · 2.04 KB
/
Machine.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include <memory>
#include <set>
#include "Tape.h"
#include "StatesUtil.h"
#include <iostream>
#include <algorithm>
using std::cout;
using std::endl;
using std::set;
using std::ostream;
using std::invalid_argument;
using std::set_union;
class Machine;
typedef set<char> symbol_set;
const string BLACK_TEXT = "\x1B[30m";
const string RED_TEXT = "\x1B[31m";
const string GREEN_TEXT = "\x1B[32m";
const string YELLOW_TEXT = "\x1B[33m";
const string BLUE_TEXT = "\x1B[34m";
const string MAGENTA_TEXT = "\x1B[35m";
const string CYAN_TEXT = "\x1B[36m";
const string WHITE_TEXT = "\x1B[37m";
const string BRIGHT_BLACK_TEXT = "\x1B[90m";
const string BRIGHT_RED_TEXT = "\x1B[91m";
const string BRIGHT_GREEN_TEXT = "\x1B[92m";
const string BRIGHT_YELLOW_TEXT = "\x1B[93m";
const string BRIGHT_BLUE_TEXT = "\x1B[94m";
const string BRIGHT_MAGENTA_TEXT = "\x1B[95m";
const string BRIGHT_CYAN_TEXT = "\x1B[96m";
const string BRIGHT_WHITE_TEXT = "\x1B[97m";
const string RESET_COLORING = "\033[0m";
static unsigned produced_machines = 0;
struct MachineSymbols {
symbol_set sigma;
symbol_set gamma;
char blank_symbol;
MachineSymbols(symbol_set sigma = symbol_set(), symbol_set gamma = symbol_set(), char blank_symbol = ' ') : sigma(sigma), gamma(gamma), blank_symbol(blank_symbol) {};
void printSymbols(ostream& os, symbol_set printable) const;
MachineSymbols& compose(const MachineSymbols& other) const;
};
class Machine {
friend class MachineBuilder;
public:
Machine(MachineSymbols symbols = MachineSymbols(), StatesUtil states = StatesUtil(), Tape tape = Tape()) : id(produced_machines++), symbols(symbols), states(states), tape(tape) {};
bool execute();
bool execute(string);
void save(ostream& os) const;
string executeAndGetTape();
string executeAndGetTape(string tape_load);
void print() const;
unsigned getId() { return id; }
Machine& after(const Machine& other) const;
Machine& compose(const Machine& other) const;
Machine& whileMachine(const Machine& condition) const;
private:
unsigned id;
Tape tape;
MachineSymbols symbols;
StatesUtil states;
};