blob: bd9a2b2923f8e59f513ccf95370e95f22c7ced1b (
plain)
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
|
#include <iostream>
#include <fstream>
#include "TocLexer.h"
#include "TocParser.h"
#include "toc.h"
#include "repr.h"
#include "repr_get.h"
#include "generic.h"
//#include "check.h"
using namespace antlr4;
int main(int argc, const char * argv[])
{
std::ifstream ifs("test/test.toc");
// create ANTLR input from filestream
ANTLRInputStream input(ifs);
// lex input
TocLexer lexer(&input);
CommonTokenStream tokens(&lexer);
// parse
TocParser parser(&tokens);
// get Prog (root node)
TocParser::ProgContext * prog = parser.prog();
// dont continue on parse error
if (parser.getNumberOfSyntaxErrors() > 0)
{
std::cerr << "Parsing error" << std::endl;
return 1;
}
// print raw parse tree
//tree::ParseTree * tree = prog;
//std::string s = tree->toStringTree(&parser) + "\n";
//std::cout << "Parse Tree: " << s << std::endl;
// generate IR from tree and instantiate generics
Program prg = getProgram(prog, nullptr);
instantiateGenerics(prg);
// print to cout and file
try
{
tocProgram(std::cout, prg);
std::ofstream ofs("output.c");
tocProgram(ofs, prg);
ofs.close();
}
catch (const char * e)
{
std::cerr << "Error: " << e << std::endl;
}
return 0;
}
|