public void Visit(Ast.Stmt.Return r) { Visit(r.Item.Expr.Value); Ast.Stmt.Funcdef fd = (Ast.Stmt.Funcdef)r.Item.Decl.Value; Ast.Expr e = r.Item.Expr.Value; if (fd.Item.Formal.Type != e.ActualType) { m_errorList.Add("Type Error: Cannot return " + e.ActualType + " from function " + fd.Item.Formal.Name + " returning " + fd.Item.Formal.Type); } }
public object EvaluateExpr(Ast.Expr expr, ScriptEnv env) { using var dt = _notebook.Query($"SELECT ({expr.Sql})", env.Vars); if (dt.Columns.Count == 1 && dt.Rows.Count == 1) { return(dt.Rows[0][0]); } else { throw new ScriptException( $"Evaluation of expression \"{expr.Sql}\" did not produce a value."); } }
public T EvaluateExpr <T>(Ast.Expr expr, ScriptEnv env) { var value = EvaluateExpr(expr, env); if (typeof(T).IsAssignableFrom(value.GetType())) { return((T)value); } else { throw new ScriptException( $"Evaluation of expression \"{expr.Sql}\" produced a value of type " + $"\"{value.GetType().Name}\" instead of the expected \"{typeof(T).Name}\"."); } }
private void Visit(Ast.Expr e) { switch (e) { case Ast.Expr.VarRef v: Visit(v); break; case Ast.Expr.Int i: Visit(i); break; case Ast.Expr.Float f: Visit(f); break; case Ast.Expr.String s: Visit(s); break; case Ast.Expr.Bool b: Visit(b); break; case Ast.Expr.FuncCall f: Visit(f); break; case Ast.Expr.BinOp b: Visit(b); break; case Ast.Expr.UnOp u: Visit(u); break; } }