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); } }
private void generateSystemsPage() throws IOException, TermWareException { PrintStream out = openPrintStream("", "systems.html"); printHeader(out, "TermWare systems"); out.println("<BODY BGCOLOR=\"white\">"); out.println("<TABLE BORDER=\"0\" WIDTH=\"100%\">"); out.println("<TR>"); out.println("<TD NOWRAP><FONT size=\"+1\">"); out.println("Systems"); out.println("</FONT></TD>"); out.println("</TR></TABLE>"); out.println("<TABLE BORDER=\"0\" WIDTH=\"100%\">"); out.println("<TR><TD NOWRAP><P>"); out.println("<FONT>"); printListOfSystems(out, TermWare.getInstance().getRoot(), ""); out.println("<BR>"); out.println("<FONT +1>"); out.println("<A href=\"all-patterns.html\" target=\"patternFrame\" >"); out.println("all patterns"); out.println("</A></FONT>"); out.println("</TD>"); out.println("</TR>"); out.println("</TABLE>"); out.println("<P> </BODY></HTML>"); out.close(); }
private void init(String[] args) throws TermWareException { for (int i = 0; i < args.length; ++i) { if (args[i].equals("-o")) { if (i == args.length - 1) { throw new AssertException("Option -o require argument"); } outDir_ = args[++i]; } } if (outDir_ == null) { throw new AssertException("option -o is not set"); } IEnv env = new SystemEnv(); TermWare.getInstance().init(); File outDirFile = new File(outDir_); if (outDirFile.exists()) { if (!outDirFile.isDirectory()) { throw new AssertException("argument of option -o must be directory"); } } else { System.out.println("created drectory :" + outDir_); outDirFile.mkdir(); } }
Term cons(Term x1, Term x2) { try { return TermWare.getInstance().getTermFactory().createTerm("cons", x1, x2); } catch (TermWareException ex) { throw new TermWareRuntimeException(ex); } }
private void generateAllPatternsPage() throws IOException { PrintStream out = openPrintStream("", "all-patterns.html"); printHeader(out, "TermWare patterns list"); out.println("<BODY BGCOLOR=\"white\">"); out.println("<TABLE BORDER=\"0\" WIDTH=\"100%\">"); out.println("<TR>"); out.println("<TD NOWRAP><FONT size=\"+1\">"); out.println("Patterns"); out.println("</FONT></TD>"); out.println("</TR></TABLE>"); out.println("<TABLE BORDER=\"0\" WIDTH=\"100%\">"); out.println("<TR><TD NOWRAP><P>"); out.println("<FONT>"); printListOfAllPatterns(out, TermWare.getInstance().getRoot(), "", 0); out.println("</FONT>"); out.println("</TD>"); out.println("</TR>"); out.println("</TABLE>"); out.println("<P> </BODY></HTML>"); out.close(); }
private void generateSystemPages() throws IOException, TermWareException { generateSystemPages(TermWare.getInstance().getRoot(), "", 0); }
private void buildListOfAllPatterns() throws TermWareException { buildListOfAllPatterns(TermWare.getInstance().getRoot(), "", 0); }
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); }