public bool Unify(Term t, VarStack varStack, bool occurCheck) { if (isUnified) return ULink.Unify(t, varStack, occurCheck); if (t.isUnified) return Unify(t.ULink, varStack, occurCheck); //Interpreter.UCount++; if (hasValue) { if (t.hasValue) { if (_functor.Equals(t._functor) && arity == t.Arity) // => two cuts will unify as well { for (int i = 0; i < arity; i++) if (!args[i].Unify(t.Arg(i), varStack, occurCheck)) return false; return true; } else return false; } // t is an unbound variable (add occur check here if deemed necessary) t.Bind(this); varStack.Push(t); } else // 'this' is an unbound variable. Add occur check here if deemed necessary { this.Bind(t); varStack.Push(this); } return true; }
private static void DCGGoal(Term t, ref TermNode body, ref Term remainder, ref bool embedded) { Term temp; if (t.IsString || t is Cut) body.Append(t); else if (t.Functor == Parser.CURL) { while (t.Arity == 2) { body.Append(t.Arg(0)); t = t.Arg(1); embedded = true; } } else if (t.IsList) { temp = new Term(); if (t == NULLLIST) t = temp; else t.SetRightmostArg(temp); if (embedded) { body.Append(new Term(Parser.EQ, remainder, t, FType.comp, OType.xfx, 700)); embedded = false; } else remainder.Bind(t); // in this case, nothing is appended to body, which may be left empty (e.g. t-->[x]) remainder = temp; } else if (t.IsAtom || t.IsCompound) { t = new DCGTerm(t, ref remainder); body.Append(t); } else if (t.IsVar) PrologIO.Error("Variable not allowed in DCG-clause: {0}", t.VarName()); else PrologIO.Error("Illegal term in DCG-clause: {0}", t); }