Ejemplo n.º 1
0
 public static object CreateInstance(this Type type, List<object> constructorArguments)
 {
     if (type == null) throw new ArgumentNullException("type");
     if (constructorArguments == null) throw new ArgumentNullException("constructorArguments");
     
     return type.CreateInstance(constructorArguments.ToArray());
 }
Ejemplo n.º 2
0
        private static AST.Program ConvertToAst(Runtime.ISolutionTreeNode unnamed_top_node)
        {
            var clause_nodes = ParsePossiblyEmptyList (unnamed_top_node ["run"] ["program"], "clause_list", "clause");

            var dcgClauses = new List <AST.DcgClause> ();
            var prologClauses = new List <AST.Clause> ();

            foreach (var clause_node in clause_nodes)
            {
                var dgc_clause_node = clause_node ["dcg_clause"];

                if (dgc_clause_node != null)
                {
                    var head = GoalToAst (dgc_clause_node ["dcg_head"] ["goal"]);

                    var dcgClause = new AST.DcgClause    
                                        {
                                            Head = new AST.Goal {
                                                                    PredicateName = head.PredicateName,
                                                                    Arguments = head.Arguments
                                                                },
                                            Body = ParsePossiblyEmptyList (dgc_clause_node ["dcg_body"], "dcg_goal_list", "dcg_goal").Select (DcgGoalToAst).ToArray ()
                                        };

                    dcgClauses.Add (dcgClause);
                }
                else
                {
                    var prolog_clause_node = clause_node ["prolog_clause"];

                    if (prolog_clause_node != null)
                    {
                        var prologClause = new AST.Clause 
                        {
                            Head = GoalToAst (prolog_clause_node ["head"] ["goal"]),
                            Body = ParsePossiblyEmptyList (prolog_clause_node ["body"], "goal_list", "goal").Select (GoalToAst).ToArray ()
                        };

                        prologClauses.Add (prologClause);
                    }
                    else
                    {
                        throw new Exception ("A 'clause' is expected to be either a 'dcg_clause' or a 'prolog_clause'.");
                    }
                }
            }

            return new AST.Program {
                Clauses = prologClauses.ToArray (),
                DcgClauses = dcgClauses.ToArray ()
            };
        }
Ejemplo n.º 3
0
        static KnowledgeBaseRule MakeRule(Structure head, List<Structure> body, bool checkSingletons, string source, int line)
        {
            if (body == null)
                return new KnowledgeBaseRule0(head, new Structure[0], checkSingletons, source, line);
            switch (body.Count)
            {
                case 0:
                    return new KnowledgeBaseRule0(head, body.ToArray(), checkSingletons, source, line);

                case 1:
                    return new KnowledgeBaseRule1(head, body.ToArray(), checkSingletons, source, line);

                case 2:
                    return new KnowledgeBaseRule2(head, body.ToArray(), checkSingletons, source, line);

                case 3:
                    return new KnowledgeBaseRule3(head, body.ToArray(), checkSingletons, source, line);

                case 4:
                    return new KnowledgeBaseRule4(head, body.ToArray(), checkSingletons, source, line);

                case 5:
                    return new KnowledgeBaseRule5(head, body.ToArray(), checkSingletons, source, line);

                case 6:
                    return new KnowledgeBaseRule6(head, body.ToArray(), checkSingletons, source, line);

                case 7:
                    return new KnowledgeBaseRule7(head, body.ToArray(), checkSingletons, source, line);

                case 8:
                    return new KnowledgeBaseRule8(head, body.ToArray(), checkSingletons, source, line);

                default:
                    throw new ArgumentException(string.Format("Rules with {0} clauses are not supported.", body.Count));
            }
        }
Ejemplo n.º 4
0
 private static IEnumerable<CutState> DeclareHigherOrderImplementation(object[] args, PrologContext context)
 {
     if (args.Length != 1)
         throw new ArgumentCountException("higher_order", args, "*predicate");
     var predicate = Term.Deref(args[0]) as Structure;
     if (predicate == null)
         throw new ArgumentTypeException("higher_order", "predicate", args[0], typeof(Structure));
     var higherOrderArguments = new List<int>();
     for (int argumentIndex=0; argumentIndex<predicate.Arity; argumentIndex++)
     {
         int indicator = Convert.ToInt32(predicate.Argument(argumentIndex));
         if (indicator > 0)
             higherOrderArguments.Add(argumentIndex);
     }
     context.KnowledgeBase.DeclareHigherOrderArguments(predicate.PredicateIndicator, higherOrderArguments.ToArray());
     yield return CutState.Continue;
 }
Ejemplo n.º 5
0
        public static object CreateGenericInstance(this Type genericType, Type[] genericTypeParameters, List<object> constructorArguments)
        {
            if (genericType == null) throw new ArgumentNullException("genericType");
            if (genericTypeParameters == null) throw new ArgumentNullException("genericTypeParameters");
            if (constructorArguments == null) throw new ArgumentNullException("constructorArguments");

            return genericType.CreateGenericInstance(genericTypeParameters, constructorArguments.ToArray());
        }
 public DisjunctiveSearchTerm (BaseTerm bindVar, bool isNegSearch, List<BaseTerm> alternatives)
 {
   this.bindVar = (Variable)bindVar;
   this.isNegSearch = isNegSearch;
   this.alternatives = alternatives.ToArray ();
 }