00001
00002
00003
00004
00005
00006
00007
00008
00009 package com.declarativa.interprolog;
00010 import java.util.*;
00011 import com.declarativa.interprolog.util.*;
00012
00016 public class PrologOperatorsContext {
00017 Hashtable prefixOperators,postfixOperators,infixOperators;
00018 boolean prefixOperator(Object node){
00019 return prefixOperators.containsKey(node);
00020 }
00021 boolean postfixOperator(Object node){
00022 return postfixOperators.containsKey(node);
00023 }
00024 boolean infixOperator(Object node){
00025 return infixOperators.containsKey(node);
00026 }
00027 PrologOperatorsContext(PrologOperator[] operators){
00028 int nOperators=0;
00029 if (operators!=null) nOperators=operators.length;
00030 prefixOperators = new Hashtable(nOperators+1);
00031 postfixOperators = new Hashtable(nOperators+1);
00032 infixOperators = new Hashtable(nOperators+1);
00033 for (int o=0;o<nOperators;o++){
00034 int type=operators[o].type;
00035 Hashtable placeholder = null;
00036 if (type==fx||type==fy)
00037 placeholder=prefixOperators;
00038 else if (type==xfx||type==xfy||type==yfx)
00039 placeholder=infixOperators;
00040 else if (type==xf||type==yf)
00041 placeholder=postfixOperators;
00042 placeholder.put(operators[o].name,operators[o]);
00043 }
00044 }
00045 PrologOperatorsContext(){
00046 this(standardXSBOperators);
00047 }
00048 static final int xfx=1,xfy=2,yfx=3,fx=4,fy=5,xf=6,yf=7;
00049 static final PrologOperator[] standardXSBOperators={
00050
00051 new PrologOperator(1200,xfx,":-"),
00052 new PrologOperator(1200,xfx,"-->"),
00053 new PrologOperator(1200,fx,"?-"),
00054 new PrologOperator(1198,xfx,"::-"),
00055 new PrologOperator(1150,fx,"hilog"),
00056 new PrologOperator(1150,fx,"dynamic"),new PrologOperator(1150,fx,"multifile"),
00057 new PrologOperator(1100,xfy,";"),
00058 new PrologOperator(1100,fx,"table"),
00059 new PrologOperator(1100,fx,"edb"),
00060 new PrologOperator(1100,fy,"index"),
00061 new PrologOperator(1100,fy,"ti"),
00062 new PrologOperator(1100,fy,"ti_off"),
00063 new PrologOperator(1100,fx,"mode"),
00064 new PrologOperator(1100,fx,"export"),
00065 new PrologOperator(1100,fx,"parallel"),
00066 new PrologOperator(1100,fx,"local"),
00067 new PrologOperator(1050,fy,"import"),
00068 new PrologOperator(1050,xfx,"from"),
00069 new PrologOperator(1050,xfy,"->"),
00070 new PrologOperator(1000,xfy,","),
00071 new PrologOperator(900,fy,"not"),
00072 new PrologOperator(900,fy,"\\+"),
00073 new PrologOperator(900,fy,"spy"),
00074 new PrologOperator(900,fy,"nospy"),
00075 new PrologOperator(700,xfx,"="),
00076 new PrologOperator(700,xfx,"\\="),
00077 new PrologOperator(700,xfx,"=="),
00078 new PrologOperator(700,xfx,"\\=="),
00079 new PrologOperator(700,xfx,"@<"),
00080 new PrologOperator(700,xfx,"@=<"),
00081 new PrologOperator(700,xfx,"@>"),
00082 new PrologOperator(700,xfx,"@>="),
00083 new PrologOperator(700,xfx,"=.."),
00084 new PrologOperator(700,xfx,"^=.."),
00085 new PrologOperator(700,xfx,"is"),
00086 new PrologOperator(700,xfx,"=:="),
00087 new PrologOperator(700,xfx,"=\\="),
00088 new PrologOperator(700,xfx,"<"),
00089 new PrologOperator(700,xfx,"=<"),
00090 new PrologOperator(700,xfx,">"),
00091 new PrologOperator(700,xfx,">="),
00092 new PrologOperator(661,xfy,"."),
00093 new PrologOperator(600,xfy,":"),
00094 new PrologOperator(500,yfx,"+"),
00095 new PrologOperator(500,yfx,"-"),
00096 new PrologOperator(500,yfx,"/\\"),
00097 new PrologOperator(500,yfx,"\\/"),
00098 new PrologOperator(500,fx,"+"),
00099 new PrologOperator(500,fx,"-"),
00100 new PrologOperator(400,yfx,"*"),
00101 new PrologOperator(400,yfx,"/"),
00102 new PrologOperator(400,yfx,"//"),
00103 new PrologOperator(400,yfx,"mod"),
00104 new PrologOperator(400,yfx,"<<"),
00105 new PrologOperator(400,yfx,">>"),
00106 new PrologOperator(400,yfx,"\\"),
00107 new PrologOperator(200,xfy,"^")
00108 };
00109
00110 static class PrologOperator{
00111 int precedence;
00112 int type;
00113 String name;
00114 PrologOperator(int p,int t,String n){
00115 if (t<xfx||t>yf||p<1||p>1200||n==null)
00116 throw new IPException("Bad arguments in PrologOperator constructor");
00117 precedence=p; type=t; name=n;
00118 }
00119 }
00120 }