-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
executable file
·53 lines (48 loc) · 1.47 KB
/
Program.cs
File metadata and controls
executable file
·53 lines (48 loc) · 1.47 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
using System;
using System.Collections.Generic;
using System.IO;
using Interpreter.Lexer;
using Interpreter.Nodes;
namespace Interpreter
{
class Program
{
static ProgramNode Parse(string code)
{
var tokens = Tokenizer.GetTokens(code);
var parser = new Parser(tokens);
var programNode = parser.ParseProgram();
return programNode;
}
static ProgramNode CheckedParse(string code)
{
var programNode = Parse(code);
var code2 = programNode.FormattedString;
var programNode2 = Parse(code2);
var code3 = programNode2.FormattedString;
if (code2 != code3)
{
Console.WriteLine(code2);
Console.WriteLine(code3);
throw new Exception("Кривой парсер или ToString у узлов");
}
return programNode;
}
static void Run(ProgramNode node, Dictionary<string, object> variables)
{
new Interpreter(variables).RunProgram(node);
}
static void Main(string[] args)
{
string code = File.ReadAllText(@"..\..\code.txt");
var programCode = CheckedParse(code);
var variables = new Dictionary<string, object>
{
{ "x", 2 },
{ "y", 10 },
{ "z", 4 }
};
Run(programCode, variables);
}
}
}