-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
91 lines (84 loc) · 3.79 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VMAssembler
{
class Program
{
public static StreamReader inFile;
public static StreamWriter outFile;
public static int labelPtr = 0;
static void Main(string[] args)
{
Parser theParser;
String line;
Console.WriteLine("Enter the name of the file with VM code, or a directory name containing VM files ");
Console.WriteLine("The file name should be the complete path including the file type field (.vm} if it is a VM file.");
Console.WriteLine("Enter the name->");
line = Console.ReadLine();
if (line.Contains(".vm"))
{
// Get the filename without extension from the entry
String[] strVals = new string[] {"\\" };
String[] strSplit = line.Split(strVals, StringSplitOptions.RemoveEmptyEntries);
String fname = (strSplit[strSplit.Count() - 1]).Trim(); ;
fname = fname.Substring(0, fname.IndexOf(".") + 1);
theParser = new Parser(fname);
line = "E:\\Learning\\Coursera\\nand2tetris\\projects\\07\\MemoryAccess\\" + line;
inFile = new StreamReader(line);
int indx = line.LastIndexOf(".");
line = line.Substring(0, indx + 1) + "asm";
outFile = new StreamWriter(line);
theParser.ReadTheFile();
//sr.DiscardBufferedData();
//sr.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
//theProcessor.FinalPass(sr, theTable, sw);
//close the Streamreader and Streamwriter
inFile.Close();
outFile.Close();
}
else
{
Console.WriteLine("You have entered a directory name");
line = "E:\\Learning\\Coursera\\nand2tetris\\projects\\08\\FunctionCalls\\" + line;
String[] strVals = new string[] { "\\" };
String[] strSplit = line.Split(strVals, StringSplitOptions.RemoveEmptyEntries);
String fname = (strSplit[strSplit.Count() - 1]).Trim();
DirectoryInfo d = new DirectoryInfo(line);
FileInfo[] fI = d.GetFiles("*.vm");
Boolean outFileDone = false;
if (fI.Length > 0)
{
if (fI.Length > 1)
{
// outFile = new StreamWriter(line + ".asm");
outFileDone = true;
}
foreach (var file in fI)
{
Console.WriteLine("processing file " + file.Name);
if (!outFileDone)
{
strSplit = file.Name.Split(strVals, StringSplitOptions.RemoveEmptyEntries);
fname = (strSplit[strSplit.Count() - 1]).Trim();
fname = fname.Substring(0, fname.IndexOf("."));
String tmp = file.Name.Substring(0,file.Name.LastIndexOf(".") + 1);
// outFile = new StreamWriter(tmp = "asm");
outFileDone = true;
}
// theParser = new Parser(fname);
// inFile = new StreamReader(file.Name);
// theParser.ReadTheFile();
}
}
else
Console.WriteLine("There are no VM files in the directory!");
}
Console.WriteLine("Press any key to close this console.");
Console.ReadKey();
}
}
}