-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
88 lines (73 loc) · 1.62 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <regex>
#include <sstream>
#include "lexer.hpp"
#include "parser.hpp"
#include "runner.hpp"
void print_cell(const Cell& cell) {
std::cout << "Cell: " << cell.type << " - " << cell.val << '\n';
}
void print_cells(const Cell& cell) {
print_cell(cell);
for (const auto& c : cell.list) {
print_cells(c);
}
}
int main() {
const std::string s(R"(
(def (trollo lollo) '(fn (a b) (+ a b)))
(list 1 2 (list 3 "Hello this is nice"))
)");
const std::string code(R"(
(prog
(def x true)
(def i 0)
(def not (fn (x) (if x false true)))
(loop (not (= i 20)) (prog
(print! i)
(set! i (+ i 1))
(if (= i 15) (set! x false) ()))))
)");
const std::string code2(R"(
(prog
(def fib (fn (x) (prog
(if (= x 1) 1
(if (= x 2) 1
(+ (fib (- x 1)) (fib (- x 2))))))))
(print! (fib 25)))
)");
const std::string code3(R"(
(prog
(print! (let ((x 5)
(y (+ x 3))
(z "Nine"))
(prog
(print! (+ x y))
(print! z)
z)))
(print! 1))
)");
Tokenizer t(code3);
auto tokens = t.tokenize();
/*
for (const auto& token : tokens) {
std::cout << token.type << " " << token.data << ' ';
}
*/
auto iter = tokens.cbegin();
auto cell = parse(iter, tokens.cend());
// print_cells(cell);
Environment e(nullptr);
addGlobalVars(e);
auto c = eval(cell, &e);
//std::cout << c.val << '\n';
/*
for (const auto& token : tokens) {
std::cout << token.data << ' ';
}*/
return 0;
}