-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (33 loc) · 1.13 KB
/
main.cpp
File metadata and controls
38 lines (33 loc) · 1.13 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
#include "Console/commandLine.h"
#include "Command/calcCommand.h"
#include "Parser/calcCommandParser.h"
#include "Computer/calcComputer.h"
#include <string>
int main() {
const std::string START_MESSAGE{ "Welcome, your calc is ready for use... (type 'quit' to quit)\n" };
const std::string HELP_MESSAGE{ "syntax: <operation> <list of space-separated numbers>\noperations: { add, sub, mult, div }\nexample: add 5 -1 2 3\n" };
CommandLine cli{};
CalcCommandParser parser{};
CalcComputer computer{};
bool quit{ false };
cli.write(START_MESSAGE);
cli.write(HELP_MESSAGE);
//TODO: add 'ans' functionality (in parser and computer)
//TODO: add feature for auto complete
while (!quit) {
std::string input{ cli.prompt() };
CalcCommand command{ parser.parse(input) };
try {
int ans{ computer.compute(command) };
cli.write(ans);
} catch(int ex) {
if (input == "quit") {
quit = true;
} else {
cli.write("Invalid command");
cli.write(HELP_MESSAGE);
}
}
}
return 0;
}