public static ASTNode AST(string inputPath) { var tokens = Lexer.Tokens(inputPath); var tree = Parser.Tree(tokens); if (tree is null) { Environment.Exit(1); } Context_to_AST astBuilder = new Context_to_AST(); ASTNode ast = astBuilder.Visit(tree); return(ast); }
static void Main(string[] args) { if (args.Length == 0) { return; } var input = new AntlrFileStream(args[0]); var lexer = new CoolLexer(input); var tokens = new CommonTokenStream(lexer); var parser = new CoolParser(tokens); var tree = parser.program(); Context_to_AST astbuilder = new Context_to_AST(); ProgNode program = astbuilder.VisitProgram(tree) as ProgNode; var scope = new Scope(); Console.WriteLine(CheckSemantic(program, scope)); Console.WriteLine("\n"); var code_visitor = new CodeGenVisitor(program, scope); var code = code_visitor.GetIntermediateCode(); foreach (var line in code) { Console.WriteLine(line); } MIPSCodeGenerator generator = new MIPSCodeGenerator(); var mips = generator.GenerateCode(code); Console.WriteLine(mips); File.WriteAllText("result.mips", mips); }