From 70b9ba407ee743364838b7e5dc01a910e624e268 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Fri, 11 Nov 2016 14:07:50 -0800 Subject: [PATCH] Moving struct and enum declaration into interface declaration --- config/iotpolicy/camerapolicy.pol | 7 + config/iotpolicy/lightbulbpolicy.pol | 7 + config/iotpolicy/struct.pol | 2 +- iotjava/iotpolicy/parser/Parser.java | 437 ++++++++++--------- iotjava/iotpolicy/tree/EnumDecl.java | 88 ++++ iotjava/iotpolicy/tree/ParseTreeHandler.java | 28 +- iotjava/iotpolicy/tree/StructDecl.java | 107 +++++ others/javacup/iotparser.cup | 50 ++- 8 files changed, 508 insertions(+), 218 deletions(-) create mode 100644 iotjava/iotpolicy/tree/EnumDecl.java create mode 100644 iotjava/iotpolicy/tree/StructDecl.java diff --git a/config/iotpolicy/camerapolicy.pol b/config/iotpolicy/camerapolicy.pol index ac64430..0afb5a0 100644 --- a/config/iotpolicy/camerapolicy.pol +++ b/config/iotpolicy/camerapolicy.pol @@ -26,6 +26,13 @@ public interface Camera { description = "The quick brown fox jumps over the clever dog"; method = "MethodE(String I, boolean J)"; } + + struct Struct { + + string name; + float value; + int year; + } } diff --git a/config/iotpolicy/lightbulbpolicy.pol b/config/iotpolicy/lightbulbpolicy.pol index 3d0ea74..3d131b6 100644 --- a/config/iotpolicy/lightbulbpolicy.pol +++ b/config/iotpolicy/lightbulbpolicy.pol @@ -19,6 +19,13 @@ public interface LightBulb { method = "MethodA(int A, float B, int AB)"; method = "MethodC(String E, List F)"; } + + enum Enum { + + APPLE, + ORANGE, + GRAPE + } } diff --git a/config/iotpolicy/struct.pol b/config/iotpolicy/struct.pol index c4f80ec..9b38ad1 100644 --- a/config/iotpolicy/struct.pol +++ b/config/iotpolicy/struct.pol @@ -3,5 +3,5 @@ struct Struct { string name; float value; - int year; + int year; } diff --git a/iotjava/iotpolicy/parser/Parser.java b/iotjava/iotpolicy/parser/Parser.java index 7d6086c..62b750d 100644 --- a/iotjava/iotpolicy/parser/Parser.java +++ b/iotjava/iotpolicy/parser/Parser.java @@ -39,21 +39,21 @@ public class Parser extends java_cup.runtime.lr_parser { /** Production table. */ protected static final short _production_table[][] = unpackFromStrings(new String[] { - "\000\056\000\002\002\003\000\002\002\004\000\002\002" + - "\003\000\002\002\003\000\002\002\003\000\002\003\011" + - "\000\002\004\004\000\002\004\002\000\002\005\011\000" + - "\002\005\011\000\002\005\014\000\002\005\014\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\007\007" + - "\000\002\007\007\000\002\007\010\000\002\007\010\000" + - "\002\011\004\000\002\011\002\000\002\012\007\000\002" + - "\013\004\000\002\013\002\000\002\014\006\000\002\014" + - "\006\000\002\015\004\000\002\015\002\000\002\016\012" + - "\000\002\017\003\000\002\017\005\000\002\017\002\000" + - "\002\020\007\000\002\021\004\000\002\021\002\000\002" + - "\022\004\000\002\022\003\000\002\023\007\000\002\024" + - "\004\000\002\024\002\000\002\025\005\000\002\025\005" + - "\000\002\025\010" }); + "\000\060\000\002\002\003\000\002\002\004\000\002\002" + + "\003\000\002\003\013\000\002\004\004\000\002\004\002" + + "\000\002\005\011\000\002\005\011\000\002\005\014\000" + + "\002\005\014\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\007\007\000\002\007\007\000\002\007\010" + + "\000\002\007\010\000\002\011\004\000\002\011\002\000" + + "\002\012\007\000\002\013\004\000\002\013\002\000\002" + + "\014\006\000\002\014\006\000\002\015\004\000\002\015" + + "\002\000\002\016\012\000\002\017\003\000\002\017\005" + + "\000\002\017\002\000\002\020\004\000\002\020\002\000" + + "\002\021\007\000\002\022\004\000\002\022\002\000\002" + + "\023\004\000\002\023\003\000\002\024\004\000\002\024" + + "\002\000\002\025\007\000\002\026\004\000\002\026\002" + + "\000\002\027\005\000\002\027\005\000\002\027\010" }); /** Access to production table. */ public short[][] production_table() {return _production_table;} @@ -61,73 +61,79 @@ public class Parser extends java_cup.runtime.lr_parser { /** Parse-action table. */ protected static final short[][] _action_table = unpackFromStrings(new String[] { - "\000\157\000\014\002\uffe3\015\012\022\uffe3\025\007\026" + - "\011\001\002\000\004\002\001\001\002\000\004\002\ufffd" + - "\001\002\000\004\002\ufffe\001\002\000\004\030\153\001" + - "\002\000\006\002\uffff\022\137\001\002\000\004\030\117" + - "\001\002\000\004\016\015\001\002\000\004\002\014\001" + - "\002\000\004\002\000\001\002\000\004\030\016\001\002" + - "\000\004\012\017\001\002\000\010\013\ufffa\015\ufffa\017" + - "\ufffa\001\002\000\010\013\uffea\015\022\017\uffea\001\002" + - "\000\010\013\ufffb\015\ufffb\017\ufffb\001\002\000\006\027" + - "\045\030\044\001\002\000\006\013\026\017\025\001\002" + - "\000\006\013\uffeb\017\uffeb\001\002\000\004\030\027\001" + - "\002\000\004\002\ufffc\001\002\000\004\012\030\001\002" + - "\000\010\013\uffe7\020\uffe7\021\uffe7\001\002\000\010\013" + - "\034\020\033\021\035\001\002\000\010\013\uffe8\020\uffe8" + - "\021\uffe8\001\002\000\004\014\041\001\002\000\006\013" + - "\uffe9\017\uffe9\001\002\000\004\014\036\001\002\000\004" + - "\031\037\001\002\000\004\004\040\001\002\000\010\013" + - "\uffe5\020\uffe5\021\uffe5\001\002\000\004\031\042\001\002" + - "\000\004\004\043\001\002\000\010\013\uffe6\020\uffe6\021" + - "\uffe6\001\002\000\006\010\073\030\074\001\002\000\004" + - "\030\046\001\002\000\004\006\047\001\002\000\010\007" + - "\ufff4\027\ufff4\030\ufff4\001\002\000\010\007\052\027\054" + - "\030\051\001\002\000\006\010\060\030\061\001\002\000" + - "\004\004\057\001\002\000\010\007\ufff5\027\ufff5\030\ufff5" + - "\001\002\000\004\030\055\001\002\000\012\005\056\007" + - "\ufff2\027\ufff2\030\ufff2\001\002\000\010\007\ufff3\027\ufff3" + - "\030\ufff3\001\002\000\010\013\ufff9\015\ufff9\017\ufff9\001" + - "\002\000\006\027\064\030\063\001\002\000\012\005\062" + - "\007\ufff0\027\ufff0\030\ufff0\001\002\000\010\007\ufff1\027" + - "\ufff1\030\ufff1\001\002\000\004\011\070\001\002\000\004" + - "\011\065\001\002\000\004\030\066\001\002\000\012\005" + - "\067\007\uffef\027\uffef\030\uffef\001\002\000\010\007\uffed" + - "\027\uffed\030\uffed\001\002\000\004\030\071\001\002\000" + - "\012\005\072\007\uffee\027\uffee\030\uffee\001\002\000\010" + - "\007\uffec\027\uffec\030\uffec\001\002\000\006\027\102\030" + - "\101\001\002\000\004\006\075\001\002\000\010\007\ufff4" + - "\027\ufff4\030\ufff4\001\002\000\010\007\077\027\054\030" + - "\051\001\002\000\004\004\100\001\002\000\010\013\ufff8" + - "\015\ufff8\017\ufff8\001\002\000\004\011\111\001\002\000" + - "\004\011\103\001\002\000\004\030\104\001\002\000\004" + - "\006\105\001\002\000\010\007\ufff4\027\ufff4\030\ufff4\001" + - "\002\000\010\007\107\027\054\030\051\001\002\000\004" + - "\004\110\001\002\000\010\013\ufff7\015\ufff7\017\ufff7\001" + - "\002\000\004\030\112\001\002\000\004\006\113\001\002" + - "\000\010\007\ufff4\027\ufff4\030\ufff4\001\002\000\010\007" + - "\115\027\054\030\051\001\002\000\004\004\116\001\002" + - "\000\010\013\ufff6\015\ufff6\017\ufff6\001\002\000\004\012" + - "\120\001\002\000\010\013\uffd7\027\uffd7\030\uffd7\001\002" + - "\000\010\013\123\027\125\030\122\001\002\000\006\010" + - "\130\030\131\001\002\000\004\002\uffd9\001\002\000\010" + - "\013\uffd8\027\uffd8\030\uffd8\001\002\000\004\030\126\001" + - "\002\000\004\004\127\001\002\000\010\013\uffd6\027\uffd6" + - "\030\uffd6\001\002\000\004\030\133\001\002\000\004\004" + - "\132\001\002\000\010\013\uffd5\027\uffd5\030\uffd5\001\002" + - "\000\004\011\134\001\002\000\004\030\135\001\002\000" + - "\004\004\136\001\002\000\010\013\uffd4\027\uffd4\030\uffd4" + - "\001\002\000\004\030\141\001\002\000\006\002\uffe4\022" + - "\uffe4\001\002\000\004\023\142\001\002\000\010\005\uffdf" + - "\024\uffdf\030\144\001\002\000\006\005\145\024\146\001" + - "\002\000\006\005\uffe1\024\uffe1\001\002\000\004\030\152" + - "\001\002\000\004\016\147\001\002\000\004\030\150\001" + - "\002\000\004\004\151\001\002\000\006\002\uffe2\022\uffe2" + - "\001\002\000\006\005\uffe0\024\uffe0\001\002\000\004\012" + - "\154\001\002\000\006\013\uffdc\030\uffdc\001\002\000\006" + - "\013\160\030\157\001\002\000\006\013\uffdd\030\uffdd\001" + - "\002\000\010\005\161\013\uffda\030\uffda\001\002\000\004" + - "\002\uffde\001\002\000\006\013\uffdb\030\uffdb\001\002" }); + "\000\161\000\010\002\uffe5\015\006\022\uffe5\001\002\000" + + "\004\002\001\001\002\000\006\002\uffff\022\150\001\002" + + "\000\004\016\011\001\002\000\004\002\010\001\002\000" + + "\004\002\000\001\002\000\004\030\012\001\002\000\004" + + "\012\013\001\002\000\014\013\ufffc\015\ufffc\017\ufffc\025" + + "\ufffc\026\ufffc\001\002\000\014\013\uffec\015\016\017\uffec" + + "\025\uffec\026\uffec\001\002\000\014\013\ufffd\015\ufffd\017" + + "\ufffd\025\ufffd\026\ufffd\001\002\000\006\027\076\030\075" + + "\001\002\000\012\013\uffdf\017\022\025\uffdf\026\uffdf\001" + + "\002\000\010\013\uffd8\025\042\026\uffd8\001\002\000\012" + + "\013\uffed\017\uffed\025\uffed\026\uffed\001\002\000\004\030" + + "\023\001\002\000\004\012\024\001\002\000\010\013\uffe9" + + "\020\uffe9\021\uffe9\001\002\000\010\013\030\020\027\021" + + "\031\001\002\000\010\013\uffea\020\uffea\021\uffea\001\002" + + "\000\004\014\035\001\002\000\012\013\uffeb\017\uffeb\025" + + "\uffeb\026\uffeb\001\002\000\004\014\032\001\002\000\004" + + "\031\033\001\002\000\004\004\034\001\002\000\010\013" + + "\uffe7\020\uffe7\021\uffe7\001\002\000\004\031\036\001\002" + + "\000\004\004\037\001\002\000\010\013\uffe8\020\uffe8\021" + + "\uffe8\001\002\000\006\013\054\026\053\001\002\000\010" + + "\013\uffe0\025\uffe0\026\uffe0\001\002\000\004\030\043\001" + + "\002\000\004\012\044\001\002\000\006\013\uffdc\030\uffdc" + + "\001\002\000\006\013\050\030\047\001\002\000\006\013" + + "\uffdd\030\uffdd\001\002\000\010\005\051\013\uffda\030\uffda" + + "\001\002\000\010\013\uffde\025\uffde\026\uffde\001\002\000" + + "\006\013\uffdb\030\uffdb\001\002\000\006\013\uffd9\026\uffd9" + + "\001\002\000\004\030\055\001\002\000\004\002\ufffe\001" + + "\002\000\004\012\056\001\002\000\010\013\uffd5\027\uffd5" + + "\030\uffd5\001\002\000\010\013\061\027\062\030\060\001" + + "\002\000\006\010\066\030\067\001\002\000\006\013\uffd7" + + "\026\uffd7\001\002\000\004\030\064\001\002\000\010\013" + + "\uffd6\027\uffd6\030\uffd6\001\002\000\004\004\065\001\002" + + "\000\010\013\uffd4\027\uffd4\030\uffd4\001\002\000\004\030" + + "\071\001\002\000\004\004\070\001\002\000\010\013\uffd3" + + "\027\uffd3\030\uffd3\001\002\000\004\011\072\001\002\000" + + "\004\030\073\001\002\000\004\004\074\001\002\000\010" + + "\013\uffd2\027\uffd2\030\uffd2\001\002\000\006\010\124\030" + + "\125\001\002\000\004\030\077\001\002\000\004\006\100" + + "\001\002\000\010\007\ufff6\027\ufff6\030\ufff6\001\002\000" + + "\010\007\103\027\105\030\102\001\002\000\006\010\111" + + "\030\112\001\002\000\004\004\110\001\002\000\010\007" + + "\ufff7\027\ufff7\030\ufff7\001\002\000\004\030\106\001\002" + + "\000\012\005\107\007\ufff4\027\ufff4\030\ufff4\001\002\000" + + "\010\007\ufff5\027\ufff5\030\ufff5\001\002\000\014\013\ufffb" + + "\015\ufffb\017\ufffb\025\ufffb\026\ufffb\001\002\000\006\027" + + "\115\030\114\001\002\000\012\005\113\007\ufff2\027\ufff2" + + "\030\ufff2\001\002\000\010\007\ufff3\027\ufff3\030\ufff3\001" + + "\002\000\004\011\121\001\002\000\004\011\116\001\002" + + "\000\004\030\117\001\002\000\012\005\120\007\ufff1\027" + + "\ufff1\030\ufff1\001\002\000\010\007\uffef\027\uffef\030\uffef" + + "\001\002\000\004\030\122\001\002\000\012\005\123\007" + + "\ufff0\027\ufff0\030\ufff0\001\002\000\010\007\uffee\027\uffee" + + "\030\uffee\001\002\000\006\027\133\030\132\001\002\000" + + "\004\006\126\001\002\000\010\007\ufff6\027\ufff6\030\ufff6" + + "\001\002\000\010\007\130\027\105\030\102\001\002\000" + + "\004\004\131\001\002\000\014\013\ufffa\015\ufffa\017\ufffa" + + "\025\ufffa\026\ufffa\001\002\000\004\011\142\001\002\000" + + "\004\011\134\001\002\000\004\030\135\001\002\000\004" + + "\006\136\001\002\000\010\007\ufff6\027\ufff6\030\ufff6\001" + + "\002\000\010\007\140\027\105\030\102\001\002\000\004" + + "\004\141\001\002\000\014\013\ufff9\015\ufff9\017\ufff9\025" + + "\ufff9\026\ufff9\001\002\000\004\030\143\001\002\000\004" + + "\006\144\001\002\000\010\007\ufff6\027\ufff6\030\ufff6\001" + + "\002\000\010\007\146\027\105\030\102\001\002\000\004" + + "\004\147\001\002\000\014\013\ufff8\015\ufff8\017\ufff8\025" + + "\ufff8\026\ufff8\001\002\000\004\030\152\001\002\000\006" + + "\002\uffe6\022\uffe6\001\002\000\004\023\153\001\002\000" + + "\010\005\uffe1\024\uffe1\030\155\001\002\000\006\005\156" + + "\024\157\001\002\000\006\005\uffe3\024\uffe3\001\002\000" + + "\004\030\163\001\002\000\004\016\160\001\002\000\004" + + "\030\161\001\002\000\004\004\162\001\002\000\006\002" + + "\uffe4\022\uffe4\001\002\000\006\005\uffe2\024\uffe2\001\002" + + "" }); /** Access to parse-action table. */ public short[][] action_table() {return _action_table;} @@ -135,45 +141,46 @@ public class Parser extends java_cup.runtime.lr_parser { /** reduce_goto table. */ protected static final short[][] _reduce_table = unpackFromStrings(new String[] { - "\000\157\000\014\002\012\003\003\015\007\020\005\023" + - "\004\001\001\000\002\001\001\000\002\001\001\000\002" + - "\001\001\000\002\001\001\000\004\016\137\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\004" + - "\017\001\001\000\006\005\020\011\022\001\001\000\002" + - "\001\001\000\002\001\001\000\004\012\023\001\001\000" + - "\002\001\001\000\002\001\001\000\002\001\001\000\002" + - "\001\001\000\004\013\030\001\001\000\004\014\031\001" + - "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\161\000\010\002\006\003\003\015\004\001\001\000" + + "\002\001\001\000\004\016\150\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" + + "\002\001\001\000\004\004\013\001\001\000\006\005\014" + + "\011\016\001\001\000\002\001\001\000\002\001\001\000" + + "\006\012\020\020\017\001\001\000\006\021\040\024\037" + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + - "\001\000\004\006\047\001\001\000\004\007\052\001\001" + + "\001\000\004\013\024\001\001\000\004\014\025\001\001" + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + - "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\001\000\004\025\051\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\004\022\044\001\001\000" + + "\004\023\045\001\001\000\002\001\001\000\002\001\001" + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + - "\002\001\001\000\002\001\001\000\002\001\001\000\002" + - "\001\001\000\004\006\075\001\001\000\004\007\052\001" + + "\002\001\001\000\002\001\001\000\002\001\001\000\004" + + "\026\056\001\001\000\004\027\062\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\006\105\001\001\000\004\007\052\001\001\000\002" + + "\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\006\113\001\001\000\004\007\052\001\001" + - "\000\002\001\001\000\002\001\001\000\002\001\001\000" + - "\004\024\120\001\001\000\004\025\123\001\001\000\002" + + "\001\000\002\001\001\000\002\001\001\000\004\006\100" + + "\001\001\000\004\007\103\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\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\017" + - "\142\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\021\154\001\001\000\004\022\155\001\001\000" + + "\001\001\000\002\001\001\000\002\001\001\000\004\006" + + "\126\001\001\000\004\007\103\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\006\136\001\001" + + "\000\004\007\103\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\004\006\144" + + "\001\001\000\004\007\103\001\001\000\002\001\001\000" + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + - "\001\001" }); + "\001\001\000\004\017\153\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;} @@ -297,63 +304,39 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 3: // policy ::= enumdec + case 3: // intface ::= PUBLIC INTERFACE IDENT BEGIN methlist capablist enumdeclist structdeclist END { ParseNode RESULT =null; - int enleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; - int enright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; - ParseNode en = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - ParseNode pn = new ParseNode("policy"); - pn.addChild(en); - RESULT = pn; - - CUP$Parser$result = parser.getSymbolFactory().newSymbol("policy",0, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 4: // policy ::= structdec - { - ParseNode RESULT =null; - int stleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; - int stright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; - ParseNode st = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; - - ParseNode pn = new ParseNode("policy"); - pn.addChild(st); - RESULT = pn; - - CUP$Parser$result = parser.getSymbolFactory().newSymbol("policy",0, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); - } - return CUP$Parser$result; - - /*. . . . . . . . . . . . . . . . . . . .*/ - case 5: // intface ::= PUBLIC INTERFACE IDENT BEGIN methlist capablist END - { - ParseNode RESULT =null; - int idintleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).left; - int idintright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).right; - Object idint = (Object)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value; - int mlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; - int mlright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).right; - ParseNode ml = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; - int clleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; - int clright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; - ParseNode cl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + 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 mlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).left; + int mlright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).right; + ParseNode ml = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-4)).value; + int clleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left; + int clright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).right; + ParseNode cl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-3)).value; + int elleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; + int elright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).right; + ParseNode el = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-2)).value; + int slleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int slright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + ParseNode sl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; ParseNode pn = new ParseNode("interface"); pn.addChild("intface_ident").setLiteral(idint); pn.addChild(ml); pn.addChild(cl); + pn.addChild(el); + pn.addChild(sl); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("intface",1, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-6)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("intface",1, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-8)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); } return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 6: // methlist ::= methlist meth + case 4: // methlist ::= methlist meth { ParseNode RESULT =null; int mlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; @@ -371,7 +354,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 7: // methlist ::= + case 5: // methlist ::= { ParseNode RESULT =null; @@ -383,7 +366,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 8: // meth ::= PUBLIC TYPE IDENT LPAR paramlist RPAR SEMICOLON + 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; @@ -407,7 +390,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 9: // meth ::= PUBLIC IDENT IDENT LPAR paramlist RPAR SEMICOLON + case 7: // meth ::= PUBLIC IDENT IDENT LPAR paramlist RPAR SEMICOLON { ParseNode RESULT =null; int clsmethleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).left; @@ -431,7 +414,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 10: // meth ::= PUBLIC IDENT LANG TYPE RANG IDENT LPAR paramlist RPAR SEMICOLON + case 8: // meth ::= PUBLIC IDENT LANG TYPE RANG IDENT LPAR paramlist RPAR SEMICOLON { ParseNode RESULT =null; int clsmethleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-8)).left; @@ -458,7 +441,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 11: // meth ::= PUBLIC IDENT LANG IDENT RANG IDENT LPAR paramlist RPAR SEMICOLON + case 9: // meth ::= PUBLIC IDENT LANG IDENT RANG IDENT LPAR paramlist RPAR SEMICOLON { ParseNode RESULT =null; int clsmethleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-8)).left; @@ -485,7 +468,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 12: // paramlist ::= paramlist param + case 10: // paramlist ::= paramlist param { ParseNode RESULT =null; int plleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; @@ -503,7 +486,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 13: // paramlist ::= + case 11: // paramlist ::= { ParseNode RESULT =null; @@ -515,7 +498,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 14: // param ::= TYPE IDENT COMMA + case 12: // param ::= TYPE IDENT COMMA { ParseNode RESULT =null; int typeprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; @@ -535,7 +518,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 15: // param ::= TYPE IDENT + case 13: // param ::= TYPE IDENT { ParseNode RESULT =null; int typeprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; @@ -555,7 +538,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 16: // param ::= IDENT IDENT COMMA + case 14: // param ::= IDENT IDENT COMMA { ParseNode RESULT =null; int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; @@ -575,7 +558,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 17: // param ::= IDENT IDENT + case 15: // param ::= IDENT IDENT { ParseNode RESULT =null; int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; @@ -595,7 +578,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 18: // param ::= IDENT LANG TYPE RANG IDENT + case 16: // param ::= IDENT LANG TYPE RANG IDENT { ParseNode RESULT =null; int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).left; @@ -618,7 +601,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 19: // param ::= IDENT LANG IDENT RANG IDENT + case 17: // param ::= IDENT LANG IDENT RANG IDENT { ParseNode RESULT =null; int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)).left; @@ -641,7 +624,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 20: // param ::= IDENT LANG TYPE RANG IDENT COMMA + case 18: // param ::= IDENT LANG TYPE RANG IDENT COMMA { ParseNode RESULT =null; int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).left; @@ -664,7 +647,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 21: // param ::= IDENT LANG IDENT RANG IDENT COMMA + case 19: // param ::= IDENT LANG IDENT RANG IDENT COMMA { ParseNode RESULT =null; int clsprmleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).left; @@ -687,7 +670,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 22: // capablist ::= capablist capab + case 20: // capablist ::= capablist capab { ParseNode RESULT =null; int clleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; @@ -705,7 +688,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 23: // capablist ::= + case 21: // capablist ::= { ParseNode RESULT =null; @@ -717,7 +700,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 24: // capab ::= CAPABILITY IDENT BEGIN capabcont END + case 22: // capab ::= CAPABILITY IDENT BEGIN capabcont END { ParseNode RESULT =null; int idcapleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left; @@ -737,7 +720,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 25: // capabcont ::= capabcont cont + case 23: // capabcont ::= capabcont cont { ParseNode RESULT =null; int ccontleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; @@ -755,7 +738,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 26: // capabcont ::= + case 24: // capabcont ::= { ParseNode RESULT =null; @@ -767,7 +750,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 27: // cont ::= DESCRIPTION ASSIGN STRINGCONST SEMICOLON + case 25: // cont ::= DESCRIPTION ASSIGN STRINGCONST SEMICOLON { ParseNode RESULT =null; int dscleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left; @@ -786,7 +769,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 28: // cont ::= METHOD ASSIGN STRINGCONST SEMICOLON + case 26: // cont ::= METHOD ASSIGN STRINGCONST SEMICOLON { ParseNode RESULT =null; int mtdleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left; @@ -805,7 +788,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 29: // reqlist ::= reqlist require + case 27: // reqlist ::= reqlist require { ParseNode RESULT =null; int rlleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; @@ -823,7 +806,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 30: // reqlist ::= + case 28: // reqlist ::= { ParseNode RESULT =null; @@ -835,7 +818,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 31: // require ::= REQUIRES IDENT WITH capintlist AS INTERFACE IDENT SEMICOLON + case 29: // 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; @@ -859,7 +842,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 32: // capintlist ::= IDENT + case 30: // capintlist ::= IDENT { ParseNode RESULT =null; int idcapleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; @@ -875,7 +858,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 33: // capintlist ::= capintlist COMMA IDENT + case 31: // capintlist ::= capintlist COMMA IDENT { ParseNode RESULT =null; int cilleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; @@ -893,7 +876,7 @@ class CUP$Parser$actions { return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 34: // capintlist ::= + case 32: // capintlist ::= { ParseNode RESULT =null; @@ -904,6 +887,36 @@ class CUP$Parser$actions { } return CUP$Parser$result; + /*. . . . . . . . . . . . . . . . . . . .*/ + case 33: // enumdeclist ::= enumdeclist enumdec + { + ParseNode RESULT =null; + int elleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int elright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + ParseNode el = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + int edleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int edright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + ParseNode ed = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + el.addChild(ed); + RESULT = el; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("enumdeclist",14, ((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 34: // enumdeclist ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("enum_dec_list"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("enumdeclist",14, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + /*. . . . . . . . . . . . . . . . . . . .*/ case 35: // enumdec ::= ENUM IDENT BEGIN enumlist END { @@ -920,7 +933,7 @@ class CUP$Parser$actions { pn.addChild(el); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("enumdec",14, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("enumdec",15, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); } return CUP$Parser$result; @@ -938,7 +951,7 @@ class CUP$Parser$actions { el.addChild(e); RESULT = el; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("enumlist",15, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("enumlist",16, ((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; @@ -950,7 +963,7 @@ class CUP$Parser$actions { ParseNode pn = new ParseNode("enum_list"); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("enumlist",15, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("enumlist",16, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); } return CUP$Parser$result; @@ -966,7 +979,7 @@ class CUP$Parser$actions { pn.addChild("enum_ident").setLiteral(idenum); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("enummem",16, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("enummem",17, ((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; @@ -982,12 +995,42 @@ class CUP$Parser$actions { pn.addChild("enum_ident").setLiteral(idenum); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("enummem",16, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("enummem",17, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); } return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 40: // structdec ::= STRUCT IDENT BEGIN structlist END + case 40: // structdeclist ::= structdeclist structdec + { + ParseNode RESULT =null; + int slleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; + int slright = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).right; + ParseNode sl = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.elementAt(CUP$Parser$top-1)).value; + int sdleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).left; + int sdright = ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()).right; + ParseNode sd = (ParseNode)((java_cup.runtime.Symbol) CUP$Parser$stack.peek()).value; + + sl.addChild(sd); + RESULT = sl; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("structdeclist",18, ((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 41: // structdeclist ::= + { + ParseNode RESULT =null; + + ParseNode pn = new ParseNode("struct_dec_list"); + RESULT = pn; + + CUP$Parser$result = parser.getSymbolFactory().newSymbol("structdeclist",18, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + } + return CUP$Parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 42: // structdec ::= STRUCT IDENT BEGIN structlist END { ParseNode RESULT =null; int idstructdecleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-3)).left; @@ -1002,12 +1045,12 @@ class CUP$Parser$actions { pn.addChild(sl); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("structdec",17, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("structdec",19, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-4)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); } return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 41: // structlist ::= structlist structmem + case 43: // structlist ::= structlist structmem { ParseNode RESULT =null; int slleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)).left; @@ -1020,24 +1063,24 @@ class CUP$Parser$actions { sl.addChild(s); RESULT = sl; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("structlist",18, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-1)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("structlist",20, ((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 42: // structlist ::= + case 44: // structlist ::= { ParseNode RESULT =null; - ParseNode pn = new ParseNode("enum_list"); + ParseNode pn = new ParseNode("struct_list"); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("structlist",18, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("structlist",20, ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); } return CUP$Parser$result; /*. . . . . . . . . . . . . . . . . . . .*/ - case 43: // structmem ::= TYPE IDENT SEMICOLON + case 45: // structmem ::= TYPE IDENT SEMICOLON { ParseNode RESULT =null; int typestrleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; @@ -1052,12 +1095,12 @@ class CUP$Parser$actions { pn.addChild("struct_ident").setLiteral(idstr); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("structmem",19, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("structmem",21, ((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 44: // structmem ::= IDENT IDENT SEMICOLON + case 46: // structmem ::= IDENT IDENT SEMICOLON { ParseNode RESULT =null; int clsstrleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)).left; @@ -1072,12 +1115,12 @@ class CUP$Parser$actions { pn.addChild("struct_ident").setLiteral(idstr); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("structmem",19, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-2)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("structmem",21, ((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 45: // structmem ::= IDENT LANG IDENT RANG IDENT SEMICOLON + case 47: // structmem ::= IDENT LANG IDENT RANG IDENT SEMICOLON { ParseNode RESULT =null; int clsstrleft = ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)).left; @@ -1095,7 +1138,7 @@ class CUP$Parser$actions { pn.addChild("struct_ident").setLiteral(idstr); RESULT = pn; - CUP$Parser$result = parser.getSymbolFactory().newSymbol("structmem",19, ((java_cup.runtime.Symbol)CUP$Parser$stack.elementAt(CUP$Parser$top-5)), ((java_cup.runtime.Symbol)CUP$Parser$stack.peek()), RESULT); + CUP$Parser$result = parser.getSymbolFactory().newSymbol("structmem",21, ((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; diff --git a/iotjava/iotpolicy/tree/EnumDecl.java b/iotjava/iotpolicy/tree/EnumDecl.java new file mode 100644 index 0000000..96e57ec --- /dev/null +++ b/iotjava/iotpolicy/tree/EnumDecl.java @@ -0,0 +1,88 @@ +package iotpolicy.tree; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +/** Class EnumDecl is a data structure for enumeration + * declaration section in the policy file. + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-11-11 + */ +public class EnumDecl extends Declaration { + + /** + * A "enum" declaration: + * enum Enum { + * + * APPLE, + * ORANGE, + * GRAPE + * } + * In this data structure we will record its enum name, i.e. Enum + * and its members. + */ + + /** + * Class properties + */ + // Members of enum (can be more than 1 declaration + private Map> mapEnumMembers; + + /** + * Class constructors + */ + public EnumDecl() { + + super(); + mapEnumMembers = new HashMap>(); + } + + + public EnumDecl(String _origInt) { + + super(_origInt); + mapEnumMembers = new HashMap>(); + } + + + /** + * addNewMember() adds a new member into the list, e.g. MELON into the list of APPLE, ORANGE, and GRAPE + */ + public void addNewMember(String enumType, String newMember) { + + if (mapEnumMembers.containsKey(enumType)) { + // Existing enum declaration + List memberList = mapEnumMembers.get(enumType); + memberList.add(newMember); + } else { + // New declaration + List newMemberList = new ArrayList(); + newMemberList.add(enumType); + mapEnumMembers.put(enumType, newMemberList); + } + } + + + /** + * getEnumDeclarations() gets list of enum declarations + */ + public Set getEnumDeclarations() { + + return mapEnumMembers.keySet(); + } + + + /** + * getMembers() gets list of enum members + */ + public List getMembers(String enumType) { + + return mapEnumMembers.get(enumType); + } +} diff --git a/iotjava/iotpolicy/tree/ParseTreeHandler.java b/iotjava/iotpolicy/tree/ParseTreeHandler.java index c5d0be7..0d2b1c5 100644 --- a/iotjava/iotpolicy/tree/ParseTreeHandler.java +++ b/iotjava/iotpolicy/tree/ParseTreeHandler.java @@ -13,9 +13,11 @@ import java.util.ArrayList; * parser (and lexer) from the policy file. * This class accepts the AST in the form of ParseNode and * ParseNodeVector class objects. - * It gives interfaces to extract the 2 types of policy file: + * It gives interfaces to extract the 4 types of policy file: * 1) Interface and capabilities definition * 2) Generated interface list ("requires" statements) + * 3) Enum declaration + * 4) Struct declaration * * @author Rahmadi Trimananda * @version 1.0 @@ -31,6 +33,8 @@ public final class ParseTreeHandler { private InterfaceDecl intDecl; private CapabilityDecl capDecl; private RequiresDecl reqDecl; + private EnumDecl enumDecl; + private StructDecl structDecl; /** @@ -43,6 +47,8 @@ public final class ParseTreeHandler { intDecl = new InterfaceDecl(); capDecl = new CapabilityDecl(); reqDecl = new RequiresDecl(); + enumDecl = new EnumDecl(); + structDecl = new StructDecl(); } @@ -53,6 +59,8 @@ public final class ParseTreeHandler { intDecl = new InterfaceDecl(_intFace); capDecl = new CapabilityDecl(_intFace); reqDecl = new RequiresDecl(_intFace); + enumDecl = new EnumDecl(); + structDecl = new StructDecl(); } @@ -223,6 +231,24 @@ public final class ParseTreeHandler { } + /** + * getEnumDecl() returns EnumDecl object + */ + public EnumDecl getEnumDecl() { + + return enumDecl; + } + + + /** + * getStructDecl() returns StructDecl object + */ + public StructDecl getStructDecl() { + + return structDecl; + } + + /** * getOrigIntface() returns the original interface in policy, e.g. Camera *

diff --git a/iotjava/iotpolicy/tree/StructDecl.java b/iotjava/iotpolicy/tree/StructDecl.java new file mode 100644 index 0000000..56a6fe4 --- /dev/null +++ b/iotjava/iotpolicy/tree/StructDecl.java @@ -0,0 +1,107 @@ +package iotpolicy.tree; + +import java.util.ArrayList; +import java.util.List; + + +/** Class StructDecl is a data structure for struct + * declaration section in the policy file. + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-11-11 + */ +public class StructDecl extends Declaration { + + /** + * A "struct" declaration: + * struct Struct { + * + * string name; + * float value; + * int year; + *} + * In this data structure we will record its struct name, i.e. Struct, + * and its member types and members. + */ + + /** + * Class properties + */ + private List listStructs; // Struct types/names (more than one struct) + private List> listMemberTypes; // Member types, e.g. string, float, int, etc. + private List> listMembers; // Member names, e.g. name, value, year, etc. + + /** + * Class constructors + */ + public StructDecl() { + + super(); + listStructs = new ArrayList(); + listMemberTypes = new ArrayList>(); + listMembers = new ArrayList>(); + } + + + public StructDecl(String _origInt) { + + super(_origInt); + listStructs = new ArrayList(); + listMemberTypes = new ArrayList>(); + listMembers = new ArrayList>(); + } + + + /** + * addNewMember() adds a new member type and value into the list + */ + public void addNewMember(String structType, String newMemberType, String newMember) { + + if (listStructs.contains(structType)) { + // Existing enum declaration + int index = listStructs.indexOf(structType); + List memberTypeList = listMemberTypes.get(index); + memberTypeList.add(newMemberType); + List memberList = listMembers.get(index); + memberList.add(newMember); + } else { + // New declaration + List newMemberTypeList = new ArrayList(); + newMemberTypeList.add(newMemberType); + listMemberTypes.add(newMemberTypeList); + List newMemberList = new ArrayList(); + newMemberList.add(newMember); + listMembers.add(newMemberList); + } + } + + + /** + * getStructTypes() gets list of recorded list structs + */ + public List getStructTypes() { + + return listStructs; + } + + + /** + * getMemberTypes() gets list of member types + */ + public List getMemberTypes(String structType) { + + int index = listStructs.indexOf(structType); + return listMemberTypes.get(index); + } + + + /** + * getMembers() gets list of members + */ + public List getMembers(String structType) { + + int index = listStructs.indexOf(structType); + return listMembers.get(index); + } +} diff --git a/others/javacup/iotparser.cup b/others/javacup/iotparser.cup index 00db795..8106d34 100644 --- a/others/javacup/iotparser.cup +++ b/others/javacup/iotparser.cup @@ -33,8 +33,8 @@ non terminal ParseNode policy; 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 enumdec, enumlist, enummem; -non terminal ParseNode structdec, structlist, structmem; +non terminal ParseNode enumdeclist, enumdec, enumlist, enummem; +non terminal ParseNode structdeclist, structdec, structlist, structmem; /** @@ -65,18 +65,6 @@ policy ::= intface:in pn.addChild(rl); RESULT = pn; :} - | enumdec:en - {: - ParseNode pn = new ParseNode("policy"); - pn.addChild(en); - RESULT = pn; - :} - | structdec:st - {: - ParseNode pn = new ParseNode("policy"); - pn.addChild(st); - RESULT = pn; - :} ; //1) Interface class definition @@ -85,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; :} ; @@ -295,7 +285,18 @@ capintlist ::= IDENT:idcap :} ; -//4) Enumeration declaration +//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"); @@ -303,7 +304,7 @@ enumdec ::= ENUM IDENT:idenumdec BEGIN enumlist:el END pn.addChild(el); RESULT = pn; :} - ; + ; enumlist ::= enumlist:el enummem:e {: el.addChild(e); @@ -329,7 +330,18 @@ enummem ::= IDENT:idenum COMMA :} ; -//5) Struct declaration +//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"); @@ -345,7 +357,7 @@ structlist ::= structlist:sl structmem:s :} | /* empty */ {: - ParseNode pn = new ParseNode("enum_list"); + ParseNode pn = new ParseNode("struct_list"); RESULT = pn; :} ; -- 2.34.1