-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.cpp
80 lines (74 loc) · 2.33 KB
/
Parser.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Command.h"
#include "Parser.h"
#include "OpenServerCommand.h"
#include "ConnectCommand.h"
#include "VarCommand.h"
#include "PrintCommand.h"
#include "LoopCommand.h"
#include "GlobalTables.h"
#include "ChangeCommand.h"
#include "ConditionParser.h"
#include "SleepCommand.h"
#include "PrintCommand.h"
#include "IfCommand.h"
#include "EnterCommand.h"
#include <string>
#include <map>
void Parser::strPrs(vector<string> cmdLines) {
vector<string> cmdTemp;
map<string,Command*> mapTmp;
mapTmp = this->mapCmd;
string temp;
Command *c;
GlobalTables* g = new GlobalTables();
for(int i = 0; i < (int)(cmdLines.size()); i++) {
string tmp((cmdLines.at(i)).c_str());
if(g->keyExists(tmp)) {
c = mapTmp["change"];
i += c->execute(cmdLines, i);
}
else if(cmdLines.at(i) != "\n" && cmdLines.at(i) != "}"){
c = mapTmp[cmdLines.at(i)];
i += c->execute(cmdLines, i);
}
}
delete g;
endSignal = true;
}
int Parser::strPrsTarget(vector<string> cmdLines, int start, string stop) {
vector<string> cmdTemp;
map<string, Command *> mapTmp;
mapTmp = this->mapCmd;
string temp;
Command *c;
int i = 0;
GlobalTables *g = new GlobalTables();
for (i = start + 1; cmdLines.at(i) != stop; i++) {
string tmp((cmdLines.at(i)).c_str());
if (g->keyExists(tmp)) {
c = mapTmp["change"];
i += c->execute(cmdLines, i);
} else if (cmdLines.at(i) != "\n") {
c = mapTmp[cmdLines.at(i)];
i += c->execute(cmdLines, i);
}
}
delete g;
return i - start;
}
Parser::Parser() {
this->mapCmd[string("openDataServer")] = new OpenServerCommand();
this->mapCmd[string("while")] = new LoopCommand("while");
this->mapCmd[string("connect")] = new ConnectCommand();
this->mapCmd[string("var")] = new VarCommand();
this->mapCmd[string("print")] = new PrintCommand();
this->mapCmd[string("change")] = new ChangeCommand();
this->mapCmd[string("sleep")] = new SleepCommand();
this->mapCmd[string("if")] = new IfCommand();
this->mapCmd[string("Enterc")] = new EnterCommand();
}
Parser::Parser(const Parser &) = default;
Parser::~Parser() {
for (map<string, Command*>::iterator it = mapCmd.begin(); it != mapCmd.end(); ++it)
delete it->second;
}