Esempio n. 1
0
        public RSResult Apply(RSExpression lhs, RSExpression rhs, Func <dynamic, dynamic, dynamic> f)
        {
            var lhsValue = Evaluate(lhs).Value as dynamic;
            var rhsValue = Evaluate(rhs).Value as dynamic;

            return(RSResult.FromValue(f(lhsValue, rhsValue)));
        }
Esempio n. 2
0
        public RSResult Evaluate(RSToken statement)
        {
            RSResult result = null;

            switch (statement)
            {
            case RSBlock p:
                foreach (var s in p.Tokens)
                {
                    result = Evaluate(s);
                    if (result.Returnable)
                    {
                        return(result);
                    }
                }
                return(result);

            case RSConstant c: return(RSResult.FromValue(c.Value));

            case RSBinary b: return(Binary(b));

            case RSNumber n: return(RSResult.FromValue(n.Value));

            case RSString s: return(RSResult.FromValue(s.Value));

            case RSOutput o:
                result = Evaluate(o.Expression);
                Output(result.Value);
                return(result);
            }
            throw (new Exception($"I don't know how to evaluate {statement.GetType()} statements"));
        }