-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
39 lines (32 loc) · 1.2 KB
/
Program.cs
File metadata and controls
39 lines (32 loc) · 1.2 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
using System;
namespace ExpressionParser
{
public class Program
{
private static Dictionary<string, Type> variablesTypes = new Dictionary<string, Type>();
private static Dictionary<string, object> variables = new Dictionary<string, object>();
public static void Main(string[] args)
{
variablesTypes.Add("var1", typeof (int));
variablesTypes.Add("var2", typeof (int));
variablesTypes.Add("var3", typeof(string));
variables = new Dictionary<string, object>();
variables.Add("var1", 5);
variables.Add("var2", 4);
variables.Add("var3", "Eeeemily");
RunTest("CONCAT('HELLO ', 'WORLD ', {var3}, ' ',{var1})");
RunTest("1 + 2 * 3");
RunTest("(1 + 2) * 3");
RunTest("-(1 + 2) * 3");
RunTest("-(1 + 2) * -3");
}
private static void RunTest(string expression)
{
Console.WriteLine($"Test: '{expression}'");
var expressionParser = new ExpressionParser(variablesTypes);
var x = expressionParser.Evaluate(expression, variables);
Console.WriteLine($"{x.GetType().ToString()} : {x.ToString()}");
Console.WriteLine();
}
}
}