-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (46 loc) · 960 Bytes
/
main.cpp
File metadata and controls
49 lines (46 loc) · 960 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
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include "Tokenizer.h"
#include "Evaluator.h"
using namespace std;
int main() {
Tokenizer tokes;
Evaluator Albert;
while (true) {
Albert.reset();
tokes.reset();
tokes.prompt();
tokes.nextnoignore();
if (tokes.type() == END) break;
while (!tokes.end_of_stream() && tokes.type() != ERR && !Albert.problem()) {
tokes.next();
if (Albert.problem())
break;
switch (tokes.type()) {
case NUM: {
Albert.num(tokes.num_read());
break;
}
case OP: {
Albert.op(tokes.op_read());
break;
}
case ERR: {
cout << "Invalid input. Aborting." << endl;
break;
}
case END: {
double result = Albert.finish();
if (Albert.problem())
break;
cout << " Result: " << result << endl;
break;
}
}
if (Albert.problem())
break;
}
if (Albert.problem()) {
cout << "Invalid input. Aborting." << endl;
}
}
}