-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (43 loc) · 1.04 KB
/
Program.cs
File metadata and controls
49 lines (43 loc) · 1.04 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
int[] registers = new int[2];
//
// for (int i = 0; i < 10; i++)
// {
// Console.WriteLine("#StopRussianAgression");
// i++;
// }
var declarations = new ICommand[]
{
new PutConstantToRegisterCommand(0, 0),
new WriteCommand("i", 0),
};
var condition = new ICommand[]
{
new PutConstantToRegisterCommand(1, 10),
new ReadCommand("i", 0),
new LtCommand(0)
};
var body = new ICommand[]
{
new OutputCommand("#StopRussianAgression")
};
var commands = new ForCommand(
preCondition: declarations,
condition: condition,
postCondition: new IncrementCommand("i").Compile().ToArray(),
body: body)
.Compile()
.ToArray();
for (int i = 0; i < commands.Length;)
{
Console.Write($"[{i.ToString().PadLeft(3, '0')}]");
var currentCommand = commands[i];
currentCommand.Dump();
Console.CursorLeft = 60;
currentCommand.Execute(registers, ref i);
Console.CursorLeft = 20;
registers.Dump();
Console.CursorLeft = 30;
Memory.Dump();
Console.WriteLine();
}
Console.ReadLine();