import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import java.math.*; import gnu.prolog.vm.*; import gnu.prolog.term.*; import gnu.prolog.database.*; public class main { static int query(Interpreter intp, Term term) { try { try { Interpreter.Goal goal = intp.prepareGoal(term); return intp.execute(goal); // todo: stop goal? } catch (Exception e) { print("fail " + e); return 0; } } catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }} public static void main(String[] args) throws Exception { Environment env = new Environment(); String streamName = "someinput"; Reader reader = new StringReader("here."); new PrologTextLoader(env.getPrologTextLoaderState(), reader, streamName); List errors = env.getLoadingErrors(); for (PrologTextLoaderError error : errors) { printStackTrace(error); } Interpreter interpreter = env.createInterpreter(); env.runInitialization(interpreter); //print(interpreter.runOnce(AtomTerm.get("here"))); //print(interpreter.runOnce(AtomTerm.get("there"))); print(query(interpreter, AtomTerm.get("true"))); print(query(interpreter, AtomTerm.get("there"))); print(query(interpreter, AtomTerm.get("here"))); } static StringBuffer local_log = new StringBuffer(); // not redirected static volatile StringBuffer print_log = local_log; // might be redirected, e.g. to main bot static void print() { print(""); } static void print(Object o) { String s = String.valueOf(o) + "\n"; local_log.append(s); if (print_log != local_log && print_log != null) print_log.append(s); System.out.print(s); } static void print(long l) { print(String.valueOf(l)); } static void printStackTrace(Throwable e) { // we go to system.out now - system.err is nonsense print(getStackTrace(e)); } static void printStackTrace() { printStackTrace(new Throwable()); } static String getStackTrace(Throwable throwable) { StringWriter writer = new StringWriter(); throwable.printStackTrace(new PrintWriter(writer)); return writer.toString(); } }