-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJMachine.cpp
More file actions
64 lines (52 loc) · 2.25 KB
/
JMachine.cpp
File metadata and controls
64 lines (52 loc) · 2.25 KB
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
#include "JMachine.hpp"
#include "JArithmeticVerbs.hpp"
#include "JBasicAdverbs.hpp"
#include "JBasicConjunctions.hpp"
#include "ShapeVerbs.hpp"
namespace J {
JMachine::JMachine(): operators(), cur_locale(Locale::Instantiate()) {
typedef pair<string, JWord::Ptr> p;
operators.insert(p("+", JWord::Ptr(new PlusVerb())));
operators.insert(p("-", JWord::Ptr(new MinusVerb())));
operators.insert(p("i.", JWord::Ptr(new IDotVerb())));
operators.insert(p("/", JWord::Ptr(new JInsertTableAdverb())));
operators.insert(p("\"", JWord::Ptr(new RankConjunction())));
operators.insert(p("\\", JWord::Ptr(new PrefixInfixAdverb())));
operators.insert(p("$", JWord::Ptr(new ShapeVerb())));
operators.insert(p(",", JWord::Ptr(new RavelAppendVerb())));
operators.insert(p(";", JWord::Ptr(new RazeLinkVerb())));
operators.insert(p("*", JWord::Ptr(new SignumTimesVerb())));
operators.insert(p("%", JWord::Ptr(new ReciprocalDivideVerb())));
operators.insert(p("<", JWord::Ptr(new LessBoxVerb())));
operators.insert(p(">", JWord::Ptr(new MoreUnboxVerb())));
operators.insert(p("<.", JWord::Ptr(new FloorLesserofVerb())));
operators.insert(p(">.", JWord::Ptr(new CeilingGreaterofVerb())));
operators.insert(p("<:", JWord::Ptr(new DecrementLessequalVerb())));
operators.insert(p(">:", JWord::Ptr(new IncrementMoreequalVerb())));
}
JMachine::Ptr JMachine::new_machine() {
return shared_ptr<JMachine>(new JMachine());
}
optional<JWord::Ptr> JMachine::lookup_symbol(const string& sym) const {
map_iterator iter = operators.find(sym);
if (iter == operators.end()) {
return optional<JWord::Ptr>();
}
return optional<JWord::Ptr>(iter->second);
}
shared_ptr<vector<string> > JMachine::list_symbols() const {
shared_ptr<vector<string> > strs(new vector<string>(operators.size()));
transform(operators.begin(), operators.end(), strs->begin(),
attr_fun(&pair<string, JWord::Ptr>::first));
return strs;
}
optional<JWord::Ptr> JMachine::lookup_name(const string& name) const {
return cur_locale->lookup_symbol(name);
}
void JMachine::add_public_symbol(const string& name, JWord::Ptr word) {
cur_locale->add_public_symbol(name, word);
}
void JMachine::add_private_symbol(const string& name, JWord::Ptr word) {
cur_locale->add_private_symbol(name, word);
}
}