public SyntaxParserService(LexicalAnalyzerService lexAnalyzer, SymbolTable symbolTable) { this.LexicalAnalyzer = lexAnalyzer; this.SymbolTable = symbolTable; this.GlobalStrings = new Dictionary<string, string>(); MethodParamSize = new Dictionary<string, int>(); MethodLocalSize = new Dictionary<string, int>(); }
public void Compile(string fileName) { var parent = Directory.GetParent(fileName); var dir = Directory.CreateDirectory($"output_{parent.Name}"); var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName); var tacFilePath = $"{dir.FullName}/{fileNameWithoutExtension}.tac"; var asmFilePath = $"{dir.FullName}/{fileNameWithoutExtension}.asm"; try { FileIn = File.CreateText(tacFilePath); var streamReader = new StreamReader(fileName); var lexAnalyzer = new LexicalAnalyzerService(streamReader); var symbolTable = new SymbolTable { Printer = (val) => { Console.WriteLine(val); } }; var syntaxParser = new SyntaxParserService(lexAnalyzer, symbolTable); PrintSourceCode(File.ReadAllText(fileName)); syntaxParser.Parse(); FileIn.Close(); Intelx86GeneratorService.Generate( File.ReadAllLines(tacFilePath), syntaxParser.GlobalStrings, syntaxParser.MethodLocalSize, syntaxParser.MethodParamSize, (str) => { if (File.Exists(asmFilePath)) { File.Delete(asmFilePath); } File.AppendAllText(asmFilePath, str); Console.WriteLine(str); }); } catch (Exception ex) { // Delete out file if (File.Exists(tacFilePath)) { FileIn.Close(); File.Delete(tacFilePath); } Print("Oops, there seems to be something wrong.\n\n", ErrorColor); Print(ex.Message, ErrorColor); } }
private SyntaxParserService CreateSyntaxParserService(string fileName) { var fullPath = $@"{FILE_PATH}{fileName}"; var data = System.IO.File.ReadAllText(fullPath); System.Diagnostics.Debug.WriteLine(data + "\n\n\n\n\n\n\n"); var streamReader = LexicalAnalyzerServiceTests.CreateStreamReaderWith(data); var lexAnalyzer = new LexicalAnalyzerService(streamReader); var symbolTable = new SymbolTable(); symbolTable.Printer = (dump) => { }; return new SyntaxParserService(lexAnalyzer, symbolTable); }