using System using System Collections Generic using System IO using Sy

 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FirstUtil
{
class Program
{
public static void Main(String[] args)
{
Lexer l = new Compiler().GetLexer(File.ReadAllText(args[0]));
l.Run();
}
}
class Compiler
{
SortedList<Position, Message> messages;
Dictionary<string, int> nameCodes;
List<string> names;
public Compiler() {
messages = new SortedList<Position, Message>();
nameCodes = new Dictionary<string, int>();
names = new List<string>();
}
public Lexer GetLexer(string program) {
return new Lexer(program, this);
}
public int AddName(string name) {
if (nameCodes.ContainsKey(name))
return nameCodes[name];
else
{
int code = names.Count;
names.Add(name);
nameCodes[name] = code;
return code;
}
}
public string GetName(int code) {
return names[code];
}
public void AddMessage(Position pos, Message msg) {
messages[pos] = msg;
}
}
}