Package jp.ac.kobe_u.cs.prolog.lang

Examples of jp.ac.kobe_u.cs.prolog.lang.ListTerm


            throw new IllegalTypeException("integer", a4);
        } else {
            engine.cut(((IntegerTerm) a4).intValue());
        }
        //END inline expansion
        a5 = new ListTerm(a3, s1);
        return new PRED_$add_operators_3(a5, a1, a2, cont);
    }
View Full Code Here


    a2 = arg2;

    a1 = a1.dereference();
    if (a1.isSymbol() || a1.isNumber() || a1.isJavaObject()
        || a1.isClosure()) {
      if (!a2.unify(new ListTerm(a1, SYM_NIL), engine.trail)) {
        return engine.fail();
      }
    } else if (a1.isList()) {
      Term t = new ListTerm(((ListTerm) a1).cdr(), SYM_NIL);
      t = new ListTerm(((ListTerm) a1).car(), t);
      t = new ListTerm(SYM_DOT, t);
      if (!a2.unify(t, engine.trail)) {
        return engine.fail();
      }
    } else if (a1.isStructure()) {
      SymbolTerm sym = SymbolTerm.makeSymbol(((StructureTerm) a1)
          .functor().name());
      Term[] args = ((StructureTerm) a1).args();
      Term t = SYM_NIL;
      for (int i = args.length; i > 0; i--) {
        t = new ListTerm(args[i - 1], t);
      }
      if (!a2.unify(new ListTerm(sym, t), engine.trail)) {
        return engine.fail();
      }
    } else if (a1.isVariable()) {
      a2 = a2.dereference();
      if (a2.isVariable()) {
View Full Code Here

            a4 = args[0];
            a5 = args[1];
        } else if (a1.isVariable()){
            a4 = new VariableTerm(engine);
            a5 = new VariableTerm(engine);
            ((VariableTerm) a1).bind(new ListTerm(a4, a5), engine.trail);
        } else {
            return engine.fail();
        }
        a6 = new VariableTerm(engine);
        //START inline expansion of $get_level(a(6))
View Full Code Here

      return SymbolTerm.makeSymbol((String) o);
    } else if (o instanceof Vector) {
      Vector v = (Vector) o;
      Term t = Prolog.Nil;
      for (int i = v.size(); i > 0; i--) {
        t = new ListTerm(inverseConversion(v.elementAt(i - 1)), t);
      }
      return t;
    }
    return new JavaObjectTerm(o);
  }
View Full Code Here

        throw new IllegalTypeException(this, 1, "atom", a1);
      }
      String s = ((SymbolTerm) a1).name();
      Term x = Nil;
      for (int i = s.length(); i > 0; i--) {
        x = new ListTerm(SymbolTerm.makeSymbol(s.substring(i - 1, i)),
            x);
      }
      if (!a2.unify(x, engine.trail)) {
        return engine.fail();
      }
View Full Code Here

          throw new ExistenceException(this, 1, "source_sink", a1, "");
        }
        PushbackReader in = new PushbackReader(new BufferedReader(
            new FileReader(file)), Prolog.PUSHBACK_SIZE);
        streamObject = new JavaObjectTerm(in);
        opts = new ListTerm(SYM_INPUT, opts);
      } else if (a2.equals(SYM_WRITE)) {
        PrintWriter out = new PrintWriter(new BufferedWriter(
            new FileWriter(file, false)));
        streamObject = new JavaObjectTerm(out);
        opts = new ListTerm(SYM_OUTPUT, opts);
      } else if (a2.equals(SYM_APPEND)) {
        PrintWriter out = new PrintWriter(new BufferedWriter(
            new FileWriter(file, true)));
        streamObject = new JavaObjectTerm(out);
        opts = new ListTerm(SYM_OUTPUT, opts);
      } else {
        throw new IllegalDomainException(this, 2, "io_mode", a2);
      }
    } catch (IOException e) {
      throw new PermissionException(this, "open", "source_sink", a1, "");
    }
    if (engine.getStreamManager().containsKey(streamObject)) {
      throw new InternalException("stream object is duplicated");
    }
    // stream_options
    a4 = a4.dereference();
    Term tmp = a4;
    while (!tmp.isNil()) {
      if (tmp.isVariable()) {
        throw new PInstantiationException(this, 4);
      }
      if (!tmp.isList()) {
        throw new IllegalTypeException(this, 4, "list", a4);
      }
      Term car = ((ListTerm) tmp).car().dereference();
      if (car.isVariable()) {
        throw new PInstantiationException(this, 4);
      }
      if (car.isStructure()) {
        SymbolTerm functor = ((StructureTerm) car).functor();
        Term[] args = ((StructureTerm) car).args();
        if (functor.equals(SYM_ALIAS_1)) {
          alias = args[0].dereference();
          if (!alias.isSymbol()) {
            throw new IllegalDomainException(this, 4,
                "stream_option", car);
          }
          if (engine.getStreamManager().containsKey(alias)) {
            throw new PermissionException(this, "open",
                "source_sink", car, "");
          }
        } else {
          throw new IllegalDomainException(this, 4, "stream_option",
              car);
        }
      } else {
        throw new IllegalDomainException(this, 4, "stream_option", car);
      }
      tmp = ((ListTerm) tmp).cdr().dereference();
    }
    Term[] args1 = { SYM_TEXT };
    Term[] args2 = { a2 };
    Term[] args3 = { SymbolTerm.makeSymbol(file.getAbsolutePath()) };
    opts = new ListTerm(new StructureTerm(SYM_TYPE_1, args1), opts);
    opts = new ListTerm(new StructureTerm(SYM_MODE_1, args2), opts);
    opts = new ListTerm(new StructureTerm(SYM_FILE_NAME_1, args3), opts);
    if (alias != null) {
      engine.getStreamManager().put(alias, streamObject);
      Term[] as = { alias };
      opts = new ListTerm(new StructureTerm(SYM_ALIAS_1, as), opts);
    }
    ((VariableTerm) a3).bind(streamObject, engine.trail);
    engine.getStreamManager().put(streamObject, opts);
    return cont;
  }
View Full Code Here

        if (a1.isList()){
            Term[] args = {((ListTerm)a1).car(), ((ListTerm)a1).cdr()};
            a4 = args[1];
        } else if (a1.isVariable()){
            a4 = new VariableTerm(engine);
            ((VariableTerm) a1).bind(new ListTerm(new VariableTerm(engine), a4), engine.trail);
        } else {
            return engine.fail();
        }
        a5 = new VariableTerm(engine);
        //START inline expansion of $plus(a(2),si(2),a(5))
View Full Code Here

      val1 = System.currentTimeMillis() - engine.getStartRuntime();
      val2 = val1 - engine.getPreviousRuntime();
      engine.setPreviousRuntime(val1);
      start = new IntegerTerm((int) val1);
      previous = new IntegerTerm((int) val2);
      result = new ListTerm(start, new ListTerm(previous, Nil));
    } else if (a1.equals(SYM_TRAIL)) {
      int top, max;
      Term free, used;
      top = engine.trail.top();
      max = engine.trail.max();
      used = new IntegerTerm(top);
      free = new IntegerTerm(max - top);
      result = new ListTerm(used, new ListTerm(free, Nil));
    } else if (a1.equals(SYM_CHOICE)) {
      int top, max;
      Term free, used;
      top = engine.stack.top();
      max = engine.stack.max();
      used = new IntegerTerm(top);
      free = new IntegerTerm(max - top);
      result = new ListTerm(used, new ListTerm(free, Nil));
    } else {
      return engine.fail();
    }
    if (!a2.unify(result, engine.trail)) {
      return engine.fail();
View Full Code Here

        break;
      case 'S':
        char[] chars = s.toString().toCharArray();
        token = Prolog.Nil;
        for (int i = chars.length; i > 0; i--) {
          token = new ListTerm(new IntegerTerm(chars[i - 1]), token);
        }
        break;
      default:
        token = SymbolTerm.makeSymbol(s.toString());
        break;
View Full Code Here

        a4 = new VariableTerm(engine);
        a5 = new VariableTerm(engine);
        Term[] y1 = {a4, a5};
        a6 = new StructureTerm(s2, y1);
        a7 = new VariableTerm(engine);
        a8 = new ListTerm(a6, a7);
        //START inline expansion of $unify(a(1),a(8))
        if (! a1.unify(a8, engine.trail)) {
            return engine.fail();
        }
        //END inline expansion
        a9 = new VariableTerm(engine);
        a10 = new VariableTerm(engine);
        a11 = new VariableTerm(engine);
        Term[] y2 = {a4, a5};
        a12 = new StructureTerm(s2, y2);
        a13 = new ListTerm(a12, a9);
        a14 = new ListTerm(a5, a10);
        p1 = new PRED_$bagof_instances0_5(a11, a2, a3, a13, a14, cont);
        return new PRED_$variants_subset_5(a7, a4, a9, a10, a11, p1);
    }
View Full Code Here

TOP

Related Classes of jp.ac.kobe_u.cs.prolog.lang.ListTerm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.