-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
25 lines (22 loc) · 865 Bytes
/
main.cpp
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
#include "CalcParser.hpp"
#include <string>
#include <iostream>
int main() {
auto parser = CalcParser::roman_calc();
std::string str;
while (std::getline(std::cin, str)) {
str = CalcParser::remove_all_spaces(str);
try {
auto result = parser.parse(str);
if (result && result.rest().empty()) {
std::cout << CalcParser::arabic_numeral_to_roman(result.value()).str();
} else if (result) {
std::cout << "error: Parsing failed. Part from position " << str.size() - result.rest().size() + 1 << " not parsed." << '\n';
} else {
std::cout << "error: Parsing failed. Message: " << result.get_message() << '\n';
}
} catch (const std::overflow_error&) {
std::cout << "error: Overflow int64 error.\n";
}
}
}