public static ExprVarValue Parse(string s) { ExprVarValue res; int i = 0; Buttons ButtonType; string button; button = ButtonFunctions.ParseNextButton(s, ref i, out ButtonType); if (ButtonType != Buttons.Letter) { throw new Exception(); } res.Name = button; button = ButtonFunctions.ParseNextButton(s, ref i, out ButtonType); if (button != "=") { throw new Exception(); } res.Value = ExpressionTree.Build(s, ref i); return(res); }
static void Main(string[] args) { // sort out more complex examples string s = "2+2"; ExpressionTree e = ExpressionTree.Build(s); ExprVarValue[] vars = { new ExprVarValue("x", 2), new ExprVarValue("y", 3) }; Console.WriteLine(s); foreach (ExprVarValue var in vars) { Console.WriteLine(var); } Console.Write(e.ToString() + " = "); Console.WriteLine(e.getValue(vars)); Console.ReadKey(); }