summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hastabel/PropertyLexer.g42
-rw-r--r--src/hastabel/PropertyParser.g456
-rw-r--r--src/hastabel/Variables.java49
-rw-r--r--src/hastabel/World.java7
-rw-r--r--src/hastabel/lang/Element.java2
-rw-r--r--src/hastabel/lang/Expression.java45
-rw-r--r--src/hastabel/lang/FunctionCall.java1
-rw-r--r--src/hastabel/lang/NamedExpression.java50
-rw-r--r--src/hastabel/lang/Operator.java1
-rw-r--r--src/hastabel/lang/Predicate.java2
-rw-r--r--src/hastabel/lang/Quantifier.java2
-rw-r--r--src/hastabel/lang/Variable.java2
12 files changed, 119 insertions, 100 deletions
diff --git a/src/hastabel/PropertyLexer.g4 b/src/hastabel/PropertyLexer.g4
index e100efb..b047ebb 100644
--- a/src/hastabel/PropertyLexer.g4
+++ b/src/hastabel/PropertyLexer.g4
@@ -1,5 +1,7 @@
lexer grammar PropertyLexer;
+@header {package hastabel;}
+
fragment SEP: [ \t\r\n]+;
L_PAREN: '(';
diff --git a/src/hastabel/PropertyParser.g4 b/src/hastabel/PropertyParser.g4
index f23f4c0..9e51f01 100644
--- a/src/hastabel/PropertyParser.g4
+++ b/src/hastabel/PropertyParser.g4
@@ -7,8 +7,14 @@ options
@header
{
+ package hastabel;
+
import hastabel.World;
import hastabel.lang.*;
+
+ import java.util.Arrays;
+ import java.util.ArrayList;
+ import java.util.List;
}
@members
@@ -86,7 +92,7 @@ id_or_string_or_fun [Variable current_node]
}
else
{
- $value = WORLD.get_variables_manager().get_variable(($ID.text));
+ $value = WORLD.get_variables_manager().get(($ID.text));
if (($value) == null)
{
@@ -147,11 +153,11 @@ predicate [Variable current_node]
{
final Expression expression;
final List<Expression> ids;
- final Predicate predicate;
+ final hastabel.lang.Predicate predicate;
- predicate = WORLD.get_predicates_manager().get_predicate(($ID.text));
+ predicate = WORLD.get_predicates_manager().get(($ID.text));
- if (predicate == (Predicate) null)
+ if (predicate == (hastabel.lang.Predicate) null)
{
System.err.println
(
@@ -189,11 +195,11 @@ function [Variable current_node]
{
final Expression function_call;
final List<Expression> ids;
- final Predicate predicate;
+ final hastabel.lang.Predicate predicate;
- predicate = WORLD.get_predicates_manager().get_predicate(($ID.text));
+ predicate = WORLD.get_predicates_manager().get(($ID.text));
- if (predicate == (Predicate) null)
+ if (predicate == (hastabel.lang.Predicate) null)
{
System.err.println
(
@@ -243,11 +249,11 @@ regex_special_predicate [Variable current_node]
{
final Expression[] params;
- final Predicate string_matches;
+ final hastabel.lang.Predicate string_matches;
params = new Expression[2];
string_matches =
- WORLD.get_predicates_manager().get_predicate("string_matches");
+ WORLD.get_predicates_manager().get("string_matches");
if (string_matches == null)
{
@@ -375,7 +381,7 @@ variable_declaration
{
final Type t;
- t = WORLD.get_types_manager().get(($type.value));
+ t = WORLD.get_types_manager().get(($type.text));
if (t == (Type) null)
{
@@ -393,7 +399,7 @@ variable_declaration
WORLD.invalidate();
}
- $variable = WORLD.get_variables_manager().add_variable(t, ($var.value));
+ $variable = WORLD.get_variables_manager().add_variable(t, ($var.text));
if (($variable) == null)
{
@@ -558,7 +564,7 @@ ax_operator [Variable current_node]
(WS)* R_PAREN
{
- final Predicate node_connect;
+ final hastabel.lang.Predicate node_connect;
if (current_node == null)
{
@@ -625,7 +631,7 @@ ex_operator [Variable current_node]
(WS)* R_PAREN
{
- final Predicate node_connect;
+ final hastabel.lang.Predicate node_connect;
if (current_node == null)
{
@@ -693,7 +699,7 @@ ag_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final Predicate is_in_path, is_path_of;
+ final hastabel.lang.Predicate is_in_path, is_path_of;
if (current_node == null)
{
@@ -714,7 +720,7 @@ ag_operator [Variable current_node]
is_in_path = WORLD.get_predicates_manager().get("is_in_path");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- if ((path_type == null) || (is_path_of == null) || (node_connect == null))
+ if ((path_type == null) || (is_path_of == null) || (is_in_path == null))
{
WORLD.invalidate();
}
@@ -780,7 +786,7 @@ eg_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final Predicate is_in_path, is_path_of;
+ final hastabel.lang.Predicate is_in_path, is_path_of;
if (current_node == null)
{
@@ -801,7 +807,7 @@ eg_operator [Variable current_node]
is_in_path = WORLD.get_predicates_manager().get("is_in_path");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- if ((path_type == null) || (is_path_of == null) || (node_connect == null))
+ if ((path_type == null) || (is_path_of == null) || (is_in_path == null))
{
WORLD.invalidate();
}
@@ -867,7 +873,7 @@ af_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final Predicate is_in_path, is_path_of;
+ final hastabel.lang.Predicate is_in_path, is_path_of;
if (current_node == null)
{
@@ -888,7 +894,7 @@ af_operator [Variable current_node]
is_in_path = WORLD.get_predicates_manager().get("is_in_path");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- if ((path_type == null) || (is_path_of == null) || (node_connect == null))
+ if ((path_type == null) || (is_path_of == null) || (is_in_path == null))
{
WORLD.invalidate();
}
@@ -954,7 +960,7 @@ ef_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final Predicate is_in_path, is_path_of;
+ final hastabel.lang.Predicate is_in_path, is_path_of;
if (current_node == null)
{
@@ -975,7 +981,7 @@ ef_operator [Variable current_node]
is_in_path = WORLD.get_predicates_manager().get("is_in_path");
is_path_of = WORLD.get_predicates_manager().get("is_path_of");
- if ((path_type == null) || (is_path_of == null) || (node_connect == null))
+ if ((path_type == null) || (is_path_of == null) || (is_in_path == null))
{
WORLD.invalidate();
}
@@ -1045,7 +1051,7 @@ au_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final Predicate is_path_of, is_in_path, is_before;
+ final hastabel.lang.Predicate is_path_of, is_in_path, is_before;
if (current_node == null)
{
@@ -1152,7 +1158,7 @@ eu_operator [Variable current_node]
{
final Type path_type;
final Variable next_path;
- final Predicate is_path_of, is_in_path, is_before;
+ final hastabel.lang.Predicate is_path_of, is_in_path, is_before;
if (current_node == null)
{
@@ -1256,7 +1262,7 @@ depth_no_parent_operator [Variable current_node]
{
final Type path_type;
final Variable next_path, node_of_path;
- final Predicate depth, is_path_of, is_lower_than, is_in_path, is_before;
+ final hastabel.lang.Predicate depth, is_path_of, is_lower_than, is_in_path, is_before;
if (current_node == null)
{
@@ -1386,7 +1392,7 @@ depth_no_change_operator [Variable current_node]
{
final Type path_type;
final Variable next_path, node_of_path;
- final Predicate depth, is_path_of, is_in_path, is_before;
+ final hastabel.lang.Predicate depth, is_path_of, is_in_path, is_before;
if (current_node == null)
{
diff --git a/src/hastabel/Variables.java b/src/hastabel/Variables.java
index eb19bc7..0ec7aac 100644
--- a/src/hastabel/Variables.java
+++ b/src/hastabel/Variables.java
@@ -4,9 +4,6 @@ import hastabel.lang.Type;
import hastabel.lang.Variable;
import hastabel.lang.Expression;
-import java.io.BufferedWriter;
-import java.io.IOException;
-
import java.util.HashMap;
import java.util.Map;
@@ -22,7 +19,7 @@ public class Variables
seeked = new HashMap<String, Variable>();
}
- private String generate_new_anonymous_variable_name ()
+ private String new_anonymous_variable_name ()
{
final String result;
@@ -33,29 +30,30 @@ public class Variables
return result;
}
- public void seek (final Type type, final String var_name)
- throws Exception
+ public Variable seek (final Type type, final String var_name)
{
final Variable var;
var = add_variable(type, var_name);
seeked.put(var_name, var);
+
+ return var;
}
public Variable add_variable (final Type type, final String var_name)
- throws Exception
{
final Variable result;
if (from_string.containsKey(var_name))
{
- throw
- new Exception
- (
- "[F] Invalid property: the variable name \""
- + var_name
- + "\" is declared multiple times."
- );
+ System.err.println
+ (
+ "[E] Invalid property: the variable name \""
+ + var_name
+ + "\" is declared multiple times."
+ );
+
+ return null;
}
result = new Variable(type, var_name);
@@ -65,8 +63,7 @@ public class Variables
return result;
}
- public Variable get_variable (final String var_name)
- throws Exception
+ public Variable get (final String var_name)
{
final Variable result;
@@ -74,21 +71,21 @@ public class Variables
if (result == null)
{
- throw
- new Exception
- (
- "[F] Variable \""
- + var_name
- + "\" is used, but not declared."
- );
+ System.err.println
+ (
+ "[F] Variable \""
+ + var_name
+ + "\" is used, but not declared."
+ );
+
+ return null;
}
return result;
}
- public Variable generate_new_anonymous_variable (final Type t)
- throws Exception
+ public Variable new_anonymous_variable (final Type t)
{
- return add_variable(t, generate_new_anonymous_variable_name());
+ return add_variable(t, new_anonymous_variable_name());
}
}
diff --git a/src/hastabel/World.java b/src/hastabel/World.java
index 181828a..1664e8b 100644
--- a/src/hastabel/World.java
+++ b/src/hastabel/World.java
@@ -13,6 +13,7 @@ public class World extends LogicWorld
private final TemplateInstances template_inst_mgr;
private final Strings strings_mgr;
+ private final Variables variables_mgr;
private final Types types_mgr;
@@ -32,6 +33,7 @@ public class World extends LogicWorld
string_type = types_mgr.declare(null, "String");
strings_mgr = new Strings(string_type, this);
+ variables_mgr = new Variables();
is_erroneous = false;
}
@@ -81,4 +83,9 @@ public class World extends LogicWorld
{
return strings_mgr;
}
+
+ public Variables get_variables_manager ()
+ {
+ return variables_mgr;
+ }
}
diff --git a/src/hastabel/lang/Element.java b/src/hastabel/lang/Element.java
index f69fca1..d330d7e 100644
--- a/src/hastabel/lang/Element.java
+++ b/src/hastabel/lang/Element.java
@@ -1,6 +1,6 @@
package hastabel.lang;
-public class Element extends Expression
+public class Element extends NamedExpression
{
public Element (final Type type, final String name)
{
diff --git a/src/hastabel/lang/Expression.java b/src/hastabel/lang/Expression.java
index 3e48426..9594864 100644
--- a/src/hastabel/lang/Expression.java
+++ b/src/hastabel/lang/Expression.java
@@ -2,49 +2,4 @@ package hastabel.lang;
public abstract class Expression
{
- public final Type type;
- public final String name;
-
- public Expression (final Type type, final String name)
- {
- this.type = type;
- this.name = name;
- }
-
- public String get_name ()
- {
- return name;
- }
-
- public Type get_type ()
- {
- return type;
- }
-
- @Override
- public boolean equals (Object o)
- {
- final Expression e;
-
- if ((o == null) || !(o instanceof Expression))
- {
- return false;
- }
-
- e = (Expression) o;
-
- return (e.name.equals(name) && e.type.equals(type));
- }
-
- @Override
- public int hashCode ()
- {
- return (name + '@' + type.get_name()).hashCode();
- }
-
- @Override
- public String toString ()
- {
- return (type.get_name() + " " + name);
- }
}
diff --git a/src/hastabel/lang/FunctionCall.java b/src/hastabel/lang/FunctionCall.java
index 6db5502..464ed57 100644
--- a/src/hastabel/lang/FunctionCall.java
+++ b/src/hastabel/lang/FunctionCall.java
@@ -13,6 +13,7 @@ class FunctionCall extends Expression
final List<Expression> params
)
{
+ super();
this.parent = parent;
this.params = params;
}
diff --git a/src/hastabel/lang/NamedExpression.java b/src/hastabel/lang/NamedExpression.java
new file mode 100644
index 0000000..fec810f
--- /dev/null
+++ b/src/hastabel/lang/NamedExpression.java
@@ -0,0 +1,50 @@
+package hastabel.lang;
+
+abstract class NamedExpression extends Expression
+{
+ public final Type type;
+ public final String name;
+
+ public NamedExpression (final Type type, final String name)
+ {
+ this.type = type;
+ this.name = name;
+ }
+
+ public String get_name ()
+ {
+ return name;
+ }
+
+ public Type get_type ()
+ {
+ return type;
+ }
+
+ @Override
+ public boolean equals (Object o)
+ {
+ final NamedExpression e;
+
+ if ((o == null) || !(o instanceof NamedExpression))
+ {
+ return false;
+ }
+
+ e = (NamedExpression) o;
+
+ return (e.name.equals(name) && e.type.equals(type));
+ }
+
+ @Override
+ public int hashCode ()
+ {
+ return (name + '@' + type.get_name()).hashCode();
+ }
+
+ @Override
+ public String toString ()
+ {
+ return (type.get_name() + " " + name);
+ }
+}
diff --git a/src/hastabel/lang/Operator.java b/src/hastabel/lang/Operator.java
index 2351656..795791e 100644
--- a/src/hastabel/lang/Operator.java
+++ b/src/hastabel/lang/Operator.java
@@ -1,6 +1,7 @@
package hastabel.lang;
import java.util.List;
+import java.util.ArrayList;
public enum Operator
{
diff --git a/src/hastabel/lang/Predicate.java b/src/hastabel/lang/Predicate.java
index 8535985..cf0b1ac 100644
--- a/src/hastabel/lang/Predicate.java
+++ b/src/hastabel/lang/Predicate.java
@@ -185,7 +185,7 @@ public class Predicate
return result;
}
- public Formula as_function_ (final Expression... e_params)
+ public Expression as_function_ (final Expression... e_params)
{
final ArrayList<Expression> params;
diff --git a/src/hastabel/lang/Quantifier.java b/src/hastabel/lang/Quantifier.java
index 4734be5..aa05ebe 100644
--- a/src/hastabel/lang/Quantifier.java
+++ b/src/hastabel/lang/Quantifier.java
@@ -12,7 +12,7 @@ public class Quantifier extends Formula
(
final Variable parent,
final Formula formula,
- final boolean is_forall;
+ final boolean is_forall
)
{
this.parent = parent;
diff --git a/src/hastabel/lang/Variable.java b/src/hastabel/lang/Variable.java
index 9df0d4f..a61025b 100644
--- a/src/hastabel/lang/Variable.java
+++ b/src/hastabel/lang/Variable.java
@@ -1,6 +1,6 @@
package hastabel.lang;
-public class Variable extends Expression
+public class Variable extends NamedExpression
{
public Variable (final Type type, final String name)
{