-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
84 lines (66 loc) · 1.76 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <program_node.h>
#include <context.h>
#include <QCoreApplication>
void yyparse();
int qt_main( int argc, char** argv, ProgramNode** parse_tree, Context** context, FILE** yyin, int* yydebug )
{
QCoreApplication app( argc, argv );
//Setup some vars
auto print_tree = false;
(*yyin) = stdin;
*yydebug = 0;
if ( argc <= 1 )
{
qDebug("Usage: ./%s [-d] [-p] FILENAME.c--", argv[0]);
return -1;
}
//Setup the switches
for ( auto& arg : app.arguments() )
{
if ( arg == "-d")
*yydebug = 1;
else if ( arg == "-p" )
print_tree = true;
}
//Setup the input
*yyin = fopen(argv[argc - 1], "r");
//Setup some parse related items
*parse_tree = new ProgramNode();
*context = new Context();
//Fill out the context
//****
//Parse out my try
yyparse();
if ( *parse_tree == nullptr) //No parse errors
{
qDebug("No parse tree found");
return -1;
}
//Detect any and all errors
Error err;
(*context)->reset();
(*parse_tree)->detectErrors( &err, *context );
//Print out the parse tree
if (print_tree)
{
(*context)->reset();
(*parse_tree)->codePrint( *context );
}
//Dump out the number of errors and warnings
qDebug("Number of warnings: 0");
qDebug("Number of errors: %d\n", err.count() );
if ( err.count() != 0)
{
qDebug("Exiting due to errors");
return 1;
}
//Compile the program
QString result;
QTextStream stream( &result );
//Dump out the code
(*context)->reset();
(*parse_tree)->codeGen( &stream, *context );
//Temp, should write to file
qDebug("Program Dump:\n%s", result.toUtf8().data());
return 0;
}