import ast.Program; import errorhandler.ErrorHandler; import introspector.model.IntrospectorModel; import introspector.view.IntrospectorTree; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import parser.CmmLexer; import parser.CmmParser; import visitor.codegeneration.*; import visitor.identification.IdentificationVisitor; import visitor.semantic.TypeCheckingVisitor; public class Main { public static void main(String... args) throws Exception { if (args.length < 1) { System.err.println("Please, pass me the input file."); return; } // create a lexer that feeds off of input CharStream CharStream input = CharStreams.fromFileName(args[0]); CmmLexer lexer = new CmmLexer(input); // create a parser that feeds off the tokens buffer CommonTokenStream tokens = new CommonTokenStream(lexer); CmmParser parser = new CmmParser(tokens); //parser.program(); Program ast = parser.program().ast; ast.accept(new IdentificationVisitor(), null); ast.accept(new TypeCheckingVisitor(), null); ast.accept(new OffsetVisitor(), null); CodeGenerator cg = new CodeGenerator(args[0], args[1]); ExecuteCGVisitor execute = new ExecuteCGVisitor(cg); ValueCGVisitor value = new ValueCGVisitor(cg); AddressCGVisitor address = new AddressCGVisitor(cg); execute.setExecuteCGVisitor(execute); execute.setValueCGVisitor(value); execute.setAddressCGVisitor(address); value.setExecuteCGVisitor(execute); value.setValueCGVisitor(value); value.setAddressCGVisitor(address); address.setExecuteCGVisitor(execute); address.setValueCGVisitor(value); address.setAddressCGVisitor(address); ast.accept(execute, null); if (ErrorHandler.getInstance().anyError()) ErrorHandler.getInstance().showErrors(System.err); else { IntrospectorModel model = new IntrospectorModel("Program", ast); new IntrospectorTree("Introspector", model); } } }