-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlol2cpp.cpp
More file actions
58 lines (47 loc) · 1.23 KB
/
lol2cpp.cpp
File metadata and controls
58 lines (47 loc) · 1.23 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
58
#include <iostream>
#include <fstream>
#include <string>
#include "tokenizer.h"
#include "parser.h"
#include "codegen.h"
void PrintHelp() {
std::cout << "Usage: lol2cpp <file>" << std::endl << std::endl;
std::cout << "After translation, compile generated C++ source using gcc "
<< "(or another C++ compiler) with: -std=c++11 -O2" << std::endl;
}
int main( int argc, char *argv[] ) {
if( argc == 1 ) {
PrintHelp();
return 0;
}
std::string srcPath( argv[1] );
if( srcPath == "--help" ) {
PrintHelp();
return 0;
}
Tokenizer tokenizer;
tokenizer.Tokenize( srcPath );
#if 0
tokenizer.GetTokens().StartIterating();
while( true ) {
Token token = tokenizer.GetTokens().PeekToken();
Token nextToken = tokenizer.GetTokens().PeekToken( 1 );
std::cout << token << " " << nextToken << std::endl;
if( token.type == TokenType::END_OF_FILE ) {
break;
}
tokenizer.GetTokens().AdvanceToNextToken();
}
#endif
Parser parser;
AST::Program *program = parser.Parse( &tokenizer.GetTokens() );
if( program == nullptr ) {
std::cout << "Error: syntax error" << std::endl;
return -1;
}
CodeGenerator codeGen;
codeGen.Visit( program );
std::ofstream cppOut( "a.cpp" );
cppOut << codeGen.GetEmittedCode();
return 0;
}