diff options
| author | Patrick Schönberger | 2021-07-28 09:07:53 +0200 |
|---|---|---|
| committer | Patrick Schönberger | 2021-07-28 09:07:53 +0200 |
| commit | 45409c781a9e35df68c43b1e2f028d30bf90c0a0 (patch) | |
| tree | 0085614e19fdc136f664568e89f1686332ba8850 /src/main.cpp | |
| download | toc-45409c781a9e35df68c43b1e2f028d30bf90c0a0.tar.gz toc-45409c781a9e35df68c43b1e2f028d30bf90c0a0.zip | |
Initial commit
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 50 |
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 |
