Example #1
0
        public override object GetValue(ExecutionContext ctx)
        {
            object lStart = _left.GetValue(ctx);
            object rStart = _right.GetValue(ctx);

            object lFinal;
            object rFinal;

            TypeChecker.GreatestCommonType gct = TypeChecker.GCT(lStart, rStart);
            switch (gct)
            {
                case TypeChecker.GreatestCommonType.StringType:
                    lFinal = Convert.ToString(lStart);
                    rFinal = Convert.ToString(rStart);
                    break;
                case TypeChecker.GreatestCommonType.BooleanType:
                    lFinal = Convert.ToBoolean(lStart);
                    rFinal = Convert.ToBoolean(rStart);
                    break;
                case TypeChecker.GreatestCommonType.NumericType:
                    lFinal = Convert.ToDecimal(lStart);
                    rFinal = Convert.ToDecimal(rStart);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            // execute on the converted values
            return _op.Evaluate(lFinal, rFinal);
        }
Example #2
0
        public object Exec(string input, ExecutionContext ctx)
        {
            var processor = new SemanticProcessor<GCToken>(new StringReader(input), actions);
            ParseMessage parseMessage = processor.ParseAll();

            if (parseMessage == ParseMessage.Accept)
            {
                var statement = processor.CurrentToken as Expression;
                if (statement != null)
                {
                    try
                    {
                        return statement.GetValue(ctx);
                    }
                    catch (FormulaSolverException ex)
                    {
                        return "??" + ex.Message;
                    }
                }
            }
            else
            {
                IToken token = processor.CurrentToken;
                return String.Format("??Syntax error at: {0} [{1}]", token.Position.Index, parseMessage);
            }

            return null;
        }
Example #3
0
 private void InsertMissingVariableLines(string input, ExecutionContext ctx)
 {
     StringBuilder sb = new StringBuilder();
     foreach (string name in ctx.GetMissingVariableNames())
     {
         sb.AppendLine(name + "=");
     }
     sb.Append(input);
     input = sb.ToString();
 }
Example #4
0
 public override object GetValue(ExecutionContext ctx)
 {
     string res = "";
     if (element != null)
     {
         res += Convert.ToString(element.GetValue(ctx));
     }
     if (concatenation != null)
     {
         res += Convert.ToString(concatenation.GetValue(ctx));
     }
     return res;
 }
Example #5
0
        public override object GetValue(ExecutionContext ctx)
        {
            string res = "";

            if (text != null)
            {
                res += text.GetValue(ctx);
            }
            if (expressionList != null)
            {
                foreach (Expression ex in expressionList)
                {
                    res += ex.GetValue(ctx);
                }
            }

            return res;
        }
Example #6
0
        public override object GetValue(ExecutionContext ctx)
        {
            string functionName = function.GetValue(ctx).ToString();
            Functor f = ctx.GetFunction(functionName);
            ArrayList arguments = new ArrayList();
            if (!emptyArgsList)
            {
                if (args.GetType() == typeof(Sequence<Expression>))
                {
                    Sequence<Expression> seq = (Sequence<Expression>)args;

                    foreach (Expression ex in (Sequence<Expression>)args)
                    {
                        arguments.Add(ex.GetValue(ctx));
                    }
                }
                else
                {
                    arguments.Add(((Expression)args).GetValue(ctx));
                }
            }
            return f.Execute(arguments.ToArray(), ctx);
        }
Example #7
0
 public override object GetValue(ExecutionContext ctx)
 {
     return _value;
 }
Example #8
0
 public override object GetValue(ExecutionContext ctx)
 {
     return ctx[_idName];
 }
Example #9
0
 public override object GetValue(ExecutionContext ctx)
 {
     ctx[_receiver._idName] = (_expr != null) ? _expr.GetValue(ctx) : "";
     return string.Format("{0}={1}", _receiver._idName, ctx[_receiver._idName]);
 }
Example #10
0
 public override object GetValue(ExecutionContext ctx)
 {
     return -(Convert.ToDecimal(computable.GetValue(ctx)));
 }
Example #11
0
 public abstract object GetValue(ExecutionContext ctx);
Example #12
0
 public override object GetValue(ExecutionContext ctx)
 {
     return functionName;
 }