aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
blob: 230d0779e38329a22b5c874483d9efd9574b3de5 (plain) (blame)
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
#include "model.h"
#include "builtin.h"
#include "parser.h"
#include "eval.h"
#include "exc.h"
#include <cstdio>

#ifdef DEBUG
extern Cons *empty_list;
void tree_print(Cons *ptr) {
    if (!ptr || ptr == empty_list) return;
    ptr->_debug_print();
    tree_print(dynamic_cast<Cons*>(ptr->car));
    tree_print(TO_CONS(ptr->cdr));
}
#endif

int main() {
    //freopen("in", "r", stdin);
    Tokenizor *tk = new Tokenizor();
    ASTGenerator *ast = new ASTGenerator();
    Evaluator *eval = new Evaluator();

    while (1)
    {
        printf("Sonsi> ");
        try
        {
            Cons *tree = ast->absorb(tk);
            if (!tree) break;
            //tree_print(tree);
            printf("%s\n", eval->run_expr(tree)->ext_repr().c_str());
        }
        catch (GeneralError &e)
        {
            printf("An error occured: %s\n", e.get_msg().c_str());
        }
    }
}