Exemplo n.º 1
0
  @Override
  public Predicate exec(Prolog engine) {
    engine.setB0();
    Term a1;
    a1 = arg1;
    Object stream = null;

    a1 = a1.dereference();
    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    } else if (a1.isSymbol()) {
      if (!engine.getStreamManager().containsKey(a1)) {
        throw new ExistenceException(this, 1, "stream", a1, "");
      }
      stream = ((JavaObjectTerm) engine.getStreamManager().get(a1)).object();
    } else if (a1.isJavaObject()) {
      stream = ((JavaObjectTerm) a1).object();
    } else {
      throw new IllegalDomainException(this, 1, "stream_or_alias", a1);
    }
    if (!(stream instanceof PushbackReader)) {
      throw new PermissionException(this, "input", "stream", a1, "");
    }
    engine.setCurrentInput((PushbackReader) stream);
    return cont;
  }
Exemplo n.º 2
0
 public Predicate exec(Prolog engine) {
   // '$parse_tokens'(A,B,C,D):-'$parse_tokens_skip_spaces'(C,E),'$parse_tokens1'(B,F,G,E,H),!,'$parse_tokens_skip_spaces'(H,I),'$parse_tokens2'(B,F,G,A,J,I,D),!
   engine.setB0();
   Term a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
   Predicate p1, p2, p3, p4, p5;
   a1 = arg1;
   a2 = arg2;
   a3 = arg3;
   a4 = arg4;
   // '$parse_tokens'(A,B,C,D):-['$get_level'(E),'$parse_tokens_skip_spaces'(C,F),'$parse_tokens1'(B,G,H,F,I),'$cut'(E),'$parse_tokens_skip_spaces'(I,J),'$parse_tokens2'(B,G,H,A,K,J,D),'$cut'(E)]
   a5 = new VariableTerm(engine);
   // START inline expansion of $get_level(a(5))
   if (!a5.unify(new IntegerTerm(engine.B0), engine.trail)) {
     return engine.fail();
   }
   // END inline expansion
   a6 = new VariableTerm(engine);
   a7 = new VariableTerm(engine);
   a8 = new VariableTerm(engine);
   a9 = new VariableTerm(engine);
   a10 = new VariableTerm(engine);
   p1 = new PRED_$cut_1(a5, cont);
   p2 = new PRED_$parse_tokens2_7(a2, a7, a8, a1, new VariableTerm(engine), a10, a4, p1);
   p3 = new PRED_$parse_tokens_skip_spaces_2(a9, a10, p2);
   p4 = new PRED_$cut_1(a5, p3);
   p5 = new PRED_$parse_tokens1_5(a2, a7, a8, a6, a9, p4);
   return new PRED_$parse_tokens_skip_spaces_2(a3, a6, p5);
 }
Exemplo n.º 3
0
 public Predicate exec(Prolog engine) {
   // '$set_prolog_flag0'(no,A,B,C):-!,illarg(permission(modify,flag,A,D),set_prolog_flag(A,B),E)
   Term a1, a2, a3, a4, a5, a6;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   a3 = engine.aregs[3];
   a4 = engine.aregs[4];
   cont = engine.cont;
   // '$set_prolog_flag0'(no,A,B,C):-['$neck_cut',illarg(permission(modify,flag,A,D),set_prolog_flag(A,B),E)]
   a1 = a1.dereference();
   if (a1.isSymbol()) {
     if (!a1.equals(s1)) return engine.fail();
   } else if (a1.isVariable()) {
     ((VariableTerm) a1).bind(s1, engine.trail);
   } else {
     return engine.fail();
   }
   // START inline expansion of $neck_cut
   engine.neckCut();
   // END inline expansion
   Term[] y1 = {s3, s4, a2, new VariableTerm(engine)};
   a5 = new StructureTerm(s2, y1);
   Term[] y2 = {a2, a3};
   a6 = new StructureTerm(s5, y2);
   return new PRED_illarg_3(a5, a6, new VariableTerm(engine), cont);
 }
Exemplo n.º 4
0
 public Predicate exec(Prolog engine) {
   // A@>=B:-A@>=B
   engine.setB0();
   Term a1, a2;
   a1 = arg1;
   a2 = arg2;
   // A@>=B:-['$not_before'(A,B)]
   // START inline expansion of $not_before(a(1),a(2))
   a1 = a1.dereference();
   a2 = a2.dereference();
   if (a1.compareTo(a2) < 0) {
     return engine.fail();
   }
   // END inline expansion
   return cont;
 }
  public Predicate exec(Prolog engine) {
    engine.setB0();
    Term a1;
    a1 = arg1;

    a1 = a1.dereference();
    if (!a1.isJavaObject()) throw new IllegalTypeException(this, 1, "java", a1);
    Object obj = ((JavaObjectTerm) a1).object();
    if (!(obj instanceof PRED_$begin_exception_1))
      throw new SystemException(
          "a1 must be an object of PRED_$begin_exception_1: " + this.toString());
    PRED_$begin_exception_1 p = ((PRED_$begin_exception_1) obj);
    p.outOfScope = true;
    engine.trail.push(new OutOfScope(p));
    return cont;
  }
 public Predicate exec(Prolog engine) {
   // '$dummy_9_builtins.pl'(A):-atom(A),!,fail
   Term a1, a2;
   Predicate cont;
   a1 = engine.aregs[1];
   cont = engine.cont;
   // '$dummy_9_builtins.pl'(A):-['$get_level'(B),atom(A),'$cut'(B),fail]
   a2 = new VariableTerm(engine);
   // START inline expansion of $get_level(a(2))
   if (!a2.unify(new IntegerTerm(engine.B0), engine.trail)) {
     return engine.fail();
   }
   // END inline expansion
   // START inline expansion of atom(a(1))
   a1 = a1.dereference();
   if (!a1.isSymbol()) {
     return engine.fail();
   }
   // END inline expansion
   // START inline expansion of $cut(a(2))
   a2 = a2.dereference();
   if (!a2.isInteger()) {
     throw new IllegalTypeException("integer", a2);
   } else {
     engine.cut(((IntegerTerm) a2).intValue());
   }
   // END inline expansion
   // START inline expansion of fail
   return engine.fail();
   // END inline expansion
 }
 public Predicate exec(Prolog engine) {
   // '$dummy_14_builtins.pl'(A):-'$parse_tokens_is_post_in_op'(A),!,fail
   Term a1, a2;
   Predicate p1, p2;
   Predicate cont;
   a1 = engine.aregs[1];
   cont = engine.cont;
   // '$dummy_14_builtins.pl'(A):-['$get_level'(B),'$parse_tokens_is_post_in_op'(A),'$cut'(B),fail]
   a2 = new VariableTerm(engine);
   // START inline expansion of $get_level(a(2))
   if (!a2.unify(new IntegerTerm(engine.B0), engine.trail)) {
     return engine.fail();
   }
   // END inline expansion
   p1 = new PRED_fail_0(cont);
   p2 = new PRED_$cut_1(a2, p1);
   return new PRED_$parse_tokens_is_post_in_op_1(a1, p2);
 }
Exemplo n.º 8
0
 public Predicate exec(Prolog engine) {
   // '$sign'(A,B):-'$sign'(A,B)
   engine.setB0();
   Term a1, a2;
   a1 = arg1;
   a2 = arg2;
   // '$sign'(A,B):-['$sign'(A,B)]
   // START inline expansion of $sign(a(1),a(2))
   try {
     if (!a2.unify(Arithmetic.evaluate(a1).signum(), engine.trail)) {
       return engine.fail();
     }
   } catch (BuiltinException e) {
     e.goal = this;
     throw e;
   }
   // END inline expansion
   return cont;
 }
Exemplo n.º 9
0
 public Predicate exec(Prolog engine) {
   // '$variants_subset'([A|B],C,D,E,[A|F]):-'$variants_subset'(B,C,D,E,F)
   Term a1, a2, a3, a4, a5, a6, a7, a8;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   a3 = engine.aregs[3];
   a4 = engine.aregs[4];
   a5 = engine.aregs[5];
   cont = engine.cont;
   // '$variants_subset'([A|B],C,D,E,[A|F]):-['$variants_subset'(B,C,D,E,F)]
   a1 = a1.dereference();
   if (a1.isList()) {
     Term[] args = {((ListTerm) a1).car(), ((ListTerm) a1).cdr()};
     a6 = args[0];
     a7 = args[1];
   } else if (a1.isVariable()) {
     a6 = new VariableTerm(engine);
     a7 = new VariableTerm(engine);
     ((VariableTerm) a1).bind(new ListTerm(a6, a7), engine.trail);
   } else {
     return engine.fail();
   }
   a5 = a5.dereference();
   if (a5.isList()) {
     Term[] args = {((ListTerm) a5).car(), ((ListTerm) a5).cdr()};
     if (!a6.unify(args[0], engine.trail)) return engine.fail();
     a8 = args[1];
   } else if (a5.isVariable()) {
     a8 = new VariableTerm(engine);
     ((VariableTerm) a5).bind(new ListTerm(a6, a8), engine.trail);
   } else {
     return engine.fail();
   }
   engine.aregs[1] = a7;
   engine.aregs[2] = a2;
   engine.aregs[3] = a3;
   engine.aregs[4] = a4;
   engine.aregs[5] = a8;
   engine.cont = cont;
   return _$variants_subset_5_top;
 }
Exemplo n.º 10
0
 public Predicate exec(Prolog engine) {
   // '$set_prolog_flag0'(A,B,C,D):-'$builtin_member'(C,D),!,'$set_prolog_impl_flag'(B,C)
   Term a1, a2, a3, a4, a5;
   Predicate p1, p2;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   a3 = engine.aregs[3];
   a4 = engine.aregs[4];
   cont = engine.cont;
   // '$set_prolog_flag0'(A,B,C,D):-['$get_level'(E),'$builtin_member'(C,D),'$cut'(E),'$set_prolog_impl_flag'(B,C)]
   a5 = new VariableTerm(engine);
   // START inline expansion of $get_level(a(5))
   if (!a5.unify(new IntegerTerm(engine.B0), engine.trail)) {
     return engine.fail();
   }
   // END inline expansion
   p1 = new PRED_$set_prolog_impl_flag_2(a2, a3, cont);
   p2 = new PRED_$cut_1(a5, p1);
   return new PRED_$builtin_member_2(a3, a4, p2);
 }
Exemplo n.º 11
0
 public Predicate exec(Prolog engine) {
   // '$mem_pair'(A,[B|C]):-'$mem_pair'(A,C)
   Term a1, a2, a3;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   cont = engine.cont;
   // '$mem_pair'(A,[B|C]):-['$mem_pair'(A,C)]
   a2 = a2.dereference();
   if (a2.isList()) {
     Term[] args = {((ListTerm) a2).car(), ((ListTerm) a2).cdr()};
     a3 = args[1];
   } else if (a2.isVariable()) {
     a3 = new VariableTerm(engine);
     ((VariableTerm) a2).bind(new ListTerm(new VariableTerm(engine), a3), engine.trail);
   } else {
     return engine.fail();
   }
   engine.aregs[1] = a1;
   engine.aregs[2] = a3;
   engine.cont = cont;
   return _$mem_pair_2_top;
 }
Exemplo n.º 12
0
 public Predicate exec(Prolog engine) {
   // '$mem_pair'(A=B,[C=D|E]):-A==C,!,B=D
   Term a1, a2, a3, a4, a5, a6, a7, a8;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   cont = engine.cont;
   // '$mem_pair'(A=B,[C=D|E]):-['$get_level'(F),'$equality_of_term'(A,C),'$cut'(F),'$unify'(B,D)]
   a1 = a1.dereference();
   if (a1.isStructure()) {
     if (!s1.equals(((StructureTerm) a1).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a1).args();
     a3 = args[0];
     a4 = args[1];
   } else if (a1.isVariable()) {
     a3 = new VariableTerm(engine);
     a4 = new VariableTerm(engine);
     Term[] args = {a3, a4};
     ((VariableTerm) a1).bind(new StructureTerm(s1, args), engine.trail);
   } else {
     return engine.fail();
   }
   a2 = a2.dereference();
   if (a2.isList()) {
     Term[] args = {((ListTerm) a2).car(), ((ListTerm) a2).cdr()};
     a5 = args[0];
   } else if (a2.isVariable()) {
     a5 = new VariableTerm(engine);
     ((VariableTerm) a2).bind(new ListTerm(a5, new VariableTerm(engine)), engine.trail);
   } else {
     return engine.fail();
   }
   a5 = a5.dereference();
   if (a5.isStructure()) {
     if (!s1.equals(((StructureTerm) a5).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a5).args();
     a6 = args[0];
     a7 = args[1];
   } else if (a5.isVariable()) {
     a6 = new VariableTerm(engine);
     a7 = new VariableTerm(engine);
     Term[] args = {a6, a7};
     ((VariableTerm) a5).bind(new StructureTerm(s1, args), engine.trail);
   } else {
     return engine.fail();
   }
   a8 = new VariableTerm(engine);
   // START inline expansion of $get_level(a(8))
   if (!a8.unify(new IntegerTerm(engine.B0), engine.trail)) {
     return engine.fail();
   }
   // END inline expansion
   // START inline expansion of $equality_of_term(a(3),a(6))
   a3 = a3.dereference();
   a6 = a6.dereference();
   if (!a3.equals(a6)) {
     return engine.fail();
   }
   // END inline expansion
   // START inline expansion of $cut(a(8))
   a8 = a8.dereference();
   if (!a8.isInteger()) {
     throw new IllegalTypeException("integer", a8);
   } else {
     engine.cut(((IntegerTerm) a8).intValue());
   }
   // END inline expansion
   // START inline expansion of $unify(a(4),a(7))
   if (!a4.unify(a7, engine.trail)) {
     return engine.fail();
   }
   // END inline expansion
   return cont;
 }
Exemplo n.º 13
0
 public Predicate exec(Prolog engine) {
   // '$dcg_connect'(A,(B->C),D,((B->C),D)):-!
   Term a1, a2, a3, a4, a5, a6, a7;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   a3 = engine.aregs[3];
   a4 = engine.aregs[4];
   cont = engine.cont;
   // '$dcg_connect'(A,(B->C),D,((B->C),D)):-['$neck_cut']
   a2 = a2.dereference();
   if (a2.isStructure()) {
     if (!s1.equals(((StructureTerm) a2).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a2).args();
     a5 = args[0];
     a6 = args[1];
   } else if (a2.isVariable()) {
     a5 = new VariableTerm(engine);
     a6 = new VariableTerm(engine);
     Term[] args = {a5, a6};
     ((VariableTerm) a2).bind(new StructureTerm(s1, args), engine.trail);
   } else {
     return engine.fail();
   }
   a4 = a4.dereference();
   if (a4.isStructure()) {
     if (!s2.equals(((StructureTerm) a4).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a4).args();
     a7 = args[0];
     if (!a3.unify(args[1], engine.trail)) return engine.fail();
   } else if (a4.isVariable()) {
     a7 = new VariableTerm(engine);
     Term[] args = {a7, a3};
     ((VariableTerm) a4).bind(new StructureTerm(s2, args), engine.trail);
   } else {
     return engine.fail();
   }
   a7 = a7.dereference();
   if (a7.isStructure()) {
     if (!s1.equals(((StructureTerm) a7).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a7).args();
     if (!a5.unify(args[0], engine.trail)) return engine.fail();
     if (!a6.unify(args[1], engine.trail)) return engine.fail();
   } else if (a7.isVariable()) {
     Term[] args = {a5, a6};
     ((VariableTerm) a7).bind(new StructureTerm(s1, args), engine.trail);
   } else {
     return engine.fail();
   }
   // START inline expansion of $neck_cut
   engine.neckCut();
   // END inline expansion
   return cont;
 }
Exemplo n.º 14
0
 public Predicate exec(Prolog engine) {
   // '$dcg_connect'((A->B),(C->D),E,(C->F)):-!,'$dcg_and'(D,E,F)
   Term a1, a2, a3, a4, a5, a6, a7;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   a3 = engine.aregs[3];
   a4 = engine.aregs[4];
   cont = engine.cont;
   // '$dcg_connect'((A->B),(C->D),E,(C->F)):-['$neck_cut','$dcg_and'(D,E,F)]
   a1 = a1.dereference();
   if (a1.isStructure()) {
     if (!s1.equals(((StructureTerm) a1).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a1).args();
   } else if (a1.isVariable()) {
     Term[] args = {new VariableTerm(engine), new VariableTerm(engine)};
     ((VariableTerm) a1).bind(new StructureTerm(s1, args), engine.trail);
   } else {
     return engine.fail();
   }
   a2 = a2.dereference();
   if (a2.isStructure()) {
     if (!s1.equals(((StructureTerm) a2).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a2).args();
     a5 = args[0];
     a6 = args[1];
   } else if (a2.isVariable()) {
     a5 = new VariableTerm(engine);
     a6 = new VariableTerm(engine);
     Term[] args = {a5, a6};
     ((VariableTerm) a2).bind(new StructureTerm(s1, args), engine.trail);
   } else {
     return engine.fail();
   }
   a4 = a4.dereference();
   if (a4.isStructure()) {
     if (!s1.equals(((StructureTerm) a4).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a4).args();
     if (!a5.unify(args[0], engine.trail)) return engine.fail();
     a7 = args[1];
   } else if (a4.isVariable()) {
     a7 = new VariableTerm(engine);
     Term[] args = {a5, a7};
     ((VariableTerm) a4).bind(new StructureTerm(s1, args), engine.trail);
   } else {
     return engine.fail();
   }
   // START inline expansion of $neck_cut
   engine.neckCut();
   // END inline expansion
   return new PRED_$dcg_and_3(a6, a3, a7, cont);
 }
Exemplo n.º 15
0
 public Predicate exec(Prolog engine) {
   // '$variants_subset'([A+B|C],D,[A+B|E],[B|F],G):-'$term_variant'(D,A),!,'$variants_subset'(C,D,E,F,G)
   Term a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13;
   Predicate p1, p2;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   a3 = engine.aregs[3];
   a4 = engine.aregs[4];
   a5 = engine.aregs[5];
   cont = engine.cont;
   // '$variants_subset'([A+B|C],D,[A+B|E],[B|F],G):-['$get_level'(H),'$term_variant'(D,A),'$cut'(H),'$variants_subset'(C,D,E,F,G)]
   a1 = a1.dereference();
   if (a1.isList()) {
     Term[] args = {((ListTerm) a1).car(), ((ListTerm) a1).cdr()};
     a6 = args[0];
     a7 = args[1];
   } else if (a1.isVariable()) {
     a6 = new VariableTerm(engine);
     a7 = new VariableTerm(engine);
     ((VariableTerm) a1).bind(new ListTerm(a6, a7), engine.trail);
   } else {
     return engine.fail();
   }
   a6 = a6.dereference();
   if (a6.isStructure()) {
     if (!s2.equals(((StructureTerm) a6).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a6).args();
     a8 = args[0];
     a9 = args[1];
   } else if (a6.isVariable()) {
     a8 = new VariableTerm(engine);
     a9 = new VariableTerm(engine);
     Term[] args = {a8, a9};
     ((VariableTerm) a6).bind(new StructureTerm(s2, args), engine.trail);
   } else {
     return engine.fail();
   }
   a3 = a3.dereference();
   if (a3.isList()) {
     Term[] args = {((ListTerm) a3).car(), ((ListTerm) a3).cdr()};
     a10 = args[0];
     a11 = args[1];
   } else if (a3.isVariable()) {
     a10 = new VariableTerm(engine);
     a11 = new VariableTerm(engine);
     ((VariableTerm) a3).bind(new ListTerm(a10, a11), engine.trail);
   } else {
     return engine.fail();
   }
   a10 = a10.dereference();
   if (a10.isStructure()) {
     if (!s2.equals(((StructureTerm) a10).functor())) return engine.fail();
     Term[] args = ((StructureTerm) a10).args();
     if (!a8.unify(args[0], engine.trail)) return engine.fail();
     if (!a9.unify(args[1], engine.trail)) return engine.fail();
   } else if (a10.isVariable()) {
     Term[] args = {a8, a9};
     ((VariableTerm) a10).bind(new StructureTerm(s2, args), engine.trail);
   } else {
     return engine.fail();
   }
   a4 = a4.dereference();
   if (a4.isList()) {
     Term[] args = {((ListTerm) a4).car(), ((ListTerm) a4).cdr()};
     if (!a9.unify(args[0], engine.trail)) return engine.fail();
     a12 = args[1];
   } else if (a4.isVariable()) {
     a12 = new VariableTerm(engine);
     ((VariableTerm) a4).bind(new ListTerm(a9, a12), engine.trail);
   } else {
     return engine.fail();
   }
   a13 = new VariableTerm(engine);
   // START inline expansion of $get_level(a(13))
   if (!a13.unify(new IntegerTerm(engine.B0), engine.trail)) {
     return engine.fail();
   }
   // END inline expansion
   p1 = new PRED_$variants_subset_5(a7, a2, a11, a12, a5, cont);
   p2 = new PRED_$cut_1(a13, p1);
   return new PRED_$term_variant_2(a2, a8, p2);
 }
Exemplo n.º 16
0
 public Predicate exec(Prolog engine) {
   // '$variants_subset'([],A,[],[],[]):-!
   Term a1, a2, a3, a4, a5;
   Predicate cont;
   a1 = engine.aregs[1];
   a2 = engine.aregs[2];
   a3 = engine.aregs[3];
   a4 = engine.aregs[4];
   a5 = engine.aregs[5];
   cont = engine.cont;
   // '$variants_subset'([],A,[],[],[]):-['$neck_cut']
   a1 = a1.dereference();
   if (a1.isSymbol()) {
     if (!a1.equals(s1)) return engine.fail();
   } else if (a1.isVariable()) {
     ((VariableTerm) a1).bind(s1, engine.trail);
   } else {
     return engine.fail();
   }
   a3 = a3.dereference();
   if (a3.isSymbol()) {
     if (!a3.equals(s1)) return engine.fail();
   } else if (a3.isVariable()) {
     ((VariableTerm) a3).bind(s1, engine.trail);
   } else {
     return engine.fail();
   }
   a4 = a4.dereference();
   if (a4.isSymbol()) {
     if (!a4.equals(s1)) return engine.fail();
   } else if (a4.isVariable()) {
     ((VariableTerm) a4).bind(s1, engine.trail);
   } else {
     return engine.fail();
   }
   a5 = a5.dereference();
   if (a5.isSymbol()) {
     if (!a5.equals(s1)) return engine.fail();
   } else if (a5.isVariable()) {
     ((VariableTerm) a5).bind(s1, engine.trail);
   } else {
     return engine.fail();
   }
   // START inline expansion of $neck_cut
   engine.neckCut();
   // END inline expansion
   return cont;
 }