summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-05-26 14:23:14 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-05-26 14:23:14 +0200
commita8325138b0d5be98923dab3014cffdf83a1da832 (patch)
tree493c2557c652ee69da227f1da1f0bb94a3c23fa2
parenta71b0feb5da9b6668d402a458ed696c184f0d610 (diff)
downloadhastabel-a8325138b0d5be98923dab3014cffdf83a1da832.zip
hastabel-a8325138b0d5be98923dab3014cffdf83a1da832.tar.bz2
Adds some toString and equals.
-rw-r--r--src/hastabel/lang/Equals.java21
-rw-r--r--src/hastabel/lang/FunctionCall.java38
-rw-r--r--src/hastabel/lang/NamedExpression.java4
-rw-r--r--src/hastabel/lang/Operator.java24
-rw-r--r--src/hastabel/lang/OperatorFormula.java38
-rw-r--r--src/hastabel/lang/PredicateFormula.java50
-rw-r--r--src/hastabel/lang/Quantifier.java40
7 files changed, 210 insertions, 5 deletions
diff --git a/src/hastabel/lang/Equals.java b/src/hastabel/lang/Equals.java
index 639f2ea..556246f 100644
--- a/src/hastabel/lang/Equals.java
+++ b/src/hastabel/lang/Equals.java
@@ -21,4 +21,25 @@ public class Equals extends Formula
{
return b;
}
+
+ @Override
+ public boolean equals (Object o)
+ {
+ final Equals e;
+
+ if ((o == null) || !(o instanceof Equals))
+ {
+ return false;
+ }
+
+ e = (Equals) o;
+
+ return (e.a.equals(a) && e.b.equals(b));
+ }
+
+ @Override
+ public String toString ()
+ {
+ return "(eq " + a.toString() + " " + b.toString() + ")";
+ }
}
diff --git a/src/hastabel/lang/FunctionCall.java b/src/hastabel/lang/FunctionCall.java
index 6ec254e..a9957b0 100644
--- a/src/hastabel/lang/FunctionCall.java
+++ b/src/hastabel/lang/FunctionCall.java
@@ -2,7 +2,7 @@ package hastabel.lang;
import java.util.List;
-class FunctionCall extends Expression
+public class FunctionCall extends Expression
{
private final Predicate parent;
private final List<Expression> params;
@@ -27,4 +27,40 @@ class FunctionCall extends Expression
{
return params;
}
+
+ @Override
+ public boolean equals (Object o)
+ {
+ final FunctionCall e;
+
+ if ((o == null) || !(o instanceof FunctionCall))
+ {
+ return false;
+ }
+
+ e = (FunctionCall) o;
+
+ return (e.parent.equals(parent) && e.params.equals(params));
+ }
+
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb;
+
+ sb = new StringBuilder();
+
+ sb.append("[");
+ sb.append(parent.get_name());
+
+ for (final Expression param: params)
+ {
+ sb.append(" ");
+ sb.append(param.toString());
+ }
+
+ sb.append("]");
+
+ return sb.toString();
+ }
}
diff --git a/src/hastabel/lang/NamedExpression.java b/src/hastabel/lang/NamedExpression.java
index 727b3e4..76e4f1e 100644
--- a/src/hastabel/lang/NamedExpression.java
+++ b/src/hastabel/lang/NamedExpression.java
@@ -1,6 +1,6 @@
package hastabel.lang;
-abstract class NamedExpression extends Expression
+public abstract class NamedExpression extends Expression
{
public final String name;
@@ -39,6 +39,6 @@ abstract class NamedExpression extends Expression
@Override
public String toString ()
{
- return (type.get_name() + " " + name);
+ return name;
}
}
diff --git a/src/hastabel/lang/Operator.java b/src/hastabel/lang/Operator.java
index 795791e..f729ea9 100644
--- a/src/hastabel/lang/Operator.java
+++ b/src/hastabel/lang/Operator.java
@@ -43,4 +43,28 @@ public enum Operator
return as_formula(params);
}
+
+ public String toString ()
+ {
+ switch (this)
+ {
+ case NOT: return "not";
+ case AND: return "and";
+ case OR: return "or";
+ case IFF: return "iff";
+ case IMPLIES: return "implies";
+ case AX: return "ax";
+ case EX: return "ex";
+ case AG: return "ag";
+ case EG: return "eg";
+ case AF: return "af";
+ case EF: return "ef";
+ case AU: return "au";
+ case EU: return "eu";
+ case NPB: return "npb";
+ case NDCB: return "ndcb";
+ }
+
+ return "???";
+ }
}
diff --git a/src/hastabel/lang/OperatorFormula.java b/src/hastabel/lang/OperatorFormula.java
index 617299c..190e6cb 100644
--- a/src/hastabel/lang/OperatorFormula.java
+++ b/src/hastabel/lang/OperatorFormula.java
@@ -2,7 +2,7 @@ package hastabel.lang;
import java.util.List;
-class OperatorFormula extends Formula
+public class OperatorFormula extends Formula
{
private final Operator parent;
private final List<Formula> params;
@@ -26,4 +26,40 @@ class OperatorFormula extends Formula
{
return params;
}
+
+ @Override
+ public boolean equals (Object o)
+ {
+ final OperatorFormula e;
+
+ if ((o == null) || !(o instanceof OperatorFormula))
+ {
+ return false;
+ }
+
+ e = (OperatorFormula) o;
+
+ return (e.parent.equals(parent) && e.params.equals(params));
+ }
+
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb;
+
+ sb = new StringBuilder();
+
+ sb.append("(");
+ sb.append(parent.toString());
+
+ for (final Formula param: params)
+ {
+ sb.append(" ");
+ sb.append(param.toString());
+ }
+
+ sb.append(")");
+
+ return sb.toString();
+ }
}
diff --git a/src/hastabel/lang/PredicateFormula.java b/src/hastabel/lang/PredicateFormula.java
index 029af6a..2658200 100644
--- a/src/hastabel/lang/PredicateFormula.java
+++ b/src/hastabel/lang/PredicateFormula.java
@@ -2,7 +2,7 @@ package hastabel.lang;
import java.util.List;
-class PredicateFormula extends Formula
+public class PredicateFormula extends Formula
{
private final Predicate parent;
private final List<Expression> params;
@@ -34,4 +34,52 @@ class PredicateFormula extends Formula
{
return signature;
}
+
+ @Override
+ public boolean equals (Object o)
+ {
+ final PredicateFormula e;
+
+ if ((o == null) || !(o instanceof PredicateFormula))
+ {
+ return false;
+ }
+
+ e = (PredicateFormula) o;
+
+ return
+ (
+ e.parent.equals(parent)
+ && e.params.equals(params)
+ && e.signature.equals(signature)
+ );
+ }
+
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb;
+
+ sb = new StringBuilder();
+
+ sb.append("(");
+ sb.append(parent.toString());
+
+ for (final Expression param: params)
+ {
+ sb.append(" ");
+ if (param == null)
+ {
+ sb.append("_");
+ }
+ else
+ {
+ sb.append(param.toString());
+ }
+ }
+
+ sb.append(")");
+
+ return sb.toString();
+ }
}
diff --git a/src/hastabel/lang/Quantifier.java b/src/hastabel/lang/Quantifier.java
index fbb6d75..5f059ae 100644
--- a/src/hastabel/lang/Quantifier.java
+++ b/src/hastabel/lang/Quantifier.java
@@ -34,4 +34,44 @@ public class Quantifier extends Formula
{
return formula;
}
+
+ @Override
+ public boolean equals (Object o)
+ {
+ final Quantifier e;
+
+ if ((o == null) || !(o instanceof Quantifier))
+ {
+ return false;
+ }
+
+ e = (Quantifier) o;
+
+ return
+ (
+ e.parent.equals(parent)
+ && e.formula.equals(formula)
+ && (e.is_forall == is_forall)
+ );
+ }
+
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb;
+
+ sb = new StringBuilder();
+
+ sb.append("(");
+ sb.append(is_forall ? "forall" : "exists");
+ sb.append(" ");
+ sb.append(parent.get_name());
+ sb.append(" ");
+ sb.append(parent.get_type().get_name());
+ sb.append(" ");
+ sb.append(formula.toString());
+ sb.append(")");
+
+ return sb.toString();
+ }
}