コード例 #1
0
        private Argument ReadFunctionArgument(Expression exp, Dictionary <string, string> dParameterNameToType, Domain d)
        {
            string sName  = exp.ToString();
            double dValue = 0.0;

            if (double.TryParse(sName, out dValue))
            {
                Constant c = new Constant("Number", sName);
                return(c);
            }
            if (exp is CompoundExpression)
            {
                CompoundExpression ce = (CompoundExpression)exp;
                if (!d.Functions.Contains(ce.Type))
                {
                    throw new ArgumentException("Function arguments can only be numbers, parameters, or functions");
                }
                ParameterizedFunctionPredicate fp = new ParameterizedFunctionPredicate(ce.Type);
                foreach (Expression e in ce.SubExpressions)
                {
                    string sParam = e.ToString();
                    if (dParameterNameToType != null && dParameterNameToType.ContainsKey(sParam))
                    {
                        fp.AddParameter(new Parameter(dParameterNameToType[sParam], sParam));
                    }
                    else if (d.ConstantNameToType.ContainsKey(sParam))
                    {
                        fp.AddParameter(new Constant(d.ConstantNameToType[sParam], sParam));
                    }
                    else
                    {
                        throw new ArgumentException("Unknown function parameter");
                    }
                }
                FunctionParameter fa = new FunctionParameter(fp);
                return(fa);
            }
            if (dParameterNameToType.ContainsKey(sName))
            {
                return(new Parameter(dParameterNameToType[sName], sName));
            }
            throw new ArgumentException("Unknown function parameter");
        }
 public void AddFunction(FunctionParameter f)
 {
     AddParameter(f);
 }