You can subscribe to this list here.
| 2008 |
Jan
|
Feb
|
Mar
(35) |
Apr
(96) |
May
(39) |
Jun
(25) |
Jul
(7) |
Aug
(7) |
Sep
(44) |
Oct
(17) |
Nov
(14) |
Dec
(9) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2009 |
Jan
(5) |
Feb
(28) |
Mar
(26) |
Apr
(14) |
May
(3) |
Jun
(3) |
Jul
(13) |
Aug
(41) |
Sep
(12) |
Oct
|
Nov
(2) |
Dec
(17) |
| 2010 |
Jan
(9) |
Feb
(5) |
Mar
(11) |
Apr
(3) |
May
(4) |
Jun
(2) |
Jul
(3) |
Aug
(8) |
Sep
(2) |
Oct
(11) |
Nov
(3) |
Dec
(1) |
| 2011 |
Jan
|
Feb
(1) |
Mar
(8) |
Apr
(4) |
May
(4) |
Jun
(5) |
Jul
(3) |
Aug
(2) |
Sep
(7) |
Oct
(4) |
Nov
(4) |
Dec
(2) |
| 2012 |
Jan
|
Feb
|
Mar
(4) |
Apr
(11) |
May
(8) |
Jun
(2) |
Jul
(7) |
Aug
(6) |
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(3) |
| 2013 |
Jan
|
Feb
(1) |
Mar
(7) |
Apr
(3) |
May
(1) |
Jun
(4) |
Jul
(8) |
Aug
(4) |
Sep
(4) |
Oct
(6) |
Nov
(8) |
Dec
(6) |
| 2014 |
Jan
|
Feb
|
Mar
(2) |
Apr
(4) |
May
(6) |
Jun
(10) |
Jul
|
Aug
(7) |
Sep
(15) |
Oct
(4) |
Nov
(1) |
Dec
(1) |
| 2015 |
Jan
|
Feb
(1) |
Mar
(10) |
Apr
(4) |
May
(6) |
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(2) |
Oct
(5) |
Nov
(6) |
Dec
(12) |
| 2016 |
Jan
(1) |
Feb
(4) |
Mar
(7) |
Apr
(30) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <jom...@us...> - 2016-04-09 11:44:32
|
Revision: 1890
http://sourceforge.net/p/jason/svn/1890
Author: jomifred
Date: 2016-04-09 11:44:30 +0000 (Sat, 09 Apr 2016)
Log Message:
-----------
remove platform dependent classes from architecture package
Modified Paths:
--------------
trunk/src/jason/architecture/MindInspectorWeb.java
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/infra/jade/RunJadeMAS.java
trunk/src/jason/util/Config.java
Added Paths:
-----------
trunk/src/jason/architecture/MindInspectorWebImpl.java
Modified: trunk/src/jason/architecture/MindInspectorWeb.java
===================================================================
--- trunk/src/jason/architecture/MindInspectorWeb.java 2016-04-09 10:45:24 UTC (rev 1889)
+++ trunk/src/jason/architecture/MindInspectorWeb.java 2016-04-09 11:44:30 UTC (rev 1890)
@@ -1,52 +1,26 @@
package jason.architecture;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.net.BindException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.concurrent.Executors;
-
import org.w3c.dom.Document;
-import com.sun.net.httpserver.Headers;
-import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import com.sun.net.httpserver.HttpServer;
-
import jason.asSemantics.Agent;
-import jason.runtime.Settings;
import jason.util.Config;
-import jason.util.asl2html;
-import jason.util.asl2xml;
-public class MindInspectorWeb {
+public abstract class MindInspectorWeb {
private static MindInspectorWeb singleton = null;
- private HttpServer httpServer = null;
- private String httpServerURL = "http://localhost:3272";
- private int httpServerPort = 3272;
- private int refreshInterval = 5;
+ protected String httpServerURL = "http://localhost:3272";
+ protected int httpServerPort = 3272;
+ protected int refreshInterval = 5;
- //private Map<String,Boolean> agHasHistory = new HashMap<String, Boolean>();
- private Map<String,List<Document>> histories = new TreeMap<String,List<Document>>();
- private Map<String,Integer> lastStepSeenByUser = new HashMap<String, Integer>();
- private Map<String,Agent> registeredAgents = new HashMap<String, Agent>();
-
public static synchronized MindInspectorWeb get() {
if (singleton == null) {
- singleton = new MindInspectorWeb();
- singleton.startHttpServer();
- singleton.registerRootBrowserView();
- singleton.registerAgentsBrowserView();
- singleton.registerAgView("no_ag");
+ try {
+ singleton = (MindInspectorWeb) Class.forName( Config.get().getMindInspectorWebServerClassName()).newInstance();
+ singleton.startHttpServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
return singleton;
}
@@ -62,316 +36,12 @@
return null;
}
- private MindInspectorWeb() {
- }
-
- private synchronized String startHttpServer() {
- if (httpServer == null) {
- try {
- httpServer = HttpServer.create(new InetSocketAddress(httpServerPort), 0);
- httpServer.setExecutor(Executors.newCachedThreadPool());
+ public abstract String startHttpServer();
- httpServer.start();
- httpServerURL = "http://"+InetAddress.getLocalHost().getHostAddress()+":"+httpServerPort;
- System.out.println("Jason Http Server running on "+httpServerURL);
- } catch (BindException e) {
- httpServerPort++;
- return startHttpServer();
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- return httpServerURL;
- }
-
- private void registerRootBrowserView() {
- if (httpServer == null)
- return;
- try {
- httpServer.createContext("/", new HttpHandler() {
- public void handle(HttpExchange exchange) throws IOException {
- String requestMethod = exchange.getRequestMethod();
- Headers responseHeaders = exchange.getResponseHeaders();
- responseHeaders.set("Content-Type", "text/html");
- exchange.sendResponseHeaders(200, 0);
- OutputStream responseBody = exchange.getResponseBody();
-
- if (requestMethod.equalsIgnoreCase("GET")) {
- String path = exchange.getRequestURI().getPath();
- StringWriter so = new StringWriter();
-
- if (path.length() < 2) { // it is the root
- so.append("<html><head><title>Jason Mind Inspector -- Web View</title></head><body>");
- so.append("<iframe width=\"20%\" height=\"100%\" align=left src=\"/agents\" border=5 frameborder=0 ></iframe>");
- so.append("<iframe width=\"78%\" height=\"100%\" align=left src=\"/agent-mind/no_ag\" name=\"am\" border=5 frameborder=0></iframe>");
- so.append("</body></html>");
- } else if (path.indexOf("agent-mind") >= 0) {
- if (tryToIncludeMindInspectorForAg(path))
- so.append("<meta http-equiv=\"refresh\" content=0>");
- else
- so.append("unkown agent!");
- }
- responseBody.write(so.toString().getBytes());
- }
- responseBody.close();
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private String getAgNameFromPath(String path) {
- int nameStart = path.indexOf("agent-mind");
- if (nameStart < 0) return null;
- nameStart += "agent-mind".length() + 1;
- int nameEnd = path.indexOf("/",nameStart+1);
- if (nameEnd >= 0)
- return path.substring(nameStart,nameEnd).trim();
- else
- return path.substring(nameStart).trim();
- }
-
- private boolean tryToIncludeMindInspectorForAg(String path) {
- try {
- Agent ag = registeredAgents.get(getAgNameFromPath(path));
- if (ag != null) {
- AgArch arch = ag.getTS().getUserAgArch();
- if (arch != null) {
- // should add a new conf for mindinspector, otherwise will start a new gui for the agent
- arch.getTS().getSettings().addOption(Settings.MIND_INSPECTOR,"web(cycle,html,no_history)");
- MindInspectorAgArch miArch = new MindInspectorAgArch();
- arch.insertAgArch(miArch);
- miArch.init();
- miArch.addAgState();
- return true;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
-
- private void registerAgentsBrowserView() {
- if (httpServer == null)
- return;
- try {
- httpServer.createContext("/agents", new HttpHandler() {
- public void handle(HttpExchange exchange) throws IOException {
- String requestMethod = exchange.getRequestMethod();
- Headers responseHeaders = exchange.getResponseHeaders();
- responseHeaders.set("Content-Type", "text/html");
- exchange.sendResponseHeaders(200, 0);
- OutputStream responseBody = exchange.getResponseBody();
-
- if (requestMethod.equalsIgnoreCase("GET")) {
- responseBody.write(("<html><head><title>Jason (list of agents)</title><meta http-equiv=\"refresh\" content=\""+refreshInterval+"\" ></head><body>").getBytes());
- responseBody.write(("<font size=\"+2\"><p style='color: red; font-family: arial;'>Agents</p></font>").getBytes());
- for (String a: histories.keySet()) {
- responseBody.write( ("- <a href=\"/agent-mind/"+a+"/latest\" target=\"am\" style=\"font-family: arial; text-decoration: none\">"+a+"</a><br/>").getBytes());
- }
- }
- responseBody.write("<hr/>by <a href=\"http://jason.sf.net\" target=\"_blank\">Jason</a>".getBytes());
- responseBody.write("</body></html>".getBytes());
- responseBody.close();
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
/** add the agent in the list of available agent for mind inspection */
- public synchronized void registerAg(Agent ag) {
- String agName = ag.getTS().getUserAgArch().getAgName();
- if (!agName.equals("no-named")) {
- registeredAgents.put(agName, ag);
- histories.put(agName, new ArrayList<Document>()); // just for the agent name to appear in the list of agents
- }
- }
+ public abstract void registerAg(Agent ag);
- public synchronized void removeAg(Agent ag) {
- String agName = ag.getTS().getUserAgArch().getAgName();
- registeredAgents.remove(agName);
- histories.remove(agName);
- }
+ public abstract void removeAg(Agent ag);
+ public abstract void addAgState(Agent ag, Document mind, boolean hasHistory);
- public synchronized void addAgState(Agent ag, Document mind, boolean hasHistory) {
- String agName = ag.getTS().getUserAgArch().getAgName();
- List<Document> h = histories.get(agName);
- if (h == null) {
- h = new ArrayList<Document>();
- histories.put(agName, h);
- }
- if (h.isEmpty())
- registerAgView(agName); // the first time a state is added for the agent, register in the browser
- if (hasHistory || h.isEmpty())
- h.add(mind);
- else
- h.set(0, mind);
- }
-
- String registerAgView(final String agName) {
- if (httpServer == null)
- return null;
- try {
- String url = "/agent-mind/"+agName;
- httpServer.createContext(url, new HttpHandler() {
- public void handle(HttpExchange exchange) throws IOException {
- String requestMethod = exchange.getRequestMethod();
- Headers responseHeaders = exchange.getResponseHeaders();
- exchange.sendResponseHeaders(200, 0);
- OutputStream responseBody = exchange.getResponseBody();
- responseHeaders.set("Content-Type", "text/html");
-
- if (requestMethod.equalsIgnoreCase("GET")) {
- try {
- StringWriter so = new StringWriter();
- so.append("<html><head><title>"+agName+"</title>");
-
- // test if the url is for this agent
- String path = exchange.getRequestURI().getPath();
- if (!getAgNameFromPath(path).equals(agName)) {
- if (tryToIncludeMindInspectorForAg(path))
- so.append("<meta http-equiv=\"refresh\" content=0>");
- else
- so.append("unkown agent!");
- } else {
-
- List<Document> h = histories.get(agName);
- if (h != null && h.size() > 0) {
- Document agState;
- int i = -1;
- exchange.getRemoteAddress();
-
- String query = exchange.getRequestURI().getRawQuery(); // what follows ?
- String remote = exchange.getRemoteAddress().toString();
-
- if (path.endsWith("hide")) {
- show.put(query,false);
- Integer ii = lastStepSeenByUser.get(remote);
- if (ii != null)
- i = ii;
- } else if (path.endsWith("show")) {
- show.put(query,true);
- Integer ii = lastStepSeenByUser.get(remote);
- if (ii != null)
- i = ii;
- } else if (path.endsWith("clear")) {
- agState = h.get(h.size()-1);
- h.clear();
- h.add(agState);
- } else {
- // see if ends with a number
- try {
- int pos = path.lastIndexOf("/");
- String n = path.substring(pos+1).trim();
- i = new Integer(n);
- } catch (Exception e) {}
- }
- if (i == -1) {
- so.append("<meta http-equiv=\"refresh\" content=\""+refreshInterval+"\">");
- agState = h.get(h.size()-1);
- } else {
- agState = h.get(i-1);
- }
- try {
- lastStepSeenByUser.put(remote, i);
- } catch (Exception e) {
- e.printStackTrace();
- }
- so.append("</head><body>");
- if (h.size() > 1) {
- //so.append("history: ");
- so.append("<a href=/agent-mind/"+agName+"/latest>latest state</a> ");
- for (i=h.size()-1; i>0; i--) {
- so.append("<a href=\"/agent-mind/"+agName+"/"+i+"\" style=\"text-decoration: none\">"+i+"</a> ");
- }
- so.append("<a href=\"/agent-mind/"+agName+"/clear\">clear history</a> ");
- so.append("<hr/>");
- }
- so.append(getAgStateAsString(agState, false));
- //so.append("<hr/><a href=\"/\"> list of agents</a> ");
- } else {
- so.append("select an agent");
- }
- }
- responseBody.write(so.toString().getBytes());
-
- //responseBody.write(("<br/><a href=/agent-code/"+agName+">code</a>").getBytes());
- responseBody.write("</body></html>".getBytes());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- responseBody.close();
- }
- });
- return httpServerURL+url;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /*
- String registerAgCodeBrowserView(String agId, final String agCode) {
- if (httpServer == null)
- return null;
- try {
- String url="/agent-code/"+agId;
- httpServer.createContext(url, new HttpHandler() {
- public void handle(HttpExchange exchange) throws IOException {
- String requestMethod = exchange.getRequestMethod();
- Headers responseHeaders = exchange.getResponseHeaders();
- responseHeaders.set("Content-Type", "text/html");
- exchange.sendResponseHeaders(200, 0);
- OutputStream responseBody = exchange.getResponseBody();
-
- if (requestMethod.equalsIgnoreCase("GET")) {
- responseBody.write(agCode.getBytes());
- }
- responseBody.close();
- }
- });
- return httpServerURL+url;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- */
-
- protected asl2xml mindInspectorTransformer = null;
- Map<String,Boolean> show = new HashMap<String,Boolean>();
-
- synchronized String getAgStateAsString(Document ag, boolean full) { // full means with show all
- try {
- if (mindInspectorTransformer == null) {
- mindInspectorTransformer = new asl2html("/xml/agInspection.xsl");
-
- show.put("bels", true);
- show.put("annots", Config.get().getBoolean(Config.SHOW_ANNOTS));
- show.put("rules", false);
- show.put("evt", true);
- show.put("mb", false);
- show.put("int", false);
- show.put("int-details", false);
- show.put("plan", false);
- show.put("plan-details", false);
- }
- for (String p: show.keySet())
- if (full)
- mindInspectorTransformer.setParameter("show-"+p, "true");
- else
- mindInspectorTransformer.setParameter("show-"+p, show.get(p)+"");
- return mindInspectorTransformer.transform(ag); // transform to HTML
- } catch (Exception e) {
- e.printStackTrace();
- return "Error XML transformation (MindInspector)";
- }
- }
-
}
Added: trunk/src/jason/architecture/MindInspectorWebImpl.java
===================================================================
--- trunk/src/jason/architecture/MindInspectorWebImpl.java (rev 0)
+++ trunk/src/jason/architecture/MindInspectorWebImpl.java 2016-04-09 11:44:30 UTC (rev 1890)
@@ -0,0 +1,351 @@
+package jason.architecture;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.net.BindException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.Executors;
+
+import org.w3c.dom.Document;
+
+import com.sun.net.httpserver.Headers;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
+import jason.asSemantics.Agent;
+import jason.runtime.Settings;
+import jason.util.Config;
+import jason.util.asl2html;
+import jason.util.asl2xml;
+
+public class MindInspectorWebImpl extends MindInspectorWeb {
+
+ private HttpServer httpServer = null;
+
+ private Map<String,List<Document>> histories = new TreeMap<String,List<Document>>();
+ private Map<String,Integer> lastStepSeenByUser = new HashMap<String, Integer>();
+ private Map<String,Agent> registeredAgents = new HashMap<String, Agent>();
+
+ public MindInspectorWebImpl() {
+ }
+
+ public synchronized String startHttpServer() {
+ try {
+ httpServer = HttpServer.create(new InetSocketAddress(httpServerPort), 0);
+ httpServer.setExecutor(Executors.newCachedThreadPool());
+
+ httpServer.start();
+ httpServerURL = "http://"+InetAddress.getLocalHost().getHostAddress()+":"+httpServerPort;
+ System.out.println("Jason Http Server running on "+httpServerURL);
+ registerRootBrowserView();
+ registerAgentsBrowserView();
+ registerAgView("no_ag");
+
+ return httpServerURL;
+ } catch (BindException e) {
+ httpServerPort++;
+ return startHttpServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private void registerRootBrowserView() {
+ if (httpServer == null)
+ return;
+ try {
+ httpServer.createContext("/", new HttpHandler() {
+ public void handle(HttpExchange exchange) throws IOException {
+ String requestMethod = exchange.getRequestMethod();
+ Headers responseHeaders = exchange.getResponseHeaders();
+ responseHeaders.set("Content-Type", "text/html");
+ exchange.sendResponseHeaders(200, 0);
+ OutputStream responseBody = exchange.getResponseBody();
+
+ if (requestMethod.equalsIgnoreCase("GET")) {
+ String path = exchange.getRequestURI().getPath();
+ StringWriter so = new StringWriter();
+
+ if (path.length() < 2) { // it is the root
+ so.append("<html><head><title>Jason Mind Inspector -- Web View</title></head><body>");
+ so.append("<iframe width=\"20%\" height=\"100%\" align=left src=\"/agents\" border=5 frameborder=0 ></iframe>");
+ so.append("<iframe width=\"78%\" height=\"100%\" align=left src=\"/agent-mind/no_ag\" name=\"am\" border=5 frameborder=0></iframe>");
+ so.append("</body></html>");
+ } else if (path.indexOf("agent-mind") >= 0) {
+ if (tryToIncludeMindInspectorForAg(path))
+ so.append("<meta http-equiv=\"refresh\" content=0>");
+ else
+ so.append("unkown agent!");
+ }
+ responseBody.write(so.toString().getBytes());
+ }
+ responseBody.close();
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private String getAgNameFromPath(String path) {
+ int nameStart = path.indexOf("agent-mind");
+ if (nameStart < 0) return null;
+ nameStart += "agent-mind".length() + 1;
+ int nameEnd = path.indexOf("/",nameStart+1);
+ if (nameEnd >= 0)
+ return path.substring(nameStart,nameEnd).trim();
+ else
+ return path.substring(nameStart).trim();
+ }
+
+ private boolean tryToIncludeMindInspectorForAg(String path) {
+ try {
+ Agent ag = registeredAgents.get(getAgNameFromPath(path));
+ if (ag != null) {
+ AgArch arch = ag.getTS().getUserAgArch();
+ if (arch != null) {
+ // should add a new conf for mindinspector, otherwise will start a new gui for the agent
+ arch.getTS().getSettings().addOption(Settings.MIND_INSPECTOR,"web(cycle,html,no_history)");
+ MindInspectorAgArch miArch = new MindInspectorAgArch();
+ arch.insertAgArch(miArch);
+ miArch.init();
+ miArch.addAgState();
+ return true;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ private void registerAgentsBrowserView() {
+ if (httpServer == null)
+ return;
+ try {
+ httpServer.createContext("/agents", new HttpHandler() {
+ public void handle(HttpExchange exchange) throws IOException {
+ String requestMethod = exchange.getRequestMethod();
+ Headers responseHeaders = exchange.getResponseHeaders();
+ responseHeaders.set("Content-Type", "text/html");
+ exchange.sendResponseHeaders(200, 0);
+ OutputStream responseBody = exchange.getResponseBody();
+
+ if (requestMethod.equalsIgnoreCase("GET")) {
+ responseBody.write(("<html><head><title>Jason (list of agents)</title><meta http-equiv=\"refresh\" content=\""+refreshInterval+"\" ></head><body>").getBytes());
+ responseBody.write(("<font size=\"+2\"><p style='color: red; font-family: arial;'>Agents</p></font>").getBytes());
+ for (String a: histories.keySet()) {
+ responseBody.write( ("- <a href=\"/agent-mind/"+a+"/latest\" target=\"am\" style=\"font-family: arial; text-decoration: none\">"+a+"</a><br/>").getBytes());
+ }
+ }
+ responseBody.write("<hr/>by <a href=\"http://jason.sf.net\" target=\"_blank\">Jason</a>".getBytes());
+ responseBody.write("</body></html>".getBytes());
+ responseBody.close();
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /** add the agent in the list of available agent for mind inspection */
+ public synchronized void registerAg(Agent ag) {
+ String agName = ag.getTS().getUserAgArch().getAgName();
+ if (!agName.equals("no-named")) {
+ registeredAgents.put(agName, ag);
+ histories.put(agName, new ArrayList<Document>()); // just for the agent name to appear in the list of agents
+ }
+ }
+
+ public synchronized void removeAg(Agent ag) {
+ String agName = ag.getTS().getUserAgArch().getAgName();
+ registeredAgents.remove(agName);
+ histories.remove(agName);
+ }
+
+ public synchronized void addAgState(Agent ag, Document mind, boolean hasHistory) {
+ String agName = ag.getTS().getUserAgArch().getAgName();
+ List<Document> h = histories.get(agName);
+ if (h == null) {
+ h = new ArrayList<Document>();
+ histories.put(agName, h);
+ }
+ if (h.isEmpty())
+ registerAgView(agName); // the first time a state is added for the agent, register in the browser
+ if (hasHistory || h.isEmpty())
+ h.add(mind);
+ else
+ h.set(0, mind);
+ }
+
+ String registerAgView(final String agName) {
+ if (httpServer == null)
+ return null;
+ try {
+ String url = "/agent-mind/"+agName;
+ httpServer.createContext(url, new HttpHandler() {
+ public void handle(HttpExchange exchange) throws IOException {
+ String requestMethod = exchange.getRequestMethod();
+ Headers responseHeaders = exchange.getResponseHeaders();
+ exchange.sendResponseHeaders(200, 0);
+ OutputStream responseBody = exchange.getResponseBody();
+ responseHeaders.set("Content-Type", "text/html");
+
+ if (requestMethod.equalsIgnoreCase("GET")) {
+ try {
+ StringWriter so = new StringWriter();
+ so.append("<html><head><title>"+agName+"</title>");
+
+ // test if the url is for this agent
+ String path = exchange.getRequestURI().getPath();
+ if (!getAgNameFromPath(path).equals(agName)) {
+ if (tryToIncludeMindInspectorForAg(path))
+ so.append("<meta http-equiv=\"refresh\" content=0>");
+ else
+ so.append("unkown agent!");
+ } else {
+
+ List<Document> h = histories.get(agName);
+ if (h != null && h.size() > 0) {
+ Document agState;
+ int i = -1;
+ exchange.getRemoteAddress();
+
+ String query = exchange.getRequestURI().getRawQuery(); // what follows ?
+ String remote = exchange.getRemoteAddress().toString();
+
+ if (path.endsWith("hide")) {
+ show.put(query,false);
+ Integer ii = lastStepSeenByUser.get(remote);
+ if (ii != null)
+ i = ii;
+ } else if (path.endsWith("show")) {
+ show.put(query,true);
+ Integer ii = lastStepSeenByUser.get(remote);
+ if (ii != null)
+ i = ii;
+ } else if (path.endsWith("clear")) {
+ agState = h.get(h.size()-1);
+ h.clear();
+ h.add(agState);
+ } else {
+ // see if ends with a number
+ try {
+ int pos = path.lastIndexOf("/");
+ String n = path.substring(pos+1).trim();
+ i = new Integer(n);
+ } catch (Exception e) {}
+ }
+ if (i == -1) {
+ so.append("<meta http-equiv=\"refresh\" content=\""+refreshInterval+"\">");
+ agState = h.get(h.size()-1);
+ } else {
+ agState = h.get(i-1);
+ }
+ try {
+ lastStepSeenByUser.put(remote, i);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ so.append("</head><body>");
+ if (h.size() > 1) {
+ //so.append("history: ");
+ so.append("<a href=/agent-mind/"+agName+"/latest>latest state</a> ");
+ for (i=h.size()-1; i>0; i--) {
+ so.append("<a href=\"/agent-mind/"+agName+"/"+i+"\" style=\"text-decoration: none\">"+i+"</a> ");
+ }
+ so.append("<a href=\"/agent-mind/"+agName+"/clear\">clear history</a> ");
+ so.append("<hr/>");
+ }
+ so.append(getAgStateAsString(agState, false));
+ //so.append("<hr/><a href=\"/\"> list of agents</a> ");
+ } else {
+ so.append("select an agent");
+ }
+ }
+ responseBody.write(so.toString().getBytes());
+
+ //responseBody.write(("<br/><a href=/agent-code/"+agName+">code</a>").getBytes());
+ responseBody.write("</body></html>".getBytes());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ responseBody.close();
+ }
+ });
+ return httpServerURL+url;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /*
+ String registerAgCodeBrowserView(String agId, final String agCode) {
+ if (httpServer == null)
+ return null;
+ try {
+ String url="/agent-code/"+agId;
+ httpServer.createContext(url, new HttpHandler() {
+ public void handle(HttpExchange exchange) throws IOException {
+ String requestMethod = exchange.getRequestMethod();
+ Headers responseHeaders = exchange.getResponseHeaders();
+ responseHeaders.set("Content-Type", "text/html");
+ exchange.sendResponseHeaders(200, 0);
+ OutputStream responseBody = exchange.getResponseBody();
+
+ if (requestMethod.equalsIgnoreCase("GET")) {
+ responseBody.write(agCode.getBytes());
+ }
+ responseBody.close();
+ }
+ });
+ return httpServerURL+url;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+ */
+
+ protected asl2xml mindInspectorTransformer = null;
+ Map<String,Boolean> show = new HashMap<String,Boolean>();
+
+ synchronized String getAgStateAsString(Document ag, boolean full) { // full means with show all
+ try {
+ if (mindInspectorTransformer == null) {
+ mindInspectorTransformer = new asl2html("/xml/agInspection.xsl");
+
+ show.put("bels", true);
+ show.put("annots", Config.get().getBoolean(Config.SHOW_ANNOTS));
+ show.put("rules", false);
+ show.put("evt", true);
+ show.put("mb", false);
+ show.put("int", false);
+ show.put("int-details", false);
+ show.put("plan", false);
+ show.put("plan-details", false);
+ }
+ for (String p: show.keySet())
+ if (full)
+ mindInspectorTransformer.setParameter("show-"+p, "true");
+ else
+ mindInspectorTransformer.setParameter("show-"+p, show.get(p)+"");
+ return mindInspectorTransformer.transform(ag); // transform to HTML
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "Error XML transformation (MindInspector)";
+ }
+ }
+
+}
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-09 10:45:24 UTC (rev 1889)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-09 11:44:30 UTC (rev 1890)
@@ -23,10 +23,17 @@
package jason.infra.centralised;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import jason.JasonException;
import jason.ReceiverNotFoundException;
import jason.architecture.AgArch;
-import jason.architecture.MindInspectorAgArch;
import jason.asSemantics.ActionExec;
import jason.asSemantics.Agent;
import jason.asSemantics.Circumstance;
@@ -37,15 +44,8 @@
import jason.mas2j.ClassParameters;
import jason.runtime.RuntimeServicesInfraTier;
import jason.runtime.Settings;
+import jason.util.Config;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
/**
* This class provides an agent architecture when using Centralised
* infrastructure to run the MAS inside Jason.
@@ -97,7 +97,7 @@
// mind inspector arch
if (stts.getUserParameter(Settings.MIND_INSPECTOR) != null) {
- insertAgArch(new MindInspectorAgArch());
+ insertAgArch( (AgArch)Class.forName( Config.get().getMindInspectorArchClassName()).newInstance() );
getFirstAgArch().init();
}
Modified: trunk/src/jason/infra/jade/RunJadeMAS.java
===================================================================
--- trunk/src/jason/infra/jade/RunJadeMAS.java 2016-04-09 10:45:24 UTC (rev 1889)
+++ trunk/src/jason/infra/jade/RunJadeMAS.java 2016-04-09 11:44:30 UTC (rev 1890)
@@ -45,7 +45,6 @@
import jade.wrapper.ContainerController;
import jade.wrapper.StaleProxyException;
import jason.JasonException;
-import jason.architecture.MindInspectorAgArch;
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Literal;
import jason.asSyntax.StringTerm;
@@ -246,7 +245,7 @@
// mind inspector arch
if (ap.getOption("mindinspector") != null) {
- ap.addArchClass(MindInspectorAgArch.class.getName());
+ ap.addArchClass( Config.get().getMindInspectorArchClassName());
}
for (int cAg = 0; cAg < ap.getNbInstances(); cAg++) {
Modified: trunk/src/jason/util/Config.java
===================================================================
--- trunk/src/jason/util/Config.java 2016-04-09 10:45:24 UTC (rev 1889)
+++ trunk/src/jason/util/Config.java 2016-04-09 11:44:30 UTC (rev 1890)
@@ -23,11 +23,6 @@
package jason.util;
-import jason.asSemantics.Message;
-import jason.asSemantics.TransitionSystem;
-import jason.infra.centralised.CentralisedFactory;
-import jason.infra.jade.JadeFactory;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -41,6 +36,11 @@
import java.util.Properties;
import java.util.StringTokenizer;
+import jason.asSemantics.Message;
+import jason.asSemantics.TransitionSystem;
+import jason.infra.centralised.CentralisedFactory;
+import jason.infra.jade.JadeFactory;
+
/**
* Jason configuration (used by JasonID to generate the project's scripts)
*
@@ -762,4 +762,12 @@
Config.get().fix();
Config.get().store();
}
+
+ public String getMindInspectorArchClassName() {
+ return "jason.architecture.MindInspectorAgArch";
+ }
+
+ public String getMindInspectorWebServerClassName() {
+ return "jason.architecture.MindInspectorWebImpl";
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-04-09 10:45:26
|
Revision: 1889
http://sourceforge.net/p/jason/svn/1889
Author: jomifred
Date: 2016-04-09 10:45:24 +0000 (Sat, 09 Apr 2016)
Log Message:
-----------
move some classes from jeditplugin package to better packages
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/asunit/TestAgent.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/asSyntax/parser/as2jTokenManager.java
trunk/src/jason/infra/InfrastructureFactory.java
trunk/src/jason/infra/centralised/CentralisedFactory.java
trunk/src/jason/infra/centralised/CentralisedMASLauncherAnt.java
trunk/src/jason/infra/jade/JadeFactory.java
trunk/src/jason/infra/jade/JadeMASLauncherAnt.java
trunk/src/jason/jeditplugin/JasonID.java
trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc
trunk/src/jason/mas2j/parser/mas2j.java
trunk/src/jason/mas2j/parser/mas2jTokenManager.java
Added Paths:
-----------
trunk/src/jason/infra/MASLauncherInfraTier.java
trunk/src/jason/infra/RunProjectListener.java
trunk/src/jason/util/CheckVersion.java
Removed Paths:
-------------
trunk/src/jason/jeditplugin/CheckVersion.java
trunk/src/jason/jeditplugin/MASLauncherInfraTier.java
trunk/src/jason/jeditplugin/RunProjectListener.java
Modified: trunk/applications/as-unit-test/src/jason/asunit/TestAgent.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/asunit/TestAgent.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/applications/as-unit-test/src/jason/asunit/TestAgent.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -1,6 +1,10 @@
package jason.asunit;
import static org.junit.Assert.fail;
+
+import java.io.StringReader;
+import java.util.logging.Level;
+
import jason.JasonException;
import jason.RevisionFailedException;
import jason.asSemantics.Agent;
@@ -16,11 +20,8 @@
import jason.asSyntax.parser.ParseException;
import jason.bb.BeliefBase;
import jason.infra.centralised.RunCentralisedMAS;
-import jason.jeditplugin.Config;
+import jason.util.Config;
-import java.io.StringReader;
-import java.util.logging.Level;
-
public class TestAgent extends Agent {
// creates the masRunner
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-04-09 10:45:24 UTC (rev 1889)
@@ -47,7 +47,7 @@
import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.Trigger.TEOperator;
import jason.asSyntax.Trigger.TEType;
- import jason.jeditplugin.*;
+ import jason.util.*;
public class as2j {
private String asSource = null;
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -16,7 +16,7 @@
import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.Trigger.TEOperator;
import jason.asSyntax.Trigger.TEType;
- import jason.jeditplugin.*;
+ import jason.util.*;
public class as2j implements as2jConstants {
private String asSource = null;
Modified: trunk/src/jason/asSyntax/parser/as2jTokenManager.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2jTokenManager.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/asSyntax/parser/as2jTokenManager.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -14,7 +14,7 @@
import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.Trigger.TEOperator;
import jason.asSyntax.Trigger.TEType;
-import jason.jeditplugin.*;
+import jason.util.*;
public class as2jTokenManager implements as2jConstants
{
Modified: trunk/src/jason/infra/InfrastructureFactory.java
===================================================================
--- trunk/src/jason/infra/InfrastructureFactory.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/infra/InfrastructureFactory.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -1,6 +1,5 @@
package jason.infra;
-import jason.jeditplugin.MASLauncherInfraTier;
import jason.runtime.RuntimeServicesInfraTier;
/**
Copied: trunk/src/jason/infra/MASLauncherInfraTier.java (from rev 1888, trunk/src/jason/jeditplugin/MASLauncherInfraTier.java)
===================================================================
--- trunk/src/jason/infra/MASLauncherInfraTier.java (rev 0)
+++ trunk/src/jason/infra/MASLauncherInfraTier.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -0,0 +1,42 @@
+package jason.infra;
+
+import jason.mas2j.MAS2JProject;
+
+/**
+ * Used to launch an MAS. Each infrastructure should
+ * implements it.
+ *
+ * <p>The methods of this class are called in the following order:
+ * <ul>
+ * <li>setProject</li>
+ * <li>setListener</li>
+ * <li>writeScripts</li>
+ * <li>stopMAS</li>
+ * </ul>
+ */
+public interface MASLauncherInfraTier extends Runnable {
+
+ /**
+ * Sets the description of the project to be run.
+ */
+ public void setProject(MAS2JProject project);
+
+ /**
+ * Sets the object that wants to be informed about the changes in
+ * the execution state. This object normally is the JasonIDE, that
+ * wants to change available buttons as the project is being
+ * executed.
+ */
+ public void setListener(RunProjectListener listener);
+
+ /**
+ * Writes the script(s), normally Ant scripts, used to launch the
+ * MAS.
+ */
+ public boolean writeScripts(boolean debug, boolean useBuildFileName);
+
+ /**
+ * Stops the MAS execution.
+ */
+ public void stopMAS();
+}
Copied: trunk/src/jason/infra/RunProjectListener.java (from rev 1888, trunk/src/jason/jeditplugin/RunProjectListener.java)
===================================================================
--- trunk/src/jason/infra/RunProjectListener.java (rev 0)
+++ trunk/src/jason/infra/RunProjectListener.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -0,0 +1,9 @@
+package jason.infra;
+
+/**
+ * This interface is implemented by objects that wants to be notified
+ * about changes in the MAS execution state (like JasonIDE).
+ */
+public interface RunProjectListener {
+ public void masFinished();
+}
Modified: trunk/src/jason/infra/centralised/CentralisedFactory.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedFactory.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/infra/centralised/CentralisedFactory.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -1,7 +1,7 @@
package jason.infra.centralised;
import jason.infra.InfrastructureFactory;
-import jason.jeditplugin.MASLauncherInfraTier;
+import jason.infra.MASLauncherInfraTier;
import jason.runtime.RuntimeServicesInfraTier;
public class CentralisedFactory implements InfrastructureFactory {
Modified: trunk/src/jason/infra/centralised/CentralisedMASLauncherAnt.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedMASLauncherAnt.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/infra/centralised/CentralisedMASLauncherAnt.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -8,8 +8,8 @@
import java.text.SimpleDateFormat;
import java.util.Date;
-import jason.jeditplugin.MASLauncherInfraTier;
-import jason.jeditplugin.RunProjectListener;
+import jason.infra.MASLauncherInfraTier;
+import jason.infra.RunProjectListener;
import jason.mas2j.MAS2JProject;
import jason.util.Config;
Modified: trunk/src/jason/infra/jade/JadeFactory.java
===================================================================
--- trunk/src/jason/infra/jade/JadeFactory.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/infra/jade/JadeFactory.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -1,7 +1,7 @@
package jason.infra.jade;
import jason.infra.InfrastructureFactory;
-import jason.jeditplugin.MASLauncherInfraTier;
+import jason.infra.MASLauncherInfraTier;
import jason.runtime.RuntimeServicesInfraTier;
public class JadeFactory implements InfrastructureFactory {
Modified: trunk/src/jason/infra/jade/JadeMASLauncherAnt.java
===================================================================
--- trunk/src/jason/infra/jade/JadeMASLauncherAnt.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/infra/jade/JadeMASLauncherAnt.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -14,8 +14,8 @@
import jason.asSyntax.Literal;
import jason.asSyntax.StringTerm;
import jason.asSyntax.parser.ParseException;
+import jason.infra.MASLauncherInfraTier;
import jason.infra.centralised.CentralisedMASLauncherAnt;
-import jason.jeditplugin.MASLauncherInfraTier;
import jason.mas2j.AgentParameters;
import jason.util.Config;
Deleted: trunk/src/jason/jeditplugin/CheckVersion.java
===================================================================
--- trunk/src/jason/jeditplugin/CheckVersion.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/jeditplugin/CheckVersion.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -1,126 +0,0 @@
-package jason.jeditplugin;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.Toolkit;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Properties;
-
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-
-import jason.util.Config;
-
-public class CheckVersion extends Thread {
-
- public static final String JasonSite = "http://jason.sf.net";
- String download;
-
- String version;
- String release;
-
- String getLatestVersion() {
- // read version from Jason site
- try {
- Properties p = new Properties();
- p.load(new URL(JasonSite+"/latest.properties").openStream());
- download = p.getProperty("download");
- version = p.getProperty("version");
- release = p.getProperty("release");
- return version + "." + release;
- } catch (Exception ex) {
- System.out.println(ex);
- return null;
- }
- }
-
- boolean isLatestVersion() {
- // get user version
- String cVersion = Config.get().getJasonRunningVersion();
- String lv = getLatestVersion();
- return lv == null || cVersion.compareTo(lv) >= 0;
- }
-
- String whatsNew() {
- try {
- StringBuilder out = new StringBuilder();
- InputStream in = new URL(JasonSite+"/whatsnew.txt").openStream();
- int c = in.read();
- while (c != -1) {
- out.append((char) c);
- c = in.read();
- }
- return out.toString();
- } catch (Exception e) {
- System.err.println("Error reading what's new!" + e);
- return null;
- }
- }
-
- void show() {
- final JFrame f = new JFrame("Jason update");
- f.setLayout(new BorderLayout());
-
- JTextArea ta = new JTextArea(20, 90);
- f.add(BorderLayout.CENTER,new JScrollPane(ta));
-
- JPanel sp = new JPanel(new FlowLayout(FlowLayout.CENTER));
- //JButton notShow = new JButton("Do not show this message again.");
- JButton ok = new JButton("Ok");
- ok.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- f.setVisible(false); }
- });
- JButton notShow = new JButton("Do not show this message again");
- notShow.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- f.setVisible(false);
- Config.get().setProperty(Config.CHECK_VERSION,"false");
- Config.get().store();
- }
- });
- sp.add(ok);
- sp.add(notShow);
- f.add(BorderLayout.SOUTH, sp);
- f.pack();
-
- ta.append("A new version of Jason (" + getLatestVersion() + ") is available at\n\n");
- ta.append(" "+download+"\n\n");
- String wn = whatsNew();
- if (wn != null) {
- ta.append("\nRelease notes:\n");
- ta.append(wn);
- }
-
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- f.setLocation((int)( (screenSize.width - f.getWidth()) / 2),(int) ((screenSize.height - f.getHeight())/2));
- f.setVisible(true);
- }
-
- static boolean alreadyRun = false;
- public void run() {
- // to avoid this thread to run twice
- if (alreadyRun) return;
- alreadyRun = true;
-
- try {
- if (Config.get().getProperty(Config.CHECK_VERSION,"true").equals("true")) {
- if (!isLatestVersion()) {
- show();
- }
- }
- } catch (Exception e) { }
- }
-
- public static void main(String[] a) {
- CheckVersion cv = new CheckVersion();
- cv.start();
- }
-}
Modified: trunk/src/jason/jeditplugin/JasonID.java
===================================================================
--- trunk/src/jason/jeditplugin/JasonID.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/jeditplugin/JasonID.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -68,6 +68,8 @@
import errorlist.DefaultErrorSource;
import errorlist.ErrorSource;
+import jason.infra.MASLauncherInfraTier;
+import jason.infra.RunProjectListener;
import jason.infra.centralised.CentralisedMASLauncherAnt;
import jason.infra.centralised.RunCentralisedMAS;
import jason.mas2j.AgentParameters;
@@ -75,6 +77,7 @@
import jason.mas2j.parser.ParseException;
import jason.mas2j.parser.TokenMgrError;
import jason.runtime.OutputStreamAdapter;
+import jason.util.CheckVersion;
import jason.util.Config;
import jason.util.asl2html;
import jason.util.asl2tex;
Deleted: trunk/src/jason/jeditplugin/MASLauncherInfraTier.java
===================================================================
--- trunk/src/jason/jeditplugin/MASLauncherInfraTier.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/jeditplugin/MASLauncherInfraTier.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -1,42 +0,0 @@
-package jason.jeditplugin;
-
-import jason.mas2j.MAS2JProject;
-
-/**
- * Used by the Jason IDE to launch an MAS. Each infrastructure should
- * implements it.
- *
- * <p>The methods of this class are called in the following order:
- * <ul>
- * <li>setProject</li>
- * <li>setListener</li>
- * <li>writeScripts</li>
- * <li>stopMAS</li>
- * </ul>
- */
-public interface MASLauncherInfraTier extends Runnable {
-
- /**
- * Sets the description of the project to be run.
- */
- public void setProject(MAS2JProject project);
-
- /**
- * Sets the object that wants to be informed about the changes in
- * the execution state. This object normally is the JasonIDE, that
- * wants to change available buttons as the project is being
- * executed.
- */
- public void setListener(RunProjectListener listener);
-
- /**
- * Writes the script(s), normally Ant scripts, used to launch the
- * MAS.
- */
- public boolean writeScripts(boolean debug, boolean useBuildFileName);
-
- /**
- * Stops the MAS execution.
- */
- public void stopMAS();
-}
Deleted: trunk/src/jason/jeditplugin/RunProjectListener.java
===================================================================
--- trunk/src/jason/jeditplugin/RunProjectListener.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/jeditplugin/RunProjectListener.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -1,9 +0,0 @@
-package jason.jeditplugin;
-
-/**
- * This interface is implemented by objects that wants to be notified
- * about changes in the MAS execution state (like JasonIDE).
- */
-public interface RunProjectListener {
- public void masFinished();
-}
Modified: trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc
===================================================================
--- trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc 2016-04-09 10:45:24 UTC (rev 1889)
@@ -36,7 +36,8 @@
import jason.mas2j.*;
import jason.asSyntax.*;
import jason.asSemantics.*;
-import jason.jeditplugin.*;
+import jason.util.*;
+import jason.infra.*;
public class mas2j {
Modified: trunk/src/jason/mas2j/parser/mas2j.java
===================================================================
--- trunk/src/jason/mas2j/parser/mas2j.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/mas2j/parser/mas2j.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -6,7 +6,8 @@
import jason.mas2j.*;
import jason.asSyntax.*;
import jason.asSemantics.*;
-import jason.jeditplugin.*;
+import jason.util.*;
+import jason.infra.*;
public class mas2j implements mas2jConstants {
Modified: trunk/src/jason/mas2j/parser/mas2jTokenManager.java
===================================================================
--- trunk/src/jason/mas2j/parser/mas2jTokenManager.java 2016-04-08 19:25:42 UTC (rev 1888)
+++ trunk/src/jason/mas2j/parser/mas2jTokenManager.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -5,7 +5,7 @@
import jason.mas2j.*;
import jason.asSyntax.*;
import jason.asSemantics.*;
-import jason.jeditplugin.*;
+import jason.util.*;
public class mas2jTokenManager implements mas2jConstants
{
Copied: trunk/src/jason/util/CheckVersion.java (from rev 1888, trunk/src/jason/jeditplugin/CheckVersion.java)
===================================================================
--- trunk/src/jason/util/CheckVersion.java (rev 0)
+++ trunk/src/jason/util/CheckVersion.java 2016-04-09 10:45:24 UTC (rev 1889)
@@ -0,0 +1,126 @@
+package jason.util;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+import jason.util.Config;
+
+public class CheckVersion extends Thread {
+
+ public static final String JasonSite = "http://jason.sf.net";
+ String download;
+
+ String version;
+ String release;
+
+ String getLatestVersion() {
+ // read version from Jason site
+ try {
+ Properties p = new Properties();
+ p.load(new URL(JasonSite+"/latest.properties").openStream());
+ download = p.getProperty("download");
+ version = p.getProperty("version");
+ release = p.getProperty("release");
+ return version + "." + release;
+ } catch (Exception ex) {
+ System.out.println(ex);
+ return null;
+ }
+ }
+
+ boolean isLatestVersion() {
+ // get user version
+ String cVersion = Config.get().getJasonRunningVersion();
+ String lv = getLatestVersion();
+ return lv == null || cVersion.compareTo(lv) >= 0;
+ }
+
+ String whatsNew() {
+ try {
+ StringBuilder out = new StringBuilder();
+ InputStream in = new URL(JasonSite+"/whatsnew.txt").openStream();
+ int c = in.read();
+ while (c != -1) {
+ out.append((char) c);
+ c = in.read();
+ }
+ return out.toString();
+ } catch (Exception e) {
+ System.err.println("Error reading what's new!" + e);
+ return null;
+ }
+ }
+
+ void show() {
+ final JFrame f = new JFrame("Jason update");
+ f.setLayout(new BorderLayout());
+
+ JTextArea ta = new JTextArea(20, 90);
+ f.add(BorderLayout.CENTER,new JScrollPane(ta));
+
+ JPanel sp = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ //JButton notShow = new JButton("Do not show this message again.");
+ JButton ok = new JButton("Ok");
+ ok.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ f.setVisible(false); }
+ });
+ JButton notShow = new JButton("Do not show this message again");
+ notShow.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ f.setVisible(false);
+ Config.get().setProperty(Config.CHECK_VERSION,"false");
+ Config.get().store();
+ }
+ });
+ sp.add(ok);
+ sp.add(notShow);
+ f.add(BorderLayout.SOUTH, sp);
+ f.pack();
+
+ ta.append("A new version of Jason (" + getLatestVersion() + ") is available at\n\n");
+ ta.append(" "+download+"\n\n");
+ String wn = whatsNew();
+ if (wn != null) {
+ ta.append("\nRelease notes:\n");
+ ta.append(wn);
+ }
+
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ f.setLocation((int)( (screenSize.width - f.getWidth()) / 2),(int) ((screenSize.height - f.getHeight())/2));
+ f.setVisible(true);
+ }
+
+ static boolean alreadyRun = false;
+ public void run() {
+ // to avoid this thread to run twice
+ if (alreadyRun) return;
+ alreadyRun = true;
+
+ try {
+ if (Config.get().getProperty(Config.CHECK_VERSION,"true").equals("true")) {
+ if (!isLatestVersion()) {
+ show();
+ }
+ }
+ } catch (Exception e) { }
+ }
+
+ public static void main(String[] a) {
+ CheckVersion cv = new CheckVersion();
+ cv.start();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-04-08 19:25:45
|
Revision: 1888
http://sourceforge.net/p/jason/svn/1888
Author: jomifred
Date: 2016-04-08 19:25:42 +0000 (Fri, 08 Apr 2016)
Log Message:
-----------
improvements in the ag-env API
move classe Config from jedit to util
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/asunit/TestArch.java
trunk/demos/using-only-jason-BDI-engine/SimpleJasonAgent.java
trunk/examples/airport/cph/CPHAgArch.java
trunk/examples/auction/AuctioneerGUI.java
trunk/src/jason/architecture/AgArch.java
trunk/src/jason/architecture/AgArchInfraTier.java
trunk/src/jason/architecture/MindInspectorAgArch.java
trunk/src/jason/architecture/MindInspectorWeb.java
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSemantics/Circumstance.java
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/asSyntax/PlanLibrary.java
trunk/src/jason/asSyntax/Structure.java
trunk/src/jason/asSyntax/directives/Include.java
trunk/src/jason/bb/BeliefBase.java
trunk/src/jason/bb/ChainBB.java
trunk/src/jason/bb/DefaultBeliefBase.java
trunk/src/jason/bb/IndexedBB.java
trunk/src/jason/bb/JDBCPersistentBB.java
trunk/src/jason/bb/TextPersistentBB.java
trunk/src/jason/control/ExecutionControlGUI.java
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/infra/centralised/CentralisedMASLauncherAnt.java
trunk/src/jason/infra/centralised/CreateJNLP.java
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
trunk/src/jason/infra/jade/JadeMASLauncherAnt.java
trunk/src/jason/infra/jade/JasonBridgeArch.java
trunk/src/jason/infra/jade/RunJadeMAS.java
trunk/src/jason/infra/repl/ReplAgGUI.java
trunk/src/jason/jeditplugin/CheckVersion.java
trunk/src/jason/jeditplugin/JasonID.java
trunk/src/jason/jeditplugin/JasonIDPlugin.java
trunk/src/jason/jeditplugin/NewAgentGUI.java
trunk/src/jason/jeditplugin/NewEnvironmentGUI.java
trunk/src/jason/jeditplugin/NewInternalActionGUI.java
trunk/src/jason/jeditplugin/NewProjectGUI.java
trunk/src/jason/mas2j/MAS2JProject.java
trunk/src/jason/util/ConfigGUI.java
trunk/src/test/VarTermTest.java
Added Paths:
-----------
trunk/src/jason/util/Config.java
Removed Paths:
-------------
trunk/src/jason/jeditplugin/Config.java
Modified: trunk/applications/as-unit-test/src/jason/asunit/TestArch.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/asunit/TestArch.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/applications/as-unit-test/src/jason/asunit/TestArch.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,5 +1,8 @@
package jason.asunit;
+import java.util.ArrayList;
+import java.util.List;
+
import jason.JasonException;
import jason.asSemantics.ActionExec;
import jason.asSyntax.Literal;
@@ -8,9 +11,6 @@
import jason.infra.centralised.CentralisedEnvironment;
import jason.infra.centralised.RunCentralisedMAS;
-import java.util.ArrayList;
-import java.util.List;
-
public class TestArch extends CentralisedAgArch implements Runnable {
private static int nameCount = 0;
@@ -77,13 +77,13 @@
}
@Override
- public void act(ActionExec action, List<ActionExec> feedback) {
+ public void act(ActionExec action) { //, List<ActionExec> feedback) {
actions.add(action.getActionTerm());
if (getEnvInfraTier() != null) {
- super.act(action, feedback); //env.scheduleAction(getAgName(), action.getActionTerm(), action);
+ super.act(action); //, feedback); //env.scheduleAction(getAgName(), action.getActionTerm(), action);
} else {
action.setResult(true);
- feedback.add(action);
+ actDone(action); //feedback.add(action);
}
}
Modified: trunk/demos/using-only-jason-BDI-engine/SimpleJasonAgent.java
===================================================================
--- trunk/demos/using-only-jason-BDI-engine/SimpleJasonAgent.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/demos/using-only-jason-BDI-engine/SimpleJasonAgent.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -64,11 +64,11 @@
// this method get the agent actions
@Override
- public void act(ActionExec action, List<ActionExec> feedback) {
+ public void act(ActionExec action) {
getTS().getLogger().info("Agent " + getAgName() + " is doing: " + action.getActionTerm());
// set that the execution was ok
action.setResult(true);
- feedback.add(action);
+ actDone(action);
}
@Override
Modified: trunk/examples/airport/cph/CPHAgArch.java
===================================================================
--- trunk/examples/airport/cph/CPHAgArch.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/examples/airport/cph/CPHAgArch.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -24,11 +24,12 @@
}
}
- public void act(ActionExec action, List<ActionExec> feedback) {
+ @Override
+ public void act(ActionExec action) { //, List<ActionExec> feedback) {
// get the action to be performed
Structure taction = action.getActionTerm();
if (!taction.getFunctor().equals("disarm")) {
- super.act(action,feedback);
+ super.act(action);
} else {
System.out.println("A CPH is trying to disarm a bomb! Disabled by its architecture.");
}
Modified: trunk/examples/auction/AuctioneerGUI.java
===================================================================
--- trunk/examples/auction/AuctioneerGUI.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/examples/auction/AuctioneerGUI.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -40,16 +40,16 @@
}
@Override
- public void act(ActionExec action, List<ActionExec> feedback) {
+ public void act(ActionExec action) { //, List<ActionExec> feedback) {
if (action.getActionTerm().getFunctor().startsWith("show_winner")) {
jt.append("Winner of auction " + action.getActionTerm().getTerm(0));
jt.append(" is " + action.getActionTerm().getTerm(1) + "\n");
action.setResult(true);
- feedback.add(action);
+ actDone(action);
auction.setEnabled(true); // enable GUI button
} else {
- super.act(action,feedback); // send the action to the environment to be performed.
+ super.act(action); // send the action to the environment to be performed.
}
}
Modified: trunk/src/jason/architecture/AgArch.java
===================================================================
--- trunk/src/jason/architecture/AgArch.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/architecture/AgArch.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -22,20 +22,17 @@
package jason.architecture;
-import jason.JasonException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+
import jason.asSemantics.ActionExec;
import jason.asSemantics.Message;
import jason.asSemantics.TransitionSystem;
import jason.asSyntax.Literal;
import jason.infra.centralised.CentralisedAgArch;
-import jason.mas2j.ClassParameters;
import jason.runtime.RuntimeServicesInfraTier;
-import jason.runtime.Settings;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-
/**
* Base agent architecture class that defines the overall agent architecture;
* the AS interpreter is the reasoner (a kind of mind) within this
@@ -69,13 +66,6 @@
firstArch = this;
}
- /**
- * @deprecated for arch initialisation you should override the init() method.
- */
- public void initAg(String agClass, ClassParameters bbPars, String asSrc, Settings stts) throws JasonException {
- //Agent.create(this, agClass, bbPars, asSrc, stts);
- }
-
public void init() throws Exception {
}
@@ -131,7 +121,6 @@
try {
AgArch a = (AgArch) Class.forName(agArchClass).newInstance();
a.setTS(ts); // so a.init() can use TS
- a.initAg(null, null, null, null); // for compatibility reasons
insertAgArch(a);
a.init();
} catch (Exception e) {
@@ -200,12 +189,15 @@
* Executes the action <i>action</i> and, when finished, add it back in
* <i>feedback</i> actions.
*/
- // TODO: remove feedback parameter and use getTS().addFeedbackAction in a new method of this class to be executed when the action is finished (as actionExecuted of centralised)
- // for jason 2.0 to avoid backward compatibility problems
- public void act(ActionExec action, List<ActionExec> feedback) {
+ public void act(ActionExec action) {
if (successor != null)
- successor.act(action, feedback);
+ successor.act(action);
}
+
+ /** called to inform that the action execution is finished */
+ public void actDone(ActionExec act) {
+ getTS().getC().addFeedbackAction(act);
+ }
/** Returns true if the agent can enter in sleep mode. */
public boolean canSleep() {
Modified: trunk/src/jason/architecture/AgArchInfraTier.java
===================================================================
--- trunk/src/jason/architecture/AgArchInfraTier.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/architecture/AgArchInfraTier.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -45,8 +45,8 @@
/** Reads the agent's mailbox and adds messages into the agent's circumstance */
public void checkMail();
- /** Executes the action <i>action</i> and, when finished, add it back in <i>feedback</i> actions. */
- public void act(ActionExec action, List<ActionExec> feedback);
+ /** Executes the action <i>action</i> in the environment */
+ public void act(ActionExec action); //, List<ActionExec> feedback);
/** Returns true whether the agent can sleep according to the arch */
public boolean canSleep();
Modified: trunk/src/jason/architecture/MindInspectorAgArch.java
===================================================================
--- trunk/src/jason/architecture/MindInspectorAgArch.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/architecture/MindInspectorAgArch.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -22,16 +22,6 @@
package jason.architecture;
-import jason.NoValueException;
-import jason.asSyntax.ASSyntax;
-import jason.asSyntax.NumberTerm;
-import jason.asSyntax.Structure;
-import jason.control.ExecutionControlGUI;
-import jason.jeditplugin.Config;
-import jason.runtime.Settings;
-import jason.util.asl2html;
-import jason.util.asl2xml;
-
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
@@ -62,6 +52,16 @@
import org.w3c.dom.Document;
+import jason.NoValueException;
+import jason.asSyntax.ASSyntax;
+import jason.asSyntax.NumberTerm;
+import jason.asSyntax.Structure;
+import jason.control.ExecutionControlGUI;
+import jason.runtime.Settings;
+import jason.util.Config;
+import jason.util.asl2html;
+import jason.util.asl2xml;
+
/**
* ArArch that displays the mind state of the agent
*/
Modified: trunk/src/jason/architecture/MindInspectorWeb.java
===================================================================
--- trunk/src/jason/architecture/MindInspectorWeb.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/architecture/MindInspectorWeb.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,11 +1,5 @@
package jason.architecture;
-import jason.asSemantics.Agent;
-import jason.jeditplugin.Config;
-import jason.runtime.Settings;
-import jason.util.asl2html;
-import jason.util.asl2xml;
-
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
@@ -26,6 +20,12 @@
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
+import jason.asSemantics.Agent;
+import jason.runtime.Settings;
+import jason.util.Config;
+import jason.util.asl2html;
+import jason.util.asl2xml;
+
public class MindInspectorWeb {
private static MindInspectorWeb singleton = null;
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/asSemantics/Agent.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -23,35 +23,6 @@
package jason.asSemantics;
-import jason.JasonException;
-import jason.RevisionFailedException;
-import jason.architecture.AgArch;
-import jason.architecture.MindInspectorWeb;
-import jason.asSyntax.ASSyntax;
-import jason.asSyntax.ArithFunctionTerm;
-import jason.asSyntax.InternalActionLiteral;
-import jason.asSyntax.Literal;
-import jason.asSyntax.LogicalFormula;
-import jason.asSyntax.Plan;
-import jason.asSyntax.PlanLibrary;
-import jason.asSyntax.Rule;
-import jason.asSyntax.Term;
-import jason.asSyntax.Trigger;
-import jason.asSyntax.Trigger.TEOperator;
-import jason.asSyntax.Trigger.TEType;
-import jason.asSyntax.directives.FunctionRegister;
-import jason.asSyntax.directives.Include;
-import jason.asSyntax.parser.ParseException;
-import jason.asSyntax.parser.as2j;
-import jason.bb.BeliefBase;
-import jason.bb.DefaultBeliefBase;
-import jason.bb.StructureWrapperForLiteral;
-import jason.functions.Count;
-import jason.functions.RuleToFunction;
-import jason.jeditplugin.Config;
-import jason.mas2j.ClassParameters;
-import jason.runtime.Settings;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -82,8 +53,37 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import jason.JasonException;
+import jason.RevisionFailedException;
+import jason.architecture.AgArch;
+import jason.architecture.MindInspectorWeb;
+import jason.asSyntax.ASSyntax;
+import jason.asSyntax.ArithFunctionTerm;
+import jason.asSyntax.InternalActionLiteral;
+import jason.asSyntax.Literal;
+import jason.asSyntax.LogicalFormula;
+import jason.asSyntax.Plan;
+import jason.asSyntax.PlanLibrary;
+import jason.asSyntax.Rule;
+import jason.asSyntax.Term;
+import jason.asSyntax.Trigger;
+import jason.asSyntax.Trigger.TEOperator;
+import jason.asSyntax.Trigger.TEType;
+import jason.asSyntax.directives.FunctionRegister;
+import jason.asSyntax.directives.Include;
+import jason.asSyntax.parser.ParseException;
+import jason.asSyntax.parser.as2j;
+import jason.bb.BeliefBase;
+import jason.bb.DefaultBeliefBase;
+import jason.bb.StructureWrapperForLiteral;
+import jason.functions.Count;
+import jason.functions.RuleToFunction;
+import jason.mas2j.ClassParameters;
+import jason.runtime.Settings;
+import jason.util.Config;
+
/**
* The Agent class has the belief base and plan library of an
* AgentSpeak agent. It also implements the default selection
Modified: trunk/src/jason/asSemantics/Circumstance.java
===================================================================
--- trunk/src/jason/asSemantics/Circumstance.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/asSemantics/Circumstance.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -23,14 +23,7 @@
package jason.asSemantics;
-import jason.asSyntax.Literal;
-import jason.asSyntax.Trigger;
-import jason.asSyntax.Trigger.TEOperator;
-import jason.asSyntax.Trigger.TEType;
-import jason.infra.centralised.CentralisedAgArch;
-
import java.io.Serializable;
-import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -43,6 +36,12 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Trigger;
+import jason.asSyntax.Trigger.TEOperator;
+import jason.asSyntax.Trigger.TEType;
+import jason.infra.centralised.CentralisedAgArch;
+
public class Circumstance implements Serializable {
private static final long serialVersionUID = 1L;
@@ -550,6 +549,7 @@
public List<ActionExec> getFeedbackActions() {
return FA;
}
+ /*
public List<ActionExec> getFeedbackActionsWrapper() {
return new AbstractList<ActionExec>() {
public boolean add(ActionExec act) {
@@ -560,6 +560,7 @@
public ActionExec get(int index) { return null; }
};
}
+ */
public void addFeedbackAction(ActionExec act) {
if (act.getIntention() != null) {
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -23,6 +23,18 @@
package jason.asSemantics;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import jason.JasonException;
import jason.NoValueException;
import jason.RevisionFailedException;
@@ -54,25 +66,13 @@
import jason.asSyntax.parser.ParseException;
import jason.bb.BeliefBase;
import jason.infra.centralised.CentralisedAgArchAsynchronous;
-import jason.jeditplugin.Config;
import jason.runtime.Settings;
import jason.stdlib.add_nested_source;
import jason.stdlib.desire;
import jason.stdlib.fail_goal;
+import jason.util.Config;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
public class TransitionSystem {
public enum State { StartRC, SelEv, RelPl, ApplPl, SelAppl, FindOp, AddIM, ProcAct, SelInt, ExecInt, ClrInt }
@@ -1515,7 +1515,7 @@
if (action != null) {
C.addPendingAction(action);
// We need to send a wrapper for FA to the user so that add method then calls C.addFA (which control atomic things)
- getUserAgArch().act(action, C.getFeedbackActionsWrapper());
+ getUserAgArch().act(action); //, C.getFeedbackActionsWrapper());
}
} catch (Exception e) {
logger.log(Level.SEVERE, "*** ERROR in the transition system (act). "+conf.C+"\nCreating a new C!", e);
Modified: trunk/src/jason/asSyntax/PlanLibrary.java
===================================================================
--- trunk/src/jason/asSyntax/PlanLibrary.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/asSyntax/PlanLibrary.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -25,13 +25,6 @@
package jason.asSyntax;
-import jason.JasonException;
-import jason.asSyntax.Trigger.TEOperator;
-import jason.asSyntax.Trigger.TEType;
-import jason.asSyntax.parser.ParseException;
-import jason.bb.BeliefBase;
-import jason.jeditplugin.Config;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -42,6 +35,13 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import jason.JasonException;
+import jason.asSyntax.Trigger.TEOperator;
+import jason.asSyntax.Trigger.TEType;
+import jason.asSyntax.parser.ParseException;
+import jason.bb.BeliefBase;
+import jason.util.Config;
+
/** Represents a set of plans used by an agent
@has - plans 0..* Plan
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/asSyntax/Structure.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -23,10 +23,6 @@
package jason.asSyntax;
-import jason.asSemantics.Unifier;
-import jason.asSyntax.parser.as2j;
-import jason.jeditplugin.Config;
-
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
@@ -39,6 +35,10 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.parser.as2j;
+import jason.util.Config;
+
/**
* Represents a structure: a functor with <i>n</i> arguments,
* e.g.: val(10,x(3)).
Modified: trunk/src/jason/asSyntax/directives/Include.java
===================================================================
--- trunk/src/jason/asSyntax/directives/Include.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/asSyntax/directives/Include.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,12 +1,5 @@
package jason.asSyntax.directives;
-import jason.asSemantics.Agent;
-import jason.asSyntax.Atom;
-import jason.asSyntax.Pred;
-import jason.asSyntax.StringTerm;
-import jason.asSyntax.parser.as2j;
-import jason.jeditplugin.Config;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -18,6 +11,13 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import jason.asSemantics.Agent;
+import jason.asSyntax.Atom;
+import jason.asSyntax.Pred;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.parser.as2j;
+import jason.util.Config;
+
/** Implementation of the <code>include</code> directive. */
public class Include extends DefaultDirective implements Directive {
Modified: trunk/src/jason/bb/BeliefBase.java
===================================================================
--- trunk/src/jason/bb/BeliefBase.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/bb/BeliefBase.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -23,6 +23,12 @@
package jason.bb;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
import jason.asSemantics.Agent;
import jason.asSemantics.Unifier;
import jason.asSyntax.Atom;
@@ -31,13 +37,7 @@
import jason.asSyntax.PredicateIndicator;
import jason.asSyntax.Term;
-import java.util.Iterator;
-import java.util.Set;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-
/**
* Common interface for all kinds of Jason Belief bases, even those
* customised by the user.
@@ -88,11 +88,12 @@
public Iterator<Literal> getAll();
/**
- * Returns an iterator for all literals in BB that match the functor/arity
+ * Returns an iterator for all literals in the default namespace of the BB that match the functor/arity
* of the parameter.<br>
*/
public Iterator<Literal> getCandidateBeliefs(PredicateIndicator pi);
-
+ public default Iterator<Literal> getCandidateBeliefs(Atom namespace, PredicateIndicator pi) { return null; }
+
/**
* Returns an iterator for all literals relevant for l's predicate
* indicator, if l is a var, returns all beliefs.<br>
@@ -127,14 +128,19 @@
/** Removes a literal from BB, returns true if succeed */
public boolean remove(Literal l);
- /** Removes all believes with some functor/arity */
+ /** Removes all believes with some functor/arity in the default namespace */
public boolean abolish(PredicateIndicator pi);
+ public default boolean abolish(Atom namespace, PredicateIndicator pi) { return false; }
/** Gets the BB as XML */
public Element getAsDOM(Document document);
public BeliefBase clone();
+ Object lock = new Object();
+
/** Gets a lock for the BB */
- public Object getLock();
+ public default Object getLock() {
+ return lock;
+ }
}
Modified: trunk/src/jason/bb/ChainBB.java
===================================================================
--- trunk/src/jason/bb/ChainBB.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/bb/ChainBB.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -90,10 +90,4 @@
}
return r;
}
-
- public final Object lockBB = new Object();
-
- public Object getLock() {
- return lockBB;
- }
}
Modified: trunk/src/jason/bb/DefaultBeliefBase.java
===================================================================
--- trunk/src/jason/bb/DefaultBeliefBase.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/bb/DefaultBeliefBase.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -72,12 +72,6 @@
}
}
- public final Object lockBB = new Object();
-
- public Object getLock() {
- return lockBB;
- }
-
public Set<Atom> getNameSpaces() {
return nameSpaces.keySet();
}
@@ -269,7 +263,10 @@
}
public boolean abolish(PredicateIndicator pi) {
- BelEntry entry = belsMapDefaultNS.remove(pi); // TODO: consider other NS (?) this method is not used by jason
+ return abolish(Literal.DefaultNS, pi);
+ }
+ public boolean abolish(Atom namespace, PredicateIndicator pi) {
+ BelEntry entry = nameSpaces.get(namespace).remove(pi);
if (entry != null) {
size -= entry.size();
@@ -301,14 +298,16 @@
}
public Iterator<Literal> getCandidateBeliefs(PredicateIndicator pi) {
- BelEntry entry = belsMapDefaultNS.get(pi); // TODO: consider other NS ? this method is not used by jason
+ return getCandidateBeliefs(Literal.DefaultNS, pi);
+ }
+ public Iterator<Literal> getCandidateBeliefs(Atom namespace, PredicateIndicator pi) {
+ BelEntry entry = nameSpaces.get(namespace).get(pi);
if (entry != null)
- //return Collections.unmodifiableList(entry.list).iterator();
return entry.list.iterator();
else
return null;
}
-
+
public Iterator<Literal> getCandidateBeliefs(Literal l, Unifier u) {
if (l.isVar()) {
// all bels are relevant
Modified: trunk/src/jason/bb/IndexedBB.java
===================================================================
--- trunk/src/jason/bb/IndexedBB.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/bb/IndexedBB.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -98,10 +98,4 @@
return nbb;
}
- public final Object lockBB = new Object();
-
- public Object getLock() {
- return lockBB;
- }
-
}
Modified: trunk/src/jason/bb/JDBCPersistentBB.java
===================================================================
--- trunk/src/jason/bb/JDBCPersistentBB.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/bb/JDBCPersistentBB.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,22 +1,6 @@
package jason.bb;
import static jason.asSyntax.ASSyntax.createNumber;
-import jason.asSemantics.Agent;
-import jason.asSemantics.Unifier;
-import jason.asSyntax.ASSyntax;
-import jason.asSyntax.ListTerm;
-import jason.asSyntax.ListTermImpl;
-import jason.asSyntax.Literal;
-import jason.asSyntax.LiteralImpl;
-import jason.asSyntax.NumberTerm;
-import jason.asSyntax.NumberTermImpl;
-import jason.asSyntax.PredicateIndicator;
-import jason.asSyntax.StringTerm;
-import jason.asSyntax.StringTermImpl;
-import jason.asSyntax.Structure;
-import jason.asSyntax.Term;
-import jason.asSyntax.parser.ParseException;
-import jason.asSyntax.parser.TokenMgrError;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -36,6 +20,23 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import jason.asSemantics.Agent;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.ASSyntax;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.LiteralImpl;
+import jason.asSyntax.NumberTerm;
+import jason.asSyntax.NumberTermImpl;
+import jason.asSyntax.PredicateIndicator;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.StringTermImpl;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+import jason.asSyntax.parser.ParseException;
+import jason.asSyntax.parser.TokenMgrError;
+
/**
Implementation of BB that stores some beliefs in a relational data base.
@@ -88,6 +89,7 @@
public class JDBCPersistentBB extends ChainBBAdapter {
private static Logger logger = Logger.getLogger(JDBCPersistentBB.class.getName());
+ // TODO: manage namespace
static final String COL_PREFIX = "term";
static final String COL_NEG = "j_negated";
static final String COL_ANNOT = "j_annots";
@@ -115,7 +117,7 @@
public void init(Agent ag, String[] args) {
try {
agentName = ag.getTS().getUserAgArch().getAgName();
- } catch (Exception _) {
+ } catch (Exception e) {
logger.warning("Can not get the agent name!");
agentName = "none";
}
@@ -713,10 +715,4 @@
}
return null;
}
-
- public final Object lockBB = new Object();
-
- public Object getLock() {
- return lockBB;
- }
}
Modified: trunk/src/jason/bb/TextPersistentBB.java
===================================================================
--- trunk/src/jason/bb/TextPersistentBB.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/bb/TextPersistentBB.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,14 +1,14 @@
package jason.bb;
-import jason.asSemantics.Agent;
-import jason.asSyntax.Literal;
-
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
+import jason.asSemantics.Agent;
+import jason.asSyntax.Literal;
+
/**
* Implementation of BB that stores the agent BB in text files. This
* implementation is very simple: when the agent starts, load the
@@ -56,11 +56,4 @@
}
nextBB.stop();
}
-
- public final Object lockBB = new Object();
-
- public Object getLock() {
- return lockBB;
- }
-
}
Modified: trunk/src/jason/control/ExecutionControlGUI.java
===================================================================
--- trunk/src/jason/control/ExecutionControlGUI.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/control/ExecutionControlGUI.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -23,12 +23,6 @@
package jason.control;
-import jason.infra.centralised.RunCentralisedMAS;
-import jason.jeditplugin.Config;
-import jason.util.asl2html;
-import jason.util.asl2tex;
-import jason.util.asl2xml;
-
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
@@ -74,6 +68,12 @@
import org.w3c.dom.Document;
+import jason.infra.centralised.RunCentralisedMAS;
+import jason.util.Config;
+import jason.util.asl2html;
+import jason.util.asl2tex;
+import jason.util.asl2xml;
+
public class ExecutionControlGUI extends ExecutionControl {
String currentAgState = "";
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -214,35 +214,18 @@
i++;
}
- /* TODO execute 1 deed from each intention
- * - use -1 as a parameter for number of cycles
- * - make a clone of the intentions and execute one by one (careful with concurrent access)
- * - careful when intentions are removed/suspended
- * */
+ i = 0;
+ int ca = cyclesAct;
+ if (cyclesAct == 9999)
+ ca = ts.getC().getIntentions().size();
- i = 0;
- if (cyclesAct == 9999) { //TODO adjust parameter for executing one deed from each intention
-
- while (running && i < ts.getC().getIntentions().size()) {
-
- //System.out.println("# Executing one deed from each intention #" + i + " -> " + getTS().getC().getIntentions().size());
-
- if (!ts.act()) {
- return false;
- } else if (ts.canSleepAct()) {
- break;
- }
- i++;
+ while (running && i < ca) {
+ if (!ts.act()) {
+ return false;
+ } else if (ts.canSleepAct()) {
+ break;
}
- } else {
- while (running && i < cyclesAct) {
- if (!ts.act()) {
- return false;
- } else if (ts.canSleepAct()) {
- break;
- }
- i++;
- }
+ i++;
}
return true;
@@ -360,7 +343,8 @@
}
/** called by the TS to ask the execution of an action in the environment */
- public void act(ActionExec action, List<ActionExec> feedback) {
+ @Override
+ public void act(ActionExec action) {
if (logger.isLoggable(Level.FINE)) logger.info("doing: " + action.getActionTerm());
if (isRunning() && infraEnv != null)
infraEnv.act(getAgName(), action);
Modified: trunk/src/jason/infra/centralised/CentralisedMASLauncherAnt.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedMASLauncherAnt.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/infra/centralised/CentralisedMASLauncherAnt.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,10 +1,5 @@
package jason.infra.centralised;
-import jason.jeditplugin.Config;
-import jason.jeditplugin.MASLauncherInfraTier;
-import jason.jeditplugin.RunProjectListener;
-import jason.mas2j.MAS2JProject;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
@@ -13,6 +8,11 @@
import java.text.SimpleDateFormat;
import java.util.Date;
+import jason.jeditplugin.MASLauncherInfraTier;
+import jason.jeditplugin.RunProjectListener;
+import jason.mas2j.MAS2JProject;
+import jason.util.Config;
+
/**
* Write the Ant script to run the MAS in centralised infrastructure and
* start this script.
Modified: trunk/src/jason/infra/centralised/CreateJNLP.java
===================================================================
--- trunk/src/jason/infra/centralised/CreateJNLP.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/infra/centralised/CreateJNLP.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,10 +1,10 @@
package jason.infra.centralised;
-import jason.jeditplugin.Config;
-
import java.io.File;
import java.io.PrintWriter;
+import jason.util.Config;
+
/** creates a JNLP file for a project */
public class CreateJNLP {
public static void main(String[] args) {
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -23,25 +23,6 @@
package jason.infra.centralised;
-import jason.JasonException;
-import jason.asSemantics.Agent;
-import jason.asSyntax.directives.DirectiveProcessor;
-import jason.asSyntax.directives.Include;
-import jason.bb.DefaultBeliefBase;
-import jason.control.ExecutionControlGUI;
-import jason.infra.components.CircumstanceListenerComponents;
-import jason.infra.repl.ReplAgGUI;
-import jason.jeditplugin.Config;
-import jason.mas2j.AgentParameters;
-import jason.mas2j.ClassParameters;
-import jason.mas2j.MAS2JProject;
-import jason.mas2j.parser.ParseException;
-import jason.runtime.MASConsoleGUI;
-import jason.runtime.MASConsoleLogFormatter;
-import jason.runtime.MASConsoleLogHandler;
-import jason.runtime.RuntimeServicesInfraTier;
-import jason.runtime.Settings;
-
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -74,6 +55,25 @@
import javax.swing.JTextArea;
import javax.swing.JTextField;
+import jason.JasonException;
+import jason.asSemantics.Agent;
+import jason.asSyntax.directives.DirectiveProcessor;
+import jason.asSyntax.directives.Include;
+import jason.bb.DefaultBeliefBase;
+import jason.control.ExecutionControlGUI;
+import jason.infra.components.CircumstanceListenerComponents;
+import jason.infra.repl.ReplAgGUI;
+import jason.mas2j.AgentParameters;
+import jason.mas2j.ClassParameters;
+import jason.mas2j.MAS2JProject;
+import jason.mas2j.parser.ParseException;
+import jason.runtime.MASConsoleGUI;
+import jason.runtime.MASConsoleLogFormatter;
+import jason.runtime.MASConsoleLogHandler;
+import jason.runtime.RuntimeServicesInfraTier;
+import jason.runtime.Settings;
+import jason.util.Config;
+
/**
* Runs MASProject using centralised infrastructure.
*/
@@ -719,7 +719,6 @@
}
}
- //TODO here creates one thread for each agent
/** creates one thread per agent */
private void createAgsThreads() {
@@ -736,7 +735,7 @@
cyclesSense = cyclesDeliberate = cyclesAct = Integer.parseInt(project.getInfrastructure().getParameter(1));
}
- logger.info("Creating a threaded agents." + "Cycles: " + cyclesSense + ", " + cyclesDeliberate + ", " + cyclesAct);
+ //logger.info("Creating a threaded agents." + "Cycles: " + cyclesSense + ", " + cyclesDeliberate + ", " + cyclesAct);
}
for (CentralisedAgArch ag : ags.values()) {
Modified: trunk/src/jason/infra/jade/JadeMASLauncherAnt.java
===================================================================
--- trunk/src/jason/infra/jade/JadeMASLauncherAnt.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/infra/jade/JadeMASLauncherAnt.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,14 +1,5 @@
package jason.infra.jade;
-import jason.asSyntax.ASSyntax;
-import jason.asSyntax.Literal;
-import jason.asSyntax.StringTerm;
-import jason.asSyntax.parser.ParseException;
-import jason.infra.centralised.CentralisedMASLauncherAnt;
-import jason.jeditplugin.Config;
-import jason.jeditplugin.MASLauncherInfraTier;
-import jason.mas2j.AgentParameters;
-
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -19,6 +10,15 @@
import java.util.Iterator;
import java.util.Set;
+import jason.asSyntax.ASSyntax;
+import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.parser.ParseException;
+import jason.infra.centralised.CentralisedMASLauncherAnt;
+import jason.jeditplugin.MASLauncherInfraTier;
+import jason.mas2j.AgentParameters;
+import jason.util.Config;
+
/**
* Creates the script build.xml to launch the MAS using JADE.
*/
Modified: trunk/src/jason/infra/jade/JasonBridgeArch.java
===================================================================
--- trunk/src/jason/infra/jade/JasonBridgeArch.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/infra/jade/JasonBridgeArch.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -184,7 +184,7 @@
@Override
- public void act(ActionExec action, List<ActionExec> feedback) {
+ public void act(ActionExec action) { //, List<ActionExec> feedback) {
if (!isRunning()) return;
if (getEnvironmentAg() == null) return;
@@ -244,7 +244,7 @@
} else {
a.setResult(false);
}
- getTS().getC().addFeedbackAction(a);
+ actDone(a);
} else {
logger.log(Level.SEVERE, "Error: received feedback for an Action that is not pending. The message is "+m);
}
Modified: trunk/src/jason/infra/jade/RunJadeMAS.java
===================================================================
--- trunk/src/jason/infra/jade/RunJadeMAS.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/infra/jade/RunJadeMAS.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -23,6 +23,20 @@
package jason.infra.jade;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+
import jade.BootProfileImpl;
import jade.core.Profile;
import jade.core.ProfileImpl;
@@ -39,26 +53,12 @@
import jason.asSyntax.directives.Include;
import jason.control.ExecutionControlGUI;
import jason.infra.centralised.RunCentralisedMAS;
-import jason.jeditplugin.Config;
import jason.mas2j.AgentParameters;
import jason.mas2j.ClassParameters;
import jason.runtime.MASConsoleGUI;
+import jason.util.Config;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-
-
/**
* Runs MASProject using JADE infrastructure.
*
Modified: trunk/src/jason/infra/repl/ReplAgGUI.java
===================================================================
--- trunk/src/jason/infra/repl/ReplAgGUI.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/infra/repl/ReplAgGUI.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -127,7 +127,6 @@
mindPanel.setText(sMind); // show the HTML in the screen
lastMind = sMind;
} catch (Exception e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}*/
Modified: trunk/src/jason/jeditplugin/CheckVersion.java
===================================================================
--- trunk/src/jason/jeditplugin/CheckVersion.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/jeditplugin/CheckVersion.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -16,6 +16,8 @@
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
+import jason.util.Config;
+
public class CheckVersion extends Thread {
public static final String JasonSite = "http://jason.sf.net";
Deleted: trunk/src/jason/jeditplugin/Config.java
===================================================================
--- trunk/src/jason/jeditplugin/Config.java 2016-04-07 16:21:43 UTC (rev 1887)
+++ trunk/src/jason/jeditplugin/Config.java 2016-04-08 19:25:42 UTC (rev 1888)
@@ -1,765 +0,0 @@
-//----------------------------------------------------------------------------
-// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// To contact the authors:
-// http://www.inf.ufrgs.br/~bordini
-// http://www.das.ufsc.br/~jomi
-//
-//----------------------------------------------------------------------------
-
-package jason.jeditplugin;
-
-import jason.asSemantics.Message;
-import jason.asSemantics.TransitionSystem;
-import jason.infra.centralised.CentralisedFactory;
-import jason.infra.jade.JadeFactory;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-/**
- * Jason configuration (used by JasonID to generate the project's scripts)
- *
- * @author jomi
- */
-public class Config extends Properties {
-
- private static final long serialVersionUID = 1L;
-
- /** path to jason.jar */
- public static final String JASON_JAR = "jasonJar";
-
- /** path to ant home (jar directory) */
- public static final String ANT_LIB = "antLib";
-
- /** path to jade.jar */
- public static final String JADE_JAR = "jadeJar";
- public static final String MOISE_JAR = "moiseJar";
- public static final String JACAMO_JAR = "jacamoJar";
-
- /** runtime jade arguments (the same used in jade.Boot) */
- public static final String JADE_ARGS = "jadeArgs";
-
- /** boolean, whether to start jade RMA or not */
- public static final String JADE_RMA = "jadeRMA";
-
- /** boolean, whether to start jade Sniffer or not */
- public static final String JADE_SNIFFER = "jadeSniffer";
-
- /** path to java home */
- public static final String JAVA_HOME = "javaHome";
-
- public static final String RUN_AS_THREAD = "runCentralisedInsideJIDE";
- public static final String SHELL_CMD = "shellCommand";
- public static final String CLOSEALL = "closeAllBeforeOpenMAS2J";
- public static final String CHECK_VERSION = "checkLatestVersion";
- public static final String WARN_SING_VAR = "warnSingletonVars";
-
- public static final String SHOW_ANNOTS = "showAnnots";
-
-
- public static final String jacamoHomeProp = "JaCaMoHome";
-
- public static final String SHORT_UNNAMED_VARS = "shortUnnamedVars";
- public static final String START_WEB_MI = "startWebMindInspector";
-
- public static final String NB_TH_SCH = "numberOfThreadsForScheduler";
-
- public static final String KQML_RECEIVED_FUNCTOR = "kqmlReceivedFunctor";
- public static final String KQML_PLANS_FILE = "kqmlPlansFile";
-
- private static Config singleton = null;
-
- protected static String configFactory = null;
-
- public static void setClassFactory(String f) {
- singleton = null;
- configFactory = f;
- }
-
- public static Config get() {
- return get(true);
- }
- public static Config get(boolean tryToFixConfig) {
- if (singleton == null) {
- if (configFactory == null)
- configFactory = Config.class.getName();
- try {
- singleton = (Config)Class.forName(configFactory).newInstance();
- } catch (Exception e) {
- System.err.println("Error creating config from "+configFactory+"("+e+"), using default.");
- singleton = new Config();
- }
- if (!singleton.load()) {
- if (tryToFixConfig) {
- singleton.fix();
- singleton.store();
- }
- }
- }
- return singleton;
- }
-
- protected Config() {
- }
-
- /** returns the file where the user preferences are stored */
- public File getUserConfFile() {
- return new File(System.getProperties().get("user.home") + File.separator + ".jason/user.properties");
- }
-
- public File getMasterConfFile() {
- return new File("jason.properties");
- }
-
- public String getFileConfComment() {
- return "Jason user configuration";
- }
-
- /** Returns true if the file is loaded correctly */
- public boolean load() {
- try {
- File f = getUserConfFile();
- if (f.exists()) {
- super.load(new FileInputStream(f));
- return true;
- } else { // load master configuration file
- f = getMasterConfFile();
- if (f.exists()) {
- System.out.println("User config file not found, loading master: "+f.getAbsolutePath());
- super.load(new FileInputStream(f));
- return true;
- }
- }
- } catch (Exception e) {
- System.err.println("Error reading preferences");
- e.printStackTrace();
- }
- return false;
- }
-
- public boolean getBoolean(String key) {
- return "true".equals(get(key));
- }
-
- /** Returns the full path to the jason.jar file */
- public String getJasonJar() {
- return getProperty(JASON_JAR);
- }
-
- /** returns the jason home (based on jason.jar) */
- public String getJasonHome() {
- try {
- return new File(getJasonJar()).getParentFile().getParent();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "";
- }
-
- /** Returns the full path to the jade.jar file */
- public String getJadeJar() {
- return getProperty(JADE_JAR);
- }
-
- /** Return the jade args (those used in jade.Boot) */
- public String getJadeArgs() {
- return getProperty(JADE_ARGS);
- }
-
- public String[] getJadeArrayArgs() {
- List<String> ls = new ArrayList<String>();
- String jadeargs = getProperty(JADE_ARGS);
- if (jadeargs != null && jadeargs.length() > 0) {
- StringTokenizer t = new StringTokenizer(jadeargs);
- while (t.hasMoreTokens()) {
- ls.add(t.nextToken());
- }
- }
- String[] as = new String[ls.size()];
- for (int i=0; i<ls.size(); i++) {
- as[i] = ls.get(i);
- }
- return as;
- }
-
- /** Returns the path to the java home directory */
- public String getJavaHome() {
- String h = getProperty(JAVA_HOME);
- if (! h.endsWith(File.separator))
- h += File.separator;
- return h;
- }
-
- /** Returns the path to the ant home directory (where its jars are stored) */
- public String getAntLib() {
- return getProperty(ANT_LIB);
- }
-
- public void setJavaHome(String jh) {
- if (jh != null) {
- jh = new File(jh).getAbsolutePath();
- if (!jh.endsWith(File.separator)) {
- jh += File.separator;
- }
- put(JAVA_HOME, jh);
- }
- }
-
- public void setAntLib(String al) {
- if (al != null) {
- al = new File(al).getAbsolutePath();
- if (!al.endsWith(File.separator)) {
- al += File.separator;
- }
- put(ANT_LIB, al);
- }
- }
-
- public String getShellCommand() {
- return getProperty(SHELL_CMD);
- }
-
- public String getKqmlFunctor() {
- return getProperty(KQML_RECEIVED_FUNCTOR, Message.kqmlReceivedFunctor);
- }
- public String getKqmlPlansFile() {
- return getProperty(KQML_PLANS_FILE, Message.kqmlDefaultPlans);
- }
-
- public void resetSomeProps() {
- //System.out.println("Reseting configuration of "+Config.MOISE_JAR);
- remove(Config.MOISE_JAR);
- //System.out.println("Reseting configuration of "+Config.JASON_JAR);
- remove(Config.JASON_JAR);
- //System.out.println("Reseting configuration of "+Config.JADE_JAR);
- remove(Config.JADE_JAR);
- //System.out.println("Reseting configuration of "+Config.ANT_LIB);
- remove(Config.ANT_LIB);
- put(Config.SHOW_ANNOTS, "false");
- }
-
-
- /** Set most important parameters with default values */
- public void fix() {
- tryToFixJarFileConf(JASON_JAR, "jason.jar", 700000);
- tryToFixJarFileConf(JADE_JAR, "jade.jar", 2000000);
- tryToFixJarFileConf(MOISE_JAR, "moise.jar", 300000);
- tryToFixJarFileConf(JACAMO_JAR, "jacamo.jar", 5000);
- tryToFixJarFileConf(JASON_JAR, "jason.jar", 700000); // in case jacamo is found
-
- // fix java home
- if (get(JAVA_HOME) == null || !checkJavaHomePath(getProperty(JAVA_HOME))) {
- String javaHome = System.getProperty("java.home");
- if (checkJavaHomePath(javaHome)) {
- setJavaHome(javaHome);
- } else {
- String javaEnvHome = System.getenv("JAVA_HOME");
- if (javaEnvHome != null && checkJavaHomePath(javaEnvHome)) {
- setJavaHome(javaEnvHome);
- } else {
- String javaHomeUp = javaHome + File.separator + "..";
- if (checkJavaHomePath(javaHomeUp)) {
- setJavaHome(javaHomeUp);
- } else {
- // try JRE
- if (checkJREHomePath(javaHome)) {
- setJavaHome(javaHome);
- } else {
- setJavaHome(File.separator);
- }
- }
- }
- }
- }
-
- // fix ant lib
- if (get(ANT_LIB) == null || !checkAntLib(getAntLib())) {
- try {
- String jjar = getJasonJar();
- if (jjar != null) {
- String antlib = new File(jjar).getParentFile().getParentFile().getAbsolutePath() + File.separator + "lib";
- if (checkAntLib(antlib)) {
- setAntLib(antlib);
- } else {
- antlib = new File(".") + File.separator + "lib";
- if (checkAntLib(antlib)) {
- setAntLib(antlib);
- } else {
- antlib = new File("..") + File.separator + "lib";
- if (checkAntLib(antlib)) {
- setAntLib(antlib);
- }
- }
- }
- }
- } catch (Exception e) {
- System.out.println("Error setting ant lib!");
- e.printStackTrace();
- }
- }
-
- // Jason version
- put("version", getJasonRunningVersion());
-
- // font
- if (get("font") == null) {
- put("font", "Monospaced");
- }
- if (get("fontSize") == null) {
- put("fontSize", "14");
- }
-
- // shell command
- if (get(SHELL_CMD) == null) {
- if (System.getProperty("os.name").startsWith("Windows 9")) {
- put(SHELL_CMD, "command.com /e:1024 /c ");
- } else if (System.getProperty("os.name").indexOf("indows") > 0) {
- put(SHELL_CMD, "cmd /c ");
- } else {
- put(SHELL_CMD, "/bin/sh ");
- }
- }
-
- // close all
- if (get(CLOSEALL) == null) {
- put(CLOSEALL, "true");
- }
-
- if (get(CHECK_VERSION) == null) {
- put(CHECK_VERSION, "true");
- }
-
- // jade args
- if (getProperty(JADE_RMA) == null) {
- put(JADE_RMA, "true");
- }
-
- // show annots
- if (getProperty(SHOW_ANNOTS) == null) {
- put(SHOW_ANNOTS, "true");
- }
-
- if (getProperty(START_WEB_MI) == null) {
- put(START_WEB_MI, "true");
- }
-
- if (getProperty(NB_TH_SCH) == null) {
- put(NB_TH_SCH, "2");
- }
-
- if (getProperty(SHORT_UNNAMED_VARS) == null) {
- put(SHORT_UNNAMED_VARS,"true");
- }
-
- if (getProperty(KQML_RECEIVED_FUNCTOR) == null) {
- put(KQML_RECEIVED_FUNCTOR, Message.kqmlReceivedFunctor);
- }
-
- if (getProperty(KQML_PLANS_FILE) == null) {
- put(KQML_PLANS_FILE, Message.kqmlDefaultPlans);
- }
-
- // Default infrastructures
- put("infrastructure.Centralised", CentralisedFactory.class.getName());
- put("infrastructure.Jade", JadeFactory.class.getName());
- put("infrastructure.JaCaMo", "jacamo.infra.JaCaMoInfrastructureFactory");
-
- }
-
- public void store() {
- store(getUserConfFile());
- }
-
- public void store(File f) {
- try {
- if (!f.getParentFile().exists()) {
- f.getParentFile().mkdirs();
- }
- System.out.println("Storing configuration at "+f);
- super.store(new FileOutputStream(f), getFileConfComment());
- } catch (Exception e) {
- System.err.println("Error writting preferences");
- e.printStackTrace();
- }
- }
-
- public String[] getAvailableInfrastructures() {
- try {
- List<String> infras = new ArrayList<String>();
- infras.add("Centralised"); // set Centralised as the first
- for (Object k: keySet()) {
- String sk = k.toString();
- int p = sk.indexOf(".");
- if (p > 0 && sk.startsWith("infrastructure") && p == sk.lastIndexOf(".")) { // only one "."
- String newinfra = sk.substring(p+1);
- if (!infras.contains(newinfra)) {
- infras.add(newinfra);
- }
- }
- }
- if (infras.size() > 0) {
- // copy infras to a array
- String[] r = new String[infras.size()];
- for (int i=0; i<r.length; i++) {
- r[i] = infras.get(i);
- }
- return r;
- }
- } catch (Exception e) {
- System.err.println("Error getting user infrastructures.");
- }
- return new String[] {"Centralised","Jade","JaCaMo"};
- }
-
- public String getInfrastructureFactoryClass(String infraId) {
- return get("infrastructure." + infraId).toString();
- }
- public void setInfrastructureFactoryClass(String infraId, String factory) {
- put("infrastructure." + infraId, factory);
- }
- public void removeInfrastructureFactoryClass(String infraId) {
- remove("infrastructure." + infraId);
- }
-
-
- public String getDistPropFile() {
- return "/dist.properties";
- }
-
- public String getJasonRunningVersion() {
- try {
- Properties p = new Properties();
- p.load(Config.class.getResource(getDistPropFile()).openStream());
- return p.getProperty("version") + "." + p.getProperty("release");
- } catch (Exception ex1) {
- try {
- Properties p = new Properties();
- System.out.println("try 2 "+ex1);
- ex1.printStackTrace();
- p.load(new FileReader("bin"+getDistPropFile()));
- return p.getProperty("version") + "." + p.getProperty("release");
- } catch (Exception ex2) {
- System.out.println("*"+ex2);
- return "?";
- }
- }
- }
-
- public String getJasonBuiltDate() {
- try {
- Properties p = new Properties();
- p.load(Config.class.getResource("/dist.properties").openStream());
- return p.get("build.date").toString();
- } catch (Exception ex) {
- return "?";
- }
- }
-
- void tryToFixJarFileConf(String jarEntry, String jarName, int minSize) {
- String jarFile = getProperty(jarEntry);
- if (jarFile == null || !checkJar(jarFile, minSize)) {
- System.out.println("Wrong configuration for " + jarName + ", current is " + jarFile);
-
- // try eclipse installation
- jarFile = getJarFromEclipseInstallation(jarName);
- if (checkJar(jarFile, minSize)) {
- put(jarEntry, jarFile);
- System.out.println("found at " + jarFile+" in eclipse installation");
- return;
- }
-
- // try to get from classpath
- jarFile = getJarFromClassPath(jarName);
- if (checkJar(jarFile, minSize)) {
- put(jarEntry, jarFile);
- System.out.println("found at " + jarFile+" by classpath");
- return;
- }
-
- try {
- // try jason jar
- File jasonjard...
[truncated message content] |
|
From: <jom...@us...> - 2016-04-07 16:21:47
|
Revision: 1887
http://sourceforge.net/p/jason/svn/1887
Author: jomifred
Date: 2016-04-07 16:21:43 +0000 (Thu, 07 Apr 2016)
Log Message:
-----------
include async arch
Modified Paths:
--------------
trunk/demos/cArtAgOandJasonEnv/cArtAgOandJasonEnv.mas2j
trunk/lib/jacamo.jar
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSemantics/Circumstance.java
trunk/src/jason/asSemantics/ConcurrentInternalAction.java
trunk/src/jason/asSemantics/GoalListenerForMetaEvents.java
trunk/src/jason/asSemantics/Intention.java
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/infra/centralised/CentralisedEnvironment.java
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
Added Paths:
-----------
trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java
trunk/src/jason/infra/components/
trunk/src/jason/infra/components/ActComponent.java
trunk/src/jason/infra/components/AgentComponent.java
trunk/src/jason/infra/components/CircumstanceListenerComponents.java
trunk/src/jason/infra/components/DeliberateComponent.java
trunk/src/jason/infra/components/SenseComponent.java
Modified: trunk/demos/cArtAgOandJasonEnv/cArtAgOandJasonEnv.mas2j
===================================================================
--- trunk/demos/cArtAgOandJasonEnv/cArtAgOandJasonEnv.mas2j 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/demos/cArtAgOandJasonEnv/cArtAgOandJasonEnv.mas2j 2016-04-07 16:21:43 UTC (rev 1887)
@@ -1,5 +1,5 @@
/*
- * This example shows how to develop an aplication that
+ * This example shows how to develop an application that
* uses both
* - a usual Jason environment and
* - a CArtAgO environment
Modified: trunk/lib/jacamo.jar
===================================================================
(Binary files differ)
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/asSemantics/Agent.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -274,7 +274,10 @@
}
public void stopAg() {
- bb.stop();
+ synchronized (bb.getLock()) {
+ bb.stop();
+ }
+
//if (qProfiling != null)
// qProfiling.show();
@@ -313,7 +316,9 @@
if (this.getTS().getSettings().verbose() >= 0)
a.logger.setLevel(this.getTS().getSettings().logLevel());
- a.bb = this.bb.clone();
+ synchronized (getBB().getLock()) {
+ a.bb = this.bb.clone();
+ }
a.pl = this.pl.clone();
try {
fixAgInIAandFunctions(a);
@@ -332,14 +337,16 @@
private void fixAgInIAandFunctions(Agent a) throws Exception {
// find all internal actions and functions and change the pointer for agent
- for (Plan p: a.getPL()) {
- // search context
- if (p.getContext() instanceof Literal)
- fixAgInIAandFunctions(a, (Literal)p.getContext());
-
- // search body
- if (p.getBody() instanceof Literal)
- fixAgInIAandFunctions(a, (Literal)p.getBody());
+ synchronized (getPL().getLock()) {
+ for (Plan p: a.getPL()) {
+ // search context
+ if (p.getContext() instanceof Literal)
+ fixAgInIAandFunctions(a, (Literal)p.getContext());
+
+ // search body
+ if (p.getBody() instanceof Literal)
+ fixAgInIAandFunctions(a, (Literal)p.getBody());
+ }
}
}
@@ -620,7 +627,7 @@
for (Literal g: a.initialGoals)
this.addInitialGoal(g);
-
+
for (Plan p: a.getPL())
this.getPL().add(p, false);
@@ -870,18 +877,20 @@
* The unifier <i>un</i> is updated by the method.
*/
public Literal findBel(Literal bel, Unifier un) {
- Iterator<Literal> relB = bb.getCandidateBeliefs(bel, un);
- if (relB != null) {
- while (relB.hasNext()) {
- Literal b = relB.next();
-
- // recall that order is important because of annotations!
- if (!b.isRule() && un.unifies(bel, b)) {
- return b;
+ synchronized (bb.getLock()) {
+ Iterator<Literal> relB = bb.getCandidateBeliefs(bel, un);
+ if (relB != null) {
+ while (relB.hasNext()) {
+ Literal b = relB.next();
+
+ // recall that order is important because of annotations!
+ if (!b.isRule() && un.unifies(bel, b)) {
+ return b;
+ }
}
- }
- }
- return null;
+ }
+ return null;
+ }
}
@@ -918,46 +927,48 @@
position = 1;
List<Literal>[] result = null;
- try {
- if (beliefToAdd != null) {
- if (logger.isLoggable(Level.FINE)) logger.fine("Doing (add) brf for " + beliefToAdd);
-
- if (getBB().add(position, beliefToAdd)) {
- result = new List[2];
- result[0] = Collections.singletonList(beliefToAdd);
- result[1] = Collections.emptyList();
+ synchronized (bb.getLock()) {
+ try {
+ if (beliefToAdd != null) {
+ if (logger.isLoggable(Level.FINE)) logger.fine("Doing (add) brf for " + beliefToAdd);
+
+ if (getBB().add(position, beliefToAdd)) {
+ result = new List[2];
+ result[0] = Collections.singletonList(beliefToAdd);
+ result[1] = Collections.emptyList();
+ }
}
- }
-
- if (beliefToDel != null) {
- Unifier u = null;
- try {
- u = i.peek().unif; // get from current intention
- } catch (Exception e) {
- u = new Unifier();
- }
-
- if (logger.isLoggable(Level.FINE)) logger.fine("Doing (del) brf for " + beliefToDel + " in BB=" + believes(beliefToDel, u));
-
- boolean removed = getBB().remove(beliefToDel);
- if (!removed && !beliefToDel.isGround()) { // then try to unify the parameter with a belief in BB
- if (believes(beliefToDel, u)) {
- beliefToDel = (Literal)beliefToDel.capply(u);
- removed = getBB().remove(beliefToDel);
+
+ if (beliefToDel != null) {
+ Unifier u = null;
+ try {
+ u = i.peek().unif; // get from current intention
+ } catch (Exception e) {
+ u = new Unifier();
}
- }
+
+ if (logger.isLoggable(Level.FINE)) logger.fine("Doing (del) brf for " + beliefToDel + " in BB=" + believes(beliefToDel, u));
- if (removed) {
- if (logger.isLoggable(Level.FINE)) logger.fine("Removed:" + beliefToDel);
- if (result == null) {
- result = new List[2];
- result[0] = Collections.emptyList();
+ boolean removed = getBB().remove(beliefToDel);
+ if (!removed && !beliefToDel.isGround()) { // then try to unify the parameter with a belief in BB
+ if (believes(beliefToDel, u)) {
+ beliefToDel = (Literal)beliefToDel.capply(u);
+ removed = getBB().remove(beliefToDel);
+ }
}
- result[1] = Collections.singletonList(beliefToDel);
+
+ if (removed) {
+ if (logger.isLoggable(Level.FINE)) logger.fine("Removed:" + beliefToDel);
+ if (result == null) {
+ result = new List[2];
+ result[0] = Collections.emptyList();
+ }
+ result[1] = Collections.singletonList(beliefToDel);
+ }
}
+ } catch (Exception e) {
+ logger.log(Level.WARNING, "Error at BRF.",e);
}
- } catch (Exception e) {
- logger.log(Level.WARNING, "Error at BRF.",e);
}
return result;
}
@@ -1003,22 +1014,24 @@
public void abolish(Literal bel, Unifier un) throws RevisionFailedException {
List<Literal> toDel = new ArrayList<Literal>();
if (un == null) un = new Unifier();
- Iterator<Literal> il = getBB().getCandidateBeliefs(bel, un);
- if (il != null) {
- while (il.hasNext()) {
- Literal inBB = il.next();
- if (!inBB.isRule()) {
- // need to clone unifier since it is changed in previous iteration
- if (un.clone().unifiesNoUndo(bel, inBB)) {
- toDel.add(inBB);
+ synchronized (bb.getLock()) {
+ Iterator<Literal> il = getBB().getCandidateBeliefs(bel, un);
+ if (il != null) {
+ while (il.hasNext()) {
+ Literal inBB = il.next();
+ if (!inBB.isRule()) {
+ // need to clone unifier since it is changed in previous iteration
+ if (un.clone().unifiesNoUndo(bel, inBB)) {
+ toDel.add(inBB);
+ }
}
}
}
+
+ for (Literal l: toDel) {
+ delBel(l);
+ }
}
-
- for (Literal l: toDel) {
- delBel(l);
- }
}
private void checkCustomSelectOption() {
Modified: trunk/src/jason/asSemantics/Circumstance.java
===================================================================
--- trunk/src/jason/asSemantics/Circumstance.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/asSemantics/Circumstance.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -39,7 +39,6 @@
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.CopyOnWriteArrayList;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -68,10 +67,12 @@
private Map<String, Intention> PI; // pending intentions, intentions suspended by any other reason
private Map<String, Event> PE; // pending events, events suspended by .suspend
- private List<CircumstanceListener> listeners = new CopyOnWriteArrayList<CircumstanceListener>();
+ private Queue<CircumstanceListener> listeners = new ConcurrentLinkedQueue<CircumstanceListener>();
private TransitionSystem ts = null;
+ public Object syncApPlanSense = new Object();
+
public Circumstance() {
create();
reset();
@@ -95,14 +96,26 @@
/** set null for A, RP, AP, SE, SO, and SI */
public void reset() {
- A = null;
+ resetSense();
+ resetDeliberate();
+ resetAct();
+ }
+
+ public void resetSense() {
+ }
+
+ public void resetDeliberate() {
RP = null;
AP = null;
SE = null;
- SO = null;
+ SO = null;
+ }
+
+ public void resetAct() {
+ A = null;
SI = null;
}
-
+
public Event addAchvGoal(Literal l, Intention i) {
Event evt = new Event(new Trigger(TEOperator.add, TEType.achieve, l), i);
addEvent(evt);
Modified: trunk/src/jason/asSemantics/ConcurrentInternalAction.java
===================================================================
--- trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -94,7 +94,7 @@
if (timeout > 0) {
// schedule a future test of the end of the action
- ts.getAg().getScheduler().schedule( new Runnable() {
+ Agent.getScheduler().schedule( new Runnable() {
public void run() {
// finish the IA by timeout
if (C.getPendingIntentions().get(key) != null) { // test if the intention is still there
@@ -107,7 +107,7 @@
}
public void startInternalAction(TransitionSystem ts, Runnable code) {
- ts.getAg().getScheduler().execute(code);
+ Agent.getScheduler().execute(code);
//new Thread(code).start();
}
@@ -147,7 +147,7 @@
}
}
});
- ts.getUserAgArch().wake();
+ ts.getUserAgArch().wakeUpDeliberate(false);
}
public void destroy() throws Exception {
Modified: trunk/src/jason/asSemantics/GoalListenerForMetaEvents.java
===================================================================
--- trunk/src/jason/asSemantics/GoalListenerForMetaEvents.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/asSemantics/GoalListenerForMetaEvents.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -47,8 +47,9 @@
Trigger eEnd = new Trigger(TEOperator.goalState, type, newGoal);
if (ts.getAg().getPL().hasCandidatePlan(eEnd))
ts.getC().insertMetaEvent(new Event(eEnd, null));
+
}
});
+ ts.getUserAgArch().wakeUpDeliberate(false);
}
-
}
Modified: trunk/src/jason/asSemantics/Intention.java
===================================================================
--- trunk/src/jason/asSemantics/Intention.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/asSemantics/Intention.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -176,19 +176,21 @@
Trigger failTrigger = new Trigger(TEOperator.del, tevent.getType(), tevent.getLiteral());
Iterator<IntendedMeans> ii = iterator();
int posInStak = size();
- while (!pl.hasCandidatePlan(failTrigger) && ii.hasNext()) {
- // TODO: pop IM until +!g or *!g (this TODO is valid only if meta events are pushed on top of the intention)
- // If *!g is found first, no failure event
- // - while popping, if some meta event (* > !) is in the stack, stop and simple pop instead of producing an failure event
- IntendedMeans im = ii.next();
- tevent = im.getTrigger();
- failTrigger = new Trigger(TEOperator.del, tevent.getType(), tevent.getLiteral());
- posInStak--;
+ synchronized (pl.getLock()) {
+ while (!pl.hasCandidatePlan(failTrigger) && ii.hasNext()) {
+ // TODO: pop IM until +!g or *!g (this TODO is valid only if meta events are pushed on top of the intention)
+ // If *!g is found first, no failure event
+ // - while popping, if some meta event (* > !) is in the stack, stop and simple pop instead of producing an failure event
+ IntendedMeans im = ii.next();
+ tevent = im.getTrigger();
+ failTrigger = new Trigger(TEOperator.del, tevent.getType(), tevent.getLiteral());
+ posInStak--;
+ }
+ if (tevent.isGoal() && tevent.isAddition() && pl.hasCandidatePlan(failTrigger))
+ return new Pair<Event, Integer>(new Event(failTrigger.clone(), this), posInStak);
+ else
+ return new Pair<Event, Integer>(null, 0);
}
- if (tevent.isGoal() && tevent.isAddition() && pl.hasCandidatePlan(failTrigger))
- return new Pair<Event, Integer>(new Event(failTrigger.clone(), this), posInStak);
- else
- return new Pair<Event, Integer>(null, 0);
}
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -53,6 +53,7 @@
import jason.asSyntax.VarTerm;
import jason.asSyntax.parser.ParseException;
import jason.bb.BeliefBase;
+import jason.infra.centralised.CentralisedAgArchAsynchronous;
import jason.jeditplugin.Config;
import jason.runtime.Settings;
import jason.stdlib.add_nested_source;
@@ -82,7 +83,13 @@
private AgArch agArch = null;
private Circumstance C = null;
private Settings setts = null;
- private State step = State.StartRC; // first step of the SOS
+ //private State step = State.StartRC; // first step of the SOS
+
+ private State stepSense = State.StartRC;
+ private State stepDeliberate = State.SelEv;
+ private State stepAct = State.ProcAct;
+
+
private int nrcslbr = Settings.ODefaultNRC; // number of reasoning cycles since last belief revision
private boolean sleepingEvt = false;
@@ -205,7 +212,42 @@
/** ******************************************************************* */
/* SEMANTIC RULES */
/** ******************************************************************* */
+
+ private void applySemanticRuleSense() throws JasonException {
+ switch (stepSense) {
+ case StartRC: applyProcMsg(); break;
+ default:
+ break;
+ }
+ }
+
+ private void applySemanticRuleDeliberate() throws JasonException {
+ switch (stepDeliberate) {
+ case SelEv: applySelEv(); break;
+ case RelPl: applyRelPl(); break;
+ case ApplPl: applyApplPl(); break;
+ case SelAppl: applySelAppl(); break;
+ case FindOp: applyFindOp(); break;
+ case AddIM: applyAddIM(); break;
+ default:
+ break;
+ }
+ }
+ private void applySemanticRuleAct() throws JasonException {
+ switch (stepAct) {
+ case ProcAct: applyProcAct(); break;
+ case SelInt: applySelInt(); break;
+ case ExecInt: applyExecInt(); break;
+ case ClrInt: confP.stepAct = State.StartRC;
+ applyClrInt(conf.C.SI);
+ break;
+ default:
+ break;
+ }
+ }
+
+ /*
private void applySemanticRule() throws JasonException {
// check the current step in the reasoning cycle
// only the main parts of the interpretation appear here
@@ -227,13 +269,14 @@
break;
}
}
+ */
// the semantic rules are referred to in comments in the functions below
private final String kqmlReceivedFunctor = Config.get().getKqmlFunctor();
private void applyProcMsg() throws JasonException {
- confP.step = State.SelEv;
+ confP.stepSense = State.SelEv;
if (conf.C.hasMsg()) {
Message m = conf.ag.selectMessage(conf.C.getMailBox());
if (m == null) return;
@@ -355,14 +398,14 @@
// Rule for atomic, if there is an atomic intention, do not select event
if (C.hasAtomicIntention()) {
- confP.step = State.ProcAct; // need to go to ProcAct to see if an atomic intention received a feedback action
+ confP.stepDeliberate = State.ProcAct; // need to go to ProcAct to see if an atomic intention received a feedback action
return;
}
// Rule for atomic, events from atomic intention have priority
confP.C.SE = C.removeAtomicEvent();
if (confP.C.SE != null) {
- confP.step = State.RelPl;
+ confP.stepDeliberate = State.RelPl;
return;
}
@@ -373,15 +416,15 @@
logger.fine("Selected event "+confP.C.SE);
if (confP.C.SE != null) {
if (ag.hasCustomSelectOption() || setts.verbose() == 2) // verbose == 2 means debug mode
- confP.step = State.RelPl;
+ confP.stepDeliberate = State.RelPl;
else
- confP.step = State.FindOp;
+ confP.stepDeliberate = State.FindOp;
return;
}
}
// Rule SelEv2
// directly to ProcAct if no event to handle
- confP.step = State.ProcAct;
+ confP.stepDeliberate = State.ProcAct;
}
private void applyRelPl() throws JasonException {
@@ -391,7 +434,7 @@
// Rule Rel1
if (confP.C.RP != null || setts.retrieve())
// retrieve is mainly for Coo-AgentSpeak
- confP.step = State.ApplPl;
+ confP.stepDeliberate = State.ApplPl;
else
applyRelApplPlRule2("relevant");
}
@@ -402,14 +445,14 @@
// Rule Appl1
if (confP.C.AP != null || setts.retrieve())
// retrieve is mainly for Coo-AgentSpeak
- confP.step = State.SelAppl;
+ confP.stepDeliberate = State.SelAppl;
else
applyRelApplPlRule2("applicable");
}
/** generates goal deletion event */
private void applyRelApplPlRule2(String m) throws JasonException {
- confP.step = State.ProcAct; // default next step
+ confP.stepDeliberate = State.ProcAct; // default next step
if (conf.C.SE.trigger.isGoal() && !conf.C.SE.trigger.isMetaEvent()) {
// can't carry on, no relevant/applicable plan.
try {
@@ -431,16 +474,16 @@
// the programmer just wanted to add the belief and it was
// relevant by chance, so just carry on instead of dropping the
// intention
- confP.C.SI = conf.C.SE.intention;
- joinRenamedVarsIntoIntentionUnifier(confP.C.SI.peek(), confP.C.SI.peek().unif);
- updateIntention();
+ Intention i = conf.C.SE.intention;
+ joinRenamedVarsIntoIntentionUnifier(i.peek(), i.peek().unif);
+ updateIntention(i);
} else if (setts.requeue()) {
// if external, then needs to check settings
confP.C.addEvent(conf.C.SE);
} else {
// current event is external and irrelevant,
// discard that event and select another one
- confP.step = State.SelEv;
+ confP.stepDeliberate = State.SelEv;
}
}
@@ -450,13 +493,13 @@
confP.C.SO = conf.ag.selectOption(confP.C.AP);
if (confP.C.SO != null) {
- confP.step = State.AddIM;
+ confP.stepDeliberate = State.AddIM;
if (logger.isLoggable(Level.FINE)) logger.fine("Selected option "+confP.C.SO+" for event "+confP.C.SE);
} else {
logger.fine("** selectOption returned null!");
generateGoalDeletionFromEvent(JasonException.createBasicErrorAnnots("no_option", "selectOption returned null"));
// can't carry on, no applicable plan.
- confP.step = State.ProcAct;
+ confP.stepDeliberate = State.ProcAct;
}
}
@@ -468,7 +511,7 @@
* @since 1.1
*/
private void applyFindOp() throws JasonException {
- confP.step = State.AddIM; // default next step
+ confP.stepDeliberate = State.AddIM; // default next step
// get all relevant plans for the selected event
//Trigger te = (Trigger) conf.C.SE.trigger.clone();
@@ -526,8 +569,6 @@
Term t = top.unif.get(vvl);
if (t != null) { // if v has got a value in top unif, put the value in the unifier
if (t instanceof Literal) {
- //Literal l= (Literal)t.clone();
- //l.apply(top.unif);
Literal l= (Literal)t.capply(top.unif);
l.makeVarsAnnon(top.renamedVars);
im.unif.function.put(vvl, l);
@@ -550,11 +591,11 @@
confP.C.SE.intention.push(im);
confP.C.addIntention(confP.C.SE.intention);
}
- confP.step = State.ProcAct;
+ confP.stepDeliberate = State.ProcAct;
}
private void applyProcAct() throws JasonException {
- confP.step = State.SelInt; // default next step
+ confP.stepAct = State.SelInt; // default next step
if (conf.C.hasFeedbackAction()) {
ActionExec a = null;
synchronized (conf.C.getFeedbackActions()) {
@@ -569,7 +610,7 @@
if (C.removePendingAction(confP.C.SI.getId()) != null) {
if (a.getResult()) {
// add the intention back in I
- updateIntention();
+ updateIntention(conf.C.SI);
applyClrInt(confP.C.SI);
if (hasGoalListener())
@@ -593,7 +634,7 @@
}
private void applySelInt() throws JasonException {
- confP.step = State.ExecInt; // default next step
+ confP.stepAct = State.ExecInt; // default next step
// Rule for Atomic Intentions
confP.C.SI = C.removeAtomicIntention();
@@ -611,12 +652,12 @@
}
}
- confP.step = State.StartRC;
+ confP.stepAct = State.StartRC;
}
@SuppressWarnings("unchecked")
private void applyExecInt() throws JasonException {
- confP.step = State.ClrInt; // default next step
+ confP.stepAct = State.ClrInt; // default next step
if (conf.C.SI.isFinished()) {
return;
@@ -629,7 +670,7 @@
if (im.isFinished()) {
// for empty plans! may need unif, etc
- updateIntention();
+ updateIntention(conf.C.SI);
return;
}
Unifier u = im.unif;
@@ -669,7 +710,6 @@
if (bTerm instanceof Literal)
body = (Literal)bTerm;
-
switch (h.getBodyType()) {
case none: break;
@@ -703,7 +743,7 @@
}
if (ok && !ia.suspendIntention())
- updateIntention();
+ updateIntention(conf.C.SI);
} catch (JasonException e) {
errorAnnots = e.getErrorTerms();
if (!generateGoalDeletion(conf.C.SI, errorAnnots))
@@ -724,7 +764,7 @@
Iterator<Unifier> iu = ((LogicalFormula)bTerm).logicalConsequence(ag, u);
if (iu.hasNext()) {
im.unif = iu.next();
- updateIntention();
+ updateIntention(conf.C.SI);
} else {
String msg = "Constraint "+h+" was not satisfied ("+h.getSrcInfo()+") un="+u;
generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots(new Atom("constraint_failed"), msg));
@@ -736,7 +776,7 @@
case achieve:
body = prepareBodyForEvent(body, u, conf.C.SI.peek());
Event evt = conf.C.addAchvGoal(body, conf.C.SI);
- confP.step = State.StartRC;
+ confP.stepAct = State.StartRC;
checkHardDeadline(evt);
break;
@@ -745,14 +785,14 @@
body = prepareBodyForEvent(body, u, null);
evt = conf.C.addAchvGoal(body, Intention.EmptyInt);
checkHardDeadline(evt);
- updateIntention();
+ updateIntention(conf.C.SI);
break;
// Rule Test
case test:
LogicalFormula f = (LogicalFormula)bTerm;
if (conf.ag.believes(f, u)) {
- updateIntention();
+ updateIntention(conf.C.SI);
} else {
boolean fail = true;
// generate event when using literal in the test (no events for log. expr. like ?(a & b))
@@ -764,7 +804,7 @@
if (ag.getPL().hasCandidatePlan(te)) {
if (logger.isLoggable(Level.FINE)) logger.fine("Test Goal '" + h + "' failed as simple query. Generating internal event for it: "+te);
conf.C.addEvent(evt);
- confP.step = State.StartRC;
+ confP.stepAct = State.StartRC;
fail = false;
}
}
@@ -825,10 +865,10 @@
// generate events
updateEvents(result,newfocus);
if (!isSameFocus) {
- updateIntention();
+ updateIntention(conf.C.SI);
}
} else {
- updateIntention();
+ updateIntention(conf.C.SI);
}
} catch (RevisionFailedException re) {
generateGoalDeletion(conf.C.SI, null);
@@ -851,10 +891,10 @@
// generate events
updateEvents(result,newfocus);
if (!setts.sameFocus()) {
- updateIntention();
+ updateIntention(conf.C.SI);
}
} else {
- updateIntention();
+ updateIntention(conf.C.SI);
}
} catch (RevisionFailedException re) {
generateGoalDeletion(conf.C.SI, null);
@@ -1025,36 +1065,38 @@
}
public List<Option> applicablePlans(List<Option> rp) throws JasonException {
- List<Option> ap = null;
- if (rp != null) {
- //ap = new ApplPlanTimeOut().get(rp);
-
- for (Option opt: rp) {
- LogicalFormula context = opt.getPlan().getContext();
- if (context == null) { // context is true
- if (ap == null) ap = new LinkedList<Option>();
- ap.add(opt);
- } else {
- boolean allUnifs = opt.getPlan().isAllUnifs();
- Iterator<Unifier> r = context.logicalConsequence(ag, opt.getUnifier());
- if (r != null) {
- while (r.hasNext()) {
- opt.setUnifier(r.next());
-
- if (ap == null) ap = new LinkedList<Option>();
- ap.add(opt);
-
- if (!allUnifs) break; // returns only the first unification
- if (r.hasNext()) {
- // create a new option for the next loop step
- opt = new Option(opt.getPlan(), null);
+ synchronized (C.syncApPlanSense) {
+ List<Option> ap = null;
+ if (rp != null) {
+ //ap = new ApplPlanTimeOut().get(rp);
+
+ for (Option opt: rp) {
+ LogicalFormula context = opt.getPlan().getContext();
+ if (context == null) { // context is true
+ if (ap == null) ap = new LinkedList<Option>();
+ ap.add(opt);
+ } else {
+ boolean allUnifs = opt.getPlan().isAllUnifs();
+ Iterator<Unifier> r = context.logicalConsequence(ag, opt.getUnifier());
+ if (r != null) {
+ while (r.hasNext()) {
+ opt.setUnifier(r.next());
+
+ if (ap == null) ap = new LinkedList<Option>();
+ ap.add(opt);
+
+ if (!allUnifs) break; // returns only the first unification
+ if (r.hasNext()) {
+ // create a new option for the next loop step
+ opt = new Option(opt.getPlan(), null);
+ }
}
}
}
- }
- }
+ }
+ }
+ return ap;
}
- return ap;
}
public void updateEvents(List<Literal>[] result, Intention focus) {
@@ -1084,10 +1126,10 @@
}
/** remove the top action and requeue the current intention */
- private void updateIntention() {
- if (!conf.C.SI.isFinished()) {
- conf.C.SI.peek().removeCurrentStep();
- confP.C.addIntention(conf.C.SI);
+ private void updateIntention(Intention i) {
+ if (!i.isFinished()) {
+ i.peek().removeCurrentStep();
+ confP.C.addIntention(i);
} else {
logger.fine("trying to update a finished intention!");
}
@@ -1251,7 +1293,7 @@
e1.printStackTrace();
}
- getAg().getScheduler().schedule(new Runnable() {
+ Agent.getScheduler().schedule(new Runnable() {
public void run() {
runAtBeginOfNextCycle(new Runnable() {
public void run() {
@@ -1271,7 +1313,7 @@
}
}
});
- getUserAgArch().wake();
+ getUserAgArch().wakeUpSense(false);
}
}, deadline, TimeUnit.MILLISECONDS);
}
@@ -1330,9 +1372,21 @@
|| (!conf.C.hasEvent() && !conf.C.hasIntention() &&
!conf.C.hasFeedbackAction() &&
!conf.C.hasMsg() &&
- //taskForBeginOfCycle.isEmpty() &&
+ taskForBeginOfCycle.isEmpty() &&
getUserAgArch().canSleep());
}
+
+ public boolean canSleepSense() {
+ return !C.hasMsg() && getUserAgArch().canSleep();
+ }
+
+ public boolean canSleepDeliberate() {
+ return !C.hasEvent() && taskForBeginOfCycle.isEmpty() && C.getSelectedEvent() == null && getUserAgArch().canSleep();
+ }
+
+ public boolean canSleepAct() {
+ return !C.hasIntention() && !C.hasFeedbackAction() && !C.hasPendingAction() && C.getSelectedIntention() == null && getUserAgArch().canSleep();
+ }
/**
* Schedule a task to be executed in the begin of the next reasoning cycle.
@@ -1349,14 +1403,132 @@
/* plus the other parts of the agent architecture besides */
/* the actual transition system of the AS interpreter */
/**********************************************************************/
- //Circumstance pc1, pc2, pc3, pc4;
+ public boolean reasoningCycle() {
+ if (!sense())
+ return false;
+ if (!deliberate())
+ return false;
+ if (!act())
+ return false;
+
+ return true;
+ }
+ public boolean sense() {
+ try {
+ if (logger.isLoggable(Level.FINE)) logger.fine("Start new reasoning cycle");
+ getUserAgArch().reasoningCycleStarting();
+
+ C.resetSense();
+
+ if (nrcslbr >= setts.nrcbp()) {
+ nrcslbr = 0;
+ synchronized (C.syncApPlanSense) {
+ ag.buf(getUserAgArch().perceive());
+ }
+ getUserAgArch().checkMail();
+ }
+ nrcslbr++; // counting number of cycles since last belief revision
+
+ if (!(getUserAgArch() instanceof CentralisedAgArchAsynchronous)) {
+ if (canSleep()) {
+ if (!sleepingEvt) {
+ sleepingEvt = true;
+ if (ag.pl.getCandidatePlans(PlanLibrary.TE_JAG_SLEEPING) != null)
+ C.addExternalEv(PlanLibrary.TE_JAG_SLEEPING);
+ } else {
+ getUserAgArch().sleep();
+ return false;
+ }
+ } else if (sleepingEvt) { // code to turn idleEvt false again
+ if (C.hasMsg()) { // the agent has messages
+ sleepingEvt = false;
+ } else if (C.hasEvent()) {
+ // check if there is an event in C.E not produced by idle intention
+ for (Event e: C.getEvents()) {
+ Intention i = e.getIntention();
+ if ( !e.getTrigger().equals(PlanLibrary.TE_JAG_SLEEPING)
+ ||
+ (i != null && i.hasTrigger(PlanLibrary.TE_JAG_SLEEPING, new Unifier()))
+ ) {
+ sleepingEvt = false;
+ break;
+ }
+ }
+ }
+ if (!sleepingEvt && ag.pl.getCandidatePlans(PlanLibrary.TE_JAG_AWAKING) != null) {
+ C.addExternalEv(PlanLibrary.TE_JAG_AWAKING);
+ }
+ }
+ }
+
+ stepSense = State.StartRC;
+ do {
+ if (!getUserAgArch().isRunning()) return false;
+ applySemanticRuleSense();
+ } while (stepSense != State.SelEv);
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "*** ERROR in the transition system (sense). "+conf.C+"\nCreating a new C!", e);
+ conf.C.create();
+ }
+ return true;
+ }
+ public boolean deliberate() {
+ try {
+ C.resetDeliberate();
+
+ // run tasks allocated to be performed in the begin of the cycle
+ Runnable r = taskForBeginOfCycle.poll();
+ while (r != null) {
+ r.run(); //It is processed only things related to operations on goals/intentions resumed/suspended/finished It can be placed in the deliberate stage, but the problem is the sleep when the synchronous execution is adopted
+ r = taskForBeginOfCycle.poll();
+ }
+
+ stepDeliberate = State.SelEv;
+ do {
+ if (!getUserAgArch().isRunning()) return false;
+ applySemanticRuleDeliberate();
+ } while (stepDeliberate != State.ProcAct);
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "*** ERROR in the transition system (deliberate). "+conf.C+"\nCreating a new C!", e);
+ conf.C.create();
+ }
+ return true;
+ }
+
+ public boolean act() {
+ try {
+ C.resetAct();
+
+ stepAct = State.ProcAct;
+ do {
+ if (!getUserAgArch().isRunning()) return false;
+ applySemanticRuleAct();
+ } while (stepAct != State.StartRC);
+
+
+ ActionExec action = C.getAction();
+ if (action != null) {
+ C.addPendingAction(action);
+ // We need to send a wrapper for FA to the user so that add method then calls C.addFA (which control atomic things)
+ getUserAgArch().act(action, C.getFeedbackActionsWrapper());
+ }
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "*** ERROR in the transition system (act). "+conf.C+"\nCreating a new C!", e);
+ conf.C.create();
+ }
+ return true;
+ }
+
+ /*
public boolean reasoningCycle() {
if (logger.isLoggable(Level.FINE)) logger.fine("Start new reasoning cycle");
getUserAgArch().reasoningCycleStarting();
-
+ */
/* used to find bugs (ignore)
int is = C.getIntentions().size();
int es = C.getEvents().size();
@@ -1383,7 +1555,7 @@
pc3 = pc2;
pc2 = pc1;
pc1 = C.clone();*/
-
+ /*
try {
C.reset();
@@ -1451,7 +1623,7 @@
return true;
}
-
+*/
// Auxiliary functions
// (for Internal Actions to be able to access the configuration)
public Agent getAg() {
@@ -1462,9 +1634,9 @@
return C;
}
- public State getStep() {
+ /*public State getStep() {
return step;
- }
+ }*/
public Settings getSettings() {
return setts;
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -33,6 +33,7 @@
import jason.asSemantics.Message;
import jason.asSemantics.TransitionSystem;
import jason.asSyntax.Literal;
+import jason.infra.centralised.RunCentralisedMAS.RConf;
import jason.mas2j.ClassParameters;
import jason.runtime.RuntimeServicesInfraTier;
import jason.runtime.Settings;
@@ -182,17 +183,79 @@
myThread.setName(agName);
}
+ public void startThread() {
+ myThread.start();
+ }
+
public boolean isRunning() {
return running;
}
+ protected boolean reasoningCycle() {
+ TransitionSystem ts = getTS();
+
+ int i = 0;
+ while (running && i < cyclesSense) {
+ if (!ts.sense()) {
+ return false;
+ } else if (ts.canSleepSense()) {
+ break;
+ }
+ i++;
+ }
+
+ i = 0;
+ while (running && i < cyclesDeliberate) {
+ if (!ts.deliberate()) {
+ return false;
+ } else if (ts.canSleepDeliberate()) {
+ break;
+ }
+ i++;
+ }
+
+ /* TODO execute 1 deed from each intention
+ * - use -1 as a parameter for number of cycles
+ * - make a clone of the intentions and execute one by one (careful with concurrent access)
+ * - careful when intentions are removed/suspended
+ * */
+
+ i = 0;
+ if (cyclesAct == 9999) { //TODO adjust parameter for executing one deed from each intention
+
+ while (running && i < ts.getC().getIntentions().size()) {
+
+ //System.out.println("# Executing one deed from each intention #" + i + " -> " + getTS().getC().getIntentions().size());
+
+ if (!ts.act()) {
+ return false;
+ } else if (ts.canSleepAct()) {
+ break;
+ }
+ i++;
+ }
+ } else {
+ while (running && i < cyclesAct) {
+ if (!ts.act()) {
+ return false;
+ } else if (ts.canSleepAct()) {
+ break;
+ }
+ i++;
+ }
+ }
+
+ return true;
+ }
+
+
public void run() {
synchronized (syncStopRun) {
TransitionSystem ts = getTS();
while (running) {
if (ts.getSettings().isSync()) {
waitSyncSignal();
- ts.reasoningCycle();
+ reasoningCycle();
boolean isBreakPoint = false;
try {
isBreakPoint = ts.getC().getSelectedOption().getPlan().hasBreakpoint();
@@ -203,7 +266,7 @@
informCycleFinished(isBreakPoint, getCycleNumber());
} else {
incCycleNumber();
- ts.reasoningCycle();
+ reasoningCycle();
}
}
}
@@ -366,4 +429,53 @@
public RuntimeServicesInfraTier getRuntimeServices() {
return new CentralisedRuntimeServices(masRunner);
}
+
+ private RConf conf;
+
+ private int cycles = 0;
+
+ private int cyclesSense = 0;
+ private int cyclesDeliberate = 0;
+ private int cyclesAct = 0;
+
+ public int getCycles() {
+ return cycles;
+ }
+
+ public void setConf(RConf conf) {
+ this.conf = conf;
+ }
+
+ public RConf getConf() {
+ return conf;
+ }
+
+ public void setCycles(int cycles) {
+ this.cycles = cycles;
+ }
+
+ public int getCyclesSense() {
+ return cyclesSense;
+ }
+
+ public void setCyclesSense(int cyclesSense) {
+ this.cyclesSense = cyclesSense;
+ }
+
+ public int getCyclesDeliberate() {
+ return cyclesDeliberate;
+ }
+
+ public void setCyclesDeliberate(int cyclesDeliberate) {
+ this.cyclesDeliberate = cyclesDeliberate;
+ }
+
+ public int getCyclesAct() {
+ return cyclesAct;
+ }
+
+ public void setCyclesAct(int cyclesAct) {
+ this.cyclesAct = cyclesAct;
+ }
+
}
Added: trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java (rev 0)
+++ trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -0,0 +1,162 @@
+package jason.infra.centralised;
+
+import jason.asSemantics.ActionExec;
+import jason.asSemantics.CircumstanceListener;
+import jason.asSemantics.Message;
+import jason.infra.components.ActComponent;
+import jason.infra.components.DeliberateComponent;
+import jason.infra.components.SenseComponent;
+
+import java.util.Queue;
+import java.util.concurrent.ExecutorService;
+
+public class CentralisedAgArchAsynchronous extends CentralisedAgArch implements Runnable {
+ private SenseComponent senseComponent;
+ private DeliberateComponent deliberateComponent;
+ private ActComponent actComponent;
+
+ private ExecutorService executorSense;
+ private ExecutorService executorDeliberate;
+ private ExecutorService executorAct;
+
+ private boolean sleepingSense = false;
+ private boolean sleepingDeliberate = false;
+ private boolean sleepingAct = false;
+
+ public Object objSense = new Object();
+ public Object objDeliberate = new Object();
+ public Object objAct = new Object();
+
+ public CentralisedAgArchAsynchronous() {
+ super();
+
+ senseComponent = new SenseComponent(this);
+ deliberateComponent = new DeliberateComponent(this);
+ actComponent = new ActComponent(this);
+ }
+
+
+ public void wakeUpSense(boolean ts) {
+ synchronized (objSense) {
+ if (ts || sleepingSense) {
+ sleepingSense = false;
+ senseComponent.enqueueExecutor(ts);
+ }
+ }
+ }
+
+ public void wakeUpDeliberate(boolean ts) {
+ synchronized (objDeliberate) {
+ if (ts || sleepingDeliberate) {
+ sleepingDeliberate = false;
+ deliberateComponent.enqueueExecutor(ts);
+ }
+ }
+ }
+
+ public void wakeUpAct(boolean ts) {
+ synchronized (objAct) {
+ if (ts || sleepingAct) {
+ sleepingAct = false;
+ actComponent.enqueueExecutor(ts);
+ }
+ }
+ }
+
+ public void sleepSense() {
+ sleepingSense = true;
+ }
+
+ public boolean isSleepingSense() {
+ return sleepingSense;
+ }
+
+
+ public void sleepDeliberate() {
+ sleepingDeliberate = true;
+ }
+
+ public boolean isSleepingDeliberate() {
+ return sleepingDeliberate;
+ }
+
+ public void sleepAct() {
+ sleepingAct = true;
+ }
+
+ public boolean isSleepingAct() {
+ return sleepingAct;
+ }
+
+ public boolean canSleepSense() {
+ return getTS().canSleepSense();
+ }
+
+ public boolean canSleepDeliberate() {
+ return getTS().canSleepDeliberate();
+ }
+
+ public boolean canSleepAct() {
+ return getTS().canSleepAct();
+ }
+
+ public SenseComponent getSenseComponent() {
+ return senseComponent;
+ }
+
+ public DeliberateComponent getDeliberateComponent() {
+ return deliberateComponent;
+ }
+
+ public ActComponent getActComponent() {
+ return actComponent;
+ }
+
+ public ExecutorService getExecutorSense() {
+ return executorSense;
+ }
+
+
+ public ExecutorService getExecutorDeliberate() {
+ return executorDeliberate;
+ }
+
+ public ExecutorService getExecutorAct() {
+ return executorAct;
+ }
+
+ public void setExecutorAct(ExecutorService executorAct) {
+ this.executorAct = executorAct;
+ }
+
+ public void setExecutorSense(ExecutorService executorSense) {
+ this.executorSense = executorSense;
+ }
+
+ public void setExecutorDeliberate(ExecutorService executorDeliberate) {
+ this.executorDeliberate = executorDeliberate;
+ }
+
+ public void setSenseComponent(SenseComponent senseComponent) {
+ this.senseComponent = senseComponent;
+ }
+
+ public void addListenerToC(CircumstanceListener listener) {
+ getTS().getC().addEventListener(listener);
+ }
+
+ public void receiveMsg(Message m) {
+ synchronized (objSense) {
+ ((Queue<Message>) getMBox()).offer(m);
+ wakeUpSense(false);
+ }
+ }
+
+ /** called the the environment when the action was executed */
+ public void actionExecuted(ActionExec action) {
+ synchronized (objSense) {
+ getTS().getC().addFeedbackAction(action);
+ wakeUpSense(false);
+ }
+ }
+}
Modified: trunk/src/jason/infra/centralised/CentralisedEnvironment.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedEnvironment.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/infra/centralised/CentralisedEnvironment.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -99,13 +99,17 @@
public void informAgsEnvironmentChanged(String... agents) {
if (agents.length == 0) {
for (CentralisedAgArch ag: masRunner.getAgs().values()) {
- ag.wake();
+ ag.getTS().getUserAgArch().wakeUpSense(false);
}
} else {
for (String agName: agents) {
CentralisedAgArch ag = masRunner.getAg(agName);
if (ag != null) {
- ag.wake();
+ if (ag instanceof CentralisedAgArchAsynchronous) {
+ ((CentralisedAgArchAsynchronous) ag.getTS().getUserAgArch()).wakeUpSense(false);
+ } else {
+ ag.wake();
+ }
} else {
logger.log(Level.SEVERE, "Error sending message notification: agent " + agName + " does not exist!");
}
@@ -121,7 +125,7 @@
for (String agName: agentsToNotify) {
CentralisedAgArch ag = masRunner.getAg(agName);
if (ag != null) {
- ag.wake();
+ ag.getTS().getUserAgArch().wakeUpSense(false);
} else {
logger.log(Level.SEVERE, "Error sending message notification: agent " + agName + " does not exist!");
}
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-06 16:33:52 UTC (rev 1886)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-07 16:21:43 UTC (rev 1887)
@@ -29,6 +29,7 @@
import jason.asSyntax.directives.Include;
import jason.bb.DefaultBeliefBase;
import jason.control.ExecutionControlGUI;
+import jason.infra.components.CircumstanceListenerComponents;
import jason.infra.repl.ReplAgGUI;
import jason.jeditplugin.Config;
import jason.mas2j.AgentParameters;
@@ -95,6 +96,14 @@
public JButton btDebug;
+ public enum RConf {
+ TRHEADED,
+ POOL_SYNCH,
+ POOL_SYNCH_SCHEDULED,
+ ASYNCH,
+ ASYNCH_SHARED_POOLS
+ }
+
public RunCentralisedMAS() {
runner = this;
}
@@ -361,7 +370,6 @@
//f.getContentPane().add(BorderLayout.CENTER,mindPanel);
final JTextField n = new JTextField(30);
n.addActionListener(new ActionListener() {
- @Override
public void actionPerformed(ActionEvent e) {
f.setVisible(false);
createReplAg(n.getText());
@@ -422,10 +430,26 @@
env = new CentralisedEnvironment(project.getEnvClass(), this);
}
}
+
public void createAgs() throws JasonException {
- boolean isPool = project.getInfrastructure().hasParameter("pool");
- if (isPool) logger.info("Creating agents....");
+
+ RConf generalConf;
+ if (project.getInfrastructure().hasParameter("pool")) {
+ generalConf = RConf.POOL_SYNCH;
+ } else if (project.getInfrastructure().hasParameter("synch_scheduled")) {
+ generalConf = RConf.POOL_SYNCH_SCHEDULED;
+ } else if (project.getInfrastructure().hasParameter("asynch")) {
+ generalConf = RConf.ASYNCH;
+ } else if (project.getInfrastructure().hasParameter("asynch_shared")) {
+ generalConf = RConf.ASYNCH_SHARED_POOLS;
+ } else {
+ generalConf = RConf.TRHEADED;
+ }
+
+ //boolean isPool = project.getInfrastructure().hasParameter("pool") || project.getInfrastructure().hasParameter("synch_scheduled");
+ //boolean isAsynch = project.getInfrastructure().hasParameter("asynch") || project.getInfrastructure().hasParameter("asynch_shared");
+ if (generalConf != RConf.TRHEADED) logger.info("Creating agents....");
int nbAg = 0;
Agent pag = null;
@@ -453,22 +477,107 @@
logger.fine("Creating agent " + numberedAg + " (" + (cAg + 1) + "/" + ap.getNbInstances() + ")");
CentralisedAgArch agArch;
- if (isPool) {
+
+ RConf agentConf;
+ if (ap.getOption("rc") != null) {
+ if (ap.getOption("rc").equals("pool")) {
+ agentConf = RConf.POOL_SYNCH;
+ } else if (ap.getOption("rc").equals("synch_scheduled")) {
+ agentConf = RConf.POOL_SYNCH_SCHEDULED;
+ } else if (ap.getOption("rc").equals("asynch")) {
+ agentConf = RConf.ASYNCH;
+ } else if (ap.getOption("rc").equals("asynch_shared")) {
+ agentConf = RConf.ASYNCH_SHARED_POOLS;
+ } else {
+ agentConf = RConf.TRHEADED;
+ }
+ } else {
+ agentConf = generalConf;
+ }
+
+ //Get the number of reasoning cycles or number of cycles for each stage
+ int cycles = 0;
+ int cyclesSense = 0;
+ int cyclesDeliberate = 0;
+ int cyclesAct = 0;
+
+ if (ap.getOption("cycles") != null) {
+ cycles = Integer.valueOf(ap.getOption("cycles"));
+ }
+ if (ap.getOption("cycles_sense") != null) {
+ cyclesSense = Integer.valueOf(ap.getOption("cycles_sense"));
+ }
+ if (ap.getOption("cycles_deliberate") != null) {
+ cyclesDeliberate = Integer.valueOf(ap.getOption("cycles_deliberate"));
+ }
+ if (ap.getOption("cycles_act") != null) {
+ cyclesAct = Integer.valueOf(ap.getOption("cycles_act"));
+ }
+
+ //Create agents according to the specific architecture
+ if (agentConf == RConf.POOL_SYNCH) {
agArch = new CentralisedAgArchForPool();
+ } else if (agentConf == RConf.POOL_SYNCH_SCHEDULED) {
+ agArch = new CentralisedAgArchSynchronousScheduled();
+ if (cycles != 0) {
+ if (cyclesSense == 0) {
+ cyclesSense = cycles;
+ }
+ if (cyclesDeliberate == 0) {
+ cyclesDeliberate = cycles;
+ }
+ if (cyclesAct == 0) {
+ cyclesAct = cycles;
+ }
+ cycles = 1;
+ }
+ } else if (agentConf == RConf.ASYNCH || agentConf == RConf.ASYNCH_SHARED_POOLS) {
+ agArch = new CentralisedAgArchAsynchronous();
+ if (cycles != 0) {
+ if (cyclesSense == 0) {
+ cyclesSense = cycles;
+ }
+ if (cyclesDeliberate == 0) {
+ cyclesDeliberate = cycles;
+ }
+ if (cyclesAct == 0) {
+ cyclesAct = cycles;
+ }
+ cycles = 1;
+ }
} else {
agArch = new CentralisedAgArch();
+ if (cycles != 0) {
+ if (cyclesSense == 0) {
+ cyclesSense = cycles;
+ }
+ if (cyclesDeliberate == 0) {
+ cyclesDeliberate = cycles;
+ }
+ if (cyclesAct == 0) {
+ cyclesAct = cycles;
+ }
+ cycles = 1;
+ }
}
+
+ agArch.setCycles(cycles);
+ agArch.setCyclesSense(cyclesSense);
+ agArch.setCyclesDeliberate(cyclesDeliberate);
+ agArch.setCyclesAct(cyclesAct);
+
+ agArch.setConf(agentConf);
agArch.setAgName(numberedAg);
agArch.setEnvInfraTier(env);
- if (isPool && cAg > 0 && ap.getAgArchClasses().isEmpty() && ap.getBBClass().equals(DefaultBeliefBase.class.getName())) {
+ if ((generalConf != RConf.TRHEADED) && cAg > 0 && ap.getAgArchClasses().isEmpty() && ap.getBBClass().equals(DefaultBeliefBase.class.getName())) {
// creation by cloning previous agent (which is faster -- no parsing, for instance)
- // used if not customisations are defined
agArch.createArchs(ap.getAgArchClasses(), pag, this);
} else {
// normal creation
agArch.createArchs(ap.getAgArchClasses(), ap.agClass.getClassName(), ap.getBBClass(), ap.asSource.toString(), ap.getAsSetts(debug, project.getControlClass() != null), this);
}
addAg(agArch);
+ ...
[truncated message content] |
|
From: <jom...@us...> - 2016-04-06 16:33:55
|
Revision: 1886
http://sourceforge.net/p/jason/svn/1886
Author: jomifred
Date: 2016-04-06 16:33:52 +0000 (Wed, 06 Apr 2016)
Log Message:
-----------
improve addPercept method
Modified Paths:
--------------
trunk/src/jason/environment/Environment.java
Modified: trunk/src/jason/environment/Environment.java
===================================================================
--- trunk/src/jason/environment/Environment.java 2016-04-06 16:26:04 UTC (rev 1885)
+++ trunk/src/jason/environment/Environment.java 2016-04-06 16:33:52 UTC (rev 1886)
@@ -209,15 +209,17 @@
}
/** Adds a perception for all agents */
- public void addPercept(Literal per) {
- if (per != null) {
- if (! percepts.contains(per)) {
- percepts.add(per);
- uptodateAgs.clear();
+ public void addPercept(Literal... perceptions) {
+ if (perceptions != null) {
+ for (Literal per: perceptions) {
+ if (! percepts.contains(per)) {
+ percepts.add(per);
+ }
}
+ uptodateAgs.clear();
}
}
-
+
/** Removes a perception from the common perception list */
public boolean removePercept(Literal per) {
if (per != null) {
@@ -286,6 +288,7 @@
}
}
+
/** Removes a perception for an agent */
public boolean removePercept(String agName, Literal per) {
if (per != null && agName != null) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-04-06 16:26:07
|
Revision: 1885
http://sourceforge.net/p/jason/svn/1885
Author: jomifred
Date: 2016-04-06 16:26:04 +0000 (Wed, 06 Apr 2016)
Log Message:
-----------
improved wake in the arch
Modified Paths:
--------------
trunk/src/jason/architecture/AgArch.java
trunk/src/jason/stdlib/relevant_rules.java
trunk/src/jason/stdlib/wait.java
Modified: trunk/src/jason/architecture/AgArch.java
===================================================================
--- trunk/src/jason/architecture/AgArch.java 2016-04-06 16:24:17 UTC (rev 1884)
+++ trunk/src/jason/architecture/AgArch.java 2016-04-06 16:26:04 UTC (rev 1885)
@@ -222,7 +222,20 @@
if (successor != null)
successor.wake();
}
+
+ public void wakeUpSense(boolean ts) {
+ wake();
+ }
+ public void wakeUpDeliberate(boolean ts) {
+ wake();
+ }
+
+ public void wakeUpAct(boolean ts) {
+ wake();
+ }
+
+
public RuntimeServicesInfraTier getRuntimeServices() {
if (successor == null)
return null;
Modified: trunk/src/jason/stdlib/relevant_rules.java
===================================================================
--- trunk/src/jason/stdlib/relevant_rules.java 2016-04-06 16:24:17 UTC (rev 1884)
+++ trunk/src/jason/stdlib/relevant_rules.java 2016-04-06 16:26:04 UTC (rev 1885)
@@ -44,16 +44,18 @@
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
Literal pattern = (Literal)args[0];
- Iterator<Literal> i = ts.getAg().getBB().getCandidateBeliefs(pattern, un);
ListTerm result = new ListTermImpl();
- while (i.hasNext()) {
- Literal l = i.next();
- if (l.isRule()) {
- if (un.clone().unifies(pattern, l)) {
- l = l.copy();
- l.delSources();
- ((Rule)l).setAsTerm(true);
- result.add(l);
+ synchronized (ts.getAg().getBB().getLock()) {
+ Iterator<Literal> i = ts.getAg().getBB().getCandidateBeliefs(pattern, un);
+ while (i.hasNext()) {
+ Literal l = i.next();
+ if (l.isRule()) {
+ if (un.clone().unifies(pattern, l)) {
+ l = l.copy();
+ l.delSources();
+ ((Rule)l).setAsTerm(true);
+ result.add(l);
+ }
}
}
}
Modified: trunk/src/jason/stdlib/wait.java
===================================================================
--- trunk/src/jason/stdlib/wait.java 2016-04-06 16:24:17 UTC (rev 1884)
+++ trunk/src/jason/stdlib/wait.java 2016-04-06 16:26:04 UTC (rev 1885)
@@ -208,7 +208,7 @@
}
}
});
- ts.getUserAgArch().wake();
+ ts.getUserAgArch().wakeUpDeliberate(false);
}
public void eventAdded(Event e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-04-06 16:24:19
|
Revision: 1884
http://sourceforge.net/p/jason/svn/1884
Author: jomifred
Date: 2016-04-06 16:24:17 +0000 (Wed, 06 Apr 2016)
Log Message:
-----------
bb support for concurrent access
Modified Paths:
--------------
trunk/src/jason/bb/BeliefBase.java
trunk/src/jason/bb/ChainBB.java
trunk/src/jason/bb/DefaultBeliefBase.java
trunk/src/jason/bb/IndexedBB.java
trunk/src/jason/bb/JDBCPersistentBB.java
trunk/src/jason/bb/TextPersistentBB.java
Modified: trunk/src/jason/bb/BeliefBase.java
===================================================================
--- trunk/src/jason/bb/BeliefBase.java 2016-04-06 16:21:17 UTC (rev 1883)
+++ trunk/src/jason/bb/BeliefBase.java 2016-04-06 16:24:17 UTC (rev 1884)
@@ -134,4 +134,7 @@
public Element getAsDOM(Document document);
public BeliefBase clone();
+
+ /** Gets a lock for the BB */
+ public Object getLock();
}
Modified: trunk/src/jason/bb/ChainBB.java
===================================================================
--- trunk/src/jason/bb/ChainBB.java 2016-04-06 16:21:17 UTC (rev 1883)
+++ trunk/src/jason/bb/ChainBB.java 2016-04-06 16:24:17 UTC (rev 1884)
@@ -90,4 +90,10 @@
}
return r;
}
+
+ public final Object lockBB = new Object();
+
+ public Object getLock() {
+ return lockBB;
+ }
}
Modified: trunk/src/jason/bb/DefaultBeliefBase.java
===================================================================
--- trunk/src/jason/bb/DefaultBeliefBase.java 2016-04-06 16:21:17 UTC (rev 1883)
+++ trunk/src/jason/bb/DefaultBeliefBase.java 2016-04-06 16:24:17 UTC (rev 1884)
@@ -72,6 +72,12 @@
}
}
+ public final Object lockBB = new Object();
+
+ public Object getLock() {
+ return lockBB;
+ }
+
public Set<Atom> getNameSpaces() {
return nameSpaces.keySet();
}
@@ -260,7 +266,7 @@
/** @deprecated use iterator() instead of getAll */
public Iterator<Literal> getAll() {
return iterator();
- }
+ }
public boolean abolish(PredicateIndicator pi) {
BelEntry entry = belsMapDefaultNS.remove(pi); // TODO: consider other NS (?) this method is not used by jason
@@ -352,22 +358,24 @@
Element ebels = null;
while (tries < 10) { // max 10 tries
try {
- ebels = (Element) document.createElement("beliefs");
- Element enss = (Element) document.createElement("namespaces");
- Element ens = (Element) document.createElement("namespace");
- ens.setAttribute("id", "default"); // to ensure default is the first
- enss.appendChild(ens);
- for (Atom ns: getNameSpaces()) {
- if (ns == Literal.DefaultNS)
- continue;
- ens = (Element) document.createElement("namespace");
- ens.setAttribute("id", ns.getFunctor());
+ synchronized (getLock()) {
+ ebels = (Element) document.createElement("beliefs");
+ Element enss = (Element) document.createElement("namespaces");
+ Element ens = (Element) document.createElement("namespace");
+ ens.setAttribute("id", "default"); // to ensure default is the first
enss.appendChild(ens);
+ for (Atom ns: getNameSpaces()) {
+ if (ns == Literal.DefaultNS)
+ continue;
+ ens = (Element) document.createElement("namespace");
+ ens.setAttribute("id", ns.getFunctor());
+ enss.appendChild(ens);
+ }
+ ebels.appendChild(enss);
+ for (Literal l: this)
+ ebels.appendChild(l.getAsDOM(document));
+ break; // quit the loop
}
- ebels.appendChild(enss);
- for (Literal l: this)
- ebels.appendChild(l.getAsDOM(document));
- break; // quit the loop
} catch (Exception e) { // normally concurrent modification, but others happen
tries++;
e.printStackTrace();
Modified: trunk/src/jason/bb/IndexedBB.java
===================================================================
--- trunk/src/jason/bb/IndexedBB.java 2016-04-06 16:21:17 UTC (rev 1883)
+++ trunk/src/jason/bb/IndexedBB.java 2016-04-06 16:24:17 UTC (rev 1884)
@@ -97,4 +97,11 @@
nbb.indexedBels = new HashMap<String,Structure>(this.indexedBels);
return nbb;
}
+
+ public final Object lockBB = new Object();
+
+ public Object getLock() {
+ return lockBB;
+ }
+
}
Modified: trunk/src/jason/bb/JDBCPersistentBB.java
===================================================================
--- trunk/src/jason/bb/JDBCPersistentBB.java 2016-04-06 16:21:17 UTC (rev 1883)
+++ trunk/src/jason/bb/JDBCPersistentBB.java 2016-04-06 16:24:17 UTC (rev 1884)
@@ -714,4 +714,9 @@
return null;
}
+ public final Object lockBB = new Object();
+
+ public Object getLock() {
+ return lockBB;
+ }
}
Modified: trunk/src/jason/bb/TextPersistentBB.java
===================================================================
--- trunk/src/jason/bb/TextPersistentBB.java 2016-04-06 16:21:17 UTC (rev 1883)
+++ trunk/src/jason/bb/TextPersistentBB.java 2016-04-06 16:24:17 UTC (rev 1884)
@@ -56,4 +56,11 @@
}
nextBB.stop();
}
+
+ public final Object lockBB = new Object();
+
+ public Object getLock() {
+ return lockBB;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-04-06 16:21:20
|
Revision: 1883
http://sourceforge.net/p/jason/svn/1883
Author: jomifred
Date: 2016-04-06 16:21:17 +0000 (Wed, 06 Apr 2016)
Log Message:
-----------
concurrent PlanLibrary
Modified Paths:
--------------
trunk/src/jason/asSyntax/PlanLibrary.java
trunk/src/jason/asSyntax/Rule.java
Modified: trunk/src/jason/asSyntax/PlanLibrary.java
===================================================================
--- trunk/src/jason/asSyntax/PlanLibrary.java 2016-04-06 16:18:42 UTC (rev 1882)
+++ trunk/src/jason/asSyntax/PlanLibrary.java 2016-04-06 16:21:17 UTC (rev 1883)
@@ -33,10 +33,10 @@
import jason.jeditplugin.Config;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.w3c.dom.Document;
@@ -49,7 +49,7 @@
public class PlanLibrary implements Iterable<Plan> {
/** a MAP from TE to a list of relevant plans */
- private Map<PredicateIndicator,List<Plan>> relPlans = new HashMap<PredicateIndicator,List<Plan>>();
+ private Map<PredicateIndicator,List<Plan>> relPlans = new ConcurrentHashMap<PredicateIndicator,List<Plan>>();
/**
* All plans as defined in the AS code (maintains the order of the plans)
@@ -60,7 +60,7 @@
private List<Plan> varPlans = new ArrayList<Plan>();
/** A map from labels to plans */
- private Map<String,Plan> planLabels = new HashMap<String,Plan>();
+ private Map<String,Plan> planLabels = new ConcurrentHashMap<String,Plan>();
private boolean hasMetaEventPlans = false;
@@ -68,8 +68,14 @@
private boolean hasUserKqmlReceived = false;
- //private Logger logger = Logger.getLogger(PlanLibrary.class.getName());
+ //private Logger logger = Logger.getLogger(PlanLibrary.class.getName());
+ private final Object lockPL = new Object();
+
+ public Object getLock() {
+ return lockPL;
+ }
+
/**
* Add a new plan written as a String. The source
* normally is "self" or the agent that sent this plan.
@@ -126,18 +132,20 @@
* @returns the plan just added
*/
public Plan add(Plan p, Term source, boolean before) throws JasonException {
- int i = plans.indexOf(p);
- if (i < 0) {
- // add label, if necessary
- if (p.getLabel() == null)
- p.setLabel(getUniqueLabel());
- p.getLabel().addSource(source);
- add(p, before);
- } else {
- p = plans.get(i);
- p.getLabel().addSource(source);
+ synchronized (lockPL) {
+ int i = plans.indexOf(p);
+ if (i < 0) {
+ // add label, if necessary
+ if (p.getLabel() == null)
+ p.setLabel(getUniqueLabel());
+ p.getLabel().addSource(source);
+ add(p, before);
+ } else {
+ p = plans.get(i);
+ p.getLabel().addSource(source);
+ }
+ return p;
}
- return p;
}
public void add(Plan p) throws JasonException {
@@ -155,83 +163,90 @@
* @throws JasonException
*/
public void add(Plan p, boolean before) throws JasonException {
- // test p.label
- if (p.getLabel() != null && planLabels.keySet().contains( getStringForLabel(p.getLabel()))) {
- // test if the new plan is equal, in this case, just add a source
- Plan planInPL = get(p.getLabel());
- if (p.equals(planInPL)) {
- planInPL.getLabel().addSource(p.getLabel().getSources().get(0));
- return;
- } else {
- throw new JasonException("There already is a plan with label " + p.getLabel());
- }
- }
-
- // add label, if necessary
- if (p.getLabel() == null)
- p.setLabel(getUniqueLabel());
+ synchronized (lockPL) {
- // add self source
- if (!p.getLabel().hasSource())
- p.getLabel().addAnnot(BeliefBase.TSelf);
-
- if (p.getTrigger().getLiteral().getFunctor().equals(kqmlReceivedFunctor)) {
- if (! (p.getSrcInfo() != null && "kqmlPlans.asl".equals(p.getSrcInfo().getSrcFile()))) {
- hasUserKqmlReceived = true;
+ // test p.label
+ if (p.getLabel() != null && planLabels.keySet().contains( getStringForLabel(p.getLabel()))) {
+ // test if the new plan is equal, in this case, just add a source
+ Plan planInPL = get(p.getLabel());
+ if (p.equals(planInPL)) {
+ planInPL.getLabel().addSource(p.getLabel().getSources().get(0));
+ return;
+ } else {
+ throw new JasonException("There already is a plan with label " + p.getLabel());
+ }
}
- }
-
- p.setAsPlanTerm(false); // it is not a term anymore
-
- planLabels.put( getStringForLabel(p.getLabel()), p);
-
- Trigger pte = p.getTrigger();
- if (pte.getLiteral().isVar()) {
- if (before)
- varPlans.add(0,p);
- else
- varPlans.add(p);
- // add plan p in all entries
- for (List<Plan> lp: relPlans.values())
- if (!lp.isEmpty() && lp.get(0).getTrigger().sameType(pte)) // only add if same type
- if (before)
- lp.add(0,p);
- else
- lp.add(p);
- } else {
- List<Plan> codesList = relPlans.get(pte.getPredicateIndicator());
- if (codesList == null) {
- codesList = new ArrayList<Plan>();
- // copy plans from var plans
- for (Plan vp: varPlans)
- if (vp.getTrigger().sameType(pte))
- codesList.add(vp);
- relPlans.put(pte.getPredicateIndicator(), codesList);
+
+ // add label, if necessary
+ if (p.getLabel() == null)
+ p.setLabel(getUniqueLabel());
+
+ // add self source
+ if (!p.getLabel().hasSource())
+ p.getLabel().addAnnot(BeliefBase.TSelf);
+
+ if (p.getTrigger().getLiteral().getFunctor().equals(kqmlReceivedFunctor)) {
+ if (! (p.getSrcInfo() != null && "kqmlPlans.asl".equals(p.getSrcInfo().getSrcFile()))) {
+ hasUserKqmlReceived = true;
+ }
}
+
+ p.setAsPlanTerm(false); // it is not a term anymore
+
+ planLabels.put( getStringForLabel(p.getLabel()), p);
+
+ Trigger pte = p.getTrigger();
+ if (pte.getLiteral().isVar()) {
+ if (before)
+ varPlans.add(0,p);
+ else
+ varPlans.add(p);
+ // add plan p in all entries
+ for (List<Plan> lp: relPlans.values())
+ if (!lp.isEmpty() && lp.get(0).getTrigger().sameType(pte)) // only add if same type
+ if (before)
+ lp.add(0,p);
+ else
+ lp.add(p);
+ } else {
+ List<Plan> codesList = relPlans.get(pte.getPredicateIndicator());
+ if (codesList == null) {
+ codesList = new ArrayList<Plan>();
+ // copy plans from var plans
+ for (Plan vp: varPlans)
+ if (vp.getTrigger().sameType(pte))
+ codesList.add(vp);
+ relPlans.put(pte.getPredicateIndicator(), codesList);
+ }
+ if (before)
+ codesList.add(0,p);
+ else
+ codesList.add(p);
+ }
+
+ if (pte.getOperator() == TEOperator.goalState)
+ hasMetaEventPlans = true;
+
if (before)
- codesList.add(0,p);
+ plans.add(0,p);
else
- codesList.add(p);
+ plans.add(p);
}
-
- if (pte.getOperator() == TEOperator.goalState)
- hasMetaEventPlans = true;
-
- if (before)
- plans.add(0,p);
- else
- plans.add(p);
}
public void addAll(PlanLibrary pl) throws JasonException {
- for (Plan p: pl) {
- add(p, false);
+ synchronized (lockPL) {
+ for (Plan p: pl) {
+ add(p, false);
+ }
}
}
public void addAll(List<Plan> plans) throws JasonException {
- for (Plan p: plans) {
- add(p, false);
+ synchronized (lockPL) {
+ for (Plan p: plans) {
+ add(p, false);
+ }
}
}
@@ -309,33 +324,35 @@
/** remove the plan with label <i>pLabel</i> */
public Plan remove(Atom pLabel) {
- Plan p = planLabels.remove( getStringForLabel(pLabel) );
-
- // remove it from plans' list
- plans.remove(p);
-
- if (p.getTrigger().getLiteral().isVar()) {
- varPlans.remove(p);
- // remove p from all entries and
- // clean empty entries
- Iterator<PredicateIndicator> ipi = relPlans.keySet().iterator();
- while (ipi.hasNext()) {
- PredicateIndicator pi = ipi.next();
- List<Plan> lp = relPlans.get(pi);
- lp.remove(p);
- if (lp.isEmpty()) {
- ipi.remove();
+ synchronized (lockPL) {
+ Plan p = planLabels.remove( getStringForLabel(pLabel) );
+
+ // remove it from plans' list
+ plans.remove(p);
+
+ if (p.getTrigger().getLiteral().isVar()) {
+ varPlans.remove(p);
+ // remove p from all entries and
+ // clean empty entries
+ Iterator<PredicateIndicator> ipi = relPlans.keySet().iterator();
+ while (ipi.hasNext()) {
+ PredicateIndicator pi = ipi.next();
+ List<Plan> lp = relPlans.get(pi);
+ lp.remove(p);
+ if (lp.isEmpty()) {
+ ipi.remove();
+ }
}
+ } else {
+ List<Plan> codesList = relPlans.get(p.getTrigger().getPredicateIndicator());
+ codesList.remove(p);
+ if (codesList.isEmpty()) {
+ // no more plans for this TE
+ relPlans.remove(p.getTrigger().getPredicateIndicator());
+ }
}
- } else {
- List<Plan> codesList = relPlans.get(p.getTrigger().getPredicateIndicator());
- codesList.remove(p);
- if (codesList.isEmpty()) {
- // no more plans for this TE
- relPlans.remove(p.getTrigger().getPredicateIndicator());
- }
+ return p;
}
- return p;
}
/** @deprecated use hasCandidatePlan(te) instead */
@@ -357,26 +374,28 @@
}
public List<Plan> getCandidatePlans(Trigger te) {
- List<Plan> l = null;
- if (te.getLiteral().isVar()) { // add all plans!
- for (Plan p: this)
- if (p.getTrigger().sameType(te)) {
- if (l == null)
- l = new ArrayList<Plan>();
- l.add(p);
- }
- } else {
- l = relPlans.get(te.getPredicateIndicator());
- if ((l == null || l.isEmpty()) && !varPlans.isEmpty() && te != TE_JAG_SLEEPING && te != TE_JAG_AWAKING) { // no rel plan, try varPlan
- for (Plan p: varPlans)
+ synchronized (lockPL) {
+ List<Plan> l = null;
+ if (te.getLiteral().isVar()) { // add all plans!
+ for (Plan p: this)
if (p.getTrigger().sameType(te)) {
if (l == null)
l = new ArrayList<Plan>();
l.add(p);
- }
+ }
+ } else {
+ l = relPlans.get(te.getPredicateIndicator());
+ if ((l == null || l.isEmpty()) && !varPlans.isEmpty() && te != TE_JAG_SLEEPING && te != TE_JAG_AWAKING) { // no rel plan, try varPlan
+ for (Plan p: varPlans)
+ if (p.getTrigger().sameType(te)) {
+ if (l == null)
+ l = new ArrayList<Plan>();
+ l.add(p);
+ }
+ }
}
+ return l; // if no rel plan, have to return null instead of empty list
}
- return l; // if no rel plan, have to return null instead of empty list
}
public static final Trigger TE_JAG_SLEEPING = new Trigger(TEOperator.add, TEType.achieve, new Atom("jag_sleeping"));
@@ -385,8 +404,10 @@
public PlanLibrary clone() {
PlanLibrary pl = new PlanLibrary();
try {
- for (Plan p: this) {
- pl.add((Plan)p.clone(), false);
+ synchronized (lockPL) {
+ for (Plan p: this) {
+ pl.add((Plan)p.clone(), false);
+ }
}
} catch (JasonException e) {
e.printStackTrace();
@@ -402,13 +423,15 @@
public Element getAsDOM(Document document) {
Element eplans = (Element) document.createElement("plans");
String lastFunctor = null;
- for (Plan p: plans) {
- String currentFunctor = p.getTrigger().getLiteral().getFunctor();
- if (lastFunctor != null && !currentFunctor.equals(lastFunctor)) {
- eplans.appendChild((Element) document.createElement("new-set-of-plans"));
+ synchronized (lockPL) {
+ for (Plan p: plans) {
+ String currentFunctor = p.getTrigger().getLiteral().getFunctor();
+ if (lastFunctor != null && !currentFunctor.equals(lastFunctor)) {
+ eplans.appendChild((Element) document.createElement("new-set-of-plans"));
+ }
+ lastFunctor = currentFunctor;
+ eplans.appendChild(p.getAsDOM(document));
}
- lastFunctor = currentFunctor;
- eplans.appendChild(p.getAsDOM(document));
}
return eplans;
}
Modified: trunk/src/jason/asSyntax/Rule.java
===================================================================
--- trunk/src/jason/asSyntax/Rule.java 2016-04-06 16:18:42 UTC (rev 1882)
+++ trunk/src/jason/asSyntax/Rule.java 2016-04-06 16:21:17 UTC (rev 1883)
@@ -107,6 +107,10 @@
return body;
}
+ public Literal getHead() {
+ return new LiteralImpl(this);
+ }
+
@Override
public Literal makeVarsAnnon(Unifier un) {
if (body instanceof Literal)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-04-06 16:18:45
|
Revision: 1882
http://sourceforge.net/p/jason/svn/1882
Author: jomifred
Date: 2016-04-06 16:18:42 +0000 (Wed, 06 Apr 2016)
Log Message:
-----------
parser for fork
Modified Paths:
--------------
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-04-06 15:11:33 UTC (rev 1881)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-04-06 16:18:42 UTC (rev 1882)
@@ -390,9 +390,6 @@
[ ";" ][ R = plan_body() ]
{ if (R != null) {
- //if (!isControl && !hasPV) {
- // throw new ParseException(getSourceRef(F)+" Expected ';' after '"+F+"'.");
- //}
((PlanBody)F).setBodyNext( R );
}
return (PlanBody)F;
@@ -400,7 +397,7 @@
}
-PlanBody plan_body_term() : { Object F; PlanBody R = null; Literal stmtLiteral; }
+PlanBody plan_body_term() : { Object F; PlanBody R = null; }
{
F = plan_body_factor()
@@ -409,8 +406,21 @@
{
if (R == null)
return (PlanBody)F;
- try {
- stmtLiteral = new InternalActionLiteral(ASSyntax.createStructure(".fork", jason.stdlib.fork.aOr, (Term)F, (Term)R), curAg);
+ try {
+ Structure s = ASSyntax.createStructure(".fork", jason.stdlib.fork.aOr, (Term)F);
+ if (R.toString().startsWith(".fork(or,")) {
+ // if R is another fork or, put they args into this fork
+ InternalActionLiteral ial = (InternalActionLiteral)R.getBodyTerm();
+ if (ial.getIA(curAg) instanceof jason.stdlib.fork) {
+ for (int i=1; i<ial.getArity(); i++) {
+ s.addTerm(ial.getTerm(i));
+ }
+ }
+ } else {
+ s.addTerm(R);
+ }
+
+ Literal stmtLiteral = new InternalActionLiteral(s, curAg);
stmtLiteral.setSrcInfo( ((Term)F).getSrcInfo() );
return new PlanBodyImpl(BodyType.internalAction, stmtLiteral);
} catch (Exception e) {
@@ -419,7 +429,7 @@
}
}
-PlanBody plan_body_factor() : { Object F; PlanBody R = null; Literal stmtLiteral; } // boolean hasPV = false; boolean isControl = true; }
+PlanBody plan_body_factor() : { Object F; PlanBody R = null; } // boolean hasPV = false; boolean isControl = true; }
{
( F = stmtIF()
@@ -429,14 +439,24 @@
if (!(F instanceof PlanBody)) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!"); }
)
- //[ ";" { hasPV = true; }
- //]
- [ <TK_PAND> R = plan_body_factor() ]
+[ <TK_PAND> R = plan_body_factor() ]
{
if (R == null)
return (PlanBody)F;
try {
- stmtLiteral = new InternalActionLiteral(ASSyntax.createStructure(".fork", jason.stdlib.fork.aAnd, (Term)F, (Term)R), curAg);
+ Structure s = ASSyntax.createStructure(".fork", jason.stdlib.fork.aAnd, (Term)F);
+ if (R.toString().startsWith(".fork(and,")) {
+ // if R is another fork and, put they args into this fork
+ InternalActionLiteral ial = (InternalActionLiteral)R.getBodyTerm();
+ if (ial.getIA(curAg) instanceof jason.stdlib.fork) {
+ for (int i=1; i<ial.getArity(); i++) {
+ s.addTerm(ial.getTerm(i));
+ }
+ }
+ } else {
+ s.addTerm(R);
+ }
+ Literal stmtLiteral = new InternalActionLiteral(s, curAg);
stmtLiteral.setSrcInfo( ((Term)F).getSrcInfo() );
return new PlanBodyImpl(BodyType.internalAction, stmtLiteral);
} catch (Exception e) {
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-04-06 15:11:33 UTC (rev 1881)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-04-06 16:18:42 UTC (rev 1882)
@@ -504,9 +504,6 @@
;
}
if (R != null) {
- //if (!isControl && !hasPV) {
- // throw new ParseException(getSourceRef(F)+" Expected ';' after '"+F+"'.");
- //}
((PlanBody)F).setBodyNext( R );
}
{if (true) return (PlanBody)F;}
@@ -514,7 +511,7 @@
}
final public PlanBody plan_body_term() throws ParseException {
- Object F; PlanBody R = null; Literal stmtLiteral;
+ Object F; PlanBody R = null;
F = plan_body_factor();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_POR:
@@ -528,7 +525,20 @@
if (R == null)
{if (true) return (PlanBody)F;}
try {
- stmtLiteral = new InternalActionLiteral(ASSyntax.createStructure(".fork", jason.stdlib.fork.aOr, (Term)F, (Term)R), curAg);
+ Structure s = ASSyntax.createStructure(".fork", jason.stdlib.fork.aOr, (Term)F);
+ if (R.toString().startsWith(".fork(or,")) {
+ // if R is another fork or, put they args into this fork
+ InternalActionLiteral ial = (InternalActionLiteral)R.getBodyTerm();
+ if (ial.getIA(curAg) instanceof jason.stdlib.fork) {
+ for (int i=1; i<ial.getArity(); i++) {
+ s.addTerm(ial.getTerm(i));
+ }
+ }
+ } else {
+ s.addTerm(R);
+ }
+
+ Literal stmtLiteral = new InternalActionLiteral(s, curAg);
stmtLiteral.setSrcInfo( ((Term)F).getSrcInfo() );
{if (true) return new PlanBodyImpl(BodyType.internalAction, stmtLiteral);}
} catch (Exception e) {
@@ -538,7 +548,7 @@
}
final public PlanBody plan_body_factor() throws ParseException {
- Object F; PlanBody R = null; Literal stmtLiteral;
+ Object F; PlanBody R = null;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_IF:
F = stmtIF();
@@ -589,7 +599,19 @@
if (R == null)
{if (true) return (PlanBody)F;}
try {
- stmtLiteral = new InternalActionLiteral(ASSyntax.createStructure(".fork", jason.stdlib.fork.aAnd, (Term)F, (Term)R), curAg);
+ Structure s = ASSyntax.createStructure(".fork", jason.stdlib.fork.aAnd, (Term)F);
+ if (R.toString().startsWith(".fork(and,")) {
+ // if R is another fork and, put they args into this fork
+ InternalActionLiteral ial = (InternalActionLiteral)R.getBodyTerm();
+ if (ial.getIA(curAg) instanceof jason.stdlib.fork) {
+ for (int i=1; i<ial.getArity(); i++) {
+ s.addTerm(ial.getTerm(i));
+ }
+ }
+ } else {
+ s.addTerm(R);
+ }
+ Literal stmtLiteral = new InternalActionLiteral(s, curAg);
stmtLiteral.setSrcInfo( ((Term)F).getSrcInfo() );
{if (true) return new PlanBodyImpl(BodyType.internalAction, stmtLiteral);}
} catch (Exception e) {
@@ -1733,11 +1755,6 @@
finally { jj_save(3, xla); }
}
- final private boolean jj_3R_117() {
- if (jj_3R_19()) return true;
- return false;
- }
-
final private boolean jj_3R_31() {
Token xsp;
xsp = jj_scanpos;
@@ -1748,82 +1765,6 @@
return false;
}
- final private boolean jj_3R_30() {
- if (jj_scan_token(41)) return true;
- return false;
- }
-
- final private boolean jj_3R_29() {
- if (jj_scan_token(40)) return true;
- return false;
- }
-
- final private boolean jj_3R_78() {
- if (jj_scan_token(50)) return true;
- if (jj_3R_55()) return true;
- return false;
- }
-
- final private boolean jj_3R_28() {
- if (jj_scan_token(39)) return true;
- return false;
- }
-
- final private boolean jj_3R_114() {
- if (jj_3R_117()) return true;
- return false;
- }
-
- final private boolean jj_3R_113() {
- if (jj_scan_token(44)) return true;
- if (jj_3R_20()) return true;
- if (jj_scan_token(45)) return true;
- return false;
- }
-
- final private boolean jj_3R_16() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_28()) {
- jj_scanpos = xsp;
- if (jj_3R_29()) {
- jj_scanpos = xsp;
- if (jj_3R_30()) return true;
- }
- }
- xsp = jj_scanpos;
- if (jj_3R_31()) jj_scanpos = xsp;
- if (jj_3R_19()) return true;
- return false;
- }
-
- final private boolean jj_3R_41() {
- if (jj_3R_55()) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_78()) { jj_scanpos = xsp; break; }
- }
- return false;
- }
-
- final private boolean jj_3R_112() {
- if (jj_scan_token(39)) return true;
- if (jj_3R_103()) return true;
- return false;
- }
-
- final private boolean jj_3R_111() {
- if (jj_scan_token(40)) return true;
- if (jj_3R_103()) return true;
- return false;
- }
-
- final private boolean jj_3R_23() {
- if (jj_3R_42()) return true;
- return false;
- }
-
final private boolean jj_3R_132() {
if (jj_3R_20()) return true;
return false;
@@ -1870,11 +1811,26 @@
return false;
}
+ final private boolean jj_3R_30() {
+ if (jj_scan_token(41)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_29() {
+ if (jj_scan_token(40)) return true;
+ return false;
+ }
+
final private boolean jj_3R_143() {
if (jj_scan_token(48)) return true;
return false;
}
+ final private boolean jj_3R_28() {
+ if (jj_scan_token(39)) return true;
+ return false;
+ }
+
final private boolean jj_3R_142() {
if (jj_scan_token(47)) return true;
return false;
@@ -1893,29 +1849,32 @@
return false;
}
- final private boolean jj_3R_139() {
+ final private boolean jj_3R_16() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_141()) {
+ if (jj_3R_28()) {
jj_scanpos = xsp;
- if (jj_3R_142()) {
+ if (jj_3R_29()) {
jj_scanpos = xsp;
- if (jj_3R_143()) return true;
+ if (jj_3R_30()) return true;
}
}
+ xsp = jj_scanpos;
+ if (jj_3R_31()) jj_scanpos = xsp;
+ if (jj_3R_19()) return true;
return false;
}
- final private boolean jj_3R_57() {
- if (jj_scan_token(TK_LABEL_AT)) return true;
- return false;
- }
-
- final private boolean jj_3R_46() {
+ final private boolean jj_3R_139() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_57()) jj_scanpos = xsp;
- if (jj_3R_16()) return true;
+ if (jj_3R_141()) {
+ jj_scanpos = xsp;
+ if (jj_3R_142()) {
+ jj_scanpos = xsp;
+ if (jj_3R_143()) return true;
+ }
+ }
return false;
}
@@ -2004,11 +1963,19 @@
return false;
}
- final private boolean jj_3R_45() {
- if (jj_scan_token(36)) return true;
+ final private boolean jj_3R_57() {
+ if (jj_scan_token(TK_LABEL_AT)) return true;
return false;
}
+ final private boolean jj_3R_46() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_57()) jj_scanpos = xsp;
+ if (jj_3R_16()) return true;
+ return false;
+ }
+
final private boolean jj_3R_108() {
if (jj_scan_token(TK_INTMOD)) return true;
return false;
@@ -2085,8 +2052,8 @@
return false;
}
- final private boolean jj_3R_44() {
- if (jj_3R_19()) return true;
+ final private boolean jj_3R_45() {
+ if (jj_scan_token(36)) return true;
return false;
}
@@ -2160,6 +2127,11 @@
return false;
}
+ final private boolean jj_3R_44() {
+ if (jj_3R_19()) return true;
+ return false;
+ }
+
final private boolean jj_3R_86() {
if (jj_scan_token(60)) return true;
return false;
@@ -2299,14 +2271,6 @@
return false;
}
- final private boolean jj_3_1() {
- if (jj_scan_token(TK_BEGIN)) return true;
- if (jj_3R_13()) return true;
- if (jj_scan_token(33)) return true;
- if (jj_3R_14()) return true;
- return false;
- }
-
final private boolean jj_3R_133() {
if (jj_scan_token(TK_ELSE)) return true;
return false;
@@ -2320,11 +2284,6 @@
return false;
}
- final private boolean jj_3R_43() {
- if (jj_scan_token(32)) return true;
- return false;
- }
-
final private boolean jj_3R_67() {
Token xsp;
xsp = jj_scanpos;
@@ -2349,6 +2308,19 @@
return false;
}
+ final private boolean jj_3_1() {
+ if (jj_scan_token(TK_BEGIN)) return true;
+ if (jj_3R_13()) return true;
+ if (jj_scan_token(33)) return true;
+ if (jj_3R_14()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_43() {
+ if (jj_scan_token(32)) return true;
+ return false;
+ }
+
final private boolean jj_3R_59() {
if (jj_3R_67()) return true;
return false;
@@ -2360,12 +2332,6 @@
return false;
}
- final private boolean jj_3R_124() {
- if (jj_scan_token(TK_PAND)) return true;
- if (jj_3R_118()) return true;
- return false;
- }
-
final private boolean jj_3R_52() {
Token xsp;
xsp = jj_scanpos;
@@ -2390,6 +2356,31 @@
return false;
}
+ final private boolean jj_3R_38() {
+ if (jj_scan_token(52)) return true;
+ if (jj_3R_20()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_124() {
+ if (jj_scan_token(TK_PAND)) return true;
+ if (jj_3R_118()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_20() {
+ if (jj_3R_37()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_38()) jj_scanpos = xsp;
+ return false;
+ }
+
+ final private boolean jj_3R_102() {
+ if (jj_3R_109()) return true;
+ return false;
+ }
+
final private boolean jj_3R_123() {
if (jj_3R_128()) return true;
return false;
@@ -2405,14 +2396,20 @@
return false;
}
- final private boolean jj_3R_38() {
- if (jj_scan_token(52)) return true;
+ final private boolean jj_3R_120() {
+ if (jj_3R_125()) return true;
+ return false;
+ }
+
+ final private boolean jj_3_3() {
+ if (jj_3R_19()) return true;
+ if (jj_scan_token(34)) return true;
if (jj_3R_20()) return true;
return false;
}
- final private boolean jj_3R_120() {
- if (jj_3R_125()) return true;
+ final private boolean jj_3R_33() {
+ if (jj_scan_token(43)) return true;
return false;
}
@@ -2434,36 +2431,6 @@
return false;
}
- final private boolean jj_3R_20() {
- if (jj_3R_37()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_38()) jj_scanpos = xsp;
- return false;
- }
-
- final private boolean jj_3R_102() {
- if (jj_3R_109()) return true;
- return false;
- }
-
- final private boolean jj_3R_27() {
- if (jj_3R_46()) return true;
- return false;
- }
-
- final private boolean jj_3_3() {
- if (jj_3R_19()) return true;
- if (jj_scan_token(34)) return true;
- if (jj_3R_20()) return true;
- return false;
- }
-
- final private boolean jj_3R_33() {
- if (jj_scan_token(43)) return true;
- return false;
- }
-
final private boolean jj_3R_32() {
if (jj_scan_token(38)) return true;
return false;
@@ -2500,11 +2467,6 @@
return false;
}
- final private boolean jj_3R_26() {
- if (jj_3R_45()) return true;
- return false;
- }
-
final private boolean jj_3R_69() {
if (jj_3R_42()) return true;
return false;
@@ -2532,12 +2494,6 @@
return false;
}
- final private boolean jj_3R_119() {
- if (jj_scan_token(TK_POR)) return true;
- if (jj_3R_115()) return true;
- return false;
- }
-
final private boolean jj_3R_97() {
if (jj_3R_42()) return true;
return false;
@@ -2570,19 +2526,6 @@
return false;
}
- final private boolean jj_3R_25() {
- if (jj_3R_44()) return true;
- return false;
- }
-
- final private boolean jj_3R_115() {
- if (jj_3R_118()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_119()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_68() {
if (jj_scan_token(32)) return true;
Token xsp;
@@ -2596,33 +2539,6 @@
return false;
}
- final private boolean jj_3R_24() {
- if (jj_3R_43()) return true;
- return false;
- }
-
- final private boolean jj_3R_14() {
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_24()) { jj_scanpos = xsp; break; }
- }
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_25()) { jj_scanpos = xsp; break; }
- }
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_26()) { jj_scanpos = xsp; break; }
- }
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_27()) { jj_scanpos = xsp; break; }
- }
- if (jj_scan_token(0)) return true;
- return false;
- }
-
final private boolean jj_3R_62() {
if (jj_3R_42()) return true;
return false;
@@ -2642,11 +2558,6 @@
return false;
}
- final private boolean jj_3R_116() {
- if (jj_3R_109()) return true;
- return false;
- }
-
final private boolean jj_3R_91() {
if (jj_scan_token(50)) return true;
if (jj_3R_66()) return true;
@@ -2658,6 +2569,11 @@
return false;
}
+ final private boolean jj_3R_27() {
+ if (jj_3R_46()) return true;
+ return false;
+ }
+
final private boolean jj_3R_60() {
if (jj_scan_token(VAR)) return true;
return false;
@@ -2696,21 +2612,27 @@
return false;
}
- final private boolean jj_3R_109() {
- if (jj_3R_115()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_scan_token(43)) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_116()) jj_scanpos = xsp;
+ final private boolean jj_3R_26() {
+ if (jj_3R_45()) return true;
return false;
}
+ final private boolean jj_3R_25() {
+ if (jj_3R_44()) return true;
+ return false;
+ }
+
final private boolean jj_3R_65() {
if (jj_3R_20()) return true;
return false;
}
+ final private boolean jj_3R_119() {
+ if (jj_scan_token(TK_POR)) return true;
+ if (jj_3R_115()) return true;
+ return false;
+ }
+
final private boolean jj_3R_64() {
if (jj_3R_68()) return true;
return false;
@@ -2721,8 +2643,8 @@
return false;
}
- final private boolean jj_3R_48() {
- if (jj_scan_token(42)) return true;
+ final private boolean jj_3R_24() {
+ if (jj_3R_43()) return true;
return false;
}
@@ -2739,6 +2661,106 @@
return false;
}
+ final private boolean jj_3R_115() {
+ if (jj_3R_118()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_119()) jj_scanpos = xsp;
+ return false;
+ }
+
+ final private boolean jj_3R_14() {
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_24()) { jj_scanpos = xsp; break; }
+ }
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_25()) { jj_scanpos = xsp; break; }
+ }
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_26()) { jj_scanpos = xsp; break; }
+ }
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_27()) { jj_scanpos = xsp; break; }
+ }
+ if (jj_scan_token(0)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_117() {
+ if (jj_3R_19()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_116() {
+ if (jj_3R_109()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_78() {
+ if (jj_scan_token(50)) return true;
+ if (jj_3R_55()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_114() {
+ if (jj_3R_117()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_113() {
+ if (jj_scan_token(44)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(45)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_41() {
+ if (jj_3R_55()) return true;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_78()) { jj_scanpos = xsp; break; }
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_112() {
+ if (jj_scan_token(39)) return true;
+ if (jj_3R_103()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_109() {
+ if (jj_3R_115()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_scan_token(43)) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_116()) jj_scanpos = xsp;
+ return false;
+ }
+
+ final private boolean jj_3R_111() {
+ if (jj_scan_token(40)) return true;
+ if (jj_3R_103()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_48() {
+ if (jj_scan_token(42)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_23() {
+ if (jj_3R_42()) return true;
+ return false;
+ }
+
final private boolean jj_3R_47() {
if (jj_scan_token(36)) return true;
return false;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-04-06 15:11:35
|
Revision: 1881
http://sourceforge.net/p/jason/svn/1881
Author: jomifred
Date: 2016-04-06 15:11:33 +0000 (Wed, 06 Apr 2016)
Log Message:
-----------
update CNET example
Modified Paths:
--------------
trunk/examples/contract-net-protocol/c.asl
trunk/examples/contract-net-protocol/p.asl
Modified: trunk/examples/contract-net-protocol/c.asl
===================================================================
--- trunk/examples/contract-net-protocol/c.asl 2016-03-21 18:51:04 UTC (rev 1880)
+++ trunk/examples/contract-net-protocol/c.asl 2016-04-06 15:11:33 UTC (rev 1881)
@@ -21,22 +21,10 @@
.findall(Name,introduction(participant,Name),LP);
.print("Sending CFP to ",LP);
.send(LP,tell,cfp(Id,Task));
- // the deadline of the CNP is now + 4 seconds, so
- // the event +!contract(Id) is generated at that time
- .at("now +4 seconds", { +!contract(Id) }).
+ // the deadline of the CNP is now + 4 seconds (or all proposals were received)
+ .wait(all_proposals_received(CNPId), 4000, _);
+ !contract(Id).
-
-// receive proposal
-// if all proposal have been received, don't wait for the deadline
-@r1 +propose(CNPId,_Offer)
- : cnp_state(CNPId,propose) & all_proposals_received(CNPId)
- <- !contract(CNPId).
-
-// receive refusals
-@r2 +refuse(CNPId)
- : cnp_state(CNPId,propose) & all_proposals_received(CNPId)
- <- !contract(CNPId).
-
// this plan needs to be atomic so as not to accept
// proposals or refusals while contracting
@lc1[atomic]
@@ -67,4 +55,3 @@
+!announce_result(CNPId,[offer(_,LAg)|T],WAg)
<- .send(LAg,tell,reject_proposal(CNPId));
!announce_result(CNPId,T,WAg).
-
Modified: trunk/examples/contract-net-protocol/p.asl
===================================================================
--- trunk/examples/contract-net-protocol/p.asl 2016-03-21 18:51:04 UTC (rev 1880)
+++ trunk/examples/contract-net-protocol/p.asl 2016-04-06 15:11:33 UTC (rev 1881)
@@ -25,4 +25,3 @@
@r2 +reject_proposal(CNPId)
<- .print("I lost CNP ",CNPId, ".");
-proposal(CNPId,_,_). // clear memory
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-03-21 18:51:07
|
Revision: 1880
http://sourceforge.net/p/jason/svn/1880
Author: jomifred
Date: 2016-03-21 18:51:04 +0000 (Mon, 21 Mar 2016)
Log Message:
-----------
initial syntax for |&| and |||
Modified Paths:
--------------
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/asSyntax/parser/as2jConstants.java
trunk/src/jason/asSyntax/parser/as2jTokenManager.java
trunk/src/jason/stdlib/fork.java
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2016-03-13 20:16:54 UTC (rev 1879)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2016-03-21 18:51:04 UTC (rev 1880)
@@ -652,19 +652,24 @@
logger.log(Level.SEVERE, msg);
return;
}
- h = (PlanBody)bTerm;
- if (h.getPlanSize() > 1) { // the case of A unified with {a;b;c}
- h.add(im.getCurrentStep().getBodyNext());
- im.insertAsNextStep(h.getBodyNext());
- }
- bTerm = h.getBodyTerm();
}
}
-
+
+ if (bTerm.isPlanBody()) {
+ h = (PlanBody)bTerm;
+ if (h.getPlanSize() > 1) {
+ h = (PlanBody)bTerm.clone();
+ h.add(im.getCurrentStep().getBodyNext());
+ im.insertAsNextStep(h.getBodyNext());
+ }
+ bTerm = h.getBodyTerm();
+ }
+
Literal body = null;
if (bTerm instanceof Literal)
body = (Literal)bTerm;
+
switch (h.getBodyType()) {
case none: break;
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-03-13 20:16:54 UTC (rev 1879)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-03-21 18:51:04 UTC (rev 1880)
@@ -166,6 +166,9 @@
| <TK_FOR: "for" >
| <TK_WHILE: "while" >
+| <TK_PAND: "|&|" >
+| <TK_POR: "|||" >
+
// Numbers
| <NUMBER: ["0"-"9"] (["0"-"9"])*
| (["0"-"9"])* "." (["0"-"9"])+ (["e","E"] (["+","-"])? (["0"-"9"])+)?
@@ -380,35 +383,69 @@
/* Plan body */
-PlanBody plan_body() : { Object F; PlanBody R = null; boolean hasPV = false; boolean isControl = true; }
+PlanBody plan_body() : { Object F; PlanBody R = null; }
{
-( F = stmtIF()
-| F = stmtFOR()
-| F = stmtWHILE()
-| F = body_formula() { isControl = false; if (!(F instanceof PlanBody)) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!"); }
-)
- // TODO: NOTE: in future releases, when old syntax for if/while/for could be forgotten,
- // change to:
- // ( F = stmtIF() ( R = plan_body() | "." )
- // | F = stmtFOR() ( R = plan_body() | "." )
- // | F = stmtWHILE() ( R = plan_body() | "." )
- // | F = body_formula() (";" R = plan_body() | ".")
-
- [ ";" { hasPV = true; }
- ]
- [ R = plan_body() ]
- { if (R != null) {
- if (!isControl && !hasPV) {
- throw new ParseException(getSourceRef(F)+" Expected ';' after '"+F+"'.");
- }
+F = plan_body_term()
+
+[ ";" ][ R = plan_body() ]
+
+ { if (R != null) {
+ //if (!isControl && !hasPV) {
+ // throw new ParseException(getSourceRef(F)+" Expected ';' after '"+F+"'.");
+ //}
((PlanBody)F).setBodyNext( R );
- }
-
- return (PlanBody)F;
- }
+ }
+ return (PlanBody)F;
+ }
+
}
+PlanBody plan_body_term() : { Object F; PlanBody R = null; Literal stmtLiteral; }
+{
+F = plan_body_factor()
+[ <TK_POR> R = plan_body_term() ]
+
+ {
+ if (R == null)
+ return (PlanBody)F;
+ try {
+ stmtLiteral = new InternalActionLiteral(ASSyntax.createStructure(".fork", jason.stdlib.fork.aOr, (Term)F, (Term)R), curAg);
+ stmtLiteral.setSrcInfo( ((Term)F).getSrcInfo() );
+ return new PlanBodyImpl(BodyType.internalAction, stmtLiteral);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
+
+PlanBody plan_body_factor() : { Object F; PlanBody R = null; Literal stmtLiteral; } // boolean hasPV = false; boolean isControl = true; }
+{
+
+( F = stmtIF()
+| F = stmtFOR()
+| F = stmtWHILE()
+| F = body_formula() { //isControl = false;
+ if (!(F instanceof PlanBody)) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!"); }
+)
+
+ //[ ";" { hasPV = true; }
+ //]
+ [ <TK_PAND> R = plan_body_factor() ]
+ {
+ if (R == null)
+ return (PlanBody)F;
+ try {
+ stmtLiteral = new InternalActionLiteral(ASSyntax.createStructure(".fork", jason.stdlib.fork.aAnd, (Term)F, (Term)R), curAg);
+ stmtLiteral.setSrcInfo( ((Term)F).getSrcInfo() );
+ return new PlanBodyImpl(BodyType.internalAction, stmtLiteral);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
+
+
PlanBody stmtIF() : { Object B; Term T1; Term T2 = null; Literal stmtLiteral; boolean useElse = false; }
{
<TK_IF>
@@ -606,7 +643,6 @@
if (B == null)
B = new PlanBodyImpl();
B.setAsBodyTerm(true);
-
return B;
}
}
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-03-13 20:16:54 UTC (rev 1879)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-03-21 18:51:04 UTC (rev 1880)
@@ -117,7 +117,7 @@
label_1:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 30:
+ case 32:
;
break;
default:
@@ -138,7 +138,7 @@
case TK_END:
case ATOM:
case UNNAMEDVAR:
- case 47:
+ case 49:
;
break;
default:
@@ -150,7 +150,7 @@
label_3:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 30:
+ case 32:
;
break;
default:
@@ -164,7 +164,7 @@
label_4:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 34:
+ case 36:
;
break;
default:
@@ -176,7 +176,7 @@
label_5:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 30:
+ case 32:
;
break;
default:
@@ -191,9 +191,9 @@
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_LABEL_AT:
- case 37:
- case 38:
case 39:
+ case 40:
+ case 41:
;
break;
default:
@@ -222,7 +222,7 @@
case TK_END:
case ATOM:
case UNNAMEDVAR:
- case 47:
+ case 49:
;
break;
default:
@@ -243,7 +243,7 @@
label_8:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 30:
+ case 32:
;
break;
default:
@@ -270,11 +270,11 @@
Agent bakAg = curAg;
boolean isEOF = false;
Atom oldNS = null;
- jj_consume_token(30);
+ jj_consume_token(32);
if (jj_2_1(4)) {
jj_consume_token(TK_BEGIN);
dir = pred();
- jj_consume_token(31);
+ jj_consume_token(33);
Agent innerAg = new Agent(); innerAg.initAg();
dir = new Pred(namespace, dir);
Directive d = directiveProcessor.getInstance(dir);
@@ -291,7 +291,7 @@
case TK_END:
case ATOM:
dir = pred();
- jj_consume_token(31);
+ jj_consume_token(33);
if (dir.toString().equals("end"))
{if (true) return true;}
dir = new Pred(namespace, dir);
@@ -323,8 +323,8 @@
{if (true) throw new ParseException(getSourceRef(h)+" variables cannot be beliefs!");}
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 32:
- jj_consume_token(32);
+ case 34:
+ jj_consume_token(34);
t = log_expr();
h = new Rule(h,(LogicalFormula)t);
// warning only not parsed files
@@ -339,7 +339,7 @@
jj_la1[9] = jj_gen;
;
}
- jj_consume_token(33);
+ jj_consume_token(35);
{if (true) return h;}
throw new Error("Missing return statement in function");
}
@@ -347,9 +347,9 @@
/* Initial goals */
final public Literal initial_goal() throws ParseException {
Literal g;
- jj_consume_token(34);
+ jj_consume_token(36);
g = literal();
- jj_consume_token(33);
+ jj_consume_token(35);
if (g.isVar()) {
{if (true) throw new ParseException(getSourceRef(g)+". a variable cannot be a goal!");}
}
@@ -378,8 +378,8 @@
// use literal to allow namespace
T = trigger();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 35:
- k = jj_consume_token(35);
+ case 37:
+ k = jj_consume_token(37);
C = log_expr();
if (start == -1) start = k.beginLine;
break;
@@ -388,8 +388,8 @@
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 36:
- k = jj_consume_token(36);
+ case 38:
+ k = jj_consume_token(38);
B = plan_body();
if (start == -1) start = k.beginLine;
break;
@@ -397,7 +397,7 @@
jj_la1[12] = jj_gen;
;
}
- k = jj_consume_token(33);
+ k = jj_consume_token(35);
if (start == -1) start = k.beginLine;
end = k.beginLine;
InternalActionLiteral ial = null;
@@ -418,16 +418,16 @@
TEType teType = TEType.belief;
Literal F;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 37:
- jj_consume_token(37);
+ case 39:
+ jj_consume_token(39);
teOp = TEOperator.add;
break;
- case 38:
- jj_consume_token(38);
+ case 40:
+ jj_consume_token(40);
teOp = TEOperator.del;
break;
- case 39:
- jj_consume_token(39);
+ case 41:
+ jj_consume_token(41);
teOp = TEOperator.goalState;
break;
default:
@@ -436,15 +436,15 @@
throw new ParseException();
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 34:
- case 40:
+ case 36:
+ case 42:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 34:
- jj_consume_token(34);
+ case 36:
+ jj_consume_token(36);
teType = TEType.achieve;
break;
- case 40:
- jj_consume_token(40);
+ case 42:
+ jj_consume_token(42);
teType = TEType.test;
break;
default:
@@ -464,17 +464,17 @@
/* Plan body */
final public PlanBody plan_body() throws ParseException {
- Object F; PlanBody R = null; boolean hasPV = false; boolean isControl = true;
+ Object F; PlanBody R = null;
+ F = plan_body_term();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case TK_IF:
- F = stmtIF();
+ case 43:
+ jj_consume_token(43);
break;
- case TK_FOR:
- F = stmtFOR();
- break;
- case TK_WHILE:
- F = stmtWHILE();
- break;
+ default:
+ jj_la1[16] = jj_gen;
+ ;
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case VAR:
case TK_TRUE:
case TK_FALSE:
@@ -482,36 +482,73 @@
case TK_NEG:
case TK_BEGIN:
case TK_END:
+ case TK_IF:
+ case TK_FOR:
+ case TK_WHILE:
case NUMBER:
case STRING:
case ATOM:
case UNNAMEDVAR:
- case 30:
- case 34:
- case 37:
- case 38:
+ case 32:
+ case 36:
+ case 39:
case 40:
case 42:
case 44:
- case 47:
- F = body_formula();
- isControl = false; if (!(F instanceof PlanBody)) {if (true) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!");}
+ case 46:
+ case 49:
+ R = plan_body();
break;
default:
- jj_la1[16] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
+ jj_la1[17] = jj_gen;
+ ;
}
+ if (R != null) {
+ //if (!isControl && !hasPV) {
+ // throw new ParseException(getSourceRef(F)+" Expected ';' after '"+F+"'.");
+ //}
+ ((PlanBody)F).setBodyNext( R );
+ }
+ {if (true) return (PlanBody)F;}
+ throw new Error("Missing return statement in function");
+ }
+
+ final public PlanBody plan_body_term() throws ParseException {
+ Object F; PlanBody R = null; Literal stmtLiteral;
+ F = plan_body_factor();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 41:
- jj_consume_token(41);
- hasPV = true;
+ case TK_POR:
+ jj_consume_token(TK_POR);
+ R = plan_body_term();
break;
default:
- jj_la1[17] = jj_gen;
+ jj_la1[18] = jj_gen;
;
}
+ if (R == null)
+ {if (true) return (PlanBody)F;}
+ try {
+ stmtLiteral = new InternalActionLiteral(ASSyntax.createStructure(".fork", jason.stdlib.fork.aOr, (Term)F, (Term)R), curAg);
+ stmtLiteral.setSrcInfo( ((Term)F).getSrcInfo() );
+ {if (true) return new PlanBodyImpl(BodyType.internalAction, stmtLiteral);}
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ throw new Error("Missing return statement in function");
+ }
+
+ final public PlanBody plan_body_factor() throws ParseException {
+ Object F; PlanBody R = null; Literal stmtLiteral;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case TK_IF:
+ F = stmtIF();
+ break;
+ case TK_FOR:
+ F = stmtFOR();
+ break;
+ case TK_WHILE:
+ F = stmtWHILE();
+ break;
case VAR:
case TK_TRUE:
case TK_FALSE:
@@ -519,61 +556,71 @@
case TK_NEG:
case TK_BEGIN:
case TK_END:
- case TK_IF:
- case TK_FOR:
- case TK_WHILE:
case NUMBER:
case STRING:
case ATOM:
case UNNAMEDVAR:
- case 30:
- case 34:
- case 37:
- case 38:
+ case 32:
+ case 36:
+ case 39:
case 40:
case 42:
case 44:
- case 47:
- R = plan_body();
+ case 46:
+ case 49:
+ F = body_formula();
+ //isControl = false;
+ if (!(F instanceof PlanBody)) {if (true) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!");}
break;
default:
- jj_la1[18] = jj_gen;
+ jj_la1[19] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case TK_PAND:
+ jj_consume_token(TK_PAND);
+ R = plan_body_factor();
+ break;
+ default:
+ jj_la1[20] = jj_gen;
;
}
- if (R != null) {
- if (!isControl && !hasPV) {
- {if (true) throw new ParseException(getSourceRef(F)+" Expected ';' after '"+F+"'.");}
- }
- ((PlanBody)F).setBodyNext( R );
- }
-
- {if (true) return (PlanBody)F;}
+ if (R == null)
+ {if (true) return (PlanBody)F;}
+ try {
+ stmtLiteral = new InternalActionLiteral(ASSyntax.createStructure(".fork", jason.stdlib.fork.aAnd, (Term)F, (Term)R), curAg);
+ stmtLiteral.setSrcInfo( ((Term)F).getSrcInfo() );
+ {if (true) return new PlanBodyImpl(BodyType.internalAction, stmtLiteral);}
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
throw new Error("Missing return statement in function");
}
final public PlanBody stmtIF() throws ParseException {
Object B; Term T1; Term T2 = null; Literal stmtLiteral; boolean useElse = false;
jj_consume_token(TK_IF);
- jj_consume_token(42);
+ jj_consume_token(44);
B = log_expr();
- jj_consume_token(43);
+ jj_consume_token(45);
T1 = rule_plan_term();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_ELSE:
- case 30:
+ case 32:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_ELSE:
jj_consume_token(TK_ELSE);
useElse = true;
break;
default:
- jj_la1[19] = jj_gen;
+ jj_la1[21] = jj_gen;
;
}
T2 = rule_plan_term();
break;
default:
- jj_la1[20] = jj_gen;
+ jj_la1[22] = jj_gen;
;
}
try {
@@ -603,9 +650,9 @@
final public PlanBody stmtFOR() throws ParseException {
Object B; Term T1; Literal stmtLiteral;
jj_consume_token(TK_FOR);
- jj_consume_token(42);
+ jj_consume_token(44);
B = log_expr();
- jj_consume_token(43);
+ jj_consume_token(45);
T1 = rule_plan_term();
try {
if (T1.isRule()) {
@@ -623,9 +670,9 @@
final public PlanBody stmtWHILE() throws ParseException {
Object B; Term T1; Literal stmtLiteral;
jj_consume_token(TK_WHILE);
- jj_consume_token(42);
+ jj_consume_token(44);
B = log_expr();
- jj_consume_token(43);
+ jj_consume_token(45);
T1 = rule_plan_term();
try {
if (T1.isRule()) {
@@ -643,80 +690,80 @@
final public Object body_formula() throws ParseException {
BodyType formType = BodyType.action; Object B;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 34:
- case 37:
- case 38:
+ case 36:
+ case 39:
case 40:
- case 44:
+ case 42:
+ case 46:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 34:
- jj_consume_token(34);
+ case 36:
+ jj_consume_token(36);
formType = BodyType.achieve;
break;
- case 44:
- jj_consume_token(44);
+ case 46:
+ jj_consume_token(46);
formType = BodyType.achieveNF;
break;
- case 40:
- jj_consume_token(40);
+ case 42:
+ jj_consume_token(42);
formType = BodyType.test;
break;
- case 37:
- jj_consume_token(37);
+ case 39:
+ jj_consume_token(39);
formType = BodyType.addBel;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 37:
- case 45:
- case 46:
+ case 39:
+ case 47:
+ case 48:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 37:
- jj_consume_token(37);
+ case 39:
+ jj_consume_token(39);
formType = BodyType.addBelNewFocus;
break;
- case 45:
- jj_consume_token(45);
+ case 47:
+ jj_consume_token(47);
formType = BodyType.addBel;
break;
- case 46:
- jj_consume_token(46);
+ case 48:
+ jj_consume_token(48);
formType = BodyType.addBelEnd;
break;
default:
- jj_la1[21] = jj_gen;
+ jj_la1[23] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
- jj_la1[22] = jj_gen;
+ jj_la1[24] = jj_gen;
;
}
break;
- case 38:
- jj_consume_token(38);
+ case 40:
+ jj_consume_token(40);
formType = BodyType.delBel;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 37:
- jj_consume_token(37);
+ case 39:
+ jj_consume_token(39);
formType = BodyType.delAddBel;
break;
default:
- jj_la1[23] = jj_gen;
+ jj_la1[25] = jj_gen;
;
}
break;
default:
- jj_la1[24] = jj_gen;
+ jj_la1[26] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
- jj_la1[25] = jj_gen;
+ jj_la1[27] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 30:
+ case 32:
B = rule_plan_term();
break;
case VAR:
@@ -730,14 +777,14 @@
case STRING:
case ATOM:
case UNNAMEDVAR:
- case 37:
- case 38:
- case 42:
- case 47:
+ case 39:
+ case 40:
+ case 44:
+ case 49:
B = log_expr();
break;
default:
- jj_la1[26] = jj_gen;
+ jj_la1[28] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -784,7 +831,7 @@
boolean pb = true; // pb = "only plan body"
Pred L = null;
Literal h = null; Object t = null;
- jj_consume_token(30);
+ jj_consume_token(32);
if (jj_2_2(4)) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_LABEL_AT:
@@ -793,41 +840,41 @@
pb = false;
break;
default:
- jj_la1[27] = jj_gen;
+ jj_la1[29] = jj_gen;
;
}
T = trigger();
if (T.getType() != TEType.belief) pb = false;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 35:
- jj_consume_token(35);
+ case 37:
+ jj_consume_token(37);
C = log_expr();
pb = false;
break;
default:
- jj_la1[28] = jj_gen;
+ jj_la1[30] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 36:
- case 41:
+ case 38:
+ case 43:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 36:
- jj_consume_token(36);
+ case 38:
+ jj_consume_token(38);
pb = false;
break;
- case 41:
- jj_consume_token(41);
+ case 43:
+ jj_consume_token(43);
if (!pb) {if (true) throw new ParseException(getSourceRef(T)+" Wrong place for ';'");}
break;
default:
- jj_la1[29] = jj_gen;
+ jj_la1[31] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
- jj_la1[30] = jj_gen;
+ jj_la1[32] = jj_gen;
;
}
} else {
@@ -835,7 +882,7 @@
}
if (jj_2_3(50)) {
h = literal();
- jj_consume_token(32);
+ jj_consume_token(34);
t = log_expr();
} else {
;
@@ -855,21 +902,21 @@
case STRING:
case ATOM:
case UNNAMEDVAR:
- case 30:
- case 34:
- case 37:
- case 38:
+ case 32:
+ case 36:
+ case 39:
case 40:
case 42:
case 44:
- case 47:
+ case 46:
+ case 49:
B = plan_body();
break;
default:
- jj_la1[31] = jj_gen;
+ jj_la1[33] = jj_gen;
;
}
- jj_consume_token(31);
+ jj_consume_token(33);
if (h != null) {
Rule r = new Rule(h,(LogicalFormula)t);
r.setAsTerm(true);
@@ -905,7 +952,6 @@
if (B == null)
B = new PlanBodyImpl();
B.setAsBodyTerm(true);
-
{if (true) return B;}
throw new Error("Missing return statement in function");
}
@@ -921,7 +967,7 @@
case TK_END:
case ATOM:
case UNNAMEDVAR:
- case 47:
+ case 49:
if (jj_2_4(10)) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case VAR:
@@ -946,16 +992,16 @@
explicitAbstractNS = false;
break;
default:
- jj_la1[32] = jj_gen;
+ jj_la1[34] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
- jj_la1[33] = jj_gen;
+ jj_la1[35] = jj_gen;
;
}
- jj_consume_token(47);
+ jj_consume_token(49);
if (explicitAbstractNS)
NS = thisnamespace;
} else {
@@ -967,7 +1013,7 @@
type = Literal.LNeg;
break;
default:
- jj_la1[34] = jj_gen;
+ jj_la1[36] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -984,7 +1030,7 @@
{if (true) return vt;}
break;
default:
- jj_la1[35] = jj_gen;
+ jj_la1[37] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -998,7 +1044,7 @@
{if (true) return Literal.LFalse;}
break;
default:
- jj_la1[36] = jj_gen;
+ jj_la1[38] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1041,30 +1087,30 @@
K = jj_consume_token(TK_END);
break;
default:
- jj_la1[37] = jj_gen;
+ jj_la1[39] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
p = new Pred(K.image);
p.setSrcInfo(new SourceInfo(asSource, K.beginLine));
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 42:
- jj_consume_token(42);
+ case 44:
+ jj_consume_token(44);
l = terms();
- jj_consume_token(43);
+ jj_consume_token(45);
p.setTerms(l);
break;
default:
- jj_la1[38] = jj_gen;
+ jj_la1[40] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 49:
+ case 51:
lt = list();
p.setAnnots(lt);
break;
default:
- jj_la1[39] = jj_gen;
+ jj_la1[41] = jj_gen;
;
}
namespace = ons;
@@ -1080,14 +1126,14 @@
label_9:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 48:
+ case 50:
;
break;
default:
- jj_la1[40] = jj_gen;
+ jj_la1[42] = jj_gen;
break label_9;
}
- jj_consume_token(48);
+ jj_consume_token(50);
v = term();
listTerms.add(v);
}
@@ -1099,10 +1145,10 @@
final public Term term() throws ParseException {
Object o;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 49:
+ case 51:
o = list();
break;
- case 30:
+ case 32:
o = rule_plan_term();
break;
case VAR:
@@ -1116,14 +1162,14 @@
case STRING:
case ATOM:
case UNNAMEDVAR:
- case 37:
- case 38:
- case 42:
- case 47:
+ case 39:
+ case 40:
+ case 44:
+ case 49:
o = log_expr();
break;
default:
- jj_la1[41] = jj_gen;
+ jj_la1[43] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1133,7 +1179,7 @@
final public ListTermImpl list() throws ParseException {
ListTermImpl lt = new ListTermImpl(); ListTerm last; Token K; Term f;
- jj_consume_token(49);
+ jj_consume_token(51);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case VAR:
case TK_TRUE:
@@ -1145,31 +1191,31 @@
case STRING:
case ATOM:
case UNNAMEDVAR:
- case 30:
- case 37:
- case 38:
- case 42:
- case 47:
+ case 32:
+ case 39:
+ case 40:
+ case 44:
case 49:
+ case 51:
f = term_in_list();
last = lt.append(f); lt.setSrcInfo(f.getSrcInfo());
label_10:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 48:
+ case 50:
;
break;
default:
- jj_la1[42] = jj_gen;
+ jj_la1[44] = jj_gen;
break label_10;
}
- jj_consume_token(48);
+ jj_consume_token(50);
f = term_in_list();
last = last.append(f);
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 50:
- jj_consume_token(50);
+ case 52:
+ jj_consume_token(52);
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case VAR:
K = jj_consume_token(VAR);
@@ -1179,26 +1225,26 @@
K = jj_consume_token(UNNAMEDVAR);
last.setNext(UnnamedVar.create(K.image));
break;
- case 49:
+ case 51:
f = list();
last = last.concat((ListTerm)f);
break;
default:
- jj_la1[43] = jj_gen;
+ jj_la1[45] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
- jj_la1[44] = jj_gen;
+ jj_la1[46] = jj_gen;
;
}
break;
default:
- jj_la1[45] = jj_gen;
+ jj_la1[47] = jj_gen;
;
}
- jj_consume_token(51);
+ jj_consume_token(53);
{if (true) return lt;}
throw new Error("Missing return statement in function");
}
@@ -1207,7 +1253,7 @@
final public Term term_in_list() throws ParseException {
Object o;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 49:
+ case 51:
o = list();
break;
case VAR:
@@ -1219,20 +1265,20 @@
case NUMBER:
case ATOM:
case UNNAMEDVAR:
- case 37:
- case 38:
- case 42:
- case 47:
+ case 39:
+ case 40:
+ case 44:
+ case 49:
o = arithm_expr();
break;
case STRING:
o = string();
break;
- case 30:
+ case 32:
o = rule_plan_term();
break;
default:
- jj_la1[46] = jj_gen;
+ jj_la1[48] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1245,13 +1291,13 @@
Object t1, t2;
t1 = log_expr_trm();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 50:
- jj_consume_token(50);
+ case 52:
+ jj_consume_token(52);
t2 = log_expr();
{if (true) return new LogExpr((LogicalFormula)t1,LogicalOp.or,(LogicalFormula)t2);}
break;
default:
- jj_la1[47] = jj_gen;
+ jj_la1[49] = jj_gen;
;
}
{if (true) return t1;}
@@ -1262,13 +1308,13 @@
Object t1, t2;
t1 = log_expr_factor();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 52:
- jj_consume_token(52);
+ case 54:
+ jj_consume_token(54);
t2 = log_expr_trm();
{if (true) return new LogExpr((LogicalFormula)t1,LogicalOp.and,(LogicalFormula)t2);}
break;
default:
- jj_la1[48] = jj_gen;
+ jj_la1[50] = jj_gen;
;
}
{if (true) return t1;}
@@ -1293,15 +1339,15 @@
case STRING:
case ATOM:
case UNNAMEDVAR:
- case 37:
- case 38:
- case 42:
- case 47:
+ case 39:
+ case 40:
+ case 44:
+ case 49:
t = rel_expr();
{if (true) return t;}
break;
default:
- jj_la1[49] = jj_gen;
+ jj_la1[51] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1329,64 +1375,64 @@
case NUMBER:
case ATOM:
case UNNAMEDVAR:
- case 37:
- case 38:
- case 42:
- case 47:
+ case 39:
+ case 40:
+ case 44:
+ case 49:
op1 = arithm_expr();
break;
case STRING:
op1 = string();
break;
default:
- jj_la1[50] = jj_gen;
+ jj_la1[52] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 45:
- case 46:
- case 53:
- case 54:
+ case 47:
+ case 48:
case 55:
case 56:
case 57:
case 58:
+ case 59:
+ case 60:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 45:
- jj_consume_token(45);
+ case 47:
+ jj_consume_token(47);
operator = RelationalOp.lt;
break;
- case 53:
- jj_consume_token(53);
+ case 55:
+ jj_consume_token(55);
operator = RelationalOp.lte;
break;
- case 46:
- jj_consume_token(46);
+ case 48:
+ jj_consume_token(48);
operator = RelationalOp.gt;
break;
- case 54:
- jj_consume_token(54);
+ case 56:
+ jj_consume_token(56);
operator = RelationalOp.gte;
break;
- case 55:
- jj_consume_token(55);
+ case 57:
+ jj_consume_token(57);
operator = RelationalOp.eq;
break;
- case 56:
- jj_consume_token(56);
+ case 58:
+ jj_consume_token(58);
operator = RelationalOp.dif;
break;
- case 57:
- jj_consume_token(57);
+ case 59:
+ jj_consume_token(59);
operator = RelationalOp.unify;
break;
- case 58:
- jj_consume_token(58);
+ case 60:
+ jj_consume_token(60);
operator = RelationalOp.literalBuilder;
break;
default:
- jj_la1[51] = jj_gen;
+ jj_la1[53] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1400,23 +1446,23 @@
case NUMBER:
case ATOM:
case UNNAMEDVAR:
- case 37:
- case 38:
- case 42:
- case 47:
+ case 39:
+ case 40:
+ case 44:
+ case 49:
op2 = arithm_expr();
break;
case STRING:
op2 = string();
break;
- case 49:
+ case 51:
op2 = list();
break;
- case 30:
+ case 32:
op2 = rule_plan_term();
break;
default:
- jj_la1[52] = jj_gen;
+ jj_la1[54] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1427,7 +1473,7 @@
{if (true) return new RelExpr((Term)op1, operator, (Term)op2);}
break;
default:
- jj_la1[53] = jj_gen;
+ jj_la1[55] = jj_gen;
;
}
{if (true) return op1;}
@@ -1442,25 +1488,25 @@
label_11:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 37:
- case 38:
+ case 39:
+ case 40:
;
break;
default:
- jj_la1[54] = jj_gen;
+ jj_la1[56] = jj_gen;
break label_11;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 37:
- jj_consume_token(37);
+ case 39:
+ jj_consume_token(39);
op = ArithmeticOp.plus;
break;
- case 38:
- jj_consume_token(38);
+ case 40:
+ jj_consume_token(40);
op = ArithmeticOp.minus;
break;
default:
- jj_la1[55] = jj_gen;
+ jj_la1[57] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1486,21 +1532,21 @@
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_INTDIV:
case TK_INTMOD:
- case 59:
- case 60:
+ case 61:
+ case 62:
;
break;
default:
- jj_la1[56] = jj_gen;
+ jj_la1[58] = jj_gen;
break label_12;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 59:
- jj_consume_token(59);
+ case 61:
+ jj_consume_token(61);
op = ArithmeticOp.times;
break;
- case 60:
- jj_consume_token(60);
+ case 62:
+ jj_consume_token(62);
op = ArithmeticOp.div;
break;
case TK_INTDIV:
@@ -1512,7 +1558,7 @@
op = ArithmeticOp.mod;
break;
default:
- jj_la1[57] = jj_gen;
+ jj_la1[59] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1534,8 +1580,8 @@
t1 = arithm_expr_simple();
op = ArithmeticOp.none;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 61:
- jj_consume_token(61);
+ case 63:
+ jj_consume_token(63);
op = ArithmeticOp.pow;
t2 = arithm_expr_factor();
if (!(t1 instanceof NumberTerm)) {
@@ -1547,7 +1593,7 @@
{if (true) return new ArithExpr((NumberTerm)t1, op, (NumberTerm)t2);}
break;
default:
- jj_la1[58] = jj_gen;
+ jj_la1[60] = jj_gen;
;
}
{if (true) return t1;}
@@ -1563,26 +1609,26 @@
ni.setSrcInfo(new SourceInfo(asSource, K.beginLine));
{if (true) return ni;}
break;
- case 38:
- jj_consume_token(38);
+ case 40:
+ jj_consume_token(40);
t = arithm_expr_simple();
if (!(t instanceof NumberTerm)) {
{if (true) throw new ParseException(getSourceRef(t)+" The argument '"+t+"' of operator '-' is not numeric or variable.");}
}
{if (true) return new ArithExpr(ArithmeticOp.minus, (NumberTerm)t);}
break;
- case 37:
- jj_consume_token(37);
+ case 39:
+ jj_consume_token(39);
t = arithm_expr_simple();
if (!(t instanceof NumberTerm)) {
{if (true) throw new ParseException(getSourceRef(t)+" The argument '"+t+"' of operator '+' is not numeric or variable.");}
}
{if (true) return new ArithExpr(ArithmeticOp.plus, (NumberTerm)t);}
break;
- case 42:
- jj_consume_token(42);
+ case 44:
+ jj_consume_token(44);
t = log_expr();
- jj_consume_token(43);
+ jj_consume_token(45);
{if (true) return t;}
break;
case VAR:
@@ -1593,12 +1639,12 @@
case TK_END:
case ATOM:
case UNNAMEDVAR:
- case 47:
+ case 49:
t = function();
{if (true) return t;}
break;
default:
- jj_la1[59] = jj_gen;
+ jj_la1[61] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1633,17 +1679,17 @@
v = UnnamedVar.create(ns, K.image);
break;
default:
- jj_la1[60] = jj_gen;
+ jj_la1[62] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 49:
+ case 51:
lt = list();
v.setAnnots(lt);
break;
default:
- jj_la1[61] = jj_gen;
+ jj_la1[63] = jj_gen;
;
}
{if (true) return v;}
@@ -1687,48 +1733,11 @@
finally { jj_save(3, xla); }
}
- final private boolean jj_3R_48() {
- if (jj_scan_token(40)) return true;
- return false;
- }
-
- final private boolean jj_3_3() {
+ final private boolean jj_3R_117() {
if (jj_3R_19()) return true;
- if (jj_scan_token(32)) return true;
- if (jj_3R_20()) return true;
return false;
}
- final private boolean jj_3R_47() {
- if (jj_scan_token(34)) return true;
- return false;
- }
-
- final private boolean jj_3R_33() {
- if (jj_scan_token(41)) return true;
- return false;
- }
-
- final private boolean jj_3R_72() {
- if (jj_3R_68()) return true;
- return false;
- }
-
- final private boolean jj_3R_32() {
- if (jj_scan_token(36)) return true;
- return false;
- }
-
- final private boolean jj_3R_71() {
- if (jj_3R_77()) return true;
- return false;
- }
-
- final private boolean jj_3R_70() {
- if (jj_3R_76()) return true;
- return false;
- }
-
final private boolean jj_3R_31() {
Token xsp;
xsp = jj_scanpos;
@@ -1739,93 +1748,36 @@
return false;
}
- final private boolean jj_3R_17() {
- if (jj_scan_token(35)) return true;
- if (jj_3R_20()) return true;
- return false;
- }
-
- final private boolean jj_3R_18() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_32()) {
- jj_scanpos = xsp;
- if (jj_3R_33()) return true;
- }
- return false;
- }
-
- final private boolean jj_3R_69() {
- if (jj_3R_42()) return true;
- return false;
- }
-
final private boolean jj_3R_30() {
- if (jj_scan_token(39)) return true;
+ if (jj_scan_token(41)) return true;
return false;
}
- final private boolean jj_3R_66() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_69()) {
- jj_scanpos = xsp;
- if (jj_3R_70()) {
- jj_scanpos = xsp;
- if (jj_3R_71()) {
- jj_scanpos = xsp;
- if (jj_3R_72()) return true;
- }
- }
- }
- return false;
- }
-
- final private boolean jj_3R_97() {
- if (jj_3R_42()) return true;
- return false;
- }
-
final private boolean jj_3R_29() {
- if (jj_scan_token(38)) return true;
+ if (jj_scan_token(40)) return true;
return false;
}
- final private boolean jj_3R_15() {
- if (jj_scan_token(TK_LABEL_AT)) return true;
- if (jj_3R_13()) return true;
+ final private boolean jj_3R_78() {
+ if (jj_scan_token(50)) return true;
+ if (jj_3R_55()) return true;
return false;
}
- final private boolean jj_3R_96() {
- if (jj_scan_token(UNNAMEDVAR)) return true;
- return false;
- }
-
- final private boolean jj_3R_77() {
- if (jj_scan_token(STRING)) return true;
- return false;
- }
-
final private boolean jj_3R_28() {
- if (jj_scan_token(37)) return true;
+ if (jj_scan_token(39)) return true;
return false;
}
- final private boolean jj_3R_95() {
- if (jj_scan_token(VAR)) return true;
+ final private boolean jj_3R_114() {
+ if (jj_3R_117()) return true;
return false;
}
- final private boolean jj_3_2() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_15()) jj_scanpos = xsp;
- if (jj_3R_16()) return true;
- xsp = jj_scanpos;
- if (jj_3R_17()) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_18()) jj_scanpos = xsp;
+ final private boolean jj_3R_113() {
+ if (jj_scan_token(44)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(45)) return true;
return false;
}
@@ -1845,151 +1797,6 @@
return false;
}
- final private boolean jj_3R_68() {
- if (jj_scan_token(30)) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3_2()) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3_3()) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_102()) jj_scanpos = xsp;
- if (jj_scan_token(31)) return true;
- return false;
- }
-
- final private boolean jj_3R_62() {
- if (jj_3R_42()) return true;
- return false;
- }
-
- final private boolean jj_3R_92() {
- if (jj_scan_token(50)) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_95()) {
- jj_scanpos = xsp;
- if (jj_3R_96()) {
- jj_scanpos = xsp;
- if (jj_3R_97()) return true;
- }
- }
- return false;
- }
-
- final private boolean jj_3R_91() {
- if (jj_scan_token(48)) return true;
- if (jj_3R_66()) return true;
- return false;
- }
-
- final private boolean jj_3R_61() {
- if (jj_scan_token(UNNAMEDVAR)) return true;
- return false;
- }
-
- final private boolean jj_3R_60() {
- if (jj_scan_token(VAR)) return true;
- return false;
- }
-
- final private boolean jj_3R_56() {
- if (jj_3R_66()) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_91()) { jj_scanpos = xsp; break; }
- }
- xsp = jj_scanpos;
- if (jj_3R_92()) jj_scanpos = xsp;
- return false;
- }
-
- final private boolean jj_3R_54() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_60()) {
- jj_scanpos = xsp;
- if (jj_3R_61()) return true;
- }
- xsp = jj_scanpos;
- if (jj_3R_62()) jj_scanpos = xsp;
- return false;
- }
-
- final private boolean jj_3R_42() {
- if (jj_scan_token(49)) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_56()) jj_scanpos = xsp;
- if (jj_scan_token(51)) return true;
- return false;
- }
-
- final private boolean jj_3R_65() {
- if (jj_3R_20()) return true;
- return false;
- }
-
- final private boolean jj_3R_64() {
- if (jj_3R_68()) return true;
- return false;
- }
-
- final private boolean jj_3R_63() {
- if (jj_3R_42()) return true;
- return false;
- }
-
- final private boolean jj_3R_57() {
- if (jj_scan_token(TK_LABEL_AT)) return true;
- return false;
- }
-
- final private boolean jj_3R_55() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_63()) {
- jj_scanpos = xsp;
- if (jj_3R_64()) {
- jj_scanpos = xsp;
- if (jj_3R_65()) return true;
- }
- }
- return false;
- }
-
- final private boolean jj_3R_46() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_57()) jj_scanpos = xsp;
- if (jj_3R_16()) return true;
- return false;
- }
-
- final private boolean jj_3R_121() {
- if (jj_3R_19()) return true;
- return false;
- }
-
- final private boolean jj_3R_78() {
- if (jj_scan_token(48)) return true;
- if (jj_3R_55()) return true;
- return false;
- }
-
- final private boolean jj_3R_114() {
- if (jj_3R_121()) return true;
- return false;
- }
-
- final private boolean jj_3R_113() {
- if (jj_scan_token(42)) return true;
- if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
- return false;
- }
-
final private boolean jj_3R_41() {
if (jj_3R_55()) return true;
Token xsp;
@@ -2001,18 +1808,13 @@
}
final private boolean jj_3R_112() {
- if (jj_scan_token(37)) return true;
+ if (jj_scan_token(39)) return true;
if (jj_3R_103()) return true;
return false;
}
- final private boolean jj_3R_45() {
- if (jj_scan_token(34)) return true;
- return false;
- }
-
final private boolean jj_3R_111() {
- if (jj_scan_token(38)) return true;
+ if (jj_scan_token(40)) return true;
if (jj_3R_103()) return true;
return false;
}
@@ -2022,23 +1824,33 @@
return false;
}
+ final private boolean jj_3R_132() {
+ if (jj_3R_20()) return true;
+ return false;
+ }
+
final private boolean jj_3R_110() {
if (jj_scan_token(NUMBER)) return true;
return false;
}
final private boolean jj_3R_22() {
- if (jj_scan_token(42)) return true;
+ if (jj_scan_token(44)) return true;
if (jj_3R_41()) return true;
- if (jj_scan_token(43)) return true;
+ if (jj_scan_token(45)) return true;
return false;
}
- final private boolean jj_3R_129() {
- if (jj_3R_20()) return true;
+ final private boolean jj_3R_140() {
+ if (jj_scan_token(39)) return true;
return false;
}
+ final private boolean jj_3R_131() {
+ if (jj_3R_68()) return true;
+ return false;
+ }
+
final private boolean jj_3R_103() {
Token xsp;
xsp = jj_scanpos;
@@ -2058,64 +1870,72 @@
return false;
}
- final private boolean jj_3R_137() {
- if (jj_scan_token(37)) return true;
+ final private boolean jj_3R_143() {
+ if (jj_scan_token(48)) return true;
return false;
}
- final private boolean jj_3R_128() {
- if (jj_3R_68()) return true;
+ final private boolean jj_3R_142() {
+ if (jj_scan_token(47)) return true;
return false;
}
- final private boolean jj_3R_140() {
- if (jj_scan_token(46)) return true;
+ final private boolean jj_3R_141() {
+ if (jj_scan_token(39)) return true;
return false;
}
- final private boolean jj_3R_139() {
- if (jj_scan_token(45)) return true;
- return false;
- }
-
final private boolean jj_3R_138() {
- if (jj_scan_token(37)) return true;
- return false;
- }
-
- final private boolean jj_3R_135() {
- if (jj_scan_token(38)) return true;
+ if (jj_scan_token(40)) return true;
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_137()) jj_scanpos = xsp;
+ if (jj_3R_140()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_136() {
+ final private boolean jj_3R_139() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_138()) {
+ if (jj_3R_141()) {
jj_scanpos = xsp;
- if (jj_3R_139()) {
+ if (jj_3R_142()) {
jj_scanpos = xsp;
- if (jj_3R_140()) return true;
+ if (jj_3R_143()) return true;
}
}
return false;
}
- final private boolean jj_3R_134() {
- if (jj_scan_token(37)) return true;
+ final private boolean jj_3R_57() {
+ if (jj_scan_token(TK_LABEL_AT)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_46() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_136()) jj_scanpos = xsp;
+ if (jj_3R_57()) jj_scanpos = xsp;
+ if (jj_3R_16()) return true;
return false;
}
+ final private boolean jj_3R_137() {
+ if (jj_scan_token(39)) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_139()) jj_scanpos = xsp;
+ return false;
+ }
+
+ final private boolean jj_3R_136() {
+ if (jj_scan_token(42)) return true;
+ return false;
+ }
+
final private boolean jj_3R_13() {
Token xsp;
xsp = jj_scanpos;
- if (jj_scan_token(23)) {
+ if (jj_scan_token(25)) {
jj_scanpos = xsp;
if (jj_scan_token(14)) {
jj_scanpos = xsp;
@@ -2129,38 +1949,28 @@
return false;
}
- final private boolean jj_3R_133() {
- if (jj_scan_token(40)) return true;
+ final private boolean jj_3R_135() {
+ if (jj_scan_token(46)) return true;
return false;
}
- final private boolean jj_3R_44() {
- if (jj_3R_19()) return true;
+ final private boolean jj_3R_134() {
+ if (jj_scan_token(36)) return true;
return false;
}
- final private boolean jj_3R_132() {
- if (jj_scan_token(44)) return true;
- return false;
- }
-
- final private boolean jj_3R_131() {
- if (jj_scan_token(34)) return true;
- return false;
- }
-
- final private boolean jj_3R_127() {
+ final private boolean jj_3R_130() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_131()) {
+ if (jj_3R_134()) {
jj_scanpos = xsp;
- if (jj_3R_132()) {
+ if (jj_3R_135()) {
jj_scanpos = xsp;
- if (jj_3R_133()) {
+ if (jj_3R_136()) {
jj_scanpos = xsp;
- if (jj_3R_134()) {
+ if (jj_3R_137()) {
jj_scanpos = xsp;
- if (jj_3R_135()) return true;
+ if (jj_3R_138()) return true;
}
}
}
@@ -2169,7 +1979,7 @@
}
final private boolean jj_3R_104() {
- if (jj_scan_token(61)) return true;
+ if (jj_scan_token(63)) return true;
if (jj_3R_98()) return true;
return false;
}
@@ -2182,18 +1992,23 @@
return false;
}
- final private boolean jj_3R_125() {
+ final private boolean jj_3R_128() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_127()) jj_scanpos = xsp;
+ if (jj_3R_130()) jj_scanpos = xsp;
xsp = jj_scanpos;
- if (jj_3R_128()) {
+ if (jj_3R_131()) {
jj_scanpos = xsp;
- if (jj_3R_129()) return true;
+ if (jj_3R_132()) return true;
}
return false;
}
+ final private boolean jj_3R_45() {
+ if (jj_scan_token(36)) return true;
+ return false;
+ }
+
final private boolean jj_3R_108() {
if (jj_scan_token(TK_INTMOD)) return true;
return false;
@@ -2205,12 +2020,12 @@
}
final private boolean jj_3R_106() {
- if (jj_scan_token(60)) return true;
+ if (jj_scan_token(62)) return true;
return false;
}
final private boolean jj_3R_105() {
- if (jj_scan_token(59)) return true;
+ if (jj_scan_token(61)) return true;
return false;
}
@@ -2241,11 +2056,11 @@
return false;
}
- final private boolean jj_3R_124() {
+ final private boolean jj_3R_127() {
if (jj_scan_token(TK_WHILE)) return true;
- if (jj_scan_token(42)) return true;
+ if (jj_scan_token(44)) return true;
if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
+ if (jj_scan_token(45)) return true;
if (jj_3R_68()) return true;
return false;
}
@@ -2266,12 +2081,17 @@
}
final private boolean jj_3R_101() {
- if (jj_scan_token(38)) return true;
+ if (jj_scan_token(40)) return true;
return false;
}
+ final private boolean jj_3R_44() {
+ if (jj_3R_19()) return true;
+ return false;
+ }
+
final private boolean jj_3R_100() {
- if (jj_scan_token(37)) return true;
+ if (jj_scan_token(39)) return true;
return false;
}
@@ -2296,14 +2116,6 @@
return false;
}
- final private boolean jj_3_1() {
- if (jj_scan_token(TK_BEGIN)) return true;
- if (jj_3R_13()) return true;
- if (jj_scan_token(31)) return true;
- if (jj_3R_14()) return true;
- return false;
- }
-
final private boolean jj_3R_76() {
if (jj_3R_93()) return true;
Token xsp;
@@ -2314,16 +2126,11 @@
return false;
}
- final private boolean jj_3R_43() {
- if (jj_scan_token(30)) return true;
- return false;
- }
-
- final private boolean jj_3R_123() {
+ final private boolean jj_3R_126() {
if (jj_scan_token(TK_FOR)) return true;
- if (jj_scan_token(42)) return true;
+ if (jj_scan_token(44)) return true;
if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
+ if (jj_scan_token(45)) return true;
if (jj_3R_68()) return true;
return false;
}
@@ -2354,7 +2161,7 @@
}
final private boolean jj_3R_86() {
- if (jj_scan_token(58)) return true;
+ if (jj_scan_token(60)) return true;
return false;
}
@@ -2364,7 +2171,7 @@
}
final private boolean jj_3R_85() {
- if (jj_scan_token(57)) return true;
+ if (jj_scan_token(59)) return true;
return false;
}
@@ -2379,12 +2186,12 @@
}
final private boolean jj_3R_84() {
- if (jj_scan_token(56)) return true;
+ if (jj_scan_token(58)) return true;
return false;
}
final private boolean jj_3R_83() {
- if (jj_scan_token(55)) return true;
+ if (jj_scan_token(57)) return true;
return false;
}
@@ -2392,27 +2199,27 @@
Token xsp;
xsp = jj_scanpos;
if (jj_3R_21()) jj_scanpos = xsp;
- if (jj_scan_token(47)) return true;
+ if (jj_scan_token(49)) return true;
return false;
}
final private boolean jj_3R_82() {
- if (jj_scan_token(54)) return true;
+ if (jj_scan_token(56)) return true;
return false;
}
final private boolean jj_3R_81() {
- if (jj_scan_token(46)) return true;
+ if (jj_scan_token(48)) return true;
return false;
}
final private boolean jj_3R_80() {
- if (jj_scan_token(53)) return true;
+ if (jj_scan_token(55)) return true;
return false;
}
final private boolean jj_3R_79() {
- if (jj_scan_token(45)) return true;
+ if (jj_scan_token(47)) return true;
return false;
}
@@ -2492,11 +2299,32 @@
return false;
}
- final private boolean jj_3R_130() {
+ final private boolean jj_3_1() {
+ if (jj_scan_token(TK_BEGIN)) return true;
+ if (jj_3R_13()) return true;
+ if (jj_scan_token(33)) return true;
+ if (jj_3R_14()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_133() {
if (jj_scan_token(TK_ELSE)) return true;
return false;
}
+ final private boolean jj_3R_129() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_133()) jj_scanpos = xsp;
+ if (jj_3R_68()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_43() {
+ if (jj_scan_token(32)) return true;
+ return false;
+ }
+
final private boolean jj_3R_67() {
Token xsp;
xsp = jj_scanpos;
@@ -2509,77 +2337,270 @@
return false;
}
- final private boolean jj_3R_126() {
+ final private boolean jj_3R_125() {
+ if (jj_scan_token(TK_IF)) return true;
+ if (jj_scan_token(44)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(45)) return true;
+ if (jj_3R_68()) return true;
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_130()) jj_scanpos = xsp;
- if (jj_3R_68()) return true;
+ if (jj_3R_129()) jj_scanpos = xsp;
return false;
}
+ final private boolean jj_3R_59() {
+ if (jj_3R_67()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_58() {
+ if (jj_scan_token(TK_NOT)) return true;
+ if (jj_3R_52()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_124() {
+ if (jj_scan_token(TK_PAND)) return true;
+ if (jj_3R_118()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_52() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_58()) {
+ jj_scanpos = xsp;
+ if (jj_3R_59()) return true;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_53() {
+ if (jj_scan_token(54)) return true;
+ if (jj_3R_37()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_37() {
+ if (jj_3R_52()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_53()) jj_scanpos = xsp;
+ return false;
+ }
+
+ final private boolean jj_3R_123() {
+ if (jj_3R_128()) return true;
+ return false;
+ }
+
...
[truncated message content] |
|
From: <jom...@us...> - 2016-03-13 20:16:56
|
Revision: 1879
http://sourceforge.net/p/jason/svn/1879
Author: jomifred
Date: 2016-03-13 20:16:54 +0000 (Sun, 13 Mar 2016)
Log Message:
-----------
handle fail_goal with fork/join
Modified Paths:
--------------
trunk/src/jason/asSemantics/Intention.java
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/asSyntax/PlanLibrary.java
trunk/src/jason/stdlib/fail_goal.java
trunk/src/jason/stdlib/fork.java
trunk/src/jason/util/Pair.java
Modified: trunk/src/jason/asSemantics/Intention.java
===================================================================
--- trunk/src/jason/asSemantics/Intention.java 2016-03-13 15:27:52 UTC (rev 1878)
+++ trunk/src/jason/asSemantics/Intention.java 2016-03-13 20:16:54 UTC (rev 1879)
@@ -26,9 +26,12 @@
import jason.asSyntax.ListTerm;
import jason.asSyntax.ListTermImpl;
import jason.asSyntax.NumberTermImpl;
+import jason.asSyntax.PlanLibrary;
import jason.asSyntax.Structure;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
+import jason.asSyntax.Trigger.TEOperator;
+import jason.util.Pair;
import java.io.Serializable;
import java.util.ArrayDeque;
@@ -106,7 +109,6 @@
atomicCount = a;
}
-
public Iterator<IntendedMeans> iterator() {
return intendedMeans.iterator();
}
@@ -167,6 +169,29 @@
return false;
}
+ public void fail(Circumstance c) {
+ }
+
+ public Pair<Event, Integer> findEventForFailure(Trigger tevent, PlanLibrary pl, Circumstance c) {
+ Trigger failTrigger = new Trigger(TEOperator.del, tevent.getType(), tevent.getLiteral());
+ Iterator<IntendedMeans> ii = iterator();
+ int posInStak = size();
+ while (!pl.hasCandidatePlan(failTrigger) && ii.hasNext()) {
+ // TODO: pop IM until +!g or *!g (this TODO is valid only if meta events are pushed on top of the intention)
+ // If *!g is found first, no failure event
+ // - while popping, if some meta event (* > !) is in the stack, stop and simple pop instead of producing an failure event
+ IntendedMeans im = ii.next();
+ tevent = im.getTrigger();
+ failTrigger = new Trigger(TEOperator.del, tevent.getType(), tevent.getLiteral());
+ posInStak--;
+ }
+ if (tevent.isGoal() && tevent.isAddition() && pl.hasCandidatePlan(failTrigger))
+ return new Pair<Event, Integer>(new Event(failTrigger.clone(), this), posInStak);
+ else
+ return new Pair<Event, Integer>(null, 0);
+ }
+
+
/** implements atomic intentions > not atomic intentions */
public int compareTo(Intention o) {
if (o.atomicCount > this.atomicCount) return 1;
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2016-03-13 15:27:52 UTC (rev 1878)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2016-03-13 20:16:54 UTC (rev 1879)
@@ -932,7 +932,7 @@
}
// if has finished a failure handling IM ...
- if (im.getTrigger().isGoal() && !im.getTrigger().isAddition() && !i.isFinished()) {//i.size() > 0) {
+ if (im.getTrigger().isGoal() && !im.getTrigger().isAddition() && !i.isFinished()) {
// needs to get rid of the IM until a goal that
// has failure handling. E.g,
// -!b
@@ -1116,6 +1116,7 @@
if (logger.isLoggable(Level.FINE)) logger.fine("Generating goal deletion " + failEvent.getTrigger() + " from goal: " + im.getTrigger());
} else {
logger.warning("No failure event was generated for " + failEvent.getTrigger());
+ i.fail(getC());
}
}
// if "discard" is set, we are deleting the whole intention!
@@ -1156,6 +1157,8 @@
//logger.warning("Generating goal deletion " + failEvent.getTrigger() + " from event: " + ev.getTrigger());
} else {
logger.warning("No fail event was generated for " + ev.getTrigger());
+ if (ev.intention != null)
+ ev.intention.fail(getC());
}
} else if (ev.isInternal()) {
logger.warning("Could not finish intention:\n" + ev.intention);
@@ -1171,22 +1174,13 @@
}
public Event findEventForFailure(Intention i, Trigger tevent) {
- Trigger failTrigger = new Trigger(TEOperator.del, tevent.getType(), tevent.getLiteral());
if (i != Intention.EmptyInt) {
- Iterator<IntendedMeans> ii = i.iterator();
- while (!getAg().getPL().hasCandidatePlan(failTrigger) && ii.hasNext()) {
- // TODO: pop IM until +!g or *!g (this TODO is valid only if meta events are pushed on top of the intention)
- // If *!g is found first, no failure event
- // - while popping, if some meta event (* > !) is in the stack, stop and simple pop instead of producing an failure event
- IntendedMeans im = ii.next();
- tevent = im.getTrigger();
- failTrigger = new Trigger(TEOperator.del, tevent.getType(), tevent.getLiteral());
- }
+ return i.findEventForFailure(tevent, getAg().getPL(), getC()).getFirst();
+ } else if (tevent.isGoal() && tevent.isAddition()) {
+ Trigger failTrigger = new Trigger(TEOperator.del, tevent.getType(), tevent.getLiteral());
+ if (getAg().getPL().hasCandidatePlan(failTrigger))
+ return new Event(failTrigger.clone(), i);
}
- // if some failure handling plan is found
- if (tevent.isGoal() && tevent.isAddition() && getAg().getPL().hasCandidatePlan(failTrigger)) {
- return new Event(failTrigger.clone(), i);
- }
return null;
}
Modified: trunk/src/jason/asSyntax/PlanLibrary.java
===================================================================
--- trunk/src/jason/asSyntax/PlanLibrary.java 2016-03-13 15:27:52 UTC (rev 1878)
+++ trunk/src/jason/asSyntax/PlanLibrary.java 2016-03-13 20:16:54 UTC (rev 1879)
@@ -344,7 +344,10 @@
}
public boolean hasCandidatePlan(Trigger te) {
- return getCandidatePlans(te) != null;
+ if (te == null)
+ return false;
+ else
+ return getCandidatePlans(te) != null;
}
Modified: trunk/src/jason/stdlib/fail_goal.java
===================================================================
--- trunk/src/jason/stdlib/fail_goal.java 2016-03-13 15:27:52 UTC (rev 1878)
+++ trunk/src/jason/stdlib/fail_goal.java 2016-03-13 20:16:54 UTC (rev 1879)
@@ -26,10 +26,10 @@
import jason.JasonException;
import jason.asSemantics.Event;
import jason.asSemantics.GoalListener;
+import jason.asSemantics.GoalListener.FinishStates;
import jason.asSemantics.Intention;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
-import jason.asSemantics.GoalListener.FinishStates;
import jason.asSyntax.Literal;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
@@ -115,6 +115,8 @@
if (ts.hasGoalListener())
for (GoalListener gl: ts.getGoalListeners())
gl.goalFinished(g, FinishStates.unachieved);
+
+ i.fail(ts.getC());
return 3;
}
}
Modified: trunk/src/jason/stdlib/fork.java
===================================================================
--- trunk/src/jason/stdlib/fork.java 2016-03-13 15:27:52 UTC (rev 1878)
+++ trunk/src/jason/stdlib/fork.java 2016-03-13 20:16:54 UTC (rev 1879)
@@ -24,7 +24,9 @@
package jason.stdlib;
import jason.JasonException;
+import jason.asSemantics.Circumstance;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.Event;
import jason.asSemantics.IntendedMeans;
import jason.asSemantics.Intention;
import jason.asSemantics.InternalAction;
@@ -37,9 +39,11 @@
import jason.asSyntax.PlanBody;
import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.PlanBodyImpl;
+import jason.asSyntax.PlanLibrary;
import jason.asSyntax.Structure;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
+import jason.util.Pair;
import java.util.HashSet;
import java.util.Set;
@@ -180,5 +184,32 @@
}
return r;
}
+
+ @Override
+ public void fail(Circumstance c) {
+ if (size() >= forkPoint && fd.isAnd) { // the fail is above fork, is an fork and, remove the others
+ for (Intention ifo: fd.intentions) {
+ drop_intention.dropInt(c, ifo);
+ }
+ }
+ }
+
+ @Override
+ public Pair<Event, Integer> findEventForFailure(Trigger tevent, PlanLibrary pl, Circumstance c) {
+ Pair<Event, Integer> p = super.findEventForFailure(tevent, pl, c);
+ if (p.getSecond() <= forkPoint) {
+ if (fd.isAnd) {
+ //System.out.println("*** remove other forks");
+ fd.intentions.remove(this);
+ for (Intention ifo: fd.intentions) {
+ drop_intention.dropInt(c, ifo);
+ }
+ } else {
+ //System.out.println("*** case or, do not search for fail plan below fork point");
+ return new Pair<Event, Integer>(null, p.getSecond());
+ }
+ }
+ return p;
+ }
}
}
Modified: trunk/src/jason/util/Pair.java
===================================================================
--- trunk/src/jason/util/Pair.java 2016-03-13 15:27:52 UTC (rev 1878)
+++ trunk/src/jason/util/Pair.java 2016-03-13 20:16:54 UTC (rev 1879)
@@ -5,12 +5,14 @@
final T1 o1;
final T2 o2;
- int hc;
+ int hc = 0;
public Pair(T1 o1, T2 o2) {
this.o1 = o1;
this.o2 = o2;
- hc = (o1.hashCode() + o2.hashCode()) * 31;
+ if (o1 != null) hc =+ o1.hashCode();
+ if (o2 != null) hc =+ o2.hashCode();
+ hc = hc * 31;
}
public T1 getFirst() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-03-13 15:27:55
|
Revision: 1878
http://sourceforge.net/p/jason/svn/1878
Author: jomifred
Date: 2016-03-13 15:27:52 +0000 (Sun, 13 Mar 2016)
Log Message:
-----------
initial implementation of internal actions .fork and .join
Modified Paths:
--------------
trunk/src/jason/asSemantics/Circumstance.java
trunk/src/jason/asSemantics/Intention.java
trunk/src/jason/stdlib/drop_intention.java
trunk/src/jason/stdlib/succeed_goal.java
trunk/src/jason/stdlib/wait.java
Added Paths:
-----------
trunk/src/jason/stdlib/fork.java
trunk/src/jason/stdlib/join.java
Modified: trunk/src/jason/asSemantics/Circumstance.java
===================================================================
--- trunk/src/jason/asSemantics/Circumstance.java 2016-03-13 11:31:38 UTC (rev 1877)
+++ trunk/src/jason/asSemantics/Circumstance.java 2016-03-13 15:27:52 UTC (rev 1878)
@@ -332,6 +332,7 @@
el.intentionResumed(intention);
}
+ /** remove intention from set I */
public boolean removeIntention(Intention i) {
if (i == AI) {
setAtomicIntention(null);
Modified: trunk/src/jason/asSemantics/Intention.java
===================================================================
--- trunk/src/jason/asSemantics/Intention.java 2016-03-13 11:31:38 UTC (rev 1877)
+++ trunk/src/jason/asSemantics/Intention.java 2016-03-13 15:27:52 UTC (rev 1878)
@@ -54,12 +54,12 @@
private static AtomicInteger idCount = new AtomicInteger(0);
private int id;
- private int atomicCount = 0; // how many atomic intended means there are in the intention
+ private int atomicCount = 0; // number of atomic intended means in the intention
private boolean isSuspended = false;
private Deque<IntendedMeans> intendedMeans = new ArrayDeque<IntendedMeans>();
- //private Trigger initialTrigger = null; // just for adicional information/debug (not really necessary)
+ //private Trigger initialTrigger = null; // just for additional information/debug (not really necessary)
//static private Logger logger = Logger.getLogger(Intention.class.getName());
@@ -118,6 +118,10 @@
public int size() {
return intendedMeans.size();
}
+
+ public void clearIM() {
+ intendedMeans.clear();
+ }
public void setSuspended(boolean b) {
isSuspended = b;
@@ -192,8 +196,14 @@
for (IntendedMeans im: intendedMeans) {
i.intendedMeans.add((IntendedMeans)im.clone());
}
- return i;
+ return i;
}
+
+ // used by fork
+ public void copyTo(Intention i) {
+ i.atomicCount = atomicCount;
+ i.intendedMeans = new ArrayDeque<IntendedMeans>(intendedMeans);
+ }
public String toString() {
StringBuilder s = new StringBuilder("intention "+id+": \n");
Modified: trunk/src/jason/stdlib/drop_intention.java
===================================================================
--- trunk/src/jason/stdlib/drop_intention.java 2016-03-13 11:31:38 UTC (rev 1877)
+++ trunk/src/jason/stdlib/drop_intention.java 2016-03-13 15:27:52 UTC (rev 1878)
@@ -136,4 +136,31 @@
}
}
}
+
+ public static void dropInt(Circumstance C, Intention del) {
+
+ // intention may be suspended in E or PE
+ Iterator<Event> ie = C.getEventsPlusAtomic();
+ while (ie.hasNext()) {
+ Event e = ie.next();
+ Intention i = e.getIntention();
+ if (i != null && i.equals(del)) {
+ C.removeEvent(e);
+ }
+ }
+ for (String k: C.getPendingEvents().keySet()) {
+ Intention i = C.getPendingEvents().get(k).getIntention();
+ if (i != null && i.equals(del)) {
+ C.removePendingEvent(k);
+ }
+ }
+
+ // intention may be suspended in PA! (in the new semantics)
+ C.dropPendingAction(del);
+ C.dropIntention(del);
+
+ // intention may be suspended in PI! (in the new semantics)
+ C.dropPendingIntention(del);
+ }
+
}
Added: trunk/src/jason/stdlib/fork.java
===================================================================
--- trunk/src/jason/stdlib/fork.java (rev 0)
+++ trunk/src/jason/stdlib/fork.java 2016-03-13 15:27:52 UTC (rev 1878)
@@ -0,0 +1,184 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://www.inf.ufrgs.br/~bordini
+// http://www.das.ufsc.br/~jomi
+//
+//----------------------------------------------------------------------------
+
+package jason.stdlib;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.IntendedMeans;
+import jason.asSemantics.Intention;
+import jason.asSemantics.InternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.Atom;
+import jason.asSyntax.InternalActionLiteral;
+import jason.asSyntax.Literal;
+import jason.asSyntax.ObjectTermImpl;
+import jason.asSyntax.PlanBody;
+import jason.asSyntax.PlanBody.BodyType;
+import jason.asSyntax.PlanBodyImpl;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+import jason.asSyntax.Trigger;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+Implementation of <b>.fort</b> (used for |& and || operators).
+
+<p>Syntax:
+<pre>
+ <i>plan_body1</i> "|&" | "||" <i>plan_body2</i> ....
+</pre>
+</p>
+
+|& is concurrent and: both plan_body1 and plan_body2 have to finishes successfully
+|| is concurrent or : either plan_body1 or plan_body2 have to finishes successfully
+
+
+<p>Example:
+<pre>
+</pre>
+</p>
+
+*/
+public class fork extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new fork();
+ return singleton;
+ }
+
+ @Override public Term[] prepareArguments(Literal body, Unifier un) {
+ return body.getTermsArray();
+ }
+
+ @Override public int getMinArgs() { return 2; }
+
+ @Override protected void checkArguments(Term[] args) throws JasonException {
+ super.checkArguments(args); // check number of arguments
+ if ( !(args[0] instanceof Atom))
+ throw JasonException.createWrongArgument(this,"first argument must be 'and' or 'or'.");
+ }
+
+ @Override public boolean suspendIntention() { return true; }
+
+ @Override public boolean canBeUsedInContext() { return false; }
+
+ private static final Structure joinS = new Structure(".join");
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ checkArguments(args);
+
+ ForkData fd = new ForkData( ((Atom)args[0]).getFunctor().equals("and")) ;
+
+ Intention currentInt = ts.getC().getSelectedIntention();
+ for (int iPlans = 1; iPlans < args.length; iPlans++) {
+ Intention i = new ForkIntention(currentInt, fd);
+ fd.addIntention(i);
+ i.pop(); // remove the top IM, it will be introduced back later (modified)
+ IntendedMeans im = (IntendedMeans)currentInt.peek().clone();
+
+ // adds the .join in the plan
+ InternalActionLiteral joinL = new InternalActionLiteral(joinS, ts.getAg());
+ joinL.addTerm(new ObjectTermImpl(fd));
+ PlanBody joinPB = new PlanBodyImpl(BodyType.internalAction, joinL);
+ joinPB.setBodyNext(im.getCurrentStep().getBodyNext());
+
+ // adds the argument in the plan (before join)
+ PlanBody whattoadd = (PlanBody)args[iPlans].clone();
+ whattoadd.add(joinPB);
+ whattoadd.setAsBodyTerm(false);
+ im.insertAsNextStep(whattoadd);
+ im.removeCurrentStep(); // remove the .fork
+ i.push(im);
+ ts.getC().addIntention(i);
+ }
+
+
+ return true;
+ }
+
+ class ForkData {
+ boolean isAnd = true;
+ Set<Intention> intentions = new HashSet<Intention>();
+ int toFinish = 0;
+
+ public ForkData(boolean isAnd) {
+ this.isAnd = isAnd;
+ }
+
+ public void addIntention(Intention i) {
+ intentions.add(i);
+ toFinish++;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder s = new StringBuilder("fork data");
+ if (isAnd)
+ s.append(" (and) ");
+ else
+ s.append(" (or) ");
+ s.append(" intentions = { ");
+ for (Intention i: intentions) {
+ s.append(" "+i.getId());
+ }
+ s.append(" } waiting for "+toFinish);
+ return s.toString();
+ }
+ }
+
+ class ForkIntention extends Intention {
+ ForkData fd;
+ int forkPoint;
+
+ ForkIntention(Intention i, ForkData fd) {
+ i.copyTo(this);
+ forkPoint = i.size();
+ this.fd = fd;
+ }
+
+ @Override
+ public boolean dropGoal(Trigger te, Unifier un) {
+ boolean r = super.dropGoal(te, un);
+ if (r && size() < forkPoint) {
+ //System.out.println("drop "+te+" i.size = "+size()+" fork point "+forkPoint+" to f "+fd+"\n"+this);
+ if (fd.toFinish > 0) { // the first intentions of the fork being dropped, keep it and ignore the rest
+ fd.toFinish = 0;
+ //System.out.println("put it back");
+ return true;
+ } else {
+ clearIM();
+ //System.out.println("ignore intention");
+ return false;
+ }
+ }
+ return r;
+ }
+ }
+}
Added: trunk/src/jason/stdlib/join.java
===================================================================
--- trunk/src/jason/stdlib/join.java (rev 0)
+++ trunk/src/jason/stdlib/join.java 2016-03-13 15:27:52 UTC (rev 1878)
@@ -0,0 +1,87 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://www.inf.ufrgs.br/~bordini
+// http://www.das.ufsc.br/~jomi
+//
+//----------------------------------------------------------------------------
+
+package jason.stdlib;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.Intention;
+import jason.asSemantics.InternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.Literal;
+import jason.asSyntax.ObjectTerm;
+import jason.asSyntax.Term;
+import jason.stdlib.fork.ForkData;
+
+/** injected by .fork */
+public class join extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new join();
+ return singleton;
+ }
+
+ @Override public Term[] prepareArguments(Literal body, Unifier un) {
+ return body.getTermsArray();
+ }
+
+ @Override protected void checkArguments(Term[] args) throws JasonException {
+ }
+
+ @Override public boolean suspendIntention() { return true; }
+ @Override public boolean canBeUsedInContext() { return false; }
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ checkArguments(args);
+
+ Intention currentInt = ts.getC().getSelectedIntention();
+ ForkData fd = (ForkData) ((ObjectTerm)args[0]).getObject();
+ fd.toFinish--;
+ //System.out.println("** in join for "+currentInt.getId()+ " with "+fd);
+
+ // in the case of fork and, all intentions should be finished to continue
+ if (fd.isAnd) {
+ if (fd.toFinish == 0) {
+ //System.out.println("join finished!");
+ currentInt.peek().removeCurrentStep();
+ ts.getC().addIntention(currentInt);
+ }
+ } else {
+ // the first intention has finished, drop others
+ fd.intentions.remove(currentInt);
+ for (Intention i: fd.intentions) {
+ //System.out.println("drop "+i.getId());
+ drop_intention.dropInt(ts.getC(), i);
+ }
+ currentInt.peek().removeCurrentStep();
+ ts.getC().addIntention(currentInt);
+ }
+
+ return true;
+ }
+
+}
Modified: trunk/src/jason/stdlib/succeed_goal.java
===================================================================
--- trunk/src/jason/stdlib/succeed_goal.java 2016-03-13 11:31:38 UTC (rev 1877)
+++ trunk/src/jason/stdlib/succeed_goal.java 2016-03-13 15:27:52 UTC (rev 1878)
@@ -129,7 +129,7 @@
} else {
// test in the event
Trigger t = e.getTrigger();
- if (i != Intention.EmptyInt && !i.isFinished()) { //i.size() > 0) {
+ if (i != Intention.EmptyInt && !i.isFinished()) {
t = t.capply(i.peek().getUnif());
}
if (un.unifies(g, t)) {
Modified: trunk/src/jason/stdlib/wait.java
===================================================================
--- trunk/src/jason/stdlib/wait.java 2016-03-13 11:31:38 UTC (rev 1877)
+++ trunk/src/jason/stdlib/wait.java 2016-03-13 15:27:52 UTC (rev 1878)
@@ -189,7 +189,7 @@
} else {
ts.generateGoalDeletion(si, JasonException.createBasicErrorAnnots("wait_timeout", "timeout in .wait"));
}
- } else {
+ } else if (! si.isFinished()) {
si.peek().removeCurrentStep();
if (elapsedTimeTerm != null) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-03-13 11:31:41
|
Revision: 1877
http://sourceforge.net/p/jason/svn/1877
Author: jomifred
Date: 2016-03-13 11:31:38 +0000 (Sun, 13 Mar 2016)
Log Message:
-----------
.relevant_plans can have a var as first arg
Modified Paths:
--------------
trunk/examples/contract-net-protocol/c.asl
trunk/src/jason/stdlib/relevant_plans.java
trunk/src/jason/stdlib/remove_plan.java
Modified: trunk/examples/contract-net-protocol/c.asl
===================================================================
--- trunk/examples/contract-net-protocol/c.asl 2016-03-07 13:22:11 UTC (rev 1876)
+++ trunk/examples/contract-net-protocol/c.asl 2016-03-13 11:31:38 UTC (rev 1877)
@@ -1,9 +1,9 @@
/* Initial beliefs and rules */
all_proposals_received(CNPId)
- :- .count(introduction(participant,_),NP) & // number of participants
- .count(propose(CNPId,_), NO) & // number of proposes received
- .count(refuse(CNPId), NR) & // number of refusals received
+ :- .count(introduction(participant,_),NP) & // number of participants
+ .count(propose(CNPId,_)[source(_)], NO) & // number of proposes received
+ .count(refuse(CNPId)[source(_)], NR) & // number of refusals received
NP = NO + NR.
/* Initial goals */
Modified: trunk/src/jason/stdlib/relevant_plans.java
===================================================================
--- trunk/src/jason/stdlib/relevant_plans.java 2016-03-07 13:22:11 UTC (rev 1876)
+++ trunk/src/jason/stdlib/relevant_plans.java 2016-03-13 11:31:38 UTC (rev 1877)
@@ -63,6 +63,8 @@
<li> <code>.relevant_plans({+!go(X,Y)},LP, LL)</code>: same as above but also
unifies LL with a list of labels of plans in LP.</li>
+ <li> <code>.relevant_plans({+!_},_,LL)</code>: gets the labels of all achievement goals.</li>
+
</ul>
@see jason.stdlib.add_plan
Modified: trunk/src/jason/stdlib/remove_plan.java
===================================================================
--- trunk/src/jason/stdlib/remove_plan.java 2016-03-07 13:22:11 UTC (rev 1876)
+++ trunk/src/jason/stdlib/remove_plan.java 2016-03-13 11:31:38 UTC (rev 1877)
@@ -89,16 +89,14 @@
if (args.length > 1) {
source = (Atom)args[1];
}
-
if (label.isList()) { // arg[0] is a list
- boolean r = true;
- ListTerm lt = (ListTerm)args[0];
- for (Term t: lt) {
- r = r && ts.getAg().getPL().remove((Atom)t, source);
+ for (Term t: (ListTerm)args[0]) {
+ //r = r && ts.getAg().getPL().remove((Atom)t, source);
+ ts.getAg().getPL().remove((Atom)t, source);
}
- return r;
} else { // args[0] is a plan label
- return ts.getAg().getPL().remove((Atom)label, source);
+ ts.getAg().getPL().remove((Atom)label, source);
}
+ return true;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-03-07 13:22:13
|
Revision: 1876
http://sourceforge.net/p/jason/svn/1876
Author: jomifred
Date: 2016-03-07 13:22:11 +0000 (Mon, 07 Mar 2016)
Log Message:
-----------
fix .relevant_plans to work with vars
Modified Paths:
--------------
trunk/src/jason/asSyntax/ASSyntax.java
trunk/src/jason/asSyntax/PlanLibrary.java
trunk/src/jason/asSyntax/directives/NameSpace.java
trunk/src/jason/stdlib/desire.java
trunk/src/jason/stdlib/package.html
Modified: trunk/src/jason/asSyntax/ASSyntax.java
===================================================================
--- trunk/src/jason/asSyntax/ASSyntax.java 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/asSyntax/ASSyntax.java 2016-03-07 13:22:11 UTC (rev 1876)
@@ -121,6 +121,17 @@
}
/**
+ * Creates a new literal, the first argument is the namespace, the second is either Literal.LPos or Literal.LNeg,
+ * the third is the functor (a string),
+ * and the n remainder arguments are terms. see documentation of this
+ * class for examples of use.
+ */
+ public static Literal createLiteral(Atom namespace, boolean positive, String functor, Term... terms) {
+ return new LiteralImpl(namespace, positive, functor).addTerms(terms);
+ }
+
+
+ /**
* Creates a new structure (compound) term, the first argument is the functor (a string),
* and the n remainder arguments are terms.
*/
@@ -153,6 +164,11 @@
return new VarTerm(functor);
}
+ /** creates a new variable term in a namespace */
+ public static VarTerm createVar(Atom namespace, String functor) {
+ return new VarTerm(namespace, functor);
+ }
+
/** creates a new variable term (possibly negated) */
public static VarTerm createVar(boolean negated, String functor) {
VarTerm v = new VarTerm(functor);
Modified: trunk/src/jason/asSyntax/PlanLibrary.java
===================================================================
--- trunk/src/jason/asSyntax/PlanLibrary.java 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/asSyntax/PlanLibrary.java 2016-03-07 13:22:11 UTC (rev 1876)
@@ -354,14 +354,24 @@
}
public List<Plan> getCandidatePlans(Trigger te) {
- List<Plan> l = relPlans.get(te.getPredicateIndicator());
- if ((l == null || l.isEmpty()) && !varPlans.isEmpty() && te != TE_JAG_SLEEPING && te != TE_JAG_AWAKING) { // no rel plan, try varPlan
- for (Plan p: varPlans)
+ List<Plan> l = null;
+ if (te.getLiteral().isVar()) { // add all plans!
+ for (Plan p: this)
if (p.getTrigger().sameType(te)) {
if (l == null)
l = new ArrayList<Plan>();
l.add(p);
- }
+ }
+ } else {
+ l = relPlans.get(te.getPredicateIndicator());
+ if ((l == null || l.isEmpty()) && !varPlans.isEmpty() && te != TE_JAG_SLEEPING && te != TE_JAG_AWAKING) { // no rel plan, try varPlan
+ for (Plan p: varPlans)
+ if (p.getTrigger().sameType(te)) {
+ if (l == null)
+ l = new ArrayList<Plan>();
+ l.add(p);
+ }
+ }
}
return l; // if no rel plan, have to return null instead of empty list
}
Modified: trunk/src/jason/asSyntax/directives/NameSpace.java
===================================================================
--- trunk/src/jason/asSyntax/directives/NameSpace.java 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/asSyntax/directives/NameSpace.java 2016-03-07 13:22:11 UTC (rev 1876)
@@ -47,10 +47,14 @@
}
String type = ((Atom)directive.getTerm(1)).getFunctor();
if (!type.equals("local") && !type.equals("global")) {
- logger.log(Level.SEVERE, "The second parameter of the directive namespace should be local or global");
+ logger.log(Level.SEVERE, "The second parameter of the directive namespace should be either local or global");
return;
}
- if (type.equals("local")) {
+ if (type.equals("global") && isLocalNS(ns)) {
+ logger.warning("The namespace "+ns+" was previously defined as local, changing it to globall!");
+ localNSs.remove(ns);
+ }
+ if (type.equals("local")) {
ns = addLocalNS(ns);
}
}
@@ -79,9 +83,12 @@
static private int nsCounter = 0;
private synchronized Atom addLocalNS(Atom ns) {
- nsCounter++;
- Atom newNS = new Atom(LOCAL_PREFIX+nsCounter+ns);
- localNSs.put(ns,newNS);
+ Atom newNS = localNSs.get(ns);
+ if (newNS == null) {
+ nsCounter++;
+ newNS = new Atom(LOCAL_PREFIX+nsCounter+ns);
+ localNSs.put(ns,newNS);
+ }
return newNS;
}
}
Modified: trunk/src/jason/stdlib/desire.java
===================================================================
--- trunk/src/jason/stdlib/desire.java 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/stdlib/desire.java 2016-03-07 13:22:11 UTC (rev 1876)
@@ -118,10 +118,11 @@
Unifier solution = null; // the current response (which is an unifier)
Iterator<Event> evtIterator = null;
Iterator<Unifier> intendInterator = null;
+ {
+ find();
+ }
public boolean hasNext() {
- if (solution == null) // the first call of hasNext should find the first response
- find();
//if (solution == null)
// logger.info("* no more solution for "+teFromL+C);
return solution != null;
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/stdlib/package.html 2016-03-07 13:22:11 UTC (rev 1876)
@@ -34,7 +34,7 @@
<li>{@link jason.stdlib.findall findall}: find a list of beliefs of some kind.</li>
<li>{@link jason.stdlib.setof setof}: find a set of beliefs of some kind.</li>
<li>{@link jason.stdlib.count count}: count the number of beliefs of some kind.</li>
- <li>{@link jason.stdlib.name_space name_space}: checks whether an argument is a name space.</li>
+ <li>{@link jason.stdlib.namespace namespace}: checks whether an argument is a name space.</li>
</ul>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-03-02 10:22:19
|
Revision: 1875
http://sourceforge.net/p/jason/svn/1875
Author: jomifred
Date: 2016-03-02 10:22:16 +0000 (Wed, 02 Mar 2016)
Log Message:
-----------
support namespace in plans label
Modified Paths:
--------------
trunk/src/jason/asSyntax/PlanLibrary.java
trunk/src/jason/asSyntax/Structure.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/stdlib/plan_label.java
Modified: trunk/src/jason/asSyntax/PlanLibrary.java
===================================================================
--- trunk/src/jason/asSyntax/PlanLibrary.java 2016-03-01 10:18:40 UTC (rev 1874)
+++ trunk/src/jason/asSyntax/PlanLibrary.java 2016-03-02 10:22:16 UTC (rev 1875)
@@ -156,9 +156,9 @@
*/
public void add(Plan p, boolean before) throws JasonException {
// test p.label
- if (p.getLabel() != null && planLabels.keySet().contains(p.getLabel().getFunctor())) {
+ if (p.getLabel() != null && planLabels.keySet().contains( getStringForLabel(p.getLabel()))) {
// test if the new plan is equal, in this case, just add a source
- Plan planInPL = get(p.getLabel().getFunctor());
+ Plan planInPL = get(p.getLabel());
if (p.equals(planInPL)) {
planInPL.getLabel().addSource(p.getLabel().getSources().get(0));
return;
@@ -183,7 +183,7 @@
p.setAsPlanTerm(false); // it is not a term anymore
- planLabels.put(p.getLabel().getFunctor(), p);
+ planLabels.put( getStringForLabel(p.getLabel()), p);
Trigger pte = p.getTrigger();
if (pte.getLiteral().isVar()) {
@@ -235,6 +235,13 @@
}
}
+ private String getStringForLabel(Atom p) {
+ if (p.getNS() == Literal.DefaultNS)
+ return p.getFunctor();
+ else
+ return p.getNS()+"::"+p.getFunctor();
+ }
+
public boolean hasMetaEventPlans() {
return hasMetaEventPlans;
}
@@ -254,8 +261,12 @@
/** return a plan for a label */
public Plan get(String label) {
- return planLabels.get(label);
+ return get(new Atom(label));
}
+ /** return a plan for a label */
+ public Plan get(Atom label) {
+ return planLabels.get(getStringForLabel(label));
+ }
public int size() {
return plans.size();
@@ -283,13 +294,13 @@
*/
public boolean remove(Atom pLabel, Term source) {
// find the plan
- Plan p = get(pLabel.getFunctor());
+ Plan p = get(pLabel);
if (p != null) {
boolean hasSource = p.getLabel().delSource(source);
// if no source anymore, remove the plan
if (hasSource && !p.getLabel().hasSource()) {
- remove(pLabel.getFunctor());
+ remove(pLabel);
}
return true;
}
@@ -297,8 +308,8 @@
}
/** remove the plan with label <i>pLabel</i> */
- public Plan remove(String pLabel) {
- Plan p = planLabels.remove(pLabel);
+ public Plan remove(Atom pLabel) {
+ Plan p = planLabels.remove( getStringForLabel(pLabel) );
// remove it from plans' list
plans.remove(p);
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2016-03-01 10:18:40 UTC (rev 1874)
+++ trunk/src/jason/asSyntax/Structure.java 2016-03-02 10:22:16 UTC (rev 1875)
@@ -147,7 +147,10 @@
if (!getFunctor().equals(tAsStruct.getFunctor()))
return false;
-
+
+ if (!getNS().equals(tAsStruct.getNS()))
+ return false;
+
for (int i=0; i<ts; i++)
if (!getTerm(i).equals(tAsStruct.getTerm(i)))
return false;
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-03-01 10:18:40 UTC (rev 1874)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-03-02 10:22:16 UTC (rev 1875)
@@ -123,6 +123,8 @@
if (u.isAtom()) {
if (((Atom)u).getFunctor().equals("default"))
return Literal.DefaultNS;
+ else if (((Atom)u).getFunctor().equals("this_ns"))
+ return thisnamespace;
else
return new Atom((Literal)u);
}
@@ -331,13 +333,13 @@
/* Plan */
Plan plan() : { Token k;
- Pred L = null;
+ Pred L = null; Literal L2;
Trigger T;
Object C = null;
PlanBody B = null;
int start = -1, end;}
{
- [ k = <TK_LABEL_AT> L=pred() { start = k.beginLine; } ]
+ [ k = <TK_LABEL_AT> L2=literal() { start = k.beginLine; L = new Pred(L2); } ] // use literal to allow namespace
T=trigger()
[ k = ":" C = log_expr() { if (start == -1) start = k.beginLine; } ]
[ k = "<-" B = plan_body() { if (start == -1) start = k.beginLine; } ]
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-03-01 10:18:40 UTC (rev 1874)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-03-02 10:22:16 UTC (rev 1875)
@@ -92,6 +92,8 @@
if (u.isAtom()) {
if (((Atom)u).getFunctor().equals("default"))
return Literal.DefaultNS;
+ else if (((Atom)u).getFunctor().equals("this_ns"))
+ return thisnamespace;
else
return new Atom((Literal)u);
}
@@ -358,7 +360,7 @@
/* Plan */
final public Plan plan() throws ParseException {
Token k;
- Pred L = null;
+ Pred L = null; Literal L2;
Trigger T;
Object C = null;
PlanBody B = null;
@@ -366,14 +368,15 @@
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_LABEL_AT:
k = jj_consume_token(TK_LABEL_AT);
- L = pred();
- start = k.beginLine;
+ L2 = literal();
+ start = k.beginLine; L = new Pred(L2);
break;
default:
jj_la1[10] = jj_gen;
;
}
- T = trigger();
+ // use literal to allow namespace
+ T = trigger();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 35:
k = jj_consume_token(35);
@@ -1684,20 +1687,15 @@
finally { jj_save(3, xla); }
}
- final private boolean jj_3_3() {
- if (jj_3R_19()) return true;
- if (jj_scan_token(32)) return true;
- if (jj_3R_20()) return true;
- return false;
- }
-
final private boolean jj_3R_48() {
if (jj_scan_token(40)) return true;
return false;
}
- final private boolean jj_3R_72() {
- if (jj_3R_68()) return true;
+ final private boolean jj_3_3() {
+ if (jj_3R_19()) return true;
+ if (jj_scan_token(32)) return true;
+ if (jj_3R_20()) return true;
return false;
}
@@ -1711,6 +1709,11 @@
return false;
}
+ final private boolean jj_3R_72() {
+ if (jj_3R_68()) return true;
+ return false;
+ }
+
final private boolean jj_3R_32() {
if (jj_scan_token(36)) return true;
return false;
@@ -1721,6 +1724,11 @@
return false;
}
+ final private boolean jj_3R_70() {
+ if (jj_3R_76()) return true;
+ return false;
+ }
+
final private boolean jj_3R_31() {
Token xsp;
xsp = jj_scanpos;
@@ -1731,11 +1739,6 @@
return false;
}
- final private boolean jj_3R_70() {
- if (jj_3R_76()) return true;
- return false;
- }
-
final private boolean jj_3R_17() {
if (jj_scan_token(35)) return true;
if (jj_3R_20()) return true;
Modified: trunk/src/jason/stdlib/plan_label.java
===================================================================
--- trunk/src/jason/stdlib/plan_label.java 2016-03-01 10:18:40 UTC (rev 1874)
+++ trunk/src/jason/stdlib/plan_label.java 2016-03-02 10:22:16 UTC (rev 1875)
@@ -27,6 +27,7 @@
import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
+import jason.asSyntax.Atom;
import jason.asSyntax.Plan;
import jason.asSyntax.Term;
@@ -75,7 +76,12 @@
checkArguments(args);
Term label = args[1];
- Plan p = ts.getAg().getPL().get(label.toString());
+ Plan p;
+ if (label.isAtom())
+ p = ts.getAg().getPL().get( (Atom)label);
+ else
+ p = ts.getAg().getPL().get( new Atom(label.toString()));
+
if (p != null) {
p = (Plan)p.clone();
p.getLabel().delSources();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-03-01 10:18:43
|
Revision: 1874
http://sourceforge.net/p/jason/svn/1874
Author: jomifred
Date: 2016-03-01 10:18:40 +0000 (Tue, 01 Mar 2016)
Log Message:
-----------
update kqmlPlans to support NS
manage local namespaces in unification and .namespace
.include support the namespace as parameter
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestNS.java
trunk/src/asl/kqmlPlans.asl
trunk/src/jason/asSemantics/Unifier.java
trunk/src/jason/asSyntax/ASSyntax.java
trunk/src/jason/asSyntax/LiteralImpl.java
trunk/src/jason/asSyntax/directives/NameSpace.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/bb/DefaultBeliefBase.java
trunk/src/jason/stdlib/include.java
trunk/src/test/BeliefBaseTest.java
trunk/src/test/NSTest.java
trunk/src/xml/agInspection.xsl
Added Paths:
-----------
trunk/src/jason/stdlib/namespace.java
Removed Paths:
-------------
trunk/src/jason/stdlib/name_space.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestNS.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestNS.java 2016-02-24 19:59:41 UTC (rev 1873)
+++ trunk/applications/as-unit-test/src/jason/tests/TestNS.java 2016-03-01 10:18:40 UTC (rev 1874)
@@ -37,10 +37,10 @@
" .findall(FV, NS::b(FV,_::_), L); "+
" jason.asunit.print(L); "+
". \n" +
- "+!ia : .name_space(ns1) <- "+
- " .findall(J, .name_space(J), L); "+
+ "+!ia : .namespace(ns1) <- "+
+ " .findall(J, .namespace(J), L); "+
" jason.asunit.print(L); "+
- " .findall(X, .name_space(NS) & NS::b(X,_::_), L2); "+
+ " .findall(X, .namespace(NS) & NS::b(X,_::_), L2); "+
" jason.asunit.print(L2); "+
" .findall(NS, NS::b(_,o), L3); "+ // all name spaces with b(_,o)
" jason.asunit.print(L3); "+
@@ -56,8 +56,10 @@
" jason.asunit.print(V); "+
" N::Y =.. [ns,p,[10,20],[a1]]; "+
" jason.asunit.print(N,\"::\",Y); "+
- " jason.asunit.print(N::Y); "+
- ". "
+ " jason.asunit.print(N::Y). "+
+ "{ begin namespace(k2,local) }" +
+ " b(550, ink2). "+
+ "{ end }"
);
}
Modified: trunk/src/asl/kqmlPlans.asl
===================================================================
--- trunk/src/asl/kqmlPlans.asl 2016-02-24 19:59:41 UTC (rev 1873)
+++ trunk/src/asl/kqmlPlans.asl 2016-03-01 10:18:40 UTC (rev 1874)
@@ -11,12 +11,12 @@
/* ---- tell performatives ---- */
@kqmlReceivedTellStructure
-+!kqml_received(Sender, tell, Content, _)
++!kqml_received(Sender, tell, NS::Content, _)
: .literal(Content) &
.ground(Content) &
not .list(Content) &
.add_nested_source(Content, Sender, CA)
- <- +CA.
+ <- +NS::CA.
@kqmlReceivedTellList
+!kqml_received(Sender, tell, Content, _)
: .list(Content)
@@ -26,11 +26,11 @@
+!add_all_kqml_received(_,[]).
@kqmlReceivedTellList2
-+!add_all_kqml_received(Sender,[H|T])
++!add_all_kqml_received(Sender,[NS::H|T])
: .literal(H) &
.ground(H)
<- .add_nested_source(H, Sender, CA);
- +CA;
+ +NS::CA;
!add_all_kqml_received(Sender,T).
@kqmlReceivedTellList3
@@ -38,17 +38,17 @@
<- !add_all_kqml_received(Sender,T).
@kqmlReceivedUnTell
-+!kqml_received(Sender, untell, Content, _)
++!kqml_received(Sender, untell, NS::Content, _)
<- .add_nested_source(Content, Sender, CA);
- -CA.
+ -NS::CA.
/* ---- achieve performatives ---- */
@kqmlReceivedAchieve
-+!kqml_received(Sender, achieve, Content, _)
++!kqml_received(Sender, achieve, NS::Content, _)
: not .list(Content) & .add_nested_source(Content, Sender, CA)
- <- !!CA.
+ <- !!NS::CA.
@kqmlReceivedAchieveList
+!kqml_received(Sender, achieve, Content, _)
: .list(Content)
@@ -59,31 +59,31 @@
+!add_all_kqml_achieve(_,[]).
@kqmlReceivedAchieveList2
-+!add_all_kqml_achieve(Sender,[H|T])
++!add_all_kqml_achieve(Sender,[NS::H|T])
<- .add_nested_source(H, Sender, CA);
- !!CA;
+ !!NS::CA;
!add_all_kqml_achieve(Sender,T).
@kqmlReceivedUnAchieve[atomic]
-+!kqml_received(_, unachieve, Content, _)
- <- .drop_desire(Content).
++!kqml_received(_, unachieve, NS::Content, _)
+ <- .drop_desire(NS::Content).
/* ---- ask performatives ---- */
@kqmlReceivedAskOne1
-+!kqml_received(Sender, askOne, Content, MsgId)
- <- ?Content;
- .send(Sender, tell, Content, MsgId).
++!kqml_received(Sender, askOne, NS::Content, MsgId)
+ <- ?NS::Content;
+ .send(Sender, tell, NS::Content, MsgId).
@kqmlReceivedAskOne2 // error in askOne, send untell
--!kqml_received(Sender, askOne, Content, MsgId)
- <- .send(Sender, untell, Content, MsgId).
+-!kqml_received(Sender, askOne, NS::Content, MsgId)
+ <- .send(Sender, untell, NS::Content, MsgId).
@kqmlReceivedAskAll2
-+!kqml_received(Sender, askAll, Content, MsgId)
- <- .findall(Content, Content, List);
++!kqml_received(Sender, askAll, NS::Content, MsgId)
+ <- .findall(NS::Content, NS::Content, List);
.send(Sender, tell, List, MsgId).
Modified: trunk/src/jason/asSemantics/Unifier.java
===================================================================
--- trunk/src/jason/asSemantics/Unifier.java 2016-02-24 19:59:41 UTC (rev 1873)
+++ trunk/src/jason/asSemantics/Unifier.java 2016-03-01 10:18:40 UTC (rev 1874)
@@ -36,6 +36,7 @@
import jason.asSyntax.Trigger;
import jason.asSyntax.UnnamedVar;
import jason.asSyntax.VarTerm;
+import jason.asSyntax.directives.NameSpace;
import java.util.HashMap;
import java.util.Iterator;
@@ -351,7 +352,9 @@
Literal lvl = (Literal)vl;
if (! unifiesNamespace(vt, lvl) )
return false;
- if (lvl.getNS() != Literal.DefaultNS)
+ if (lvl.getFunctor().startsWith(NameSpace.LOCAL_PREFIX)) // cannot unify a var with a local namespace
+ return false;
+ if (lvl.getNS() != Literal.DefaultNS)
vl = lvl.cloneNS(Literal.DefaultNS);
}
Modified: trunk/src/jason/asSyntax/ASSyntax.java
===================================================================
--- trunk/src/jason/asSyntax/ASSyntax.java 2016-02-24 19:59:41 UTC (rev 1873)
+++ trunk/src/jason/asSyntax/ASSyntax.java 2016-03-01 10:18:40 UTC (rev 1874)
@@ -70,7 +70,9 @@
keywords.add(new PredicateIndicator("all_unifs", 0));
keywords.add(new PredicateIndicator("default", 0));
- keywords.add(new PredicateIndicator("source", 0));
+ keywords.add(new PredicateIndicator("this_ns", 0));
+
+ keywords.add(new PredicateIndicator("source", 1));
keywords.add(new PredicateIndicator("self", 0));
keywords.add(new PredicateIndicator("percept", 0));
Modified: trunk/src/jason/asSyntax/LiteralImpl.java
===================================================================
--- trunk/src/jason/asSyntax/LiteralImpl.java 2016-02-24 19:59:41 UTC (rev 1873)
+++ trunk/src/jason/asSyntax/LiteralImpl.java 2016-03-01 10:18:40 UTC (rev 1874)
@@ -171,7 +171,7 @@
@Override
public Element getAsDOM(Document document) {
Element u = (Element) document.createElement("literal");
- u.setAttribute("name-space", getNS().getFunctor());
+ u.setAttribute("namespace", getNS().getFunctor());
if (negated()) {
u.setAttribute("negated", negated()+"");
}
Modified: trunk/src/jason/asSyntax/directives/NameSpace.java
===================================================================
--- trunk/src/jason/asSyntax/directives/NameSpace.java 2016-02-24 19:59:41 UTC (rev 1873)
+++ trunk/src/jason/asSyntax/directives/NameSpace.java 2016-03-01 10:18:40 UTC (rev 1874)
@@ -14,6 +14,8 @@
/** Implementation of the <code>namespace</code> directive. */
public class NameSpace implements Directive {
+ public static final String LOCAL_PREFIX = "#";
+
static Logger logger = Logger.getLogger(NameSpace.class.getName());
private Map<Atom,Atom> localNSs = new HashMap<Atom,Atom>();
@@ -78,7 +80,7 @@
static private int nsCounter = 0;
private synchronized Atom addLocalNS(Atom ns) {
nsCounter++;
- Atom newNS = new Atom("#"+nsCounter+ns);
+ Atom newNS = new Atom(LOCAL_PREFIX+nsCounter+ns);
localNSs.put(ns,newNS);
return newNS;
}
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-24 19:59:41 UTC (rev 1873)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-03-01 10:18:40 UTC (rev 1874)
@@ -52,7 +52,10 @@
public class as2j {
private String asSource = null;
private Agent curAg = null;
- private Atom namespace = Literal.DefaultNS;
+
+ private Atom namespace = Literal.DefaultNS;
+ private Atom thisnamespace = Literal.DefaultNS;
+
private DirectiveProcessor directiveProcessor = new DirectiveProcessor();
private NameSpace nsDirective = (NameSpace)directiveProcessor.getInstance("namespace");
@@ -61,7 +64,7 @@
private static Config config = Config.get(false);
public void setAg(Agent ag) { curAg = ag; }
- public void setNS(Atom ns) { namespace = ns; }
+ public void setNS(Atom ns) { namespace = ns; thisnamespace = ns; }
public Atom getNS() { return namespace; }
private String getSourceRef(SourceInfo s) {
@@ -610,23 +613,32 @@
/* Literal */
Literal literal() :
{ Pred F = null; Pred V; Token k; boolean type = Literal.LPos;
- Atom NS = namespace; Token tns = null; }
+ Atom NS = namespace; Token tns = null; boolean explicitAbstractNS = true; }
{
( (
// namespace
[ LOOKAHEAD(10)
+ [
(tns = <ATOM> { if (tns.image.equals("default"))
NS = Literal.DefaultNS;
- else
+ else if (tns.image.equals("this_ns"))
+ NS = thisnamespace;
+ else
NS = new Atom(tns.image);
+ explicitAbstractNS = false;
}
|
NS = var(Literal.DefaultNS)
{ if (NS.hasAnnot())
throw new ParseException(getSourceRef(NS)+" name space cannot have annotations.");
+ explicitAbstractNS = false;
}
- )
+ )
+ ]
"::"
+ { if (explicitAbstractNS)
+ NS = thisnamespace;
+ }
]
[ <TK_NEG> { type = Literal.LNeg; }
@@ -668,7 +680,9 @@
}
/* Annotated Formulae */
-Pred pred() : { Token K; Pred p; List l; ListTerm lt; Term b; }
+Pred pred() : { Token K; Pred p; List l; ListTerm lt; Term b;
+ Atom ons = namespace; namespace = Literal.DefaultNS; // do not replace abstract namespace for terms
+ }
{
(
K=<ATOM>
@@ -685,12 +699,12 @@
"(" l = terms()
")" { p.setTerms(l); }
]
- //( b=rule_plan_term() { p.addTerm(b); }
- //)*
[
lt = list() { p.setAnnots(lt); }
]
- { return p; }
+ { namespace = ons;
+ return p;
+ }
}
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-02-24 19:59:41 UTC (rev 1873)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-03-01 10:18:40 UTC (rev 1874)
@@ -21,7 +21,10 @@
public class as2j implements as2jConstants {
private String asSource = null;
private Agent curAg = null;
- private Atom namespace = Literal.DefaultNS;
+
+ private Atom namespace = Literal.DefaultNS;
+ private Atom thisnamespace = Literal.DefaultNS;
+
private DirectiveProcessor directiveProcessor = new DirectiveProcessor();
private NameSpace nsDirective = (NameSpace)directiveProcessor.getInstance("namespace");
@@ -30,7 +33,7 @@
private static Config config = Config.get(false);
public void setAg(Agent ag) { curAg = ag; }
- public void setNS(Atom ns) { namespace = ns; }
+ public void setNS(Atom ns) { namespace = ns; thisnamespace = ns; }
public Atom getNS() { return namespace; }
private String getSourceRef(SourceInfo s) {
@@ -133,6 +136,7 @@
case TK_END:
case ATOM:
case UNNAMEDVAR:
+ case 47:
;
break;
default:
@@ -216,6 +220,7 @@
case TK_END:
case ATOM:
case UNNAMEDVAR:
+ case 47:
;
break;
default:
@@ -485,6 +490,7 @@
case 40:
case 42:
case 44:
+ case 47:
F = body_formula();
isControl = false; if (!(F instanceof PlanBody)) {if (true) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!");}
break;
@@ -524,6 +530,7 @@
case 40:
case 42:
case 44:
+ case 47:
R = plan_body();
break;
default:
@@ -723,6 +730,7 @@
case 37:
case 38:
case 42:
+ case 47:
B = log_expr();
break;
default:
@@ -851,6 +859,7 @@
case 40:
case 42:
case 44:
+ case 47:
B = plan_body();
break;
default:
@@ -901,7 +910,7 @@
/* Literal */
final public Literal literal() throws ParseException {
Pred F = null; Pred V; Token k; boolean type = Literal.LPos;
- Atom NS = namespace; Token tns = null;
+ Atom NS = namespace; Token tns = null; boolean explicitAbstractNS = true;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case VAR:
case TK_NEG:
@@ -909,27 +918,43 @@
case TK_END:
case ATOM:
case UNNAMEDVAR:
+ case 47:
if (jj_2_4(10)) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case VAR:
case ATOM:
- tns = jj_consume_token(ATOM);
+ case UNNAMEDVAR:
+ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
+ case ATOM:
+ tns = jj_consume_token(ATOM);
if (tns.image.equals("default"))
NS = Literal.DefaultNS;
+ else if (tns.image.equals("this_ns"))
+ NS = thisnamespace;
else
NS = new Atom(tns.image);
- break;
- case VAR:
- case UNNAMEDVAR:
- NS = var(Literal.DefaultNS);
+ explicitAbstractNS = false;
+ break;
+ case VAR:
+ case UNNAMEDVAR:
+ NS = var(Literal.DefaultNS);
if (NS.hasAnnot())
{if (true) throw new ParseException(getSourceRef(NS)+" name space cannot have annotations.");}
+ explicitAbstractNS = false;
+ break;
+ default:
+ jj_la1[32] = jj_gen;
+ jj_consume_token(-1);
+ throw new ParseException();
+ }
break;
default:
- jj_la1[32] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
+ jj_la1[33] = jj_gen;
+ ;
}
jj_consume_token(47);
+ if (explicitAbstractNS)
+ NS = thisnamespace;
} else {
;
}
@@ -939,7 +964,7 @@
type = Literal.LNeg;
break;
default:
- jj_la1[33] = jj_gen;
+ jj_la1[34] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -956,7 +981,7 @@
{if (true) return vt;}
break;
default:
- jj_la1[34] = jj_gen;
+ jj_la1[35] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -970,7 +995,7 @@
{if (true) return Literal.LFalse;}
break;
default:
- jj_la1[35] = jj_gen;
+ jj_la1[36] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1001,6 +1026,7 @@
/* Annotated Formulae */
final public Pred pred() throws ParseException {
Token K; Pred p; List l; ListTerm lt; Term b;
+ Atom ons = namespace; namespace = Literal.DefaultNS;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case ATOM:
K = jj_consume_token(ATOM);
@@ -1012,7 +1038,7 @@
K = jj_consume_token(TK_END);
break;
default:
- jj_la1[36] = jj_gen;
+ jj_la1[37] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1026,7 +1052,7 @@
p.setTerms(l);
break;
default:
- jj_la1[37] = jj_gen;
+ jj_la1[38] = jj_gen;
;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -1035,9 +1061,10 @@
p.setAnnots(lt);
break;
default:
- jj_la1[38] = jj_gen;
+ jj_la1[39] = jj_gen;
;
}
+ namespace = ons;
{if (true) return p;}
throw new Error("Missing return statement in function");
}
@@ -1054,7 +1081,7 @@
;
break;
default:
- jj_la1[39] = jj_gen;
+ jj_la1[40] = jj_gen;
break label_9;
}
jj_consume_token(48);
@@ -1089,10 +1116,11 @@
case 37:
case 38:
case 42:
+ case 47:
o = log_expr();
break;
default:
- jj_la1[40] = jj_gen;
+ jj_la1[41] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1118,6 +1146,7 @@
case 37:
case 38:
case 42:
+ case 47:
case 49:
f = term_in_list();
last = lt.append(f); lt.setSrcInfo(f.getSrcInfo());
@@ -1128,7 +1157,7 @@
;
break;
default:
- jj_la1[41] = jj_gen;
+ jj_la1[42] = jj_gen;
break label_10;
}
jj_consume_token(48);
@@ -1152,18 +1181,18 @@
last = last.concat((ListTerm)f);
break;
default:
- jj_la1[42] = jj_gen;
+ jj_la1[43] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
- jj_la1[43] = jj_gen;
+ jj_la1[44] = jj_gen;
;
}
break;
default:
- jj_la1[44] = jj_gen;
+ jj_la1[45] = jj_gen;
;
}
jj_consume_token(51);
@@ -1190,6 +1219,7 @@
case 37:
case 38:
case 42:
+ case 47:
o = arithm_expr();
break;
case STRING:
@@ -1199,7 +1229,7 @@
o = rule_plan_term();
break;
default:
- jj_la1[45] = jj_gen;
+ jj_la1[46] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1218,7 +1248,7 @@
{if (true) return new LogExpr((LogicalFormula)t1,LogicalOp.or,(LogicalFormula)t2);}
break;
default:
- jj_la1[46] = jj_gen;
+ jj_la1[47] = jj_gen;
;
}
{if (true) return t1;}
@@ -1235,7 +1265,7 @@
{if (true) return new LogExpr((LogicalFormula)t1,LogicalOp.and,(LogicalFormula)t2);}
break;
default:
- jj_la1[47] = jj_gen;
+ jj_la1[48] = jj_gen;
;
}
{if (true) return t1;}
@@ -1263,11 +1293,12 @@
case 37:
case 38:
case 42:
+ case 47:
t = rel_expr();
{if (true) return t;}
break;
default:
- jj_la1[48] = jj_gen;
+ jj_la1[49] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1298,13 +1329,14 @@
case 37:
case 38:
case 42:
+ case 47:
op1 = arithm_expr();
break;
case STRING:
op1 = string();
break;
default:
- jj_la1[49] = jj_gen;
+ jj_la1[50] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1351,7 +1383,7 @@
operator = RelationalOp.literalBuilder;
break;
default:
- jj_la1[50] = jj_gen;
+ jj_la1[51] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1368,6 +1400,7 @@
case 37:
case 38:
case 42:
+ case 47:
op2 = arithm_expr();
break;
case STRING:
@@ -1380,7 +1413,7 @@
op2 = rule_plan_term();
break;
default:
- jj_la1[51] = jj_gen;
+ jj_la1[52] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1391,7 +1424,7 @@
{if (true) return new RelExpr((Term)op1, operator, (Term)op2);}
break;
default:
- jj_la1[52] = jj_gen;
+ jj_la1[53] = jj_gen;
;
}
{if (true) return op1;}
@@ -1411,7 +1444,7 @@
;
break;
default:
- jj_la1[53] = jj_gen;
+ jj_la1[54] = jj_gen;
break label_11;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -1424,7 +1457,7 @@
op = ArithmeticOp.minus;
break;
default:
- jj_la1[54] = jj_gen;
+ jj_la1[55] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1455,7 +1488,7 @@
;
break;
default:
- jj_la1[55] = jj_gen;
+ jj_la1[56] = jj_gen;
break label_12;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -1476,7 +1509,7 @@
op = ArithmeticOp.mod;
break;
default:
- jj_la1[56] = jj_gen;
+ jj_la1[57] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1511,7 +1544,7 @@
{if (true) return new ArithExpr((NumberTerm)t1, op, (NumberTerm)t2);}
break;
default:
- jj_la1[57] = jj_gen;
+ jj_la1[58] = jj_gen;
;
}
{if (true) return t1;}
@@ -1557,11 +1590,12 @@
case TK_END:
case ATOM:
case UNNAMEDVAR:
+ case 47:
t = function();
{if (true) return t;}
break;
default:
- jj_la1[58] = jj_gen;
+ jj_la1[59] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1596,7 +1630,7 @@
v = UnnamedVar.create(ns, K.image);
break;
default:
- jj_la1[59] = jj_gen;
+ jj_la1[60] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
@@ -1606,7 +1640,7 @@
v.setAnnots(lt);
break;
default:
- jj_la1[60] = jj_gen;
+ jj_la1[61] = jj_gen;
;
}
{if (true) return v;}
@@ -1650,47 +1684,9 @@
finally { jj_save(3, xla); }
}
- final private boolean jj_3R_108() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_114()) {
- jj_scanpos = xsp;
- if (jj_3R_115()) {
- jj_scanpos = xsp;
- if (jj_3R_116()) {
- jj_scanpos = xsp;
- if (jj_3R_117()) return true;
- }
- }
- }
- xsp = jj_scanpos;
- if (jj_3R_118()) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_119()) jj_scanpos = xsp;
- return false;
- }
-
- final private boolean jj_3R_101() {
- if (jj_3R_108()) return true;
- return false;
- }
-
- final private boolean jj_3R_53() {
- if (jj_scan_token(52)) return true;
- if (jj_3R_38()) return true;
- return false;
- }
-
- final private boolean jj_3R_38() {
- if (jj_3R_52()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_53()) jj_scanpos = xsp;
- return false;
- }
-
- final private boolean jj_3R_39() {
- if (jj_scan_token(50)) return true;
+ final private boolean jj_3_3() {
+ if (jj_3R_19()) return true;
+ if (jj_scan_token(32)) return true;
if (jj_3R_20()) return true;
return false;
}
@@ -1700,10 +1696,8 @@
return false;
}
- final private boolean jj_3_3() {
- if (jj_3R_19()) return true;
- if (jj_scan_token(32)) return true;
- if (jj_3R_20()) return true;
+ final private boolean jj_3R_72() {
+ if (jj_3R_68()) return true;
return false;
}
@@ -1712,17 +1706,22 @@
return false;
}
- final private boolean jj_3R_34() {
+ final private boolean jj_3R_33() {
if (jj_scan_token(41)) return true;
return false;
}
- final private boolean jj_3R_33() {
+ final private boolean jj_3R_32() {
if (jj_scan_token(36)) return true;
return false;
}
- final private boolean jj_3R_32() {
+ final private boolean jj_3R_71() {
+ if (jj_3R_77()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_31() {
Token xsp;
xsp = jj_scanpos;
if (jj_3R_47()) {
@@ -1732,11 +1731,8 @@
return false;
}
- final private boolean jj_3R_20() {
- if (jj_3R_38()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_39()) jj_scanpos = xsp;
+ final private boolean jj_3R_70() {
+ if (jj_3R_76()) return true;
return false;
}
@@ -1749,19 +1745,45 @@
final private boolean jj_3R_18() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_33()) {
+ if (jj_3R_32()) {
jj_scanpos = xsp;
- if (jj_3R_34()) return true;
+ if (jj_3R_33()) return true;
}
return false;
}
- final private boolean jj_3R_31() {
+ final private boolean jj_3R_69() {
+ if (jj_3R_42()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_30() {
if (jj_scan_token(39)) return true;
return false;
}
- final private boolean jj_3R_30() {
+ final private boolean jj_3R_66() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_69()) {
+ jj_scanpos = xsp;
+ if (jj_3R_70()) {
+ jj_scanpos = xsp;
+ if (jj_3R_71()) {
+ jj_scanpos = xsp;
+ if (jj_3R_72()) return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_97() {
+ if (jj_3R_42()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_29() {
if (jj_scan_token(38)) return true;
return false;
}
@@ -1772,11 +1794,26 @@
return false;
}
- final private boolean jj_3R_29() {
+ final private boolean jj_3R_96() {
+ if (jj_scan_token(UNNAMEDVAR)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_77() {
+ if (jj_scan_token(STRING)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_28() {
if (jj_scan_token(37)) return true;
return false;
}
+ final private boolean jj_3R_95() {
+ if (jj_scan_token(VAR)) return true;
+ return false;
+ }
+
final private boolean jj_3_2() {
Token xsp;
xsp = jj_scanpos;
@@ -1792,20 +1829,20 @@
final private boolean jj_3R_16() {
Token xsp;
xsp = jj_scanpos;
+ if (jj_3R_28()) {
+ jj_scanpos = xsp;
if (jj_3R_29()) {
jj_scanpos = xsp;
- if (jj_3R_30()) {
- jj_scanpos = xsp;
- if (jj_3R_31()) return true;
+ if (jj_3R_30()) return true;
}
}
xsp = jj_scanpos;
- if (jj_3R_32()) jj_scanpos = xsp;
+ if (jj_3R_31()) jj_scanpos = xsp;
if (jj_3R_19()) return true;
return false;
}
- final private boolean jj_3R_67() {
+ final private boolean jj_3R_68() {
if (jj_scan_token(30)) return true;
Token xsp;
xsp = jj_scanpos;
@@ -1813,198 +1850,137 @@
xsp = jj_scanpos;
if (jj_3_3()) jj_scanpos = xsp;
xsp = jj_scanpos;
- if (jj_3R_101()) jj_scanpos = xsp;
+ if (jj_3R_102()) jj_scanpos = xsp;
if (jj_scan_token(31)) return true;
return false;
}
- final private boolean jj_3R_71() {
- if (jj_3R_67()) return true;
- return false;
- }
-
- final private boolean jj_3R_70() {
- if (jj_3R_78()) return true;
- return false;
- }
-
- final private boolean jj_3R_69() {
- if (jj_3R_77()) return true;
- return false;
- }
-
- final private boolean jj_3R_68() {
+ final private boolean jj_3R_62() {
if (jj_3R_42()) return true;
return false;
}
- final private boolean jj_3R_65() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_68()) {
- jj_scanpos = xsp;
- if (jj_3R_69()) {
- jj_scanpos = xsp;
- if (jj_3R_70()) {
- jj_scanpos = xsp;
- if (jj_3R_71()) return true;
- }
- }
- }
- return false;
- }
-
- final private boolean jj_3R_94() {
- if (jj_3R_42()) return true;
- return false;
- }
-
- final private boolean jj_3R_93() {
- if (jj_scan_token(UNNAMEDVAR)) return true;
- return false;
- }
-
- final private boolean jj_3R_78() {
- if (jj_scan_token(STRING)) return true;
- return false;
- }
-
final private boolean jj_3R_92() {
- if (jj_scan_token(VAR)) return true;
- return false;
- }
-
- final private boolean jj_3R_56() {
- if (jj_3R_42()) return true;
- return false;
- }
-
- final private boolean jj_3R_76() {
if (jj_scan_token(50)) return true;
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_92()) {
+ if (jj_3R_95()) {
jj_scanpos = xsp;
- if (jj_3R_93()) {
+ if (jj_3R_96()) {
jj_scanpos = xsp;
- if (jj_3R_94()) return true;
+ if (jj_3R_97()) return true;
}
}
return false;
}
- final private boolean jj_3R_75() {
+ final private boolean jj_3R_91() {
if (jj_scan_token(48)) return true;
- if (jj_3R_65()) return true;
+ if (jj_3R_66()) return true;
return false;
}
- final private boolean jj_3R_55() {
+ final private boolean jj_3R_61() {
if (jj_scan_token(UNNAMEDVAR)) return true;
return false;
}
- final private boolean jj_3R_54() {
+ final private boolean jj_3R_60() {
if (jj_scan_token(VAR)) return true;
return false;
}
- final private boolean jj_3R_59() {
- if (jj_scan_token(TK_LABEL_AT)) return true;
- return false;
- }
-
- final private boolean jj_3R_58() {
- if (jj_3R_65()) return true;
+ final private boolean jj_3R_56() {
+ if (jj_3R_66()) return true;
Token xsp;
while (true) {
xsp = jj_scanpos;
- if (jj_3R_75()) { jj_scanpos = xsp; break; }
+ if (jj_3R_91()) { jj_scanpos = xsp; break; }
}
xsp = jj_scanpos;
- if (jj_3R_76()) jj_scanpos = xsp;
+ if (jj_3R_92()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_40() {
+ final private boolean jj_3R_54() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_54()) {
+ if (jj_3R_60()) {
jj_scanpos = xsp;
- if (jj_3R_55()) return true;
+ if (jj_3R_61()) return true;
}
xsp = jj_scanpos;
- if (jj_3R_56()) jj_scanpos = xsp;
+ if (jj_3R_62()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_46() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_59()) jj_scanpos = xsp;
- if (jj_3R_16()) return true;
- return false;
- }
-
final private boolean jj_3R_42() {
if (jj_scan_token(49)) return true;
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_58()) jj_scanpos = xsp;
+ if (jj_3R_56()) jj_scanpos = xsp;
if (jj_scan_token(51)) return true;
return false;
}
- final private boolean jj_3R_64() {
+ final private boolean jj_3R_65() {
if (jj_3R_20()) return true;
return false;
}
- final private boolean jj_3R_63() {
- if (jj_3R_67()) return true;
+ final private boolean jj_3R_64() {
+ if (jj_3R_68()) return true;
return false;
}
- final private boolean jj_3R_62() {
+ final private boolean jj_3R_63() {
if (jj_3R_42()) return true;
return false;
}
final private boolean jj_3R_57() {
+ if (jj_scan_token(TK_LABEL_AT)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_55() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_62()) {
- jj_scanpos = xsp;
if (jj_3R_63()) {
jj_scanpos = xsp;
- if (jj_3R_64()) return true;
+ if (jj_3R_64()) {
+ jj_scanpos = xsp;
+ if (jj_3R_65()) return true;
}
}
return false;
}
- final private boolean jj_3R_120() {
+ final private boolean jj_3R_46() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_57()) jj_scanpos = xsp;
+ if (jj_3R_16()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_121() {
if (jj_3R_19()) return true;
return false;
}
- final private boolean jj_3R_79() {
+ final private boolean jj_3R_78() {
if (jj_scan_token(48)) return true;
- if (jj_3R_57()) return true;
+ if (jj_3R_55()) return true;
return false;
}
- final private boolean jj_3R_45() {
- if (jj_scan_token(34)) return true;
+ final private boolean jj_3R_114() {
+ if (jj_3R_121()) return true;
return false;
}
final private boolean jj_3R_113() {
- if (jj_3R_120()) return true;
- return false;
- }
-
- final private boolean jj_3R_112() {
if (jj_scan_token(42)) return true;
if (jj_3R_20()) return true;
if (jj_scan_token(43)) return true;
@@ -2012,48 +1988,70 @@
}
final private boolean jj_3R_41() {
- if (jj_3R_57()) return true;
+ if (jj_3R_55()) return true;
Token xsp;
while (true) {
xsp = jj_scanpos;
- if (jj_3R_79()) { jj_scanpos = xsp; break; }
+ if (jj_3R_78()) { jj_scanpos = xsp; break; }
}
return false;
}
- final private boolean jj_3R_128() {
- if (jj_3R_20()) return true;
+ final private boolean jj_3R_112() {
+ if (jj_scan_token(37)) return true;
+ if (jj_3R_103()) return true;
return false;
}
+ final private boolean jj_3R_45() {
+ if (jj_scan_token(34)) return true;
+ return false;
+ }
+
final private boolean jj_3R_111() {
- if (jj_scan_token(37)) return true;
- if (jj_3R_102()) return true;
+ if (jj_scan_token(38)) return true;
+ if (jj_3R_103()) return true;
return false;
}
- final private boolean jj_3R_136() {
- if (jj_scan_token(37)) return true;
+ final private boolean jj_3R_23() {
+ if (jj_3R_42()) return true;
return false;
}
- final private boolean jj_3R_127() {
- if (jj_3R_67()) return true;
+ final private boolean jj_3R_110() {
+ if (jj_scan_token(NUMBER)) return true;
return false;
}
- final private boolean jj_3R_139() {
- if (jj_scan_token(46)) return true;
+ final private boolean jj_3R_22() {
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_41()) return true;
+ if (jj_scan_token(43)) return true;
return false;
}
- final private boolean jj_3R_24() {
- if (jj_3R_42()) return true;
+ final private boolean jj_3R_129() {
+ if (jj_3R_20()) return true;
return false;
}
- final private boolean jj_3R_138() {
- if (jj_scan_token(45)) return true;
+ final private boolean jj_3R_103() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_110()) {
+ jj_scanpos = xsp;
+ if (jj_3R_111()) {
+ jj_scanpos = xsp;
+ if (jj_3R_112()) {
+ jj_scanpos = xsp;
+ if (jj_3R_113()) {
+ jj_scanpos = xsp;
+ if (jj_3R_114()) return true;
+ }
+ }
+ }
+ }
return false;
}
@@ -2062,73 +2060,73 @@
return false;
}
- final private boolean jj_3R_134() {
- if (jj_scan_token(38)) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_136()) jj_scanpos = xsp;
+ final private boolean jj_3R_128() {
+ if (jj_3R_68()) return true;
return false;
}
- final private boolean jj_3R_110() {
- if (jj_scan_token(38)) return true;
- if (jj_3R_102()) return true;
+ final private boolean jj_3R_140() {
+ if (jj_scan_token(46)) return true;
return false;
}
- final private boolean jj_3R_135() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_137()) {
- jj_scanpos = xsp;
- if (jj_3R_138()) {
- jj_scanpos = xsp;
- if (jj_3R_139()) return true;
- }
- }
+ final private boolean jj_3R_139() {
+ if (jj_scan_token(45)) return true;
return false;
}
- final private boolean jj_3R_109() {
- if (jj_scan_token(NUMBER)) return true;
+ final private boolean jj_3R_138() {
+ if (jj_scan_token(37)) return true;
return false;
}
- final private boolean jj_3R_23() {
- if (jj_scan_token(42)) return true;
- if (jj_3R_41()) return true;
- if (jj_scan_token(43)) return true;
+ final private boolean jj_3R_135() {
+ if (jj_scan_token(38)) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_137()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_102() {
+ final private boolean jj_3R_136() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_109()) {
+ if (jj_3R_138()) {
jj_scanpos = xsp;
- if (jj_3R_110()) {
+ if (jj_3R_139()) {
jj_scanpos = xsp;
- if (jj_3R_111()) {
- jj_scanpos = xsp;
- if (jj_3R_112()) {
- jj_scanpos = xsp;
- if (jj_3R_113()) return true;
+ if (jj_3R_140()) return true;
}
}
- }
- }
return false;
}
- final private boolean jj_3R_133() {
+ final private boolean jj_3R_134() {
if (jj_scan_token(37)) return true;
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_135()) jj_scanpos = xsp;
+ if (jj_3R_136()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_132() {
+ final private boolean jj_3R_13() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_scan_token(23)) {
+ jj_scanpos = xsp;
+ if (jj_scan_token(14)) {
+ jj_scanpos = xsp;
+ if (jj_scan_token(15)) return true;
+ }
+ }
+ xsp = jj_scanpos;
+ if (jj_3R_22()) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_23()) jj_scanpos = xsp;
+ return false;
+ }
+
+ final private boolean jj_3R_133() {
if (jj_scan_token(40)) return true;
return false;
}
@@ -2138,28 +2136,28 @@
return false;
}
- final private boolean jj_3R_131() {
+ final private boolean jj_3R_132() {
if (jj_scan_token(44)) return true;
return false;
}
- final private boolean jj_3R_130() {
+ final private boolean jj_3R_131() {
if (jj_scan_token(34)) return true;
return false;
}
- final private boolean jj_3R_126() {
+ final private boolean jj_3R_127() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_130()) {
- jj_scanpos = xsp;
if (jj_3R_131()) {
jj_scanpos = xsp;
if (jj_3R_132()) {
jj_scanpos = xsp;
if (jj_3R_133()) {
jj_scanpos = xsp;
- if (jj_3R_134()) return true;
+ if (jj_3R_134()) {
+ jj_scanpos = xsp;
+ if (jj_3R_135()) return true;
}
}
}
@@ -2167,145 +2165,126 @@
return false;
}
- final private boolean jj_3R_124() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_126()) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_127()) {
- jj_scanpos = xsp;
- if (jj_3R_128()) return true;
- }
+ final private boolean jj_3R_104() {
+ if (jj_scan_token(61)) return true;
+ if (jj_3R_98()) return true;
return false;
}
- final private boolean jj_3R_13() {
+ final private boolean jj_3R_98() {
+ if (jj_3R_103()) return true;
Token xsp;
xsp = jj_scanpos;
- if (jj_scan_token(23)) {
- jj_scanpos = xsp;
- if (jj_scan_token(14)) {
- jj_scanpos = xsp;
- if (jj_scan_token(15)) return true;
- }
- }
- xsp = jj_scanpos;
- if (jj_3R_23()) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_24()) jj_scanpos = xsp;
+ if (jj_3R_104()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_103() {
- if (jj_scan_token(61)) return true;
- if (jj_3R_97()) return true;
- return false;
- }
-
- final private boolean jj_3R_97() {
- if (jj_3R_102()) return true;
+ final private boolean jj_3R_125() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_103()) jj_scanpos = xsp;
+ if (jj_3R_127()) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_128()) {
+ jj_scanpos = xsp;
+ if (jj_3R_129()) return true;
+ }
return false;
}
- final private boolean jj_3R_123() {
- if (jj_scan_token(TK_WHILE)) return true;
- if (jj_scan_token(42)) return true;
- if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
- if (jj_3R_67()) return true;
+ final private boolean jj_3R_108() {
+ if (jj_scan_token(TK_INTMOD)) return true;
return false;
}
final private boolean jj_3R_107() {
- if (jj_scan_token(TK_INTMOD)) return true;
+ if (jj_scan_token(TK_INTDIV)) return true;
return false;
}
final private boolean jj_3R_106() {
- if (jj_scan_token(TK_INTDIV)) return true;
+ if (jj_scan_token(60)) return true;
return false;
}
final private boolean jj_3R_105() {
- if (jj_scan_token(60)) return true;
- return false;
- }
-
- final private boolean jj_3R_104() {
if (jj_scan_token(59)) return true;
return false;
}
- final private boolean jj_3R_98() {
+ final private boolean jj_3R_99() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_104()) {
- jj_scanpos = xsp;
if (jj_3R_105()) {
jj_scanpos = xsp;
if (jj_3R_106()) {
jj_scanpos = xsp;
- if (jj_3R_107()) return true;
+ if (jj_3R_107()) {
+ jj_scanpos = xsp;
+ if (jj_3R_108()) return true;
}
}
}
- if (jj_3R_97()) return true;
+ if (jj_3R_98()) return true;
return false;
}
- final private boolean jj_3R_95() {
- if (jj_3R_97()) return true;
+ final private boolean jj_3R_93() {
+ if (jj_3R_98()) return true;
Token xsp;
while (true) {
xsp = jj_scanpos;
- if (jj_3R_98()) { jj_scanpos = xsp; break; }
+ if (jj_3R_99()) { jj_scanpos = xsp; break; }
}
return false;
}
- final private boolean jj_3_1() {
- if (jj_scan_token(TK_BEGIN)) return true;
- if (jj_3R_13()) return true;
- if (jj_scan_token(31)) return true;
- if (jj_3R_14()) return true;
+ final private boolean jj_3R_124() {
+ if (jj_scan_token(TK_WHILE)) return true;
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(43)) return true;
+ if (jj_3R_68()) return true;
return false;
}
- final private boolean jj_3R_37() {
+ final private boolean jj_3R_36() {
if (jj_scan_token(TK_FALSE)) return true;
return false;
}
- final private boolean jj_3R_36() {
+ final private boolean jj_3R_35() {
if (jj_scan_token(TK_TRUE)) return true;
return false;
}
final private boolean jj_3R_51() {
- if (jj_3R_40()) return true;
+ if (jj_3R_54()) return true;
return false;
}
- final private boolean jj_3R_43() {
- if (jj_scan_token(30)) return true;
+ final private boolean jj_3R_101() {
+ if (jj_scan_token(38)) return true;
return false;
}
- final private boolean jj_3R_50() {
- if (jj_3R_13()) return true;
+ final private boolean jj_3R_100() {
+ if (jj_scan_token(37)) return true;
return false;
}
- final private boolean jj_3R_100() {
- if (jj_scan_token(38)) return true;
+ final private boolean jj_3R_50() {
+ if (jj_3R_13()) return true;
return false;
}
- final private boolean jj_3R_99() {
- if (jj_scan_token(37)) return true;
+ final private boolean jj_3R_94() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_100()) {
+ jj_scanpos = xsp;
+ if (jj_3R_101()) return true;
+ }
+ if (jj_3R_93()) return true;
return false;
}
@@ -2314,69 +2293,50 @@
return false;
}
- final private boolean jj_3R_122() {
- if (jj_scan_token(TK_FOR)) return true;
- if (jj_scan_token(42)) return true;
- if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
- if (jj_3R_67()) return true;
+ final private boolean jj_3_1() {
+ if (jj_scan_token(TK_BEGIN)) return true;
+ if (jj_3R_13()) return true;
+ if (jj_scan_token(31)) return true;
+ if (jj_3R_14()) return true;
return false;
}
- final private boolean jj_3R_96() {
+ final private boolean jj_3R_76() {
+ if (jj_3R_93()) return true;
Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_99()) {
- jj_scanpos = xsp;
- if (jj_3R_100()) return true;
- }
- if (jj_3R_95()) return true;
- return false;
- }
-
- final private boolean jj_3R_77() {
- if (jj_3R_95()) return true;
- Token xsp;
while (true) {
xsp = jj_scanpos;
- if (jj_3R_96()) { jj_scanpos = xsp; break; }
+ if (jj_3R_94()) { jj_scanpos = xsp; break; }
}
return false;
}
- final private boolean jj_3R_22() {
- if (jj_3R_40()) return true;
+ final private boolean jj_3R_43() {
+ if (jj_scan_token(30)) return true;
return false;
}
- final private boolean jj_3R_21() {
- if (jj_scan_token(ATOM)) return true;
+ final private boolean jj_3R_123() {
+ if (jj_scan_token(TK_FOR)) return true;
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(43)) return true;
+ if (jj_3R_68()) return true;
return false;
}
- final private boolean jj_3R_91() {
- if (jj_3R_67()) return true;
+ final private boolean jj_3R_40() {
+ if (jj_3R_54()) return true;
return false;
}
- final private boolean jj_3_4() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_21()) {
- jj_scanpos = xsp;
- if (jj_3R_22()) return true;
- }
- if (jj_scan_token(47)) return true;
- return false;
- }
-
final private boolean jj_3R_90() {
- if (jj_3R_42()) return true;
+ if (jj_3R_68()) return true;
return false;
}
final private boolean jj_3R_89() {
- if (jj_3R_78()) return true;
+ if (jj_3R_42()) return true;
return false;
}
@@ -2385,89 +2345,93 @@
return false;
}
- final private boolean jj_3R_35() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3_4()) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_49()) jj_scanpos = xsp;
- xsp = jj_scanpos;
- if (jj_3R_50()) {
- jj_scanpos = xsp;
- if (jj_3R_51()) return true;
- }
+ final private boolean jj_3R_87() {
+ if (jj_3R_76()) return true;
return false;
}
- final private boolean jj_3R_87() {
+ final private boolean jj_3R_86() {
if (jj_scan_token(58)) return true;
return false;
}
- final private boolean jj_3R_19() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_35()) {
- jj_scanpos = xsp;
- if (jj_3R_36()) {
- jj_scanpos = xsp;
- if (jj_3R_37()) return true;
- }
- }
+ final private boolean jj_3R_39() {
+ if (jj_scan_token(ATOM)) return true;
return false;
}
- final private boolean jj_3R_86() {
+ final private boolean jj_3R_85() {
if (jj_scan_token(57)) return true;
return false;
}
- final private boolean jj_3R_85() {
- if (jj_scan_token(56)) return true;
+ final private boolean jj_3R_21() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_39()) {
+ jj_scanpos = xsp;
+ if (jj_3R_40()) return true;
+ }
return false;
}
final private boolean jj_3R_84() {
- if (jj_scan_token(55)) return true;
+ if (jj_scan_token(56)) return true;
return false;
}
final private boolean jj_3R_83() {
- if (jj_scan_token(54)) return true;
+ if (jj_scan_token(55)) return true;
return false;
}
- final private boolean jj_3R_129() {
- if (jj_scan_token(TK_ELSE)) return true;
+ final private boolean jj_3_4() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_21()) jj_scanpos = xsp;
+ if (jj_scan_token(47)) return true;
return false;
}
final private boolean jj_3R_82() {
- if (jj_scan_token(46)) return true;
+ if (jj_scan_token(54)) return true;
return false;
}
final private boolean jj_3R_81() {
- if (jj_scan_token(53)) return true;
+ if (jj_scan_token(46)) return true;
return false;
}
- final private boolean jj_3R_125() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_129()) jj_scanpos = xsp;
- if (jj_3R_67()) return true;
+ final private boolean jj_3R_80() {
+ if (jj_scan_token(53)) return true;
return false;
}
- final private boolean jj_3R_80() {
+ final private boolean jj_3R_79() {
if (jj_scan_token(45)) return true;
return false;
}
- final private boolean jj_3R_74() {
+ final private boolean jj_3R_34() {
Token xsp;
xsp = jj_scanpos;
+ if (jj_3_4()) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_49()) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_50()) {
+ jj_scanpos = xsp;
+ if (jj_3R_51()) return true;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_75() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_79()) {
+ jj_scanpos = xsp;
if (jj_3R_80()) {
jj_scanpos = xsp;
if (jj_3R_81()) {
@@ -2480,9 +2444,7 @@
jj_scanpos = xsp;
if (jj_3R_85()) {
jj_scanpos = xsp;
- if (jj_3R_86()) {
- jj_scanpos = xsp;
- if (jj_3R_87()) return true;
+ if (jj_3R_86()) return true;
}
}
}
@@ -2491,87 +2453,138 @@
}
}
xsp = jj_scanpos;
+ if (jj_3R_87()) {
+ jj_scanpos = xsp;
if (jj_3R_88()) {
jj_scanpos = xsp;
if (jj_3R_89()) {
jj_scanpos = xsp;
- if (jj_3R_90()) {
- jj_scanpos = xsp;
- if (jj_3R_91()) return true;
+ if (jj_3R_90()) return true;
}
}
}
return false;
}
- final private boolean jj_3R_73() {
- if (jj_3R_78()) return true;
+ final private boolean jj_3R_19() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_34()) {
+ jj_scanpos = xsp;
+ if (jj_3R_35()) {
+ jj_scanpos = xsp;
+ if (jj_3R_36()) return true;
+ }
+ }
return false;
}
- final private boolean jj_3R_72() {
+ final private boolean jj_3R_74() {
if (jj_3R_77()) return true;
return false;
}
- final private boolean jj_3R_121() {
- if (jj_scan_token(TK_IF)) return true;
- if (jj_scan_token(42)) return true;
- if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
- if (jj_3R_67()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_125()) jj_scanpos = xsp;
+ final private boolean jj_3R_73() {
+ if (jj_3R_76()) return true;
return false;
}
- final private boolean jj_3R_28() {
- if (jj_3R_46()) return true;
+ final private boolean jj_3R_130() {
+ if (jj_scan_token(TK_ELSE)) return true;
return false;
}
- final private boolean jj_3R_66() {
+ final private boolean jj_3R_67() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_72()) {
+ if (jj_3R_73()) {
jj_scanpos = xsp;
- if (jj_3R_73()) return true;
+ if (jj_3R_74()) return true;
}
xsp = jj_scanpos;
- if (jj_3R_74()) jj_scanpos = xsp;
+ if (jj_3R_75()) jj_scanpos = xsp;
return false;
}
+ final private boolean jj_3R_126() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_130()) jj_scanpos = xsp;
+ if (jj_3R_68()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_122() {
+ if (jj_scan_token(TK_IF)) return true;
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(43)) return true;
+ if (jj_3R_68()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_126()) jj_scanpos = xsp;
+ return false;
+ }
+
final private boolean jj_3R_27() {
+ if (jj_3R_46()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_26() {
if (jj_3R_45()) return true;
return false;
}
- final private boolean jj_3R_26() {
+ final private boolean jj_3R_59() {
+ if (jj_3R_67()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_25() {
if (jj_3R_44()) return true;
return false;
}
- final private boolean jj_3R_119() {
- if (jj_3R_108()) return true;
+ final private boolean jj_3R_120() {
+ if (jj_3R_109()) return true;
return false;
}
- final private boolean jj_3R_118() {
+ final private boolean jj_3R_58() {
+ if (jj_scan_token(TK_NOT)) return true;
+ if (jj_3R_52()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_119() {
if (jj_scan_token(41)) return true;
return false;
}
- final private boolean jj_3R_25() {
+ final private boolean jj_3R_24() {
if (jj_3R_43()) return true;
return false;
}
+ final private boolean jj_3R_52() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_58()) {
+ jj_scanpos = xsp;
+ if (jj_3R_59()) return true;
+ }
+ return false;
+ }
+
final private boolean jj_3R_14() {
Token xsp;
while (true) {
xsp = jj_scanpos;
+ if (jj_3R_24()) { jj_scanpos = xsp; break; }
+ }
+ while (true) {
+ xsp = jj_scanpos;
if (jj_3R_25()) { jj_scanpos = xsp; break; }
}
while (true) {
@@ -2582,25 +2595,35 @@
xsp = jj_scanpos;
if (jj_3R_27()) { jj_scanpos = xsp; break; }
}
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_28()) { jj_scanpos = xsp; break; }
- }
if (jj_scan_token(0)) return true;
return false;
}
- final private boolean jj_3R_61() {
- if (jj_3R_66()) return true;
+ final private boolean jj_3R_53() {
+ if (jj_scan_token(52)) return true;
+ if (jj_3R_37()) return true;
return false;
}
- final private boolean jj_3R_60() {
- if (jj_scan_token(TK_NOT)) return true;
+ final private boolean jj_3R_37() {
if (jj_3R_52()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_53()) jj_scanpos = xsp;
return false;
}
+ final private boolean jj_3R_38() {
+ if (jj_scan_token(50)) return true;
+ if (jj_3R_20()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_118() {
+ if (jj_3R_125()) return true;
+ return false;
+ }
+
final private boolean jj_3R_117() {
if (jj_3R_124()) return true;
return false;
@@ -2611,13 +2634,11 @@
return false;
}
- final private boolean jj_3R_52() {
+ final private boolean jj_3R_20() {
+ if (jj_3R_37()) return true;
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_60()) {
- jj_scanpos = xsp;
- if (jj_3R_61()) return true;
- }
+ if (jj_3R_38()) jj_scanpos = xsp;
return false;
}
@@ -2626,11 +2647,31 @@
return false;
}
- final private boolean jj_3R_114() {
- if (jj_3R_121()) return true;
+ final private boolean jj_3R_109() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_115()) {
+ jj_scanpos = xsp;
+ if (jj_3R_116()) {
+ jj_scanpos = xsp;
+ if (jj_3R_117()) {
+ jj_scanpos = xsp;
+ if (jj_3R_118()) return true;
+ }
+ }
+ }
+ xsp = jj_scanpos;
+ if (jj_3R_119()) jj_scanpos = xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_120()) jj_scanpos = xsp;
return false;
}
+ final private boolean jj_3R_102() {
+ if (jj_3R_109()) return true;
+ return false;
+ }
+
public as2jTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
@@ -2640,7 +2681,7 @@
public boolean lookingAhead = false;
private boolean jj_semLA;
private int jj_gen;
- final private int[] jj_la1 = new int[61];
+ final private int[] jj_la1 = new int[62];
static private int[] jj_la1_0;
static private int[] jj_la1_1;
static {
@@ -2648,10 +2689,10 @@
jj_la1_1();
}
private static void jj_la1_0() {
- jj_la1_0 = new int[] {0x40000000,0x180cb80,0x40000000,0x0,0x40000000,0x10000,0x180cb80,0x40000000,0x80c000,0x0,0x10000,0x0,0x0,0x0,0x0,0x0,0x41facf80,0x0,0x41facf80,0x40000,0x40040000,0x0,0x0,0x0,0x0,0x0,0x41e0cf80,0x10000,0x0,0x0,0x0,0x41facf80,0x1800080,0x800,0x180c080,0x180cb80,0x80c000,0x0,0x0,0x0,0x41e0cf80,0x0,0x1000080,0x0,0x41e0cb80,0x41e0cb80,0x0,0x0,0x1e0cf80,0x1e0cb80,0x0,0x41e0cb80,0x0,0x0,0x0,0x3000,0x3000,0x0,0x1a0cb80,0x1000080,0x0,};
+ jj_la1_0 = new int[] {0x40000000,0x180cb80,0x40000000,0x0,0x40000000,0x10000,0x180cb80,0x40000000,0x80c000,0x0,0x10000,0x0,0x0,0x0,0x0,0x0,0x41facf80,0x0,0x41facf80,0x40000,0x40040000,0x0,0x0,0x0,0x0,0x0,0x41e0cf80,0x10000,0x0,0x0,0x0,0x41facf80,0x1800080,0x1800080,0x800,0x180c080,0x180cb80,0x80c000,0x0,0x0,0x0,0x41e0cf80,0x0,0x1000080,0x0,0x41e0cb80,0x41e0cb80,0x0,0x0,0x1e0cf80,0x1e0cb80,0x0,0x41e0cb80,0x0,0x0,0x0,0x3000,0x3000,0x0,0x1a0cb80,0x1000080,0x0,};
}
private static void jj_la1_1() {
- jj_la1_1 = new int[] {0x0,0x0,0x0,0x4,0x0,0xe0,0x0,0x0,0x0,0x1,0x0,0x8,0x10,0xe0,0x104,0x104,0x1564,0x200,0x1564,0x0,0x0,0x6020,0x6020,0x20,0x1164,0x1164,0x460,0x0,0x8,0x210,0x210,0x1564,0x0,0x0,0x0,0x0,0x0,0x400,0x20000,0x10000,0x20460,0x10000,0x20000,0x40000,0x20460,0x20460,0x40000,0x100000,0x460,0x460,0x7e06000,0x20460,0x7e06000,0x60,0x60,0x18000000,0x18000000,0x20000000,0x460,0x0,0x20000,};
+ jj_la1_1 = new int[] {0x0,0x8000,0x0,0x4,0x0,0xe0,0x8000,0x0,0x0,0x1,0x0,0x8,0x10,0xe0,0x104,0x104,0x9564,0x200,0x9564,0x0,0x0,0x6020,0x6020,0x20,0x1164,0x1164,0x8460,0x0,0x8,0x210,0x210,0x9564,0x0,0x0,0x0,0x0,0x8000,0x0,0x400,0x20000,0x10000,0x28460,0x10000,0x20000,0x40000,0x28460,0x28460,0x40000,0x100000,0x8460,0x8460,0x7e06000,0x28460,0x7e06000,0x60,0x60,0x18000000,0x18000000,0x20000000,0x8460,0x0,0x20000,};
}
final private JJCalls[] jj_2_rtns = new JJCalls[4];
private boolean jj_rescan = false;
@@ -2666,7 +2707,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 61; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 62; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2679,7 +2720,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 61; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 62; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2689,7 +2730,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 61; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 62; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2699,7 +2740,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 61; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 62; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2708,7 +2749,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 61; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 62; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2717,7 +2758,7 @@
token = new Token();
jj_ntk = -1;
jj_gen = 0;
- for (int i = 0; i < 61; i++) jj_la1[i] = -1;
+ for (int i = 0; i < 62; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
@@ -2836,7 +2877,7 @@
la1tokens[jj_kind] = true;
jj_kind = -1;
}
- for (int i = 0; i < 61; i++) {
+ for (int i = 0; i < 62; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
Modified: trunk/src/jason/bb/DefaultBeliefBase.java
===================================================================
--- trunk/src/jason/bb/DefaultBeli...
[truncated message content] |
|
From: <jom...@us...> - 2016-02-24 19:59:44
|
Revision: 1873
http://sourceforge.net/p/jason/svn/1873
Author: jomifred
Date: 2016-02-24 19:59:41 +0000 (Wed, 24 Feb 2016)
Log Message:
-----------
include internal action accepts a namespace as parameter
Modified Paths:
--------------
trunk/demos/directives/myp/LoggerDirective.java
trunk/src/jason/asSyntax/InternalActionLiteral.java
trunk/src/jason/asSyntax/directives/DirectiveProcessor.java
trunk/src/jason/asSyntax/directives/FunctionRegister.java
trunk/src/jason/asSyntax/directives/Include.java
trunk/src/jason/asSyntax/directives/NameSpace.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/asSyntax/patterns/goal/BC.java
trunk/src/jason/asSyntax/patterns/goal/BDG.java
trunk/src/jason/asSyntax/patterns/goal/DG.java
trunk/src/jason/asSyntax/patterns/goal/EBDG.java
trunk/src/jason/asSyntax/patterns/goal/MG.java
trunk/src/jason/asSyntax/patterns/goal/OMC.java
trunk/src/jason/asSyntax/patterns/goal/RC.java
trunk/src/jason/asSyntax/patterns/goal/SGA.java
trunk/src/jason/asSyntax/patterns/goal/SMC.java
trunk/src/jason/mas2j/MAS2JProject.java
trunk/src/jason/stdlib/include.java
Modified: trunk/demos/directives/myp/LoggerDirective.java
===================================================================
--- trunk/demos/directives/myp/LoggerDirective.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/demos/directives/myp/LoggerDirective.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -2,12 +2,13 @@
package myp;
import jason.asSemantics.Agent;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Plan;
import jason.asSyntax.PlanBody;
+import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.PlanBodyImpl;
-import jason.asSyntax.Literal;
-import jason.asSyntax.Plan;
import jason.asSyntax.Pred;
-import jason.asSyntax.PlanBody.BodyType;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import java.util.logging.Level;
@@ -18,7 +19,7 @@
* @author jomi
*/
-public class LoggerDirective implements Directive {
+public class LoggerDirective extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(LoggerDirective.class.getName());
Modified: trunk/src/jason/asSyntax/InternalActionLiteral.java
===================================================================
--- trunk/src/jason/asSyntax/InternalActionLiteral.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/InternalActionLiteral.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -56,7 +56,7 @@
// used by clone
public InternalActionLiteral(InternalActionLiteral l) {
- super(DefaultNS, (Structure) l);
+ super(l.getNS(), (Structure) l);
this.ia = l.ia;
}
@@ -68,7 +68,10 @@
// used by the parser
public InternalActionLiteral(Structure p, Agent ag) throws Exception {
- super(p);
+ this(DefaultNS, p, ag);
+ }
+ public InternalActionLiteral(Atom ns, Structure p, Agent ag) throws Exception {
+ super(ns, p);
if (ag != null)
ia = ag.getIA(getFunctor());
}
Modified: trunk/src/jason/asSyntax/directives/DirectiveProcessor.java
===================================================================
--- trunk/src/jason/asSyntax/directives/DirectiveProcessor.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/directives/DirectiveProcessor.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -115,22 +115,4 @@
return null;
}
-
-/*
- public Agent process(Pred directive, Agent outerAg, Agent innerAg) {
- try {
- //logger.fine("Processing directive "+directive);
- Directive d = get(directive.getFunctor());
- if (d != null) {
- return d.process(directive, outerAg, innerAg);
- } else {
- logger.log(Level.SEVERE, "Unknown directive "+directive);
- }
- } catch (Exception e) {
- logger.log(Level.SEVERE, "Error processing directive "+directive,e);
- }
- return null;
- }
-*/
-
}
Modified: trunk/src/jason/asSyntax/directives/FunctionRegister.java
===================================================================
--- trunk/src/jason/asSyntax/directives/FunctionRegister.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/directives/FunctionRegister.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -100,6 +100,7 @@
}
@SuppressWarnings("unchecked")
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
if (outerContent == null)
return null;
Modified: trunk/src/jason/asSyntax/directives/Include.java
===================================================================
--- trunk/src/jason/asSyntax/directives/Include.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/directives/Include.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -1,6 +1,7 @@
package jason.asSyntax.directives;
import jason.asSemantics.Agent;
+import jason.asSyntax.Atom;
import jason.asSyntax.Pred;
import jason.asSyntax.StringTerm;
import jason.asSyntax.parser.as2j;
@@ -28,6 +29,8 @@
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
if (outerContent == null)
return null;
+
+ // handles file (arg[0])
String file = ((StringTerm)directive.getTerm(0)).getString().replaceAll("\\\\", "/");
try {
InputStream in = null;
@@ -73,12 +76,21 @@
in = new FileInputStream(checkPathAndFixWithSourcePath(file, aslSourcePath, null));
}
}
-
+ // handles namespace (args[1])
+ Atom ns = directive.getNS();
+ if (directive.getArity() > 1) {
+ if (! directive.getTerm(1).isAtom()) {
+ logger.log(Level.SEVERE, "The second parameter of the directive include (the namespace) should be an atom and not "+directive.getTerm(1)+". It is being ignored!");
+ } else {
+ ns = new Atom( ((Atom)directive.getTerm(1)).getFunctor() );
+ }
+ }
Agent ag = new Agent();
ag.initAg();
ag.setASLSrc(file);
- as2j parser = new as2j(in);
- parser.agent(ag);
+ as2j sparser = new as2j(in);
+ sparser.setNS(ns);
+ sparser.agent(ag);
logger.fine("as2j: AgentSpeak program '"+file+"' parsed successfully!");
return ag;
} catch (FileNotFoundException e) {
Modified: trunk/src/jason/asSyntax/directives/NameSpace.java
===================================================================
--- trunk/src/jason/asSyntax/directives/NameSpace.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/directives/NameSpace.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -8,12 +8,14 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/** Implementation of the <code>namespace</code> directive. */
public class NameSpace implements Directive {
- //static Logger logger = Logger.getLogger(NameSpace.class.getName());
-
+ static Logger logger = Logger.getLogger(NameSpace.class.getName());
+
private Map<Atom,Atom> localNSs = new HashMap<Atom,Atom>();
@Override
@@ -30,23 +32,35 @@
@Override
public void begin(Pred directive, as2j parser) {
- oldNS.push(parser.getNS());
+ if (! directive.getTerm(0).isAtom()) {
+ logger.log(Level.SEVERE, "The first parameter of the directive namespace should be an atom and not "+directive.getTerm(0));
+ return;
+ }
Atom ns = new Atom( ((Atom)directive.getTerm(0)).getFunctor() );
+
if (directive.getArity() > 1) {
+ if (! directive.getTerm(1).isAtom()) {
+ logger.log(Level.SEVERE, "The second parameter of the directive namespace should be an atom and not "+directive.getTerm(1));
+ return;
+ }
String type = ((Atom)directive.getTerm(1)).getFunctor();
+ if (!type.equals("local") && !type.equals("global")) {
+ logger.log(Level.SEVERE, "The second parameter of the directive namespace should be local or global");
+ return;
+ }
if (type.equals("local")) {
ns = addLocalNS(ns);
}
}
+
+ oldNS.push(parser.getNS());
parser.setNS(ns);
- //return ns;
}
@Override
public void end(Pred directive, as2j parser) {
- Atom ns = oldNS.pop();
- if (ns != null)
- parser.setNS(ns);
+ if (!oldNS.isEmpty())
+ parser.setNS(oldNS.pop());
}
public boolean isLocalNS(Atom ns) {
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-24 19:59:41 UTC (rev 1873)
@@ -261,19 +261,22 @@
( LOOKAHEAD(4)
<TK_BEGIN> dir = pred() "}"
{ Agent innerAg = new Agent(); innerAg.initAg();
- directiveProcessor.getInstance(dir).begin(dir,this);
+ dir = new Pred(namespace, dir);
+ Directive d = directiveProcessor.getInstance(dir);
+ d.begin(dir,this);
}
isEOF = agent(innerAg)
{ if (isEOF)
throw new ParseException(getSourceRef(dir)+" The directive '{ begin "+dir+"}' does not end with '{ end }'.");
- resultOfDirective = directiveProcessor.getInstance(dir).process(dir, outerAg, innerAg);
- directiveProcessor.getInstance(dir).end(dir,this);
+ resultOfDirective = d.process(dir, outerAg, innerAg);
+ d.end(dir,this);
}
|
dir = pred() "}"
{ if (dir.toString().equals("end"))
return true;
+ dir = new Pred(namespace, dir);
Directive d = directiveProcessor.getInstance(dir);
d.begin(dir, this); // to declare the namespace as local
resultOfDirective = d.process(dir, outerAg, null);
@@ -640,21 +643,25 @@
| k=<TK_FALSE> { return Literal.LFalse; }
)
{
+ if (ASSyntax.isKeyword(F))
+ NS = Literal.DefaultNS;
+ NS = nsDirective.map(NS);
+
if (F.getFunctor().indexOf(".") >= 0) {
if (F.hasAnnot())
throw new ParseException(getSourceRef(F)+" Internal actions cannot have annotations.");
if (type == Literal.LNeg)
throw new ParseException(getSourceRef(F)+" Internal actions cannot be negated.");
try {
- return new InternalActionLiteral(F, curAg);
+ if (F.getFunctor().equals(".include")) // .include needs a namespace (see its code)
+ return new InternalActionLiteral(NS, F, curAg);
+ else
+ return new InternalActionLiteral(F, curAg);
} catch (Exception e) {
if (getArithFunction(F) == null) // it is not a registered function
logger.warning(getSourceRef(F)+" warning: The internal action class for '"+F+"' was not loaded! Error: "+e);
}
}
- if (ASSyntax.isKeyword(F))
- NS = Literal.DefaultNS;
- NS = nsDirective.map(NS);
return new LiteralImpl(NS, type, F);
}
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -269,13 +269,15 @@
dir = pred();
jj_consume_token(31);
Agent innerAg = new Agent(); innerAg.initAg();
- directiveProcessor.getInstance(dir).begin(dir,this);
+ dir = new Pred(namespace, dir);
+ Directive d = directiveProcessor.getInstance(dir);
+ d.begin(dir,this);
isEOF = agent(innerAg);
if (isEOF)
{if (true) throw new ParseException(getSourceRef(dir)+" The directive '{ begin "+dir+"}' does not end with '{ end }'.");}
- resultOfDirective = directiveProcessor.getInstance(dir).process(dir, outerAg, innerAg);
- directiveProcessor.getInstance(dir).end(dir,this);
+ resultOfDirective = d.process(dir, outerAg, innerAg);
+ d.end(dir,this);
} else {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_BEGIN:
@@ -285,6 +287,7 @@
jj_consume_token(31);
if (dir.toString().equals("end"))
{if (true) return true;}
+ dir = new Pred(namespace, dir);
Directive d = directiveProcessor.getInstance(dir);
d.begin(dir, this); // to declare the namespace as local
resultOfDirective = d.process(dir, outerAg, null);
@@ -971,21 +974,25 @@
jj_consume_token(-1);
throw new ParseException();
}
+ if (ASSyntax.isKeyword(F))
+ NS = Literal.DefaultNS;
+ NS = nsDirective.map(NS);
+
if (F.getFunctor().indexOf(".") >= 0) {
if (F.hasAnnot())
{if (true) throw new ParseException(getSourceRef(F)+" Internal actions cannot have annotations.");}
if (type == Literal.LNeg)
{if (true) throw new ParseException(getSourceRef(F)+" Internal actions cannot be negated.");}
try {
- {if (true) return new InternalActionLiteral(F, curAg);}
+ if (F.getFunctor().equals(".include")) // .include needs a namespace (see its code)
+ {if (true) return new InternalActionLiteral(NS, F, curAg);}
+ else
+ {if (true) return new InternalActionLiteral(F, curAg);}
} catch (Exception e) {
if (getArithFunction(F) == null) // it is not a registered function
logger.warning(getSourceRef(F)+" warning: The internal action class for '"+F+"' was not loaded! Error: "+e);
}
}
- if (ASSyntax.isKeyword(F))
- NS = Literal.DefaultNS;
- NS = nsDirective.map(NS);
{if (true) return new LiteralImpl(NS, type, F);}
throw new Error("Missing return statement in function");
@@ -1643,22 +1650,6 @@
finally { jj_save(3, xla); }
}
- final private boolean jj_3R_115() {
- if (jj_3R_122()) return true;
- return false;
- }
-
- final private boolean jj_3R_60() {
- if (jj_scan_token(TK_NOT)) return true;
- if (jj_3R_52()) return true;
- return false;
- }
-
- final private boolean jj_3R_114() {
- if (jj_3R_121()) return true;
- return false;
- }
-
final private boolean jj_3R_108() {
Token xsp;
xsp = jj_scanpos;
@@ -1684,19 +1675,23 @@
return false;
}
- final private boolean jj_3R_52() {
+ final private boolean jj_3R_53() {
+ if (jj_scan_token(52)) return true;
+ if (jj_3R_38()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_38() {
+ if (jj_3R_52()) return true;
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_60()) {
- jj_scanpos = xsp;
- if (jj_3R_61()) return true;
- }
+ if (jj_3R_53()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_53() {
- if (jj_scan_token(52)) return true;
- if (jj_3R_38()) return true;
+ final private boolean jj_3R_39() {
+ if (jj_scan_token(50)) return true;
+ if (jj_3R_20()) return true;
return false;
}
@@ -1712,14 +1707,6 @@
return false;
}
- final private boolean jj_3R_38() {
- if (jj_3R_52()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_53()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_47() {
if (jj_scan_token(34)) return true;
return false;
@@ -1745,9 +1732,11 @@
return false;
}
- final private boolean jj_3R_39() {
- if (jj_scan_token(50)) return true;
- if (jj_3R_20()) return true;
+ final private boolean jj_3R_20() {
+ if (jj_3R_38()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_39()) jj_scanpos = xsp;
return false;
}
@@ -1783,14 +1772,6 @@
return false;
}
- final private boolean jj_3R_20() {
- if (jj_3R_38()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_39()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_29() {
if (jj_scan_token(37)) return true;
return false;
@@ -1912,11 +1893,6 @@
return false;
}
- final private boolean jj_3R_59() {
- if (jj_scan_token(TK_LABEL_AT)) return true;
- return false;
- }
-
final private boolean jj_3R_75() {
if (jj_scan_token(48)) return true;
if (jj_3R_65()) return true;
@@ -1928,16 +1904,13 @@
return false;
}
- final private boolean jj_3R_46() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_59()) jj_scanpos = xsp;
- if (jj_3R_16()) return true;
+ final private boolean jj_3R_54() {
+ if (jj_scan_token(VAR)) return true;
return false;
}
- final private boolean jj_3R_54() {
- if (jj_scan_token(VAR)) return true;
+ final private boolean jj_3R_59() {
+ if (jj_scan_token(TK_LABEL_AT)) return true;
return false;
}
@@ -1965,6 +1938,14 @@
return false;
}
+ final private boolean jj_3R_46() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_59()) jj_scanpos = xsp;
+ if (jj_3R_16()) return true;
+ return false;
+ }
+
final private boolean jj_3R_42() {
if (jj_scan_token(49)) return true;
Token xsp;
@@ -2007,24 +1988,19 @@
return false;
}
- final private boolean jj_3R_45() {
- if (jj_scan_token(34)) return true;
- return false;
- }
-
final private boolean jj_3R_79() {
if (jj_scan_token(48)) return true;
if (jj_3R_57()) return true;
return false;
}
- final private boolean jj_3R_113() {
- if (jj_3R_120()) return true;
+ final private boolean jj_3R_45() {
+ if (jj_scan_token(34)) return true;
return false;
}
- final private boolean jj_3R_128() {
- if (jj_3R_20()) return true;
+ final private boolean jj_3R_113() {
+ if (jj_3R_120()) return true;
return false;
}
@@ -2045,6 +2021,17 @@
return false;
}
+ final private boolean jj_3R_128() {
+ if (jj_3R_20()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_111() {
+ if (jj_scan_token(37)) return true;
+ if (jj_3R_102()) return true;
+ return false;
+ }
+
final private boolean jj_3R_136() {
if (jj_scan_token(37)) return true;
return false;
@@ -2060,14 +2047,13 @@
return false;
}
- final private boolean jj_3R_138() {
- if (jj_scan_token(45)) return true;
+ final private boolean jj_3R_24() {
+ if (jj_3R_42()) return true;
return false;
}
- final private boolean jj_3R_111() {
- if (jj_scan_token(37)) return true;
- if (jj_3R_102()) return true;
+ final private boolean jj_3R_138() {
+ if (jj_scan_token(45)) return true;
return false;
}
@@ -2084,6 +2070,12 @@
return false;
}
+ final private boolean jj_3R_110() {
+ if (jj_scan_token(38)) return true;
+ if (jj_3R_102()) return true;
+ return false;
+ }
+
final private boolean jj_3R_135() {
Token xsp;
xsp = jj_scanpos;
@@ -2097,17 +2089,37 @@
return false;
}
- final private boolean jj_3R_24() {
- if (jj_3R_42()) return true;
+ final private boolean jj_3R_109() {
+ if (jj_scan_token(NUMBER)) return true;
return false;
}
- final private boolean jj_3R_110() {
- if (jj_scan_token(38)) return true;
- if (jj_3R_102()) return true;
+ final private boolean jj_3R_23() {
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_41()) return true;
+ if (jj_scan_token(43)) return true;
return false;
}
+ final private boolean jj_3R_102() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_109()) {
+ jj_scanpos = xsp;
+ if (jj_3R_110()) {
+ jj_scanpos = xsp;
+ if (jj_3R_111()) {
+ jj_scanpos = xsp;
+ if (jj_3R_112()) {
+ jj_scanpos = xsp;
+ if (jj_3R_113()) return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
final private boolean jj_3R_133() {
if (jj_scan_token(37)) return true;
Token xsp;
@@ -2121,23 +2133,11 @@
return false;
}
- final private boolean jj_3R_109() {
- if (jj_scan_token(NUMBER)) return true;
- return false;
- }
-
final private boolean jj_3R_44() {
if (jj_3R_19()) return true;
return false;
}
- final private boolean jj_3R_23() {
- if (jj_scan_token(42)) return true;
- if (jj_3R_41()) return true;
- if (jj_scan_token(43)) return true;
- return false;
- }
-
final private boolean jj_3R_131() {
if (jj_scan_token(44)) return true;
return false;
@@ -2167,25 +2167,6 @@
return false;
}
- final private boolean jj_3R_102() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_109()) {
- jj_scanpos = xsp;
- if (jj_3R_110()) {
- jj_scanpos = xsp;
- if (jj_3R_111()) {
- jj_scanpos = xsp;
- if (jj_3R_112()) {
- jj_scanpos = xsp;
- if (jj_3R_113()) return true;
- }
- }
- }
- }
- return false;
- }
-
final private boolean jj_3R_124() {
Token xsp;
xsp = jj_scanpos;
@@ -2258,14 +2239,6 @@
return false;
}
- final private boolean jj_3_1() {
- if (jj_scan_token(TK_BEGIN)) return true;
- if (jj_3R_13()) return true;
- if (jj_scan_token(31)) return true;
- if (jj_3R_14()) return true;
- return false;
- }
-
final private boolean jj_3R_98() {
Token xsp;
xsp = jj_scanpos;
@@ -2293,8 +2266,11 @@
return false;
}
- final private boolean jj_3R_43() {
- if (jj_scan_token(30)) return true;
+ final private boolean jj_3_1() {
+ if (jj_scan_token(TK_BEGIN)) return true;
+ if (jj_3R_13()) return true;
+ if (jj_scan_token(31)) return true;
+ if (jj_3R_14()) return true;
return false;
}
@@ -2313,11 +2289,26 @@
return false;
}
+ final private boolean jj_3R_43() {
+ if (jj_scan_token(30)) return true;
+ return false;
+ }
+
final private boolean jj_3R_50() {
if (jj_3R_13()) return true;
return false;
}
+ final private boolean jj_3R_100() {
+ if (jj_scan_token(38)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_99() {
+ if (jj_scan_token(37)) return true;
+ return false;
+ }
+
final private boolean jj_3R_49() {
if (jj_scan_token(TK_NEG)) return true;
return false;
@@ -2332,16 +2323,6 @@
return false;
}
- final private boolean jj_3R_100() {
- if (jj_scan_token(38)) return true;
- return false;
- }
-
- final private boolean jj_3R_99() {
- if (jj_scan_token(37)) return true;
- return false;
- }
-
final private boolean jj_3R_96() {
Token xsp;
xsp = jj_scanpos;
@@ -2353,11 +2334,6 @@
return false;
}
- final private boolean jj_3R_22() {
- if (jj_3R_40()) return true;
- return false;
- }
-
final private boolean jj_3R_77() {
if (jj_3R_95()) return true;
Token xsp;
@@ -2368,11 +2344,21 @@
return false;
}
+ final private boolean jj_3R_22() {
+ if (jj_3R_40()) return true;
+ return false;
+ }
+
final private boolean jj_3R_21() {
if (jj_scan_token(ATOM)) return true;
return false;
}
+ final private boolean jj_3R_91() {
+ if (jj_3R_67()) return true;
+ return false;
+ }
+
final private boolean jj_3_4() {
Token xsp;
xsp = jj_scanpos;
@@ -2384,11 +2370,6 @@
return false;
}
- final private boolean jj_3R_91() {
- if (jj_3R_67()) return true;
- return false;
- }
-
final private boolean jj_3R_90() {
if (jj_3R_42()) return true;
return false;
@@ -2399,6 +2380,11 @@
return false;
}
+ final private boolean jj_3R_88() {
+ if (jj_3R_77()) return true;
+ return false;
+ }
+
final private boolean jj_3R_35() {
Token xsp;
xsp = jj_scanpos;
@@ -2413,8 +2399,8 @@
return false;
}
- final private boolean jj_3R_88() {
- if (jj_3R_77()) return true;
+ final private boolean jj_3R_87() {
+ if (jj_scan_token(58)) return true;
return false;
}
@@ -2431,16 +2417,6 @@
return false;
}
- final private boolean jj_3R_87() {
- if (jj_scan_token(58)) return true;
- return false;
- }
-
- final private boolean jj_3R_129() {
- if (jj_scan_token(TK_ELSE)) return true;
- return false;
- }
-
final private boolean jj_3R_86() {
if (jj_scan_token(57)) return true;
return false;
@@ -2451,14 +2427,6 @@
return false;
}
- final private boolean jj_3R_125() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_129()) jj_scanpos = xsp;
- if (jj_3R_67()) return true;
- return false;
- }
-
final private boolean jj_3R_84() {
if (jj_scan_token(55)) return true;
return false;
@@ -2469,6 +2437,11 @@
return false;
}
+ final private boolean jj_3R_129() {
+ if (jj_scan_token(TK_ELSE)) return true;
+ return false;
+ }
+
final private boolean jj_3R_82() {
if (jj_scan_token(46)) return true;
return false;
@@ -2479,6 +2452,14 @@
return false;
}
+ final private boolean jj_3R_125() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_129()) jj_scanpos = xsp;
+ if (jj_3R_67()) return true;
+ return false;
+ }
+
final private boolean jj_3R_80() {
if (jj_scan_token(45)) return true;
return false;
@@ -2523,6 +2504,16 @@
return false;
}
+ final private boolean jj_3R_73() {
+ if (jj_3R_78()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_72() {
+ if (jj_3R_77()) return true;
+ return false;
+ }
+
final private boolean jj_3R_121() {
if (jj_scan_token(TK_IF)) return true;
if (jj_scan_token(42)) return true;
@@ -2540,21 +2531,6 @@
return false;
}
- final private boolean jj_3R_73() {
- if (jj_3R_78()) return true;
- return false;
- }
-
- final private boolean jj_3R_72() {
- if (jj_3R_77()) return true;
- return false;
- }
-
- final private boolean jj_3R_27() {
- if (jj_3R_45()) return true;
- return false;
- }
-
final private boolean jj_3R_66() {
Token xsp;
xsp = jj_scanpos;
@@ -2567,13 +2543,13 @@
return false;
}
- final private boolean jj_3R_26() {
- if (jj_3R_44()) return true;
+ final private boolean jj_3R_27() {
+ if (jj_3R_45()) return true;
return false;
}
- final private boolean jj_3R_25() {
- if (jj_3R_43()) return true;
+ final private boolean jj_3R_26() {
+ if (jj_3R_44()) return true;
return false;
}
@@ -2582,6 +2558,16 @@
return false;
}
+ final private boolean jj_3R_118() {
+ if (jj_scan_token(41)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_25() {
+ if (jj_3R_43()) return true;
+ return false;
+ }
+
final private boolean jj_3R_14() {
Token xsp;
while (true) {
@@ -2604,18 +2590,19 @@
return false;
}
- final private boolean jj_3R_118() {
- if (jj_scan_token(41)) return true;
+ final private boolean jj_3R_61() {
+ if (jj_3R_66()) return true;
return false;
}
- final private boolean jj_3R_117() {
- if (jj_3R_124()) return true;
+ final private boolean jj_3R_60() {
+ if (jj_scan_token(TK_NOT)) return true;
+ if (jj_3R_52()) return true;
return false;
}
- final private boolean jj_3R_61() {
- if (jj_3R_66()) return true;
+ final private boolean jj_3R_117() {
+ if (jj_3R_124()) return true;
return false;
}
@@ -2624,6 +2611,26 @@
return false;
}
+ final private boolean jj_3R_52() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_60()) {
+ jj_scanpos = xsp;
+ if (jj_3R_61()) return true;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_115() {
+ if (jj_3R_122()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_114() {
+ if (jj_3R_121()) return true;
+ return false;
+ }
+
public as2jTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
Modified: trunk/src/jason/asSyntax/patterns/goal/BC.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/BC.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/BC.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -20,6 +20,7 @@
static Logger logger = Logger.getLogger(BC.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Term goal = directive.getTerm(0);
Modified: trunk/src/jason/asSyntax/patterns/goal/BDG.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/BDG.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/BDG.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -17,6 +17,7 @@
static Logger logger = Logger.getLogger(BDG.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
// apply DG in the inner plans
Modified: trunk/src/jason/asSyntax/patterns/goal/DG.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/DG.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/DG.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -3,12 +3,12 @@
import jason.asSemantics.Agent;
import jason.asSemantics.Unifier;
import jason.asSyntax.ASSyntax;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Plan;
import jason.asSyntax.PlanBody;
+import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.PlanBodyImpl;
-import jason.asSyntax.Literal;
-import jason.asSyntax.Plan;
import jason.asSyntax.Pred;
-import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
@@ -24,6 +24,7 @@
static Logger logger = Logger.getLogger(DG.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Agent newAg = new Agent();
Modified: trunk/src/jason/asSyntax/patterns/goal/EBDG.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/EBDG.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/EBDG.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -5,13 +5,13 @@
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Literal;
import jason.asSyntax.LogExpr;
+import jason.asSyntax.LogExpr.LogicalOp;
import jason.asSyntax.LogicalFormula;
import jason.asSyntax.Plan;
import jason.asSyntax.PlanBody;
+import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.PlanBodyImpl;
import jason.asSyntax.Pred;
-import jason.asSyntax.LogExpr.LogicalOp;
-import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
@@ -27,6 +27,7 @@
static Logger logger = Logger.getLogger(EBDG.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Agent newAg = new Agent();
Modified: trunk/src/jason/asSyntax/patterns/goal/MG.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/MG.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/MG.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -21,6 +21,7 @@
static Logger logger = Logger.getLogger(MG.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Literal goal = Literal.parseLiteral(directive.getTerm(0).toString());
Modified: trunk/src/jason/asSyntax/patterns/goal/OMC.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/OMC.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/OMC.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -22,6 +22,7 @@
static Logger logger = Logger.getLogger(OMC.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Term goal = directive.getTerm(0);
Modified: trunk/src/jason/asSyntax/patterns/goal/RC.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/RC.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/RC.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -20,6 +20,7 @@
static Logger logger = Logger.getLogger(RC.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Term goal = directive.getTerm(0);
Modified: trunk/src/jason/asSyntax/patterns/goal/SGA.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/SGA.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/SGA.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -23,6 +23,7 @@
static Logger logger = Logger.getLogger(SGA.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Trigger trigger = ASSyntax.parseTrigger(((StringTerm)directive.getTerm(0)).getString());
Modified: trunk/src/jason/asSyntax/patterns/goal/SMC.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/SMC.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/asSyntax/patterns/goal/SMC.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -20,6 +20,7 @@
static Logger logger = Logger.getLogger(SMC.class.getName());
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Term goal = directive.getTerm(0);
Modified: trunk/src/jason/mas2j/MAS2JProject.java
===================================================================
--- trunk/src/jason/mas2j/MAS2JProject.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/mas2j/MAS2JProject.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -24,7 +24,6 @@
package jason.mas2j;
import jason.JasonException;
-import jason.asSyntax.directives.Directive;
import jason.asSyntax.directives.DirectiveProcessor;
import jason.infra.InfrastructureFactory;
import jason.jeditplugin.Config;
@@ -224,7 +223,7 @@
if (directiveClasses != null) {
for (String id: directiveClasses.keySet()) {
try {
- DirectiveProcessor.addDirective(id, (Directive)Class.forName(directiveClasses.get(id)).newInstance());
+ DirectiveProcessor.registerDirective(id, Class.forName(directiveClasses.get(id)));
} catch (Exception e) {
logger.log(Level.SEVERE, "Error registering directives "+directiveClasses,e);
}
Modified: trunk/src/jason/stdlib/include.java
===================================================================
--- trunk/src/jason/stdlib/include.java 2016-02-24 15:55:05 UTC (rev 1872)
+++ trunk/src/jason/stdlib/include.java 2016-02-24 19:59:41 UTC (rev 1873)
@@ -28,6 +28,8 @@
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
+import jason.asSyntax.Atom;
+import jason.asSyntax.Literal;
import jason.asSyntax.Pred;
import jason.asSyntax.Term;
import jason.asSyntax.directives.DirectiveProcessor;
@@ -50,7 +52,7 @@
public class include extends DefaultInternalAction {
@Override public int getMinArgs() { return 1; }
- @Override public int getMaxArgs() { return 1; }
+ @Override public int getMaxArgs() { return 2; }
@Override protected void checkArguments(Term[] args) throws JasonException {
super.checkArguments(args); // check number of arguments
@@ -58,12 +60,20 @@
throw JasonException.createWrongArgument(this,"first argument must be a string.");
}
+ Atom ns = Literal.DefaultNS;
+
+ @Override
+ public Term[] prepareArguments(Literal body, Unifier un) {
+ ns = body.getNS();
+ return super.prepareArguments(body, un);
+ }
+
@Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
Agent ag = ts.getAg();
- Pred inc = new Pred("include");
- inc.addTerm(args[0]);
+ Pred inc = new Pred(ns, "include");
+ inc.addTerms(args);
Agent result = ((Include)DirectiveProcessor.getDirective("include")).process(
inc,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-02-24 15:55:07
|
Revision: 1872
http://sourceforge.net/p/jason/svn/1872
Author: jomifred
Date: 2016-02-24 15:55:05 +0000 (Wed, 24 Feb 2016)
Log Message:
-----------
improve directive API
Modified Paths:
--------------
trunk/src/jason/asSyntax/directives/Directive.java
trunk/src/jason/asSyntax/directives/DirectiveProcessor.java
trunk/src/jason/asSyntax/directives/FunctionRegister.java
trunk/src/jason/asSyntax/directives/Include.java
trunk/src/jason/asSyntax/directives/NameSpace.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/asSyntax/patterns/goal/BC.java
trunk/src/jason/asSyntax/patterns/goal/DG.java
trunk/src/jason/asSyntax/patterns/goal/EBDG.java
trunk/src/jason/asSyntax/patterns/goal/MG.java
trunk/src/jason/asSyntax/patterns/goal/OMC.java
trunk/src/jason/asSyntax/patterns/goal/RC.java
trunk/src/jason/asSyntax/patterns/goal/SGA.java
trunk/src/jason/asSyntax/patterns/goal/SMC.java
trunk/src/test/ASParserTest.java
trunk/src/test/NSTest.java
Added Paths:
-----------
trunk/src/jason/asSyntax/directives/DefaultDirective.java
Added: trunk/src/jason/asSyntax/directives/DefaultDirective.java
===================================================================
--- trunk/src/jason/asSyntax/directives/DefaultDirective.java (rev 0)
+++ trunk/src/jason/asSyntax/directives/DefaultDirective.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -0,0 +1,24 @@
+package jason.asSyntax.directives;
+
+import jason.asSemantics.Agent;
+import jason.asSyntax.Pred;
+import jason.asSyntax.parser.as2j;
+
+public abstract class DefaultDirective implements Directive {
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public void begin(Pred directive, as2j parser) {
+ }
+
+ public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
+ return innerContent;
+ }
+
+ public void end(Pred directive, as2j parser) {
+ }
+
+}
Modified: trunk/src/jason/asSyntax/directives/Directive.java
===================================================================
--- trunk/src/jason/asSyntax/directives/Directive.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/directives/Directive.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -2,6 +2,7 @@
import jason.asSemantics.Agent;
import jason.asSyntax.Pred;
+import jason.asSyntax.parser.as2j;
/**
* Interface for all compiler directives (e.g. include and goal patterns).
@@ -46,6 +47,9 @@
* @author jomi
*/
public interface Directive {
+ /** called when the directive is declared */
+ void begin(Pred directive, as2j parser);
+
/**
* This method is called to process the directive.
*
@@ -55,4 +59,10 @@
* @return the agent (plans, bels, ...) with the result of the directive.
*/
Agent process(Pred directive, Agent outerContent, Agent innerContent);
+
+ /** called when the directive ends */
+ void end(Pred directive, as2j parser);
+
+ /** returns true if the same instance will be used by all agents/parsers in the JVM */
+ boolean isSingleton();
}
Modified: trunk/src/jason/asSyntax/directives/DirectiveProcessor.java
===================================================================
--- trunk/src/jason/asSyntax/directives/DirectiveProcessor.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/directives/DirectiveProcessor.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -1,6 +1,5 @@
package jason.asSyntax.directives;
-import jason.asSemantics.Agent;
import jason.asSyntax.Pred;
import jason.asSyntax.patterns.goal.BC;
import jason.asSyntax.patterns.goal.BDG;
@@ -27,42 +26,101 @@
* @author jomi
*
*/
+@SuppressWarnings("rawtypes")
public class DirectiveProcessor {
static Logger logger = Logger.getLogger(DirectiveProcessor.class.getName());
- private static Map<String,Directive> directives = new HashMap<String,Directive>();
+ private static Map<String,Class> directives = new HashMap<String,Class>();
+ private Map<String,Directive> instances = new HashMap<String,Directive>();
+ private static Map<String,Directive> singletons = new HashMap<String,Directive>();
- public static void addDirective(String id, Directive d) {
+ public static void registerDirective(String id, Class d) {
directives.put(id,d);
}
+
public static Directive getDirective(String id) {
- return directives.get(id);
+ Directive d = singletons.get(id);
+ if (d != null)
+ return d;
+
+ // create the instance
+ Class c = directives.get(id);
+ if (c == null) {
+ logger.log(Level.SEVERE, "Unknown directive "+id);
+ return null;
+ }
+
+ try {
+ d = (Directive)c.newInstance();
+ if (d.isSingleton())
+ singletons.put(id, d);
+ return d;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
}
- public static Directive removeDirective(String id) {
- return directives.remove(id);
- }
+ //public static Directive removeDirective(String id) {
+ // return directives.remove(id);
+ //}
+
// add known directives
static {
- addDirective("include", new Include());
- addDirective("register_function", new FunctionRegister());
- addDirective("namespace", new NameSpace());
+ registerDirective("include", Include.class);
+ registerDirective("register_function", FunctionRegister.class);
+ registerDirective("namespace", NameSpace.class);
- addDirective("dg", new DG());
- addDirective("bdg", new BDG());
- addDirective("ebdg", new EBDG());
- addDirective("bc", new BC());
- addDirective("smc", new SMC());
- addDirective("rc", new RC());
- addDirective("omc", new OMC());
- addDirective("mg", new MG());
- addDirective("sga", new SGA());
+ registerDirective("dg", DG.class);
+ registerDirective("bdg", BDG.class);
+ registerDirective("ebdg",EBDG.class);
+ registerDirective("bc", BC.class);
+ registerDirective("smc", SMC.class);
+ registerDirective("rc", RC.class);
+ registerDirective("omc", OMC.class);
+ registerDirective("mg", MG.class);
+ registerDirective("sga", SGA.class);
}
- public static Agent process(Pred directive, Agent outerAg, Agent innerAg) {
+ public Directive getInstance(Pred directive) {
+ return getInstance(directive.getFunctor());
+ }
+
+ public Directive getInstance(String id) {
+ Directive d = instances.get(id);
+ if (d != null)
+ return d;
+
+ d = singletons.get(id);
+ if (d != null)
+ return d;
+
+ // create the instance
+ Class c = directives.get(id);
+ if (c == null) {
+ logger.log(Level.SEVERE, "Unknown directive "+id);
+ return null;
+ }
+
try {
- logger.fine("Processing directive "+directive);
- Directive d = directives.get(directive.getFunctor());
+ d = (Directive)c.newInstance();
+ if (d.isSingleton())
+ singletons.put(id, d);
+ else
+ instances.put(id, d);
+ return d;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+
+/*
+ public Agent process(Pred directive, Agent outerAg, Agent innerAg) {
+ try {
+ //logger.fine("Processing directive "+directive);
+ Directive d = get(directive.getFunctor());
if (d != null) {
return d.process(directive, outerAg, innerAg);
} else {
@@ -73,5 +131,6 @@
}
return null;
}
-
+*/
+
}
Modified: trunk/src/jason/asSyntax/directives/FunctionRegister.java
===================================================================
--- trunk/src/jason/asSyntax/directives/FunctionRegister.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/directives/FunctionRegister.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -32,7 +32,7 @@
*
* @author Jomi
*/
-public class FunctionRegister implements Directive {
+public class FunctionRegister extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(FunctionRegister.class.getName());
private static Map<String,ArithFunction> functions = new HashMap<String,ArithFunction>();
Modified: trunk/src/jason/asSyntax/directives/Include.java
===================================================================
--- trunk/src/jason/asSyntax/directives/Include.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/directives/Include.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -18,7 +18,7 @@
import java.util.logging.Logger;
/** Implementation of the <code>include</code> directive. */
-public class Include implements Directive {
+public class Include extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(Include.class.getName());
public static final String CRPrefix = "ClassResource:";
Modified: trunk/src/jason/asSyntax/directives/NameSpace.java
===================================================================
--- trunk/src/jason/asSyntax/directives/NameSpace.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/directives/NameSpace.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -3,9 +3,11 @@
import jason.asSemantics.Agent;
import jason.asSyntax.Atom;
import jason.asSyntax.Pred;
+import jason.asSyntax.parser.as2j;
import java.util.HashMap;
import java.util.Map;
+import java.util.Stack;
/** Implementation of the <code>namespace</code> directive. */
public class NameSpace implements Directive {
@@ -14,21 +16,39 @@
private Map<Atom,Atom> localNSs = new HashMap<Atom,Atom>();
+ @Override
+ public boolean isSingleton() {
+ return false;
+ }
+
+ @Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
return innerContent;
}
- public Atom declareNS(Pred directive) {
+ Stack<Atom> oldNS = new Stack<Atom>();
+
+ @Override
+ public void begin(Pred directive, as2j parser) {
+ oldNS.push(parser.getNS());
Atom ns = new Atom( ((Atom)directive.getTerm(0)).getFunctor() );
if (directive.getArity() > 1) {
String type = ((Atom)directive.getTerm(1)).getFunctor();
if (type.equals("local")) {
- return addLocalNS(ns);
+ ns = addLocalNS(ns);
}
}
- return ns;
+ parser.setNS(ns);
+ //return ns;
}
+ @Override
+ public void end(Pred directive, as2j parser) {
+ Atom ns = oldNS.pop();
+ if (ns != null)
+ parser.setNS(ns);
+ }
+
public boolean isLocalNS(Atom ns) {
return localNSs.get(ns) != null;
}
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-24 15:55:05 UTC (rev 1872)
@@ -53,7 +53,8 @@
private String asSource = null;
private Agent curAg = null;
private Atom namespace = Literal.DefaultNS;
- private NameSpace nsDirective = new NameSpace();
+ private DirectiveProcessor directiveProcessor = new DirectiveProcessor();
+ private NameSpace nsDirective = (NameSpace)directiveProcessor.getInstance("namespace");
private static Logger logger = Logger.getLogger("aslparser");
private static Set<String> parsedFiles = new HashSet<String>();
@@ -61,7 +62,8 @@
public void setAg(Agent ag) { curAg = ag; }
public void setNS(Atom ns) { namespace = ns; }
-
+ public Atom getNS() { return namespace; }
+
private String getSourceRef(SourceInfo s) {
if (s == null)
return "[]";
@@ -259,27 +261,23 @@
( LOOKAHEAD(4)
<TK_BEGIN> dir = pred() "}"
{ Agent innerAg = new Agent(); innerAg.initAg();
- if (dir.getFunctor().equals("namespace")) {
- Atom newNS = nsDirective.declareNS(dir); // to declare the namespace as local
- oldNS = namespace;
- setNS( newNS );
- }
+ directiveProcessor.getInstance(dir).begin(dir,this);
}
isEOF = agent(innerAg)
{ if (isEOF)
throw new ParseException(getSourceRef(dir)+" The directive '{ begin "+dir+"}' does not end with '{ end }'.");
- else
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, innerAg);
- if (oldNS != null)
- setNS( oldNS );
+
+ resultOfDirective = directiveProcessor.getInstance(dir).process(dir, outerAg, innerAg);
+ directiveProcessor.getInstance(dir).end(dir,this);
}
|
dir = pred() "}"
{ if (dir.toString().equals("end"))
return true;
- if (dir.getFunctor().equals("namespace"))
- nsDirective.declareNS(dir); // to declare the namespace as local
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
+ Directive d = directiveProcessor.getInstance(dir);
+ d.begin(dir, this); // to declare the namespace as local
+ resultOfDirective = d.process(dir, outerAg, null);
+ d.end(dir, this);
}
)
{ if (resultOfDirective != null && outerAg != null) {
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -22,7 +22,8 @@
private String asSource = null;
private Agent curAg = null;
private Atom namespace = Literal.DefaultNS;
- private NameSpace nsDirective = new NameSpace();
+ private DirectiveProcessor directiveProcessor = new DirectiveProcessor();
+ private NameSpace nsDirective = (NameSpace)directiveProcessor.getInstance("namespace");
private static Logger logger = Logger.getLogger("aslparser");
private static Set<String> parsedFiles = new HashSet<String>();
@@ -30,6 +31,7 @@
public void setAg(Agent ag) { curAg = ag; }
public void setNS(Atom ns) { namespace = ns; }
+ public Atom getNS() { return namespace; }
private String getSourceRef(SourceInfo s) {
if (s == null)
@@ -267,18 +269,13 @@
dir = pred();
jj_consume_token(31);
Agent innerAg = new Agent(); innerAg.initAg();
- if (dir.getFunctor().equals("namespace")) {
- Atom newNS = nsDirective.declareNS(dir); // to declare the namespace as local
- oldNS = namespace;
- setNS( newNS );
- }
+ directiveProcessor.getInstance(dir).begin(dir,this);
isEOF = agent(innerAg);
if (isEOF)
{if (true) throw new ParseException(getSourceRef(dir)+" The directive '{ begin "+dir+"}' does not end with '{ end }'.");}
- else
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, innerAg);
- if (oldNS != null)
- setNS( oldNS );
+
+ resultOfDirective = directiveProcessor.getInstance(dir).process(dir, outerAg, innerAg);
+ directiveProcessor.getInstance(dir).end(dir,this);
} else {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_BEGIN:
@@ -288,9 +285,10 @@
jj_consume_token(31);
if (dir.toString().equals("end"))
{if (true) return true;}
- if (dir.getFunctor().equals("namespace"))
- nsDirective.declareNS(dir); // to declare the namespace as local
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
+ Directive d = directiveProcessor.getInstance(dir);
+ d.begin(dir, this); // to declare the namespace as local
+ resultOfDirective = d.process(dir, outerAg, null);
+ d.end(dir, this);
break;
default:
jj_la1[8] = jj_gen;
@@ -1645,6 +1643,22 @@
finally { jj_save(3, xla); }
}
+ final private boolean jj_3R_115() {
+ if (jj_3R_122()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_60() {
+ if (jj_scan_token(TK_NOT)) return true;
+ if (jj_3R_52()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_114() {
+ if (jj_3R_121()) return true;
+ return false;
+ }
+
final private boolean jj_3R_108() {
Token xsp;
xsp = jj_scanpos;
@@ -2244,6 +2258,14 @@
return false;
}
+ final private boolean jj_3_1() {
+ if (jj_scan_token(TK_BEGIN)) return true;
+ if (jj_3R_13()) return true;
+ if (jj_scan_token(31)) return true;
+ if (jj_3R_14()) return true;
+ return false;
+ }
+
final private boolean jj_3R_98() {
Token xsp;
xsp = jj_scanpos;
@@ -2271,16 +2293,13 @@
return false;
}
- final private boolean jj_3R_37() {
- if (jj_scan_token(TK_FALSE)) return true;
+ final private boolean jj_3R_43() {
+ if (jj_scan_token(30)) return true;
return false;
}
- final private boolean jj_3_1() {
- if (jj_scan_token(TK_BEGIN)) return true;
- if (jj_3R_13()) return true;
- if (jj_scan_token(31)) return true;
- if (jj_3R_14()) return true;
+ final private boolean jj_3R_37() {
+ if (jj_scan_token(TK_FALSE)) return true;
return false;
}
@@ -2294,11 +2313,6 @@
return false;
}
- final private boolean jj_3R_43() {
- if (jj_scan_token(30)) return true;
- return false;
- }
-
final private boolean jj_3R_50() {
if (jj_3R_13()) return true;
return false;
@@ -2521,6 +2535,11 @@
return false;
}
+ final private boolean jj_3R_28() {
+ if (jj_3R_46()) return true;
+ return false;
+ }
+
final private boolean jj_3R_73() {
if (jj_3R_78()) return true;
return false;
@@ -2531,8 +2550,8 @@
return false;
}
- final private boolean jj_3R_28() {
- if (jj_3R_46()) return true;
+ final private boolean jj_3R_27() {
+ if (jj_3R_45()) return true;
return false;
}
@@ -2548,28 +2567,18 @@
return false;
}
- final private boolean jj_3R_27() {
- if (jj_3R_45()) return true;
- return false;
- }
-
- final private boolean jj_3R_119() {
- if (jj_3R_108()) return true;
- return false;
- }
-
final private boolean jj_3R_26() {
if (jj_3R_44()) return true;
return false;
}
- final private boolean jj_3R_118() {
- if (jj_scan_token(41)) return true;
+ final private boolean jj_3R_25() {
+ if (jj_3R_43()) return true;
return false;
}
- final private boolean jj_3R_25() {
- if (jj_3R_43()) return true;
+ final private boolean jj_3R_119() {
+ if (jj_3R_108()) return true;
return false;
}
@@ -2595,6 +2604,11 @@
return false;
}
+ final private boolean jj_3R_118() {
+ if (jj_scan_token(41)) return true;
+ return false;
+ }
+
final private boolean jj_3R_117() {
if (jj_3R_124()) return true;
return false;
@@ -2610,22 +2624,6 @@
return false;
}
- final private boolean jj_3R_115() {
- if (jj_3R_122()) return true;
- return false;
- }
-
- final private boolean jj_3R_60() {
- if (jj_scan_token(TK_NOT)) return true;
- if (jj_3R_52()) return true;
- return false;
- }
-
- final private boolean jj_3R_114() {
- if (jj_3R_121()) return true;
- return false;
- }
-
public as2jTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
Modified: trunk/src/jason/asSyntax/patterns/goal/BC.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/BC.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/patterns/goal/BC.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -4,6 +4,7 @@
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Pred;
import jason.asSyntax.Term;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import jason.asSyntax.directives.DirectiveProcessor;
@@ -15,7 +16,7 @@
*
* @author jomi
*/
-public class BC implements Directive {
+public class BC extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(BC.class.getName());
Modified: trunk/src/jason/asSyntax/patterns/goal/DG.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/DG.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/patterns/goal/DG.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -9,6 +9,7 @@
import jason.asSyntax.Plan;
import jason.asSyntax.Pred;
import jason.asSyntax.PlanBody.BodyType;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import java.util.logging.Level;
@@ -19,7 +20,7 @@
*
* @author jomi
*/
-public class DG implements Directive {
+public class DG extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(DG.class.getName());
Modified: trunk/src/jason/asSyntax/patterns/goal/EBDG.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/EBDG.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/patterns/goal/EBDG.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -12,6 +12,7 @@
import jason.asSyntax.Pred;
import jason.asSyntax.LogExpr.LogicalOp;
import jason.asSyntax.PlanBody.BodyType;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import java.util.logging.Level;
@@ -22,7 +23,7 @@
*
* @author jomi
*/
-public class EBDG implements Directive {
+public class EBDG extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(EBDG.class.getName());
Modified: trunk/src/jason/asSyntax/patterns/goal/MG.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/MG.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/patterns/goal/MG.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -4,6 +4,7 @@
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Literal;
import jason.asSyntax.Pred;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import jason.asSyntax.directives.DirectiveProcessor;
import jason.bb.BeliefBase;
@@ -16,7 +17,7 @@
*
* @author jomi
*/
-public class MG implements Directive {
+public class MG extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(MG.class.getName());
Modified: trunk/src/jason/asSyntax/patterns/goal/OMC.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/OMC.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/patterns/goal/OMC.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -6,6 +6,7 @@
import jason.asSyntax.Pred;
import jason.asSyntax.SourceInfo;
import jason.asSyntax.Term;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import jason.asSyntax.directives.DirectiveProcessor;
@@ -17,7 +18,7 @@
*
* @author jomi
*/
-public class OMC implements Directive {
+public class OMC extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(OMC.class.getName());
Modified: trunk/src/jason/asSyntax/patterns/goal/RC.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/RC.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/patterns/goal/RC.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -4,6 +4,7 @@
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Pred;
import jason.asSyntax.Term;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import jason.asSyntax.directives.DirectiveProcessor;
@@ -15,7 +16,7 @@
*
* @author jomi
*/
-public class RC implements Directive {
+public class RC extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(RC.class.getName());
Modified: trunk/src/jason/asSyntax/patterns/goal/SGA.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/SGA.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/patterns/goal/SGA.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -8,6 +8,7 @@
import jason.asSyntax.StringTerm;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import java.util.logging.Level;
@@ -18,7 +19,7 @@
*
* @author jomi
*/
-public class SGA implements Directive {
+public class SGA extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(SGA.class.getName());
Modified: trunk/src/jason/asSyntax/patterns/goal/SMC.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/SMC.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/jason/asSyntax/patterns/goal/SMC.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -4,6 +4,7 @@
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Pred;
import jason.asSyntax.Term;
+import jason.asSyntax.directives.DefaultDirective;
import jason.asSyntax.directives.Directive;
import jason.asSyntax.directives.DirectiveProcessor;
@@ -15,7 +16,7 @@
*
* @author jomi
*/
-public class SMC implements Directive {
+public class SMC extends DefaultDirective implements Directive {
static Logger logger = Logger.getLogger(SMC.class.getName());
Modified: trunk/src/test/ASParserTest.java
===================================================================
--- trunk/src/test/ASParserTest.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/test/ASParserTest.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -326,6 +326,7 @@
parseDir(f);
} else if (f.getName().endsWith(MAS2JProject.AS_EXT)) {
if (f.getName().equals("search.asl")) continue; // ignore this file
+ if (f.getName().equals("b.asl")) continue; // ignore this file
as2j parser = new as2j(new FileInputStream(f));
//Agent ag = new Agent();
//ag.init();
Modified: trunk/src/test/NSTest.java
===================================================================
--- trunk/src/test/NSTest.java 2016-02-24 14:32:39 UTC (rev 1871)
+++ trunk/src/test/NSTest.java 2016-02-24 15:55:05 UTC (rev 1872)
@@ -6,6 +6,7 @@
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Atom;
import jason.asSyntax.Literal;
+import jason.asSyntax.Plan;
import jason.asSyntax.Term;
import jason.asSyntax.VarTerm;
import jason.asSyntax.parser.ParseException;
@@ -252,7 +253,7 @@
"{end}\n"+
"{begin namespace(ns2,local)}\n"+
" b4(t). "+
- " +tk <- .print(t); !g5(u). "+
+ " +tk <- .print(t); +ns1::tick; !g5(u). "+
"{end}\n"+
"b5(i)."+
"{namespace(ns3,local)}\n"+
@@ -265,10 +266,11 @@
parser.agent(a);
a.addInitialBelsInBB();
//System.out.println(a.getBB());
- //System.out.println(a.getPL().toString());
+ for (Plan p: a.getPL())
+ System.out.println(p);
assertTrue(a.getPL().toString().contains("+ns1::tick <- .print(ns1::t); !ns1::g(ns1::u)"));
+ assertTrue(a.getPL().toString().contains("+#1ns2::tk <- .print(#1ns2::t); +ns1::tick; !#1ns2::g5(#1ns2::u)"));
assertTrue(a.getPL().toString().contains("+!nsd::g2(nsd::V) <- +nsd::b3(nsd::h); +ns1::tick; +#1ns2::tk; +#2ns3::b5(#1ns2::t)"));
- assertTrue(a.getPL().toString().contains("+#1ns2::tk <- .print(#1ns2::t); !#1ns2::g5(#1ns2::u)"));
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-02-24 14:32:42
|
Revision: 1871
http://sourceforge.net/p/jason/svn/1871
Author: jomifred
Date: 2016-02-24 14:32:39 +0000 (Wed, 24 Feb 2016)
Log Message:
-----------
namespace directive
Modified Paths:
--------------
trunk/src/jason/asSyntax/directives/DirectiveProcessor.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/jeditplugin/Config.java
trunk/src/test/NSTest.java
Added Paths:
-----------
trunk/src/jason/asSyntax/directives/NameSpace.java
Modified: trunk/src/jason/asSyntax/directives/DirectiveProcessor.java
===================================================================
--- trunk/src/jason/asSyntax/directives/DirectiveProcessor.java 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/jason/asSyntax/directives/DirectiveProcessor.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -46,6 +46,7 @@
static {
addDirective("include", new Include());
addDirective("register_function", new FunctionRegister());
+ addDirective("namespace", new NameSpace());
addDirective("dg", new DG());
addDirective("bdg", new BDG());
Added: trunk/src/jason/asSyntax/directives/NameSpace.java
===================================================================
--- trunk/src/jason/asSyntax/directives/NameSpace.java (rev 0)
+++ trunk/src/jason/asSyntax/directives/NameSpace.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -0,0 +1,51 @@
+package jason.asSyntax.directives;
+
+import jason.asSemantics.Agent;
+import jason.asSyntax.Atom;
+import jason.asSyntax.Pred;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/** Implementation of the <code>namespace</code> directive. */
+public class NameSpace implements Directive {
+
+ //static Logger logger = Logger.getLogger(NameSpace.class.getName());
+
+ private Map<Atom,Atom> localNSs = new HashMap<Atom,Atom>();
+
+ public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
+ return innerContent;
+ }
+
+ public Atom declareNS(Pred directive) {
+ Atom ns = new Atom( ((Atom)directive.getTerm(0)).getFunctor() );
+ if (directive.getArity() > 1) {
+ String type = ((Atom)directive.getTerm(1)).getFunctor();
+ if (type.equals("local")) {
+ return addLocalNS(ns);
+ }
+ }
+ return ns;
+ }
+
+ public boolean isLocalNS(Atom ns) {
+ return localNSs.get(ns) != null;
+ }
+
+ public Atom map(Atom ns) {
+ Atom n = localNSs.get(ns);
+ if (n == null)
+ return ns;
+ else
+ return n;
+ }
+
+ static private int nsCounter = 0;
+ private synchronized Atom addLocalNS(Atom ns) {
+ nsCounter++;
+ Atom newNS = new Atom("#"+nsCounter+ns);
+ localNSs.put(ns,newNS);
+ return newNS;
+ }
+}
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-24 14:32:39 UTC (rev 1871)
@@ -50,9 +50,10 @@
import jason.jeditplugin.*;
public class as2j {
- private String asSource = null;
- private Agent curAg = null;
- private Atom namespace = Literal.DefaultNS;
+ private String asSource = null;
+ private Agent curAg = null;
+ private Atom namespace = Literal.DefaultNS;
+ private NameSpace nsDirective = new NameSpace();
private static Logger logger = Logger.getLogger("aslparser");
private static Set<String> parsedFiles = new HashSet<String>();
@@ -251,24 +252,34 @@
Agent resultOfDirective = null;
Agent bakAg = curAg;
boolean isEOF = false;
+ Atom oldNS = null;
}
{
"{"
( LOOKAHEAD(4)
<TK_BEGIN> dir = pred() "}"
- { Agent innerAg = new Agent(); innerAg.initAg(); }
+ { Agent innerAg = new Agent(); innerAg.initAg();
+ if (dir.getFunctor().equals("namespace")) {
+ Atom newNS = nsDirective.declareNS(dir); // to declare the namespace as local
+ oldNS = namespace;
+ setNS( newNS );
+ }
+ }
isEOF = agent(innerAg)
{ if (isEOF)
throw new ParseException(getSourceRef(dir)+" The directive '{ begin "+dir+"}' does not end with '{ end }'.");
else
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, innerAg);
+ resultOfDirective = DirectiveProcessor.process(dir, outerAg, innerAg);
+ if (oldNS != null)
+ setNS( oldNS );
}
|
dir = pred() "}"
{ if (dir.toString().equals("end"))
return true;
- else
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
+ if (dir.getFunctor().equals("namespace"))
+ nsDirective.declareNS(dir); // to declare the namespace as local
+ resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
}
)
{ if (resultOfDirective != null && outerAg != null) {
@@ -645,6 +656,7 @@
}
if (ASSyntax.isKeyword(F))
NS = Literal.DefaultNS;
+ NS = nsDirective.map(NS);
return new LiteralImpl(NS, type, F);
}
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -19,9 +19,10 @@
import jason.jeditplugin.*;
public class as2j implements as2jConstants {
- private String asSource = null;
- private Agent curAg = null;
- private Atom namespace = Literal.DefaultNS;
+ private String asSource = null;
+ private Agent curAg = null;
+ private Atom namespace = Literal.DefaultNS;
+ private NameSpace nsDirective = new NameSpace();
private static Logger logger = Logger.getLogger("aslparser");
private static Set<String> parsedFiles = new HashSet<String>();
@@ -259,17 +260,25 @@
Agent resultOfDirective = null;
Agent bakAg = curAg;
boolean isEOF = false;
+ Atom oldNS = null;
jj_consume_token(30);
if (jj_2_1(4)) {
jj_consume_token(TK_BEGIN);
dir = pred();
jj_consume_token(31);
Agent innerAg = new Agent(); innerAg.initAg();
+ if (dir.getFunctor().equals("namespace")) {
+ Atom newNS = nsDirective.declareNS(dir); // to declare the namespace as local
+ oldNS = namespace;
+ setNS( newNS );
+ }
isEOF = agent(innerAg);
if (isEOF)
{if (true) throw new ParseException(getSourceRef(dir)+" The directive '{ begin "+dir+"}' does not end with '{ end }'.");}
else
resultOfDirective = DirectiveProcessor.process(dir, outerAg, innerAg);
+ if (oldNS != null)
+ setNS( oldNS );
} else {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_BEGIN:
@@ -279,8 +288,9 @@
jj_consume_token(31);
if (dir.toString().equals("end"))
{if (true) return true;}
- else
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
+ if (dir.getFunctor().equals("namespace"))
+ nsDirective.declareNS(dir); // to declare the namespace as local
+ resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
break;
default:
jj_la1[8] = jj_gen;
@@ -977,6 +987,7 @@
}
if (ASSyntax.isKeyword(F))
NS = Literal.DefaultNS;
+ NS = nsDirective.map(NS);
{if (true) return new LiteralImpl(NS, type, F);}
throw new Error("Missing return statement in function");
@@ -1634,37 +1645,6 @@
finally { jj_save(3, xla); }
}
- final private boolean jj_3R_117() {
- if (jj_3R_124()) return true;
- return false;
- }
-
- final private boolean jj_3R_116() {
- if (jj_3R_123()) return true;
- return false;
- }
-
- final private boolean jj_3R_61() {
- if (jj_3R_66()) return true;
- return false;
- }
-
- final private boolean jj_3R_115() {
- if (jj_3R_122()) return true;
- return false;
- }
-
- final private boolean jj_3R_114() {
- if (jj_3R_121()) return true;
- return false;
- }
-
- final private boolean jj_3R_60() {
- if (jj_scan_token(TK_NOT)) return true;
- if (jj_3R_52()) return true;
- return false;
- }
-
final private boolean jj_3R_108() {
Token xsp;
xsp = jj_scanpos;
@@ -1700,6 +1680,12 @@
return false;
}
+ final private boolean jj_3R_53() {
+ if (jj_scan_token(52)) return true;
+ if (jj_3R_38()) return true;
+ return false;
+ }
+
final private boolean jj_3R_48() {
if (jj_scan_token(40)) return true;
return false;
@@ -1712,9 +1698,11 @@
return false;
}
- final private boolean jj_3R_53() {
- if (jj_scan_token(52)) return true;
- if (jj_3R_38()) return true;
+ final private boolean jj_3R_38() {
+ if (jj_3R_52()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_53()) jj_scanpos = xsp;
return false;
}
@@ -1728,14 +1716,6 @@
return false;
}
- final private boolean jj_3R_38() {
- if (jj_3R_52()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_53()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_33() {
if (jj_scan_token(36)) return true;
return false;
@@ -1751,6 +1731,12 @@
return false;
}
+ final private boolean jj_3R_39() {
+ if (jj_scan_token(50)) return true;
+ if (jj_3R_20()) return true;
+ return false;
+ }
+
final private boolean jj_3R_17() {
if (jj_scan_token(35)) return true;
if (jj_3R_20()) return true;
@@ -1767,12 +1753,6 @@
return false;
}
- final private boolean jj_3R_39() {
- if (jj_scan_token(50)) return true;
- if (jj_3R_20()) return true;
- return false;
- }
-
final private boolean jj_3R_31() {
if (jj_scan_token(39)) return true;
return false;
@@ -1789,11 +1769,6 @@
return false;
}
- final private boolean jj_3R_29() {
- if (jj_scan_token(37)) return true;
- return false;
- }
-
final private boolean jj_3R_20() {
if (jj_3R_38()) return true;
Token xsp;
@@ -1802,6 +1777,11 @@
return false;
}
+ final private boolean jj_3R_29() {
+ if (jj_scan_token(37)) return true;
+ return false;
+ }
+
final private boolean jj_3_2() {
Token xsp;
xsp = jj_scanpos;
@@ -1904,11 +1884,6 @@
return false;
}
- final private boolean jj_3R_59() {
- if (jj_scan_token(TK_LABEL_AT)) return true;
- return false;
- }
-
final private boolean jj_3R_76() {
if (jj_scan_token(50)) return true;
Token xsp;
@@ -1923,11 +1898,8 @@
return false;
}
- final private boolean jj_3R_46() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_59()) jj_scanpos = xsp;
- if (jj_3R_16()) return true;
+ final private boolean jj_3R_59() {
+ if (jj_scan_token(TK_LABEL_AT)) return true;
return false;
}
@@ -1942,6 +1914,14 @@
return false;
}
+ final private boolean jj_3R_46() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_59()) jj_scanpos = xsp;
+ if (jj_3R_16()) return true;
+ return false;
+ }
+
final private boolean jj_3R_54() {
if (jj_scan_token(VAR)) return true;
return false;
@@ -2024,13 +2004,13 @@
return false;
}
- final private boolean jj_3R_128() {
- if (jj_3R_20()) return true;
+ final private boolean jj_3R_113() {
+ if (jj_3R_120()) return true;
return false;
}
- final private boolean jj_3R_113() {
- if (jj_3R_120()) return true;
+ final private boolean jj_3R_128() {
+ if (jj_3R_20()) return true;
return false;
}
@@ -2041,6 +2021,16 @@
return false;
}
+ final private boolean jj_3R_41() {
+ if (jj_3R_57()) return true;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_79()) { jj_scanpos = xsp; break; }
+ }
+ return false;
+ }
+
final private boolean jj_3R_136() {
if (jj_scan_token(37)) return true;
return false;
@@ -2051,16 +2041,6 @@
return false;
}
- final private boolean jj_3R_41() {
- if (jj_3R_57()) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_79()) { jj_scanpos = xsp; break; }
- }
- return false;
- }
-
final private boolean jj_3R_139() {
if (jj_scan_token(46)) return true;
return false;
@@ -2071,6 +2051,12 @@
return false;
}
+ final private boolean jj_3R_111() {
+ if (jj_scan_token(37)) return true;
+ if (jj_3R_102()) return true;
+ return false;
+ }
+
final private boolean jj_3R_137() {
if (jj_scan_token(37)) return true;
return false;
@@ -2084,12 +2070,6 @@
return false;
}
- final private boolean jj_3R_111() {
- if (jj_scan_token(37)) return true;
- if (jj_3R_102()) return true;
- return false;
- }
-
final private boolean jj_3R_135() {
Token xsp;
xsp = jj_scanpos;
@@ -2127,21 +2107,16 @@
return false;
}
- final private boolean jj_3R_44() {
- if (jj_3R_19()) return true;
+ final private boolean jj_3R_109() {
+ if (jj_scan_token(NUMBER)) return true;
return false;
}
- final private boolean jj_3R_131() {
- if (jj_scan_token(44)) return true;
+ final private boolean jj_3R_44() {
+ if (jj_3R_19()) return true;
return false;
}
- final private boolean jj_3R_109() {
- if (jj_scan_token(NUMBER)) return true;
- return false;
- }
-
final private boolean jj_3R_23() {
if (jj_scan_token(42)) return true;
if (jj_3R_41()) return true;
@@ -2149,6 +2124,11 @@
return false;
}
+ final private boolean jj_3R_131() {
+ if (jj_scan_token(44)) return true;
+ return false;
+ }
+
final private boolean jj_3R_130() {
if (jj_scan_token(34)) return true;
return false;
@@ -2244,24 +2224,11 @@
return false;
}
- final private boolean jj_3_1() {
- if (jj_scan_token(TK_BEGIN)) return true;
- if (jj_3R_13()) return true;
- if (jj_scan_token(31)) return true;
- if (jj_3R_14()) return true;
- return false;
- }
-
final private boolean jj_3R_107() {
if (jj_scan_token(TK_INTMOD)) return true;
return false;
}
- final private boolean jj_3R_43() {
- if (jj_scan_token(30)) return true;
- return false;
- }
-
final private boolean jj_3R_106() {
if (jj_scan_token(TK_INTDIV)) return true;
return false;
@@ -2294,11 +2261,6 @@
return false;
}
- final private boolean jj_3R_37() {
- if (jj_scan_token(TK_FALSE)) return true;
- return false;
- }
-
final private boolean jj_3R_95() {
if (jj_3R_97()) return true;
Token xsp;
@@ -2309,6 +2271,19 @@
return false;
}
+ final private boolean jj_3R_37() {
+ if (jj_scan_token(TK_FALSE)) return true;
+ return false;
+ }
+
+ final private boolean jj_3_1() {
+ if (jj_scan_token(TK_BEGIN)) return true;
+ if (jj_3R_13()) return true;
+ if (jj_scan_token(31)) return true;
+ if (jj_3R_14()) return true;
+ return false;
+ }
+
final private boolean jj_3R_36() {
if (jj_scan_token(TK_TRUE)) return true;
return false;
@@ -2319,6 +2294,11 @@
return false;
}
+ final private boolean jj_3R_43() {
+ if (jj_scan_token(30)) return true;
+ return false;
+ }
+
final private boolean jj_3R_50() {
if (jj_3R_13()) return true;
return false;
@@ -2400,6 +2380,11 @@
return false;
}
+ final private boolean jj_3R_89() {
+ if (jj_3R_78()) return true;
+ return false;
+ }
+
final private boolean jj_3R_35() {
Token xsp;
xsp = jj_scanpos;
@@ -2414,11 +2399,6 @@
return false;
}
- final private boolean jj_3R_89() {
- if (jj_3R_78()) return true;
- return false;
- }
-
final private boolean jj_3R_88() {
if (jj_3R_77()) return true;
return false;
@@ -2437,13 +2417,13 @@
return false;
}
- final private boolean jj_3R_129() {
- if (jj_scan_token(TK_ELSE)) return true;
+ final private boolean jj_3R_87() {
+ if (jj_scan_token(58)) return true;
return false;
}
- final private boolean jj_3R_87() {
- if (jj_scan_token(58)) return true;
+ final private boolean jj_3R_129() {
+ if (jj_scan_token(TK_ELSE)) return true;
return false;
}
@@ -2452,6 +2432,11 @@
return false;
}
+ final private boolean jj_3R_85() {
+ if (jj_scan_token(56)) return true;
+ return false;
+ }
+
final private boolean jj_3R_125() {
Token xsp;
xsp = jj_scanpos;
@@ -2460,21 +2445,11 @@
return false;
}
- final private boolean jj_3R_85() {
- if (jj_scan_token(56)) return true;
- return false;
- }
-
final private boolean jj_3R_84() {
if (jj_scan_token(55)) return true;
return false;
}
- final private boolean jj_3R_28() {
- if (jj_3R_46()) return true;
- return false;
- }
-
final private boolean jj_3R_83() {
if (jj_scan_token(54)) return true;
return false;
@@ -2495,23 +2470,6 @@
return false;
}
- final private boolean jj_3R_27() {
- if (jj_3R_45()) return true;
- return false;
- }
-
- final private boolean jj_3R_121() {
- if (jj_scan_token(TK_IF)) return true;
- if (jj_scan_token(42)) return true;
- if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
- if (jj_3R_67()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_125()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_74() {
Token xsp;
xsp = jj_scanpos;
@@ -2551,13 +2509,20 @@
return false;
}
- final private boolean jj_3R_73() {
- if (jj_3R_78()) return true;
+ final private boolean jj_3R_121() {
+ if (jj_scan_token(TK_IF)) return true;
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(43)) return true;
+ if (jj_3R_67()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_125()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_26() {
- if (jj_3R_44()) return true;
+ final private boolean jj_3R_73() {
+ if (jj_3R_78()) return true;
return false;
}
@@ -2566,8 +2531,8 @@
return false;
}
- final private boolean jj_3R_25() {
- if (jj_3R_43()) return true;
+ final private boolean jj_3R_28() {
+ if (jj_3R_46()) return true;
return false;
}
@@ -2583,6 +2548,31 @@
return false;
}
+ final private boolean jj_3R_27() {
+ if (jj_3R_45()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_119() {
+ if (jj_3R_108()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_26() {
+ if (jj_3R_44()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_118() {
+ if (jj_scan_token(41)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_25() {
+ if (jj_3R_43()) return true;
+ return false;
+ }
+
final private boolean jj_3R_14() {
Token xsp;
while (true) {
@@ -2605,16 +2595,37 @@
return false;
}
- final private boolean jj_3R_119() {
- if (jj_3R_108()) return true;
+ final private boolean jj_3R_117() {
+ if (jj_3R_124()) return true;
return false;
}
- final private boolean jj_3R_118() {
- if (jj_scan_token(41)) return true;
+ final private boolean jj_3R_61() {
+ if (jj_3R_66()) return true;
return false;
}
+ final private boolean jj_3R_116() {
+ if (jj_3R_123()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_115() {
+ if (jj_3R_122()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_60() {
+ if (jj_scan_token(TK_NOT)) return true;
+ if (jj_3R_52()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_114() {
+ if (jj_3R_121()) return true;
+ return false;
+ }
+
public as2jTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
Modified: trunk/src/jason/jeditplugin/Config.java
===================================================================
--- trunk/src/jason/jeditplugin/Config.java 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/jason/jeditplugin/Config.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -696,8 +696,11 @@
private String getJarFromEclipseInstallation(String file) {
String eclipse = System.getProperty("eclipse.launcher");
//eclipse = "/Applications/eclipse/eclipse";
- if (eclipse != null) {
- File f = new File( (new File(eclipse)).getParentFile()+"/"+getEclipseInstallationDirectory()+"/lib/"+file);
+ if (eclipse != null) {
+ File f = (new File(eclipse)).getParentFile().getParentFile();
+ if (eclipse.contains("Eclipse.app/Contents")) // MacOs case
+ f = f.getParentFile().getParentFile();
+ f = new File(f+"/"+getEclipseInstallationDirectory()+"/lib/"+file);
if (f.exists())
return f.getAbsolutePath();
}
Modified: trunk/src/test/NSTest.java
===================================================================
--- trunk/src/test/NSTest.java 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/test/NSTest.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -242,4 +242,33 @@
parser.agent(a);
assertTrue(a.getPL().toString().contains("[source(self)] +NS::tick <- .print(ns33::NS)."));
}
+
+
+ public void testDirective() throws ParseException, JasonException {
+ as2j parser = new as2j(new StringReader(
+ "{begin namespace(ns1)}\n"+
+ " b1(t). "+
+ " +tick <- .print(t); !g(u). "+
+ "{end}\n"+
+ "{begin namespace(ns2,local)}\n"+
+ " b4(t). "+
+ " +tk <- .print(t); !g5(u). "+
+ "{end}\n"+
+ "b5(i)."+
+ "{namespace(ns3,local)}\n"+
+ "b2(t). +!g2(V) <- +b3(h); +ns1::tick; +ns2::tk; +ns3::b5(ns2::t). "
+ ));
+
+ Agent a = new Agent();
+ a.initAg();
+ parser.setNS(new Atom("nsd"));
+ parser.agent(a);
+ a.addInitialBelsInBB();
+ //System.out.println(a.getBB());
+ //System.out.println(a.getPL().toString());
+ assertTrue(a.getPL().toString().contains("+ns1::tick <- .print(ns1::t); !ns1::g(ns1::u)"));
+ assertTrue(a.getPL().toString().contains("+!nsd::g2(nsd::V) <- +nsd::b3(nsd::h); +ns1::tick; +#1ns2::tk; +#2ns3::b5(#1ns2::t)"));
+ assertTrue(a.getPL().toString().contains("+#1ns2::tk <- .print(#1ns2::t); !#1ns2::g5(#1ns2::u)"));
+
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-02-21 11:55:02
|
Revision: 1870
http://sourceforge.net/p/jason/svn/1870
Author: jomifred
Date: 2016-02-21 11:55:00 +0000 (Sun, 21 Feb 2016)
Log Message:
-----------
fix bug related to namespaces and makevarsannon
Modified Paths:
--------------
trunk/build.xml
trunk/pom.xml
trunk/src/jason/asSemantics/Unifier.java
trunk/src/jason/asSyntax/Structure.java
trunk/src/jason/bb/DefaultBeliefBase.java
trunk/src/jason/jeditplugin/Config.java
trunk/src/test/TermTest.java
Added Paths:
-----------
trunk/bin/jason-ide.bat
trunk/bin/jason-ide.sh
Removed Paths:
-------------
trunk/bin/jason.bat
trunk/bin/jason.sh
Copied: trunk/bin/jason-ide.bat (from rev 1869, trunk/bin/jason.bat)
===================================================================
--- trunk/bin/jason-ide.bat (rev 0)
+++ trunk/bin/jason-ide.bat 2016-02-21 11:55:00 UTC (rev 1870)
@@ -0,0 +1,5 @@
+@echo off
+rem SET JAVA_HOME=C:\Program Files\jdk1.5
+rem SET PATH="%JAVA_HOME%\bin";%PATH%
+java -cp ..\lib\jason.jar;..\lib\jade.jar;jedit\jedit.jar;..\lib\cartago.jar;..\lib\c4jason.jar;..\lib\moise.jar;..\lib\jacamo.jar;%CLASSPATH% org.gjt.sp.jedit.jEdit
+
Copied: trunk/bin/jason-ide.sh (from rev 1869, trunk/bin/jason.sh)
===================================================================
--- trunk/bin/jason-ide.sh (rev 0)
+++ trunk/bin/jason-ide.sh 2016-02-21 11:55:00 UTC (rev 1870)
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+CURDIR=`pwd`
+JASON_HOME=`dirname $0`
+cd "$JASON_HOME/.."
+JASON_HOME=`pwd`
+#cd "$JASON_HOME/bin"
+cd $CURDIR
+
+OS=`uname`
+
+if [ -z $JDK_HOME ] ; then
+ if [ -n $JAVA_HOME ] ; then
+ JDK_HOME=$JAVA_HOME
+ fi
+fi
+
+if [ -z $JDK_HOME ] ; then
+ if [ $OS == Darwin ] ; then
+ JDK_HOME=/usr
+ fi
+fi
+
+# check JDK_HOME
+if [ ! -f $JDK_HOME/bin/javac ] ; then
+ echo JDK_HOME is not properly set!
+fi
+
+export PATH="$JDK_HOME/bin":$PATH
+
+DPAR=""
+if [ $OS == Darwin ] ; then
+ DPAR="-Dapple.laf.useScreenMenuBar=true"
+fi
+
+# run jIDE
+java -classpath "$JASON_HOME/lib/jason.jar":"$JASON_HOME/bin/jedit/jedit.jar":"$JASON_HOME/lib/saci.jar":"$JASON_HOME/lib/jade.jar":"$JASON_HOME/lib/cartago.jar":"$JASON_HOME/lib/c4jason.jar":"$JASON_HOME/bin/jedit/jars/ErrorList.jar":"$JASON_HOME/bin/jedit/jars/SideKick.jar":$JASON_HOME/lib/cartago.jar:$JASON_HOME/lib/c4jason.jar:$JASON_HOME/lib/moise.jar:$JASON_HOME/lib/jacamo.jar:$CLASSPATH:. \
+ $DPAR \
+ org.gjt.sp.jedit.jEdit $1
+
+#"$JASON_HOME/lib/ant.jar":"$JASON_HOME/lib/ant-launcher.jar":
+#-settings=$JASON_HOME/bin/.jedit
Deleted: trunk/bin/jason.bat
===================================================================
--- trunk/bin/jason.bat 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/bin/jason.bat 2016-02-21 11:55:00 UTC (rev 1870)
@@ -1,5 +0,0 @@
-@echo off
-rem SET JAVA_HOME=C:\Program Files\jdk1.5
-rem SET PATH="%JAVA_HOME%\bin";%PATH%
-java -cp ..\lib\jason.jar;..\lib\saci.jar;..\lib\jade.jar;jedit\jedit.jar;..\lib\cartago.jar;..\lib\c4jason.jar;..\lib\moise.jar;..\lib\jacamo.jar;%CLASSPATH% org.gjt.sp.jedit.jEdit
-
Deleted: trunk/bin/jason.sh
===================================================================
--- trunk/bin/jason.sh 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/bin/jason.sh 2016-02-21 11:55:00 UTC (rev 1870)
@@ -1,42 +0,0 @@
-#!/bin/bash
-
-CURDIR=`pwd`
-JASON_HOME=`dirname $0`
-cd "$JASON_HOME/.."
-JASON_HOME=`pwd`
-#cd "$JASON_HOME/bin"
-cd $CURDIR
-
-OS=`uname`
-
-if [ -z $JDK_HOME ] ; then
- if [ -n $JAVA_HOME ] ; then
- JDK_HOME=$JAVA_HOME
- fi
-fi
-
-if [ -z $JDK_HOME ] ; then
- if [ $OS == Darwin ] ; then
- JDK_HOME=/usr
- fi
-fi
-
-# check JDK_HOME
-if [ ! -f $JDK_HOME/bin/javac ] ; then
- echo JDK_HOME is not properly set!
-fi
-
-export PATH="$JDK_HOME/bin":$PATH
-
-DPAR=""
-if [ $OS == Darwin ] ; then
- DPAR="-Dapple.laf.useScreenMenuBar=true"
-fi
-
-# run jIDE
-java -classpath "$JASON_HOME/lib/jason.jar":"$JASON_HOME/bin/jedit/jedit.jar":"$JASON_HOME/lib/saci.jar":"$JASON_HOME/lib/jade.jar":"$JASON_HOME/lib/cartago.jar":"$JASON_HOME/lib/c4jason.jar":"$JASON_HOME/bin/jedit/jars/ErrorList.jar":"$JASON_HOME/bin/jedit/jars/SideKick.jar":$JASON_HOME/lib/cartago.jar:$JASON_HOME/lib/c4jason.jar:$JASON_HOME/lib/moise.jar:$JASON_HOME/lib/jacamo.jar:$CLASSPATH:. \
- $DPAR \
- org.gjt.sp.jedit.jEdit $1
-
-#"$JASON_HOME/lib/ant.jar":"$JASON_HOME/lib/ant-launcher.jar":
-#-settings=$JASON_HOME/bin/.jedit
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/build.xml 2016-02-21 11:55:00 UTC (rev 1870)
@@ -20,7 +20,7 @@
<property name="jedit.install.dir" value="${basedir}/bin/jedit" />
<property name="plugin.jar.name" value="jason-jedit-plugin.jar" />
- <!-- define Maven coordinates -->
+ <!-- define Maven coordinates, from http://central.sonatype.org/pages/apache-ant.html -->
<property name="groupId" value="net.sf.jason" />
<property name="artifactId" value="jason" />
<!-- define artifacts' name, which follows the convention of Maven -->
@@ -412,6 +412,8 @@
</jar>
</target>
+ <!-- code from http://central.sonatype.org/pages/apache-ant.html -->
+
<target name="maven-deploy" depends="maven-init" description="generate the maven distribution">
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy-file" />
@@ -427,7 +429,9 @@
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
<arg value="-Durl=${maven-staging-repository-url}" />
- <arg value="-DrepositoryId=${maven-staging-repository-id}" />
+ <arg value="-Darguments=gpg.passphrase=''" />
+ <!-- arg value="-DrepositoryId=${maven-staging-repository-id}" /-->
+ <arg value="-DrepositoryId=${ossrh-server-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${maven-jar}" />
<arg value="-Pgpg" />
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/pom.xml 2016-02-21 11:55:00 UTC (rev 1870)
@@ -4,7 +4,7 @@
<artifactId>jason</artifactId>
<packaging>jar</packaging>
<name>Jason</name>
- <version>1.4.1</version>
+ <version>1.4.2</version>
<description>Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language, and is implemented in Java. Using JADE a multi-agent system can be distributed over a network effortlessly.</description>
<url>http://jason.sf.net</url>
<licenses>
Modified: trunk/src/jason/asSemantics/Unifier.java
===================================================================
--- trunk/src/jason/asSemantics/Unifier.java 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/src/jason/asSemantics/Unifier.java 2016-02-21 11:55:00 UTC (rev 1870)
@@ -243,7 +243,14 @@
} else if (t2vl != null) {
return bind(t1gv, t2vl);
} else { // unify two vars
- return bind(t1gv, t2gv);
+ if (! t1gv.getNS().equals(t2gv.getNS()))
+ return false;
+
+ if (t1gv.negated() != t2gv.negated())
+ return false;
+
+ bind(t1gv, t2gv);
+ return true;
}
}
@@ -318,14 +325,7 @@
return v;
}
- public boolean bind(VarTerm vt1, VarTerm vt2) {
- if (! vt1.getNS().equals(vt2.getNS()))
- return false;
-
- if (vt1.negated() != vt2.negated()) {
- return false;
- }
-
+ public void bind(VarTerm vt1, VarTerm vt2) {
vt1 = getVarForUnifier(vt1);
vt2 = getVarForUnifier(vt2);
final int comp = vt1.compareTo(vt2);
@@ -335,7 +335,6 @@
} else if (comp > 0){
function.put(vt2, vt1);
} // if they are the same (comp == 0), do not bind
- return true;
}
public boolean bind(VarTerm vt, Term vl) {
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/src/jason/asSyntax/Structure.java 2016-02-21 11:55:00 UTC (rev 1870)
@@ -364,7 +364,10 @@
// if the variable hasn't been renamed given the input unifier, then rename it.
if (deref.equals(vt)) {
// forget the name
- UnnamedVar var = useShortUnnamedVars ? new UnnamedVar() : UnnamedVar.create(t.toString());
+ Atom ns = vt.getNS();
+ if (ns.isVar())
+ ns = varToReplace(ns, un);
+ UnnamedVar var = useShortUnnamedVars ? new UnnamedVar(ns) : UnnamedVar.create(ns, t.toString());
//var.setFromMakeVarAnnon();
// if deref has annotations then we need to replicate these in the new variable
@@ -374,18 +377,21 @@
}
un.bind(deref, var);
return var;
+ } else {
+ // otherwise it has already been renamed in this scope so return
+ // the existing renaming
+ Atom ns = vt.getNS();
+ if (ns.isVar())
+ ns = varToReplace(ns, un);
+ deref = (VarTerm)deref.cloneNS(ns);
+ // ensure that if the input term has an annotation and the existing
+ // renaming doesn't then we add the anonymized annotations
+ if (vt.hasAnnot() && !deref.hasAnnot()) {
+ deref.setAnnots(vt.getAnnots().cloneLT());
+ deref.makeVarsAnnon(un);
+ }
+ return deref;
}
-
- // otherwise it has already been renamed in this scope so return
- // the existing renaming
- deref = (VarTerm)deref.clone();
- // ensure that if the input term has an annotation and the existing
- // renaming doesn't then we add the anonymized annotations
- if (vt.hasAnnot() && !deref.hasAnnot()) {
- deref.setAnnots(vt.getAnnots().cloneLT());
- deref.makeVarsAnnon(un);
- }
- return deref;
}
/*
Modified: trunk/src/jason/bb/DefaultBeliefBase.java
===================================================================
--- trunk/src/jason/bb/DefaultBeliefBase.java 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/src/jason/bb/DefaultBeliefBase.java 2016-02-21 11:55:00 UTC (rev 1870)
@@ -219,11 +219,11 @@
return new Iterator<Literal>() {
Iterator<BelEntry> ibe = ins.next().values().iterator();
- Iterator<Literal> il = ibe.next().list.iterator();
+ Iterator<Literal> il = (ibe.hasNext() ? ibe.next().list.iterator() : null);
Literal l;
public boolean hasNext() {
- return il.hasNext();
+ return il != null && il.hasNext();
}
public Literal next() {
Modified: trunk/src/jason/jeditplugin/Config.java
===================================================================
--- trunk/src/jason/jeditplugin/Config.java 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/src/jason/jeditplugin/Config.java 2016-02-21 11:55:00 UTC (rev 1870)
@@ -251,6 +251,19 @@
return getProperty(KQML_PLANS_FILE, Message.kqmlDefaultPlans);
}
+ public void resetSomeProps() {
+ //System.out.println("Reseting configuration of "+Config.MOISE_JAR);
+ remove(Config.MOISE_JAR);
+ //System.out.println("Reseting configuration of "+Config.JASON_JAR);
+ remove(Config.JASON_JAR);
+ //System.out.println("Reseting configuration of "+Config.JADE_JAR);
+ remove(Config.JADE_JAR);
+ //System.out.println("Reseting configuration of "+Config.ANT_LIB);
+ remove(Config.ANT_LIB);
+ put(Config.SHOW_ANNOTS, "false");
+ }
+
+
/** Set most important parameters with default values */
public void fix() {
tryToFixJarFileConf(JASON_JAR, "jason.jar", 700000);
@@ -287,17 +300,20 @@
// fix ant lib
if (get(ANT_LIB) == null || !checkAntLib(getAntLib())) {
try {
- String antlib = new File(getJasonJar()).getParentFile().getParentFile().getAbsolutePath() + File.separator + "lib";
- if (checkAntLib(antlib)) {
- setAntLib(antlib);
- } else {
- antlib = new File(".") + File.separator + "lib";
+ String jjar = getJasonJar();
+ if (jjar != null) {
+ String antlib = new File(jjar).getParentFile().getParentFile().getAbsolutePath() + File.separator + "lib";
if (checkAntLib(antlib)) {
setAntLib(antlib);
} else {
- antlib = new File("..") + File.separator + "lib";
+ antlib = new File(".") + File.separator + "lib";
if (checkAntLib(antlib)) {
setAntLib(antlib);
+ } else {
+ antlib = new File("..") + File.separator + "lib";
+ if (checkAntLib(antlib)) {
+ setAntLib(antlib);
+ }
}
}
}
@@ -430,16 +446,22 @@
remove("infrastructure." + infraId);
}
+
+ public String getDistPropFile() {
+ return "/dist.properties";
+ }
+
public String getJasonRunningVersion() {
try {
Properties p = new Properties();
- p.load(Config.class.getResource("/dist.properties").openStream());
+ p.load(Config.class.getResource(getDistPropFile()).openStream());
return p.getProperty("version") + "." + p.getProperty("release");
} catch (Exception ex1) {
try {
Properties p = new Properties();
- System.out.println("try 2");
- p.load(new FileReader("bin/dist.properties"));
+ System.out.println("try 2 "+ex1);
+ ex1.printStackTrace();
+ p.load(new FileReader("bin"+getDistPropFile()));
return p.getProperty("version") + "." + p.getProperty("release");
} catch (Exception ex2) {
System.out.println("*"+ex2);
@@ -457,13 +479,22 @@
return "?";
}
}
+
void tryToFixJarFileConf(String jarEntry, String jarName, int minSize) {
String jarFile = getProperty(jarEntry);
if (jarFile == null || !checkJar(jarFile, minSize)) {
System.out.println("Wrong configuration for " + jarName + ", current is " + jarFile);
+ // try eclipse installation
+ jarFile = getJarFromEclipseInstallation(jarName);
+ if (checkJar(jarFile, minSize)) {
+ put(jarEntry, jarFile);
+ System.out.println("found at " + jarFile+" in eclipse installation");
+ return;
+ }
+
// try to get from classpath
- jarFile = getJavaHomePathFromClassPath(jarName);
+ jarFile = getJarFromClassPath(jarName);
if (checkJar(jarFile, minSize)) {
put(jarEntry, jarFile);
System.out.println("found at " + jarFile+" by classpath");
@@ -647,7 +678,7 @@
return System.getProperty("os.name").startsWith("Windows");
}
- static private String getJavaHomePathFromClassPath(String file) {
+ static private String getJarFromClassPath(String file) {
StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), File.pathSeparator);
while (st.hasMoreTokens()) {
String token = st.nextToken();
@@ -658,7 +689,21 @@
return null;
}
+ protected String getEclipseInstallationDirectory() {
+ return "jason";
+ }
+ private String getJarFromEclipseInstallation(String file) {
+ String eclipse = System.getProperty("eclipse.launcher");
+ //eclipse = "/Applications/eclipse/eclipse";
+ if (eclipse != null) {
+ File f = new File( (new File(eclipse)).getParentFile()+"/"+getEclipseInstallationDirectory()+"/lib/"+file);
+ if (f.exists())
+ return f.getAbsolutePath();
+ }
+ return null;
+ }
+
public String getTemplate(String templateName) {
try {
if (templateName.equals("agent.asl"))
Modified: trunk/src/test/TermTest.java
===================================================================
--- trunk/src/test/TermTest.java 2016-01-04 15:15:40 UTC (rev 1869)
+++ trunk/src/test/TermTest.java 2016-02-21 11:55:00 UTC (rev 1870)
@@ -827,7 +827,24 @@
}
}
}
-
+
+ public void testMakeVarAnnon7() {
+ Literal l1 = Literal.parseLiteral("likes(jane,ns::X,peter,nnn::X)");
+ Unifier u = new Unifier();
+ l1.makeVarsAnnon(u);
+ assertTrue(l1.toString().startsWith("likes(jane,ns::_"));
+ assertTrue(l1.toString().contains("nnn::_"));
+ assertEquals(1, u.size());
+ l1 = Literal.parseLiteral("likes(jane,NS::X,peter,NNN::X,NS::Y)");
+ u = new Unifier();
+ l1.makeVarsAnnon(u);
+ assertEquals(4, u.size());
+ l1 = Literal.parseLiteral("kk(Y,NS::X,peter)");
+ l1.makeVarsAnnon(u);
+ String s = "kk("+u.deref(new VarTerm("Y"))+","+u.deref(new VarTerm("NS"))+"::"+u.deref(new VarTerm("X"));
+ assertTrue(l1.toString().startsWith(s));
+ }
+
public void testAddAnnots() {
Literal p1 = Literal.parseLiteral("p1");
Literal p2 = Literal.parseLiteral("p2[a1,a2]");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-01-04 15:15:42
|
Revision: 1869
http://sourceforge.net/p/jason/svn/1869
Author: jomifred
Date: 2016-01-04 15:15:40 +0000 (Mon, 04 Jan 2016)
Log Message:
-----------
fix bug reported by Federico Xella
Modified Paths:
--------------
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/mas2j/AgentParameters.java
trunk/src/test/NSTest.java
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2015-12-24 09:26:31 UTC (rev 1868)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-01-04 15:15:40 UTC (rev 1869)
@@ -609,7 +609,8 @@
NS = new Atom(tns.image);
}
|
- NS = var(NS) { if (NS.hasAnnot())
+ NS = var(Literal.DefaultNS)
+ { if (NS.hasAnnot())
throw new ParseException(getSourceRef(NS)+" name space cannot have annotations.");
}
)
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2015-12-24 09:26:31 UTC (rev 1868)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-01-04 15:15:40 UTC (rev 1869)
@@ -909,7 +909,7 @@
break;
case VAR:
case UNNAMEDVAR:
- NS = var(NS);
+ NS = var(Literal.DefaultNS);
if (NS.hasAnnot())
{if (true) throw new ParseException(getSourceRef(NS)+" name space cannot have annotations.");}
break;
@@ -1644,13 +1644,13 @@
return false;
}
- final private boolean jj_3R_115() {
- if (jj_3R_122()) return true;
+ final private boolean jj_3R_61() {
+ if (jj_3R_66()) return true;
return false;
}
- final private boolean jj_3R_61() {
- if (jj_3R_66()) return true;
+ final private boolean jj_3R_115() {
+ if (jj_3R_122()) return true;
return false;
}
@@ -1712,6 +1712,12 @@
return false;
}
+ final private boolean jj_3R_53() {
+ if (jj_scan_token(52)) return true;
+ if (jj_3R_38()) return true;
+ return false;
+ }
+
final private boolean jj_3R_47() {
if (jj_scan_token(34)) return true;
return false;
@@ -1722,9 +1728,11 @@
return false;
}
- final private boolean jj_3R_53() {
- if (jj_scan_token(52)) return true;
- if (jj_3R_38()) return true;
+ final private boolean jj_3R_38() {
+ if (jj_3R_52()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_53()) jj_scanpos = xsp;
return false;
}
@@ -1733,14 +1741,6 @@
return false;
}
- final private boolean jj_3R_38() {
- if (jj_3R_52()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_53()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_32() {
Token xsp;
xsp = jj_scanpos;
@@ -1794,6 +1794,14 @@
return false;
}
+ final private boolean jj_3R_20() {
+ if (jj_3R_38()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_39()) jj_scanpos = xsp;
+ return false;
+ }
+
final private boolean jj_3_2() {
Token xsp;
xsp = jj_scanpos;
@@ -1806,14 +1814,6 @@
return false;
}
- final private boolean jj_3R_20() {
- if (jj_3R_38()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_39()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_16() {
Token xsp;
xsp = jj_scanpos;
@@ -1899,13 +1899,13 @@
return false;
}
- final private boolean jj_3R_59() {
- if (jj_scan_token(TK_LABEL_AT)) return true;
+ final private boolean jj_3R_56() {
+ if (jj_3R_42()) return true;
return false;
}
- final private boolean jj_3R_56() {
- if (jj_3R_42()) return true;
+ final private boolean jj_3R_59() {
+ if (jj_scan_token(TK_LABEL_AT)) return true;
return false;
}
@@ -2008,18 +2008,13 @@
return false;
}
- final private boolean jj_3R_45() {
- if (jj_scan_token(34)) return true;
- return false;
- }
-
final private boolean jj_3R_120() {
if (jj_3R_19()) return true;
return false;
}
- final private boolean jj_3R_128() {
- if (jj_3R_20()) return true;
+ final private boolean jj_3R_45() {
+ if (jj_scan_token(34)) return true;
return false;
}
@@ -2029,11 +2024,23 @@
return false;
}
+ final private boolean jj_3R_128() {
+ if (jj_3R_20()) return true;
+ return false;
+ }
+
final private boolean jj_3R_113() {
if (jj_3R_120()) return true;
return false;
}
+ final private boolean jj_3R_112() {
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(43)) return true;
+ return false;
+ }
+
final private boolean jj_3R_136() {
if (jj_scan_token(37)) return true;
return false;
@@ -2044,13 +2051,6 @@
return false;
}
- final private boolean jj_3R_112() {
- if (jj_scan_token(42)) return true;
- if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
- return false;
- }
-
final private boolean jj_3R_41() {
if (jj_3R_57()) return true;
Token xsp;
@@ -2137,6 +2137,18 @@
return false;
}
+ final private boolean jj_3R_109() {
+ if (jj_scan_token(NUMBER)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_23() {
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_41()) return true;
+ if (jj_scan_token(43)) return true;
+ return false;
+ }
+
final private boolean jj_3R_130() {
if (jj_scan_token(34)) return true;
return false;
@@ -2161,18 +2173,6 @@
return false;
}
- final private boolean jj_3R_109() {
- if (jj_scan_token(NUMBER)) return true;
- return false;
- }
-
- final private boolean jj_3R_23() {
- if (jj_scan_token(42)) return true;
- if (jj_3R_41()) return true;
- if (jj_scan_token(43)) return true;
- return false;
- }
-
final private boolean jj_3R_102() {
Token xsp;
xsp = jj_scanpos;
@@ -2252,13 +2252,13 @@
return false;
}
- final private boolean jj_3R_43() {
- if (jj_scan_token(30)) return true;
+ final private boolean jj_3R_107() {
+ if (jj_scan_token(TK_INTMOD)) return true;
return false;
}
- final private boolean jj_3R_107() {
- if (jj_scan_token(TK_INTMOD)) return true;
+ final private boolean jj_3R_43() {
+ if (jj_scan_token(30)) return true;
return false;
}
@@ -2348,11 +2348,6 @@
return false;
}
- final private boolean jj_3R_22() {
- if (jj_3R_40()) return true;
- return false;
- }
-
final private boolean jj_3R_96() {
Token xsp;
xsp = jj_scanpos;
@@ -2364,6 +2359,11 @@
return false;
}
+ final private boolean jj_3R_22() {
+ if (jj_3R_40()) return true;
+ return false;
+ }
+
final private boolean jj_3R_77() {
if (jj_3R_95()) return true;
Token xsp;
@@ -2395,6 +2395,11 @@
return false;
}
+ final private boolean jj_3R_90() {
+ if (jj_3R_42()) return true;
+ return false;
+ }
+
final private boolean jj_3R_35() {
Token xsp;
xsp = jj_scanpos;
@@ -2409,13 +2414,13 @@
return false;
}
- final private boolean jj_3R_90() {
- if (jj_3R_42()) return true;
+ final private boolean jj_3R_89() {
+ if (jj_3R_78()) return true;
return false;
}
- final private boolean jj_3R_89() {
- if (jj_3R_78()) return true;
+ final private boolean jj_3R_88() {
+ if (jj_3R_77()) return true;
return false;
}
@@ -2432,11 +2437,6 @@
return false;
}
- final private boolean jj_3R_88() {
- if (jj_3R_77()) return true;
- return false;
- }
-
final private boolean jj_3R_129() {
if (jj_scan_token(TK_ELSE)) return true;
return false;
@@ -2447,6 +2447,11 @@
return false;
}
+ final private boolean jj_3R_86() {
+ if (jj_scan_token(57)) return true;
+ return false;
+ }
+
final private boolean jj_3R_125() {
Token xsp;
xsp = jj_scanpos;
@@ -2455,13 +2460,13 @@
return false;
}
- final private boolean jj_3R_86() {
- if (jj_scan_token(57)) return true;
+ final private boolean jj_3R_85() {
+ if (jj_scan_token(56)) return true;
return false;
}
- final private boolean jj_3R_85() {
- if (jj_scan_token(56)) return true;
+ final private boolean jj_3R_84() {
+ if (jj_scan_token(55)) return true;
return false;
}
@@ -2470,11 +2475,6 @@
return false;
}
- final private boolean jj_3R_84() {
- if (jj_scan_token(55)) return true;
- return false;
- }
-
final private boolean jj_3R_83() {
if (jj_scan_token(54)) return true;
return false;
@@ -2551,13 +2551,13 @@
return false;
}
- final private boolean jj_3R_26() {
- if (jj_3R_44()) return true;
+ final private boolean jj_3R_73() {
+ if (jj_3R_78()) return true;
return false;
}
- final private boolean jj_3R_73() {
- if (jj_3R_78()) return true;
+ final private boolean jj_3R_26() {
+ if (jj_3R_44()) return true;
return false;
}
@@ -2571,6 +2571,18 @@
return false;
}
+ final private boolean jj_3R_66() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_72()) {
+ jj_scanpos = xsp;
+ if (jj_3R_73()) return true;
+ }
+ xsp = jj_scanpos;
+ if (jj_3R_74()) jj_scanpos = xsp;
+ return false;
+ }
+
final private boolean jj_3R_14() {
Token xsp;
while (true) {
@@ -2593,18 +2605,6 @@
return false;
}
- final private boolean jj_3R_66() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_72()) {
- jj_scanpos = xsp;
- if (jj_3R_73()) return true;
- }
- xsp = jj_scanpos;
- if (jj_3R_74()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_119() {
if (jj_3R_108()) return true;
return false;
Modified: trunk/src/jason/mas2j/AgentParameters.java
===================================================================
--- trunk/src/jason/mas2j/AgentParameters.java 2015-12-24 09:26:31 UTC (rev 1868)
+++ trunk/src/jason/mas2j/AgentParameters.java 2016-01-04 15:15:40 UTC (rev 1869)
@@ -105,22 +105,31 @@
public void setAgClass(String c) {
- if (c != null) agClass = new ClassParameters(c);
+ if (c != null)
+ agClass = new ClassParameters(c);
}
public void addArchClass(String... cs) {
+ if (cs == null)
+ return;
for (String c: cs)
archClasses.add(new ClassParameters(c));
}
public void addArchClass(Collection<String> cs) {
+ if (cs == null)
+ return;
for (String c: cs)
archClasses.add(new ClassParameters(c));
}
public void addArchClass(ClassParameters... cps) {
+ if (cps == null)
+ return;
for (ClassParameters c: cps)
archClasses.add(c);
}
public void insertArchClass(ClassParameters... cps) {
+ if (cps == null)
+ return;
for (ClassParameters c: cps)
archClasses.add(0,c);
}
Modified: trunk/src/test/NSTest.java
===================================================================
--- trunk/src/test/NSTest.java 2015-12-24 09:26:31 UTC (rev 1868)
+++ trunk/src/test/NSTest.java 2016-01-04 15:15:40 UTC (rev 1869)
@@ -205,7 +205,7 @@
assertEquals(p1.compareTo(p1), 0);
}
- public void testParserNS() throws ParseException, JasonException {
+ public void testParserNS1() throws ParseException, JasonException {
as2j parser = new as2j(new StringReader("b(10). b(20). b(tell). ns71::b(30). default::b(40). !g(ok). +!g(X) <- .print(kk, 10, X). "));
parser.setNS(new Atom("ns33"));
@@ -233,4 +233,13 @@
}
+ public void testParserNS2() throws ParseException, JasonException {
+
+ as2j parser = new as2j(new StringReader("+NS::tick <- .print(NS). "));
+ parser.setNS(new Atom("ns33"));
+ Agent a = new Agent();
+ a.initAg();
+ parser.agent(a);
+ assertTrue(a.getPL().toString().contains("[source(self)] +NS::tick <- .print(ns33::NS)."));
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2015-12-24 09:26:33
|
Revision: 1868
http://sourceforge.net/p/jason/svn/1868
Author: jomifred
Date: 2015-12-24 09:26:31 +0000 (Thu, 24 Dec 2015)
Log Message:
-----------
fix: wait with formula parameter does not wait if the ag already believes in the formula
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/BugIfGoalReturn.java
trunk/build.xml
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSyntax/UnnamedVar.java
trunk/src/jason/stdlib/wait.java
Modified: trunk/applications/as-unit-test/src/jason/tests/BugIfGoalReturn.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/BugIfGoalReturn.java 2015-12-11 13:05:52 UTC (rev 1867)
+++ trunk/applications/as-unit-test/src/jason/tests/BugIfGoalReturn.java 2015-12-24 09:26:31 UTC (rev 1868)
@@ -48,6 +48,7 @@
);
}
+ @SuppressWarnings("deprecation")
@Test(timeout=2000)
public void testRule() {
ag.addGoal("start");
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2015-12-11 13:05:52 UTC (rev 1867)
+++ trunk/build.xml 2015-12-24 09:26:31 UTC (rev 1868)
@@ -12,8 +12,8 @@
<property name="build.dir" value="${basedir}/bin/classes" />
<property name="dist.properties" value="${basedir}/bin/dist.properties" />
- <property name="version" value="1" />
- <property name="release" value="2.beta" />
+ <property name="version" value="2" />
+ <property name="release" value="0.beta" />
<property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" />
<property name="distFile" value="${env.HOME}/Jason-${version}.${release}" />
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2015-12-11 13:05:52 UTC (rev 1867)
+++ trunk/src/jason/asSemantics/Agent.java 2015-12-24 09:26:31 UTC (rev 1868)
@@ -717,7 +717,21 @@
* @return the number of changes (add + dels)
*/
public int buf(List<Literal> percepts) {
+
+ /*
// complexity 3n
+
+ HashSet percepts = clone from the list of current environment percepts // 1n
+
+ for b in BBPercept (the set of perceptions already in BB) // 1n
+ if b not in percepts // constant time test
+ remove b in BBPercept // constant time
+ remove b in percept
+
+ for p still in percepts // 1n
+ add p in BBPercepts
+ */
+
if (percepts == null) {
return 0;
}
@@ -752,7 +766,8 @@
}
}
}
- /*
+
+ /*
////// previous version, without perW hashset
// could not use percepts.contains(l), since equalsAsTerm must be
// used (to ignore annotations)
@@ -787,7 +802,7 @@
}
*/
/*
- // old version
+ // even older version
// can not delete l, but l[source(percept)]
l = (Literal)l.clone();
l.clearAnnots();
@@ -819,61 +834,7 @@
return adds + dels;
}
- public int bufAlternative(List<Literal> percepts) {
- // complexity 4n
-
- if (percepts == null) {
- return 0;
- }
-
- // stat
- int adds = 0;
- int dels = 0;
- //Set<Literal> pinBB = ((DefaultBeliefBase)getBB()).getPerceptsSet();
- Set<StructureWrapperForLiteral> pinBBW = new HashSet<StructureWrapperForLiteral>();
- Iterator<Literal> ibb = getBB().getPercepts();
- while (ibb.hasNext())
- pinBBW.add(new StructureWrapperForLiteral( ibb.next()));
-
- Iterator<Literal> ip = percepts.iterator();
- while (ip.hasNext()) {
- Literal t = ip.next();
- StructureWrapperForLiteral lrt = new StructureWrapperForLiteral(t);
- if ( pinBBW.remove(lrt) ) {
- // since this percept in in BB, do not need to be added neither removed
- ip.remove();
- }
- }
-
- // percepts that are not in BB
- for (Literal lp : percepts) {
- try {
- lp = lp.copy().forceFullLiteralImpl();
- lp.addAnnot(BeliefBase.TPercept);
- if (getBB().add(lp)) {
- adds++;
- ts.updateEvents(new Event(new Trigger(TEOperator.add, TEType.belief, lp), Intention.EmptyInt));
- }
- } catch (Exception e) {
- logger.log(Level.SEVERE, "Error adding percetion " + lp, e);
- }
- }
-
- // remove what was not perceived
- for (StructureWrapperForLiteral lw: pinBBW) {
- Literal l = lw.getLiteral();
- l = ASSyntax.createLiteral(l.getFunctor(), l.getTermsArray());
- l.addAnnot(BeliefBase.TPercept);
- if (bb.remove(l)) {
- dels++;
- ts.updateEvents(new Event(new Trigger(TEOperator.del, TEType.belief, l), Intention.EmptyInt));
- }
- }
- return adds + dels;
- }
-
-
/*
public QueryCacheSimple getQueryCache() {
return qCache;
Modified: trunk/src/jason/asSyntax/UnnamedVar.java
===================================================================
--- trunk/src/jason/asSyntax/UnnamedVar.java 2015-12-11 13:05:52 UTC (rev 1867)
+++ trunk/src/jason/asSyntax/UnnamedVar.java 2015-12-24 09:26:31 UTC (rev 1868)
@@ -78,12 +78,7 @@
}
public Term clone() {
- UnnamedVar newv = new UnnamedVar(getNS(), getFunctor());
- newv.myId = this.myId;
- newv.hashCodeCache = this.hashCodeCache;
- if (hasAnnot())
- newv.addAnnots(this.getAnnots().cloneLT());
- return newv;
+ return cloneNS(getNS());
}
@Override
Modified: trunk/src/jason/stdlib/wait.java
===================================================================
--- trunk/src/jason/stdlib/wait.java 2015-12-11 13:05:52 UTC (rev 1867)
+++ trunk/src/jason/stdlib/wait.java 2015-12-24 09:26:31 UTC (rev 1868)
@@ -113,6 +113,8 @@
te = Trigger.tryToGetTrigger(args[0]); // wait for event
if (te == null && args[0] instanceof LogicalFormula) { // wait for an expression to become true
f = (LogicalFormula)args[0];
+ if (ts.getAg().believes(f, un))
+ return true;
}
if (args.length >= 2)
timeout = (long) ((NumberTerm) args[1]).solve();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2015-12-11 13:05:54
|
Revision: 1867
http://sourceforge.net/p/jason/svn/1867
Author: jomifred
Date: 2015-12-11 13:05:52 +0000 (Fri, 11 Dec 2015)
Log Message:
-----------
revise unifier for namespaces/negated vars
Modified Paths:
--------------
trunk/build.xml
trunk/doc/index.html
trunk/src/jason/asSemantics/Unifier.java
trunk/src/jason/asSyntax/ASSyntax.java
trunk/src/jason/asSyntax/Literal.java
trunk/src/jason/asSyntax/LiteralImpl.java
trunk/src/jason/asSyntax/Pred.java
trunk/src/jason/asSyntax/Structure.java
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/jason/bb/ChainBB.java
trunk/src/jason/bb/DefaultBeliefBase.java
trunk/src/jason/stdlib/package.html
trunk/src/test/ASParserTest.java
trunk/src/test/BeliefBaseTest.java
trunk/src/test/NSTest.java
trunk/src/test/VarTermTest.java
Added Paths:
-----------
trunk/src/jason/bb/StructureWrapperForLiteral.java
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/build.xml 2015-12-11 13:05:52 UTC (rev 1867)
@@ -13,7 +13,7 @@
<property name="dist.properties" value="${basedir}/bin/dist.properties" />
<property name="version" value="1" />
- <property name="release" value="4.2" />
+ <property name="release" value="2.beta" />
<property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" />
<property name="distFile" value="${env.HOME}/Jason-${version}.${release}" />
Modified: trunk/doc/index.html
===================================================================
--- trunk/doc/index.html 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/doc/index.html 2015-12-11 13:05:52 UTC (rev 1867)
@@ -17,7 +17,7 @@
<li><a href="faq.html">FAQ</a> (html)</li><br/>
-<li><a href="api/jason/stdlib/package-summary.html#package_description">Stantard internal actions</a> (html)</li>
+<li><a href="api/jason/stdlib/package-summary.html#package.description">Stantard internal actions</a> (html)</li>
<li><a href="api/jason/functions/package-summary.html">Stantard arithmetic functions</a> (html)</li>
<li>API of all classes: generated by <a href="api/index.html">JavaDoc</a>.</li><br>
Modified: trunk/src/jason/asSemantics/Unifier.java
===================================================================
--- trunk/src/jason/asSemantics/Unifier.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/asSemantics/Unifier.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -76,6 +76,7 @@
if (vl != null && vl.isVar()) { // optimised deref
return get((VarTerm)vl);
}
+ /* vars in unifier are not negated anymore! (works like namespace)
if (vl == null) { // try negated value of the var
//System.out.println("for "+vtp+" try "+new VarTerm(vtp.negated(), vtp.getFunctor())+" in "+this);
vl = function.get( new VarTerm(vtp.negated(), vtp.getFunctor()) );
@@ -88,6 +89,7 @@
((Literal)vl).setNegated(((Literal)vl).negated());
}
}
+ */
return vl;
}
@@ -209,11 +211,6 @@
}
}
- /*if (t1g.isCyclicTerm())
- remove(t1g.getCyclicVar());
- if (t2g.isCyclicTerm())
- remove(t2g.getCyclicVar());
- */
return ok;
}
@@ -229,22 +226,18 @@
final boolean t1gisvar = t1g.isVar();
final boolean t2gisvar = t2g.isVar();
-
+
// one of the args is a var
if (t1gisvar || t2gisvar) {
+ final VarTerm t1gv = t1gisvar ? (VarTerm)t1g : null;
+ final VarTerm t2gv = t2gisvar ? (VarTerm)t2g : null;
- // deref vars
- final VarTerm t1gv = t1gisvar ? deref((VarTerm)t1g) : null;
- final VarTerm t2gv = t2gisvar ? deref((VarTerm)t2g) : null;
-
// get their values
- //final Term t1vl = t1gisvar ? function.get(t1gv) : t1g;
- //final Term t2vl = t2gisvar ? function.get(t2gv) : t2g;
final Term t1vl = t1gisvar ? get(t1gv) : t1g;
final Term t2vl = t2gisvar ? get(t2gv) : t2g;
-
+
if (t1vl != null && t2vl != null) { // unifies the two values of the vars
- return unifiesNoUndo(t1vl, t2vl);
+ return unifiesNoUndo(t1vl, t2vl);
} else if (t1vl != null) { // unifies var with value
return bind(t2gv, t1vl);
} else if (t2vl != null) {
@@ -329,35 +322,32 @@
if (! vt1.getNS().equals(vt2.getNS()))
return false;
- if (vt1.negated() && vt2.negated()) { // in the case of ~A = ~B, put A=B in the unifier
- vt1 = new VarTerm(vt1.getFunctor());
- vt2 = new VarTerm(vt2.getFunctor());
+ if (vt1.negated() != vt2.negated()) {
+ return false;
}
+
+ vt1 = getVarForUnifier(vt1);
+ vt2 = getVarForUnifier(vt2);
final int comp = vt1.compareTo(vt2);
+ //System.out.println(vt1+"="+vt2+" ==> "+getVarForUnifier(vt1) +"="+ getVarForUnifier(vt2)+" in "+this+" cmp="+comp);
if (comp < 0) {
- function.put((VarTerm)vt1.clone(), vt2.clone());
+ function.put(vt1, vt2);
} else if (comp > 0){
- function.put((VarTerm)vt2.clone(), vt1.clone());
+ function.put(vt2, vt1);
} // if they are the same (comp == 0), do not bind
return true;
}
public boolean bind(VarTerm vt, Term vl) {
if (vt.negated()) { // negated vars unifies only with negated literals
- if (vl.isLiteral()) {
- if (!((Literal)vl).negated()) {
- return false;
- } else {
- // put also the positive case in the unifier
- Literal vlp = (Literal)vl.clone();
- vlp.setNegated(Literal.LPos);
- unifies(new VarTerm(vt.getFunctor()), vlp);
- }
- } else {
+ if (!vl.isLiteral() || !((Literal)vl).negated()) {
return false;
- }
+ }
+ vl = (Literal)vl.clone();
+ ((Literal)vl).setNegated(Literal.LPos);
}
+ // namespace
if (vl.isLiteral()) {
Literal lvl = (Literal)vl;
if (! unifiesNamespace(vt, lvl) )
@@ -370,9 +360,15 @@
vl = new CyclicTerm((Literal)vl, (VarTerm)vt.clone());
}
- function.put((VarTerm) vt.cloneNS(Literal.DefaultNS), vl);
+ function.put(getVarForUnifier(vt), vl);
return true;
}
+
+ private VarTerm getVarForUnifier(VarTerm v) {
+ v = (VarTerm)deref(v).cloneNS(Literal.DefaultNS);
+ v.setNegated(Literal.LPos);
+ return v;
+ }
public void clear() {
function.clear();
Modified: trunk/src/jason/asSyntax/ASSyntax.java
===================================================================
--- trunk/src/jason/asSyntax/ASSyntax.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/asSyntax/ASSyntax.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -66,6 +66,8 @@
static {
keywords.add(new PredicateIndicator("atomic", 0));
+ keywords.add(new PredicateIndicator("breakpoint", 0));
+ keywords.add(new PredicateIndicator("all_unifs", 0));
keywords.add(new PredicateIndicator("default", 0));
keywords.add(new PredicateIndicator("source", 0));
@@ -76,15 +78,15 @@
keywords.add(new PredicateIndicator("untell", 0));
keywords.add(new PredicateIndicator("achieve", 0));
keywords.add(new PredicateIndicator("unachieve", 0));
- keywords.add(new PredicateIndicator("ask", 0));
keywords.add(new PredicateIndicator("askOne", 0));
keywords.add(new PredicateIndicator("askAll", 0));
keywords.add(new PredicateIndicator("askHow", 0));
keywords.add(new PredicateIndicator("tellHow", 0));
+ keywords.add(new PredicateIndicator("untellHow", 0));
}
- public void addKeyword(PredicateIndicator pi) {
+ public static void addKeyword(PredicateIndicator pi) {
keywords.add(pi);
}
@@ -149,6 +151,13 @@
return new VarTerm(functor);
}
+ /** creates a new variable term (possibly negated) */
+ public static VarTerm createVar(boolean negated, String functor) {
+ VarTerm v = new VarTerm(functor);
+ v.setNegated(negated);
+ return v;
+ }
+
/** creates a new anonymous (or unnamed) variable */
public static VarTerm createVar() {
return new UnnamedVar();
Modified: trunk/src/jason/asSyntax/Literal.java
===================================================================
--- trunk/src/jason/asSyntax/Literal.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/asSyntax/Literal.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -124,7 +124,12 @@
/** returns all terms of this literal */
public List<Term> getTerms() { return Structure.emptyTermList; }
/** returns all terms of this literal as an array */
- public Term[] getTermsArray() { return getTerms().toArray(Structure.emptyTermArray); }
+ public Term[] getTermsArray() {
+ if (hasTerm())
+ return getTerms().toArray(Structure.emptyTermArray);
+ else
+ return Structure.emptyTermArray;
+ }
private static final List<VarTerm> emptyListVar = new ArrayList<VarTerm>();
/** returns all singleton vars (that appears once) in this literal */
@@ -507,7 +512,7 @@
tfunctor = ASSyntax.parseTerm( ((StringTerm)tfunctor).getString() );
}
- Literal l = new LiteralImpl(ns, pos,((Atom)tfunctor).getFunctor(),5);
+ Literal l = new LiteralImpl(ns, pos,((Atom)tfunctor).getFunctor());
if (i.hasNext()) {
l.setTerms(((ListTerm)i.next()).cloneLT());
Modified: trunk/src/jason/asSyntax/LiteralImpl.java
===================================================================
--- trunk/src/jason/asSyntax/LiteralImpl.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/asSyntax/LiteralImpl.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -50,12 +50,6 @@
type = pos;
}
- /** if pos == true, the literal is positive, otherwise it is negative */
- public LiteralImpl(Atom namespace, boolean pos, String functor, int nbTerms) {
- super(namespace, functor, nbTerms);
- type = pos;
- }
-
public LiteralImpl(Literal l) {
super(l);
type = !l.negated();
@@ -74,16 +68,18 @@
type = pos;
}
+ /** if pos == true, the literal is positive, otherwise it is negative */
+ public LiteralImpl(Atom namespace, boolean pos, String functor) {
+ super(namespace, functor);
+ type = pos;
+ }
+
/** creates a literal based on another but in another name space and signal */
public LiteralImpl(Atom namespace, boolean pos, Literal l) {
super(namespace, l);
type = pos;
}
- protected LiteralImpl(String functor, int terms) {
- super(functor, terms);
- }
-
@Override
public boolean isAtom() {
return super.isAtom() && !negated();
Modified: trunk/src/jason/asSyntax/Pred.java
===================================================================
--- trunk/src/jason/asSyntax/Pred.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/asSyntax/Pred.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -50,14 +50,14 @@
super(functor);
}
- public Pred(Atom namespace, String functor, int nbTerms) {
- super(namespace, functor, nbTerms);
- }
-
public Pred(Literal l) {
this(l.getNS(), l);
}
+ public Pred(Atom namespace, String functor) {
+ super(namespace, functor);
+ }
+
public Pred(Atom namespace, Literal l) {
super(namespace, l);
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/asSyntax/Structure.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -59,28 +59,27 @@
public Structure(String functor) {
//this.functor = (functor == null ? null : functor.intern()); // it does not improve performance in test i did!
- super(functor);
- this.terms = new ArrayList<Term>(5);
+ this(DefaultNS, functor);
}
- public Structure(Atom namespace, String functor, int nbTerms) {
- //this.functor = (functor == null ? null : functor.intern()); // it does not improve performance in test i did!
- super(namespace, functor);
- if (nbTerms > 0)
- this.terms = new ArrayList<Term>(5);
- }
-
-
public Structure(Literal l) {
this(l.getNS(), l);
}
+
+ public Structure(Atom namespace, String functor) {
+ //this.functor = (functor == null ? null : functor.intern()); // it does not improve performance in test i did!
+ super(namespace, functor);
+ }
+
public Structure(Atom namespace, Literal l) {
super(namespace, l);
final int tss = l.getArity();
- terms = new ArrayList<Term>(tss);
- for (int i = 0; i < tss; i++)
- terms.add(l.getTerm(i).clone());
+ if (tss > 0) {
+ terms = new ArrayList<Term>(tss);
+ for (int i = 0; i < tss; i++)
+ terms.add(l.getTerm(i).clone());
+ }
//isGround = null;
}
@@ -88,9 +87,11 @@
protected Structure(Literal l, Unifier u) {
super(l, u);
final int tss = l.getArity();
- terms = new ArrayList<Term>(tss);
- for (int i = 0; i < tss; i++)
- terms.add(l.getTerm(i).capply(u));
+ if (tss > 0) {
+ terms = new ArrayList<Term>(tss);
+ for (int i = 0; i < tss; i++)
+ terms.add(l.getTerm(i).capply(u));
+ }
resetHashCodeCache();
//isGround = null;
}
@@ -217,6 +218,7 @@
@Override
public void addTerm(Term t) {
if (t == null) return;
+ if (terms == null) terms = new ArrayList<Term>(5);
terms.add(t);
//if (!t.isGround())
// isGround = false;
@@ -226,6 +228,7 @@
@Override
public void delTerm(int index) {
+ if (terms == null) return;
terms.remove(index);
predicateIndicatorCache = null;
resetHashCodeCache();
@@ -234,8 +237,8 @@
@Override
public Literal addTerms(Term ... ts ) {
+ if (terms == null) terms = new ArrayList<Term>(5);
for (Term t: ts)
- //addTerm(t);
terms.add(t);
predicateIndicatorCache = null;
resetHashCodeCache();
@@ -244,8 +247,8 @@
@Override
public Literal addTerms(List<Term> l) {
+ if (terms == null) terms = new ArrayList<Term>(5);
for (Term t: l)
- //addTerm(t);
terms.add(t);
predicateIndicatorCache = null;
resetHashCodeCache();
@@ -263,6 +266,7 @@
@Override
public void setTerm(int i, Term t) {
+ if (terms == null) terms = new ArrayList<Term>(5);
terms.set(i,t);
resetHashCodeCache();
//if (!t.isGround() && isGround())
@@ -270,7 +274,10 @@
}
public Term getTerm(int i) {
- return terms.get(i);
+ if (terms == null)
+ return null;
+ else
+ return terms.get(i);
}
@Override
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/asSyntax/VarTerm.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -66,12 +66,9 @@
e.printStackTrace();
}
}
- public VarTerm(boolean negated, String functor) {
- super(negated, functor);
- }
public VarTerm(Atom namespace, String functor) {
- super(namespace, LPos, functor, 0);
+ super(namespace, LPos, functor);
}
public VarTerm(Atom namespace, Literal v) {
@@ -90,14 +87,6 @@
}
@Override
- protected int calcHashCode() {
- int result = getFunctor().hashCode();
- if (negated()) result += 3271;
- // Do not consider NS!
- return result;
- }
-
- @Override
public Term capply(Unifier u) {
if (u != null) {
Term vl = u.get(this);
@@ -119,10 +108,17 @@
vl = vl.capply(u); // should clone here, since there is no cloning in unify
- if (getNS() != Literal.DefaultNS && vl.isLiteral()) {
- // use var ns for the value ns
- vl = ((Literal)vl).cloneNS( (Atom)getNS().capply(u) ); // this var ns could be a var, so capply
+ if (vl.isLiteral()) {
+ if (getNS() != Literal.DefaultNS) {
+ // TODO: change capply to has the new namespace as parameter and them remove this code
+ // use var ns for the value ns
+ vl = ((Literal)vl).cloneNS( (Atom)getNS().capply(u) ); // this var ns could be a var, so capply
+ }
+ if (negated()) {
+ ((Literal)vl).setNegated(Literal.LNeg);
+ }
}
+
// decide whether to use var annots in apply
// X = p[a]
@@ -143,15 +139,7 @@
}
public Term clone() {
- // do not call constructor with term parameter!
- //VarTerm t = new VarTerm(super.getFunctor());
- //t.setNegated(!negated());
- VarTerm t = new VarTerm(this.getNS(), this);
- //t.srcInfo = this.srcInfo;
- //t.hashCodeCache = this.hashCodeCache;
- //if (hasAnnot())
- // t.setAnnots(getAnnots().cloneLT());
- return t;
+ return new VarTerm(this.getNS(), this);
}
@Override
@@ -177,6 +165,10 @@
return false;
}
+ // DO NOT consider ns in equals and hashcode!
+ // idem for negated
+ // in the unifier, the vars have no ns neither negation
+
@Override
public boolean equals(Object t) {
if (t == null) return false;
@@ -184,19 +176,28 @@
// is t also a var? (its value must also be null)
if (t instanceof VarTerm) {
final VarTerm tAsVT = (VarTerm) t;
- // DO NOT consider ns in equals of hashcode!
- return negated() == tAsVT.negated() && getFunctor().equals(tAsVT.getFunctor()); // && getNS().equals(tAsVT.getNS());
+ return //negated() == tAsVT.negated() &&
+ getFunctor().equals(tAsVT.getFunctor()); // && getNS().equals(tAsVT.getNS());
}
return false;
}
+
+ @Override
+ protected int calcHashCode() {
+ int result = getFunctor().hashCode();
+ //if (negated()) result += 3271; // TODO: review
+ // Do not consider NS and negated! (in unifier, A = ~A)
+ return result;
+ }
+
public int compareTo(Term t) {
if (t == null || t.isUnnamedVar())
return -1;
else if (t.isVar()) {
- if (!negated() && ((VarTerm)t).negated())
- return -1;
- else
+ //if (!negated() && ((VarTerm)t).negated())
+ // return -1;
+ //else
return getFunctor().compareTo(((VarTerm)t).getFunctor());
} else {
return 1;
Modified: trunk/src/jason/bb/ChainBB.java
===================================================================
--- trunk/src/jason/bb/ChainBB.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/bb/ChainBB.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -52,8 +52,10 @@
Structure bbs = Structure.parse(s);
String[] bbargs = new String[bbs.getArity()];
int i = 0;
- for (Term t: bbs.getTerms()) {
- bbargs[i++] = t.isString() ? ((StringTerm)t).getString(): t.toString();
+ if (bbs.hasTerm()) {
+ for (Term t: bbs.getTerms()) {
+ bbargs[i++] = t.isString() ? ((StringTerm)t).getString(): t.toString();
+ }
}
bb.init(ag, bbargs);
bb = bb.getNextAdapter();
Modified: trunk/src/jason/bb/DefaultBeliefBase.java
===================================================================
--- trunk/src/jason/bb/DefaultBeliefBase.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/bb/DefaultBeliefBase.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -372,10 +372,10 @@
final class BelEntry {
final private Deque<Literal> list = new LinkedBlockingDeque<Literal>(); // maintains the order of the beliefs
- final private Map<LiteralWrapper,Literal> map = new ConcurrentHashMap<LiteralWrapper,Literal>(); // to find content faster
+ final private Map<StructureWrapperForLiteral,Literal> map = new ConcurrentHashMap<StructureWrapperForLiteral,Literal>(); // to find content faster
public void add(Literal l, boolean addInEnd) {
- map.put(new LiteralWrapper(l), l);
+ map.put(new StructureWrapperForLiteral(l), l);
if (addInEnd) {
list.addLast(l);
} else {
@@ -384,7 +384,7 @@
}
public void remove(Literal l) {
- Literal linmap = map.remove(new LiteralWrapper(l));
+ Literal linmap = map.remove(new StructureWrapperForLiteral(l));
if (linmap != null) {
list.remove(linmap);
}
@@ -399,7 +399,7 @@
}
public Literal contains(Literal l) {
- return map.get(new LiteralWrapper(l));
+ return map.get(new StructureWrapperForLiteral(l));
}
protected Object clone() {
@@ -416,16 +416,6 @@
s.append(l+":"+l.hashCode()+",");
}
return s.toString();
- }
-
- /** a literal that uses equalsAsTerm for equals */
- final class LiteralWrapper implements Comparable<LiteralWrapper> {
- final private Literal l;
- public LiteralWrapper(Literal l) { this.l = l; }
- public int hashCode() { return l.hashCode(); }
- public boolean equals(Object o) { return o instanceof LiteralWrapper && l.equalsAsStructure(((LiteralWrapper)o).l); }
- public String toString() { return l.toString(); }
- public int compareTo(LiteralWrapper o) { return l.compareTo(o.l); }
- }
+ }
}
}
Added: trunk/src/jason/bb/StructureWrapperForLiteral.java
===================================================================
--- trunk/src/jason/bb/StructureWrapperForLiteral.java (rev 0)
+++ trunk/src/jason/bb/StructureWrapperForLiteral.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -0,0 +1,14 @@
+package jason.bb;
+
+import jason.asSyntax.Literal;
+
+/** a literal that uses equalsAsTerm for equals */
+public final class StructureWrapperForLiteral implements Comparable<StructureWrapperForLiteral> {
+ final private Literal l;
+ public StructureWrapperForLiteral(Literal l) { this.l = l; }
+ public int hashCode() { return l.hashCode(); }
+ public boolean equals(Object o) { return o instanceof StructureWrapperForLiteral && l.equalsAsStructure(((StructureWrapperForLiteral)o).l); }
+ public String toString() { return l.toString(); }
+ public int compareTo(StructureWrapperForLiteral o) { return l.compareTo(o.l); }
+ public Literal getLiteral() { return l; }
+}
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/jason/stdlib/package.html 2015-12-11 13:05:52 UTC (rev 1867)
@@ -34,6 +34,7 @@
<li>{@link jason.stdlib.findall findall}: find a list of beliefs of some kind.</li>
<li>{@link jason.stdlib.setof setof}: find a set of beliefs of some kind.</li>
<li>{@link jason.stdlib.count count}: count the number of beliefs of some kind.</li>
+ <li>{@link jason.stdlib.name_space name_space}: checks whether an argument is a name space.</li>
</ul>
@@ -142,7 +143,7 @@
<li>{@link jason.stdlib.random random}: produces random numbers.</li>
- <li>{@link jason.stdlib.include include}: loads a source code at run time.</li>
+ <li>{@link jason.stdlib.include include}: imports a source code at run time.</li>
</ul>
</body>
Modified: trunk/src/test/ASParserTest.java
===================================================================
--- trunk/src/test/ASParserTest.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/test/ASParserTest.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -49,7 +49,7 @@
assertTrue(l.negated());
Literal l1 = ASSyntax.parseLiteral("~B");
Literal l2 = ASSyntax.parseLiteral("B");
- assertFalse(l1.equals(l2));
+ assertTrue(l1.equals(l2)); // see comment in varterm equals
}
public void testTrue() throws ParseException {
Modified: trunk/src/test/BeliefBaseTest.java
===================================================================
--- trunk/src/test/BeliefBaseTest.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/test/BeliefBaseTest.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -21,6 +21,7 @@
import jason.bb.DefaultBeliefBase;
import jason.bb.JDBCPersistentBB;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -630,6 +631,30 @@
assertEquals(ag.getBB().size(), c.size());
}
+ public void testBUF() {
+ Agent ag = new Agent();
+ ag.initAg();
+
+ ag.getBB().add(Literal.parseLiteral("a(10)[source(bob)]"));
+ List<Literal> percepts = new ArrayList<Literal>();
+ percepts.add(Literal.parseLiteral("a(10)"));
+ percepts.add(Literal.parseLiteral("a(20)"));
+
+ assertEquals(2,ag.buf(percepts));
+ assertEquals(2,ag.getBB().size());
+
+ assertEquals(0,ag.buf(new ArrayList<Literal>(percepts)));
+ assertEquals(2,ag.getBB().size());
+
+ percepts.remove(1); // remove a(20)
+ assertEquals(1,ag.buf(new ArrayList<Literal>(percepts)));
+ assertEquals(1,ag.getBB().size());
+
+ percepts.clear();
+ assertEquals(1,ag.buf(new ArrayList<Literal>(percepts)));
+ assertEquals(1,ag.getBB().size());
+ }
+
private int iteratorSize(@SuppressWarnings("rawtypes") Iterator i) {
int c = 0;
while (i.hasNext()) {
Modified: trunk/src/test/NSTest.java
===================================================================
--- trunk/src/test/NSTest.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/test/NSTest.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -128,9 +128,9 @@
// ns::A = ns::B // A -> B
u = new Unifier();
assertTrue(u.unifies(p1, p6));
- assertTrue(u.unifies(new VarTerm("A"), ASSyntax.parseLiteral("ns::bob(45)")));
- Literal t = (Literal)p1.capply(u);
- assertEquals("ns::bob(45)", t.toString());
+ assertFalse(u.unifies(new VarTerm("A"), ASSyntax.parseLiteral("ns::bob(45)")));
+ //Literal t = (Literal)p1.capply(u);
+ //assertEquals("ns::bob(45)", t.toString());
// ns::A = other::B // fail
u = new Unifier();
Modified: trunk/src/test/VarTermTest.java
===================================================================
--- trunk/src/test/VarTermTest.java 2015-12-11 11:01:07 UTC (rev 1866)
+++ trunk/src/test/VarTermTest.java 2015-12-11 13:05:52 UTC (rev 1867)
@@ -562,7 +562,7 @@
Literal l2 = ASSyntax.parseLiteral("~p(1)");
Unifier u = new Unifier();
assertTrue(u.unifies(l1, l2)); // ~B = ~p(1)
- assertEquals(u.get((VarTerm)l1).toString(),"~p(1)");
+ assertEquals(u.get((VarTerm)l1).toString(),"p(1)");
// apply in ~B should result in ~p(1)
assertEquals(l1.capply(u).toString(),"~p(1)");
@@ -584,6 +584,11 @@
assertEquals(l1.capply(u).toString(),"~p(1)");
l1 = ASSyntax.parseLiteral("~B");
+ l2 = ASSyntax.parseLiteral("A");
+ u = new Unifier();
+ assertFalse(u.unifies(l1, l2));
+
+ l1 = ASSyntax.parseLiteral("~B");
l2 = ASSyntax.parseLiteral("~A");
u = new Unifier();
assertTrue(u.unifies(l1, l2));
@@ -601,38 +606,39 @@
l2 = ASSyntax.parseLiteral("~A");
u = new Unifier();
assertTrue(u.unifies(l1, l2)); // A = B
- // if ~A = ~p(10), apply in B should be p(10).
+ // if ~A = ~p(10), then B -> p(10).
assertTrue(u.unifies(l2, ASSyntax.parseLiteral("~p(10)")));
//l2.apply(u);
- assertEquals(l2.capply(u).toString(),"~p(10)");
+ assertEquals("~p(10)", l2.capply(u).toString());
//l1.apply(u);
- assertEquals(l1.capply(u).toString(),"~p(10)"); // ~B is ~p(10)
+ assertEquals("~p(10)", l1.capply(u).toString()); // ~B is ~p(10)
VarTerm vb = new VarTerm("B");
//vb.apply(u);
- assertEquals(vb.capply(u).toString(),"p(10)"); // B is p(10)
+ assertEquals("p(10)", vb.capply(u).toString());
u = new Unifier();
u.unifies(new VarTerm("A"),ASSyntax.parseLiteral("p(10)"));
u.unifies(new VarTerm("B"),ASSyntax.parseLiteral("~p(10)"));
assertFalse(u.unifies(new VarTerm("A"), new VarTerm("B")));
+
l1 = ASSyntax.parseLiteral("~B");
l2 = ASSyntax.parseLiteral("~A");
assertFalse(u.unifies(l1, l2));
u = new Unifier();
u.unifies(new VarTerm("A"),ASSyntax.parseLiteral("p(10)"));
- assertFalse(u.unifies(new VarTerm(Literal.LNeg,"B"),new VarTerm("A")));
+ assertFalse(u.unifies( ASSyntax.createVar(Literal.LNeg, "B"), new VarTerm("A")));
u = new Unifier();
u.unifies(new VarTerm("A"),ASSyntax.parseLiteral("~p(10)"));
- vb = new VarTerm(Literal.LNeg,"B");
+ vb = ASSyntax.createVar(Literal.LNeg, "B");
assertTrue(u.unifies(vb,new VarTerm("A")));
//vb.apply(u);
assertEquals(vb.capply(u).toString(),"~p(10)");
u = new Unifier();
u.unifies(new VarTerm("A"),ASSyntax.parseLiteral("~p(10)"));
- vb = new VarTerm(Literal.LNeg,"B");
+ vb = ASSyntax.createVar(Literal.LNeg, "B");
assertTrue(u.unifies(vb,new VarTerm("A")));
vb = new VarTerm("B");
//vb.apply(u);
@@ -643,6 +649,7 @@
// => apply B is ~p(10)
// apply A is p(10)
// apply ~A is ~p(10)
+ /* should not work any more (B = ~A does not unify)
l1 = ASSyntax.parseLiteral("B");
l2 = ASSyntax.parseLiteral("~A");
u = new Unifier();
@@ -654,7 +661,8 @@
//l1.apply(u);
assertEquals(l1.capply(u).toString(),"~p(10)");
//l2.apply(u);
- assertEquals(l2.capply(u).toString(),"~p(10)");
+ assertEquals(l2.capply(u).toString(),"~p(10)");
+ */
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2015-12-11 11:01:10
|
Revision: 1866
http://sourceforge.net/p/jason/svn/1866
Author: jomifred
Date: 2015-12-11 11:01:07 +0000 (Fri, 11 Dec 2015)
Log Message:
-----------
new buf
Modified Paths:
--------------
trunk/src/jason/asSemantics/Agent.java
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2015-12-09 14:20:46 UTC (rev 1865)
+++ trunk/src/jason/asSemantics/Agent.java 2015-12-11 11:01:07 UTC (rev 1866)
@@ -45,6 +45,7 @@
import jason.asSyntax.parser.as2j;
import jason.bb.BeliefBase;
import jason.bb.DefaultBeliefBase;
+import jason.bb.StructureWrapperForLiteral;
import jason.functions.Count;
import jason.functions.RuleToFunction;
import jason.jeditplugin.Config;
@@ -64,10 +65,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
+import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
@@ -714,6 +717,7 @@
* @return the number of changes (add + dels)
*/
public int buf(List<Literal> percepts) {
+ // complexity 3n
if (percepts == null) {
return 0;
}
@@ -723,11 +727,33 @@
int dels = 0;
//long startTime = qProfiling == null ? 0 : System.nanoTime();
+ // to copy percepts allows the use of contains below
+ Set<StructureWrapperForLiteral> perW = new HashSet<StructureWrapperForLiteral>();
+ Iterator<Literal> iper = percepts.iterator();
+ while (iper.hasNext())
+ perW.add(new StructureWrapperForLiteral(iper.next()));
+
+
// deleting percepts in the BB that is not perceived anymore
Iterator<Literal> perceptsInBB = getBB().getPercepts();
while (perceptsInBB.hasNext()) {
Literal l = perceptsInBB.next();
-
+ if (! perW.remove(new StructureWrapperForLiteral(l))) { // l is not perceived anymore
+ dels++;
+ perceptsInBB.remove(); // remove l as perception from BB
+
+ // new version (it is sure that l is in BB, only clone l when the event is relevant)
+ Trigger te = new Trigger(TEOperator.del, TEType.belief, l);
+ if (ts.getC().hasListener() || pl.hasCandidatePlan(te)) {
+ l = ASSyntax.createLiteral(l.getFunctor(), l.getTermsArray());
+ l.addAnnot(BeliefBase.TPercept);
+ te.setLiteral(l);
+ ts.getC().addEvent(new Event(te, Intention.EmptyInt));
+ }
+ }
+ }
+ /*
+ ////// previous version, without perW hashset
// could not use percepts.contains(l), since equalsAsTerm must be
// used (to ignore annotations)
boolean wasPerceived = false;
@@ -759,7 +785,7 @@
te.setLiteral(l);
ts.getC().addEvent(new Event(te, Intention.EmptyInt));
}
-
+ */
/*
// old version
// can not delete l, but l[source(percept)]
@@ -770,22 +796,19 @@
ts.updateEvents(new Event(new Trigger(TEOperator.del, TEType.belief, l), Intention.EmptyInt));
}
*/
- }
- }
+ //}
+ //}
- // BUF only adds a belief when appropriate
- // checking all percepts for new beliefs
- for (Literal lp : percepts) {
+ for (StructureWrapperForLiteral lw: perW) {
try {
- lp = lp.copy().forceFullLiteralImpl();
+ Literal lp = lw.getLiteral().copy().forceFullLiteralImpl();
lp.addAnnot(BeliefBase.TPercept);
if (getBB().add(lp)) {
adds++;
- Trigger te = new Trigger(TEOperator.add, TEType.belief, lp);
- ts.updateEvents(new Event(te, Intention.EmptyInt));
+ ts.updateEvents(new Event(new Trigger(TEOperator.add, TEType.belief, lp), Intention.EmptyInt));
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Error adding percetion " + lp, e);
+ logger.log(Level.SEVERE, "Error adding percetion " + lw.getLiteral(), e);
}
}
@@ -796,6 +819,61 @@
return adds + dels;
}
+ public int bufAlternative(List<Literal> percepts) {
+ // complexity 4n
+
+ if (percepts == null) {
+ return 0;
+ }
+
+ // stat
+ int adds = 0;
+ int dels = 0;
+
+ //Set<Literal> pinBB = ((DefaultBeliefBase)getBB()).getPerceptsSet();
+ Set<StructureWrapperForLiteral> pinBBW = new HashSet<StructureWrapperForLiteral>();
+ Iterator<Literal> ibb = getBB().getPercepts();
+ while (ibb.hasNext())
+ pinBBW.add(new StructureWrapperForLiteral( ibb.next()));
+
+ Iterator<Literal> ip = percepts.iterator();
+ while (ip.hasNext()) {
+ Literal t = ip.next();
+ StructureWrapperForLiteral lrt = new StructureWrapperForLiteral(t);
+ if ( pinBBW.remove(lrt) ) {
+ // since this percept in in BB, do not need to be added neither removed
+ ip.remove();
+ }
+ }
+
+ // percepts that are not in BB
+ for (Literal lp : percepts) {
+ try {
+ lp = lp.copy().forceFullLiteralImpl();
+ lp.addAnnot(BeliefBase.TPercept);
+ if (getBB().add(lp)) {
+ adds++;
+ ts.updateEvents(new Event(new Trigger(TEOperator.add, TEType.belief, lp), Intention.EmptyInt));
+ }
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Error adding percetion " + lp, e);
+ }
+ }
+
+ // remove what was not perceived
+ for (StructureWrapperForLiteral lw: pinBBW) {
+ Literal l = lw.getLiteral();
+ l = ASSyntax.createLiteral(l.getFunctor(), l.getTermsArray());
+ l.addAnnot(BeliefBase.TPercept);
+ if (bb.remove(l)) {
+ dels++;
+ ts.updateEvents(new Event(new Trigger(TEOperator.del, TEType.belief, l), Intention.EmptyInt));
+ }
+ }
+ return adds + dels;
+ }
+
+
/*
public QueryCacheSimple getQueryCache() {
return qCache;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|