private static CompileResult ParseFile(SourceProjectFile sourceFile, out AST ast) { // If not virtual, make sure the file exists if (!sourceFile.IsVirtual) { if (!File.Exists(sourceFile.Value)) { ast = null; return(new CompileResult(false, $"Source file \"{sourceFile.Value}\" not found.")); } } // Lex program Lexer lexer = new Lexer(); LexToken[] tokens = sourceFile.IsVirtual ? lexer.Lex(sourceFile.Value) : lexer.LexFile(sourceFile.Value); // Build AST and return it ASTBuilder builder = new ASTBuilder(tokens); ParsingResult result = builder.Parse(); if (result.Success) { ast = builder.Build(); ast.SetSource(sourceFile); return(new CompileResult(true)); } else { ast = null; return(new CompileResult(false)); } }
private AST BuildAST(string rawCode) { this.builder = new ASTBuilder(this.lexer.Lex(rawCode)); Assert.That(builder.Parse().Success is true); return(this.builder.Build()); }