-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoo.cpp
More file actions
79 lines (73 loc) · 1.88 KB
/
foo.cpp
File metadata and controls
79 lines (73 loc) · 1.88 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
using namespace std;
#include "compiler.h"
void doWork(string& input) {
cout << input << ": " << endl;
AStruct& program = AKCompiler::compiler(input);
program.print();
program.deleteNode();
cout << endl << endl;
}
void loadfile(const string& filename) {
cout << filename << ": " << endl;
AStruct& program = AKCompiler::loadfile(filename);
program.print();
program.deleteNode();
cout << endl << endl;
}
void testInput() {
string input;
input = "if (+ x y) { * 890909 9 } { / 9 3 }";
doWork(input);
input = "(add 2 (subtract 4 2))";
doWork(input);
input = "+ 1 2";
doWork(input);
input = "/";
doWork(input);
input = "(- 100)";
doWork(input);
input = "(/ ())";
doWork(input);
input = "list 1 2 3 4";
doWork(input);
input = "{head (list 1 2 3 4)}";
doWork(input);
input = "eval {head (list 1 2 3 4)}";
doWork(input);
input = "tail {tail tail tail}";
doWork(input);
input = "eval (tail {tail tail {5 6 7}})";
doWork(input);
input = "eval (head {(+ 1 2) (+ 10 20)})";
doWork(input);
input = "def {x} 100";
doWork(input);
input = "x";
doWork(input);
input = "def {a b} 5 6";
doWork(input);
input = "def {arglist} {a b x y}";
doWork(input);
input = "def {add-mul} (\\ {x y} {+ x (* x y)})";
doWork(input);
input = "def {fun} (\\ {args body} {def (head args) (\\ (tail args) body)})";
doWork(input);
input = "fun {add-together x y} {+ x y}";
doWork(input);
input = "fun {unpack f xs} {eval (join (list f) xs)}";
doWork(input);
input = "fun {pack f & xs} {f xs}";
doWork(input);
input = "def {uncurry} pack";
doWork(input);
input = "print \"Hello World!\"";
doWork(input);
}
void testLoadfile() {
loadfile("test.lisp");
}
int main() {
testInput();
testLoadfile();
}