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
81
82
83
84
85
86
|
#include "script.h"
bool validateExprNodeType(ExprNodeType type){
return type>=EFN_ADD&&type<=EFN_INVALID;
}
/*//returns parsed func and length of func
pair<ExprFunction,int> parseExprFunction(const string &s,int start=0){
switch(s[start]){
case '+':
return {EFN_ADD,1};
case '-':
return {EFN_SUBTRACT,1};
case '*':
return {EFN_MULTIPLY,1};
case '/':
return {EFN_DIVIDE,1};
case '%':
return {EFN_MODULO,1};
case '=':
if(s[start+1]=='=')return {EFN_EQUAL,2};
else return {EFN_INVALID,0};
case '!':
if(s[start+1]=='=')return {EFN_UNEQUAL,2};
else return {EFN_NOT,1};
case '<':
if(s[start+1]=='=')return {EFN_LESSEQUAL,2};
else return {EFN_LESS,1};
case '>':
if(s[start+1]=='=')return {EFN_GREATEREQUAL,2};
else return {EFN_GREATER,1};
case '&':
if(s[start+1]=='&')return {EFN_AND,2};
else return {EFN_INVALID,0};
case '|':
if(s[start+1]=='|')return {EFN_OR,2};
else return {EFN_INVALID,0};
default:
return {EFN_INVALID,0};
}
}*/
int Expression::evaluate(unordered_map<string,QueryResult> &vars){
;
}
ScriptLine::~ScriptLine(void){
if(querystub)delete querystub;
if(destvar)delete destvar;
if(expr)delete expr;
if(block)delete block;
}
vector<QueryResult> ScriptLine::execute(map<string,Table> &tables,unordered_map<string,QueryResult> &vars){
if(type==SLT_QUERYSTUB&&querystub){
Query *qu=resolveQueryStub(*querystub,tables,vars);
QueryResult res=qu->execute(tables);
delete qu;
if(destvar)vars[*destvar]=res;
return {res};
} else if(type==SLT_IF&&expr&&block){
if(expr->evaluate(vars))return block->execute(tables,vars);
} else if(type==SLT_WHILE&&expr&&block){
while(expr->evaluate(vars))return block->execute(tables,vars);
} else if(type==SLT_ASSIGNMENT&&destvar&&expr){
vars[*destvar]=QueryResult(expr->evaluate(vars));
return {};
}
return {};
}
vector<QueryResult> Script::execute(map<string,Table> &tables){
unordered_map<string,QueryResult> vars;
return execute(tables,vars);
}
vector<QueryResult> Script::execute(map<string,Table> &tables,unordered_map<string,QueryResult> &vars){
;
}
Query* resolveQueryStub(const string &stub,map<string,Table> &tables,unordered_map<string,QueryResult> &vars){
;
}
|