-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_sam.cpp
More file actions
38 lines (37 loc) · 951 Bytes
/
error_sam.cpp
File metadata and controls
38 lines (37 loc) · 951 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
#include "evaluator.h"
bool Error::check(string math)
{
istringstream tokens(math);
char next;
char temp;
char temp2;
int char_num = 1;
tokens >> next;
// Checking the first char(s)
if (!(is_operand(convert_str(next))) && (!(next == '+' || next == '-') && !((char)tokens.peek() == next) || next != '!')){
//Invalid beginning char error
cout << "Expression starts with an invalid character" << endl;
system("pause");
exit(1);
}
else{
tokens.putback(next);
//Checking the rest of the expression
while (tokens >> next)
{
temp = (char)tokens.peek();
if ((next == '&' || next == '|' || next == '=') && (temp != next)){
cout << "This isn't a valid operator" << endl;
system("pause");
exit(1);
}
if (next == '/' && temp == '0'){ //Division by 0
cout << "Division by 0 error @ char " << char_num << endl;
system("pause");
exit(1);
}
char_num++;
}
}
return false;
}