-
Notifications
You must be signed in to change notification settings - Fork 3
/
bf_interpreter.h
41 lines (33 loc) · 1 KB
/
bf_interpreter.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
// Copyright 2014 Brian Quinlan
// See "LICENSE" file for details.
//
// Implements a BrainfuckRunner that interprets the Brainfuck source one command
// at a time.
#ifndef BF_INTERPRETER_H_
#define BF_INTERPRETER_H_
#include <map>
#include <string>
#include "bf_runner.h"
using std::map;
using std::string;
class BrainfuckInterpreter : public BrainfuckRunner {
public:
BrainfuckInterpreter();
virtual bool init(string::const_iterator start,
string::const_iterator end);
virtual void* run(BrainfuckReader reader,
void* reader_arg,
BrainfuckWriter writer,
void* writer_arg,
void* memory);
private:
string::const_iterator start_;
string::const_iterator end_;
// Maps the position of a Brainfuck block start to the token after the end of
// the block e.g.
// ,[..,]
// ^ ^
// x => y
map<string::const_iterator, string::const_iterator> loop_start_to_after_end_;
};
#endif // BF_INTERPRETER_H_