diff options
Diffstat (limited to 'script.cpp')
-rw-r--r-- | script.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/script.cpp b/script.cpp new file mode 100644 index 0000000..689066f --- /dev/null +++ b/script.cpp @@ -0,0 +1,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){ + ; +} |