public boolean runTest(IEnv env) { try { TermSystem general = TermWare.getInstance().getRoot().resolveSystem("general"); Term t = TermWare.getInstance().getTermFactory().createParsedTerm("neq(p(x),p(x))"); Term r = general.reduce(t); if (!(r.isBoolean() && r.getBoolean() == false)) { System.out.println("r1=" + TermHelper.termToString(r)); return false; } t = TermWare.getInstance().getTermFactory().createParsedTerm("neq(p(\"x\"),p(\"x\"))"); r = general.reduce(t); if (r.isBoolean()) { if (r.getBoolean() == false) { return true; } else { return false; } } else { System.out.println("r2=" + TermHelper.termToString(r)); return false; } } catch (TermWareException ex) { ex.printStackTrace(); return false; } }
Term createDoubleOrFloat(String x) { Term retval = null; if (x.endsWith("F") || x.endsWith("f")) { retval = TermWare.getInstance() .getTermFactory() .createFloat(Float.valueOf(x.substring(0, x.length() - 1))); } else { retval = TermWare.getInstance().getTermFactory().createDouble(Double.valueOf(x)); } return retval; }
Term createIntegerOrLong(String x) throws ParseException { try { Term retval = null; if (x.endsWith("L") || x.endsWith("l")) { try { retval = TermWare.getInstance() .getTermFactory() .createLong(Long.decode(x.substring(0, x.length() - 1))); } catch (NumberFormatException ex) { // it can be just too big, becouse literals can be unsigned, while decode does not handle // unsogned, // bigger then MAX // Here we will handle one case, which exists in JDK sources. (java/lang/Long.java) if (x.length() > 2) { char last = x.charAt(x.length() - 2); long l = Long.decode(x.substring(0, x.length() - 2)); char x0 = x.charAt(0); char x1 = x.charAt(1); if (x0 == '0') { if (x1 == 'x' || x1 == 'X') { // hex int l1 = Character.digit(last, 16); l = ((l << 8) + l1); } else { // oct int l1 = Character.digit(last, 8); l = ((l << 4) + l1); } } retval = TermWare.getInstance().getTermFactory().createLong(l); } else { throw ex; } } } else { long l = Long.decode(x); retval = TermWare.getInstance().getTermFactory().createInt((int) l); } return retval; } catch (NumberFormatException ex) { throw new ParseException( "Can't read IntegerLiteral " + ex.getMessage() + "(s=" + x + ") " + " in file " + inFname); } }
Term cons(Term x1, Term x2) { try { return TermWare.getInstance().getTermFactory().createTerm("cons", x1, x2); } catch (TermWareException ex) { throw new TermWareRuntimeException(ex); } }
Term createInt(int x) { return TermWare.getInstance().getTermFactory().createInt(x); }
Term createNil() { return TermWare.getInstance().getTermFactory().createNil(); }
Term createAtom(String name) { return TermWare.getInstance().getTermFactory().createAtom(name); }
Term createTerm(String name, Term x1, Term x2) throws TermWareException { return TermWare.getInstance().getTermFactory().createTerm(name, x1, x2); }
Term createBoolean(boolean x) { return TermWare.getInstance().getTermFactory().createBoolean(x); }
Term createString(String x) { return TermWare.getInstance().getTermFactory().createString(x); }
Term createChar(char x) { return TermWare.getInstance().getTermFactory().createChar(x); }