Esempio n. 1
0
    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);
    }