-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
46 lines (40 loc) · 1.43 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
#include "Parser.h" // C_Parser
#include "ParserIdDef.h" // TID_LEX_Spaces
#include "Scanner.h" // C_Scanner
//-------------------------------------------------------------
#include "bux/MemIn.h" // bux::C_IMemStream<>
#include <iostream> // std::cin, std::cerr
#include <sstream> // std::ostringstream
int main()
{
std::string line;
while (std::getline(std::cin, line))
{
if (line.empty())
// Bye!
break;
std::ostringstream err_out;
C_Parser parser{err_out};
bux::C_ScreenerNo<TID_LEX_Spaces> screener{parser};
C_Scanner scanner{screener};
bux::C_IMemStream in{line};
bux::scanFile(">", in, scanner);
// Check if parsing is ok
if (const auto err_str = err_out.str(); !err_str.empty())
{
std::cerr <<err_str <<"Fail to parse!\n";
continue;
}
// Acceptance
if (!parser.accepted())
{
std::cerr <<"Incomplete expression!\n";
continue;
}
// Output the result
auto ans = bux::unlex<int>(parser.getFinalLex());
std::cerr <<"= " <<ans <<" = 0x" <<std::hex <<ans <<" = 0" <<std::oct <<ans <<std::dec <<'\n';
}
// Ok
std::cerr <<"Mission complete!\n";
}