-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter.hpp
51 lines (38 loc) · 1.21 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
/*! \file interpreter.hpp
The interpreter can parse from a stream into an internal AST and evaluate it.
It maintains an environment during evaluation.
*/
#ifndef INTERPRETER_HPP
#define INTERPRETER_HPP
// system includes
#include <istream>
#include <string>
// module includes
#include "environment.hpp"
#include "expression.hpp"
/*! \class Interpreter
\brief Class to parse and evaluate an expression (program)
Interpreter has an Environment, which starts at a default.
The parse method builds an internal AST.
The eval method updates Environment and returns last result.
*/
class Interpreter {
public:
/*! Parse into an internal Expression from a stream
\param expression the raw text stream repreenting the candidate expression
\return true on successful parsing
*/
bool parseStream(std::istream &expression) noexcept;
/*! Evaluate the Expression by walking the tree, returning the result.
\return the Expression resulting from the evaluation in the current environment
\throws SemanticError when a semantic error is encountered
*/
Expression evaluate();
void setInterrupSig(MessageQueueStr * signal);
private:
// the environment
Environment env;
// the AST
Expression ast;
};
#endif