abouttreesummaryrefslogcommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..a7742ac
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,50 @@
+#include <iostream>
+#include <fstream>
+
+#include "TocLexer.h"
+#include "TocParser.h"
+
+#include "toc.h"
+#include "repr.h"
+#include "repr_get.h"
+
+using namespace antlr4;
+
+
+int main(int argc, const char * argv[]) {
+ std::ifstream ifs("test.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;
+
+ //toc(std::cout, prog);
+
+ //std::ofstream ofs("output.c");
+ //toc(ofs, prog);
+ //ofs.close();
+
+ Program prg = getProgram(prog);
+ std::cout << "Variables:\n";
+ for (auto v : prg.variables)
+ std::cout << " " << v.name << endl;
+ std::cout << "Functions:\n";
+ for (auto f : prg.functions)
+ std::cout << " " << f.name << endl;
+
+ return 0;
+} \ No newline at end of file