-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpreter.hpp
61 lines (43 loc) · 1.52 KB
/
interpreter.hpp
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
// File: interpreter.hpp
// Author: Samuel McFalls
#ifndef INTERPRETER_H
#define INTERPRETER_H
#include <fstream>
#include "expression.hpp"
#include "environment.hpp"
#include "tokenize.hpp"
#include "interpreter_semantic_error.hpp"
class Interpreter {
public:
// Default construct an Interpreter with the default environment and an empty AST
Interpreter();
// Given a vtscript program as a std::istream, attempt to parse into an internal AST
// return true on success, false on failure
bool parse(std::istream & expression) noexcept;
// Evaluate the current AST and return the resulting Expression
// throws InterpreterSemanticError if a semantic error is encountered
// the exception message string should document the nature of the semantic error
Expression eval();
// Saves the state of the environment so it can be restored later
void saveState();
// Restores the state of the environment to the last saved point
void restoreState();
// Gets the vector of items to be drawn from the last eval()
// Guaranteed to only contain graphical types
// @return The vector of items to be drawn
std::vector<Atom> toBeDrawn();
private:
Tokenizer tkn;
Expression AST;
Environment env;
Environment save;
Expression postEval(Expression exp);
Expression begin(Expression exp);
Expression define(Expression exp);
Expression ifSF(Expression exp);
Expression draw(Expression exp);
bool isProcType(EnvEntry proc);
Expression runProc(EnvEntry proc, std::vector<Atom> args);
Expression retValue(Expression exp);
};
#endif