-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathInterpreter.h
60 lines (47 loc) · 2.31 KB
/
Interpreter.h
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
/*
* File: Interpreter.h
* Author: Dreamszhu
*
* Created on September 17, 2014, 10:18 AM
*/
#ifndef INTERPRETER_H
#define INTERPRETER_H
#include <string>
#include <stack>
#include <boost/any.hpp>
#include <boost/filesystem.hpp>
#include <boost/unordered_map.hpp>
#include "json/json.h"
#include "Compiler.h"
#include "interpreter/StatementResult.h"
#include "interpreter/ZephirValue.h"
#include "interpreter/LocalEnvironment.h"
using namespace boost::filesystem;
class Interpreter {
public:
Interpreter(const Compiler &compiler);
virtual ~Interpreter();
bool run(const std::string& filename);
private:
StatementResult executeStatements(const Json::Value& statements, LocalEnvironment* const env);
StatementResult executeStatement(const Json::Value& statement, LocalEnvironment* const env);
StatementResult executeDeclareStatement(const Json::Value& statement, LocalEnvironment* const env);
StatementResult executeLetStatement(const Json::Value& statement, LocalEnvironment* const env);
StatementResult executeAssignmentStatement(const Json::Value& statement, LocalEnvironment* const env);
StatementResult executeEchoStatement(const Json::Value& statement, LocalEnvironment* const env);
StatementResult executeIfStatement(const Json::Value& statement, LocalEnvironment* const env);
StatementResult executeWhileStatement(const Json::Value& statement, LocalEnvironment* const env);
StatementResult executeExpressionStatement(const Json::Value& statement, LocalEnvironment* const env);
StatementResult executeParametersStatements(const Json::Value& parameters, const Json::Value& parameters2, LocalEnvironment* const env);
void addVariable(const std::string& name, const ZephirValue& value, LocalEnvironment* const env);
ZephirValue getVariable(const std::string& name, LocalEnvironment* const env);
ZephirValue callMethod(const ZephirValue& value, const std::string& method, LocalEnvironment* const env);
ZephirValue callStringMethod(const ZephirValue& value, const std::string& method, LocalEnvironment* const env);
ZephirValue callFunction(const std::string& function_name, const Json::Value& parameters, LocalEnvironment* const env);
private:
Compiler compiler;
Json::Value statements;
boost::unordered_map<std::string, ZephirValue> global_variables;
std::stack<ZephirValue> eval_stack;
};
#endif /* INTERPRETER_H */