public PrologObject AdjustVariables(PrologObject po, ArrayList vars, int offset)
        {
            if (po is StructureObject)
            {
                po = ((StructureObject)po).Normalize();
            }

            if (po is StringObject && ((StringObject)po).IsVariableName())
            {
                int off;

                off = vars.IndexOf(po);

                if (off >= 0)
                {
                    return(GetVariable(off + offset));
                }

                vars.Add(po);

                po = GetVariable(offset + vars.Count - 1);
            }
            else if (po is StructureObject)
            {
                po = new StructureObject((StructureObject)po, this, vars, offset);
            }

            return(po);
        }
 private void Add(PrologMachine pm, PrologObject po)
 {
     if (po is StructureObject && ((StructureObject)(po)).Functor == this)
     {
         StructureObject ast = ((StructureObject)(po));
         Add(pm, ast.Parameters[1]);
         Add(pm, ast.Parameters[0]);
     }
     else
     {
         pm.PushPending(po);
     }
 }
Exemple #3
0
        private bool IsPredicate(PrologObject fact, StringObject atom)
        {
            if (fact.Equals(atom))
            {
                return(true);
            }

            if (!(fact is StructureObject))
            {
                return(false);
            }

            StructureObject st = ((StructureObject)(fact));

            if (st.Functor.Equals(atom))
            {
                return(true);
            }

            if (!(st.Functor == IfPrimitive.GetInstance()))
            {
                return(false);
            }

            fact = st.Parameters[0];

            if (fact.Equals(atom))
            {
                return(true);
            }

            if (!(fact is StructureObject))
            {
                return(false);
            }

            st = (StructureObject)fact;

            if (st.Functor.Equals(atom))
            {
                return(true);
            }

            return(false);
        }
        public StructureObject(StructureObject st, PrologMachine pm, ArrayList vars, int offset)
        {
            this.functor = pm.AdjustVariables(st.Functor, vars, offset);

            if (st.Arity == 0)
            {
                this.parameters = null;
            }
            else
            {
                this.parameters = new PrologObject[st.Arity];
            }

            for (int np = 0; np <= st.Arity - 1; np++)
            {
                this.parameters[np] = pm.AdjustVariables(st.Parameters[np], vars, offset);
            }
        }
        public override bool Equals(object obj)
        {
            PrologObject objMe;

            objMe = Normalize();

            if (!(objMe == this))
            {
                return(objMe.Equals(obj));
            }

            if (obj is StructureObject)
            {
                obj = ((StructureObject)(obj)).Normalize();
            }

            if (obj == null || !(obj.GetType().Equals(this.GetType())))
            {
                return(false);
            }

            StructureObject st = ((StructureObject)(obj));

            if (!(Functor.Equals(st.Functor)))
            {
                return(false);
            }

            if (!(Arity == st.Arity))
            {
                return(false);
            }

            for (int k = 0; k <= Arity - 1; k++)
            {
                if (!(Parameters[k].Equals(st.Parameters[k])))
                {
                    return(false);
                }
            }

            return(true);
        }
 public bool Unify(PrologObject po1, PrologObject po2)
 {
     po1 = po1.Dereference();
     po2 = po2.Dereference();
     if (po1.Equals(po2))
     {
         return(true);
     }
     if (po1 is Variable)
     {
         ((Variable)(po1)).Bind(po2);
         return(true);
     }
     if (po2 is Variable)
     {
         ((Variable)(po2)).Bind(po1);
         return(true);
     }
     if (po1 is StructureObject && po2 is StructureObject)
     {
         StructureObject st1 = ((StructureObject)(po1));
         StructureObject st2 = ((StructureObject)(po2));
         if (!(Unify(st1.Functor, st2.Functor)))
         {
             return(false);
         }
         if (!(st1.Arity == st2.Arity))
         {
             return(false);
         }
         for (int k = 0; k <= st1.Arity - 1; k++)
         {
             if (!(Unify(st1.Parameters[k], st2.Parameters[k])))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Exemple #7
0
 public AndNode(PrologMachine pm, StructureObject st)
     : base(pm, st)
 {
 }
Exemple #8
0
 public PrimitiveNode(PrologMachine pm, StructureObject st)
     : base(pm, st)
 {
     primitive  = ((Primitive)(st.Functor));
     parameters = st.Parameters;
 }
 public PrimitiveStatusNode(PrologMachine pm, StructureObject st)
     : base(pm, st)
 {
 }
Exemple #10
0
 public virtual PrologObject Evaluate(PrologMachine pm, StructureObject st)
 {
     return(st);
 }