public IParseTreeValue Evaluate(IParseTreeValue LHS, IParseTreeValue RHS, string opSymbol) { if (!(IsSupportedSymbol(opSymbol))) { throw new ArgumentException($"Unsupported operation ({opSymbol}) passed to Evaluate function"); } if (opSymbol.Equals(LogicalOperators.NOT)) { throw new ArgumentException($"Unary operator ({opSymbol}) passed to binary Evaluate function"); } var opProvider = new OperatorTypesProvider((LHS.ValueType, RHS.ValueType), opSymbol); if (opProvider.IsMismatch) { return(_valueFactory.CreateMismatchExpression($"{LHS.Token} {opSymbol} {RHS.Token}", Tokens.Variant)); } if (ArithmeticOperators.Includes(opSymbol)) { return(EvaluateArithmeticOp(opSymbol, LHS, RHS)); } if (RelationalOperators.Includes(opSymbol)) { return(EvaluateRelationalOp(opSymbol, LHS, RHS)); } return(EvaluateLogicalOperator(opSymbol, LHS, RHS)); }
private bool IsSupportedSymbol(string opSymbol) { return(ArithmeticOperators.Includes(opSymbol) || RelationalOperators.Includes(opSymbol) || LogicalOperators.Incudes(opSymbol)); }