abouttreesummaryrefslogcommitdiff
path: root/src/main.cpp
blob: 6792e832b692413aa6a6c916690d0707a19d9222 (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
#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/test2.toc");

  ANTLRInputStream input(ifs);

  TocLexer lexer(&input);
  CommonTokenStream tokens(&lexer);

  TocParser parser(&tokens);
  TocParser::ProgContext * prog = parser.prog();
  tree::ParseTree * tree = prog;

  if (parser.getNumberOfSyntaxErrors() > 0)
  {
    std::cerr << "Parsing error" << std::endl;
    return 1;
  }

  //std::string s = tree->toStringTree(&parser) + "\n";
  //std::cout << "Parse Tree: " << s << std::endl;

  Program prg = getProgram(prog, nullptr);
  instantiateGenerics(prg);

  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;
}