Perfecting 4th benchmark; adding needed MySQL config files; maturing Zigbee drivers
[iot2.git] / others / javacup / iotparser.cup
index ff3b02f55df41fd490d6f3813b4554e3fe6c052d..8106d34e0152278796bfc405206c79efe297beea 100644 (file)
@@ -24,15 +24,18 @@ parser code {:
   }
 :};
 
-terminal SEMICOLON, COMMA, LPAR, RPAR, BEGIN, END, ASSIGN;
-terminal PUBLIC, INTERFACE, CAPABILITY, DESCRIPTION, METHOD, REQUIRES, WITH, AS; 
+terminal SEMICOLON, COMMA, LPAR, RPAR, LANG, RANG, BEGIN, END, ASSIGN;
+terminal PUBLIC, INTERFACE, CAPABILITY, DESCRIPTION, METHOD, REQUIRES, WITH, AS, ENUM, STRUCT
 terminal TYPE;
 terminal IDENT, STRINGCONST;
 
 non terminal ParseNode policy;
-non terminal ParseNode intface, methlist, meth, paramlist, param;
+non terminal ParseNode intface, methlist, meth, paramlist, param, paramtype;
 non terminal ParseNode capablist, capab, capabcont, cont;
 non terminal ParseNode reqlist, require, capintlist;
+non terminal ParseNode enumdeclist, enumdec, enumlist, enummem;
+non terminal ParseNode structdeclist, structdec, structlist, structmem;
+
 
 /**
  * A policy file normally consists of:
@@ -44,6 +47,11 @@ non terminal ParseNode reqlist, require, capintlist;
  * to declare their required capabilities in the
  * generated interfaces
  * 2) List of generated interfaces (requires)
+ *
+ * Additionally we support declarations for these
+ * data types:
+ * 3) Enumeration
+ * 4) Struct
  */
 policy     ::= intface:in
        {:
@@ -65,12 +73,14 @@ policy     ::= intface:in
 // 3) Driver list
 
 // Interface
-intface    ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml capablist:cl END
+intface    ::= PUBLIC INTERFACE IDENT:idint BEGIN methlist:ml capablist:cl enumdeclist:el structdeclist:sl END
        {:
                ParseNode pn = new ParseNode("interface");
                pn.addChild("intface_ident").setLiteral(idint);
                pn.addChild(ml);
                pn.addChild(cl);
+               pn.addChild(el);
+               pn.addChild(sl);
                RESULT = pn;
        :}
     ;
@@ -101,6 +111,23 @@ meth       ::= PUBLIC TYPE:typemeth IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLO
                pn.addChild(pl);
                RESULT = pn;
        :}
+       /* generic/template return value with one type, e.g. set<int> */
+    | PUBLIC IDENT:clsmeth LANG TYPE:typegen RANG IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
+       {:
+               ParseNode pn = new ParseNode("method");
+               pn.addChild("method_class").setLiteral((String)clsmeth + "<" + typegen + ">");
+               pn.addChild("method_ident").setLiteral(idmeth);
+               pn.addChild(pl);
+               RESULT = pn;
+       :}
+    | PUBLIC IDENT:clsmeth LANG IDENT:clsgen RANG IDENT:idmeth LPAR paramlist:pl RPAR SEMICOLON
+       {:
+               ParseNode pn = new ParseNode("method");
+               pn.addChild("method_class").setLiteral((String)clsmeth + "<" + clsgen + ">");
+               pn.addChild("method_ident").setLiteral(idmeth);
+               pn.addChild(pl);
+               RESULT = pn;
+       :}
     ;
 paramlist  ::= paramlist:pl param:p
        {:
@@ -141,6 +168,37 @@ param      ::= TYPE:typeprm IDENT:idprm COMMA
                pn.addChild("param_ident").setLiteral(idprm);
                RESULT = pn;
        :}
+       /* generic/template with one type, e.g. set<int> */
+    | IDENT:clsprm LANG TYPE:typegen RANG IDENT:idprm
+       {:
+               ParseNode pn = new ParseNode("param");
+               pn.addChild("param_class").setLiteral((String)clsprm + "<" + typegen + ">");
+               pn.addChild("param_ident").setLiteral(idprm);
+               RESULT = pn;
+       :}
+    | IDENT:clsprm LANG IDENT:clsgen RANG IDENT:idprm
+       {:
+               ParseNode pn = new ParseNode("param");
+               pn.addChild("param_class").setLiteral((String)clsprm + "<" + clsgen + ">");
+               pn.addChild("param_ident").setLiteral(idprm);
+               RESULT = pn;
+       :}
+       /* Add comma at the end... */
+       /* generic/template with one type, e.g. set<int> */
+    | IDENT:clsprm LANG TYPE:typegen RANG IDENT:idprm COMMA
+       {:
+               ParseNode pn = new ParseNode("param");
+               pn.addChild("param_class").setLiteral((String)clsprm + "<" + typegen + ">");
+               pn.addChild("param_ident").setLiteral(idprm);
+               RESULT = pn;
+       :}
+    | IDENT:clsprm LANG IDENT:clsgen RANG IDENT:idprm COMMA
+       {:
+               ParseNode pn = new ParseNode("param");
+               pn.addChild("param_class").setLiteral((String)clsprm + "<" + clsgen + ">");
+               pn.addChild("param_ident").setLiteral(idprm);
+               RESULT = pn;
+       :}
     ;
 
 //2) List of capabilities and their respective contents, i.e. description, method, etc.
@@ -227,3 +285,101 @@ capintlist ::= IDENT:idcap
        :}
        ;
 
+//4) Enumeration declaration list
+enumdeclist  ::= enumdeclist:el enumdec:ed
+       {:
+               el.addChild(ed);
+               RESULT = el;
+       :}
+       | /* empty */
+       {:
+               ParseNode pn = new ParseNode("enum_dec_list");
+               RESULT = pn;
+       :}
+       ;
+enumdec                ::= ENUM IDENT:idenumdec BEGIN enumlist:el END
+       {:
+               ParseNode pn = new ParseNode("enum_dec");
+               pn.addChild("enum_dec_ident").setLiteral(idenumdec);
+               pn.addChild(el);
+               RESULT = pn;
+       :}
+       ;
+enumlist       ::= enumlist:el enummem:e
+       {:
+               el.addChild(e);
+               RESULT = el;
+       :}
+    | /* empty */
+       {:
+               ParseNode pn = new ParseNode("enum_list");
+               RESULT = pn;
+       :}
+    ;
+enummem                ::= IDENT:idenum COMMA
+       {:
+               ParseNode pn = new ParseNode("enum_mem");
+               pn.addChild("enum_ident").setLiteral(idenum);
+               RESULT = pn;
+       :}
+    | IDENT:idenum
+       {:
+               ParseNode pn = new ParseNode("enum_mem");
+               pn.addChild("enum_ident").setLiteral(idenum);
+               RESULT = pn;
+       :}
+    ;
+
+//5) Struct declaration list
+structdeclist  ::= structdeclist:sl structdec:sd
+       {:
+               sl.addChild(sd);
+               RESULT = sl;
+       :}
+       | /* empty */
+       {:
+               ParseNode pn = new ParseNode("struct_dec_list");
+               RESULT = pn;
+       :}
+       ;
+structdec      ::= STRUCT IDENT:idstructdec BEGIN structlist:sl END
+       {:
+               ParseNode pn = new ParseNode("struct_dec");
+               pn.addChild("struct_dec_ident").setLiteral(idstructdec);
+               pn.addChild(sl);
+               RESULT = pn;
+       :}
+    ;
+structlist     ::= structlist:sl structmem:s
+       {:
+               sl.addChild(s);
+               RESULT = sl;
+       :}
+    | /* empty */
+       {:
+               ParseNode pn = new ParseNode("struct_list");
+               RESULT = pn;
+       :}
+    ;
+structmem      ::= TYPE:typestr IDENT:idstr SEMICOLON
+       {:
+               ParseNode pn = new ParseNode("struct_mem");
+               pn.addChild("struct_type").setLiteral(typestr);
+               pn.addChild("struct_ident").setLiteral(idstr);
+               RESULT = pn;
+       :}
+    | IDENT:clsstr IDENT:idstr SEMICOLON
+       {:
+               ParseNode pn = new ParseNode("struct_mem");
+               pn.addChild("struct_class").setLiteral(clsstr);
+               pn.addChild("struct_ident").setLiteral(idstr);
+               RESULT = pn;
+       :}
+    | IDENT:clsstr LANG IDENT:clsgen RANG IDENT:idstr SEMICOLON
+       {:
+               ParseNode pn = new ParseNode("struct_mem");
+               pn.addChild("struct_class").setLiteral((String)clsstr + "<" + clsgen + ">");
+               pn.addChild("struct_ident").setLiteral(idstr);
+               RESULT = pn;
+       :}
+    ;