-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.cpp
More file actions
40 lines (33 loc) · 825 Bytes
/
Function.cpp
File metadata and controls
40 lines (33 loc) · 825 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
/*
* Function.cpp
*
* Created on: 03.01.2014
* Author: atamas
*/
#include "Function.h"
#include "Commands.h"
Function::Function(std::vector <std::string> parNames, std::vector<command *> body, std::map<std::string, Function> * funcNamespace):
_parNames(parNames),
_body(body){
_funcNamespace = funcNamespace;
}
int Function::eval(std::vector<int> & parameters){
std::map<std::string, int> varNamespace;
int pos = 0;
for(unsigned int i = 0; i < parameters.size(); ++i){
varNamespace.insert( std::pair<std::string, int>(_parNames[i], parameters[i]) );
}
while(pos < (int)_body.size()){
command * c = _body[pos];
bool returnFlag;
int val;
val = c->execute(varNamespace, *_funcNamespace, pos, returnFlag);
if(returnFlag){
return val;
}
++pos;
}
return 0;
}
Function::~Function() {
}