void Equal(object sender, EventArgs e) { if (Equation.Text == "") { Equation.Text = ""; } else { try { Equation.Text = Equation.Text.Replace(",", "."); List <Node> nodes = t.Tokenize(RealEquation(Equation.Text)); Node nf = p.Parse(nodes); nf.f = Flags.Derivate; Node nd = d.Derivate(nf); Result.Text = RealResult(OrganizeTree(nd, nd)); Result.Text = Result.Text.Replace(",", "."); ans = Result.Text; } catch { Result.Text = "Error"; } } }
static void Main(string[] args) { Tokenizer t = new Tokenizer(); Parser p = new Parser(); Solver s = new Solver(); Derivator d = new Derivator(); Simplifier simp = new Simplifier(); //ha he's a simp Console.Write("Solve equation (S/I/D):"); string decision = Console.ReadLine(); while (true) { Console.Write("Equation:"); List <Node> nodes = t.Tokenize(Console.ReadLine()); foreach (Node n in nodes) { Console.WriteLine(n.t + " " + n.op + " " + n.value + " " + n.var + " " + n.f + " " + n.priority_value + "\n"); } Console.WriteLine("\n"); Console.WriteLine("\n"); Console.WriteLine("\n"); Console.WriteLine("\n"); Node nf = p.Parse(nodes); PrintTree(nf, "", true); Console.WriteLine("\n"); Console.WriteLine("\n"); Console.WriteLine("\n"); Console.Write(OrganizeTree(nf, nf)); Console.WriteLine("\n"); Console.WriteLine("\n"); Console.WriteLine("\n"); if (decision == "S" || decision == "S") { Console.WriteLine(s.Solve(nf)); } else if (decision == "I" || decision == "i") { Node origin_simp = simp.Simplify(nf); PrintTree(origin_simp, "", true); Console.WriteLine(OrganizeTree(origin_simp, origin_simp)); } else if (decision == "D" || decision == "d") { nf.f = Flags.Derivate; Node derivated = d.Derivate(nf); PrintTree(derivated, "", true); Console.WriteLine(OrganizeTree(derivated, derivated)); } } }