-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
51 lines (39 loc) · 940 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
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
#include <iostream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include "ast/AST.h"
#include "execengine/ExecEngine.h"
#ifdef _WIN32
extern "C"
{
#endif
extern int yyparse();
extern int yylex();
#ifdef _WIN32
}
#endif
extern FILE* yyin;
extern ast::AST* syntaxTree;
void showHelp(const char* name)
{
std::cout << "Usage: " << name << " filename.lec \"StartupClass\" \"startupMessage\"\n";
exit(1);
}
int main(int argc, char** args)
{
if (argc < 4)
showHelp(args[0]);
/* Parse */
if (yyin = fopen(args[1], "r")) {
yyparse();
fclose(yyin);
} else {
std::cerr << "Could not open the file: " << args[1] << std::endl;
showHelp(args[0]);
}
/* Execute the AST */
execengine::ExecEngine* ee = execengine::ExecEngine::execEngine();
ee->initializeEngine(syntaxTree);
return ee->execute(std::string(args[2]), std::string(args[3]));
}