Exemple #1
0
        void Evaluate(string expression_str, Expression expr, string label)
        {
            EvalContext ctx = new EvalContext();

            ctx.SetVariable("x", "XXX");
            ctx.SetVariable("y", "YYY");
            ctx.SetVariable("true", "SSS");
            SafeEvalContext safe_ctx = new SafeEvalContext(ctx);
            Value           v        = expr.Evaluate(safe_ctx);

            Console.WriteLine("{0}: {1}", label, v.ToString());

            List <Variable> unresolved_variables = expr.CollectUnresolvedVariables(ctx);

            if (unresolved_variables.Count > 0)
            {
                Console.WriteLine("Unresolved variables in the expression: {0}", unresolved_variables.Count);
                Console.WriteLine(expression_str);
                foreach (Variable var in unresolved_variables)
                {
                    Console.WriteLine(new string(' ', var.Position) + "^");
                    Console.WriteLine(new string(' ', var.Position) + var.Name);
                }
            }
        }
        public List <Variable> CollectUnresolvedVariables(IEvalContext ctx)
        {
            Debug.Assert(!(ctx is SafeEvalContext));
            Private.UnresolvedVariableCollectorEvalContext uvc_ctx = new Private.UnresolvedVariableCollectorEvalContext(ctx);
            SafeEvalContext safe_ctx = new SafeEvalContext(uvc_ctx);

            RecursiveCollectUnresolvedVariables(safe_ctx);
            return(uvc_ctx.UnresolvedVariables);
        }