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