-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
61 lines (58 loc) · 1.4 KB
/
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
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
#include "stdafx.h"
#include "analysis.h"
int main(int argc, const char* argv[])
{
/*if (argc != 2)
{
std::cout << "file name expected";
std::exit(EXIT_FAILURE);
}*/
setlocale(LC_ALL, "Russian");
Parser Interpretator("code.txt"/*argv[1]*/); //имя файла
try {
Interpretator.gc();
Interpretator.getNextLexeme();
Interpretator.PARSE_PROGRAM();
}
catch (const char* err) {
std::cout << "Error parsing: " << err
<< " in line #" << Interpretator.line_num << std::endl;
system("Pause");
return 1;
}
catch (const std::ifstream::failure&) {
//if there is no end-of-code indicatore before eof then smth gone wrong
if (Interpretator.currentChar != '.')
{
std::cout << "Unexpected end of file\n";
system("Pause");
return 1;
}
else
std::cout << "Expression parsed, calculating...\n";
}
catch (...) {
std::cout << "Undefined exception while parsing thrown.\n"
<< "Waiting for input to exit the program";
std::cin.get();
std::exit(EXIT_FAILURE);
}
//Вычисление
try {
Interpretator.calculate();
std::cout << "Calculated\n";
}
catch (const char* err) {
std::cout << "Error calculating: " << err << std::endl;
system("Pause");
return 1;
}
catch (...) {
std::cout << "Undefined exception while calculating thrown.\n"
<< "Waiting for input to exit the program";
std::cin.get();
std::exit(EXIT_FAILURE);
}
system("Pause");
return 0;
}