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

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


    Term[] args;
    int arity, argNo;

    a1 = a1.dereference();
    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    } else if (!a1.isInteger()) {
      throw new IllegalTypeException(this, 1, "integer", a1);
    }
    a2 = a2.dereference();
    if (a2.isList()) {
      args = new Term[2];
      args[0] = ((ListTerm) a2).car();
      args[1] = ((ListTerm) a2).cdr();
      arity = 2;
    } else if (a2.isStructure()) {
      args = ((StructureTerm) a2).args();
      arity = ((StructureTerm) a2).arity();
    } else if (a2.isVariable()) {
      throw new PInstantiationException(this, 2);
    } else {
      throw new IllegalTypeException(this, 2, "compound", a2);
    }
    argNo = ((IntegerTerm) a1).intValue();
    if (argNo < 0) {
View Full Code Here


    Object stream = null;

    // Char
    a2 = a2.dereference();
    if (a2.isVariable()) {
      throw new PInstantiationException(this, 2);
    }
    if (!a2.isInteger()) {
      throw new IllegalTypeException(this, 2, "integer", a2);
    }
    // S_or_a
    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))
View Full Code Here

        if (!a1.unify(SymbolTerm.makeSymbol(""), engine.trail)) {
          return engine.fail();
        }
        return cont;
      } else if (a2.isVariable()) {
        throw new PInstantiationException(this, 2);
      } else if (!a2.isList()) {
        throw new IllegalTypeException(this, 2, "list", a2);
      }
      StringBuffer sb = new StringBuffer();
      Term x = a2;
      while (!x.isNil()) {
        if (x.isVariable()) {
          throw new PInstantiationException(this, 2);
        }
        if (!x.isList()) {
          throw new IllegalTypeException(this, 2, "list", a2);
        }
        Term car = ((ListTerm) x).car().dereference();
        if (car.isVariable()) {
          throw new PInstantiationException(this, 2);
        }
        if (!car.isSymbol() || ((SymbolTerm) car).name().length() != 1) {
          throw new IllegalTypeException(this, 2, "character", a2);
        }
        sb.append(((SymbolTerm) car).name());
View Full Code Here

    try {
      // 1st. argument (atom or java term)
      a1 = a1.dereference();
      if (a1.isVariable()) {
        throw new PInstantiationException(this, 1);
      } else if (a1.isSymbol()) { // class
        clazz = Class.forName(((SymbolTerm) a1).name());
      } else if (a1.isJavaObject()) { // instance
        instance = ((JavaObjectTerm) a1).object();
        clazz = ((JavaObjectTerm) a1).getClazz();
      } else {
        throw new IllegalTypeException(this, 1, "atom_or_java", a1);
      }
      // 2nd. argument (atom)
      a2 = a2.dereference();
      if (a2.isVariable()) {
        throw new PInstantiationException(this, 2);
      } else if (!a2.isSymbol()) {
        throw new IllegalTypeException(this, 2, "atom", a2);
      }
      field = clazz.getDeclaredField(((SymbolTerm) a2).name());
      // 3rd. argument (term)
View Full Code Here

      throw new IllegalTypeException(this, 3, "variable", a3);
    }
    // source_sink
    a1 = a1.dereference();
    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    }
    if (!a1.isSymbol()) {
      throw new IllegalDomainException(this, 1, "source_sink", a1);
    }
    file = new File(((SymbolTerm) a1).name());
    // io_mode
    a2 = a2.dereference();
    if (a2.isVariable()) {
      throw new PInstantiationException(this, 2);
    }
    if (!a2.isSymbol()) {
      throw new IllegalTypeException(this, 2, "atom", a2);
    }
    try {
      if (a2.equals(SYM_READ)) {
        if (!file.exists()) {
          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)) {
View Full Code Here

    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))
View Full Code Here

    a2 = arg2;
    Term result = null;

    a1 = a1.dereference();
    if (a1.isVariable()) {
      throw new PInstantiationException(this, 1);
    } else if (!a1.isSymbol()) {
      throw new IllegalTypeException(this, 1, "atom", a1);
    } else if (a1.equals(SYM_RUNTIME)) {
      long val1, val2;
      Term start, previous;
View Full Code Here

    a1 = a1.dereference();
    a2 = a2.dereference();
    if (a1.isVariable()) { // char_code(-Char, +CharCode)
      if (a2.isVariable()) {
        throw new PInstantiationException(this, 2);
      } else if (!a2.isInteger()) {
        throw new IllegalTypeException(this, 2, "integer", a2);
      }
      int i = ((IntegerTerm) a2).intValue();
      if (!Character.isDefined(i)) {
View Full Code Here

    Term token;

    // S_or_a
    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))
View Full Code Here

    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))
View Full Code Here

TOP

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

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.