Separating policy file into main policy and generated interfaces; fixing lexer, parse...
authorrtrimana <rtrimana@uci.edu>
Tue, 27 Sep 2016 21:13:21 +0000 (14:13 -0700)
committerrtrimana <rtrimana@uci.edu>
Tue, 27 Sep 2016 21:13:21 +0000 (14:13 -0700)
16 files changed:
config/iotpolicy/policy.pol
config/iotpolicy/requires.pol [new file with mode: 0644]
config/iotpolicy/tree-view.xsl [deleted file]
config/iotpolicy/tree.xsl [deleted file]
iotjava/Makefile
iotjava/iotpolicy/IoTCompiler.java [new file with mode: 0644]
iotjava/iotpolicy/IoTStubCompiler.java [deleted file]
iotjava/iotpolicy/parser/Lexer.java
iotjava/iotpolicy/parser/Parser.java
iotjava/iotpolicy/parser/sym.java
iotjava/iotpolicy/tree/CapabilityDecl.java
iotjava/iotpolicy/tree/InterfaceDecl.java
iotjava/iotpolicy/tree/ParseTreeHandler.java
iotjava/iotpolicy/tree/RequiresDecl.java
others/javacup/iotparser.cup
others/jflex/iotparser.jflex

index 7bcefcd..3048c1e 100644 (file)
@@ -1,30 +1,32 @@
 public interface Camera {
-    public void MethodA(int A, int B);
-    public int MethodB(int C, string D);
-    public string MethodC(string E, int F);
-    public float MethodD(int G, float H);
-    public boolean MethodE(Camera I, boolean J);
-       public void MethodF();
-}
 
-capability Camera.ImageCapture {
-       description = "The quick brown fox jumps over the smart dog";
-       description = "Another description";
-       method = MethodA;
-       method = MethodB;
-}
+    public void MethodA(int A, Speaker B);
+    public void MethodA(int A, Speaker B, int AB);
+    public int MethodB(int C, String D);
+    public String MethodC(String E, Map<int> F);
+    public float MethodD(Set<String> G, float H);
+    public boolean MethodE(String I, boolean J);
+       public void MethodF(LightBulb K);
 
-capability Camera.VideoRecording {
-       description = "The quick brown fox jumps over the cool dog";
-       method = MethodC;
-       method = MethodD;
-}
+       capability ImageCapture {
+               description = "The quick brown fox jumps over the smart dog";
+               description = "Another description";
+               method = "MethodA(int A, Speaker B)";
+               method = "MethodB(int C, String D)";
+               method = "MethodC(String E, Map<int> F)";
+       }
+
+       capability VideoRecording {
+               description = "The quick brown fox jumps over the cool dog";
+               method = "MethodA(int A, Speaker B)";
+               method = "MethodA(int A, Speaker B, int AB)";
+               method = "MethodD(Set<String> G, float H)";
+       }
 
-capability Camera.BackupData {
-       description = "The quick brown fox jumps over the clever dog";
-       method = MethodE;
+       capability BackupData {
+               description = "The quick brown fox jumps over the clever dog";
+               method = "MethodE(String I, boolean J)";
+       }
 }
 
-requires Camera with VideoRecording, ImageCapture as interface CameraWithCaptureAndData;
 
-requires Camera with ImageCapture, VideoRecording as interface CameraWithCaptureAndRecording;
diff --git a/config/iotpolicy/requires.pol b/config/iotpolicy/requires.pol
new file mode 100644 (file)
index 0000000..2531e20
--- /dev/null
@@ -0,0 +1,4 @@
+
+requires Camera with ImageCapture, BackupData as interface CameraWithCaptureAndData;
+requires Camera with ImageCapture, VideoRecording as interface CameraWithCaptureAndRecording;
+
diff --git a/config/iotpolicy/tree-view.xsl b/config/iotpolicy/tree-view.xsl
deleted file mode 100644 (file)
index 0a2e141..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-  <xsl:output method="html" 
-             encoding="UTF-8"
-             indent="no"/>
-
-  <xsl:variable name="apos">'</xsl:variable>
-
-  <xsl:template match="/">
-    <html>
-      <head>
-       <meta charset="UTF-8" />
-        <title>Parse-Tree</title>
-        <link type="text/css" rel="stylesheet" href="tree-view.css"/>
-      </head>
-      <body>
-        <h3>Parse-Tree</h3>
-        <xsl:apply-templates select="." mode="render"/>
-      </body>
-    </html>
-  </xsl:template>
-
-  <xsl:template match="/" mode="render">
-    <xsl:apply-templates mode="render"/>
-  </xsl:template>
-
-  <xsl:template match="*" mode="render">
-    <xsl:call-template name="ascii-art-hierarchy"/>
-    <br/>
-    <xsl:call-template name="ascii-art-hierarchy"/>
-    <span class='connector'>___</span>
-    <span class="element"><xsl:value-of select="local-name()"/></span>
-    <xsl:text>&#160;</xsl:text>
-    <br/>
-    <xsl:apply-templates select="@*" mode="render"/>
-    <xsl:apply-templates mode="render"/>
-  </xsl:template>
-
-  <xsl:template match="@*" mode="render">
-    <xsl:call-template name="ascii-art-hierarchy"/>
-    <span class='connector'>&#160;&#160;</span>
-    <span class='connector'>\___</span>
-
-    <xsl:text>&#160;</xsl:text>
-    <span class="name">
-      <xsl:value-of select="local-name()"/>
-    </span>
-    <xsl:text> = </xsl:text>
-    <span class="value">
-      <xsl:call-template name="escape-ws">
-        <xsl:with-param name="text" select="translate(.,' ','&#160;')"/>
-      </xsl:call-template>
-    </span>
-    <br/>
-  </xsl:template>
-
-  <xsl:template match="text()" mode="render">
-    <xsl:call-template name="ascii-art-hierarchy"/>
-    <br/>
-    <xsl:call-template name="ascii-art-hierarchy"/>
-    <span class='connector'>___</span>
-    <xsl:text>&#160;</xsl:text>
-    <span class="value">
-      <xsl:call-template name="escape-ws">
-        <xsl:with-param name="text" select="translate(.,' ','&#160;')"/>
-      </xsl:call-template>
-    </span>
-    <br/>
-  </xsl:template>
-
-  <xsl:template match="comment()" mode="render" />
-  <xsl:template match="processing-instruction()" mode="render" />
-
-
-  <xsl:template name="ascii-art-hierarchy">
-    <xsl:for-each select="ancestor::*">
-      <xsl:choose>
-        <xsl:when test="following-sibling::node()">
-          <span class='connector'>&#160;&#160;</span>|<span class='connector'>&#160;&#160;</span>
-          <xsl:text>&#160;</xsl:text>
-        </xsl:when>
-        <xsl:otherwise>
-          <span class='connector'>&#160;&#160;&#160;&#160;</span>
-          <span class='connector'>&#160;&#160;</span>
-        </xsl:otherwise>
-      </xsl:choose>
-    </xsl:for-each>
-    <xsl:choose>
-      <xsl:when test="parent::node() and ../child::node()">
-        <span class='connector'>&#160;&#160;</span>
-        <xsl:text>|</xsl:text>
-      </xsl:when>
-      <xsl:otherwise>
-        <span class='connector'>&#160;&#160;&#160;</span>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-
-  <!-- recursive template to escape linefeeds, tabs -->
-  <xsl:template name="escape-ws">
-    <xsl:param name="text"/>
-    <xsl:choose>
-      <xsl:when test="contains($text, '&#xA;')">
-        <xsl:call-template name="escape-ws">
-          <xsl:with-param name="text" select="substring-before($text, '&#xA;')"/>
-        </xsl:call-template>
-        <span class="escape">\n</span>
-        <xsl:call-template name="escape-ws">
-          <xsl:with-param name="text" select="substring-after($text, '&#xA;')"/>
-        </xsl:call-template>
-      </xsl:when>
-      <xsl:when test="contains($text, '&#x9;')">
-        <xsl:value-of select="substring-before($text, '&#x9;')"/>
-        <span class="escape">\t</span>
-        <xsl:call-template name="escape-ws">
-          <xsl:with-param name="text" select="substring-after($text, '&#x9;')"/>
-        </xsl:call-template>
-      </xsl:when>
-      <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-
-</xsl:stylesheet>
diff --git a/config/iotpolicy/tree.xsl b/config/iotpolicy/tree.xsl
deleted file mode 100644 (file)
index 05e1b27..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" 
-               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-               xmlns:exsl="http://exslt.org/common"
-               >
-<xsl:output method="xml" version="1.0" encoding="UTF-8" />
-
-<xsl:include href="tree-view.xsl"/>
-
-<xsl:template match="blacklist"  mode="flatten" />
-
-<xsl:template match="document"  mode="flatten">
-      <xsl:apply-templates  mode="flatten" select="parsetree"/>
-</xsl:template>
-
-<xsl:template match="nonterminal" mode="flatten">
-  <xsl:variable name="temp" select="@id" />
-  <xsl:choose>
-    
-    <xsl:when test="count(*)=3 and contains($temp,'expr') and *[contains(@id,'expr')]"> 
-      <xsl:apply-templates  mode="flatten"/>
-    </xsl:when>
-
-    <!-- collapses degenerated trees like lists, conserving the blacklist subtrees-->
-    <xsl:when test="../@id = @id and count(/document/blacklist[1]/symbol[text() = $temp])=0"> 
-      <xsl:apply-templates  mode="flatten"/>
-    </xsl:when>
-
-    <!-- collapses unary productions -->
-    <xsl:when test="count(*)=3 and count(/document/blacklist[1]/symbol[text() = $temp])=0"> 
-      <xsl:apply-templates  mode="flatten"/>
-    </xsl:when>
-
-    <xsl:otherwise>
-      <xsl:element name="{@id}" >
-       <xsl:attribute name="variant"><xsl:value-of select="@variant" /></xsl:attribute>
-       <xsl:apply-templates mode="flatten"/>
-      </xsl:element>
-    </xsl:otherwise>
-
-  </xsl:choose>
-</xsl:template>
-
-<xsl:template match="terminal" mode="flatten">
-  <xsl:element name="{@id}">
-    <xsl:apply-templates  mode="flatten"/>
-  </xsl:element>
-</xsl:template>
-
-<xsl:template match="/">
- <xsl:variable name="flatten">
-     <xsl:apply-templates  mode="flatten"/>
- </xsl:variable>
- <xsl:variable name="rendered">
-    <xsl:apply-templates mode="rendered" select="exsl:node-set($flatten)"/>
- </xsl:variable>
-
- <!--xsl:copy-of select="$rendered" /-->
- <xsl:copy-of select="$flatten" />
-</xsl:template>
-
-
-</xsl:stylesheet>
\ No newline at end of file
index 8d92c94..8cfe1c6 100644 (file)
@@ -2,24 +2,24 @@ BASE := ..
 
 include $(BASE)/common.mk
 
-all: iotparsertree iotparser iotcompiler
+all: tree parser compiler
 
-PHONY += iotparsertree
-iotparsertree:
+PHONY += tree
+tree:
        $(JAVAC) -cp .:$(PARSERJARS) -d $(BIN_DIR) iotpolicy/tree/*.java
 
-PHONY += iotparser
-iotparser:
+PHONY += parser
+parser:
        $(JAVAC) -cp .:$(PARSERJARS) -d $(BIN_DIR) iotpolicy/parser/*.java
 
-PHONY += iotcompiler
-iotcompiler:
+PHONY += compiler
+compiler:
        $(JAVAC) -cp .:$(PARSERJARS) -d $(BIN_DIR) iotpolicy/*.java
        cp ../config/iotpolicy/*.pol $(BIN_DIR)/iotpolicy/
 
-PHONY += iotcompilestub
-iotcompilestub:
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTStubCompiler policy.pol
+PHONY += run
+run:
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler policy.pol requires.pol -java JavaStub -cplus CPlusStub
 
 PHONY += doc
 doc: iotruntime iotinstaller
diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java
new file mode 100644 (file)
index 0000000..7573277
--- /dev/null
@@ -0,0 +1,547 @@
+package iotpolicy;
+
+import java_cup.runtime.ComplexSymbolFactory;
+import java_cup.runtime.ScannerBuffer;
+import java.io.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import iotpolicy.parser.Lexer;
+import iotpolicy.parser.Parser;
+import iotpolicy.tree.ParseNode;
+import iotpolicy.tree.ParseNodeVector;
+import iotpolicy.tree.ParseTreeHandler;
+import iotpolicy.tree.CapabilityDecl;
+import iotpolicy.tree.InterfaceDecl;
+import iotpolicy.tree.RequiresDecl;
+
+/** Class IoTCompiler is the main stub compiler for
+ *  stub files generation. This class calls helper classes
+ *  such as Parser, Lexer, InterfaceDecl, CapabilityDecl,
+ *  RequiresDecl, ParseTreeHandler, etc.
+ *
+ * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
+ * @version     1.0
+ * @since       2016-09-22
+ */
+public class IoTCompiler {
+
+       /**
+        * Class properties
+        */
+       private String origInt;
+       private ParseTreeHandler ptHandler;
+       private InterfaceDecl intDecl;
+       private CapabilityDecl capDecl;
+       private RequiresDecl reqDecl;
+       private Map<String,Set<String>> mapCapabMethods;
+       private PrintWriter pw;
+       private String dir;
+
+       /**
+        * Class constants
+        */
+       private final static String OUTPUT_DIRECTORY = "stubfiles";
+
+       /**
+        * Class constructors
+        */
+       public IoTCompiler() {
+
+               origInt = null;
+               ptHandler = new ParseTreeHandler();
+               intDecl = null;
+               capDecl = null;
+               capDecl = null;
+               mapCapabMethods = new HashMap<String,Set<String>>();
+               pw = null;
+               dir = OUTPUT_DIRECTORY;
+       }
+
+
+       public IoTCompiler(String _origInt, ParseNode _pnPol, ParseNode _pnReq) {
+
+               origInt = _origInt;
+               ptHandler = new ParseTreeHandler(_origInt, _pnPol, _pnReq);
+               intDecl = null;
+               capDecl = null;
+               reqDecl = null;
+               mapCapabMethods = new HashMap<String,Set<String>>();
+               pw = null;
+               dir = OUTPUT_DIRECTORY;
+       }
+
+
+       /**
+        * parsePolicyFile() parses policy file
+        * <p>
+        * It also generates parse tree and
+        * copies useful information from parse tree into
+        * InterfaceDecl, CapabilityDecl, and RequiresDecl 
+        * data structures.
+        * Additionally, the data structure handles are
+        * returned from tree-parsing for further process.
+        *
+        */
+       public void parsePolicyFile() {
+
+               ptHandler.processInterfaceDecl();
+               intDecl = ptHandler.getInterfaceDecl();
+
+               ptHandler.processCapabilityDecl();
+               capDecl = ptHandler.getCapabilityDecl();
+
+               ptHandler.processRequiresDecl();
+               reqDecl = ptHandler.getRequiresDecl();
+       }
+
+
+       /**
+        * getMethodsForIntface() reads for methods in the data structure
+        * <p>
+        * It is going to give list of methods for a certain interface
+        *              based on the declaration of capabilities.
+        */
+       public void getMethodsForIntface() {
+
+               // Get set of new interfaces, e.g. CameraWithCaptureAndData
+               // Generate this new interface with all the methods it needs
+               //              from different capabilities it declares
+               Set<String> setIntfaces = reqDecl.getInterfaces();
+               for (String strInt : setIntfaces) {
+
+                       // Initialize a set of methods
+                       Set<String> setMethods = new HashSet<String>();
+                       // Get list of capabilities, e.g. ImageCapture, VideoRecording, etc.
+                       List<String> listCapab = reqDecl.getCapabList(strInt);
+                       for (String strCap : listCapab) {
+
+                               // Get list of methods for each capability
+                               List<String> listCapabMeth = capDecl.getMethods(strCap);
+                               for (String strMeth : listCapabMeth) {
+
+                                       // Add methods into setMethods
+                                       // This is to also handle redundancies (say two capabilities
+                                       //              share the same methods)
+                                       setMethods.add(strMeth);
+                               }
+                       }
+                       // Add interface and methods information into map
+                       mapCapabMethods.put(strInt, setMethods);
+               }
+       }
+
+
+       /**
+        * generateJavaInterfaces() generate stub interfaces based on the methods list in Java
+        */
+       public void generateJavaInterfaces() throws IOException {
+
+               // Create a new directory
+               createDirectory(dir);
+               for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
+
+                       // Open a new file to write into
+                       String newIntface = intMeth.getKey();
+                       FileWriter fw = new FileWriter(dir + "/" + newIntface + ".java");
+                       pw = new PrintWriter(new BufferedWriter(fw));
+                       // Write interface header
+                       println("");
+                       println("public interface " + newIntface + " {");
+                       List<String> meths = intDecl.getMethods();
+
+                       // Write methods
+                       for (String method : intMeth.getValue()) {
+
+                               List<String> methParams = intDecl.getMethodParams(method);
+                               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                               print("public " + intDecl.getMethodType(method) + " " +
+                                       intDecl.getMethodId(method) + "(");
+                               for (int i = 0; i < methParams.size(); i++) {
+                                        print(methPrmTypes.get(i) + " " + methParams.get(i));
+                                       // Check if this is the last element (don't print a comma)
+                                       if (i != methParams.size() - 1) {
+                                               print(", ");
+                                       }
+                               }
+                               println(");");
+                       }
+                       println("}");
+                       pw.close();
+                       System.out.println("IoTCompiler: Generated interface " + newIntface + ".java...");
+               }
+       }
+
+
+       /**
+        * generateCPlusInterfaces() generate stub interfaces based on the methods list in C++
+        * <p>
+        * For C++ we use virtual classe as interface
+        */
+       public void generateCPlusInterfaces() throws IOException {
+
+               // Create a new directory
+               createDirectory(dir);
+               for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
+
+                       // Open a new file to write into
+                       String newIntface = intMeth.getKey();
+                       FileWriter fw = new FileWriter(dir + "/" + newIntface + ".hpp");
+                       pw = new PrintWriter(new BufferedWriter(fw));
+                       // Write file headers
+                       println("#include<iostream>");
+                       println("");
+                       println("using namespace std;");
+                       println("");
+                       println("class " + newIntface);
+                       println("{");
+                       println("public:");
+                       // Write methods
+                       for (String method : intMeth.getValue()) {
+
+                               List<String> methParams = intDecl.getMethodParams(method);
+                               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                               print("virtual " + convertType(intDecl.getMethodType(method)) + " " +
+                                       intDecl.getMethodId(method) + "(");
+                               for (int i = 0; i < methParams.size(); i++) {
+                                        print(convertType(methPrmTypes.get(i)) + " " + methParams.get(i));
+                                       // Check if this is the last element (don't print a comma)
+                                       if (i != methParams.size() - 1) {
+                                               print(", ");
+                                       }
+                               }
+                               println(") = 0;");
+                       }
+                       print("}");
+                       println(";");
+                       pw.close();
+                       System.out.println("IoTCompiler: Generated interface " + newIntface + ".hpp...");
+               }
+       }
+
+
+       /**
+        * generateJavaStubClasses() generate stubs based on the methods list in Java
+        */
+       public void generateJavaStubClasses() throws IOException {
+
+               // Create a new directory
+               createDirectory(dir);
+               for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
+
+                       // Open a new file to write into
+                       String newIntface = intMeth.getKey();
+                       String newStubClass = newIntface + "_Stub";
+                       FileWriter fw = new FileWriter(dir + "/" + newStubClass + ".java");
+                       pw = new PrintWriter(new BufferedWriter(fw));
+                       // Write interface header
+                       println("");
+                       println("public class " + newStubClass + " implements " + newIntface + " {");
+                       println("");
+                       // Write methods
+                       for (String method : intMeth.getValue()) {
+
+                               List<String> methParams = intDecl.getMethodParams(method);
+                               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                               print("public " + intDecl.getMethodType(method) + " " +
+                                       intDecl.getMethodId(method) + "(");
+                               for (int i = 0; i < methParams.size(); i++) {
+                                        print(methPrmTypes.get(i) + " " + methParams.get(i));
+                                       // Check if this is the last element (don't print a comma)
+                                       if (i != methParams.size() - 1) {
+                                               print(", ");
+                                       }
+                               }
+                               println(") {");
+                               // Check if this is not "void"
+                               if (!intDecl.getMethodType(method).equals("void")) {
+                                       String retStmt = generateReturnStmt(intDecl.getMethodType(method));
+                                       println("return " + retStmt + ";");
+                               }
+                               println("}");
+                               println("");
+                       }
+                       println("}");
+                       pw.close();
+                       System.out.println("IoTCompiler: Generated stub class " + newStubClass + ".java...");
+               }
+       }
+
+
+       /**
+        * generateCPlusStubClasses() generate stubs based on the methods list in C++
+        */
+       public void generateCPlusStubClasses() throws IOException {
+
+               // Create a new directory
+               createDirectory(dir);
+               for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
+
+                       // Open a new file to write into
+                       String newIntface = intMeth.getKey();
+                       String newStubClass = newIntface + "_Stub";
+                       FileWriter fw = new FileWriter(dir + "/" + newStubClass + ".hpp");
+                       pw = new PrintWriter(new BufferedWriter(fw));
+                       // Write file headers
+                       println("#include<iostream>");
+                       println("#include \"" + newIntface + ".hpp\""); println("");            
+                       println("using namespace std;"); println("");
+                       println("class " + newStubClass + " : public " + newIntface);
+                       println("{");
+                       println("public:"); println("");
+                       // Add default constructor and destructor
+                       println(newStubClass + "() { }"); println("");
+                       println("~" + newStubClass + "() { }"); println("");            
+                       // Write methods
+                       for (String method : intMeth.getValue()) {
+
+                               List<String> methParams = intDecl.getMethodParams(method);
+                               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
+                               print(convertType(intDecl.getMethodType(method)) + " " +
+                                       intDecl.getMethodId(method) + "(");
+                               for (int i = 0; i < methParams.size(); i++) {
+                                        print(convertType(methPrmTypes.get(i)) + " " + methParams.get(i));
+                                       // Check if this is the last element (don't print a comma)
+                                       if (i != methParams.size() - 1) {
+                                               print(", ");
+                                       }
+                               }
+                               println(") { ");
+                               // Check if this is not "void"
+                               if (!intDecl.getMethodType(method).equals("void")) {
+                                       String retStmt = generateReturnStmt(intDecl.getMethodType(method));
+                                       if (retStmt.equals("null")) { // null = NULL in C++
+                                               retStmt = "NULL";
+                                       }
+                                       println("return " + retStmt + ";");
+                               }
+                               println("}"); println("");
+                       }
+                       print("}"); println(";");
+                       pw.close();
+                       System.out.println("IoTCompiler: Generated stub class " + newIntface + ".hpp...");
+               }
+       }
+
+
+       /**
+        * generateReturnStmt() generate return statement based on methType
+        */
+       public String generateReturnStmt(String methType) {
+
+               // Generate dummy returns for now
+               if (methType.equals("short")||
+                       methType.equals("int")  ||
+                       methType.equals("long") ||
+                       methType.equals("float")||
+                       methType.equals("double")) {
+
+                       return "1";
+               } else if ( methType.equals("String") ||
+                                       methType.equals("byte")) {
+  
+                       return "\"a\"";
+               } else if ( methType.equals("char")) {
+
+                       return "\'a\'";
+               } else if ( methType.equals("boolean")) {
+
+                       return "true";
+               } else {
+                       return "null";
+               }
+       }
+
+
+       /**
+        * setDirectory() set a new directory for stub files
+        */
+       public void setDirectory(String _dir) {
+
+               dir = _dir;
+       }
+
+
+       /**
+        * printUsage() prints the usage of this compiler
+        */
+       public static void printUsage() {
+
+               System.out.println();
+               System.out.println("Sentinel interface and stub compiler version 1.0");
+               System.out.println("Copyright (c) 2015-2016 University of California, Irvine - Programming Language Group.");
+               System.out.println("All rights reserved.");
+               System.out.println("Usage:");
+               System.out.println("\tjava IoTCompiler --help / -h\t\t\t\t\tDisplay this help texts");
+               System.out.println("\tjava IoTCompiler <main-policy-file> <req-policy-file>\t\tGenerate both Java and C++ stub files");
+               System.out.println("\tjava IoTCompiler <main-policy-file> <req-policy-file> [options]");
+               System.out.println("Options:");
+               System.out.println("\t-java\t<directory>\tGenerate Java stub files");
+               System.out.println("\t-cplus\t<directory>\tGenerate C++ stub files");
+               System.out.println();
+       }
+
+
+       /**================================================
+        * Helper functions to write stub codes into files
+        **================================================
+        */
+       boolean newline=true;
+       int tablevel=0;
+
+       private void print(String str) {
+               if (newline) {
+                       int tab=tablevel;
+                       if (str.equals("}"))
+                               tab--;
+                       for(int i=0; i<tab; i++)
+                               pw.print("\t");
+               }
+               pw.print(str);
+               updatetabbing(str);
+               newline=false;
+       }
+
+       /**
+        * This function converts Java to C++ type for compilation
+        */
+       private String convertType(String jType) {
+
+               // Generate dummy returns for now
+               if (jType.equals("short")||
+                       jType.equals("int")  ||
+                       jType.equals("long") ||
+                       jType.equals("char") ||
+                       jType.equals("float")||
+                       jType.equals("double")) {
+
+                       return jType;
+               } else if ( jType.equals("String")) {
+  
+                       return "string";
+               } else if ( jType.equals("byte")) {
+
+                       return "char";
+               } else if ( jType.equals("boolean")) {
+
+                       return "bool";
+               } else {
+                       return jType;
+               }       
+       }
+
+
+       private void println(String str) {
+               if (newline) {
+                       int tab = tablevel;
+                       if (str.equals("}"))
+                               tab--;
+                       for(int i=0; i<tab; i++)
+                               pw.print("\t");
+               }
+               pw.println(str);
+               updatetabbing(str);
+               newline = true;
+       }
+
+
+       private void updatetabbing(String str) {
+               tablevel+=count(str,'{')-count(str,'}');
+       }
+
+
+       private int count(String str, char key) {
+               char[] array = str.toCharArray();
+               int count = 0;
+               for(int i=0; i<array.length; i++) {
+                       if (array[i] == key)
+                               count++;
+               }
+               return count;
+       }
+
+
+       private void createDirectory(String dirName) {
+
+               File file = new File(dirName);
+               if (!file.exists()) {
+                       if (file.mkdir()) {
+                               System.out.println("IoTCompiler: Directory " + dirName + " has been created!");
+                       } else {
+                               System.out.println("IoTCompiler: Failed to create directory " + dirName + "!");
+                       }
+               } else {
+                       System.out.println("IoTCompiler: Directory " + dirName + " exists...");
+               }
+       }
+
+
+       public static void main(String[] args) throws Exception {
+
+               // Runtime options
+               if (args.length != 0) {
+                       // Display help
+                       if ((args[0].equals("--help") ||
+                               (args[0].equals("-h")))) {
+                               IoTCompiler.printUsage();
+                       } else {
+                               // Parse main policy file
+                               ComplexSymbolFactory csfPol = new ComplexSymbolFactory();
+                               ScannerBuffer lexerPol = 
+                                       new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[0])),csfPol));
+                               Parser parsePol = new Parser(lexerPol,csfPol);
+                               ParseNode pnPol = (ParseNode) parsePol.parse().value;
+                               // Parse "requires" policy file
+                               ComplexSymbolFactory csfReq = new ComplexSymbolFactory();
+                               ScannerBuffer lexerReq = 
+                                       new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[1])),csfReq));
+                               Parser parseReq = new Parser(lexerReq,csfReq);
+                               ParseNode pnReq = (ParseNode) parseReq.parse().value;
+                               // Get interface name
+                               String intFace = ParseTreeHandler.getOrigIntface(pnPol);
+                               //System.out.println("IoTCompiler: Original interface: " + intFace);
+                               IoTCompiler comp = new IoTCompiler(intFace, pnPol, pnReq);
+                               // Generate all policy files if just policy file is provided
+                               comp.parsePolicyFile();
+                               comp.getMethodsForIntface();
+                               if (args.length == 2) {
+                                       comp.generateJavaInterfaces();
+                                       comp.generateJavaStubClasses();
+                                       comp.generateCPlusInterfaces();
+                                       comp.generateCPlusStubClasses();
+                               } else {
+                               // Check other options
+                                       int i = 2;
+                                       while(i < args.length) {
+                                               // Check whether <directory> is provided
+                                               if ((i + 1) < args.length) {
+                                                       comp.setDirectory(args[i+1]);
+                                               } else
+                                                       throw new Error("IoTCompiler: ERROR - please provide <directory> after option: " + args[i]);
+                                               if (args[i].equals("-java")) {
+                                                       comp.generateJavaInterfaces();
+                                                       comp.generateJavaStubClasses();
+                                               } else if (args[i].equals("-cplus")) {
+                                                       comp.generateCPlusInterfaces();
+                                                       comp.generateCPlusStubClasses();
+                                               } else
+                                                       throw new Error("IoTCompiler: ERROR - unrecognized command line option: " + args[i]);
+                                               i = i + 2;
+                                       }
+                               }
+                       }
+
+               } else {
+               // Need at least the policy file name
+                       IoTCompiler.printUsage();
+                       throw new Error("IoTCompiler: At least two arguments (main and requires policy files) have to be provided!");
+               }
+       }
+}
+
+
+
+
diff --git a/iotjava/iotpolicy/IoTStubCompiler.java b/iotjava/iotpolicy/IoTStubCompiler.java
deleted file mode 100644 (file)
index c11d32f..0000000
+++ /dev/null
@@ -1,540 +0,0 @@
-package iotpolicy;
-
-import java_cup.runtime.ComplexSymbolFactory;
-import java_cup.runtime.ScannerBuffer;
-import java.io.*;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import iotpolicy.parser.Lexer;
-import iotpolicy.parser.Parser;
-import iotpolicy.tree.ParseNode;
-import iotpolicy.tree.ParseNodeVector;
-import iotpolicy.tree.ParseTreeHandler;
-import iotpolicy.tree.CapabilityDecl;
-import iotpolicy.tree.InterfaceDecl;
-import iotpolicy.tree.RequiresDecl;
-
-/** Class IoTStubCompiler is the main stub compiler for
- *  stub files generation. This class calls helper classes
- *  such as Parser, Lexer, InterfaceDecl, CapabilityDecl,
- *  RequiresDecl, ParseTreeHandler, etc.
- *
- * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
- * @version     1.0
- * @since       2016-09-22
- */
-public final class IoTStubCompiler {
-
-       /**
-        * Class properties
-        */
-       private String origInt;
-       private ParseTreeHandler ptHandler;
-       private InterfaceDecl intDecl;
-       private CapabilityDecl capDecl;
-       private RequiresDecl reqDecl;
-       private Map<String,Set<String>> mapCapabMethods;
-       private PrintWriter pw;
-       private String dir;
-
-       /**
-        * Class constants
-        */
-       private final static String OUTPUT_DIRECTORY = "stubfiles";
-
-       /**
-        * Class constructors
-        */
-       public IoTStubCompiler() {
-
-               origInt = null;
-               ptHandler = new ParseTreeHandler();
-               intDecl = null;
-               capDecl = null;
-               capDecl = null;
-               mapCapabMethods = new HashMap<String,Set<String>>();
-               pw = null;
-               dir = OUTPUT_DIRECTORY;
-       }
-
-
-       public IoTStubCompiler(String _origInt, ParseNode _pn) {
-
-               origInt = _origInt;
-               ptHandler = new ParseTreeHandler(_origInt, _pn);
-               intDecl = null;
-               capDecl = null;
-               reqDecl = null;
-               mapCapabMethods = new HashMap<String,Set<String>>();
-               pw = null;
-               dir = OUTPUT_DIRECTORY;
-       }
-
-
-       /**
-        * parsePolicyFile() parses policy file
-        * <p>
-        * It also generates parse tree and
-        * copies useful information from parse tree into
-        * InterfaceDecl, CapabilityDecl, and RequiresDecl 
-        * data structures.
-        * Additionally, the data structure handles are
-        * returned from tree-parsing for further process.
-        *
-        */
-       public void parsePolicyFile() {
-
-               ptHandler.processInterfaceDecl();
-               intDecl = ptHandler.getInterfaceDecl();
-
-               ptHandler.processCapabilityDecl();
-               capDecl = ptHandler.getCapabilityDecl();
-
-               ptHandler.processRequiresDecl();
-               reqDecl = ptHandler.getRequiresDecl();
-       }
-
-
-       /**
-        * getMethodsForIntface() reads for methods in the data structure
-        * <p>
-        * It is going to give list of methods for a certain interface
-        *              based on the declaration of capabilities.
-        */
-       public void getMethodsForIntface() {
-
-               // Get set of new interfaces, e.g. CameraWithCaptureAndData
-               // Generate this new interface with all the methods it needs
-               //              from different capabilities it declares
-               Set<String> setIntfaces = reqDecl.getInterfaces();
-               for (String strInt : setIntfaces) {
-
-                       // Initialize a set of methods
-                       Set<String> setMethods = new HashSet<String>();
-                       // Get list of capabilities, e.g. ImageCapture, VideoRecording, etc.
-                       List<String> listCapab = reqDecl.getCapabList(strInt);
-                       for (String strCap : listCapab) {
-
-                               // Get list of methods for each capability
-                               List<String> listCapabMeth = capDecl.getMethods(strCap);
-                               for (String strMeth : listCapabMeth) {
-
-                                       // Add methods into setMethods
-                                       // This is to also handle redundancies (say two capabilities
-                                       //              share the same methods)
-                                       setMethods.add(strMeth);
-                               }
-                       }
-                       // Add interface and methods information into map
-                       mapCapabMethods.put(strInt, setMethods);
-               }
-       }
-
-
-       /**
-        * generateJavaInterfaces() generate stub interfaces based on the methods list in Java
-        */
-       public void generateJavaInterfaces() throws IOException {
-
-               // Create a new directory
-               createDirectory(dir);
-               for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
-
-                       // Open a new file to write into
-                       String newIntface = intMeth.getKey();
-                       FileWriter fw = new FileWriter(dir + "/" + newIntface + ".java");
-                       pw = new PrintWriter(new BufferedWriter(fw));
-                       // Write interface header
-                       println("");
-                       println("public interface " + newIntface + " {");
-                       // Write methods
-                       for (String method : intMeth.getValue()) {
-
-                               List<String> methParams = intDecl.getMethodParams(method);
-                               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-                               print("public " + intDecl.getMethodType(method) + " " +
-                                       method + "(");
-                               for (int i = 0; i < methParams.size(); i++) {
-                                        print(methPrmTypes.get(i) + " " + methParams.get(i));
-                                       // Check if this is the last element (don't print a comma)
-                                       if (i != methParams.size() - 1) {
-                                               print(", ");
-                                       }
-                               }
-                               println(");");
-                       }
-                       println("}");
-                       pw.close();
-                       System.out.println("IoTStubCompiler: Generated interface " + newIntface + ".java...");
-               }
-       }
-
-
-       /**
-        * generateCPlusInterfaces() generate stub interfaces based on the methods list in C++
-        * <p>
-        * For C++ we use virtual classe as interface
-        */
-       public void generateCPlusInterfaces() throws IOException {
-
-               // Create a new directory
-               createDirectory(dir);
-               for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
-
-                       // Open a new file to write into
-                       String newIntface = intMeth.getKey();
-                       FileWriter fw = new FileWriter(dir + "/" + newIntface + ".hpp");
-                       pw = new PrintWriter(new BufferedWriter(fw));
-                       // Write file headers
-                       println("#include<iostream>");
-                       println("");
-                       println("using namespace std;");
-                       println("");
-                       println("class " + newIntface);
-                       println("{");
-                       println("public:");
-                       // Write methods
-                       for (String method : intMeth.getValue()) {
-
-                               List<String> methParams = intDecl.getMethodParams(method);
-                               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-                               print("virtual " + convertType(intDecl.getMethodType(method)) + " " +
-                                       method + "(");
-                               for (int i = 0; i < methParams.size(); i++) {
-                                        print(convertType(methPrmTypes.get(i)) + " " + methParams.get(i));
-                                       // Check if this is the last element (don't print a comma)
-                                       if (i != methParams.size() - 1) {
-                                               print(", ");
-                                       }
-                               }
-                               println(") = 0;");
-                       }
-                       print("}");
-                       println(";");
-                       pw.close();
-                       System.out.println("IoTStubCompiler: Generated interface " + newIntface + ".hpp...");
-               }
-       }
-
-
-       /**
-        * generateJavaStubClasses() generate stubs based on the methods list in Java
-        */
-       public void generateJavaStubClasses() throws IOException {
-
-               // Create a new directory
-               createDirectory(dir);
-               for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
-
-                       // Open a new file to write into
-                       String newIntface = intMeth.getKey();
-                       String newStubClass = newIntface + "_Stub";
-                       FileWriter fw = new FileWriter(dir + "/" + newStubClass + ".java");
-                       pw = new PrintWriter(new BufferedWriter(fw));
-                       // Write interface header
-                       println("");
-                       println("public class " + newStubClass + " implements " + newIntface + " {");
-                       println("");
-                       // Write methods
-                       for (String method : intMeth.getValue()) {
-
-                               List<String> methParams = intDecl.getMethodParams(method);
-                               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-                               print("public " + intDecl.getMethodType(method) + " " +
-                                       method + "(");
-                               for (int i = 0; i < methParams.size(); i++) {
-                                        print(methPrmTypes.get(i) + " " + methParams.get(i));
-                                       // Check if this is the last element (don't print a comma)
-                                       if (i != methParams.size() - 1) {
-                                               print(", ");
-                                       }
-                               }
-                               println(") {");
-                               // Check if this is not "void"
-                               if (!intDecl.getMethodType(method).equals("void")) {
-                                       String retStmt = generateReturnStmt(intDecl.getMethodType(method));
-                                       println("return " + retStmt + ";");
-                               }
-                               println("}");
-                               println("");
-                       }
-                       println("}");
-                       pw.close();
-                       System.out.println("IoTStubCompiler: Generated stub class " + newStubClass + ".java...");
-               }
-       }
-
-
-       /**
-        * generateCPlusStubClasses() generate stubs based on the methods list in C++
-        */
-       public void generateCPlusStubClasses() throws IOException {
-
-               // Create a new directory
-               createDirectory(dir);
-               for (Map.Entry<String,Set<String>> intMeth : mapCapabMethods.entrySet()) {
-
-                       // Open a new file to write into
-                       String newIntface = intMeth.getKey();
-                       String newStubClass = newIntface + "_Stub";
-                       FileWriter fw = new FileWriter(dir + "/" + newStubClass + ".hpp");
-                       pw = new PrintWriter(new BufferedWriter(fw));
-                       // Write file headers
-                       println("#include<iostream>");
-                       println("#include \"" + newIntface + ".hpp\""); println("");            
-                       println("using namespace std;"); println("");
-                       println("class " + newStubClass + " : public " + newIntface);
-                       println("{");
-                       println("public:"); println("");
-                       // Add default constructor and destructor
-                       println(newStubClass + "() { }"); println("");
-                       println("~" + newStubClass + "() { }"); println("");            
-                       // Write methods
-                       for (String method : intMeth.getValue()) {
-
-                               List<String> methParams = intDecl.getMethodParams(method);
-                               List<String> methPrmTypes = intDecl.getMethodParamTypes(method);
-                               print(convertType(intDecl.getMethodType(method)) + " " +
-                                       method + "(");
-                               for (int i = 0; i < methParams.size(); i++) {
-                                        print(convertType(methPrmTypes.get(i)) + " " + methParams.get(i));
-                                       // Check if this is the last element (don't print a comma)
-                                       if (i != methParams.size() - 1) {
-                                               print(", ");
-                                       }
-                               }
-                               println(") { ");
-                               // Check if this is not "void"
-                               if (!intDecl.getMethodType(method).equals("void")) {
-                                       String retStmt = generateReturnStmt(intDecl.getMethodType(method));
-                                       if (retStmt.equals("null")) { // null = NULL in C++
-                                               retStmt = "NULL";
-                                       }
-                                       println("return " + retStmt + ";");
-                               }
-                               println("}"); println("");
-                       }
-                       print("}"); println(";");
-                       pw.close();
-                       System.out.println("IoTStubCompiler: Generated stub class " + newIntface + ".hpp...");
-               }
-       }
-
-
-       /**
-        * generateReturnStmt() generate return statement based on methType
-        */
-       public String generateReturnStmt(String methType) {
-
-               // Generate dummy returns for now
-               if (methType.equals("short")||
-                       methType.equals("int")  ||
-                       methType.equals("long") ||
-                       methType.equals("float")||
-                       methType.equals("double")) {
-
-                       return "1";
-               } else if ( methType.equals("String") ||
-                                       methType.equals("byte")) {
-  
-                       return "\"a\"";
-               } else if ( methType.equals("char")) {
-
-                       return "\'a\'";
-               } else if ( methType.equals("boolean")) {
-
-                       return "true";
-               } else {
-                       return "null";
-               }
-       }
-
-
-       /**
-        * setDirectory() set a new directory for stub files
-        */
-       public void setDirectory(String _dir) {
-
-               dir = _dir;
-       }
-
-
-       /**
-        * printUsage() prints the usage of this compiler
-        */
-       public static void printUsage() {
-
-               System.out.println();
-               System.out.println("Sentinel stub compiler version 1.0");
-               System.out.println("Copyright (c) 2015-2016 University of California, Irvine - Programming Language Group.");
-               System.out.println("All rights reserved.");
-               System.out.println("Usage:");
-               System.out.println("\tjava IoTStubCompiler --help\t\t\tDisplay this help texts");
-               System.out.println("\tjava IoTStubCompiler <policy-file>\t\tGenerate both Java and C++ stub files");
-               System.out.println("\tjava IoTStubCompiler <policy-file> [options]");
-               System.out.println("Options:");
-               System.out.println("\t-java\t<directory>\tGenerate Java stub files");
-               System.out.println("\t-cplus\t<directory>\tGenerate C++ stub files");
-               System.out.println();
-       }
-
-
-       /**================================================
-        * Helper functions to write stub codes into files
-        **================================================
-        */
-       boolean newline=true;
-       int tablevel=0;
-
-       private void print(String str) {
-               if (newline) {
-                       int tab=tablevel;
-                       if (str.equals("}"))
-                               tab--;
-                       for(int i=0; i<tab; i++)
-                               pw.print("\t");
-               }
-               pw.print(str);
-               updatetabbing(str);
-               newline=false;
-       }
-
-       /**
-        * This function converts Java to C++ type for compilation
-        */
-       private String convertType(String jType) {
-
-               // Generate dummy returns for now
-               if (jType.equals("short")||
-                       jType.equals("int")  ||
-                       jType.equals("long") ||
-                       jType.equals("char") ||
-                       jType.equals("float")||
-                       jType.equals("double")) {
-
-                       return jType;
-               } else if ( jType.equals("String")) {
-  
-                       return "string";
-               } else if ( jType.equals("byte")) {
-
-                       return "char";
-               } else if ( jType.equals("boolean")) {
-
-                       return "bool";
-               } else {
-                       return jType;
-               }       
-       }
-
-
-       private void println(String str) {
-               if (newline) {
-                       int tab = tablevel;
-                       if (str.equals("}"))
-                               tab--;
-                       for(int i=0; i<tab; i++)
-                               pw.print("\t");
-               }
-               pw.println(str);
-               updatetabbing(str);
-               newline = true;
-       }
-
-
-       private void updatetabbing(String str) {
-               tablevel+=count(str,'{')-count(str,'}');
-       }
-
-
-       private int count(String str, char key) {
-               char[] array = str.toCharArray();
-               int count = 0;
-               for(int i=0; i<array.length; i++) {
-                       if (array[i] == key)
-                               count++;
-               }
-               return count;
-       }
-
-
-       private void createDirectory(String dirName) {
-
-               File file = new File(dirName);
-               if (!file.exists()) {
-                       if (file.mkdir()) {
-                               System.out.println("IoTStubCompiler: Directory " + dirName + "has been created!");
-                       } else {
-                               System.out.println("IoTStubCompiler: Failed to create directory " + dirName + "!");
-                       }
-               } else {
-                       System.out.println("IoTStubCompiler: Directory " + dirName + " exists...");
-               }
-       }
-
-
-       public static void main(String[] args) throws Exception {
-
-               // Runtime options
-               if (args.length != 0) {
-                       // Display help
-                       if (args[0].equals("--help")) {
-                               IoTStubCompiler.printUsage();
-                       } else {
-                               // Initialize the symbol factory
-                               ComplexSymbolFactory csf = new ComplexSymbolFactory();
-                               // Create a buffering scanner wrapper
-                               ScannerBuffer lexer = 
-                                       new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[0])),csf));
-                               // Start parsing
-                               Parser p = new Parser(lexer,csf);
-                               ParseNode pn = (ParseNode) p.parse().value;
-                               // Handle parse-tree and process it
-                               String intFace = ParseTreeHandler.getOrigIntface(pn);
-                               //System.out.println("IoTStubCompiler: Original interface: " + intFace);
-                               IoTStubCompiler stubComp = new IoTStubCompiler(intFace, pn);
-                               // Generate all policy files if just policy file is provided
-                               stubComp.parsePolicyFile();
-                               stubComp.getMethodsForIntface();
-                               if (args.length == 1) {
-                                       stubComp.generateJavaInterfaces();
-                                       stubComp.generateJavaStubClasses();
-                                       stubComp.generateCPlusInterfaces();
-                                       stubComp.generateCPlusStubClasses();
-                               } else {
-                               // Check other options
-                                       int i = 1;
-                                       while(i < args.length) {
-                                               // Check whether <directory> is provided
-                                               if ((i + 1) < args.length) {
-                                                       stubComp.setDirectory(args[i+1]);
-                                               } else
-                                                       throw new Error("IoTStubCompiler: ERROR - please provide <directory> after option: " + args[i]);
-                                               if (args[i].equals("-java")) {
-                                                       stubComp.generateJavaInterfaces();
-                                                       stubComp.generateJavaStubClasses();
-                                               } else if (args[i].equals("-cplus")) {
-                                                       stubComp.generateCPlusInterfaces();
-                                                       stubComp.generateCPlusStubClasses();
-                                               } else
-                                                       throw new Error("IoTStubCompiler: ERROR - unrecognized command line option: " + args[i]);
-                                               i = i + 2;
-                                       }
-                               }
-                       }
-
-               } else {
-               // Need at least the policy file name
-                       IoTStubCompiler.printUsage();
-                       throw new Error("IoTStubCompiler: At least one argument (policy file) has to be provided!");
-               }
-       }
-}
-
-
-
-
index aa40a6e..0e9d534 100644 (file)
@@ -1,5 +1,3 @@
-package iotpolicy.parser;
-
 /* The following code was generated by JFlex 1.6.1 */
 
 // JFlex parser specification written by
@@ -9,6 +7,7 @@ package iotpolicy.parser;
 
 // Technische Universitaet Muenchen 
 // Fakultaet fuer Informatik 
+package iotpolicy.parser;
 
 import java_cup.runtime.Symbol;
 import java_cup.runtime.ComplexSymbolFactory;
@@ -46,13 +45,13 @@ public class Lexer implements java_cup.runtime.Scanner, sym {
    * Translates characters to character classes
    */
   private static final String ZZ_CMAP_PACKED = 
-    "\11\0\1\6\1\4\1\47\1\6\1\3\22\0\1\6\1\0\1\36"+
-    "\1\0\1\1\3\0\1\41\1\42\2\0\1\37\1\0\1\40\1\0"+
-    "\12\2\1\0\1\5\1\0\1\45\3\0\22\1\1\30\7\1\1\0"+
-    "\1\46\2\0\1\1\1\0\1\24\1\16\1\27\1\25\1\20\1\23"+
-    "\1\22\1\13\1\7\2\1\1\21\1\33\1\10\1\14\1\32\1\34"+
-    "\1\15\1\12\1\11\1\26\1\31\1\35\1\1\1\17\1\1\1\43"+
-    "\1\0\1\44\7\0\1\47\u1fa2\0\1\47\1\47\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\udfe6\0";
+    "\11\0\1\6\1\4\1\46\1\6\1\3\22\0\1\6\1\0\1\36"+
+    "\1\0\1\1\3\0\1\40\1\41\2\0\1\37\3\0\12\2\1\0"+
+    "\1\5\1\2\1\44\1\2\2\0\22\1\1\30\7\1\1\0\1\45"+
+    "\2\0\1\1\1\0\1\24\1\16\1\27\1\25\1\20\1\23\1\22"+
+    "\1\13\1\7\2\1\1\21\1\33\1\10\1\14\1\32\1\34\1\15"+
+    "\1\12\1\11\1\26\1\31\1\35\1\1\1\17\1\1\1\42\1\0"+
+    "\1\43\7\0\1\46\u1fa2\0\1\46\1\46\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\udfe6\0";
 
   /** 
    * Translates characters to character classes
@@ -67,14 +66,14 @@ public class Lexer implements java_cup.runtime.Scanner, sym {
   private static final String ZZ_ACTION_PACKED_0 =
     "\2\0\1\1\1\2\2\3\1\4\16\2\1\5\1\6"+
     "\1\7\1\10\1\11\1\12\1\13\1\14\1\15\1\16"+
-    "\1\17\1\0\10\2\1\20\11\2\1\21\1\22\1\23"+
-    "\1\24\1\25\25\2\1\26\1\27\3\2\1\30\2\2"+
-    "\1\31\2\2\1\32\2\2\1\33\2\2\1\34\7\2"+
-    "\1\35\2\2\1\36\2\2\1\37\1\40\1\41\2\2"+
-    "\1\42\3\2\1\43\2\2\1\44\3\2\1\45\1\46";
+    "\1\0\10\2\1\17\11\2\1\20\1\21\1\22\1\23"+
+    "\1\24\25\2\1\25\1\26\3\2\1\27\2\2\1\30"+
+    "\2\2\1\31\2\2\1\32\2\2\1\33\7\2\1\34"+
+    "\2\2\1\35\2\2\1\36\1\37\1\40\2\2\1\41"+
+    "\3\2\1\42\2\2\1\43\3\2\1\44\1\45";
 
   private static int [] zzUnpackAction() {
-    int [] result = new int[126];
+    int [] result = new int[125];
     int offset = 0;
     offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
     return result;
@@ -99,25 +98,25 @@ public class Lexer implements java_cup.runtime.Scanner, sym {
   private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
 
   private static final String ZZ_ROWMAP_PACKED_0 =
-    "\0\0\0\50\0\120\0\170\0\240\0\120\0\120\0\310"+
-    "\0\360\0\u0118\0\u0140\0\u0168\0\u0190\0\u01b8\0\u01e0\0\u0208"+
-    "\0\u0230\0\u0258\0\u0280\0\u02a8\0\u02d0\0\120\0\120\0\120"+
-    "\0\120\0\120\0\120\0\120\0\120\0\u02f8\0\120\0\u0320"+
-    "\0\u0348\0\u0370\0\u0398\0\u03c0\0\u03e8\0\u0410\0\u0438\0\u0460"+
-    "\0\u0488\0\170\0\u04b0\0\u04d8\0\u0500\0\u0528\0\u0550\0\u0578"+
-    "\0\u05a0\0\u05c8\0\u05f0\0\120\0\120\0\120\0\120\0\u0618"+
-    "\0\u0640\0\u0668\0\u0690\0\u06b8\0\u06e0\0\u0708\0\u0730\0\u0758"+
-    "\0\u0780\0\u07a8\0\u07d0\0\u07f8\0\u0820\0\u0848\0\u0870\0\u0898"+
-    "\0\u08c0\0\u08e8\0\u0910\0\u0938\0\u0960\0\170\0\170\0\u0988"+
-    "\0\u09b0\0\u09d8\0\170\0\u0a00\0\u0a28\0\170\0\u0a50\0\u0a78"+
-    "\0\170\0\u0aa0\0\u0ac8\0\170\0\u0af0\0\u0b18\0\170\0\u0b40"+
-    "\0\u0b68\0\u0b90\0\u0bb8\0\u0be0\0\u0c08\0\u0c30\0\170\0\u0c58"+
-    "\0\u0c80\0\170\0\u0ca8\0\u0cd0\0\170\0\170\0\170\0\u0cf8"+
-    "\0\u0d20\0\170\0\u0d48\0\u0d70\0\u0d98\0\170\0\u0dc0\0\u0de8"+
-    "\0\170\0\u0e10\0\u0e38\0\u0e60\0\170\0\170";
+    "\0\0\0\47\0\116\0\165\0\234\0\116\0\116\0\303"+
+    "\0\352\0\u0111\0\u0138\0\u015f\0\u0186\0\u01ad\0\u01d4\0\u01fb"+
+    "\0\u0222\0\u0249\0\u0270\0\u0297\0\u02be\0\116\0\116\0\116"+
+    "\0\116\0\116\0\116\0\116\0\u02e5\0\116\0\u030c\0\u0333"+
+    "\0\u035a\0\u0381\0\u03a8\0\u03cf\0\u03f6\0\u041d\0\u0444\0\u046b"+
+    "\0\165\0\u0492\0\u04b9\0\u04e0\0\u0507\0\u052e\0\u0555\0\u057c"+
+    "\0\u05a3\0\u05ca\0\116\0\116\0\116\0\116\0\u05f1\0\u0618"+
+    "\0\u063f\0\u0666\0\u068d\0\u06b4\0\u06db\0\u0702\0\u0729\0\u0750"+
+    "\0\u0777\0\u079e\0\u07c5\0\u07ec\0\u0813\0\u083a\0\u0861\0\u0888"+
+    "\0\u08af\0\u08d6\0\u08fd\0\u0924\0\165\0\165\0\u094b\0\u0972"+
+    "\0\u0999\0\165\0\u09c0\0\u09e7\0\165\0\u0a0e\0\u0a35\0\165"+
+    "\0\u0a5c\0\u0a83\0\165\0\u0aaa\0\u0ad1\0\165\0\u0af8\0\u0b1f"+
+    "\0\u0b46\0\u0b6d\0\u0b94\0\u0bbb\0\u0be2\0\165\0\u0c09\0\u0c30"+
+    "\0\165\0\u0c57\0\u0c7e\0\165\0\165\0\165\0\u0ca5\0\u0ccc"+
+    "\0\165\0\u0cf3\0\u0d1a\0\u0d41\0\165\0\u0d68\0\u0d8f\0\165"+
+    "\0\u0db6\0\u0ddd\0\u0e04\0\165\0\165";
 
   private static int [] zzUnpackRowMap() {
-    int [] result = new int[126];
+    int [] result = new int[125];
     int offset = 0;
     offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
     return result;
@@ -144,78 +143,77 @@ public class Lexer implements java_cup.runtime.Scanner, sym {
     "\2\4\1\11\2\4\1\12\1\13\2\4\1\14\1\4"+
     "\1\15\1\16\1\17\1\4\1\20\1\21\1\22\1\23"+
     "\1\24\1\4\1\25\1\26\1\27\1\30\1\31\1\32"+
-    "\1\33\1\34\1\35\1\3\1\0\3\36\1\0\1\3"+
-    "\31\36\1\37\7\36\1\40\1\36\51\0\2\4\4\0"+
-    "\27\4\16\0\1\41\44\0\2\4\4\0\1\4\1\42"+
-    "\25\4\13\0\2\4\4\0\2\4\1\43\1\4\1\44"+
-    "\22\4\13\0\2\4\4\0\11\4\1\45\15\4\13\0"+
-    "\2\4\4\0\5\4\1\46\2\4\1\47\16\4\13\0"+
-    "\2\4\4\0\5\4\1\50\21\4\13\0\2\4\4\0"+
-    "\12\4\1\51\14\4\13\0\2\4\4\0\3\4\1\52"+
-    "\23\4\13\0\2\4\4\0\5\4\1\53\3\4\1\54"+
-    "\15\4\13\0\2\4\4\0\4\4\1\55\10\4\1\56"+
-    "\11\4\13\0\2\4\4\0\2\4\1\57\24\4\13\0"+
-    "\2\4\4\0\5\4\1\60\21\4\13\0\2\4\4\0"+
-    "\17\4\1\61\7\4\13\0\2\4\4\0\11\4\1\62"+
-    "\15\4\13\0\2\4\4\0\1\63\26\4\12\0\3\36"+
-    "\2\0\31\36\1\0\7\36\1\0\1\36\10\0\1\64"+
-    "\1\65\3\0\1\66\20\0\1\67\16\0\1\6\43\0"+
-    "\2\4\4\0\2\4\1\70\24\4\13\0\2\4\4\0"+
-    "\6\4\1\71\20\4\13\0\2\4\4\0\5\4\1\72"+
-    "\21\4\13\0\2\4\4\0\25\4\1\73\1\4\13\0"+
-    "\2\4\4\0\5\4\1\74\21\4\13\0\2\4\4\0"+
-    "\2\4\1\75\24\4\13\0\2\4\4\0\1\4\1\76"+
-    "\25\4\13\0\2\4\4\0\5\4\1\77\21\4\13\0"+
-    "\2\4\4\0\17\4\1\100\7\4\13\0\2\4\4\0"+
-    "\3\4\1\101\23\4\13\0\2\4\4\0\15\4\1\102"+
-    "\11\4\13\0\2\4\4\0\23\4\1\103\3\4\13\0"+
-    "\2\4\4\0\6\4\1\104\20\4\13\0\2\4\4\0"+
-    "\1\105\26\4\13\0\2\4\4\0\7\4\1\106\17\4"+
-    "\13\0\2\4\4\0\2\4\1\107\24\4\13\0\2\4"+
-    "\4\0\2\4\1\110\24\4\13\0\2\4\4\0\11\4"+
-    "\1\111\15\4\13\0\2\4\4\0\1\112\26\4\13\0"+
-    "\2\4\4\0\6\4\1\113\20\4\13\0\2\4\4\0"+
-    "\17\4\1\114\7\4\13\0\2\4\4\0\12\4\1\115"+
-    "\14\4\13\0\2\4\4\0\11\4\1\116\15\4\13\0"+
-    "\2\4\4\0\13\4\1\117\13\4\13\0\2\4\4\0"+
-    "\15\4\1\120\11\4\13\0\2\4\4\0\7\4\1\121"+
-    "\17\4\13\0\2\4\4\0\20\4\1\122\6\4\13\0"+
-    "\2\4\4\0\6\4\1\123\20\4\13\0\2\4\4\0"+
-    "\15\4\1\124\11\4\13\0\2\4\4\0\1\125\26\4"+
-    "\13\0\2\4\4\0\16\4\1\126\10\4\13\0\2\4"+
-    "\4\0\12\4\1\127\14\4\13\0\2\4\4\0\4\4"+
-    "\1\130\22\4\13\0\2\4\4\0\4\4\1\131\22\4"+
-    "\13\0\2\4\4\0\6\4\1\132\20\4\13\0\2\4"+
-    "\4\0\1\4\1\133\25\4\13\0\2\4\4\0\2\4"+
-    "\1\134\24\4\13\0\2\4\4\0\1\135\26\4\13\0"+
-    "\2\4\4\0\11\4\1\136\15\4\13\0\2\4\4\0"+
-    "\2\4\1\137\24\4\13\0\2\4\4\0\12\4\1\140"+
-    "\14\4\13\0\2\4\4\0\6\4\1\141\20\4\13\0"+
-    "\2\4\4\0\7\4\1\142\17\4\13\0\2\4\4\0"+
-    "\1\4\1\143\25\4\13\0\2\4\4\0\1\144\26\4"+
-    "\13\0\2\4\4\0\5\4\1\145\21\4\13\0\2\4"+
-    "\4\0\14\4\1\146\12\4\13\0\2\4\4\0\13\4"+
-    "\1\147\13\4\13\0\2\4\4\0\6\4\1\150\20\4"+
-    "\13\0\2\4\4\0\15\4\1\151\11\4\13\0\2\4"+
-    "\4\0\11\4\1\152\15\4\13\0\2\4\4\0\1\153"+
-    "\26\4\13\0\2\4\4\0\1\154\26\4\13\0\2\4"+
-    "\4\0\13\4\1\155\13\4\13\0\2\4\4\0\20\4"+
-    "\1\156\6\4\13\0\2\4\4\0\16\4\1\157\10\4"+
-    "\13\0\2\4\4\0\15\4\1\160\11\4\13\0\2\4"+
-    "\4\0\11\4\1\161\15\4\13\0\2\4\4\0\1\4"+
-    "\1\162\25\4\13\0\2\4\4\0\23\4\1\163\3\4"+
-    "\13\0\2\4\4\0\12\4\1\164\14\4\13\0\2\4"+
-    "\4\0\20\4\1\165\6\4\13\0\2\4\4\0\3\4"+
-    "\1\166\23\4\13\0\2\4\4\0\2\4\1\167\24\4"+
-    "\13\0\2\4\4\0\1\170\26\4\13\0\2\4\4\0"+
-    "\11\4\1\171\15\4\13\0\2\4\4\0\1\172\26\4"+
-    "\13\0\2\4\4\0\2\4\1\173\24\4\13\0\2\4"+
-    "\4\0\5\4\1\174\21\4\13\0\2\4\4\0\10\4"+
-    "\1\175\16\4\13\0\2\4\4\0\1\4\1\176\25\4"+
-    "\12\0";
+    "\1\33\1\34\1\3\1\0\3\35\1\0\1\3\31\35"+
+    "\1\36\6\35\1\37\1\35\50\0\2\4\4\0\27\4"+
+    "\15\0\1\40\43\0\2\4\4\0\1\4\1\41\25\4"+
+    "\12\0\2\4\4\0\2\4\1\42\1\4\1\43\22\4"+
+    "\12\0\2\4\4\0\11\4\1\44\15\4\12\0\2\4"+
+    "\4\0\5\4\1\45\2\4\1\46\16\4\12\0\2\4"+
+    "\4\0\5\4\1\47\21\4\12\0\2\4\4\0\12\4"+
+    "\1\50\14\4\12\0\2\4\4\0\3\4\1\51\23\4"+
+    "\12\0\2\4\4\0\5\4\1\52\3\4\1\53\15\4"+
+    "\12\0\2\4\4\0\4\4\1\54\10\4\1\55\11\4"+
+    "\12\0\2\4\4\0\2\4\1\56\24\4\12\0\2\4"+
+    "\4\0\5\4\1\57\21\4\12\0\2\4\4\0\17\4"+
+    "\1\60\7\4\12\0\2\4\4\0\11\4\1\61\15\4"+
+    "\12\0\2\4\4\0\1\62\26\4\11\0\3\35\2\0"+
+    "\31\35\1\0\6\35\1\0\1\35\10\0\1\63\1\64"+
+    "\3\0\1\65\20\0\1\66\15\0\1\6\42\0\2\4"+
+    "\4\0\2\4\1\67\24\4\12\0\2\4\4\0\6\4"+
+    "\1\70\20\4\12\0\2\4\4\0\5\4\1\71\21\4"+
+    "\12\0\2\4\4\0\25\4\1\72\1\4\12\0\2\4"+
+    "\4\0\5\4\1\73\21\4\12\0\2\4\4\0\2\4"+
+    "\1\74\24\4\12\0\2\4\4\0\1\4\1\75\25\4"+
+    "\12\0\2\4\4\0\5\4\1\76\21\4\12\0\2\4"+
+    "\4\0\17\4\1\77\7\4\12\0\2\4\4\0\3\4"+
+    "\1\100\23\4\12\0\2\4\4\0\15\4\1\101\11\4"+
+    "\12\0\2\4\4\0\23\4\1\102\3\4\12\0\2\4"+
+    "\4\0\6\4\1\103\20\4\12\0\2\4\4\0\1\104"+
+    "\26\4\12\0\2\4\4\0\7\4\1\105\17\4\12\0"+
+    "\2\4\4\0\2\4\1\106\24\4\12\0\2\4\4\0"+
+    "\2\4\1\107\24\4\12\0\2\4\4\0\11\4\1\110"+
+    "\15\4\12\0\2\4\4\0\1\111\26\4\12\0\2\4"+
+    "\4\0\6\4\1\112\20\4\12\0\2\4\4\0\17\4"+
+    "\1\113\7\4\12\0\2\4\4\0\12\4\1\114\14\4"+
+    "\12\0\2\4\4\0\11\4\1\115\15\4\12\0\2\4"+
+    "\4\0\13\4\1\116\13\4\12\0\2\4\4\0\15\4"+
+    "\1\117\11\4\12\0\2\4\4\0\7\4\1\120\17\4"+
+    "\12\0\2\4\4\0\20\4\1\121\6\4\12\0\2\4"+
+    "\4\0\6\4\1\122\20\4\12\0\2\4\4\0\15\4"+
+    "\1\123\11\4\12\0\2\4\4\0\1\124\26\4\12\0"+
+    "\2\4\4\0\16\4\1\125\10\4\12\0\2\4\4\0"+
+    "\12\4\1\126\14\4\12\0\2\4\4\0\4\4\1\127"+
+    "\22\4\12\0\2\4\4\0\4\4\1\130\22\4\12\0"+
+    "\2\4\4\0\6\4\1\131\20\4\12\0\2\4\4\0"+
+    "\1\4\1\132\25\4\12\0\2\4\4\0\2\4\1\133"+
+    "\24\4\12\0\2\4\4\0\1\134\26\4\12\0\2\4"+
+    "\4\0\11\4\1\135\15\4\12\0\2\4\4\0\2\4"+
+    "\1\136\24\4\12\0\2\4\4\0\12\4\1\137\14\4"+
+    "\12\0\2\4\4\0\6\4\1\140\20\4\12\0\2\4"+
+    "\4\0\7\4\1\141\17\4\12\0\2\4\4\0\1\4"+
+    "\1\142\25\4\12\0\2\4\4\0\1\143\26\4\12\0"+
+    "\2\4\4\0\5\4\1\144\21\4\12\0\2\4\4\0"+
+    "\14\4\1\145\12\4\12\0\2\4\4\0\13\4\1\146"+
+    "\13\4\12\0\2\4\4\0\6\4\1\147\20\4\12\0"+
+    "\2\4\4\0\15\4\1\150\11\4\12\0\2\4\4\0"+
+    "\11\4\1\151\15\4\12\0\2\4\4\0\1\152\26\4"+
+    "\12\0\2\4\4\0\1\153\26\4\12\0\2\4\4\0"+
+    "\13\4\1\154\13\4\12\0\2\4\4\0\20\4\1\155"+
+    "\6\4\12\0\2\4\4\0\16\4\1\156\10\4\12\0"+
+    "\2\4\4\0\15\4\1\157\11\4\12\0\2\4\4\0"+
+    "\11\4\1\160\15\4\12\0\2\4\4\0\1\4\1\161"+
+    "\25\4\12\0\2\4\4\0\23\4\1\162\3\4\12\0"+
+    "\2\4\4\0\12\4\1\163\14\4\12\0\2\4\4\0"+
+    "\20\4\1\164\6\4\12\0\2\4\4\0\3\4\1\165"+
+    "\23\4\12\0\2\4\4\0\2\4\1\166\24\4\12\0"+
+    "\2\4\4\0\1\167\26\4\12\0\2\4\4\0\11\4"+
+    "\1\170\15\4\12\0\2\4\4\0\1\171\26\4\12\0"+
+    "\2\4\4\0\2\4\1\172\24\4\12\0\2\4\4\0"+
+    "\5\4\1\173\21\4\12\0\2\4\4\0\10\4\1\174"+
+    "\16\4\12\0\2\4\4\0\1\4\1\175\25\4\11\0";
 
   private static int [] zzUnpackTrans() {
-    int [] result = new int[3720];
+    int [] result = new int[3627];
     int offset = 0;
     offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
     return result;
@@ -253,11 +251,11 @@ public class Lexer implements java_cup.runtime.Scanner, sym {
   private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
 
   private static final String ZZ_ATTRIBUTE_PACKED_0 =
-    "\2\0\1\11\2\1\2\11\16\1\10\11\1\1\1\11"+
+    "\2\0\1\11\2\1\2\11\16\1\7\11\1\1\1\11"+
     "\1\1\1\0\22\1\4\11\107\1";
 
   private static int [] zzUnpackAttribute() {
-    int [] result = new int[126];
+    int [] result = new int[125];
     int offset = 0;
     offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
     return result;
@@ -379,7 +377,7 @@ public class Lexer implements java_cup.runtime.Scanner, sym {
     char [] map = new char[0x110000];
     int i = 0;  /* index in packed string  */
     int j = 0;  /* index in unpacked array */
-    while (i < 168) {
+    while (i < 166) {
       int  count = packed.charAt(i++);
       char value = packed.charAt(i++);
       do map[j++] = value; while (--count > 0);
@@ -749,156 +747,152 @@ public class Lexer implements java_cup.runtime.Scanner, sym {
             { /* throw new Error("Illegal character <"+ yytext()+">");*/
                    error("Illegal character <"+ yytext()+">");
             }
-          case 39: break;
+          case 38: break;
           case 2: 
             { return symbol("Identifier",IDENT, yytext());
             }
-          case 40: break;
+          case 39: break;
           case 3: 
             { /* ignore */
             }
-          case 41: break;
+          case 40: break;
           case 4: 
             { return symbol("semicolon",SEMICOLON);
             }
-          case 42: break;
+          case 41: break;
           case 5: 
             { string.setLength(0); yybegin(STRING);
             }
-          case 43: break;
+          case 42: break;
           case 6: 
             { return symbol("comma",COMMA);
             }
-          case 44: break;
+          case 43: break;
           case 7: 
-            { return symbol("dot",DOT);
-            }
-          case 45: break;
-          case 8: 
             { return symbol("(",LPAR);
             }
-          case 46: break;
-          case 9
+          case 44: break;
+          case 8
             { return symbol(")",RPAR);
             }
-          case 47: break;
-          case 10
+          case 45: break;
+          case 9
             { return symbol("{",BEGIN);
             }
-          case 48: break;
-          case 11
+          case 46: break;
+          case 10
             { return symbol("}",END);
             }
-          case 49: break;
-          case 12
+          case 47: break;
+          case 11
             { return symbol("=",ASSIGN);
             }
-          case 50: break;
-          case 13
+          case 48: break;
+          case 12
             { string.append( yytext() );
             }
-          case 51: break;
-          case 14
+          case 49: break;
+          case 13
             { yybegin(YYINITIAL); 
       return symbol("StringConst",STRINGCONST,string.toString(),string.length());
             }
-          case 52: break;
-          case 15
+          case 50: break;
+          case 14
             { string.append('\\');
             }
-          case 53: break;
-          case 16
+          case 51: break;
+          case 15
             { return symbol("as",AS);
             }
-          case 54: break;
-          case 17
+          case 52: break;
+          case 16
             { string.append('\n');
             }
-          case 55: break;
-          case 18
+          case 53: break;
+          case 17
             { string.append('\t');
             }
-          case 56: break;
-          case 19
+          case 54: break;
+          case 18
             { string.append('\r');
             }
-          case 57: break;
-          case 20
+          case 55: break;
+          case 19
             { string.append('\"');
             }
-          case 58: break;
-          case 21
+          case 56: break;
+          case 20
             { return symbol("int",TYPE, "int" );
             }
-          case 59: break;
-          case 22
+          case 57: break;
+          case 21
             { return symbol("byte",TYPE, "byte" );
             }
-          case 60: break;
-          case 23
+          case 58: break;
+          case 22
             { return symbol("long",TYPE, "long" );
             }
-          case 61: break;
-          case 24
+          case 59: break;
+          case 23
             { return symbol("char",TYPE, "char" );
             }
-          case 62: break;
-          case 25
+          case 60: break;
+          case 24
             { return symbol("void",TYPE, "void" );
             }
-          case 63: break;
-          case 26
+          case 61: break;
+          case 25
             { return symbol("with",WITH);
             }
-          case 64: break;
-          case 27
+          case 62: break;
+          case 26
             { return symbol("short",TYPE, "short" );
             }
-          case 65: break;
-          case 28
+          case 63: break;
+          case 27
             { return symbol("float",TYPE, "float" );
             }
-          case 66: break;
-          case 29
+          case 64: break;
+          case 28
             { return symbol("string",TYPE, "String" );
             }
-          case 67: break;
-          case 30
+          case 65: break;
+          case 29
             { return symbol("double",TYPE, "double" );
             }
-          case 68: break;
-          case 31
+          case 66: break;
+          case 30
             { return symbol("String",TYPE, "String" );
             }
-          case 69: break;
-          case 32
+          case 67: break;
+          case 31
             { return symbol("public",PUBLIC);
             }
-          case 70: break;
-          case 33
+          case 68: break;
+          case 32
             { return symbol("method",METHOD);
             }
-          case 71: break;
-          case 34
+          case 69: break;
+          case 33
             { return symbol("boolean",TYPE, "boolean" );
             }
-          case 72: break;
-          case 35
+          case 70: break;
+          case 34
             { return symbol("requires",REQUIRES);
             }
-          case 73: break;
-          case 36
+          case 71: break;
+          case 35
             { return symbol("interface",INTERFACE);
             }
-          case 74: break;
-          case 37
+          case 72: break;
+          case 36
             { return symbol("capability",CAPABILITY);
             }
-          case 75: break;
-          case 38
+          case 73: break;
+          case 37
             { return symbol("description",DESCRIPTION);
             }
-          case 76: break;
+          case 74: break;
           default:
             zzScanError(ZZ_NO_MATCH);
         }
index f06a0b9..cc7af92 100644 (file)
@@ -1,8 +1,8 @@
-package iotpolicy.parser;
 
 //----------------------------------------------------
 // The following code was generated by CUP v0.11b 20160615 (GIT 4ac7450)
 //----------------------------------------------------
+package iotpolicy.parser;
 
 import java_cup.runtime.ComplexSymbolFactory;
 import java_cup.runtime.ScannerBuffer;
@@ -15,7 +15,6 @@ import javax.xml.transform.stream.*;
 import java_cup.runtime.XMLElement;
 
 import iotpolicy.tree.ParseNode;
-import iotpolicy.tree.ParseNodeVector;
 
 /** CUP v0.11b 20160615 (GIT 4ac7450) generated parser.
   */
@@ -40,15 +39,15 @@ public class Parser extends java_cup.runtime.lr_parser {
   /** Production table. */
   protected static final short _production_table[][] = 
     unpackFromStrings(new String[] {
-    "\000\032\000\002\002\005\000\002\002\004\000\002\003" +
-    "\010\000\002\003\002\000\002\004\004\000\002\004\002" +
-    "\000\002\005\011\000\002\006\004\000\002\006\002\000" +
-    "\002\007\005\000\002\007\004\000\002\007\005\000\002" +
-    "\007\004\000\002\010\004\000\002\010\002\000\002\011" +
-    "\011\000\002\012\004\000\002\012\002\000\002\013\006" +
-    "\000\002\013\006\000\002\014\004\000\002\014\002\000" +
-    "\002\015\012\000\002\016\003\000\002\016\005\000\002" +
-    "\016\002" });
+    "\000\033\000\002\002\003\000\002\002\004\000\002\002" +
+    "\003\000\002\003\011\000\002\004\004\000\002\004\002" +
+    "\000\002\005\011\000\002\005\011\000\002\006\004\000" +
+    "\002\006\002\000\002\007\005\000\002\007\004\000\002" +
+    "\007\005\000\002\007\004\000\002\010\004\000\002\010" +
+    "\002\000\002\011\007\000\002\012\004\000\002\012\002" +
+    "\000\002\013\006\000\002\013\006\000\002\014\004\000" +
+    "\002\014\002\000\002\015\012\000\002\016\003\000\002" +
+    "\016\005\000\002\016\002" });
 
   /** Access to production table. */
   public short[][] production_table() {return _production_table;}
@@ -56,40 +55,43 @@ public class Parser extends java_cup.runtime.lr_parser {
   /** Parse-action table. */
   protected static final short[][] _action_table = 
     unpackFromStrings(new String[] {
-    "\000\070\000\012\002\ufffe\014\005\016\ufffe\021\ufffe\001" +
-    "\002\000\010\002\ufff3\016\ufff3\021\ufff3\001\002\000\004" +
-    "\015\010\001\002\000\004\002\007\001\002\000\004\002" +
-    "\000\001\002\000\004\025\011\001\002\000\004\011\012" +
-    "\001\002\000\006\012\ufffc\014\ufffc\001\002\000\006\012" +
-    "\016\014\015\001\002\000\006\012\ufffd\014\ufffd\001\002" +
-    "\000\004\024\017\001\002\000\010\002\uffff\016\uffff\021" +
-    "\uffff\001\002\000\004\025\020\001\002\000\004\007\021" +
-    "\001\002\000\010\010\ufff9\024\ufff9\025\ufff9\001\002\000" +
-    "\010\010\025\024\026\025\023\001\002\000\004\025\032" +
-    "\001\002\000\010\010\ufffa\024\ufffa\025\ufffa\001\002\000" +
-    "\004\004\031\001\002\000\004\025\027\001\002\000\012" +
-    "\005\030\010\ufff7\024\ufff7\025\ufff7\001\002\000\010\010" +
-    "\ufff8\024\ufff8\025\ufff8\001\002\000\006\012\ufffb\014\ufffb" +
-    "\001\002\000\012\005\033\010\ufff5\024\ufff5\025\ufff5\001" +
-    "\002\000\010\010\ufff6\024\ufff6\025\ufff6\001\002\000\010" +
-    "\002\uffec\016\037\021\uffec\001\002\000\010\002\ufff4\016" +
-    "\ufff4\021\ufff4\001\002\000\006\002\001\021\057\001\002" +
-    "\000\004\025\040\001\002\000\004\006\041\001\002\000" +
-    "\004\025\042\001\002\000\004\011\043\001\002\000\010" +
-    "\012\ufff0\017\ufff0\020\ufff0\001\002\000\010\012\047\017" +
-    "\046\020\050\001\002\000\010\012\ufff1\017\ufff1\020\ufff1" +
-    "\001\002\000\004\013\054\001\002\000\010\002\ufff2\016" +
-    "\ufff2\021\ufff2\001\002\000\004\013\051\001\002\000\004" +
-    "\025\052\001\002\000\004\004\053\001\002\000\010\012" +
-    "\uffee\017\uffee\020\uffee\001\002\000\004\026\055\001\002" +
-    "\000\004\004\056\001\002\000\010\012\uffef\017\uffef\020" +
-    "\uffef\001\002\000\004\025\061\001\002\000\006\002\uffed" +
-    "\021\uffed\001\002\000\004\022\062\001\002\000\010\005" +
-    "\uffe8\023\uffe8\025\063\001\002\000\006\005\uffea\023\uffea" +
-    "\001\002\000\006\005\065\023\066\001\002\000\004\025" +
-    "\072\001\002\000\004\015\067\001\002\000\004\025\070" +
-    "\001\002\000\004\004\071\001\002\000\006\002\uffeb\021" +
-    "\uffeb\001\002\000\006\005\uffe9\023\uffe9\001\002" });
+    "\000\074\000\010\002\uffeb\013\006\020\uffeb\001\002\000" +
+    "\004\002\001\001\002\000\006\002\uffff\020\063\001\002" +
+    "\000\004\014\011\001\002\000\004\002\010\001\002\000" +
+    "\004\002\000\001\002\000\004\024\012\001\002\000\004" +
+    "\010\013\001\002\000\010\011\ufffc\013\ufffc\015\ufffc\001" +
+    "\002\000\010\011\ufff2\013\016\015\ufff2\001\002\000\010" +
+    "\011\ufffd\013\ufffd\015\ufffd\001\002\000\006\023\041\024" +
+    "\040\001\002\000\006\011\022\015\021\001\002\000\006" +
+    "\011\ufff3\015\ufff3\001\002\000\004\024\023\001\002\000" +
+    "\004\002\ufffe\001\002\000\004\010\024\001\002\000\010" +
+    "\011\uffef\016\uffef\017\uffef\001\002\000\010\011\030\016" +
+    "\027\017\031\001\002\000\010\011\ufff0\016\ufff0\017\ufff0" +
+    "\001\002\000\004\012\035\001\002\000\006\011\ufff1\015" +
+    "\ufff1\001\002\000\004\012\032\001\002\000\004\025\033" +
+    "\001\002\000\004\004\034\001\002\000\010\011\uffed\016" +
+    "\uffed\017\uffed\001\002\000\004\025\036\001\002\000\004" +
+    "\004\037\001\002\000\010\011\uffee\016\uffee\017\uffee\001" +
+    "\002\000\004\024\056\001\002\000\004\024\042\001\002" +
+    "\000\004\006\043\001\002\000\010\007\ufff8\023\ufff8\024" +
+    "\ufff8\001\002\000\010\007\047\023\050\024\045\001\002" +
+    "\000\004\024\054\001\002\000\010\007\ufff9\023\ufff9\024" +
+    "\ufff9\001\002\000\004\004\053\001\002\000\004\024\051" +
+    "\001\002\000\012\005\052\007\ufff6\023\ufff6\024\ufff6\001" +
+    "\002\000\010\007\ufff7\023\ufff7\024\ufff7\001\002\000\010" +
+    "\011\ufffb\013\ufffb\015\ufffb\001\002\000\012\005\055\007" +
+    "\ufff4\023\ufff4\024\ufff4\001\002\000\010\007\ufff5\023\ufff5" +
+    "\024\ufff5\001\002\000\004\006\057\001\002\000\010\007" +
+    "\ufff8\023\ufff8\024\ufff8\001\002\000\010\007\061\023\050" +
+    "\024\045\001\002\000\004\004\062\001\002\000\010\011" +
+    "\ufffa\013\ufffa\015\ufffa\001\002\000\004\024\065\001\002" +
+    "\000\006\002\uffec\020\uffec\001\002\000\004\021\066\001" +
+    "\002\000\010\005\uffe7\022\uffe7\024\070\001\002\000\006" +
+    "\005\071\022\072\001\002\000\006\005\uffe9\022\uffe9\001" +
+    "\002\000\004\024\076\001\002\000\004\014\073\001\002" +
+    "\000\004\024\074\001\002\000\004\004\075\001\002\000" +
+    "\006\002\uffea\020\uffea\001\002\000\006\005\uffe8\022\uffe8" +
+    "\001\002" });
 
   /** Access to parse-action table. */
   public short[][] action_table() {return _action_table;}
@@ -97,26 +99,27 @@ public class Parser extends java_cup.runtime.lr_parser {
   /** <code>reduce_goto</code> table. */
   protected static final short[][] _reduce_table = 
     unpackFromStrings(new String[] {
-    "\000\070\000\006\002\005\003\003\001\001\000\004\010" +
-    "\033\001\001\000\002\001\001\000\002\001\001\000\002" +
-    "\001\001\000\002\001\001\000\002\001\001\000\004\004" +
-    "\012\001\001\000\004\005\013\001\001\000\002\001\001" +
+    "\000\074\000\010\002\006\003\003\014\004\001\001\000" +
+    "\002\001\001\000\004\015\063\001\001\000\002\001\001" +
     "\000\002\001\001\000\002\001\001\000\002\001\001\000" +
-    "\002\001\001\000\004\006\021\001\001\000\004\007\023" +
+    "\002\001\001\000\004\004\013\001\001\000\006\005\014" +
+    "\010\016\001\001\000\002\001\001\000\002\001\001\000" +
+    "\004\011\017\001\001\000\002\001\001\000\002\001\001" +
+    "\000\002\001\001\000\002\001\001\000\004\012\024\001" +
+    "\001\000\004\013\025\001\001\000\002\001\001\000\002" +
     "\001\001\000\002\001\001\000\002\001\001\000\002\001" +
     "\001\000\002\001\001\000\002\001\001\000\002\001\001" +
     "\000\002\001\001\000\002\001\001\000\002\001\001\000" +
-    "\006\011\034\014\035\001\001\000\002\001\001\000\004" +
-    "\015\057\001\001\000\002\001\001\000\002\001\001\000" +
-    "\002\001\001\000\002\001\001\000\004\012\043\001\001" +
-    "\000\004\013\044\001\001\000\002\001\001\000\002\001" +
+    "\002\001\001\000\002\001\001\000\004\006\043\001\001" +
+    "\000\004\007\045\001\001\000\002\001\001\000\002\001" +
     "\001\000\002\001\001\000\002\001\001\000\002\001\001" +
     "\000\002\001\001\000\002\001\001\000\002\001\001\000" +
-    "\002\001\001\000\002\001\001\000\002\001\001\000\002" +
-    "\001\001\000\002\001\001\000\004\016\063\001\001\000" +
-    "\002\001\001\000\002\001\001\000\002\001\001\000\002" +
-    "\001\001\000\002\001\001\000\002\001\001\000\002\001" +
-    "\001\000\002\001\001" });
+    "\002\001\001\000\002\001\001\000\004\006\057\001\001" +
+    "\000\004\007\045\001\001\000\002\001\001\000\002\001" +
+    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +
+    "\000\004\016\066\001\001\000\002\001\001\000\002\001" +
+    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +
+    "\000\002\001\001\000\002\001\001\000\002\001\001" });
 
   /** Access to <code>reduce_goto</code> table. */
   public short[][] reduce_table() {return _reduce_table;}
@@ -166,107 +169,6 @@ public class Parser extends java_cup.runtime.lr_parser {
       // start parsing
       Parser p = new Parser(lexer,csf);
       ParseNode pn = (ParseNode) p.parse().value;
-
-      //System.out.println("INTERFACE: ");
-      System.out.println(pn);
-      ParseNodeVector pnv = pn.getChildren();
-      /*System.out.println("Children: " + pnv.size());
-      ParseNode pnIntChild = pnv.elementAt(0);
-      System.out.println("Child 1: " + pnIntChild.getLabel());
-      System.out.println("Child 1: " + pnIntChild.getLiteral());
-      System.out.println();
-
-      ParseNodeVector pnIntChildren = pnIntChild.getChildren();
-      System.out.println("Grand children: " + pnIntChildren.size());
-      ParseNode pnIntGrandChild1 = pnIntChildren.elementAt(0);
-      System.out.println("Child 1: " + pnIntGrandChild1.getLabel());
-      System.out.println("Child 1: " + pnIntGrandChild1.getLiteral());
-      System.out.println("Great grand children: " + pnIntGrandChild1.getChildren().size());
-      System.out.println();
-
-      ParseNode pnIntGrandChild2 = pnIntChildren.elementAt(1);
-      System.out.println("Child 2: " + pnIntGrandChild2.getLabel());
-      System.out.println("Child 2: " + pnIntGrandChild2.getLiteral());
-      System.out.println("Great grand children: " + pnIntGrandChild2.getChildren().size());
-      System.out.println();
-      System.out.println();*/
-
-      System.out.println("CAPABILITIES: ");
-      ParseNode pnCapabChild = pnv.elementAt(1);
-      System.out.println("Child 2: " + pnv.elementAt(1).getLabel());
-      System.out.println("Child 2: " + pnv.elementAt(1).getLiteral());
-      ParseNodeVector pnvCap = pnCapabChild.getChildren();
-      System.out.println("Grand children: " + pnvCap.size());
-      ParseNode pnCapGrandChild1 = pnvCap.elementAt(0);
-      System.out.println("Child 1: " + pnCapGrandChild1.getLabel());
-      System.out.println("Child 1: " + pnCapGrandChild1.getLiteral());
-      ParseNodeVector pnvCap2 = pnCapGrandChild1.getChildren();
-      System.out.println("Great grand children: " + pnvCap2.size());
-      ParseNode pnCapGreatGrandChild1 = pnvCap2.elementAt(0);
-      System.out.println("Great grand Child 1: " + pnCapGreatGrandChild1.getLabel());
-      System.out.println("Great grand Child 1: " + pnCapGreatGrandChild1.getLiteral());
-      ParseNode pnCapGreatGrandChild2 = pnvCap2.elementAt(1);
-      System.out.println("Great grand Child 2: " + pnCapGreatGrandChild2.getLabel());
-      System.out.println("Great grand Child 2: " + pnCapGreatGrandChild2.getLiteral());
-      ParseNode pnCapGreatGrandChild3 = pnvCap2.elementAt(2);
-      System.out.println("Great grand Child 3: " + pnCapGreatGrandChild3.getLabel());
-      System.out.println("Great grand Child 3: " + pnCapGreatGrandChild3.getLiteral());
-      ParseNodeVector pnvCap3 = pnCapGreatGrandChild3.getChildren();
-      System.out.println("Great great grand children: " + pnvCap3.size());
-      ParseNode pnCapGreatGreatGrandChild1 = pnvCap3.elementAt(0);
-      System.out.println("Great great grand Child 1: " + pnCapGreatGreatGrandChild1.getLabel());
-      System.out.println("Great great grand Child 1: " + pnCapGreatGreatGrandChild1.getLiteral());
-      ParseNodeVector pnvDesc = pnCapGreatGreatGrandChild1.getChildren();
-      System.out.println("Great great great grand children: " + pnvDesc.size());
-      ParseNode pnDesc = pnvDesc.elementAt(0);
-      System.out.println("Description: " + pnDesc.getLabel());
-      System.out.println("Description: " + pnDesc.getLiteral());
-
-
-      ParseNode pnCapGreatGreatGrandChild2 = pnvCap3.elementAt(1);
-      System.out.println("Great great grand Child 2: " + pnCapGreatGreatGrandChild2.getLabel());
-      System.out.println("Great great grand Child 2: " + pnCapGreatGreatGrandChild2.getLiteral());
-      ParseNode pnCapGreatGreatGrandChild3 = pnvCap3.elementAt(2);
-      System.out.println("Great great grand Child 3: " + pnCapGreatGreatGrandChild3.getLabel());
-      System.out.println("Great great grand Child 3: " + pnCapGreatGreatGrandChild3.getLiteral());
-      ParseNode pnCapGreatGreatGrandChild4 = pnvCap3.elementAt(3);
-      System.out.println("Great great grand Child 4: " + pnCapGreatGreatGrandChild4.getLabel());
-      System.out.println("Great great grand Child 4: " + pnCapGreatGreatGrandChild4.getLiteral());
-
-      System.out.println();
-
-      /*System.out.println("REQUIRES: ");
-      ParseNode pnReqChild = pnv.elementAt(2);
-      System.out.println("Child 3: " + pnv.elementAt(2).getLabel());
-      System.out.println("Child 3: " + pnv.elementAt(2).getLiteral());
-      ParseNodeVector pnvReq = pnReqChild.getChildren();
-      System.out.println("Grand children: " + pnvReq.size());
-      ParseNode pnReqGrandChild = pnvReq.elementAt(0);
-      System.out.println("Grand Child 1: " + pnReqGrandChild.getLabel());
-      System.out.println("Grand Child 1: " + pnReqGrandChild.getLiteral());
-      ParseNodeVector pnvReqGrand = pnReqGrandChild.getChildren();
-      System.out.println("Grand children: " + pnvReqGrand.size());
-      ParseNode pnReqGreatGrandChild = pnvReqGrand.elementAt(0);
-      System.out.println("Great grand Child 1: " + pnReqGreatGrandChild.getLabel());
-      System.out.println("Great grand Child 1: " + pnReqGreatGrandChild.getLiteral());
-      ParseNode pnReqGreatGrandChild2 = pnvReqGrand.elementAt(1);
-      System.out.println("Great grand Child 2: " + pnReqGreatGrandChild2.getLabel());
-      System.out.println("Great grand Child 2: " + pnReqGreatGrandChild2.getLiteral());
-      ParseNodeVector pnvCapList = pnReqGreatGrandChild2.getChildren();
-      System.out.println("Grand children: " + pnvCapList.size());
-      ParseNode pnReqGreatGreatGrandChild2 = pnvCapList.elementAt(0);
-      System.out.println("Great great grand Child 2: " + pnReqGreatGreatGrandChild2.getLabel());
-      System.out.println("Great great grand Child 2: " + pnReqGreatGreatGrandChild2.getLiteral());
-
-      ParseNode pnReqGreatGrandChild3 = pnvReqGrand.elementAt(2);
-      System.out.println("Great grand Child 3: " + pnReqGreatGrandChild3.getLabel());
-      System.out.println("Great grand Child 3: " + pnReqGreatGrandChild3.getLiteral());
-
-
-      //ParseNodeVector pnvReqGreatGrand = pnReqGreatGrandChild2.getChildren();
-      //System.out.println("Grand children: " + pnvReqGreatGrand.size());
-      System.out.println();*/
-
   }
 
 
@@ -295,26 +197,18 @@ class CUP$Parser$actions {
       switch (CUP$Parser$act_num)
         {
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 0: // policy ::= intface capablist reqlist 
+          case 0: // policy ::= intface 
             {
               ParseNode RESULT =null;
-               int inleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left;
-               int inright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).right;
-               ParseNode in = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value;
-               int capleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
-               int capright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
-               ParseNode cap = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
-               int rlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left;
-               int rlright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right;
-               ParseNode rl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value;
+               int inleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left;
+               int inright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right;
+               ParseNode in = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value;
                
                ParseNode pn = new ParseNode("policy");
                pn.addChild(in);
-               pn.addChild(cap);
-               pn.addChild(rl);
                RESULT = pn;
        
-              CUP$Parser$result = parser.getSymbolFactory().newSymbol("policy",0, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
+              CUP$Parser$result = parser.getSymbolFactory().newSymbol("policy",0, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
             }
           return CUP$Parser$result;
 
@@ -333,34 +227,42 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 2: // intface ::= PUBLIC INTERFACE IDENT BEGIN methlist END 
+          case 2: // policy ::= reqlist 
             {
               ParseNode RESULT =null;
-               int idintleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left;
-               int idintright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).right;
-               Object idint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value;
-               int mlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
-               int mlright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
-               ParseNode ml = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
+               int rlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left;
+               int rlright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right;
+               ParseNode rl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value;
                
-               ParseNode pn = new ParseNode("interface");
-               pn.addChild("intface_ident").setLiteral(idint);
-               pn.addChild(ml);
+               ParseNode pn = new ParseNode("policy");
+               pn.addChild(rl);
                RESULT = pn;
        
-              CUP$Parser$result = parser.getSymbolFactory().newSymbol("intface",1, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
+              CUP$Parser$result = parser.getSymbolFactory().newSymbol("policy",0, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
             }
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 3: // intface ::= 
+          case 3: // intface ::= PUBLIC INTERFACE IDENT BEGIN methlist capablist END 
             {
               ParseNode RESULT =null;
+               int idintleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).left;
+               int idintright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).right;
+               Object idint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value;
+               int mlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left;
+               int mlright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).right;
+               ParseNode ml = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value;
+               int clleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
+               int clright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
+               ParseNode cl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
                
                ParseNode pn = new ParseNode("interface");
+               pn.addChild("intface_ident").setLiteral(idint);
+               pn.addChild(ml);
+               pn.addChild(cl);
                RESULT = pn;
        
-              CUP$Parser$result = parser.getSymbolFactory().newSymbol("intface",1, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
+              CUP$Parser$result = parser.getSymbolFactory().newSymbol("intface",1, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
             }
           return CUP$Parser$result;
 
@@ -419,7 +321,31 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 7: // paramlist ::= paramlist param 
+          case 7: // meth ::= PUBLIC IDENT IDENT LPAR paramlist RPAR SEMICOLON 
+            {
+              ParseNode RESULT =null;
+               int clsmethleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).left;
+               int clsmethright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).right;
+               Object clsmeth = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-5)).value;
+               int idmethleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).left;
+               int idmethright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).right;
+               Object idmeth = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value;
+               int plleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left;
+               int plright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).right;
+               ParseNode pl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value;
+               
+               ParseNode pn = new ParseNode("method");
+               pn.addChild("method_class").setLiteral(clsmeth);
+               pn.addChild("method_ident").setLiteral(idmeth);
+               pn.addChild(pl);
+               RESULT = pn;
+       
+              CUP$Parser$result = parser.getSymbolFactory().newSymbol("meth",3, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
+            }
+          return CUP$Parser$result;
+
+          /*. . . . . . . . . . . . . . . . . . . .*/
+          case 8: // paramlist ::= paramlist param 
             {
               ParseNode RESULT =null;
                int plleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
@@ -437,7 +363,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 8: // paramlist ::= 
+          case 9: // paramlist ::= 
             {
               ParseNode RESULT =null;
                
@@ -449,7 +375,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 9: // param ::= TYPE IDENT COMMA 
+          case 10: // param ::= TYPE IDENT COMMA 
             {
               ParseNode RESULT =null;
                int typeprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left;
@@ -469,7 +395,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 10: // param ::= TYPE IDENT 
+          case 11: // param ::= TYPE IDENT 
             {
               ParseNode RESULT =null;
                int typeprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
@@ -489,7 +415,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 11: // param ::= IDENT IDENT COMMA 
+          case 12: // param ::= IDENT IDENT COMMA 
             {
               ParseNode RESULT =null;
                int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left;
@@ -509,7 +435,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 12: // param ::= IDENT IDENT 
+          case 13: // param ::= IDENT IDENT 
             {
               ParseNode RESULT =null;
                int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
@@ -529,25 +455,25 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 13: // capablist ::= capablist capab 
+          case 14: // capablist ::= capablist capab 
             {
               ParseNode RESULT =null;
-               int clistleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
-               int clistright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
-               ParseNode clist = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
+               int clleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
+               int clright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
+               ParseNode cl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
                int capleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left;
                int capright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right;
                ParseNode cap = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value;
                
-               clist.addChild(cap);
-               RESULT = clist;
+               cl.addChild(cap);
+               RESULT = cl;
        
               CUP$Parser$result = parser.getSymbolFactory().newSymbol("capablist",6, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
             }
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 14: // capablist ::= 
+          case 15: // capablist ::= 
             {
               ParseNode RESULT =null;
                
@@ -559,12 +485,9 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 15: // capab ::= CAPABILITY IDENT DOT IDENT BEGIN capabcont END 
+          case 16: // capab ::= CAPABILITY IDENT BEGIN capabcont END 
             {
               ParseNode RESULT =null;
-               int idintleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).left;
-               int idintright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).right;
-               Object idint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-5)).value;
                int idcapleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left;
                int idcapright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).right;
                Object idcap = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value;
@@ -573,17 +496,16 @@ class CUP$Parser$actions {
                ParseNode ccont = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
                
                ParseNode pn = new ParseNode("capability");
-               pn.addChild("intface_ident").setLiteral(idint);
                pn.addChild("capab_ident").setLiteral(idcap);
                pn.addChild(ccont);
                RESULT = pn;
        
-              CUP$Parser$result = parser.getSymbolFactory().newSymbol("capab",7, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
+              CUP$Parser$result = parser.getSymbolFactory().newSymbol("capab",7, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
             }
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 16: // capabcont ::= capabcont cont 
+          case 17: // capabcont ::= capabcont cont 
             {
               ParseNode RESULT =null;
                int ccontleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
@@ -601,7 +523,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 17: // capabcont ::= 
+          case 18: // capabcont ::= 
             {
               ParseNode RESULT =null;
                
@@ -613,18 +535,18 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 18: // cont ::= DESCRIPTION ASSIGN STRINGCONST SEMICOLON 
+          case 19: // cont ::= DESCRIPTION ASSIGN STRINGCONST SEMICOLON 
             {
               ParseNode RESULT =null;
                int dscleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left;
                int dscright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).right;
                Object dsc = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value;
-               int strleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
-               int strright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
-               Object str = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
+               int strdscleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
+               int strdscright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
+               Object strdsc = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
                
                ParseNode pn = new ParseNode("capab_content");
-               pn.addChild("capab_desc").setLiteral(str);
+               pn.addChild("capab_desc").setLiteral(strdsc);
                RESULT = pn;
        
               CUP$Parser$result = parser.getSymbolFactory().newSymbol("cont",9, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
@@ -632,18 +554,18 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 19: // cont ::= METHOD ASSIGN IDENT SEMICOLON 
+          case 20: // cont ::= METHOD ASSIGN STRINGCONST SEMICOLON 
             {
               ParseNode RESULT =null;
                int mtdleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left;
                int mtdright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).right;
                Object mtd = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value;
-               int idmethleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
-               int idmethright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
-               Object idmeth = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
+               int strmethleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
+               int strmethright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right;
+               Object strmeth = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value;
                
                ParseNode pn = new ParseNode("capab_content");
-               pn.addChild("capab_ident").setLiteral(idmeth);
+               pn.addChild("capab_meth").setLiteral(strmeth);
                RESULT = pn;
        
               CUP$Parser$result = parser.getSymbolFactory().newSymbol("cont",9, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
@@ -651,7 +573,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 20: // reqlist ::= reqlist require 
+          case 21: // reqlist ::= reqlist require 
             {
               ParseNode RESULT =null;
                int rlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left;
@@ -669,11 +591,11 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 21: // reqlist ::= 
+          case 22: // reqlist ::= 
             {
               ParseNode RESULT =null;
                
-               ParseNode pn = new ParseNode("requires_list");
+               ParseNode pn = new ParseNode("reqlist");
                RESULT = pn;
        
               CUP$Parser$result = parser.getSymbolFactory().newSymbol("reqlist",10, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT);
@@ -681,7 +603,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 22: // require ::= REQUIRES IDENT WITH capintlist AS INTERFACE IDENT SEMICOLON 
+          case 23: // require ::= REQUIRES IDENT WITH capintlist AS INTERFACE IDENT SEMICOLON 
             {
               ParseNode RESULT =null;
                int idintleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)).left;
@@ -705,7 +627,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 23: // capintlist ::= IDENT 
+          case 24: // capintlist ::= IDENT 
             {
               ParseNode RESULT =null;
                int idcapleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left;
@@ -721,7 +643,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 24: // capintlist ::= capintlist COMMA IDENT 
+          case 25: // capintlist ::= capintlist COMMA IDENT 
             {
               ParseNode RESULT =null;
                int cilleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left;
@@ -739,7 +661,7 @@ class CUP$Parser$actions {
           return CUP$Parser$result;
 
           /*. . . . . . . . . . . . . . . . . . . .*/
-          case 25: // capintlist ::= 
+          case 26: // capintlist ::= 
             {
               ParseNode RESULT =null;
                
index 3a5f6dc..e299639 100644 (file)
@@ -1,39 +1,37 @@
-package iotpolicy.parser;
 
 //----------------------------------------------------
 // The following code was generated by CUP v0.11b 20160615 (GIT 4ac7450)
 //----------------------------------------------------
+package iotpolicy.parser;
 
 /** CUP generated interface containing symbol constants. */
 public interface sym {
   /* terminals */
-  public static final int IDENT = 19;
+  public static final int IDENT = 18;
   public static final int SEMICOLON = 2;
-  public static final int STRINGCONST = 20;
-  public static final int REQUIRES = 15;
-  public static final int END = 8;
-  public static final int CAPABILITY = 12;
-  public static final int AS = 17;
-  public static final int WITH = 16;
-  public static final int PUBLIC = 10;
-  public static final int BEGIN = 7;
-  public static final int TYPE = 18;
-  public static final int DESCRIPTION = 13;
+  public static final int STRINGCONST = 19;
+  public static final int REQUIRES = 14;
+  public static final int END = 7;
+  public static final int CAPABILITY = 11;
+  public static final int AS = 16;
+  public static final int WITH = 15;
+  public static final int PUBLIC = 9;
+  public static final int BEGIN = 6;
+  public static final int TYPE = 17;
+  public static final int DESCRIPTION = 12;
   public static final int COMMA = 3;
   public static final int EOF = 0;
-  public static final int METHOD = 14;
+  public static final int METHOD = 13;
   public static final int error = 1;
-  public static final int DOT = 4;
-  public static final int INTERFACE = 11;
-  public static final int ASSIGN = 9;
-  public static final int RPAR = 6;
-  public static final int LPAR = 5;
+  public static final int INTERFACE = 10;
+  public static final int ASSIGN = 8;
+  public static final int RPAR = 5;
+  public static final int LPAR = 4;
   public static final String[] terminalNames = new String[] {
   "EOF",
   "error",
   "SEMICOLON",
   "COMMA",
-  "DOT",
   "LPAR",
   "RPAR",
   "BEGIN",
index 71ec2ca..e9c694a 100644 (file)
@@ -10,7 +10,7 @@ import java.util.List;
  * @version     1.0
  * @since       2016-09-20
  */
-public final class CapabilityDecl {
+public class CapabilityDecl {
 
        /**
         * Class properties
index 27e9326..a646e62 100644 (file)
@@ -1,7 +1,11 @@
 package iotpolicy.tree;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /** Class InterfaceDecl is a data structure for interface
  *  declaration section in the policy file.
@@ -10,7 +14,7 @@ import java.util.List;
  * @version     1.0
  * @since       2016-09-20
  */
-public final class InterfaceDecl {
+public class InterfaceDecl {
 
        /**
         * Class properties
@@ -30,7 +34,8 @@ public final class InterfaceDecl {
         * In this data structure we will record its interface name, i.e. Camera
         *              its method names and the parameters for each method.
         */
-       private List<String> listMethods;                                       // Method names, e.g. MethodA
+       private List<String> listMethods;                                       // Method signature (no spaces), e.g. MethodA(intA,SpeakerB)
+       private List<String> listMethodIds;                                     // Method identifiers, e.g. MethodA
        private List<String> listMethodTypes;                           // Method types, e.g. void
        private List<List<String>> listMethodParams;            // Method parameter names, e.g. A, B
        private List<List<String>> listMethodParamTypes;        // Method parameter types, e.g. int, int
@@ -42,6 +47,7 @@ public final class InterfaceDecl {
 
                origInt = null;
                listMethods = new ArrayList<String>();
+               listMethodIds = new ArrayList<String>();
                listMethodTypes = new ArrayList<String>();
                listMethodParams = new ArrayList<List<String>>();
                listMethodParamTypes = new ArrayList<List<String>>();
@@ -52,6 +58,7 @@ public final class InterfaceDecl {
 
                origInt = _origInt;
                listMethods = new ArrayList<String>();
+               listMethodIds = new ArrayList<String>();
                listMethodTypes = new ArrayList<String>();
                listMethodParams = new ArrayList<List<String>>();
                listMethodParamTypes = new ArrayList<List<String>>();
@@ -61,9 +68,10 @@ public final class InterfaceDecl {
        /**
         * addNewMethod() adds a new method name and type into the list
         */
-       public void addNewMethod(String newMethod, String newMethodType) {
+       public void addNewMethod(String newMethod, String newMethodId, String newMethodType) {
 
                listMethods.add(newMethod);
+               listMethodIds.add(newMethodId);
                listMethodTypes.add(newMethodType);
                listMethodParams.add(new ArrayList<String>());
                listMethodParamTypes.add(new ArrayList<String>());
@@ -90,8 +98,17 @@ public final class InterfaceDecl {
 
                return listMethods;
        }
-       
-       
+
+
+       /**
+        * getMethodIds() gets method identifiers
+        */
+       public List<String> getMethodIds() {
+
+               return listMethodIds;
+       }
+
+
        /**
         * getMethodTypes() gets method types
         */
@@ -101,6 +118,16 @@ public final class InterfaceDecl {
        }
 
 
+       /**
+        * getMethodId() gets a method identifier
+        */
+       public String getMethodId(String method) {
+
+               int index = listMethods.indexOf(method);
+               return listMethodIds.get(index);
+       }
+
+
        /**
         * getMethodType() gets a method type
         */
@@ -134,9 +161,7 @@ public final class InterfaceDecl {
        public static void main(String[] args) {
 
                InterfaceDecl id = new InterfaceDecl("Camera");
-               id.addNewMethod("MethodA", "void");
-               id.addNewMethod("MethodB", "int");
-               id.addNewMethod("MethodC", "String");
+               id.addNewMethod("MethodA(intA,SpeakerB)", "MethodA", "void");
                id.addMethodParam("MethodA", "A", "int");
                id.addMethodParam("MethodA", "B", "int");
                id.addMethodParam("MethodB", "C", "int");
@@ -144,8 +169,6 @@ public final class InterfaceDecl {
                id.addMethodParam("MethodC", "E", "string");
                id.addMethodParam("MethodC", "F", "int");
 
-
-
                System.out.println("Set of methods: " + id.getMethods().toString());
                System.out.println("Set of params: " + id.getMethodParams("MethodA").toString());
                System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodA").toString());
index 69a36c2..c5d0be7 100644 (file)
@@ -6,13 +6,16 @@ import java.io.*;
 import iotpolicy.tree.ParseNodeVector;
 import iotpolicy.tree.ParseNode;
 
+import java.util.List;
+import java.util.ArrayList;
+
 /** Class ParseTreeHandler handles the parse tree generated by the 
  *  parser (and lexer) from the policy file. 
- *  This class accepts the AST in the form of XMLElement class object.
- *  It gives interfaces to extract the 3 sections of a policy file:
- *  1) Interface
- *  2) Capability list
- *  3) Generated interface list
+ *  This class accepts the AST in the form of ParseNode and
+ *  ParseNodeVector class objects.
+ *  It gives interfaces to extract the 2 types of policy file:
+ *  1) Interface and capabilities definition
+ *  2) Generated interface list ("requires" statements)
  *
  * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
  * @version     1.0
@@ -23,7 +26,8 @@ public final class ParseTreeHandler {
        /**
         * Class properties
         */
-       private ParseNode pn;
+       private ParseNode pnPol;                // Policy: interface and capabilities
+       private ParseNode pnReq;                // Policy: "requires" statements
        private InterfaceDecl intDecl;
        private CapabilityDecl capDecl;
        private RequiresDecl reqDecl;
@@ -34,16 +38,18 @@ public final class ParseTreeHandler {
         */
        public ParseTreeHandler() {
 
-               pn = null;
+               pnPol = null;
+               pnReq = null;
                intDecl = new InterfaceDecl();
                capDecl = new CapabilityDecl();
                reqDecl = new RequiresDecl();
        }
 
 
-       public ParseTreeHandler(String _intFace, ParseNode _pn) {
+       public ParseTreeHandler(String _intFace, ParseNode _pnPol, ParseNode _pnReq) {
 
-               pn = _pn;
+               pnPol = _pnPol;
+               pnReq = _pnReq;
                intDecl = new InterfaceDecl(_intFace);
                capDecl = new CapabilityDecl(_intFace);
                reqDecl = new RequiresDecl(_intFace);
@@ -55,47 +61,52 @@ public final class ParseTreeHandler {
         */
        public void processInterfaceDecl() {
 
-               // Get the root - interface list (element 0)
-               ParseNodeVector pnv = pn.getChildren();
+               ParseNodeVector pnv = pnPol.getChildren();
                ParseNode pnRoot = pnv.elementAt(0);
-               // Get the second child of root for "method_list"
                ParseNodeVector pnvGen2 = pnRoot.getChildren();
                if (pnvGen2.size() == 0) {
                        throw new Error("ParseTreeHandler: Interface declaration is missing! Please check your policy file...");
                }
                ParseNode pnGen2 = pnvGen2.elementAt(1);
-               // Get the next level child for methods
                ParseNodeVector pnvGen3 = pnGen2.getChildren();
-               // Loop and extract methods
-               for(int i = 0; i < pnvGen3.size(); i++) {
+               for(int i = 0; i < pnvGen3.size(); i++) { // Loop on methods
 
-                       // Get the level where label is "method"
                        ParseNode pnGen3 = pnvGen3.elementAt(i);
-                       // Get the next level child - method info
                        ParseNodeVector pnvGen4 = pnGen3.getChildren();
-                       // Method type
+                       // Method type, identifier, and param node
                        ParseNode pnGen4_type = pnvGen4.elementAt(0);
-                       // Method identifier
                        ParseNode pnGen4_ident  = pnvGen4.elementAt(1);
-                       // Add a new method (type and identifier)
-                       intDecl.addNewMethod(pnGen4_ident.getLiteral().toString(), 
-                               pnGen4_type.getLiteral().toString());
-                       // Get the next level child - method params
                        ParseNode pnGen4_params  = pnvGen4.elementAt(2);
                        ParseNodeVector pnvGen5 = pnGen4_params.getChildren();
-                       for(int j = 0; j < pnvGen5.size(); j++) {
+                       // First loop - create a key without spaces, e.g. MethodA(intA,SpeakerB)
+                       String methodKey = pnGen4_ident.getLiteral().toString() + "(";
+                       List<String> paramTypes = new ArrayList<String>();
+                       List<String> params = new ArrayList<String>();
+                       for(int j = 0; j < pnvGen5.size(); j++) { // Loop on params
 
                                ParseNode pnGen5 = pnvGen5.elementAt(j);
                                ParseNodeVector pnvGen6 = pnGen5.getChildren();
-                               // Param type
+                               // Param type and identifier
                                ParseNode pnGen6_type = pnvGen6.elementAt(0);
-                               // Param identifier
                                ParseNode pnGen6_ident = pnvGen6.elementAt(1);
-                               // Add a new method param (type and identifier)
-                               intDecl.addMethodParam(pnGen4_ident.getLiteral().toString(),
-                                       pnGen6_ident.getLiteral().toString(), pnGen6_type.getLiteral().toString());
+                               methodKey = methodKey + pnGen6_type.getLiteral().toString();
+                               methodKey = methodKey + pnGen6_ident.getLiteral().toString();
+                               // Keep the parameters temporarily
+                               paramTypes.add(pnGen6_type.getLiteral().toString());
+                               params.add(pnGen6_ident.getLiteral().toString());
+                               // Don't add comma for the last parameter
+                               if (j != pnvGen5.size() - 1) {
+                                       methodKey = methodKey + ",";
+                               }
+                       }
+                       methodKey = methodKey + ")";
+                       // Add a new method (signature key, identifier, and type)
+                       intDecl.addNewMethod(methodKey, pnGen4_ident.getLiteral().toString(), 
+                               pnGen4_type.getLiteral().toString());
+                       // Second loop - add the method parameters
+                       for(int j = 0; j < params.size(); j++) {
+                               intDecl.addMethodParam(methodKey, params.get(j), paramTypes.get(j));
                        }
-                       //System.out.println();
                }
        }
 
@@ -106,41 +117,43 @@ public final class ParseTreeHandler {
        public void processCapabilityDecl() {
 
                // Get the root - capability list (element 1)
-               ParseNodeVector pnv = pn.getChildren();
-               ParseNode pnRoot = pnv.elementAt(1);
-               // Get the second child of root for "capab_list"
+               ParseNodeVector pnv = pnPol.getChildren();
+               ParseNode pnRoot = pnv.elementAt(0);
                ParseNodeVector pnvGen2 = pnRoot.getChildren();
-               if (pnvGen2.size() == 0) {
+               // Get the third child of root for "capab_list"
+               ParseNode pnGen2 = pnvGen2.elementAt(2);
+               ParseNodeVector pnvGen3 = pnGen2.getChildren();
+               if (pnvGen3.size() == 0) {
                        throw new Error("ParseTreeHandler: Capability declaration is missing! Please check your policy file...");
                }
                // Iterate over the list of capabilities
-               for(int i = 0; i < pnvGen2.size(); i++) {
+               for(int i = 0; i < pnvGen3.size(); i++) {
 
-                       ParseNode pnGen2 = pnvGen2.elementAt(i);
+                       ParseNode pnGen3 = pnvGen3.elementAt(i);
                        // Get the next level child for capabilities
-                       ParseNodeVector pnvGen3 = pnGen2.getChildren();
+                       ParseNodeVector pnvGen4 = pnGen3.getChildren();
                        // Get the capability name, e.g. ImageCapture for Camera.ImageCapture
-                       ParseNode pnGen3_capab = pnvGen3.elementAt(1);
+                       ParseNode pnGen4_capab = pnvGen4.elementAt(0);
                        // Add new capability
-                       capDecl.addNewCapability(pnGen3_capab.getLiteral().toString());
+                       capDecl.addNewCapability(pnGen4_capab.getLiteral().toString());
                        // Get the capability contents, i.e. descriptions and methods
-                       ParseNode pnGen3_capab_cont = pnvGen3.elementAt(2);
-                       ParseNodeVector pnvGen4 = pnGen3_capab_cont.getChildren();
+                       ParseNode pnGen4_capab_cont = pnvGen4.elementAt(1);
+                       ParseNodeVector pnvGen5 = pnGen4_capab_cont.getChildren();
                        // Iterate over the list of capability contents
-                       for(int j = 0; j < pnvGen4.size(); j++) {
+                       for(int j = 0; j < pnvGen5.size(); j++) {
 
-                               ParseNode pnGen4 = pnvGen4.elementAt(j);
-                               ParseNodeVector pnvGen5 = pnGen4.getChildren();
-                               ParseNode pnGen5 = pnvGen5.elementAt(0);
+                               ParseNode pnGen5 = pnvGen5.elementAt(j);
+                               ParseNodeVector pnvGen6 = pnGen5.getChildren();
+                               ParseNode pnGen6 = pnvGen6.elementAt(0);
                                // Check the label and separate between description (capab_desc)
                                // and method name (capab_ident)
-                               String label = pnGen5.getLabel().toString();
+                               String label = pnGen6.getLabel().toString();
                                if (label.equals("capab_desc")) {
-                                       capDecl.addNewDescription(pnGen3_capab.getLiteral().toString(),
-                                               pnGen5.getLiteral().toString());
-                               } else if (label.equals("capab_ident")) {
-                                       capDecl.addNewMethod(pnGen3_capab.getLiteral().toString(),
-                                               pnGen5.getLiteral().toString());                                
+                                       capDecl.addNewDescription(pnGen4_capab.getLiteral().toString(),
+                                               pnGen6.getLiteral().toString());
+                               } else if (label.equals("capab_meth")) {
+                                       capDecl.addNewMethod(pnGen4_capab.getLiteral().toString(),
+                                               pnGen6.getLiteral().toString().replaceAll("\\s+",""));
                                } else
                                        throw new Error("ParseTreeHandler: Unknown label '" + label + "' while operating on parse tree!");
 
@@ -155,9 +168,9 @@ public final class ParseTreeHandler {
        public void processRequiresDecl() {
 
                // Get the root - requires list (element 2)
-               ParseNodeVector pnv = pn.getChildren();
-               ParseNode pnRoot = pnv.elementAt(2);
-               // Get the second child of root for "capab_list"
+               ParseNodeVector pnv = pnReq.getChildren();
+               ParseNode pnRoot = pnv.elementAt(0);
+               // Get the second child of root for "reqlist"
                ParseNodeVector pnvGen2 = pnRoot.getChildren();
                if (pnvGen2.size() == 0) {
                        throw new Error("ParseTreeHandler: 'Requires' declaration is missing! Please check your policy file...");
@@ -225,6 +238,7 @@ public final class ParseTreeHandler {
                if (pnvGen2.size() == 0) {
                        throw new Error("ParseTreeHandler: Interface declaration is missing! Please check your policy file...");
                }
+               // Get "intface_def"
                ParseNode pnGen2 = pnvGen2.elementAt(0);
                // Confirm that this is "intface_ident"
                if (pnGen2.getLabel().equals("intface_ident")) {
@@ -235,23 +249,4 @@ public final class ParseTreeHandler {
                } else
                        throw new Error("ParseTreeHandler: Label 'intface_ident' is not found! Instead, '" + pnGen2.getLabel() + "' was found...");
        }
-
-
-/*     public static void main(String[] args) throws Exception {
-
-               // initialize the symbol factory
-               ComplexSymbolFactory csf = new ComplexSymbolFactory();
-               // create a buffering scanner wrapper
-               ScannerBuffer lexer = new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[0])),csf));
-               // start parsing
-               Parser p = new Parser(lexer,csf);
-               ParseNode pn = (ParseNode) p.parse().value;
-
-               String intFace = ParseTreeHandler.getOrigIntface(pn);
-               System.out.println("Original interface name: " + intFace);
-               ParseTreeHandler pth = new ParseTreeHandler(intFace, pn);
-               pth.processInterfaceDecl();
-               pth.processCapabilityDecl();
-               pth.processRequiresDecl();
-       }*/
 }
index 73239e1..5a92155 100644 (file)
@@ -15,7 +15,7 @@ import java.util.Set;
  * @version     1.0
  * @since       2016-09-20
  */
-public final class RequiresDecl {
+public class RequiresDecl {
 
        /**
         * Class properties
index 22e929a..ff3b02f 100644 (file)
@@ -21,63 +21,56 @@ parser code {:
       // start parsing
       Parser p = new Parser(lexer,csf);
       ParseNode pn = (ParseNode) p.parse().value;
-
-      /*XMLElement e = (XMLElement)p.parse().value;
-      // create XML output file 
-      XMLOutputFactory outFactory = XMLOutputFactory.newInstance();
-      XMLStreamWriter sw = outFactory.createXMLStreamWriter(new FileOutputStream(args[1]), "UTF-8");
-      // dump XML output to the file
-      XMLElement.dump(lexer,sw,e,"expr","stmt");
-
-       // transform the parse tree into an AST and a rendered HTML version
-      Transformer transformer = TransformerFactory.newInstance()
-           .newTransformer(new StreamSource(new File("tree.xsl")));
-      Source text = new StreamSource(new File(args[1]));
-      transformer.transform(text, new StreamResult(new File("output.xml")));
-      transformer = TransformerFactory.newInstance()
-           .newTransformer(new StreamSource(new File("tree-view.xsl")));
-      text = new StreamSource(new File("output.xml"));
-      transformer.transform(text, new StreamResult(new File("ast.html")));*/
   }
 :};
 
-terminal SEMICOLON, COMMA, DOT, LPAR, RPAR, BEGIN, END, ASSIGN;
+terminal SEMICOLON, COMMA, LPAR, RPAR, BEGIN, END, ASSIGN;
 terminal PUBLIC, INTERFACE, CAPABILITY, DESCRIPTION, METHOD, REQUIRES, WITH, AS; 
 terminal TYPE;
 terminal IDENT, STRINGCONST;
 
-non terminal ParseNode policy, intface, methlist, meth, paramlist, param;
+non terminal ParseNode policy;
+non terminal ParseNode intface, methlist, meth, paramlist, param;
 non terminal ParseNode capablist, capab, capabcont, cont;
 non terminal ParseNode reqlist, require, capintlist;
 
 /**
- * A policy file normally consists of 3 parts:
- * 1) Interface (in Java syntax)
- * 2) List of capabilities and their contents
- * 3) List of interface generation definitions
+ * A policy file normally consists of:
+ * 1) Interface 
+ *    - Interface definition
+ *    - List of capabilities and their contents
+ *
+ * We also define "requires" statements for users
+ * to declare their required capabilities in the
+ * generated interfaces
+ * 2) List of generated interfaces (requires)
  */
-policy     ::= 
-       intface:in capablist:cap reqlist:rl
+policy     ::= intface:in
        {:
                ParseNode pn = new ParseNode("policy");
                pn.addChild(in);
-               pn.addChild(cap);
+               RESULT = pn;
+       :}
+       | reqlist:rl
+       {:
+               ParseNode pn = new ParseNode("policy");
                pn.addChild(rl);
                RESULT = pn;
        :}
     ;
 
-// Interface class definition
-intface    ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml END
+//1) Interface class definition
+// 1) Interface definition
+// 2) Library list
+// 3) Driver list
+
+// Interface
+intface    ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml capablist:cl END
        {:
                ParseNode pn = new ParseNode("interface");
                pn.addChild("intface_ident").setLiteral(idint);
                pn.addChild(ml);
-               RESULT = pn;
-       :}
-    | /* empty */
-       {:
-               ParseNode pn = new ParseNode("interface");
+               pn.addChild(cl);
                RESULT = pn;
        :}
     ;
@@ -100,6 +93,14 @@ meth       ::= PUBLIC TYPE:typemeth IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLO
                pn.addChild(pl);
                RESULT = pn;
        :}
+    | PUBLIC IDENT:clsmeth IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
+       {:
+               ParseNode pn = new ParseNode("method");
+               pn.addChild("method_class").setLiteral(clsmeth);
+               pn.addChild("method_ident").setLiteral(idmeth);
+               pn.addChild(pl);
+               RESULT = pn;
+       :}
     ;
 paramlist  ::= paramlist:pl param:p
        {:
@@ -142,11 +143,11 @@ param      ::= TYPE:typeprm IDENT:idprm COMMA
        :}
     ;
 
-// List of capabilities and their respective contents, i.e. description, method, etc.
-capablist  ::= capablist:clist capab:cap
+//2) List of capabilities and their respective contents, i.e. description, method, etc.
+capablist  ::= capablist:cl capab:cap
        {:
-               clist.addChild(cap);
-               RESULT = clist;
+               cl.addChild(cap);
+               RESULT = cl;
        :}
        | /* empty */
        {:
@@ -154,10 +155,9 @@ capablist  ::= capablist:clist capab:cap
                RESULT = pn;
        :}
        ;
-capab      ::= CAPABILITY IDENT:idint DOT IDENT:idcap BEGIN capabcont:ccont END
+capab      ::= CAPABILITY IDENT:idcap BEGIN capabcont:ccont END
        {:
                ParseNode pn = new ParseNode("capability");
-               pn.addChild("intface_ident").setLiteral(idint);
                pn.addChild("capab_ident").setLiteral(idcap);
                pn.addChild(ccont);
                RESULT = pn;
@@ -174,21 +174,21 @@ capabcont  ::= capabcont:ccont cont:cnt
                RESULT = pn;
        :}
        ;
-cont       ::= DESCRIPTION:dsc ASSIGN STRINGCONST:str SEMICOLON
+cont       ::= DESCRIPTION:dsc ASSIGN STRINGCONST:strdsc SEMICOLON
        {:
                ParseNode pn = new ParseNode("capab_content");
-               pn.addChild("capab_desc").setLiteral(str);
+               pn.addChild("capab_desc").setLiteral(strdsc);
                RESULT = pn;
        :}
-       | METHOD:mtd ASSIGN IDENT:idmeth SEMICOLON
+       | METHOD:mtd ASSIGN STRINGCONST:strmeth SEMICOLON
        {:
                ParseNode pn = new ParseNode("capab_content");
-               pn.addChild("capab_ident").setLiteral(idmeth);
+               pn.addChild("capab_meth").setLiteral(strmeth);
                RESULT = pn;
        :}
        ;
 
-// List of interface generation definitions
+//3) List of interface generation definitions ("requires" statements)
 reqlist    ::= reqlist:rl require:req
        {:
                rl.addChild(req);
@@ -196,7 +196,7 @@ reqlist    ::= reqlist:rl require:req
        :}
        | /* empty */
        {:
-               ParseNode pn = new ParseNode("requires_list");
+               ParseNode pn = new ParseNode("reqlist");
                RESULT = pn;
        :}
        ;
index f16ef69..a9e70d1 100644 (file)
@@ -52,7 +52,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location;
 %eofval}
 
 
-Ident = [a-zA-Z$_] [a-zA-Z0-9$_]*
+Ident = [a-zA-Z$_] [a-zA-Z0-9$_<>]*
 
 new_line = \r|\n|\r\n;
 
@@ -102,7 +102,6 @@ white_space = {new_line} | [ \t\f]
   \"              { string.setLength(0); yybegin(STRING); }
 ";"               { return symbol("semicolon",SEMICOLON); }
 ","               { return symbol("comma",COMMA); }
-"."               { return symbol("dot",DOT); }
 "("               { return symbol("(",LPAR); }
 ")"               { return symbol(")",RPAR); }
 "{"               { return symbol("{",BEGIN); }