2026-03-04 10:54:23 +01:00

54 lines
1.1 KiB
C++

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include "antlr4-runtime.h"
#include "generated/ifccLexer.h"
#include "generated/ifccParser.h"
#include "generated/ifccBaseVisitor.h"
#include "CodeGenVisitor.h"
#include "DeclarationVisitor.h"
using namespace antlr4;
using namespace std;
int main(int argn, const char **argv) {
stringstream in;
if (argn == 2) {
ifstream lecture(argv[1]);
if (!lecture.good()) {
cerr << "error: cannot read file: " << argv[1] << endl;
exit(1);
}
in << lecture.rdbuf();
} else {
cerr << "usage: ifcc path/to/file.c" << endl;
exit(1);
}
ANTLRInputStream input(in.str());
ifccLexer lexer(&input);
CommonTokenStream tokens(&lexer);
tokens.fill();
ifccParser parser(&tokens);
tree::ParseTree *tree = parser.axiom();
if (parser.getNumberOfSyntaxErrors() != 0) {
cerr << "error: syntax error during parsing" << endl;
exit(1);
}
DeclarationVisitor dv;
dv.visit(tree);
CodeGenVisitor cgv = CodeGenVisitor(dv.getSymbolTable());
cgv.visit(tree);
return 0;
}