-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.cs
More file actions
72 lines (67 loc) · 1.96 KB
/
Code.cs
File metadata and controls
72 lines (67 loc) · 1.96 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Scheduling
{
class Code
{
protected List<string> m_lLines;
public int LineCount { get { return m_lLines.Count; } }
protected Dictionary<string, int> m_dLables;
public string this[int iLine]
{
get
{
return GetLine(iLine);
}
}
public Code()
{
m_lLines = new List<string>();
m_dLables = new Dictionary<string, int>();
}
public Code(string sCodeFile) : this()
{
StreamReader sr = new StreamReader(sCodeFile);
string sLine = "";
while (!sr.EndOfStream)
{
sLine = sr.ReadLine().Trim();
if (!sLine.Contains(' ') && sLine.EndsWith(":"))
{
sLine = sLine.Replace(":", "");
m_dLables.Add(sLine, m_lLines.Count);
}
else
m_lLines.Add(sLine);
}
sr.Close();
}
private string ReplaceLabels(string sLine)
{
string[] asTokens = sLine.Split(' ');
string s = "";
for (int i = 0; i < asTokens.Length; i++)
{
if (m_dLables.ContainsKey(asTokens[i]))
s += m_dLables[asTokens[i]];
else
s += asTokens[i];
s += " ";
}
return s.TrimEnd();
}
private string GetLine(int iLine)
{
string sLine = m_lLines[iLine];
if (sLine.StartsWith("goto"))
{
foreach (KeyValuePair<string, int> p in m_dLables)
sLine = ReplaceLabels(sLine);
}
return sLine;
}
}
}