01: package ca.draisey.free.tprolog;
02:
03:
04:
05:
06:
07:
08: final class PairTerm extends Term {
09: PairTerm( final Term l, final Term r )
10: {
11: left = l; right = r;
12: }
13:
14:
15: final void listing( final int f, final Variables these, final java.io.PrintWriter p, final Monitor m )
16: {
17:
18: m.monitor();
19: if( ( f & -2 ) == 0 ) {
20: p.print( "PairTerm( " );
21: left.listing( f, these, p, m );
22: p.print( ", " );
23: right.listing( f, these, p, m );
24: p.print( ")" );
25: }
26: else {
27: left.listing( f, these, p, m );
28: p.print( "( " );
29: right.listing( f, these, p, m );
30: p.print( " )" );
31: }
32: }
33:
34:
35: final String getkey() {
36: return left.getkey() + "()";
37: }
38:
39:
40: protected final void unifythrough( final Term that, final Variables these, final Variables those, final Successor success )
41: {
42: that.unifytoPair( this, those, these, success );
43: }
44:
45:
46: protected final void unifytoPair( final PairTerm that, final Variables these, final Variables those, final Successor success )
47: {
48:
49: left.unifythrough( that.left, these, those, success.succession().new SuccessionSuccessor() {
50: void succeed()
51: {
52: right.unifythrough( that.right, these, those, success );
53:
54: }
55: } );
56: }
57:
58:
59:
60:
61: private final Term left, right;
62: }
63:
64:
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