|
From: <jom...@us...> - 2008-03-20 08:56:49
|
Revision: 1167
http://jason.svn.sourceforge.net/jason/?rev=1167&view=rev
Author: jomifred
Date: 2008-03-20 01:56:41 -0700 (Thu, 20 Mar 2008)
Log Message:
-----------
fix bug related to plan's TE being an Atom
Modified Paths:
--------------
trunk/src/jason/asSyntax/Atom.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
Modified: trunk/src/jason/asSyntax/Atom.java
===================================================================
--- trunk/src/jason/asSyntax/Atom.java 2008-03-19 17:50:11 UTC (rev 1166)
+++ trunk/src/jason/asSyntax/Atom.java 2008-03-20 08:56:41 UTC (rev 1167)
@@ -142,6 +142,12 @@
return super.addAnnot(t);
}
+ @Override
+ public void addAnnots(List<Term> l) {
+ logger.log(Level.SEVERE, "You should not add annots '"+l+"' in atom "+this+"\n",new Exception());
+ super.addAnnots(l);
+ }
+
@Override public void makeTermsAnnon() { }
@Override public void makeVarsAnnon() { }
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-03-19 17:50:11 UTC (rev 1166)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-03-20 08:56:41 UTC (rev 1167)
@@ -310,7 +310,10 @@
( F=literal()
| F=var()
- ) { return new Trigger(teOp,teType,F); }
+ ) { if (F instanceof Atom)
+ F = new Literal(F.getFunctor()); // trigger literal must be a literal and not an atom
+ return new Trigger(teOp,teType,F);
+ }
}
/* Literal */
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2008-03-19 17:50:11 UTC (rev 1166)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2008-03-20 08:56:41 UTC (rev 1167)
@@ -406,6 +406,8 @@
jj_consume_token(-1);
throw new ParseException();
}
+ if (F instanceof Atom)
+ F = new Literal(F.getFunctor()); // trigger literal must be a literal and not an atom
{if (true) return new Trigger(teOp,teType,F);}
throw new Error("Missing return statement in function");
}
@@ -1166,28 +1168,6 @@
finally { jj_save(1, xla); }
}
- final private boolean jj_3R_19() {
- if (jj_scan_token(39)) return true;
- if (jj_3R_25()) return true;
- if (jj_scan_token(40)) return true;
- return false;
- }
-
- final private boolean jj_3R_18() {
- if (jj_3R_24()) return true;
- return false;
- }
-
- final private boolean jj_3R_17() {
- if (jj_3R_23()) return true;
- return false;
- }
-
- final private boolean jj_3R_22() {
- if (jj_scan_token(34)) return true;
- return false;
- }
-
final private boolean jj_3R_71() {
if (jj_scan_token(TK_INTMOD)) return true;
return false;
@@ -1667,6 +1647,28 @@
return false;
}
+ final private boolean jj_3R_19() {
+ if (jj_scan_token(39)) return true;
+ if (jj_3R_25()) return true;
+ if (jj_scan_token(40)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_18() {
+ if (jj_3R_24()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_17() {
+ if (jj_3R_23()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_22() {
+ if (jj_scan_token(34)) return true;
+ return false;
+ }
+
public as2jTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-03-31 21:10:55
|
Revision: 1184
http://jason.svn.sourceforge.net/jason/?rev=1184&view=rev
Author: jomifred
Date: 2008-03-31 14:10:53 -0700 (Mon, 31 Mar 2008)
Log Message:
-----------
add PlanBody* classes in svn
Modified Paths:
--------------
trunk/src/jason/asSyntax/BodyLiteral.java
Added Paths:
-----------
trunk/src/jason/asSyntax/PlanBody.java
trunk/src/jason/asSyntax/PlanBodyImpl.java
Modified: trunk/src/jason/asSyntax/BodyLiteral.java
===================================================================
--- trunk/src/jason/asSyntax/BodyLiteral.java 2008-03-31 20:04:20 UTC (rev 1183)
+++ trunk/src/jason/asSyntax/BodyLiteral.java 2008-03-31 21:10:53 UTC (rev 1184)
@@ -25,7 +25,6 @@
}
private static PlanBody.BodyType oldToNew(BodyType old) {
- // TODO: implement it!
switch (old) {
case action: return PlanBody.BodyType.action;
case internalAction: return PlanBody.BodyType.internalAction;
Added: trunk/src/jason/asSyntax/PlanBody.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBody.java (rev 0)
+++ trunk/src/jason/asSyntax/PlanBody.java 2008-03-31 21:10:53 UTC (rev 1184)
@@ -0,0 +1,33 @@
+package jason.asSyntax;
+
+public interface PlanBody extends Term {
+
+ public enum BodyType {
+ none { public String toString() { return ""; }},
+ action { public String toString() { return ""; }},
+ internalAction { public String toString() { return ""; }},
+ achieve { public String toString() { return "!"; }},
+ test { public String toString() { return "?"; }},
+ addBel { public String toString() { return "+"; }},
+ delBel { public String toString() { return "-"; }},
+ delAddBel { public String toString() { return "-+"; }},
+ achieveNF { public String toString() { return "!!"; }},
+ constraint { public String toString() { return ""; }}
+ }
+
+ public BodyType getBodyType();
+ public Term getBodyTerm();
+ public PlanBody getBodyNext();
+
+ public boolean isEmptyBody();
+ public int getPlanSize();
+
+ public void setBodyType(BodyType bt);
+ public void setBodyTerm(Term t);
+ public void setBodyNext(PlanBody bl);
+
+
+ public boolean add(PlanBody bl);
+ public boolean add(int index, PlanBody bl);
+ public Term removeBody(int index);
+}
\ No newline at end of file
Added: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java (rev 0)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-03-31 21:10:53 UTC (rev 1184)
@@ -0,0 +1,236 @@
+package jason.asSyntax;
+
+import jason.asSemantics.Unifier;
+
+import java.util.Iterator;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Represents a plan body item (achieve, test, action, ...) and its successors.
+ *
+ * A plan body like <code>a1; ?t; !g</code> is represented by the following structure
+ * <code>(a1, (?t, (!g)))</code>.
+ *
+ * @author Jomi
+ */
+public class PlanBodyImpl extends Structure implements PlanBody, Iterable<PlanBody> {
+
+ public static final String BODY_PLAN_FUNCTOR = ";";
+
+ private Term term = null;
+ private PlanBody next = null;
+ private BodyType formType = BodyType.none;
+
+ /** constructor for empty plan body */
+ public PlanBodyImpl() {
+ super(BODY_PLAN_FUNCTOR, 0);
+ }
+
+ public PlanBodyImpl(BodyType t, Term b) {
+ super(BODY_PLAN_FUNCTOR, 0);
+ term = b;
+ formType = t;
+ setSrc(b);
+ }
+
+ public void setBodyNext(PlanBody next) {
+ this.next = next;
+ }
+ public PlanBody getBodyNext() {
+ return next;
+ }
+
+ public boolean isEmptyBody() {
+ return term == null;
+ }
+
+ public BodyType getBodyType() {
+ return formType;
+ }
+ public void setBodyType(BodyType bt) {
+ formType = bt;
+ }
+
+ public Term getBodyTerm() {
+ return term;
+ }
+ public void setBodyTerm(Term t) {
+ term = t;
+ }
+
+ @Override
+ public boolean isPlanBody() {
+ return true;
+ }
+
+ public Iterator<PlanBody> iterator() {
+ return new Iterator<PlanBody>() {
+ PlanBody current = PlanBodyImpl.this;
+ public boolean hasNext() {
+ return current != null && current.getBodyTerm() != null;
+ }
+ public PlanBody next() {
+ PlanBody r = current;
+ if (current != null)
+ current = current.getBodyNext();
+ return r;
+ }
+ public void remove() { }
+ };
+ }
+
+ // Override some structure methods to work with unification/equals
+ @Override
+ public int getArity() {
+ if (term == null)
+ return 0;
+ else if (next == null)
+ return 1;
+ else
+ return 2;
+ }
+
+ @Override
+ public Term getTerm(int i) {
+ if (i == 0)
+ return term;
+ if (i == 1) {
+ if (next != null && next.getBodyTerm().isVar() && next.getBodyNext() == null)
+ // if next is the last VAR, return that var
+ return next.getBodyTerm();
+ else
+ return next;
+ }
+ return null;
+ }
+
+ @Override
+ public void setTerm(int i, Term t) {
+ if (i == 0) term = t;
+ if (i == 1) System.out.println("Should not set next of body literal!");
+ }
+
+ @Override
+ public boolean apply(Unifier u) {
+ // do not apply in next!
+ resetHashCodeCache();
+ if (term != null && term.apply(u)) {
+ if (term.isPlanBody()) { // we can not have "inner" body literals
+ formType = ((PlanBody)term).getBodyType();
+ term = ((PlanBody)term).getBodyTerm();
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (o == this) return true;
+
+ if (o instanceof PlanBody) {
+ PlanBody b = (PlanBody)o;
+ return formType == b.getBodyType() && super.equals(o);
+ }
+ return false;
+ }
+
+ @Override
+ public int calcHashCode() {
+ return formType.hashCode() + super.calcHashCode();
+ }
+
+ public boolean add(PlanBody bl) {
+ if (term == null)
+ swap(bl);
+ else if (next == null)
+ next = bl;
+ else
+ next.add(bl);
+ return true;
+ }
+
+ public boolean add(int index, PlanBody bl) {
+ if (index == 0) {
+ swap(bl);
+ this.next = bl;
+ } else {
+ next.add(index - 1, bl);
+ }
+ return true;
+ }
+
+ public Term removeBody(int index) {
+ if (index == 0) {
+ if (next == null) {
+ term = null; // becomes an empty
+ } else {
+ Term oldvalue = term;
+ swap(next); // get values of text
+ next = next.getBodyNext();
+ return oldvalue;
+ }
+ return this;
+ } else {
+ return next.removeBody(index - 1);
+ }
+ }
+
+ public int getPlanSize() {
+ if (term == null)
+ return 0;
+ else if (next == null)
+ return 1;
+ else
+ return next.getPlanSize() + 1;
+ }
+
+ private void swap(PlanBody bl) {
+ BodyType bt = this.formType;
+ this.formType = bl.getBodyType();
+ bl.setBodyType(bt);
+
+ Term l = this.term;
+ this.term = bl.getBodyTerm();
+ bl.setBodyTerm(l);
+ }
+
+ public Object clone() {
+ if (term == null) // empty
+ return new PlanBodyImpl();
+
+ PlanBodyImpl c = new PlanBodyImpl(formType, (Term)term.clone());
+ if (next != null)
+ c.setBodyNext((PlanBody)getBodyNext().clone());
+ return c;
+ }
+
+ public String toString() {
+ if (term == null)
+ return "";
+ else if (next == null)
+ return formType.toString() + term;
+ else
+ return formType.toString() + term + "; " + next;
+ }
+
+ /** get as XML */
+ public Element getAsDOM(Document document) {
+ Element eb = (Element) document.createElement("body");
+ PlanBody bl = this;
+ while (bl != null && !bl.isEmptyBody()) {
+ Element u = (Element) document.createElement("body-literal");
+ if (bl.getBodyType().toString().length() > 0) {
+ u.setAttribute("type", bl.getBodyType().toString());
+ }
+ u.appendChild( ((Structure)bl.getBodyTerm()).getAsDOM(document));
+ eb.appendChild(u);
+
+ bl = bl.getBodyNext();
+ }
+ return eb;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|