-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptCode.cpp
More file actions
43 lines (37 loc) · 881 Bytes
/
ScriptCode.cpp
File metadata and controls
43 lines (37 loc) · 881 Bytes
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
#include "ScriptCode.h"
#include "Script.h"
#include <iostream>
ScriptCode::ScriptCode(std::istringstream & ss)
{
std::vector<std::shared_ptr<Statement>> tokens;
while (!ss.eof())
{
tokens.push_back(std::shared_ptr<Statement>(new Statement(0, Token(ss), 0)));
if (tokens.back()->token.lexeme.size() == 0)
tokens.pop_back();
}
while (tokens.size())
{
statements.push_back(Statement(tokens));
}
}
ScriptCode::ScriptCode(std::vector<std::shared_ptr<Statement>> tokens)
{
while (tokens.size())
{
statements.push_back(Statement(tokens));
//std::cout << statements.back().output("") << std::endl;
}
}
ScriptCode::~ScriptCode(void)
{
}
std::shared_ptr<Variable> ScriptCode::run(std::shared_ptr<ScriptMemory> mem)
{
for (auto i = statements.begin();i!=statements.end();++i) {
i->run(mem);
if (mem->return_var!=0)
return mem->return_var;
}
return 0;
}