Trivial Prolog in Java

01: package ca.draisey.free.tprolog;
02:
03:
04:
05:
06:
07: final class SymbolTable {
08:         final QuanTerm linkQuanTerm( final String symbol )
09:         {
10:                 // if( symbol.equals( "_" ) ) ...
11:                 if( table.containsKey( symbol ) ) {
12:                         return table.get( symbol );
13:                 }
14:                 else {
15:                         final QuanTerm t = new QuanTerm( symbol, size );
16:                         table.put( symbol, t );
17:                         ++size;
18:                         return t;
19:                 }
20:         }
21:         // append quantifiers for each variable to the beginning of the clause
22:         final Sentence quantify( final Clause c )
23:         {
24:                 Sentence sentence = c;
25:                 for( QuanTerm t : table.values() ) {
26:                         sentence = new QuantifiedSentence( size, t, sentence );
27:                 }
28:                 return sentence;
29:         }
30:         private final java.util.Map< String, QuanTerm > table = new java.util.HashMap< String, QuanTerm >();
31:         private int size = 0;
32: }
33:
34: // fin