Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
 public override object GetValue(ExecutionContext ctx)
 {
     return functionName;
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 9
0
 public override object GetValue(ExecutionContext ctx)
 {
     return(_value);
 }
Ejemplo n.º 10
0
 public abstract object GetValue(ExecutionContext ctx);
Ejemplo n.º 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]);
 }
Ejemplo n.º 12
0
 public override object GetValue(ExecutionContext ctx)
 {
     return -(Convert.ToDecimal(computable.GetValue(ctx)));
 }
Ejemplo n.º 13
0
 public override object GetValue(ExecutionContext ctx)
 {
     return ctx[_idName];
 }
Ejemplo n.º 14
0
 public override object GetValue(ExecutionContext ctx)
 {
     return _value;
 }