Ejemplo n.º 1
0
        /// <summary>
        /// the list of parameters must correspond the the required set of Arguments
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public override object Eval(object[] parameters, ParseTreeEvaluator tree)
        {
            // create a new scope for the arguments
            var pars = Arguments.Clone();

            // now push a copy of the function arguments on the stack
            tree.Context.PushScope(pars);

            // assign the parameters to the current function scope variables
            var i    = 0;
            var keys = pars.Keys.ToArray();

            foreach (var key in keys)
            {
                pars[key] = parameters[i++];
            }

            // execute the function here

            var result = Node.Eval(tree, null);

            // clean up the stack
            tree.Context.PopScope();

            return(result);
        }
Ejemplo n.º 2
0
        public override object Eval(object[] parameters, ParseTreeEvaluator tree)
        {
            tree.Context.PushScope(null);
            var result = FunctionDelegate(parameters);

            tree.Context.PopScope();
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// required to override this function from base otherwise the parsetree will consist of incorrect types of nodes
        /// </summary>
        /// <param name="token"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public override ParseNode CreateNode(Token token, string text)
        {
            var node = new ParseTreeEvaluator();

            node.Token  = token;
            node.text   = text;
            node.Parent = this;
            return(node);
        }
Ejemplo n.º 4
0
        public Expression(string exp)
        {
            expression = exp;
            var scanner = new Scanner();
            var parser  = new Parser(scanner);

            tree = new ParseTreeEvaluator(Context.Default);
            tree = parser.Parse(expression, tree) as ParseTreeEvaluator;
        }
Ejemplo n.º 5
0
 public abstract object Eval(object[] parameters, ParseTreeEvaluator tree);
Ejemplo n.º 6
0
        public override object Eval(object[] parameters, ParseTreeEvaluator tree)
        {
//            CommandPrompt console = tree.Context.Console;
//            if (console != null) console.Text = "";
            return(null);
        }