public void SymbolPreDefinitionTest() { var parser = new HackParser(); var hack = parser.Parse(new[] { "0", "(SYM)", "@SYM" }); Assert.Equal(hack.Last(), "0000000000000001"); }
public void ASymbolCommandParseTest() { var parser = new HackParser(); var hack = parser.Parse(new[] { "@SYM" }); Assert.Equal(hack, new [] { "0000000000010000" }); }
public void SymbolPostDefinitionTest() { var parser = new HackParser(); var hack = parser.Parse(new[] { "@SYM", "0", "(SYM)" }); Assert.Equal(hack.First(), "0000000000000010"); }
public void CCommandParseTest(string source, string result) { var parser = new HackParser(); var hack = parser.Parse(new[] { source }); Assert.Equal(hack, new [] { result }); }
public static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Source path is not defined. Usage: HackAssembler.exe <source_path>"); return(1); } var sourcePath = args[0]; var parser = new HackParser(); try { IEnumerable <string> lines; using (var source = new StreamReader(sourcePath)) { if (!sourcePath.ToLower().EndsWith(".asm")) { Console.WriteLine("File is not .asm file"); } lines = parser.Parse(source.ReadToEnd().Split(new[] { "\n", "\r\n" }, StringSplitOptions.None)) .ToArray(); } var outPath = sourcePath.Replace(".asm", ".hack"); using (var output = new StreamWriter(outPath)) { output.Write(string.Join("\n", lines)); } Console.WriteLine("Compilation successful"); Console.WriteLine($"Output location: {outPath}"); return(0); } catch (IOException e) { Console.WriteLine(e.Message); return(1); } catch (ParserException e) { Console.WriteLine($"{e.Message} at line {e.Line}"); return(1); } }