-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJExecutor.cpp
More file actions
33 lines (25 loc) · 831 Bytes
/
JExecutor.cpp
File metadata and controls
33 lines (25 loc) · 831 Bytes
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
#include "JExecutor.hpp"
namespace J {
JExecutor::JExecutor(JMachine::Ptr m): jmachine(m), tokenizer() {
shared_ptr<vector<string> > symbols = jmachine->list_symbols();
tokenizer = parser_type::Instantiate(symbols->begin(), symbols->end());
}
JExecutor::token_sequence JExecutor::parse_line(const string& line) const {
string trimmed(trim_string(line));
token_sequence res;
string::iterator iter(trimmed.begin());
try {
res = tokenizer->parse(&iter, trimmed.end());
} catch (J::JParser::ParserFailure& mf) {
throw JParserException();
}
if (iter != trimmed.end()) {
throw JParserException();
}
return res;
}
JWord::Ptr JExecutor::operator()(const string& line) {
token_sequence seq(parse_line(line));
return J::JEvaluator::big_eval_loop(jmachine, seq->rbegin(), seq->rend());
}
}