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

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


    a2 = arg2;

    a1 = a1.dereference();
    a2 = a2.dereference();
    if (a2.isNil()) {
      throw new SyntaxException(this, 2, "character_code_list", a2, "");
    }
    if (a1.isVariable()) { // number_codes(-Number, +CharCodeList)
      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.isInteger()) {
          throw new RepresentationException(this, 2, "character_code");
        }
        // car is an integer
        int i = ((IntegerTerm) car).intValue();
        if (!Character.isDefined((char) i)) {
          throw new RepresentationException(this, 2, "character_code");
        }
        sb.append((char) i);
        x = ((ListTerm) x).cdr().dereference();
      }
      try {
        if (!a1.unify(new IntegerTerm(Integer.parseInt(sb.toString())),
            engine.trail)) {
          return engine.fail();
        }
        return cont;
      } catch (NumberFormatException e) {
      }
      try {
        if (!a1.unify(
            new DoubleTerm(Double.parseDouble(sb.toString())),
            engine.trail)) {
          return engine.fail();
        }
        return cont;
      } catch (NumberFormatException e) {
        throw new SyntaxException(this, 2, "character_code_list", a2,
            "");
      }
    } else if (a1.isNumber()) { // number_codes(+Number, ?CharCodeList)
      char[] chars = a1.toString().toCharArray();
      Term y = Nil;
View Full Code Here


    a2 = arg2;

    a1 = a1.dereference();
    a2 = a2.dereference();
    if (a2.isNil()) {
      throw new SyntaxException(this, 2, "character_code_list", a2, "");
    }
    if (a1.isVariable()) { // number_chars(-Number, +CharList)
      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());
        x = ((ListTerm) x).cdr().dereference();
      }
      try {
        if (!a1.unify(new IntegerTerm(Integer.parseInt(sb.toString())),
            engine.trail)) {
          return engine.fail();
        }
        return cont;
      } catch (NumberFormatException e) {
      }
      try {
        if (!a1.unify(
            new DoubleTerm(Double.parseDouble(sb.toString())),
            engine.trail)) {
          return engine.fail();
        }
        return cont;
      } catch (NumberFormatException e) {
        throw new SyntaxException(this, 2, "character_code_list", a2,
            "");
      }
    } else if (a1.isNumber()) { // number_chars(+Number, ?CharList)
      String s = a1.toString();
      Term y = Nil;
View Full Code Here

TOP

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

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.