-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpreter.h
More file actions
39 lines (33 loc) · 1.22 KB
/
interpreter.h
File metadata and controls
39 lines (33 loc) · 1.22 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
#pragma once
#include <variant>
#include <string>
#include <map>
#include <vector>
#include <iostream>
#include <functional>
#include <memory>
#include "expression.h"
#include "utils.h"
// evaluation
const Expression eval(const Expression& exp, Environments& env);
std::optional<const Expression> applySpecialForm(const Symbol& formName, const List& args, Environments& env);
std::optional<const Expression> getPrimitiveFunction(const Symbol& s);
const Expression parseAndEvalFile(const char* fileName, Environments& env);
class Evaluator
{
Environments& env;
public:
Evaluator(Environments& _env) : env(_env) {}
const Expression operator()(const Null& n) { return n; }
const Expression operator()(const Symbol& s);
const Expression operator()(const String& s) { return s; }
const Expression operator()(const Integer& i) { return i; }
const Expression operator()(const Boolean& b) { return b; }
const Expression operator()(const Pair& p);
const Expression operator()(const Closure& f) { return f; }
};
// end evaluation
// helper
void insertArgsIntoEnvironment(const Pair& names, const Pair& args, Environment& env);
const Expression evalAllArgsInList(const Expression& exp, Environments& env);
// end helper