private static void PrintTree(string codePath, string outputPath) { var output = outputPath != null ? File.CreateText(outputPath) : Console.Out; var stream = new AntlrFileStream(codePath); var lexer = new AdamantLexer(stream); var tokens = new CommonTokenStream(lexer); var parser = new AdamantParser(tokens) { BuildParseTree = true }; var tree = parser.compilationUnit(); var syntaxCheck = new SyntaxCheckVisitor(); tree.Accept(syntaxCheck); output.WriteLine(tree.ToStringTree(parser)); }
private static MainFunctions Compile(string codePath, TextWriter output) { var stream = new AntlrFileStream(codePath); var lexer = new AdamantLexer(stream); var tokens = new CommonTokenStream(lexer); var parser = new AdamantParser(tokens) { BuildParseTree = true }; var tree = parser.compilationUnit(); var syntaxCheck = new SyntaxCheckVisitor(); tree.Accept(syntaxCheck); //var buildAst = new BuildAstVisitor(); //var ast = (Assemblage)tree.Accept(buildAst); //var borrowChecker = new BorrowChecker(); //borrowChecker.Check(ast); var cSharpGenerator = new CSharpGenerator(output); return tree.Accept(cSharpGenerator); }
private static void Tokenize(string codePath, string outputPath) { var output = outputPath != null ? File.CreateText(outputPath) : Console.Out; var stream = new AntlrFileStream(codePath); var lexer = new AdamantLexer(stream); var tokens = new CommonTokenStream(lexer); tokens.Fill(); foreach(var token in tokens.GetTokens()) output.WriteLine(Format(token)); }