/// <summary> /// Takes an expression or value and evaluates it. /// </summary> /// <param name="expr">The expression or value to evaluate.</param> /// <returns>The value represented by the expression or value.</returns> /// <exception cref="Exception">Throws when a variable is undefined or the expression is unhandled.</exception> public virtual IValue Run(IValueExpressible expr) { switch (expr) { case ScalarVar s: return(Scope[s] ?? throw new Exception($"Scalar {s.Value} not found")); case ListVar l: return(Scope[l] ?? throw new Exception($"List {l.Value} not found")); case ValueExpression e: return(Builtins[""].Invoke(this, e)); case IValue i: return(i); default: throw new Exception($"Unexpected expression type {expr.GetType()}"); } }
public ValueExpression(IValueExpressible value) { Values = new[] { value }; IsValue = true; }