示例#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);
        }
示例#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;
        }
示例#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();
 }
示例#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;
 }
示例#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;
        }
示例#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);
        }
示例#7
0
 public override object GetValue(ExecutionContext ctx)
 {
     return functionName;
 }
示例#8
0
        private void bnSolve_Click(object sender, EventArgs e)
        {
            StoreFormula();
            String formula = tbFormula.Text;
            tbSolutions.Text = "";

            if (formula.Length > 0)
            {
                string[] lines = formula.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                StringBuilder sb = new StringBuilder();
                ExecutionContext ctx = new ExecutionContext(Core);

                foreach (string line in lines)
                {
                    if (line.Length == 0)
                    {
                        sb.AppendLine("");
                    }
                    else
                    {
                        string res = Convert.ToString(interpreter.Exec(line, ctx), new System.Globalization.CultureInfo(""));
                        sb.AppendLine(res);
                    }
                }

                if (ctx.HasMissingVariables())
                {
                    string text = string.Format(StrRes.GetString(StrRes.STR_MISSING_VARIABLES), String.Join(", ", ctx.GetMissingVariableNames()));
                    if (MessageBox.Show(text, "Formula Solver", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        StringBuilder sbInput = new StringBuilder();
                        foreach (string name in ctx.GetMissingVariableNames())
                        {
                            sbInput.AppendLine(name + "=");
                            }
                        foreach (string line in lines)
                        {
                            sbInput.AppendLine(line);
                    }

                        tbFormula.Text = sbInput.ToString();
                }
                    sb.Clear();
                }
                tbSolutions.Text = sb.ToString();
            }
        }
示例#9
0
 public override object GetValue(ExecutionContext ctx)
 {
     return(_value);
 }
示例#10
0
 public abstract object GetValue(ExecutionContext ctx);
示例#11
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]);
 }
示例#12
0
文件: Negate.cs 项目: gahadzikwa/GAPP
 public override object GetValue(ExecutionContext ctx)
 {
     return -(Convert.ToDecimal(computable.GetValue(ctx)));
 }
示例#13
0
 public override object GetValue(ExecutionContext ctx)
 {
     return ctx[_idName];
 }
示例#14
0
 public override object GetValue(ExecutionContext ctx)
 {
     return _value;
 }