001: package ca.draisey.free.tprolog;
002:
003:
004:
005:
006:
007:
008: abstract class Sentence {
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020:
021:
022:
023:
024:
025:
026:
027:
028: public final String toString()
029: {
030: return tostring( new Monitor() );
031: }
032:
033: final String tostring( final Monitor m )
034: {
035: final java.io.StringWriter sout = new java.io.StringWriter();
036: final java.io.PrintWriter pout = new java.io.PrintWriter( sout, true );
037: listing( 11, null, pout, m );
038: pout.flush();
039: return sout.toString();
040: }
041:
042:
043:
044:
045:
046:
047:
048:
049:
050:
051:
052:
053:
054:
055:
056:
057:
058:
059:
060:
061:
062:
063:
064:
065:
066:
067:
068:
069:
070:
071:
072: final void listing( final int f, final Variables these, final java.io.PrintWriter p )
073: {
074: listing( f, these, p, new Monitor() );
075: }
076: abstract void listing( int f, Variables these, java.io.PrintWriter p, Monitor m );
077:
078:
079: final void listVariables( final Variables these, final java.io.PrintWriter p )
080: {
081: listVariables( these, p, new Monitor() );
082: }
083: void listVariables( final Variables these, final java.io.PrintWriter p, final Monitor m ) {}
084:
085: final java.util.Iterator iterListedVariables( final Variables these )
086: {
087: return iterListedVariables( these, new Monitor() );
088: }
089: final java.util.Iterator iterListedVariables( final Variables these, final Monitor m )
090: {
091: return new java.util.Iterator() {
092: Sentence car = Sentence.this;
093: public final boolean hasNext() { return car.hasNextQuantifier(); }
094: public final Object next()
095: {
096: final java.io.StringWriter sout = new java.io.StringWriter();
097: final java.io.PrintWriter pout = new java.io.PrintWriter( sout, true );
098: car.listed( these, pout, m );
099: pout.flush();
100: car = car.nextQuantifier();
101: return sout.toString();
102: }
103: public final void remove() { throw new UnsupportedOperationException(); }
104: };
105: }
106:
107:
108: boolean hasNextQuantifier() { return false; }
109: Sentence nextQuantifier() { throw new java.util.NoSuchElementException(); }
110: void listed( final Variables these, final java.io.PrintWriter p, final Monitor m ) { throw new java.util.NoSuchElementException(); }
111:
112:
113:
114: Variables instantiateVariables() { return null; }
115:
116: abstract Clause dequantifyClause();
117: Term dequantifyTerm() { throw new UnsupportedOperationException(); }
118:
119:
120: String getkey()
121: {
122: throw new UnsupportedOperationException();
123: }
124: }
125:
126:
Prolog in Java
A trivial prolog interpreter written in java.
Copyright 2004, M.E.J.Draisey
This file is part of tprologinjava.
tprologinjava is free software; you can redistribute it and/or modify it under
the terms of the GNU General
Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
tprologinjava is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with tprologinjava; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Formatted with
GNU source-highlight:
http:// www.gnu.org/ software/ src-highlite