summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hastabel/LangLexer.g42
-rw-r--r--src/hastabel/LangParser.g42
-rw-r--r--src/hastabel/Predicates.java9
-rw-r--r--src/hastabel/PropertyLexer.g42
-rw-r--r--src/hastabel/PropertyParser.g464
-rw-r--r--src/hastabel/World.java10
-rw-r--r--src/hastabel/lang/Predicate.java48
7 files changed, 83 insertions, 54 deletions
diff --git a/src/hastabel/LangLexer.g4 b/src/hastabel/LangLexer.g4
index 45062f0..773ae54 100644
--- a/src/hastabel/LangLexer.g4
+++ b/src/hastabel/LangLexer.g4
@@ -13,7 +13,7 @@ SUB_TYPE_OF: '::';
STAR: '*';
ADD_TYPE_KW: 'add_type' SEP;
-ADD_RELATION_KW: 'add_relation' SEP;
+ADD_PREDICATE_KW: ('add_predicate' | 'add_function') SEP;
ADD_TEMPLATE_KW: 'add_template' SEP;
WS: SEP;
diff --git a/src/hastabel/LangParser.g4 b/src/hastabel/LangParser.g4
index 6d881a9..e71bf81 100644
--- a/src/hastabel/LangParser.g4
+++ b/src/hastabel/LangParser.g4
@@ -37,7 +37,7 @@ lang_instr:
{
}
- | (WS)* ADD_RELATION_KW (WS)* new_predicate (WS)*
+ | (WS)* ADD_PREDICATE_KW (WS)* new_predicate (WS)*
{
}
diff --git a/src/hastabel/Predicates.java b/src/hastabel/Predicates.java
index 07c47a3..66eebd7 100644
--- a/src/hastabel/Predicates.java
+++ b/src/hastabel/Predicates.java
@@ -38,17 +38,12 @@ public class Predicates
return result;
}
- if (signature.equals(previous_instance.get_signature()))
+ if (previous_instance.get_signatures().contains(signature))
{
return previous_instance;
}
- System.err.println
- (
- "[F] Conflicting signatures for predicate \""
- + name
- + "\"."
- );
+ previous_instance.add_signature(signature);
return null;
}
diff --git a/src/hastabel/PropertyLexer.g4 b/src/hastabel/PropertyLexer.g4
index b047ebb..568e0ff 100644
--- a/src/hastabel/PropertyLexer.g4
+++ b/src/hastabel/PropertyLexer.g4
@@ -9,7 +9,7 @@ R_PAREN: ')';
L_BRAKT: '[';
R_BRAKT: ']';
-TAG_EXISTING_KW: '(tag_existing' SEP;
+TAG_EXISTING_KW: '(seek' SEP;
IFF_OPERATOR_KW: '(iff' SEP;
AND_OPERATOR_KW: '(and' SEP;
diff --git a/src/hastabel/PropertyParser.g4 b/src/hastabel/PropertyParser.g4
index 9e51f01..b0685ad 100644
--- a/src/hastabel/PropertyParser.g4
+++ b/src/hastabel/PropertyParser.g4
@@ -699,7 +699,7 @@ ag_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final hastabel.lang.Predicate is_in_path, is_path_of;
+ final hastabel.lang.Predicate contains_node, is_path_of;
if (current_node == null)
{
@@ -717,10 +717,10 @@ ag_operator [Variable current_node]
}
path_type = WORLD.get_types_manager().get("path");
- is_in_path = WORLD.get_predicates_manager().get("is_in_path");
+ contains_node = WORLD.get_predicates_manager().get("contains_node");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- if ((path_type == null) || (is_path_of == null) || (is_in_path == null))
+ if ((path_type == null) || (is_path_of == null) || (contains_node == null))
{
WORLD.invalidate();
}
@@ -745,7 +745,7 @@ ag_operator [Variable current_node]
next_node,
Formula.implies
(
- is_in_path.as_formula_(next_node, next_path),
+ contains_node.as_formula_(next_path, next_node),
($formula.result)
)
)
@@ -786,7 +786,7 @@ eg_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final hastabel.lang.Predicate is_in_path, is_path_of;
+ final hastabel.lang.Predicate contains_node, is_path_of;
if (current_node == null)
{
@@ -804,10 +804,10 @@ eg_operator [Variable current_node]
}
path_type = WORLD.get_types_manager().get("path");
- is_in_path = WORLD.get_predicates_manager().get("is_in_path");
+ contains_node = WORLD.get_predicates_manager().get("contains_node");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- if ((path_type == null) || (is_path_of == null) || (is_in_path == null))
+ if ((path_type == null) || (is_path_of == null) || (contains_node == null))
{
WORLD.invalidate();
}
@@ -832,7 +832,7 @@ eg_operator [Variable current_node]
next_node,
Formula.implies
(
- is_in_path.as_formula_(next_node, next_path),
+ contains_node.as_formula_(next_path, next_node),
($formula.result)
)
)
@@ -873,7 +873,7 @@ af_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final hastabel.lang.Predicate is_in_path, is_path_of;
+ final hastabel.lang.Predicate contains_node, is_path_of;
if (current_node == null)
{
@@ -891,10 +891,10 @@ af_operator [Variable current_node]
}
path_type = WORLD.get_types_manager().get("path");
- is_in_path = WORLD.get_predicates_manager().get("is_in_path");
+ contains_node = WORLD.get_predicates_manager().get("contains_node");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- if ((path_type == null) || (is_path_of == null) || (is_in_path == null))
+ if ((path_type == null) || (is_path_of == null) || (contains_node == null))
{
WORLD.invalidate();
}
@@ -919,7 +919,7 @@ af_operator [Variable current_node]
next_node,
Formula.and
(
- is_in_path.as_formula_(next_node, next_path),
+ contains_node.as_formula_(next_path, next_node),
($formula.result)
)
)
@@ -960,7 +960,7 @@ ef_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final hastabel.lang.Predicate is_in_path, is_path_of;
+ final hastabel.lang.Predicate contains_node, is_path_of;
if (current_node == null)
{
@@ -978,10 +978,10 @@ ef_operator [Variable current_node]
}
path_type = WORLD.get_types_manager().get("path");
- is_in_path = WORLD.get_predicates_manager().get("is_in_path");
+ contains_node = WORLD.get_predicates_manager().get("contains_node");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- if ((path_type == null) || (is_path_of == null) || (is_in_path == null))
+ if ((path_type == null) || (is_path_of == null) || (contains_node == null))
{
WORLD.invalidate();
}
@@ -1006,7 +1006,7 @@ ef_operator [Variable current_node]
next_node,
Formula.and
(
- is_in_path.as_formula_(next_node, next_path),
+ contains_node.as_formula_(next_path, next_node),
($formula.result)
)
)
@@ -1051,7 +1051,7 @@ au_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final hastabel.lang.Predicate is_path_of, is_in_path, is_before;
+ final hastabel.lang.Predicate is_path_of, contains_node, is_before;
if (current_node == null)
{
@@ -1070,14 +1070,14 @@ au_operator [Variable current_node]
path_type = WORLD.get_types_manager().get("path");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- is_in_path = WORLD.get_predicates_manager().get("is_in_path");
+ contains_node = WORLD.get_predicates_manager().get("contains_node");
is_before = WORLD.get_predicates_manager().get("is_before");
if
(
(path_type == null)
|| (is_path_of == null)
- || (is_in_path == null)
+ || (contains_node == null)
|| (is_before == null)
)
{
@@ -1104,7 +1104,7 @@ au_operator [Variable current_node]
f2_node,
Formula.and
(
- is_in_path.as_formula_(f2_node, next_path),
+ contains_node.as_formula_(next_path, f2_node),
($f2.result),
Formula.forall
(
@@ -1158,7 +1158,7 @@ eu_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final hastabel.lang.Predicate is_path_of, is_in_path, is_before;
+ final hastabel.lang.Predicate is_path_of, contains_node, is_before;
if (current_node == null)
{
@@ -1177,14 +1177,14 @@ eu_operator [Variable current_node]
path_type = WORLD.get_types_manager().get("path");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- is_in_path = WORLD.get_predicates_manager().get("is_in_path");
+ contains_node = WORLD.get_predicates_manager().get("contains_node");
is_before = WORLD.get_predicates_manager().get("is_before");
if
(
(path_type == null)
|| (is_path_of == null)
- || (is_in_path == null)
+ || (contains_node == null)
|| (is_before == null)
)
{
@@ -1211,7 +1211,7 @@ eu_operator [Variable current_node]
f2_node,
Formula.and
(
- is_in_path.as_formula_(f2_node, next_path),
+ contains_node.as_formula_(next_path, f2_node),
($f2.result),
Formula.forall
(
@@ -1262,7 +1262,7 @@ depth_no_parent_operator [Variable current_node]
{
final Type path_type;
final Variable next_path, node_of_path;
- final hastabel.lang.Predicate depth, is_path_of, is_lower_than, is_in_path, is_before;
+ final hastabel.lang.Predicate depth, is_path_of, is_lower_than, contains_node, is_before;
if (current_node == null)
{
@@ -1282,7 +1282,7 @@ depth_no_parent_operator [Variable current_node]
path_type = WORLD.get_types_manager().get("path");
depth = WORLD.get_predicates_manager().get("depth");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- is_in_path = WORLD.get_predicates_manager().get("is_in_path");
+ contains_node = WORLD.get_predicates_manager().get("contains_node");
is_before = WORLD.get_predicates_manager().get("is_before");
is_lower_than = WORLD.get_predicates_manager().get("is_lower_than");
@@ -1290,7 +1290,7 @@ depth_no_parent_operator [Variable current_node]
(
(path_type == null)
|| (is_path_of == null)
- || (is_in_path == null)
+ || (contains_node == null)
|| (is_lower_than == null)
|| (is_before == null)
|| (depth == null)
@@ -1322,7 +1322,7 @@ depth_no_parent_operator [Variable current_node]
node_for_f,
Formula.and
(
- is_in_path.as_formula_(node_for_f, next_path),
+ contains_node.as_formula_(next_path, node_for_f),
($formula.result),
Formula.not
(
@@ -1392,7 +1392,7 @@ depth_no_change_operator [Variable current_node]
{
final Type path_type;
final Variable next_path, node_of_path;
- final hastabel.lang.Predicate depth, is_path_of, is_in_path, is_before;
+ final hastabel.lang.Predicate depth, is_path_of, contains_node, is_before;
if (current_node == null)
{
@@ -1412,14 +1412,14 @@ depth_no_change_operator [Variable current_node]
path_type = WORLD.get_types_manager().get("path");
depth = WORLD.get_predicates_manager().get("depth");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- is_in_path = WORLD.get_predicates_manager().get("is_in_path");
+ contains_node = WORLD.get_predicates_manager().get("contains_node");
is_before = WORLD.get_predicates_manager().get("is_before");
if
(
(path_type == null)
|| (is_path_of == null)
- || (is_in_path == null)
+ || (contains_node == null)
|| (is_before == null)
|| (depth == null)
)
@@ -1450,7 +1450,7 @@ depth_no_change_operator [Variable current_node]
node_for_f,
Formula.and
(
- is_in_path.as_formula_(node_for_f, next_path),
+ contains_node.as_formula_(next_path, node_for_f),
($formula.result),
Formula.equals
(
diff --git a/src/hastabel/World.java b/src/hastabel/World.java
index d7dc2a0..aaa66e4 100644
--- a/src/hastabel/World.java
+++ b/src/hastabel/World.java
@@ -52,14 +52,14 @@ public class World extends LogicWorld
parser.lang_file(this);
- if (!is_erroneous)
- {
- is_erroneous = !(new GraphToFirstOrder("path_")).run(this);
- }
-
return !is_erroneous;
}
+ public void ensure_first_order ()
+ {
+ is_erroneous = !(new GraphToFirstOrder("path_")).run(this);
+ }
+
public Formula load_property (final String filename)
throws IOException
{
diff --git a/src/hastabel/lang/Predicate.java b/src/hastabel/lang/Predicate.java
index 1b9571f..bfdd701 100644
--- a/src/hastabel/lang/Predicate.java
+++ b/src/hastabel/lang/Predicate.java
@@ -11,13 +11,25 @@ import java.util.ArrayList;
public class Predicate
{
- private final List<Type> signature;
+ private final Collection<List<Type>> signatures;
private final Set<List<Element>> members;
private final String name;
public Predicate (final List<Type> signature, final String name)
{
- this.signature = signature;
+ signatures = new ArrayList<List<Type>>(1);
+ signatures.add(signature);
+
+ this.name = name;
+
+ members = new HashSet<List<Element>>();
+ }
+
+ public Predicate (final Collection<List<Type>> signatures, final String name)
+ {
+ this.signatures = new ArrayList<List<Type>>();
+ this.signatures.addAll(signatures);
+
this.name = name;
members = new HashSet<List<Element>>();
@@ -48,7 +60,11 @@ public class Predicate
}
}
- public boolean is_compatible_with (final List<Element> elements)
+ private boolean is_compatible_with_signature
+ (
+ final List<Element> elements,
+ final List<Type> signature
+ )
{
final Iterator<Element> e_iter;
final Iterator<Type> s_iter;
@@ -72,14 +88,27 @@ public class Predicate
return true;
}
+ public boolean is_compatible_with (final List<Element> elements)
+ {
+ for (final List<Type> signature: signatures)
+ {
+ if (is_compatible_with_signature(elements, signature))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public String get_name ()
{
return name;
}
- public List<Type> get_signature ()
+ public Collection<List<Type>> get_signatures ()
{
- return signature;
+ return signatures;
}
public Set<List<Element>> get_members ()
@@ -89,7 +118,7 @@ public class Predicate
public Predicate shallow_copy ()
{
- return new Predicate(signature, name);
+ return new Predicate(signatures, name);
}
@Override
@@ -113,6 +142,11 @@ public class Predicate
return name.hashCode();
}
+ public void add_signature (final List<Type> signature)
+ {
+ signatures.add(signature);
+ }
+
public String get_definition ()
{
final StringBuilder sb;
@@ -146,7 +180,7 @@ public class Predicate
final Iterator<Type> s_iter;
sb = new StringBuilder();
- s_iter = signature.iterator();
+ s_iter = ((List<Type>) signatures.toArray()[0]).iterator();
sb.append(name);
sb.append(": ");