-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet.cpp
More file actions
214 lines (193 loc) · 7.12 KB
/
Copy pathSet.cpp
File metadata and controls
214 lines (193 loc) · 7.12 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "Set.h"
Set::Set(){
}
void Set::doSet(vector<Var*>const&vec,int garbage){
}
int Set::doGet(vector<Var*>const&vec){
return -1;
}
Instruction* Set::clone(){
return nullptr;
}
void Set::checkOps(vector<Var*>const&vec){
string myAssign = "ASSIGN";
string myVar = "VAR";
string myLabel = "LABEL";
if((dynamic_cast<String*>(vec.at(0))) && ((vec.at(0)->getString().compare(myAssign))==0)){
int length = (int)vec.size();
if(length != 3){
ofstream outputFile;
outputFile.open(".err");
outputFile << "You have entered an invalid number of arguments for the instruction" << endl;
exit(EXIT_SUCCESS);
}
Var *tempAssign = vec.at(1);
Var *tempAssign2 = vec.at(2);
Var *var1 = getEntry(tempAssign->getString());
Var *var2;
bool checkvar2;
if(dynamic_cast<Int*>(tempAssign2) || dynamic_cast<Double*>(tempAssign2) || dynamic_cast<Char*>(tempAssign2)){
checkvar2 = false;
} else if(dynamic_cast<String*>(tempAssign2)){
char temp = tempAssign2->getString().at(0);
if(temp == '\"') {
checkvar2 = false;
} else {
checkvar2 = true;
var2 = getEntry(tempAssign2->getString());
}
}
bool throwError = false;
if(dynamic_cast<Int*>(var1)){
if(checkvar2 == true){
if(!dynamic_cast<Int*>(var2)){
throwError = true;
}
} else {
if(!dynamic_cast<Int*>(tempAssign2)){
throwError = true;
}
}
} else if(dynamic_cast<Double*>(var1)) {
if(checkvar2 == true){
if(!dynamic_cast<Double*>(var2)){
throwError = true;
}
} else {
if(!dynamic_cast<Double*>(tempAssign2)){
throwError = true;
}
}
} else if(dynamic_cast<String*>(var1)) {
if(checkvar2 == true){
if(!dynamic_cast<String*>(var2)){
throwError = true;
}
} else {
if(!dynamic_cast<String*>(tempAssign2)){
throwError = true;
}
}
} else if(dynamic_cast<Char*>(var1)) {
if(checkvar2 == true){
if(!dynamic_cast<Char*>(var2)){
throwError = true;
}
} else {
if(!dynamic_cast<Char*>(tempAssign2)){
throwError = true;
}
}
}
if(throwError == true){
ofstream outputFile;
outputFile.open(".err");
outputFile << "You have the wrong datatypes in Assign parameter" << endl;
exit(EXIT_SUCCESS);
}
}
else if((dynamic_cast<String*>(vec.at(0))) && ((vec.at(0)->getString().compare(myVar))==0)){
int length = (int)vec.size();
string a = "NUMERIC";
string b = "REAL";
string c = "CHAR";
string d = "STRING";
if ((vec.at(2)->getString()).compare(a) == 0) {
if(length != 4) {
ofstream outputFile;
outputFile.open(".err");
outputFile << "The length does not meet the requirement for NUMERIC type" << endl;
exit(EXIT_SUCCESS);
}
//it is known that it has to be a numeric value
if( dynamic_cast<Int*>(vec.at(3))) {
}
else { //if it does not match NUMERIC type with int type
ofstream outputFile;
outputFile.open(".err");
outputFile << "That is not a numeric value" << endl;
exit(EXIT_SUCCESS);
}
}
else if ((vec.at(2)->getString()).compare(b) == 0) {
if(length != 4) {
ofstream outputFile;
outputFile.open(".err");
outputFile << "The length does not meet the requirement for REAL type" << endl;
exit(EXIT_SUCCESS);
}
if(dynamic_cast<Double*>(vec.at(3))){
}
else {
ofstream outputFile;
outputFile.open(".err");
outputFile << "That is not a real value" << endl;
exit(EXIT_SUCCESS);
}
}
else if ((vec.at(2)->getString()).compare(c) == 0) {
if(length != 4) {
ofstream outputFile;
outputFile.open(".err");
outputFile << "The length does not meet the requirement for CHAR type" << endl;
exit(EXIT_SUCCESS);
}
if(dynamic_cast<Char*>(vec.at(3))) {
}
else {
ofstream outputFile;
outputFile.open(".err");
outputFile << "That is not a char value" << endl;
exit(EXIT_SUCCESS);
}
}
else if ((vec.at(2)->getString()).compare(d) == 0)
{
if(length != 5){ //checks
ofstream outputFile;
outputFile.open(".err");
outputFile << "The length does not meet the requirement for STRING type" << endl;
exit(EXIT_SUCCESS);
}
if(dynamic_cast<Int*>(vec.at(3))){
}else{
ofstream outputFile;
outputFile.open(".err");
outputFile << "This length is not an int in the allocation for string" << endl;
exit(EXIT_SUCCESS);
}
if(dynamic_cast<String*>(vec.at(4))){
}
else {
ofstream outputFile;
outputFile.open(".err");
outputFile << "that is not a char array value" << endl;
exit(EXIT_SUCCESS);
}
}
else {
ofstream outputFile;
outputFile.open(".err");
outputFile << "You have not entered a correct data type" << endl;
exit(EXIT_SUCCESS);
}
}
else if((dynamic_cast<String*>(vec.at(0))) && ((vec.at(0)->getString().compare(myLabel))==0)){
int length = (int)vec.size();
if(length != 2){
ofstream outputFile;
outputFile.open(".err");
outputFile << "You have entered an invalid number of arguments for the instruction." << endl;
exit(EXIT_SUCCESS);
}
}
else {
int length = (int)vec.size();
ofstream outputFile;
outputFile.open("err");
outputFile << "You have entered an invalid instruction name" << endl;
exit(EXIT_SUCCESS);
}
}
Set::~Set(){
}