forked from kanaka/mal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step1_read_print.cpp
66 lines (54 loc) · 1.17 KB
/
step1_read_print.cpp
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
#include "MAL.h"
#include "ReadLine.h"
#include "Types.h"
#include <iostream>
#include <memory>
malValuePtr READ(const String& input);
String PRINT(malValuePtr ast);
static ReadLine s_readLine("~/.mal-history");
static String rep(const String& input);
static malValuePtr EVAL(malValuePtr ast);
int main(int argc, char* argv[])
{
String prompt = "user> ";
String input;
while (s_readLine.get(prompt, input)) {
String out;
try {
out = rep(input);
}
catch (malEmptyInputException&) {
continue; // no output
}
catch (String& s) {
out = s;
};
std::cout << out << "\n";
}
return 0;
}
static String rep(const String& input)
{
return PRINT(EVAL(READ(input)));
}
malValuePtr READ(const String& input)
{
return readStr(input);
}
static malValuePtr EVAL(malValuePtr ast)
{
return ast;
}
String PRINT(malValuePtr ast)
{
return ast->print(true);
}
// These have been added after step 1 to keep the linker happy.
malValuePtr EVAL(malValuePtr ast, malEnvPtr)
{
return ast;
}
malValuePtr APPLY(malValuePtr ast, malValueIter, malValueIter)
{
return ast;
}