-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·57 lines (55 loc) · 1.64 KB
/
main.cpp
File metadata and controls
executable file
·57 lines (55 loc) · 1.64 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//#include <vld.h>
#include "parser.h"
#include "generator.h"
const std::string ext = "asm";
int main(int argc, char **argv)
{
if(argc < 2)
std::cout << "notFreePascal Compiler, Denis Sushko, 2011" << std::endl;
else
{
FILE *input = _fsopen(argv[2], "r", _SH_DENYWR);
std::string out_name = "";
out_name += argv[2];
for(size_t i = out_name.size() - 1, j = ext.size() - 1; i > out_name.size() - 4; --i, --j)
out_name[i] = ext[j];
std::ofstream output(out_name, std::ios::out);
if (input != nullptr)
{
Scanner lexemeScanner(input, output);
if(strcmp(argv[1], "-l") == 0)
{
output << argv[2];
while (!lexemeScanner.is_eof())
{
Token token(lexemeScanner.next());
token.print(output);
}
}
else if (strcmp(argv[1], "-p") == 0)
{
Parser par(lexemeScanner, output);
par.parse()->print(output);
par.print_table();
}
else if (strcmp(argv[1], "-g") == 0)
{
Parser par(lexemeScanner, output);
auto gen = std::make_shared<Generator>();
par.generate(gen);
gen->write_to_file(output, false);
}
else if (strcmp(argv[1], "-o") == 0)
{
Parser par(lexemeScanner, output);
auto gen = std::make_shared<Generator>();
par.generate(gen);
gen->write_to_file(output, true);
}
fclose(input);
output.close();
}
else
std::cout << "Error opening file" << std::endl;
}
}