static void TestGenerator(Node root, int debugLevel) { if (root != null) { Generator.Generator gen = new Generator.Generator(); string asm = gen.Generate(root); if (debugLevel > 0) { Console.Write(asm); } } }
static void Compile(string inputPath, string outputPath, bool debug) { //Lexing Lexer.Lexer lexer = new Lexer.Lexer(); StreamReader file = new StreamReader(inputPath); string contents = file.ReadToEnd(); List <Token> tokens = lexer.Lex(contents); if (debug) { Console.WriteLine($"Lexed {inputPath.Split("/").Last()}."); } //Parsing Parser.Parser p = new Parser.Parser(tokens); try { Node programNode = p.Parse(NodeType.ProgramNode); if (debug) { Console.WriteLine($"Parsed \"{inputPath.Split("/").Last()}\""); } //Generating Generator.Generator generator = new Generator.Generator(); string program = generator.Generate(programNode); File.WriteAllText(outputPath, program); } catch (Exception e) { Console.WriteLine($"Error in file \"{inputPath.Split("/").Last()}\""); Console.WriteLine(e.Message); } }