public void ParseTree( TreeNodeCollection n , Expression ex ) { foreach (Expression e in ex.Members) { TreeNode t = n.Add(FormName(e)); ParseTree ( t.Nodes, e ); } }
public string FormName(Expression e) { if ((e as CompoundExpression) != null) return "Составное выражение " + e.calculate(); if ((e as BinaryOperation) != null) { if ((((BinaryOperation)e) as Addition) != null) return "Сложение " + e.calculate(); if ((((BinaryOperation)e) as Substract) != null) return "Вычитание " + e.calculate(); if ((((BinaryOperation)e) as Multiplication) != null) return "Умножение " + e.calculate(); if ((((BinaryOperation)e) as Division) != null) return "Деление " + e.calculate(); } if ((e as Number) != null) { return "Число " + ((Number)e).calculate(); } else return "Недопустимое значение!"; }
public Substract(Expression exp1,Expression exp2) : base(exp1, exp2) { }
public BinaryOperation(Expression exp1, Expression exp2) { _exp1 = exp1; _exp2 = exp2; }
public Multiplication(Expression exp1,Expression exp2) : base(exp1, exp2) { }
public Addition(Expression exp1,Expression exp2) : base(exp1, exp2) { }
public Division(Expression exp1,Expression exp2) : base(exp1, exp2) { }
public CompoundExpression(Expression exp) { _exp = exp; }