-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunifuck.h
78 lines (64 loc) · 2.6 KB
/
unifuck.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
74
75
76
77
78
#ifndef _NOT_ANOTHER_CLUSTERFUCK
#define _NOT_ANOTHER_CLUSTERFUCK
#include <list>
#include <map>
#include <iostream>
#include <regex>
namespace unifuck{
enum instruction {NULL_INSTRUCTION, INCREMENT_POINTER, DECREMENT_POINTER,
INCREMENT_DATA, DECREMENT_DATA,
OUTPUT_DATA, INPUT_DATA,
JUMP_FORWARD, JUMP_BACKWARD
};
}
namespace _unifuck_internals {
typedef char cell_data; // The data type used by the program data cells
typedef std::list<cell_data> data_cells;
typedef std::list<unifuck::instruction> script;
typedef script::const_iterator code_point;
}
namespace unifuck{
class interpreter {
public:
// constructs an interpreter for a language spesified as a map from
// keywords to instructions. An istream and/or stream can also be
// spesified to be used for the language's io operations, using
// stdin and stdout by default
interpreter(std::map<std::string,instruction>, std::istream& = std::cin,
std::ostream& = std::cout);
// reads and runs source code given as either an string or input stream
void run(std::istream &);
void run(std::string);
// runs the interpreter as an interactive prompt
void live_run();
private:
std::istream &input_stream;
std::ostream &output_stream = std::cout;
std::map<std::string, instruction> keywords;
_unifuck_internals::data_cells program_data;
_unifuck_internals::data_cells::iterator data_pointer;
void reset_data();
inline void null_instruction();
inline void increment_pointer();
inline void decrement_pointer();
inline void increment_data();
inline void decrement_data();
inline void output_data();
inline void input_data();
inline void jump_forward(_unifuck_internals::code_point&,
const _unifuck_internals::code_point&) const;
inline void jump_backward(_unifuck_internals::code_point&,
const _unifuck_internals::code_point&) const;
_unifuck_internals::script read_code(const std::string &) const;
inline instruction get_current_instruction(
const _unifuck_internals::code_point&) const;
inline instruction get_next_instruction(
_unifuck_internals::code_point &,
const _unifuck_internals::code_point&) const;
inline instruction get_previous_instruction(
_unifuck_internals::code_point&,
const _unifuck_internals::code_point&) const;
const std::regex keyword_regex;
};
}
#endif