/// Read expression from string, evaluate it and return the value public object Eval(string expression) { if (expression == null) { return(null); } if (_exprCache == null) { _exprCache = new PrecompiledCache(128); } IOperation ex = _exprCache[expression]; if (ex == null) { using (var sr = new ParsingReader(new StringReader(expression))) { ex = new Parser(TokenSpecialCharacters).Parse(sr); sr.SkipWhiteSpace(); sr.ReadAndThrowIfNot(-1); _exprCache[expression] = ex; } } if (ex == null) { return(null); } return(Eval(ex)); }
/// Read multi-expression (like ${a|b|=3+5}) from the string, evaluate it and return the value public object EvalMulti(string multiExpression) { if (multiExpression == null) { return(null); } if (_exprCache == null) { _exprCache = new PrecompiledCache(128); } IOperation o = _exprCache[multiExpression]; if (o == null) { using (var sr = new ParsingReader(new StringReader(multiExpression))) { o = new Parser(TokenSpecialCharacters).ParseMulti(sr); sr.SkipWhiteSpace(); sr.ReadAndThrowIfNot(-1); _exprCache[multiExpression] = o; } } return(Eval(o)); }