public static TreeNode VariableSet(EvaluatorBase evaluator, TreeNode [] args, bool update) { if (args.Length != 2) { throw new ArgumentException("must have two arguments"); } if (!(args[0] is FunctionNode)) { throw new ArgumentException("first argument must be a variable"); } FunctionNode variable_node = evaluator.ResolveFunction(args[0] as FunctionNode); if (variable_node != null) { variable_node.Body = evaluator.Evaluate(args[1]); } else { TreeNode parent = args[0].Parent; parent = parent.Parent ?? parent; parent.RegisterFunction((args[0] as FunctionNode).Function, evaluator.Evaluate(args[1])); } return(new VoidLiteral()); }
public virtual TreeNode OnDefine(TreeNode [] args) { if (args.Length < 2 || args.Length > 3) { throw new ArgumentException("define must have two or three arguments"); } if (!(args[0] is FunctionNode)) { throw new ArgumentException("first define argument must be a variable"); } FunctionNode function = new FunctionNode((args[0] as FunctionNode).Function, args[args.Length - 1]); if (args.Length == 3 && args[1].HasChildren) { foreach (TreeNode function_arg in args[1].Children) { if (!(function_arg is FunctionNode)) { throw new ArgumentException("define function arguments must be variable tokens"); } function.RegisterFunction((function_arg as FunctionNode).Function, new VoidLiteral()); } } TreeNode parent = args[0].Parent; parent = parent.Parent ?? parent; parent.RegisterFunction(function.Function, function); return(new VoidLiteral()); }
public void RegisterVariable(string name, string value) { expression.RegisterFunction(name, value); }