01: package ca.draisey.free.tprolog;
02:
03:
04:
05:
06:
07:
08:
09:
10:
11:
12:
13: final class HornClause extends Clause {
14: HornClause( final Clause c, final Term a )
15: {
16: consequent = c; antecedent = a;
17: }
18:
19:
20: final void listing( final int f, final Variables these, final java.io.PrintWriter p, final Monitor m )
21: {
22: m.monitor();
23:
24: if( ( f & -2 ) == 0 ) {
25: p.print( "HornClause( " );
26: consequent.listing( f, these, p, m );
27: p.print( ", " );
28: antecedent.listing( f, these, p, m );
29: p.print( " )" );
30: }
31: else if( ( f & 8 ) != 0 ) {
32: consequent.listing( f, these, p, m );
33: p.print( " " );
34: antecedent.listing( f, these, p, m );
35: }
36: else {
37: consequent.listing( f, these, p, m );
38: p.print( ". " );
39: antecedent.listing( f, these, p, m );
40: p.print( "," );
41: }
42: }
43:
44:
45: final String getkey() {
46: return consequent.getkey();
47: }
48:
49:
50:
51:
52:
53:
54:
55: final void queryClause( final Term goal, final Variables these, final Variables goals, final Successor success )
56: {
57:
58: consequent.queryClause( goal, these, goals, success.succession().new SuccessionSuccessor() {
59: void succeed()
60: {
61: succession().queryDatabase( antecedent, these, success );
62: }
63: } );
64: }
65:
66:
67: private final Clause consequent;
68: private final Term antecedent;
69: }
70:
71:
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