-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interpreter.cs
45 lines (43 loc) · 1.8 KB
/
Interpreter.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDullCS
{
class Interpreter
{
public bool InterpretTree(AST tree)
{
bool isOk = true;
for (int i = 0; i < tree.roots.Count(); i++)
{
List<Root> roots = tree.roots;
if (i < roots.Count)
{
if (roots[i].name == "Add" && roots[i].nodes[0] != null && roots[i].nodes[1] != null)
{
Console.WriteLine(roots[i].nodes[1].value + roots[i].nodes[1].value);
}
if (roots[i].name == "Subtract" && roots[i].nodes[0] != null && roots[i].nodes[1] != null)
{
Console.WriteLine(roots[i].nodes[1].value - roots[i].nodes[1].value);
}
if (roots[i].name == "Multi" && roots[i].nodes[0] != null && roots[i].nodes[1] != null)
{
Console.WriteLine(roots[i].nodes[0].value * roots[i].nodes[1].value);
}
if (roots[i].name == "Divide" && roots[i].nodes[0] != null && roots[i].nodes[1] != null)
{
Console.WriteLine(roots[i].nodes[0].value / roots[i].nodes[1].value);
}
if (roots[i].name == "Assign" && roots[i].nodes[0] != null && roots[i].nodes[1] != null)
{
Console.WriteLine("CGHY");
Console.WriteLine("Assigned "+ roots[i].nodes[1].value+" to "+ roots[i].nodes[0].val);
}
}
} return isOk;
}
}
}