From f0af28e363e1e1d2a3f98eb5bacde13ad09eef8b Mon Sep 17 00:00:00 2001 From: rtrimana Date: Fri, 23 Sep 2016 16:25:41 -0700 Subject: [PATCH] Perfecting parser, lexer, and parse-tree handling for policy files; Generating skeletons for stubs --- config/{iotparser => iotpolicy}/policy.pol | 0 config/{iotparser => iotpolicy}/tree-view.xsl | 0 config/{iotparser => iotpolicy}/tree.xsl | 0 iotjava/Makefile | 22 +- iotjava/iotparser/Parser.java | 690 ---------------- iotjava/iotpolicy/IoTStubCompiler.java | 540 ++++++++++++ .../parser}/Lexer.java | 317 +++---- iotjava/iotpolicy/parser/Parser.java | 777 ++++++++++++++++++ .../{iotparser => iotpolicy/parser}/sym.java | 2 +- iotjava/iotpolicy/tree/CapabilityDecl.java | 140 ++++ iotjava/iotpolicy/tree/InterfaceDecl.java | 157 ++++ iotjava/iotpolicy/tree/ParseNode.java | 234 ++++++ iotjava/iotpolicy/tree/ParseNodeVector.java | 27 + iotjava/iotpolicy/tree/ParseTreeHandler.java | 257 ++++++ iotjava/iotpolicy/tree/RequiresDecl.java | 106 +++ iotjava/iotpolicy/tree/Walkable.java | 34 + others/javacup/iotparser.cup | 143 +++- others/jflex/iotparser.jflex | 21 +- 18 files changed, 2598 insertions(+), 869 deletions(-) rename config/{iotparser => iotpolicy}/policy.pol (100%) rename config/{iotparser => iotpolicy}/tree-view.xsl (100%) rename config/{iotparser => iotpolicy}/tree.xsl (100%) delete mode 100644 iotjava/iotparser/Parser.java create mode 100644 iotjava/iotpolicy/IoTStubCompiler.java rename iotjava/{iotparser => iotpolicy/parser}/Lexer.java (78%) create mode 100644 iotjava/iotpolicy/parser/Parser.java rename iotjava/{iotparser => iotpolicy/parser}/sym.java (98%) create mode 100644 iotjava/iotpolicy/tree/CapabilityDecl.java create mode 100644 iotjava/iotpolicy/tree/InterfaceDecl.java create mode 100644 iotjava/iotpolicy/tree/ParseNode.java create mode 100644 iotjava/iotpolicy/tree/ParseNodeVector.java create mode 100644 iotjava/iotpolicy/tree/ParseTreeHandler.java create mode 100644 iotjava/iotpolicy/tree/RequiresDecl.java create mode 100644 iotjava/iotpolicy/tree/Walkable.java diff --git a/config/iotparser/policy.pol b/config/iotpolicy/policy.pol similarity index 100% rename from config/iotparser/policy.pol rename to config/iotpolicy/policy.pol diff --git a/config/iotparser/tree-view.xsl b/config/iotpolicy/tree-view.xsl similarity index 100% rename from config/iotparser/tree-view.xsl rename to config/iotpolicy/tree-view.xsl diff --git a/config/iotparser/tree.xsl b/config/iotpolicy/tree.xsl similarity index 100% rename from config/iotparser/tree.xsl rename to config/iotpolicy/tree.xsl diff --git a/iotjava/Makefile b/iotjava/Makefile index fa16fc7..8d92c94 100644 --- a/iotjava/Makefile +++ b/iotjava/Makefile @@ -2,19 +2,27 @@ BASE := .. include $(BASE)/common.mk -all: iotparser +all: iotparsertree iotparser iotcompiler + +PHONY += iotparsertree +iotparsertree: + $(JAVAC) -cp .:$(PARSERJARS) -d $(BIN_DIR) iotpolicy/tree/*.java PHONY += iotparser iotparser: - $(JAVAC) -cp .:$(PARSERJARS) -d $(BIN_DIR) iotparser/*.java - cp ../config/iotparser/* $(BIN_DIR)/iotparser/ + $(JAVAC) -cp .:$(PARSERJARS) -d $(BIN_DIR) iotpolicy/parser/*.java + +PHONY += iotcompiler +iotcompiler: + $(JAVAC) -cp .:$(PARSERJARS) -d $(BIN_DIR) iotpolicy/*.java + cp ../config/iotpolicy/*.pol $(BIN_DIR)/iotpolicy/ -PHONY += iotparse -iotparse: - cd $(BIN_DIR)/iotparser; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotparser.Parser policy.pol out.xml +PHONY += iotcompilestub +iotcompilestub: + cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTStubCompiler policy.pol PHONY += doc doc: iotruntime iotinstaller - $(JAVADOC) -d $(DOCS_DIR) iotparser/*.java + $(JAVADOC) -d $(DOCS_DIR) iotpolicy/*.java .PHONY: $(PHONY) diff --git a/iotjava/iotparser/Parser.java b/iotjava/iotparser/Parser.java deleted file mode 100644 index 99b2ae1..0000000 --- a/iotjava/iotparser/Parser.java +++ /dev/null @@ -1,690 +0,0 @@ -package iotparser; - -//---------------------------------------------------- -// The following code was generated by CUP v0.11b 20160615 (GIT 4ac7450) -//---------------------------------------------------- - -import java_cup.runtime.ComplexSymbolFactory; -import java_cup.runtime.ScannerBuffer; -import java_cup.runtime.XMLElement; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamWriter; -import java.io.*; -import javax.xml.transform.*; -import javax.xml.transform.stream.*; -import java_cup.runtime.ComplexSymbolFactory.Location; -import java_cup.runtime.XMLElement; - -/** CUP v0.11b 20160615 (GIT 4ac7450) generated parser. - */ -@SuppressWarnings({"rawtypes"}) -public class Parser extends java_cup.runtime.lr_parser { - - public final Class getSymbolContainer() { - return sym.class; -} - - /** Default constructor. */ - @Deprecated - public Parser() {super();} - - /** Constructor which sets the default scanner. */ - @Deprecated - public Parser(java_cup.runtime.Scanner s) {super(s);} - - /** Constructor which sets the default scanner. */ - public Parser(java_cup.runtime.Scanner s, java_cup.runtime.SymbolFactory sf) {super(s,sf);} - - /** 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" }); - - /** Access to production table. */ - public short[][] production_table() {return _production_table;} - - /** 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" }); - - /** Access to parse-action table. */ - public short[][] action_table() {return _action_table;} - - /** reduce_goto 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\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" + - "\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" + - "\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" }); - - /** Access to reduce_goto table. */ - public short[][] reduce_table() {return _reduce_table;} - - /** Instance of action encapsulation class. */ - protected CUP$Parser$actions action_obj; - - /** Action encapsulation object initializer. */ - protected void init_actions() - { - action_obj = new CUP$Parser$actions(this); - } - - /** Invoke a user supplied parse action. */ - public java_cup.runtime.Symbol do_action( - int act_num, - java_cup.runtime.lr_parser parser, - java.util.Stack stack, - int top) - throws java.lang.Exception - { - /* call code in generated class */ - return action_obj.CUP$Parser$do_action(act_num, parser, stack, top); - } - - /** Indicates start state. */ - public int start_state() {return 0;} - /** Indicates start production. */ - public int start_production() {return 1;} - - /** EOF Symbol index. */ - public int EOF_sym() {return 0;} - - /** error Symbol index. */ - public int error_sym() {return 1;} - - - - public Parser(Lexer lex, ComplexSymbolFactory sf) { - super(lex,sf); - } - 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); - 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"))); - } - - -/** Cup generated class to encapsulate user supplied action code.*/ -@SuppressWarnings({"rawtypes", "unchecked", "unused"}) -class CUP$Parser$actions { - private final Parser parser; - - /** Constructor */ - CUP$Parser$actions(Parser parser) { - this.parser = parser; - } - - /** Method 0 with the actual generated action code for actions 0 to 300. */ - public final java_cup.runtime.Symbol CUP$Parser$do_action_part00000000( - int CUP$Parser$act_num, - java_cup.runtime.lr_parser CUP$Parser$parser, - java.util.Stack CUP$Parser$stack, - int CUP$Parser$top) - throws java.lang.Exception - { - /* Symbol object for return from actions */ - java_cup.runtime.Symbol CUP$Parser$result; - - /* select the action based on the action number */ - switch (CUP$Parser$act_num) - { - /*. . . . . . . . . . . . . . . . . . . .*/ - case 0: // policy ::= intface capablist reqlist - { - XMLElement RESULT; - Location inxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location inxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object in = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location capxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location capxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object cap = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location rlxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location rlxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object rl = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("policy",0,(XMLElement)in,(XMLElement)cap,(XMLElement)rl); - 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); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 1: // $START ::= policy EOF - { - XMLElement RESULT; - Location start_valxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location start_valxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object start_val = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location EOF1xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location EOF1xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object EOF1 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("_START",0,(XMLElement)start_val); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("$START",0, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - /* ACCEPT */ - CUP$Parser$parser.done_parsing(); - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 2: // intface ::= PUBLIC INTERFACE IDENT BEGIN methlist END - { - XMLElement RESULT; - Location PUBLIC0xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).xleft; - Location PUBLIC0xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).xright; - Object PUBLIC0 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-5)).value; - Location INTERFACE1xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).xleft; - Location INTERFACE1xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).xright; - Object INTERFACE1 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value; - Location idintxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xleft; - Location idintxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xright; - Object idint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value; - Location BEGIN3xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location BEGIN3xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object BEGIN3 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location mlxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location mlxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object ml = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location END5xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location END5xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object END5 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("intface",0,new XMLElement.Terminal(idintxleft,"idint",idint,idintxright),(XMLElement)ml); - 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); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 3: // intface ::= - { - XMLElement RESULT; - - RESULT = new XMLElement.NonTerminal("intface",1); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("intface",1, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 4: // methlist ::= methlist meth - { - XMLElement RESULT; - Location mlxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location mlxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object ml = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location mxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location mxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object m = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("methlist",0,(XMLElement)ml,(XMLElement)m); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("methlist",2, ((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 5: // methlist ::= - { - XMLElement RESULT; - - RESULT = new XMLElement.NonTerminal("methlist",1); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("methlist",2, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 6: // meth ::= PUBLIC TYPE IDENT LPAR paramlist RPAR SEMICOLON - { - XMLElement RESULT; - Location PUBLIC0xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)).xleft; - Location PUBLIC0xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)).xright; - Object PUBLIC0 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-6)).value; - Location typemethxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).xleft; - Location typemethxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).xright; - Object typemeth = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-5)).value; - Location idmethxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).xleft; - Location idmethxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).xright; - Object idmeth = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value; - Location LPAR3xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xleft; - Location LPAR3xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xright; - Object LPAR3 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value; - Location plxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location plxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object pl = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location RPAR5xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location RPAR5xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object RPAR5 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location SEMICOLON6xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location SEMICOLON6xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object SEMICOLON6 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("meth",0,new XMLElement.Terminal(typemethxleft,"typemeth",typemeth,typemethxright),new XMLElement.Terminal(idmethxleft,"idmeth",idmeth,idmethxright),(XMLElement)pl); - 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 7: // paramlist ::= paramlist param - { - XMLElement RESULT; - Location plxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location plxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object pl = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location pxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location pxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object p = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("paramlist",0,(XMLElement)pl,(XMLElement)p); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("paramlist",4, ((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 8: // paramlist ::= - { - XMLElement RESULT; - - RESULT = new XMLElement.NonTerminal("paramlist",1); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("paramlist",4, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 9: // param ::= TYPE IDENT COMMA - { - XMLElement RESULT; - Location typeprmxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location typeprmxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object typeprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location idprmxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location idprmxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object idprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location COMMA2xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location COMMA2xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object COMMA2 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("param",0,new XMLElement.Terminal(typeprmxleft,"typeprm",typeprm,typeprmxright),new XMLElement.Terminal(idprmxleft,"idprm",idprm,idprmxright)); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("param",5, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 10: // param ::= TYPE IDENT - { - XMLElement RESULT; - Location typeprmxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location typeprmxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object typeprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location idprmxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location idprmxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object idprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("param",1,new XMLElement.Terminal(typeprmxleft,"typeprm",typeprm,typeprmxright),new XMLElement.Terminal(idprmxleft,"idprm",idprm,idprmxright)); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("param",5, ((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 11: // param ::= IDENT IDENT COMMA - { - XMLElement RESULT; - Location clsprmxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location clsprmxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object clsprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location idprmxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location idprmxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object idprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location COMMA2xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location COMMA2xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object COMMA2 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("param",2,new XMLElement.Terminal(clsprmxleft,"clsprm",clsprm,clsprmxright),new XMLElement.Terminal(idprmxleft,"idprm",idprm,idprmxright)); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("param",5, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 12: // param ::= IDENT IDENT - { - XMLElement RESULT; - Location clsprmxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location clsprmxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object clsprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location idprmxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location idprmxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object idprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("param",3,new XMLElement.Terminal(clsprmxleft,"clsprm",clsprm,clsprmxright),new XMLElement.Terminal(idprmxleft,"idprm",idprm,idprmxright)); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("param",5, ((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 13: // capablist ::= capablist capab - { - XMLElement RESULT; - Location clistxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location clistxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object clist = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location capxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location capxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object cap = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("capablist",0,(XMLElement)clist,(XMLElement)cap); - 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 ::= - { - XMLElement RESULT; - - RESULT = new XMLElement.NonTerminal("capablist",1); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("capablist",6, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 15: // capab ::= CAPABILITY IDENT DOT IDENT BEGIN capabcont END - { - XMLElement RESULT; - Location CAPABILITY0xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)).xleft; - Location CAPABILITY0xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)).xright; - Object CAPABILITY0 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-6)).value; - Location idintxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).xleft; - Location idintxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).xright; - Object idint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-5)).value; - Location DOT2xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).xleft; - Location DOT2xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).xright; - Object DOT2 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value; - Location idcapxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xleft; - Location idcapxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xright; - Object idcap = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value; - Location BEGIN4xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location BEGIN4xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object BEGIN4 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location ccontxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location ccontxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object ccont = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location END6xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location END6xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object END6 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("capab",0,new XMLElement.Terminal(idintxleft,"idint",idint,idintxright),new XMLElement.Terminal(idcapxleft,"idcap",idcap,idcapxright),(XMLElement)ccont); - 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); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 16: // capabcont ::= capabcont cont - { - XMLElement RESULT; - Location ccontxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location ccontxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object ccont = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location cntxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location cntxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object cnt = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("capabcont",0,(XMLElement)ccont,(XMLElement)cnt); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("capabcont",8, ((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 17: // capabcont ::= - { - XMLElement RESULT; - - RESULT = new XMLElement.NonTerminal("capabcont",1); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("capabcont",8, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 18: // cont ::= DESCRIPTION ASSIGN STRINGCONST SEMICOLON - { - XMLElement RESULT; - Location dscxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xleft; - Location dscxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xright; - Object dsc = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value; - Location ASSIGN1xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location ASSIGN1xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object ASSIGN1 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location STRINGCONST2xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location STRINGCONST2xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object STRINGCONST2 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location SEMICOLON3xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location SEMICOLON3xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object SEMICOLON3 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("cont",0,new XMLElement.Terminal(dscxleft,"dsc",dsc,dscxright)); - 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); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 19: // cont ::= METHOD ASSIGN IDENT SEMICOLON - { - XMLElement RESULT; - Location mtdxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xleft; - Location mtdxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xright; - Object mtd = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value; - Location ASSIGN1xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location ASSIGN1xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object ASSIGN1 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location idmethxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location idmethxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object idmeth = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location SEMICOLON3xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location SEMICOLON3xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object SEMICOLON3 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("cont",1,new XMLElement.Terminal(mtdxleft,"mtd",mtd,mtdxright),new XMLElement.Terminal(idmethxleft,"idmeth",idmeth,idmethxright)); - 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); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 20: // reqlist ::= reqlist require - { - XMLElement RESULT; - Location rlxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location rlxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object rl = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location reqxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location reqxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object req = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("reqlist",0,(XMLElement)rl,(XMLElement)req); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("reqlist",10, ((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 21: // reqlist ::= - { - XMLElement RESULT; - - RESULT = new XMLElement.NonTerminal("reqlist",1); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("reqlist",10, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 22: // require ::= REQUIRES IDENT WITH capintlist AS INTERFACE IDENT SEMICOLON - { - XMLElement RESULT; - Location REQUIRES0xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-7)).xleft; - Location REQUIRES0xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-7)).xright; - Object REQUIRES0 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-7)).value; - Location idintxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)).xleft; - Location idintxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)).xright; - Object idint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-6)).value; - Location WITH2xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).xleft; - Location WITH2xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).xright; - Object WITH2 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-5)).value; - Location cilxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).xleft; - Location cilxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).xright; - Object cil = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value; - Location AS4xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xleft; - Location AS4xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).xright; - Object AS4 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value; - Location INTERFACE5xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location INTERFACE5xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object INTERFACE5 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location idnewintxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location idnewintxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object idnewint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location SEMICOLON7xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location SEMICOLON7xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object SEMICOLON7 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("require",0,new XMLElement.Terminal(idintxleft,"idint",idint,idintxright),(XMLElement)cil,new XMLElement.Terminal(idnewintxleft,"idnewint",idnewint,idnewintxright)); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("require",11, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-7)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 23: // capintlist ::= IDENT - { - XMLElement RESULT; - Location idcapxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location idcapxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object idcap = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("capintlist",0,new XMLElement.Terminal(idcapxleft,"idcap",idcap,idcapxright)); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("capintlist",12, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 24: // capintlist ::= capintlist COMMA IDENT - { - XMLElement RESULT; - Location cilxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xleft; - Location cilxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).xright; - Object cil = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - Location COMMA1xleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xleft; - Location COMMA1xright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).xright; - Object COMMA1 = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; - Location idcapxleft = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xleft; - Location idcapxright = ((java_cup.runtime.ComplexSymbolFactory.ComplexSymbol)CUP$Parser$stack.peek()).xright; - Object idcap = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - RESULT = new XMLElement.NonTerminal("capintlist",1,(XMLElement)cil,new XMLElement.Terminal(idcapxleft,"idcap",idcap,idcapxright)); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("capintlist",12, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 25: // capintlist ::= - { - XMLElement RESULT; - - RESULT = new XMLElement.NonTerminal("capintlist",2); - CUP$Parser$result = parser.getSymbolFactory().newSymbol("capintlist",12, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /* . . . . . .*/ - default: - throw new Exception( - "Invalid action number "+CUP$Parser$act_num+"found in internal parse table"); - - } - } /* end of method */ - - /** Method splitting the generated action code into several parts. */ - public final java_cup.runtime.Symbol CUP$Parser$do_action( - int CUP$Parser$act_num, - java_cup.runtime.lr_parser CUP$Parser$parser, - java.util.Stack CUP$Parser$stack, - int CUP$Parser$top) - throws java.lang.Exception - { - return CUP$Parser$do_action_part00000000( - CUP$Parser$act_num, - CUP$Parser$parser, - CUP$Parser$stack, - CUP$Parser$top); - } -} - -} diff --git a/iotjava/iotpolicy/IoTStubCompiler.java b/iotjava/iotpolicy/IoTStubCompiler.java new file mode 100644 index 0000000..c11d32f --- /dev/null +++ b/iotjava/iotpolicy/IoTStubCompiler.java @@ -0,0 +1,540 @@ +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 + * @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> 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>(); + 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>(); + pw = null; + dir = OUTPUT_DIRECTORY; + } + + + /** + * parsePolicyFile() parses policy file + *

+ * 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 + *

+ * 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 setIntfaces = reqDecl.getInterfaces(); + for (String strInt : setIntfaces) { + + // Initialize a set of methods + Set setMethods = new HashSet(); + // Get list of capabilities, e.g. ImageCapture, VideoRecording, etc. + List listCapab = reqDecl.getCapabList(strInt); + for (String strCap : listCapab) { + + // Get list of methods for each capability + List 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> 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 methParams = intDecl.getMethodParams(method); + List 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++ + *

+ * For C++ we use virtual classe as interface + */ + public void generateCPlusInterfaces() throws IOException { + + // Create a new directory + createDirectory(dir); + for (Map.Entry> 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"); + println(""); + println("using namespace std;"); + println(""); + println("class " + newIntface); + println("{"); + println("public:"); + // Write methods + for (String method : intMeth.getValue()) { + + List methParams = intDecl.getMethodParams(method); + List 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> 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 methParams = intDecl.getMethodParams(method); + List 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> 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"); + 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 methParams = intDecl.getMethodParams(method); + List 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 \t\tGenerate both Java and C++ stub files"); + System.out.println("\tjava IoTStubCompiler [options]"); + System.out.println("Options:"); + System.out.println("\t-java\t\tGenerate Java stub files"); + System.out.println("\t-cplus\t\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 is provided + if ((i + 1) < args.length) { + stubComp.setDirectory(args[i+1]); + } else + throw new Error("IoTStubCompiler: ERROR - please provide 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!"); + } + } +} + + + + diff --git a/iotjava/iotparser/Lexer.java b/iotjava/iotpolicy/parser/Lexer.java similarity index 78% rename from iotjava/iotparser/Lexer.java rename to iotjava/iotpolicy/parser/Lexer.java index c527efb..aa40a6e 100644 --- a/iotjava/iotparser/Lexer.java +++ b/iotjava/iotpolicy/parser/Lexer.java @@ -1,4 +1,4 @@ -package iotparser; +package iotpolicy.parser; /* The following code was generated by JFlex 1.6.1 */ @@ -46,13 +46,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\46\1\6\1\3\22\0\1\6\1\0\1\35"+ - "\1\0\1\1\3\0\1\40\1\41\2\0\1\36\1\0\1\37\1\0"+ - "\12\2\1\0\1\5\1\0\1\44\3\0\32\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\32\1\10\1\14\1\31\1\33\1\15\1\12"+ - "\1\11\1\26\1\30\1\34\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"; + "\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"; /** * Translates characters to character classes @@ -65,16 +65,16 @@ public class Lexer implements java_cup.runtime.Scanner, sym { private static final int [] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = - "\2\0\1\1\1\2\2\3\1\4\15\2\1\5\1\6"+ + "\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\10\2\1\21\1\22\1\23"+ - "\1\24\1\25\24\2\1\26\1\27\3\2\1\30\1\2"+ - "\1\31\2\2\1\32\2\2\1\33\2\2\1\34\6\2"+ - "\1\35\2\2\1\36\2\2\1\37\1\40\2\2\1\41"+ - "\3\2\1\42\2\2\1\43\3\2\1\44\1\45"; + "\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"; private static int [] zzUnpackAction() { - int [] result = new int[120]; + int [] result = new int[126]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; @@ -99,24 +99,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\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\116\0\116\0\116\0\116"+ - "\0\116\0\116\0\116\0\116\0\u02be\0\116\0\u02e5\0\u030c"+ - "\0\u0333\0\u035a\0\u0381\0\u03a8\0\u03cf\0\u03f6\0\u041d\0\u0444"+ - "\0\165\0\u046b\0\u0492\0\u04b9\0\u04e0\0\u0507\0\u052e\0\u0555"+ - "\0\u057c\0\116\0\116\0\116\0\116\0\u05a3\0\u05ca\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\165\0\165\0\u08d6\0\u08fd\0\u0924\0\165"+ - "\0\u094b\0\165\0\u0972\0\u0999\0\165\0\u09c0\0\u09e7\0\165"+ - "\0\u0a0e\0\u0a35\0\165\0\u0a5c\0\u0a83\0\u0aaa\0\u0ad1\0\u0af8"+ - "\0\u0b1f\0\165\0\u0b46\0\u0b6d\0\165\0\u0b94\0\u0bbb\0\165"+ - "\0\165\0\u0be2\0\u0c09\0\165\0\u0c30\0\u0c57\0\u0c7e\0\165"+ - "\0\u0ca5\0\u0ccc\0\165\0\u0cf3\0\u0d1a\0\u0d41\0\165\0\165"; + "\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"; private static int [] zzUnpackRowMap() { - int [] result = new int[120]; + int [] result = new int[126]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; @@ -142,75 +143,79 @@ public class Lexer implements java_cup.runtime.Scanner, sym { "\1\3\1\4\1\3\1\5\1\6\1\7\1\6\1\10"+ "\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\4\1\24\1\25\1\26\1\27\1\30\1\31\1\32"+ - "\1\33\1\34\1\3\1\0\3\35\1\0\1\3\30\35"+ - "\1\36\7\35\1\37\1\35\50\0\2\4\4\0\26\4"+ - "\16\0\1\40\43\0\2\4\4\0\1\4\1\41\24\4"+ - "\13\0\2\4\4\0\2\4\1\42\1\4\1\43\21\4"+ - "\13\0\2\4\4\0\11\4\1\44\14\4\13\0\2\4"+ - "\4\0\5\4\1\45\2\4\1\46\15\4\13\0\2\4"+ - "\4\0\5\4\1\47\20\4\13\0\2\4\4\0\12\4"+ - "\1\50\13\4\13\0\2\4\4\0\3\4\1\51\22\4"+ - "\13\0\2\4\4\0\5\4\1\52\3\4\1\53\14\4"+ - "\13\0\2\4\4\0\4\4\1\54\10\4\1\55\10\4"+ - "\13\0\2\4\4\0\5\4\1\56\20\4\13\0\2\4"+ - "\4\0\17\4\1\57\6\4\13\0\2\4\4\0\11\4"+ - "\1\60\14\4\13\0\2\4\4\0\1\61\25\4\12\0"+ - "\3\35\2\0\30\35\1\0\7\35\1\0\1\35\10\0"+ - "\1\62\1\63\3\0\1\64\17\0\1\65\16\0\1\6"+ - "\42\0\2\4\4\0\2\4\1\66\23\4\13\0\2\4"+ - "\4\0\6\4\1\67\17\4\13\0\2\4\4\0\5\4"+ - "\1\70\20\4\13\0\2\4\4\0\24\4\1\71\1\4"+ - "\13\0\2\4\4\0\5\4\1\72\20\4\13\0\2\4"+ - "\4\0\2\4\1\73\23\4\13\0\2\4\4\0\1\4"+ - "\1\74\24\4\13\0\2\4\4\0\5\4\1\75\20\4"+ - "\13\0\2\4\4\0\17\4\1\76\6\4\13\0\2\4"+ - "\4\0\3\4\1\77\22\4\13\0\2\4\4\0\15\4"+ - "\1\100\10\4\13\0\2\4\4\0\22\4\1\101\3\4"+ - "\13\0\2\4\4\0\1\102\25\4\13\0\2\4\4\0"+ - "\7\4\1\103\16\4\13\0\2\4\4\0\2\4\1\104"+ - "\23\4\13\0\2\4\4\0\2\4\1\105\23\4\13\0"+ - "\2\4\4\0\11\4\1\106\14\4\13\0\2\4\4\0"+ - "\1\107\25\4\13\0\2\4\4\0\6\4\1\110\17\4"+ - "\13\0\2\4\4\0\17\4\1\111\6\4\13\0\2\4"+ - "\4\0\12\4\1\112\13\4\13\0\2\4\4\0\11\4"+ - "\1\113\14\4\13\0\2\4\4\0\13\4\1\114\12\4"+ - "\13\0\2\4\4\0\15\4\1\115\10\4\13\0\2\4"+ - "\4\0\7\4\1\116\16\4\13\0\2\4\4\0\20\4"+ - "\1\117\5\4\13\0\2\4\4\0\6\4\1\120\17\4"+ - "\13\0\2\4\4\0\15\4\1\121\10\4\13\0\2\4"+ - "\4\0\16\4\1\122\7\4\13\0\2\4\4\0\12\4"+ - "\1\123\13\4\13\0\2\4\4\0\4\4\1\124\21\4"+ - "\13\0\2\4\4\0\4\4\1\125\21\4\13\0\2\4"+ - "\4\0\6\4\1\126\17\4\13\0\2\4\4\0\1\4"+ - "\1\127\24\4\13\0\2\4\4\0\2\4\1\130\23\4"+ - "\13\0\2\4\4\0\1\131\25\4\13\0\2\4\4\0"+ - "\11\4\1\132\14\4\13\0\2\4\4\0\2\4\1\133"+ - "\23\4\13\0\2\4\4\0\12\4\1\134\13\4\13\0"+ - "\2\4\4\0\6\4\1\135\17\4\13\0\2\4\4\0"+ - "\7\4\1\136\16\4\13\0\2\4\4\0\1\137\25\4"+ - "\13\0\2\4\4\0\5\4\1\140\20\4\13\0\2\4"+ - "\4\0\14\4\1\141\11\4\13\0\2\4\4\0\13\4"+ - "\1\142\12\4\13\0\2\4\4\0\6\4\1\143\17\4"+ - "\13\0\2\4\4\0\15\4\1\144\10\4\13\0\2\4"+ - "\4\0\11\4\1\145\14\4\13\0\2\4\4\0\1\146"+ - "\25\4\13\0\2\4\4\0\1\147\25\4\13\0\2\4"+ - "\4\0\20\4\1\150\5\4\13\0\2\4\4\0\16\4"+ - "\1\151\7\4\13\0\2\4\4\0\15\4\1\152\10\4"+ - "\13\0\2\4\4\0\11\4\1\153\14\4\13\0\2\4"+ - "\4\0\1\4\1\154\24\4\13\0\2\4\4\0\22\4"+ - "\1\155\3\4\13\0\2\4\4\0\12\4\1\156\13\4"+ - "\13\0\2\4\4\0\20\4\1\157\5\4\13\0\2\4"+ - "\4\0\3\4\1\160\22\4\13\0\2\4\4\0\2\4"+ - "\1\161\23\4\13\0\2\4\4\0\1\162\25\4\13\0"+ - "\2\4\4\0\11\4\1\163\14\4\13\0\2\4\4\0"+ - "\1\164\25\4\13\0\2\4\4\0\2\4\1\165\23\4"+ - "\13\0\2\4\4\0\5\4\1\166\20\4\13\0\2\4"+ - "\4\0\10\4\1\167\15\4\13\0\2\4\4\0\1\4"+ - "\1\170\24\4\12\0"; + "\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"; private static int [] zzUnpackTrans() { - int [] result = new int[3432]; + int [] result = new int[3720]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; @@ -248,11 +253,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\15\1\10\11\1\1\1\11"+ - "\1\1\1\0\21\1\4\11\103\1"; + "\2\0\1\11\2\1\2\11\16\1\10\11\1\1\1\11"+ + "\1\1\1\0\22\1\4\11\107\1"; private static int [] zzUnpackAttribute() { - int [] result = new int[120]; + int [] result = new int[126]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; @@ -374,7 +379,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 < 164) { + while (i < 168) { int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); @@ -744,152 +749,156 @@ public class Lexer implements java_cup.runtime.Scanner, sym { { /* throw new Error("Illegal character <"+ yytext()+">");*/ error("Illegal character <"+ yytext()+">"); } - case 38: break; + case 39: break; case 2: { return symbol("Identifier",IDENT, yytext()); } - case 39: break; + case 40: break; case 3: { /* ignore */ } - case 40: break; + case 41: break; case 4: { return symbol("semicolon",SEMICOLON); } - case 41: break; + case 42: break; case 5: { string.setLength(0); yybegin(STRING); } - case 42: break; + case 43: break; case 6: { return symbol("comma",COMMA); } - case 43: break; + case 44: break; case 7: { return symbol("dot",DOT); } - case 44: break; + case 45: break; case 8: { return symbol("(",LPAR); } - case 45: break; + case 46: break; case 9: { return symbol(")",RPAR); } - case 46: break; + case 47: break; case 10: { return symbol("{",BEGIN); } - case 47: break; + case 48: break; case 11: { return symbol("}",END); } - case 48: break; + case 49: break; case 12: { return symbol("=",ASSIGN); } - case 49: break; + case 50: break; case 13: { string.append( yytext() ); } - case 50: break; + case 51: break; case 14: { yybegin(YYINITIAL); return symbol("StringConst",STRINGCONST,string.toString(),string.length()); } - case 51: break; + case 52: break; case 15: { string.append('\\'); } - case 52: break; + case 53: break; case 16: { return symbol("as",AS); } - case 53: break; + case 54: break; case 17: { string.append('\n'); } - case 54: break; + case 55: break; case 18: { string.append('\t'); } - case 55: break; + case 56: break; case 19: { string.append('\r'); } - case 56: break; + case 57: break; case 20: { string.append('\"'); } - case 57: break; + case 58: break; case 21: - { return symbol("int",TYPE, "INT" ); + { return symbol("int",TYPE, "int" ); } - case 58: break; + case 59: break; case 22: - { return symbol("byte",TYPE, "BYTE" ); + { return symbol("byte",TYPE, "byte" ); } - case 59: break; + case 60: break; case 23: - { return symbol("long",TYPE, "LONG" ); + { return symbol("long",TYPE, "long" ); } - case 60: break; + case 61: break; case 24: - { return symbol("char",TYPE, "CHAR" ); + { return symbol("char",TYPE, "char" ); } - case 61: break; + case 62: break; case 25: - { return symbol("void",TYPE, "VOID" ); + { return symbol("void",TYPE, "void" ); } - case 62: break; + case 63: break; case 26: { return symbol("with",WITH); } - case 63: break; + case 64: break; case 27: - { return symbol("short",TYPE, "SHORT" ); + { return symbol("short",TYPE, "short" ); } - case 64: break; + case 65: break; case 28: - { return symbol("float",TYPE, "FLOAT" ); + { return symbol("float",TYPE, "float" ); } - case 65: break; + case 66: break; case 29: - { return symbol("string",TYPE, "STRING" ); + { return symbol("string",TYPE, "String" ); } - case 66: break; + case 67: break; case 30: - { return symbol("double",TYPE, "DOUBLE" ); + { return symbol("double",TYPE, "double" ); } - case 67: break; + case 68: break; case 31: - { return symbol("public",PUBLIC); + { return symbol("String",TYPE, "String" ); } - case 68: break; + case 69: break; case 32: - { return symbol("method",METHOD); + { return symbol("public",PUBLIC); } - case 69: break; + case 70: break; case 33: - { return symbol("boolean",TYPE, "BOOL" ); + { return symbol("method",METHOD); } - case 70: break; + case 71: break; case 34: - { return symbol("requires",REQUIRES); + { return symbol("boolean",TYPE, "boolean" ); } - case 71: break; + case 72: break; case 35: - { return symbol("interface",INTERFACE); + { return symbol("requires",REQUIRES); } - case 72: break; + case 73: break; case 36: - { return symbol("capability",CAPABILITY); + { return symbol("interface",INTERFACE); } - case 73: break; + case 74: break; case 37: + { return symbol("capability",CAPABILITY); + } + case 75: break; + case 38: { return symbol("description",DESCRIPTION); } - case 74: break; + case 76: break; default: zzScanError(ZZ_NO_MATCH); } diff --git a/iotjava/iotpolicy/parser/Parser.java b/iotjava/iotpolicy/parser/Parser.java new file mode 100644 index 0000000..f06a0b9 --- /dev/null +++ b/iotjava/iotpolicy/parser/Parser.java @@ -0,0 +1,777 @@ +package iotpolicy.parser; + +//---------------------------------------------------- +// The following code was generated by CUP v0.11b 20160615 (GIT 4ac7450) +//---------------------------------------------------- + +import java_cup.runtime.ComplexSymbolFactory; +import java_cup.runtime.ScannerBuffer; +import java_cup.runtime.XMLElement; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; +import java.io.*; +import javax.xml.transform.*; +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. + */ +@SuppressWarnings({"rawtypes"}) +public class Parser extends java_cup.runtime.lr_parser { + + public final Class getSymbolContainer() { + return sym.class; +} + + /** Default constructor. */ + @Deprecated + public Parser() {super();} + + /** Constructor which sets the default scanner. */ + @Deprecated + public Parser(java_cup.runtime.Scanner s) {super(s);} + + /** Constructor which sets the default scanner. */ + public Parser(java_cup.runtime.Scanner s, java_cup.runtime.SymbolFactory sf) {super(s,sf);} + + /** 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" }); + + /** Access to production table. */ + public short[][] production_table() {return _production_table;} + + /** 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" }); + + /** Access to parse-action table. */ + public short[][] action_table() {return _action_table;} + + /** reduce_goto 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\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" + + "\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" + + "\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" }); + + /** Access to reduce_goto table. */ + public short[][] reduce_table() {return _reduce_table;} + + /** Instance of action encapsulation class. */ + protected CUP$Parser$actions action_obj; + + /** Action encapsulation object initializer. */ + protected void init_actions() + { + action_obj = new CUP$Parser$actions(this); + } + + /** Invoke a user supplied parse action. */ + public java_cup.runtime.Symbol do_action( + int act_num, + java_cup.runtime.lr_parser parser, + java.util.Stack stack, + int top) + throws java.lang.Exception + { + /* call code in generated class */ + return action_obj.CUP$Parser$do_action(act_num, parser, stack, top); + } + + /** Indicates start state. */ + public int start_state() {return 0;} + /** Indicates start production. */ + public int start_production() {return 1;} + + /** EOF Symbol index. */ + public int EOF_sym() {return 0;} + + /** error Symbol index. */ + public int error_sym() {return 1;} + + + + public Parser(Lexer lex, ComplexSymbolFactory sf) { + super(lex,sf); + } + 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; + + //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();*/ + + } + + +/** Cup generated class to encapsulate user supplied action code.*/ +@SuppressWarnings({"rawtypes", "unchecked", "unused"}) +class CUP$Parser$actions { + private final Parser parser; + + /** Constructor */ + CUP$Parser$actions(Parser parser) { + this.parser = parser; + } + + /** Method 0 with the actual generated action code for actions 0 to 300. */ + public final java_cup.runtime.Symbol CUP$Parser$do_action_part00000000( + int CUP$Parser$act_num, + java_cup.runtime.lr_parser CUP$Parser$parser, + java.util.Stack CUP$Parser$stack, + int CUP$Parser$top) + throws java.lang.Exception + { + /* Symbol object for return from actions */ + java_cup.runtime.Symbol CUP$Parser$result; + + /* select the action based on the action number */ + switch (CUP$Parser$act_num) + { + /*. . . . . . . . . . . . . . . . . . . .*/ + case 0: // policy ::= intface capablist reqlist + { + 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; + + 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); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 1: // $START ::= policy EOF + { + Object RESULT =null; + int start_valleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int start_valright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + ParseNode start_val = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + RESULT = start_val; + CUP$Parser$result = parser.getSymbolFactory().newSymbol("$START",0, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + /* ACCEPT */ + CUP$Parser$parser.done_parsing(); + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 2: // intface ::= PUBLIC INTERFACE IDENT BEGIN methlist END + { + 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; + + ParseNode pn = new ParseNode("interface"); + pn.addChild("intface_ident").setLiteral(idint); + pn.addChild(ml); + 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); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 3: // intface ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("interface"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("intface",1, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 4: // methlist ::= methlist meth + { + ParseNode RESULT =null; + 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 mleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int mright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + ParseNode m = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + ml.addChild(m); + RESULT = ml; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("methlist",2, ((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 5: // methlist ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("method_list"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("methlist",2, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 6: // meth ::= PUBLIC TYPE IDENT LPAR paramlist RPAR SEMICOLON + { + ParseNode RESULT =null; + int typemethleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).left; + int typemethright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).right; + Object typemeth = (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_type").setLiteral(typemeth); + 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 7: // paramlist ::= paramlist param + { + ParseNode RESULT =null; + int plleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int plright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + ParseNode pl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + int pleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int pright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + ParseNode p = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + pl.addChild(p); + RESULT = pl; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("paramlist",4, ((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 8: // paramlist ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("param_list"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("paramlist",4, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 9: // param ::= TYPE IDENT COMMA + { + ParseNode RESULT =null; + int typeprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; + int typeprmright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).right; + Object typeprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; + int idprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int idprmright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + Object idprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + + ParseNode pn = new ParseNode("param"); + pn.addChild("param_type").setLiteral(typeprm); + pn.addChild("param_ident").setLiteral(idprm); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("param",5, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 10: // param ::= TYPE IDENT + { + ParseNode RESULT =null; + int typeprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int typeprmright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + Object typeprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + int idprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int idprmright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + Object idprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + ParseNode pn = new ParseNode("param"); + pn.addChild("param_type").setLiteral(typeprm); + pn.addChild("param_ident").setLiteral(idprm); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("param",5, ((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 11: // param ::= IDENT IDENT COMMA + { + ParseNode RESULT =null; + int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; + int clsprmright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).right; + Object clsprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; + int idprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int idprmright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + Object idprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + + ParseNode pn = new ParseNode("param"); + pn.addChild("param_class").setLiteral(clsprm); + pn.addChild("param_ident").setLiteral(idprm); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("param",5, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 12: // param ::= IDENT IDENT + { + ParseNode RESULT =null; + int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int clsprmright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + Object clsprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + int idprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int idprmright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + Object idprm = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + ParseNode pn = new ParseNode("param"); + pn.addChild("param_class").setLiteral(clsprm); + pn.addChild("param_ident").setLiteral(idprm); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("param",5, ((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 13: // 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 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; + + 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 ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("capab_list"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("capablist",6, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 15: // capab ::= CAPABILITY IDENT DOT 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; + int ccontleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int ccontright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + 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); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 16: // capabcont ::= capabcont cont + { + ParseNode RESULT =null; + int ccontleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int ccontright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + ParseNode ccont = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + int cntleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int cntright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + ParseNode cnt = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + ccont.addChild(cnt); + RESULT = ccont; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("capabcont",8, ((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 17: // capabcont ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("capab_content"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("capabcont",8, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 18: // 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; + + ParseNode pn = new ParseNode("capab_content"); + pn.addChild("capab_desc").setLiteral(str); + 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); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 19: // cont ::= METHOD ASSIGN IDENT 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; + + ParseNode pn = new ParseNode("capab_content"); + pn.addChild("capab_ident").setLiteral(idmeth); + 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); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 20: // reqlist ::= reqlist require + { + ParseNode RESULT =null; + int rlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int rlright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + ParseNode rl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + int reqleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int reqright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + ParseNode req = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + rl.addChild(req); + RESULT = rl; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("reqlist",10, ((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 21: // reqlist ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("requires_list"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("reqlist",10, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 22: // 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; + int idintright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)).right; + Object idint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-6)).value; + int cilleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).left; + int cilright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).right; + ParseNode cil = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value; + int idnewintleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int idnewintright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + Object idnewint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + + ParseNode pn = new ParseNode("requires"); + pn.addChild("intface_ident").setLiteral(idint); + pn.addChild(cil); + pn.addChild("new_intface_ident").setLiteral(idnewint); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("require",11, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-7)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 23: // capintlist ::= IDENT + { + ParseNode RESULT =null; + int idcapleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int idcapright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + Object idcap = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + ParseNode pn = new ParseNode("capab_ident_list"); + pn.addChild("capab_ident").setLiteral(idcap); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("capintlist",12, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 24: // capintlist ::= capintlist COMMA IDENT + { + ParseNode RESULT =null; + int cilleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; + int cilright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).right; + ParseNode cil = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; + int idcapleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int idcapright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + Object idcap = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + cil.addChild("capab_ident").setLiteral(idcap); + RESULT = cil; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("capintlist",12, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 25: // capintlist ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("capab_ident_list"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("capintlist",12, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /* . . . . . .*/ + default: + throw new Exception( + "Invalid action number "+CUP$Parser$act_num+"found in internal parse table"); + + } + } /* end of method */ + + /** Method splitting the generated action code into several parts. */ + public final java_cup.runtime.Symbol CUP$Parser$do_action( + int CUP$Parser$act_num, + java_cup.runtime.lr_parser CUP$Parser$parser, + java.util.Stack CUP$Parser$stack, + int CUP$Parser$top) + throws java.lang.Exception + { + return CUP$Parser$do_action_part00000000( + CUP$Parser$act_num, + CUP$Parser$parser, + CUP$Parser$stack, + CUP$Parser$top); + } +} + +} diff --git a/iotjava/iotparser/sym.java b/iotjava/iotpolicy/parser/sym.java similarity index 98% rename from iotjava/iotparser/sym.java rename to iotjava/iotpolicy/parser/sym.java index d34e748..3a5f6dc 100644 --- a/iotjava/iotparser/sym.java +++ b/iotjava/iotpolicy/parser/sym.java @@ -1,4 +1,4 @@ -package iotparser; +package iotpolicy.parser; //---------------------------------------------------- // The following code was generated by CUP v0.11b 20160615 (GIT 4ac7450) diff --git a/iotjava/iotpolicy/tree/CapabilityDecl.java b/iotjava/iotpolicy/tree/CapabilityDecl.java new file mode 100644 index 0000000..71ec2ca --- /dev/null +++ b/iotjava/iotpolicy/tree/CapabilityDecl.java @@ -0,0 +1,140 @@ +package iotpolicy.tree; + +import java.util.ArrayList; +import java.util.List; + +/** Class CapabilityDecl is a data structure for capability + * declaration section (list of capabilities) in the policy file. + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-09-20 + */ +public final class CapabilityDecl { + + /** + * Class properties + */ + private String origInt; + + /** + * A "capability" statement: + * capability Camera.ImageCapture { + * description = "The quick brown fox jumps over the smart dog"; + * description = "Another description"; + * method = MethodA; + * method = MethodB; + * } + * In this data structure we will record its capability name, i.e. ImageCapture + * and its descriptions and methods. + */ + private List listCapabs; // list of capabilities + private List> listDescs; // list of descriptions + private List> listMethods; // list of methods + + /** + * Class constructors + */ + public CapabilityDecl() { + + origInt = null; + listCapabs = new ArrayList(); + listDescs = new ArrayList>(); + listMethods = new ArrayList>(); + } + + + public CapabilityDecl(String _origInt) { + + origInt = _origInt; + listCapabs = new ArrayList(); + listDescs = new ArrayList>(); + listMethods = new ArrayList>(); + } + + + /** + * addNewCapability() adds a new capability into the list + */ + public void addNewCapability(String newCap) { + + listCapabs.add(newCap); + listDescs.add(new ArrayList()); + listMethods.add(new ArrayList()); + } + + + /** + * addNewDescription() adds a new description into the list + */ + public void addNewDescription(String cap, String newDesc) { + + int index = listCapabs.indexOf(cap); + List listDesc = listDescs.get(index); + listDesc.add(newDesc); + } + + + /** + * addNewMethod() adds a new method into the list + */ + public void addNewMethod(String cap, String newMethod) { + + int index = listCapabs.indexOf(cap); + List listMethod = listMethods.get(index); + listMethod.add(newMethod); + } + + + /** + * getCapabilities() gets list of capabilities + */ + public List getCapabilities() { + + return listCapabs; + } + + + /** + * getDescriptions() gets list of descriptions + */ + public List getDescriptions(String cap) { + + int index = listCapabs.indexOf(cap); + return listDescs.get(index); + } + + + /** + * getMethods() gets list of methods + */ + public List getMethods(String cap) { + + int index = listCapabs.indexOf(cap); + return listMethods.get(index); + } + + + public static void main(String[] args) { + + CapabilityDecl cd = new CapabilityDecl("Camera"); + cd.addNewCapability("ImageCapture"); + cd.addNewDescription("ImageCapture", "The quick brown fox jumps over the smart dog"); + cd.addNewDescription("ImageCapture", "ImageCapture capability"); + cd.addNewMethod("ImageCapture", "MethodA"); + cd.addNewMethod("ImageCapture", "MethodC"); + cd.addNewMethod("ImageCapture", "MethodD"); + + cd.addNewCapability("VideoRecording"); + cd.addNewDescription("VideoRecording", "The quick brown fox jumps over the smart dog"); + cd.addNewDescription("VideoRecording", "VideoRecording "); + cd.addNewMethod("VideoRecording", "MethodE"); + cd.addNewMethod("VideoRecording", "MethodF"); + + System.out.println("Set of capabilities: " + cd.getCapabilities().toString()); + System.out.println("Set of descriptions: " + cd.getDescriptions("VideoRecording").toString()); + System.out.println("Set of methods: " + cd.getMethods("VideoRecording").toString()); + System.out.println("Set of descriptions: " + cd.getDescriptions("ImageCapture").toString()); + System.out.println("Set of methods: " + cd.getMethods("ImageCapture").toString()); + } +} diff --git a/iotjava/iotpolicy/tree/InterfaceDecl.java b/iotjava/iotpolicy/tree/InterfaceDecl.java new file mode 100644 index 0000000..27e9326 --- /dev/null +++ b/iotjava/iotpolicy/tree/InterfaceDecl.java @@ -0,0 +1,157 @@ +package iotpolicy.tree; + +import java.util.ArrayList; +import java.util.List; + +/** Class InterfaceDecl is a data structure for interface + * declaration section in the policy file. + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-09-20 + */ +public final class InterfaceDecl { + + /** + * Class properties + */ + private String origInt; + + /** + * A "interface" statement: + * 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(); + * } + * In this data structure we will record its interface name, i.e. Camera + * its method names and the parameters for each method. + */ + private List listMethods; // Method names, e.g. MethodA + private List listMethodTypes; // Method types, e.g. void + private List> listMethodParams; // Method parameter names, e.g. A, B + private List> listMethodParamTypes; // Method parameter types, e.g. int, int + + /** + * Class constructors + */ + public InterfaceDecl() { + + origInt = null; + listMethods = new ArrayList(); + listMethodTypes = new ArrayList(); + listMethodParams = new ArrayList>(); + listMethodParamTypes = new ArrayList>(); + } + + + public InterfaceDecl(String _origInt) { + + origInt = _origInt; + listMethods = new ArrayList(); + listMethodTypes = new ArrayList(); + listMethodParams = new ArrayList>(); + listMethodParamTypes = new ArrayList>(); + } + + + /** + * addNewMethod() adds a new method name and type into the list + */ + public void addNewMethod(String newMethod, String newMethodType) { + + listMethods.add(newMethod); + listMethodTypes.add(newMethodType); + listMethodParams.add(new ArrayList()); + listMethodParamTypes.add(new ArrayList()); + } + + + /** + * addMethodParam() adds the name and type of a parameter + */ + public void addMethodParam(String method, String paramName, String paramType) { + + int index = listMethods.indexOf(method); + List listMethodParam = listMethodParams.get(index); + listMethodParam.add(paramName); + List listMethodParamType = listMethodParamTypes.get(index); + listMethodParamType.add(paramType); + } + + + /** + * getMethods() gets list of methods + */ + public List getMethods() { + + return listMethods; + } + + + /** + * getMethodTypes() gets method types + */ + public List getMethodTypes() { + + return listMethodTypes; + } + + + /** + * getMethodType() gets a method type + */ + public String getMethodType(String method) { + + int index = listMethods.indexOf(method); + return listMethodTypes.get(index); + } + + + /** + * getMethodParams() gets list of method parameters for a method + */ + public List getMethodParams(String method) { + + int index = listMethods.indexOf(method); + return listMethodParams.get(index); + } + + + /** + * getMethodParams() gets list of method parameter types for a method + */ + public List getMethodParamTypes(String method) { + + int index = listMethods.indexOf(method); + return listMethodParamTypes.get(index); + } + + + public static void main(String[] args) { + + InterfaceDecl id = new InterfaceDecl("Camera"); + id.addNewMethod("MethodA", "void"); + id.addNewMethod("MethodB", "int"); + id.addNewMethod("MethodC", "String"); + id.addMethodParam("MethodA", "A", "int"); + id.addMethodParam("MethodA", "B", "int"); + id.addMethodParam("MethodB", "C", "int"); + id.addMethodParam("MethodB", "D", "string"); + 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()); + System.out.println("Set of params: " + id.getMethodParams("MethodB").toString()); + System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodB").toString()); + System.out.println("Set of params: " + id.getMethodParams("MethodC").toString()); + System.out.println("Set of paramtypes: " + id.getMethodParamTypes("MethodC").toString()); + } +} diff --git a/iotjava/iotpolicy/tree/ParseNode.java b/iotjava/iotpolicy/tree/ParseNode.java new file mode 100644 index 0000000..75ade8e --- /dev/null +++ b/iotjava/iotpolicy/tree/ParseNode.java @@ -0,0 +1,234 @@ +/* + + Class: ParseNode + Author: Dan Roy + Purpose: ParseNode is used to represent a parse production + + */ + +package iotpolicy.tree; + +import java.util.*; + +public class ParseNode implements Walkable { + + private String label; + private ParseNode parent; + private ParseNodeVector children; + private int line; + private Object literal; + + //private SymbolTable st; + + public ParseNode(String label) { + this.label = label; + this.line = -1; + this.parent = null; + this.literal=null; + children = new ParseNodeVector(); + } + + public ParseNode (String label, int line) { + this.label = label; + this.line = line; + this.parent = null; + this.literal=null; + children = new ParseNodeVector(); + } + + public void setLabel(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + public void setLiteral(Object o) { + literal=o; + } + + public Object getLiteral() { + return literal; + } + + /* + public void setSymbolTable(SymbolTable st) { + if (st == null) { + throw new IRException("symboltable is null!"); + } + this.st = st; + } + + public SymbolTable getSymbolTable() { + if (st == null) { + if (parent != null) { + return parent.getSymbolTable(); + } else { + return null; + } + } else { + return st; + } + } + */ + + public int getLine() { + if (line >= 0) { + return line; + } else { + if (parent != null) { + return parent.getLine(); + } else { + return 0; + } + } + } + + public void setParent(ParseNode parent) { + this.parent = parent; + } + + public ParseNode getParent() { + return parent; + } + + public ParseNode insertChild(ParseNode child) { + if (child == null) { + throw new NullPointerException("Can't add null node to parse tree"); + } + + children.insertElementAt(child, 0); + child.setParent(this); + return child; + } + + public ParseNode insertChild(String newlabel) { + ParseNode child = new ParseNode(newlabel, -1); + return insertChild(child); + } + + public ParseNode addChild(ParseNode child) { + + if (child == null) { + throw new NullPointerException("Can't add null node to parse tree: "+getLabel()); + } + + children.addElement(child); + child.setParent(this); + return child; + } + + public ParseNode addChild(String newlabel) { + + ParseNode child = new ParseNode(newlabel, -1); + children.addElement(child); + child.setParent(this); + return child; + } + + public ParseNode addChild(String newlabel, int line) { + ParseNode child = new ParseNode(newlabel, line); + children.addElement(child); + child.setParent(this); + return child; + } + + public ParseNodeVector getChildren() { + return children; + } + + public ParseNode getChild(String label) { + int i; + ParseNode p; + + for (i = 0; i < children.size(); i++) { + p = children.elementAt(i); + if (p.getLabel().equals(label)) { + return p; + } + } + + return null; + } + + public ParseNode getRoot() { + return (parent == null)?this:parent.getRoot(); + } + + public String getTerminal() { + ParseNode pn = children.elementAt(0); + if (pn == null) { + return null; + } else { + return pn.getLabel(); + } + } + + public ParseNode getFirstChild() { + return children.elementAt(0); + } + + public ParseNodeVector getChildren(String label) { + int i; + ParseNodeVector v = new ParseNodeVector(); + + for (i = 0; i < children.size(); i++) { + ParseNode pn = children.elementAt(i); + if (pn.getLabel().equals(label)) + v.addElement(pn); + } + + return v; + } + + public String getNodeName() { + return label + " - " + getLine(); + } + + public int getNeighborCount() { + return children.size(); + } + + public Object getNeighbor(int index) { + return children.elementAt(index); + } + + public String doIndent(int indent) { + + String output = new String(); + for(int i=0; i\n"; + } else { + output += doIndent(indent) + "<" + label + ">\n"; + indent += 2; + + if (recursive) { + for (int i = 0; i < children.size(); i++) { + Walkable w = (Walkable)children.elementAt(i); + output += w.PPrint(indent, true); + } + } else { + for (int i = 0; i < children.size(); i++) { + Walkable w = (Walkable)children.elementAt(i); + output += doIndent(indent) + "<" + w.getNodeName() + "/>\n"; + } + } + + indent -= 2; + output += doIndent(indent) + "\n"; + } + + return output; + } + +} + diff --git a/iotjava/iotpolicy/tree/ParseNodeVector.java b/iotjava/iotpolicy/tree/ParseNodeVector.java new file mode 100644 index 0000000..29c95dc --- /dev/null +++ b/iotjava/iotpolicy/tree/ParseNodeVector.java @@ -0,0 +1,27 @@ +package iotpolicy.tree; + +import java.util.Vector; + +public class ParseNodeVector { + private Vector v; + + public ParseNodeVector() { + v = new Vector(); + } + + public void addElement(ParseNode pn) { + v.addElement(pn); + } + + public void insertElementAt(ParseNode pn, int n) { + v.insertElementAt(pn, n); + } + + public ParseNode elementAt(int i) { + return (ParseNode) v.elementAt(i); + } + + public int size() { + return v.size(); + } +} diff --git a/iotjava/iotpolicy/tree/ParseTreeHandler.java b/iotjava/iotpolicy/tree/ParseTreeHandler.java new file mode 100644 index 0000000..69a36c2 --- /dev/null +++ b/iotjava/iotpolicy/tree/ParseTreeHandler.java @@ -0,0 +1,257 @@ +package iotpolicy.tree; + +import java_cup.runtime.ComplexSymbolFactory; +import java_cup.runtime.ScannerBuffer; +import java.io.*; +import iotpolicy.tree.ParseNodeVector; +import iotpolicy.tree.ParseNode; + +/** 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 + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-09-20 + */ +public final class ParseTreeHandler { + + /** + * Class properties + */ + private ParseNode pn; + private InterfaceDecl intDecl; + private CapabilityDecl capDecl; + private RequiresDecl reqDecl; + + + /** + * Class constructors + */ + public ParseTreeHandler() { + + pn = null; + intDecl = new InterfaceDecl(); + capDecl = new CapabilityDecl(); + reqDecl = new RequiresDecl(); + } + + + public ParseTreeHandler(String _intFace, ParseNode _pn) { + + pn = _pn; + intDecl = new InterfaceDecl(_intFace); + capDecl = new CapabilityDecl(_intFace); + reqDecl = new RequiresDecl(_intFace); + } + + + /** + * processInterfaceDecl() processes interface declaration part + */ + public void processInterfaceDecl() { + + // Get the root - interface list (element 0) + ParseNodeVector pnv = pn.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++) { + + // 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 + 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++) { + + ParseNode pnGen5 = pnvGen5.elementAt(j); + ParseNodeVector pnvGen6 = pnGen5.getChildren(); + // Param type + 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()); + } + //System.out.println(); + } + } + + + /** + * processCapabilityDecl() processes capability declaration part + */ + 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 pnvGen2 = pnRoot.getChildren(); + if (pnvGen2.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++) { + + ParseNode pnGen2 = pnvGen2.elementAt(i); + // Get the next level child for capabilities + ParseNodeVector pnvGen3 = pnGen2.getChildren(); + // Get the capability name, e.g. ImageCapture for Camera.ImageCapture + ParseNode pnGen3_capab = pnvGen3.elementAt(1); + // Add new capability + capDecl.addNewCapability(pnGen3_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(); + // Iterate over the list of capability contents + for(int j = 0; j < pnvGen4.size(); j++) { + + ParseNode pnGen4 = pnvGen4.elementAt(j); + ParseNodeVector pnvGen5 = pnGen4.getChildren(); + ParseNode pnGen5 = pnvGen5.elementAt(0); + // Check the label and separate between description (capab_desc) + // and method name (capab_ident) + String label = pnGen5.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()); + } else + throw new Error("ParseTreeHandler: Unknown label '" + label + "' while operating on parse tree!"); + + } + } + } + + + /** + * processRequiresDecl() processes "requires" declaration part + */ + 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 pnvGen2 = pnRoot.getChildren(); + if (pnvGen2.size() == 0) { + throw new Error("ParseTreeHandler: 'Requires' declaration is missing! Please check your policy file..."); + } + // Iterate over the list of requires statements + for(int i = 0; i < pnvGen2.size(); i++) { + + ParseNode pnGen2 = pnvGen2.elementAt(i); + ParseNodeVector pnvGen3 = pnGen2.getChildren(); + // Get the new interface that we want to generate + ParseNode pnGen3_intface = pnvGen3.elementAt(2); + reqDecl.addNewIntface(pnGen3_intface.getLiteral().toString()); + // Get capability list at element 1 + ParseNode pnGen3_capab_list = pnvGen3.elementAt(1); + ParseNodeVector pnvGen4 = pnGen3_capab_list.getChildren(); + // Browse through capabilities + for (int j = 0; j < pnvGen4.size(); j++) { + ParseNode pnGen4 = pnvGen4.elementAt(j); + reqDecl.addNewCapability(pnGen3_intface.getLiteral().toString(), + pnGen4.getLiteral().toString()); + } + } + } + + + /** + * getInterfaceDecl() returns InterfaceDecl object + */ + public InterfaceDecl getInterfaceDecl() { + + return intDecl; + } + + + /** + * getCapabilityDecl() returns CapabilityDecl object + */ + public CapabilityDecl getCapabilityDecl() { + + return capDecl; + } + + + /** + * getRequiresDecl() returns RequiresDecl object + */ + public RequiresDecl getRequiresDecl() { + + return reqDecl; + } + + + /** + * getOrigIntface() returns the original interface in policy, e.g. Camera + *

+ * The ParseNode object should be the one returned from .parse().value + */ + public static String getOrigIntface(ParseNode pn) { + + // Get the root: just keyword "interface" + ParseNodeVector pnv = pn.getChildren(); + ParseNode pnRoot = pnv.elementAt(0); + // Get the child: intface_ident = original interface identifier, e.g. Camera + 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(0); + // Confirm that this is "intface_ident" + if (pnGen2.getLabel().equals("intface_ident")) { + if (pnGen2.getLiteral() != null) { + return pnGen2.getLiteral().toString(); + } else + throw new Error("ParseTreeHandler: No interface name found! Please fix policy file!"); + } 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(); + }*/ +} diff --git a/iotjava/iotpolicy/tree/RequiresDecl.java b/iotjava/iotpolicy/tree/RequiresDecl.java new file mode 100644 index 0000000..73239e1 --- /dev/null +++ b/iotjava/iotpolicy/tree/RequiresDecl.java @@ -0,0 +1,106 @@ +package iotpolicy.tree; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** Class RequiresDecl is a data structure for "requires" + * declaration section in the policy file. + * This section declares the needed interfaces based on + * different combinations of capabilities. + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-09-20 + */ +public final class RequiresDecl { + + /** + * Class properties + */ + private String origInt; + + /** + * A "requires" statement: + * requires Camera with VideoRecording, ImageCapture as interface CameraWithCaptureAndData; + * + * In this data structure we will record its new interface name, i.e. CameraWithCaptureAndData + * and its required capabilities, i.e. VideoRecording and ImageCapture. + */ + private Map> mapRequires; + + /** + * Class constructors + */ + public RequiresDecl() { + + origInt = null; + mapRequires = new HashMap>(); + } + + + public RequiresDecl(String _origInt) { + + origInt = _origInt; + mapRequires = new HashMap>(); + } + + + /** + * addNewInterface() adds a new interface name into the map + */ + public void addNewIntface(String newInt) { + + mapRequires.put(newInt, new ArrayList()); + } + + + /** + * addNewCapability() adds a new capability name into the map + */ + public void addNewCapability(String intFace, String newCapab) { + + List listCapab = mapRequires.get(intFace); + listCapab.add(newCapab); + } + + + /** + * getInterfaces() gets set of interfaces + */ + public Set getInterfaces() { + + return mapRequires.keySet(); + } + + + /** + * getCapabList() gets list of capabilities + */ + public List getCapabList(String intFace) { + + return mapRequires.get(intFace); + } + + + public static void main(String[] args) { + + RequiresDecl rd = new RequiresDecl("Camera"); + rd.addNewIntface("CameraWithCaptureAndData"); + rd.addNewCapability("CameraWithCaptureAndData", "ImageCapture"); + rd.addNewCapability("CameraWithCaptureAndData", "VideoRecording"); + + System.out.println("Set of interfaces: " + rd.getInterfaces().toString()); + System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString()); + + rd.addNewIntface("CameraWithCaptureAndRecording"); + rd.addNewCapability("CameraWithCaptureAndRecording", "ImageCapture"); + rd.addNewCapability("CameraWithCaptureAndRecording", "BackupData"); + + System.out.println("Set of interfaces: " + rd.getInterfaces().toString()); + System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString()); + System.out.println("Set of capabilities: " + rd.getCapabList("CameraWithCaptureAndData").toString()); + } +} diff --git a/iotjava/iotpolicy/tree/Walkable.java b/iotjava/iotpolicy/tree/Walkable.java new file mode 100644 index 0000000..ea1d55c --- /dev/null +++ b/iotjava/iotpolicy/tree/Walkable.java @@ -0,0 +1,34 @@ +package iotpolicy.tree; + +/** + * The Walkable interface specifies a set of methods that defines a web. + */ + +public interface Walkable { + + /** + * Returns the name of the node + */ + public String getNodeName(); + + + /** + * Returns the number of neighbors from this node + */ + public int getNeighborCount(); + + + /** + * Returns a specific neighbor + */ + public Object getNeighbor(int index); + + /** + * Returns a pretty print of the representation of the node. + * + * @param indent number of blank spaces to skip for a new line + * @param recursive if true, recursively print children + */ + public String PPrint(int indent, boolean recursive); +} + diff --git a/others/javacup/iotparser.cup b/others/javacup/iotparser.cup index ca44aae..22e929a 100644 --- a/others/javacup/iotparser.cup +++ b/others/javacup/iotparser.cup @@ -8,6 +8,7 @@ import java.io.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; + parser code {: public Parser(Lexer lex, ComplexSymbolFactory sf) { super(lex,sf); @@ -19,7 +20,9 @@ parser code {: ScannerBuffer lexer = new ScannerBuffer(new Lexer(new BufferedReader(new FileReader(args[0])),csf)); // start parsing Parser p = new Parser(lexer,csf); - XMLElement e = (XMLElement)p.parse().value; + 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"); @@ -34,7 +37,7 @@ parser code {: 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"))); + transformer.transform(text, new StreamResult(new File("ast.html")));*/ } :}; @@ -43,9 +46,9 @@ terminal PUBLIC, INTERFACE, CAPABILITY, DESCRIPTION, METHOD, REQUIRES, WITH, AS; terminal TYPE; terminal IDENT, STRINGCONST; -non terminal policy, intface, methlist, meth, paramlist, param; -non terminal capablist, capab, capabcont, cont; -non terminal reqlist, require, capintlist; +non terminal ParseNode policy, 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: @@ -53,48 +56,174 @@ non terminal reqlist, require, capintlist; * 2) List of capabilities and their contents * 3) List of interface generation definitions */ -policy ::= intface:in capablist:cap reqlist:rl +policy ::= + intface:in capablist:cap reqlist:rl + {: + ParseNode pn = new ParseNode("policy"); + pn.addChild(in); + pn.addChild(cap); + pn.addChild(rl); + RESULT = pn; + :} ; // Interface class definition intface ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml END + {: + ParseNode pn = new ParseNode("interface"); + pn.addChild("intface_ident").setLiteral(idint); + pn.addChild(ml); + RESULT = pn; + :} | /* empty */ + {: + ParseNode pn = new ParseNode("interface"); + RESULT = pn; + :} ; methlist ::= methlist:ml meth:m + {: + ml.addChild(m); + RESULT = ml; + :} | /* empty */ + {: + ParseNode pn = new ParseNode("method_list"); + RESULT = pn; + :} ; meth ::= PUBLIC TYPE:typemeth IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON + {: + ParseNode pn = new ParseNode("method"); + pn.addChild("method_type").setLiteral(typemeth); + pn.addChild("method_ident").setLiteral(idmeth); + pn.addChild(pl); + RESULT = pn; + :} ; paramlist ::= paramlist:pl param:p + {: + pl.addChild(p); + RESULT = pl; + :} | /* empty */ + {: + ParseNode pn = new ParseNode("param_list"); + RESULT = pn; + :} ; param ::= TYPE:typeprm IDENT:idprm COMMA + {: + ParseNode pn = new ParseNode("param"); + pn.addChild("param_type").setLiteral(typeprm); + pn.addChild("param_ident").setLiteral(idprm); + RESULT = pn; + :} | TYPE:typeprm IDENT:idprm + {: + ParseNode pn = new ParseNode("param"); + pn.addChild("param_type").setLiteral(typeprm); + pn.addChild("param_ident").setLiteral(idprm); + RESULT = pn; + :} | IDENT:clsprm IDENT:idprm COMMA + {: + ParseNode pn = new ParseNode("param"); + pn.addChild("param_class").setLiteral(clsprm); + pn.addChild("param_ident").setLiteral(idprm); + RESULT = pn; + :} | IDENT:clsprm IDENT:idprm + {: + ParseNode pn = new ParseNode("param"); + pn.addChild("param_class").setLiteral(clsprm); + pn.addChild("param_ident").setLiteral(idprm); + RESULT = pn; + :} ; // List of capabilities and their respective contents, i.e. description, method, etc. capablist ::= capablist:clist capab:cap + {: + clist.addChild(cap); + RESULT = clist; + :} | /* empty */ + {: + ParseNode pn = new ParseNode("capab_list"); + RESULT = pn; + :} ; capab ::= CAPABILITY IDENT:idint DOT 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; + :} ; capabcont ::= capabcont:ccont cont:cnt + {: + ccont.addChild(cnt); + RESULT = ccont; + :} | /* empty */ + {: + ParseNode pn = new ParseNode("capab_content"); + RESULT = pn; + :} ; -cont ::= DESCRIPTION:dsc ASSIGN STRINGCONST SEMICOLON +cont ::= DESCRIPTION:dsc ASSIGN STRINGCONST:str SEMICOLON + {: + ParseNode pn = new ParseNode("capab_content"); + pn.addChild("capab_desc").setLiteral(str); + RESULT = pn; + :} | METHOD:mtd ASSIGN IDENT:idmeth SEMICOLON + {: + ParseNode pn = new ParseNode("capab_content"); + pn.addChild("capab_ident").setLiteral(idmeth); + RESULT = pn; + :} ; // List of interface generation definitions reqlist ::= reqlist:rl require:req + {: + rl.addChild(req); + RESULT = rl; + :} | /* empty */ + {: + ParseNode pn = new ParseNode("requires_list"); + RESULT = pn; + :} ; require ::= REQUIRES IDENT:idint WITH capintlist:cil AS INTERFACE IDENT:idnewint SEMICOLON + {: + ParseNode pn = new ParseNode("requires"); + pn.addChild("intface_ident").setLiteral(idint); + pn.addChild(cil); + pn.addChild("new_intface_ident").setLiteral(idnewint); + RESULT = pn; + :} ; capintlist ::= IDENT:idcap + {: + ParseNode pn = new ParseNode("capab_ident_list"); + pn.addChild("capab_ident").setLiteral(idcap); + RESULT = pn; + :} | capintlist:cil COMMA IDENT:idcap + {: + cil.addChild("capab_ident").setLiteral(idcap); + RESULT = cil; + :} | /* empty */ + {: + ParseNode pn = new ParseNode("capab_ident_list"); + RESULT = pn; + :} ; diff --git a/others/jflex/iotparser.jflex b/others/jflex/iotparser.jflex index bad298e..f16ef69 100644 --- a/others/jflex/iotparser.jflex +++ b/others/jflex/iotparser.jflex @@ -64,16 +64,17 @@ white_space = {new_line} | [ \t\f] { /* keywords */ -"int" { return symbol("int",TYPE, "INT" ); } -"short" { return symbol("short",TYPE, "SHORT" ); } -"byte" { return symbol("byte",TYPE, "BYTE" ); } -"long" { return symbol("long",TYPE, "LONG" ); } -"float" { return symbol("float",TYPE, "FLOAT" ); } -"double" { return symbol("double",TYPE, "DOUBLE" ); } -"char" { return symbol("char",TYPE, "CHAR" ); } -"string" { return symbol("string",TYPE, "STRING" ); } -"boolean" { return symbol("boolean",TYPE, "BOOL" ); } -"void" { return symbol("void",TYPE, "VOID" ); } +"int" { return symbol("int",TYPE, "int" ); } +"short" { return symbol("short",TYPE, "short" ); } +"byte" { return symbol("byte",TYPE, "byte" ); } +"long" { return symbol("long",TYPE, "long" ); } +"float" { return symbol("float",TYPE, "float" ); } +"double" { return symbol("double",TYPE, "double" ); } +"char" { return symbol("char",TYPE, "char" ); } +"string" { return symbol("string",TYPE, "String" ); } +"String" { return symbol("String",TYPE, "String" ); } +"boolean" { return symbol("boolean",TYPE, "boolean" ); } +"void" { return symbol("void",TYPE, "void" ); } "public" { return symbol("public",PUBLIC); } "interface" { return symbol("interface",INTERFACE); } "capability" { return symbol("capability",CAPABILITY); } -- 2.34.1