-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguageStack.cpp
More file actions
executable file
·52 lines (37 loc) · 1.39 KB
/
LanguageStack.cpp
File metadata and controls
executable file
·52 lines (37 loc) · 1.39 KB
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
#include "LanguageStack.hpp"
#include "RuntimeException.hpp"
void LanguageStack::deleteObject() {
}
Function* LanguageStack::getFunction(Variable* var) {
if(var->getType() == Types::LANGUAGEELEMENT) {
return new Function(*this, var);
} else {
throw RuntimeException("Language Element Expected");
}
}
Variable* LanguageStack::evaluateFunction(std::string& functionName, Variable* parameters) {
if(functionName.compare("push") == 0) {
if(parameters == nullptr || parameters->getType() == Types::COMMALIST) {
throw RuntimeException("Expected only one parameter");
}
if(stackType == Types::OTHER) {
stackType = parameters->getType();
} else if(stackType != parameters->getType()) {
throw RuntimeException("Type mismatch in stack");
}
variableStack.push(new Variable(parameters));
return new Variable(nullptr, Types::OTHER, -1);
} else if(functionName.compare("pop") == 0) {
if(parameters != nullptr) {
throw RuntimeException("Expected no parameters");
}
return variableStack.pop();
} else if(functionName.compare("isEmpty") == 0) {
if(parameters != nullptr) {
throw RuntimeException("Expected no parameters");
}
return new Variable(((void*)(new bool(variableStack.isEmpty()))), Types::BOOLEAN, -1);
} else {
throw RuntimeException(functionName + " is not a member function of stack");
}
}