public int ParseExpression() { int operatorPosition; operatorPosition = GetOperatorPosition(Expression); if (operatorPosition == -1) { Left = null; Right = null; return 0; } // 左側 Left = new Node(); Left.Expression = Expression.Substring(0, operatorPosition); Left.Expression = RemoveBracket(Left.Expression); if (Left.ParseExpression() < 0) return -1; // 右側 Right = new Node(); Right.Expression = Expression.Substring(operatorPosition + 1, Expression.Length - operatorPosition - 1); Right.Expression = RemoveBracket(Right.Expression); if (Right.ParseExpression() < 0) return -1; Expression = Expression[operatorPosition].ToString(); return 0; }
public static Expression Parse(string expression) { string expr = RemoveSpaces(expression); Node root = new Node(); root.Expression = expr; root.ParseExpression(); return new Expression(root); }
public Expression(Node root) { Root = root; }