Add support for Enum type for mgc version and also add default constructor. Comment...
[IRC.git] / Robust / src / Parse / java14.cup
index 80c2f59304023bc2f9d66efbc64cde4318e3b5ea..2fd93f3f51d686020e65e2a1d416bb5eb048aedb 100644 (file)
@@ -52,11 +52,11 @@ terminal STATIC; // modifier
 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
 terminal CLASS; // class_declaration
 terminal EXTENDS; // super
-//terminal IMPLEMENTS; // interfaces
+terminal IMPLEMENTS; // interfaces
 terminal VOID; // method_header
 terminal THROWS; // throws
 terminal THIS, SUPER; // explicit_constructor_invocation
-//terminal INTERFACE; // interface_declaration
+terminal INTERFACE; // interface_declaration
 terminal IF, ELSE; // if_then_statement, if_then_else_statement
 terminal SWITCH; // switch_statement
 terminal CASE, DEFAULT; // switch_label
@@ -103,6 +103,9 @@ terminal ASSERT; // assert_statement
 terminal ELLIPSIS;
 terminal ENUM;
 
+// added for disjoint reachability analysis
+terminal GENREACH;
+
 
 // 19.2) The Syntactic Grammar
 non terminal ParseNode goal;
@@ -114,7 +117,7 @@ non terminal ParseNode integral_type, floating_point_type;
 non terminal ParseNode reference_type;
 non terminal ParseNode class_or_interface_type;
 non terminal ParseNode class_type;
-//non terminal ParseNode interface_type;
+non terminal ParseNode interface_type;
 non terminal ParseNode array_type;
 // 19.5) Names
 non terminal ParseNode name, simple_name, qualified_name;
@@ -131,7 +134,7 @@ non terminal ParseNode type_declaration;
 non terminal ParseNode modifiers_opt, modifiers, modifier;
 // 19.8.1) Class Declaration
 non terminal ParseNode class_declaration, super, super_opt;
-//non terminal interfaces, interfaces_opt, interface_type_list;
+non terminal ParseNode interfaces, interfaces_opt, interface_type_list;
 non terminal ParseNode class_body;
 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
 non terminal ParseNode class_body_declaration, class_member_declaration;
@@ -148,18 +151,18 @@ non terminal ParseNode formal_parameter;
 //non terminal ParseNode class_type_list;
 non terminal ParseNode method_body;
 // 19.8.4) Static Initializers
-//non terminal ParseNode static_initializer;
+non terminal ParseNode static_initializer;
 // 19.8.5) Constructor Declarations
 non terminal ParseNode constructor_declaration, constructor_declarator;
 non terminal ParseNode constructor_body;
 non terminal ParseNode explicit_constructor_invocation;
 // 19.9.1) Interface Declarations
-//non terminal ParseNode interface_declaration;
-//non terminal ParseNode extends_interfaces_opt, extends_interfaces;
-//non terminal ParseNode interface_body;
-//non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
-//non terminal ParseNode interface_member_declaration, constant_declaration;
-//non terminal ParseNode abstract_method_declaration;
+non terminal ParseNode interface_declaration;
+non terminal ParseNode extends_interfaces_opt, extends_interfaces;
+non terminal ParseNode interface_body;
+non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
+non terminal ParseNode interface_member_declaration, constant_declaration;
+non terminal ParseNode abstract_method_declaration;
 // 19.10) Arrays
 non terminal ParseNode array_initializer;
 non terminal ParseNode variable_initializers;
@@ -174,10 +177,10 @@ non terminal ParseNode empty_statement;
 non terminal ParseNode expression_statement, statement_expression;
 non terminal ParseNode if_then_statement;
 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
-//non terminal ParseNode switch_statement, switch_block;
-//non terminal ParseNode switch_block_statement_groups;
-//non terminal ParseNode switch_block_statement_group;
-//non terminal ParseNode switch_labels, switch_label;
+non terminal ParseNode switch_statement, switch_block;
+non terminal ParseNode switch_block_statement_groups;
+non terminal ParseNode switch_block_statement_group;
+non terminal ParseNode switch_labels, switch_label;
 non terminal ParseNode while_statement, while_statement_no_short_if;
 non terminal ParseNode do_statement;
 non terminal ParseNode for_statement, for_statement_no_short_if;
@@ -194,6 +197,7 @@ non terminal ParseNode synchronized_statement;
 //non terminal ParseNode catches, catch_clause;
 //non terminal ParseNode finally;
 //non terminal ParseNode assert_statement;
+non terminal ParseNode genreach_statement;
 // 19.12) Expressions
 non terminal ParseNode primary, primary_no_new_array;
 non terminal ParseNode class_instance_creation_expression;
@@ -219,7 +223,7 @@ non terminal ParseNode assignment_expression;
 non terminal ParseNode assignment;
 non terminal ParseNode assignment_operator;
 non terminal ParseNode expression_opt, expression;
-//non terminal ParseNode constant_expression;
+non terminal ParseNode constant_expression;
 //failure aware computation keywords
 terminal FLAG;
 terminal OPTIONAL;
@@ -267,8 +271,15 @@ terminal DISJOINT;
 
 //coarse-grain parallelization
 terminal SESE;
+terminal RBLOCK;
 non terminal ParseNode sese_statement;
 
+// mgc
+// JSR-201) Enum Declaration
+non terminal ParseNode enum_declaration;
+non terminal ParseNode enum_body, enum_constants_opt, enum_constants, enum_constant;
+//non terminal ParseNode enum_arguments_opt, enum_body_declarations_opt;
+
 
 start with goal;
 
@@ -564,7 +575,7 @@ class_or_interface_type ::= name:name {:
        :};
 
 class_type ::= class_or_interface_type:type {: RESULT=type; :};
-//interface_type ::= class_or_interface_type;
+interface_type ::= class_or_interface_type:type {: RESULT=type; :};
 
 array_type ::= primitive_type:prim dims:dims {: 
                ParseNode pn=(new ParseNode("type")).addChild("array");
@@ -680,11 +691,18 @@ type_declaration ::=
                {:
                        RESULT=cd;
                :}
+       |       enum_declaration:ed
+           {:
+               RESULT=ed;
+           :}
        |       task_declaration:td 
                {:
                        RESULT=td;
                :}
-//      |       interface_declaration
+    |   interface_declaration:in
+        {:
+                       RESULT=in;
+               :}
        |       SEMICOLON {: RESULT=new ParseNode("empty"); :}
        ;
 
@@ -710,13 +728,14 @@ modifier ::=
        PROTECTED {: RESULT=new ParseNode("protected"); :}|
        PRIVATE {: RESULT=new ParseNode("private"); :}|
        STATIC {: RESULT=new ParseNode("static"); :} |
-//     ABSTRACT |
+       ABSTRACT {: RESULT=new ParseNode("abstract"); :}  |
        FINAL {: RESULT=new ParseNode("final"); :}|
        NATIVE {: RESULT=new ParseNode("native"); :} |
        SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
-       ATOMIC {: RESULT=new ParseNode("atomic"); :}
+       ATOMIC {: RESULT=new ParseNode("atomic"); :} |
+       VOLATILE {: RESULT=new ParseNode("volatile"); :}
 //     TRANSIENT | 
-//     VOLATILE |
+
 //     STRICTFP // note that semantic analysis must check that the
                         // context of the modifier allows strictfp.
        ;
@@ -725,13 +744,14 @@ modifier ::=
 
 // 19.8.1) Class Declaration:
 class_declaration ::= 
-       modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so //interfaces_opt
-class_body:body 
+       modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo 
+       class_body:body 
        {:
        ParseNode pn=new ParseNode("class_declaration");
        pn.addChild("modifiers").addChild(mo);
        pn.addChild("name").addChild(id);
        pn.addChild("super").addChild(so);
+       pn.addChild("superIF").addChild(ifo);
        pn.addChild("classbody").addChild(body);
        RESULT=pn;
        :}
@@ -747,15 +767,23 @@ super_opt ::=
        :}
        ;
 
-//interfaces ::= IMPLEMENTS interface_type_list
-//       ;
-//interfaces_opt::=
-//       |       interfaces
-//       ;
-//interface_type_list ::=
-//               interface_type
-//       |       interface_type_list COMMA interface_type
-//       ;
+interfaces ::= IMPLEMENTS interface_type_list:iftl {: RESULT=iftl; :}
+       ;
+interfaces_opt ::=
+       {: RESULT=new ParseNode("empty"); :}
+       |       interfaces:ifs {: RESULT=ifs; :}
+       ;
+interface_type_list ::=
+               interface_type:ift {: 
+                       ParseNode pn=new ParseNode("interface_type_list");
+                       pn.addChild(ift);
+                       RESULT=pn;
+               :}
+       |       interface_type_list:iftl COMMA interface_type:ift {: 
+                       iftl.addChild(ift);
+                       RESULT=iftl;
+               :}
+       ;
 
 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
        ;
@@ -780,7 +808,9 @@ class_body_declaration ::=
                class_member_declaration:member {: 
                RESULT=(new ParseNode("member")).addChild(member).getRoot();
        :}
-//     |       static_initializer
+       |       static_initializer:block{:
+               RESULT=(new ParseNode("static_block")).addChild(block).getRoot();
+       :}
        |       constructor_declaration:constructor {: 
                RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
        :}
@@ -801,10 +831,75 @@ class_member_declaration ::=
        RESULT=(new ParseNode("method")).addChild(method).getRoot(); 
        :}
        /* repeat the prod for 'class_declaration' here: */
-//     |       modifiers_opt CLASS IDENTIFIER super_opt class_body
-//      |       interface_declaration
+       |       modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo class_body:body
+       {:
+       ParseNode pn=new ParseNode("inner_class_declaration");
+       pn.addChild("modifiers").addChild(mo);
+       pn.addChild("name").addChild(id);
+       pn.addChild("super").addChild(so);
+       pn.addChild("superIF").addChild(ifo);
+       pn.addChild("classbody").addChild(body);
+       RESULT=pn;
+       :}
+       |       enum_declaration:ed
+       {:
+       RESULT=ed; 
+       :}
+//    |       interface_declaration:interfaced {: 
+//     RESULT=(new ParseNode("interface")).addChild(interfaced).getRoot(); 
+//     :}
        |       SEMICOLON       {: RESULT=new ParseNode("empty"); :}
        ;
+       
+// mgc
+// JSR-201) Enum Declaration
+enum_declaration ::=
+               modifiers_opt:mo ENUM IDENTIFIER:id /*interfaces_opt:io*/ enum_body:body
+               {:
+                       ParseNode pn=new ParseNode("enum_declaration");
+                       pn.addChild("modifiers").addChild(mo);
+                       pn.addChild("name").addChild(id);
+                       //pn.addChild("superIF").addChild(ifo);
+                       pn.addChild("enumbody").addChild(body);
+                       RESULT=pn;
+               :}
+       ;
+enum_body ::=
+               LBRACE enum_constants_opt:eco /*enum_body_declarations_opt:ebdo*/ RBRACE
+               {: RESULT=eco; :}
+       ;
+enum_constants_opt ::=
+  {: RESULT=new ParseNode("empty"); :}
+       |       enum_constants:ecs
+       {: RESULT=ecs; :}
+       ;
+enum_constants ::=
+               enum_constant:ec {: 
+               ParseNode pn=new ParseNode("enum_constants_list");
+               pn.addChild(ec);
+               RESULT=pn;
+       :}
+       |       enum_constants:ecs COMMA enum_constant:ec {:
+           ecs.addChild(ec);
+           RESULT=ecs;
+       :}
+       ;
+enum_constant ::=
+               IDENTIFIER:id /*enum_arguments_opt*/
+               {: 
+                   ParseNode pn=new ParseNode("enum_constant");
+                   pn.addChild("name").addChild(id);
+                   RESULT=pn; 
+               :}
+//     |       IDENTIFIER enum_arguments_opt class_body
+       ;
+//enum_arguments_opt ::=
+//     |       LPAREN argument_list_opt RPAREN
+//     ;
+//enum_body_declarations_opt ::=
+//     |       SEMICOLON class_body_declarations_opt:cbdo
+//     ;
+
 
 //Failure aware computation
 flag_declaration ::= 
@@ -964,9 +1059,13 @@ method_body ::=   block:block {:
        ;
 
 // 19.8.4) Static Initializers
-//static_initializer ::=
-//             STATIC block
-//     ;
+static_initializer ::=
+               STATIC block:body {:
+               ParseNode pn=new ParseNode("static_block_declaration");
+               pn.addChild("body").addChild(body);
+               RESULT=pn;
+       :}
+       ;
 
 // 19.8.5) Constructor Declarations
 constructor_declaration ::=
@@ -1019,8 +1118,12 @@ constructor_body ::=
        |       LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
        ;
 explicit_constructor_invocation ::=
-//             THIS LPAREN argument_list_opt RPAREN SEMICOLON
-//     |       
+       THIS LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
+            ParseNode pn=new ParseNode("explconstrinv");
+            pn.addChild(alo);
+            RESULT=pn;
+       :}
+       |       
 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {: 
        ParseNode pn=new ParseNode("superinvoke");
        pn.addChild(alo);
@@ -1033,43 +1136,84 @@ SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
 // 19.9) Interfaces
 
 // 19.9.1) Interface Declarations
-//interface_declaration ::=
-//               modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
-//                       interface_body
-//       ;
-//extends_interfaces_opt ::=
-//       |       extends_interfaces
-//       ;
-//extends_interfaces ::=
-//               EXTENDS interface_type
-//       |       extends_interfaces COMMA interface_type
-//       ;
-//interface_body ::=
-//               LBRACE interface_member_declarations_opt RBRACE
-//       ;
-//interface_member_declarations_opt ::=
-//       |       interface_member_declarations
-//       ;
-//interface_member_declarations ::=
-//               interface_member_declaration
-//       |       interface_member_declarations interface_member_declaration
-//       ;
-//interface_member_declaration ::=
-//               constant_declaration
-//       |       abstract_method_declaration
-//       |       class_declaration
-//       |       interface_declaration
-//       |       SEMICOLON
-//       ;
-//constant_declaration ::=
-//               field_declaration
-//       // need to semantically check that modifiers of field declaration
-//       // include only PUBLIC, STATIC, or FINAL.  Other modifiers are
-//       // disallowed.
-//       ;
-//abstract_method_declaration ::=
-//               method_header SEMICOLON
-//       ;
+interface_declaration ::=
+               modifiers_opt:mo INTERFACE IDENTIFIER:id extends_interfaces_opt:io
+                       interface_body:body
+       {:
+       ParseNode pn=new ParseNode("interface_declaration");
+       pn.addChild("modifiers").addChild(mo);
+       pn.addChild("name").addChild(id);
+       pn.addChild("superIF").addChild(io);
+       pn.addChild("interfacebody").addChild(body);
+       RESULT=pn;
+       :}
+       ;
+extends_interfaces_opt ::=
+       {: RESULT=new ParseNode("empty"); :}
+       |       extends_interfaces:eifs {: RESULT=eifs; :}
+       ;
+extends_interfaces ::=
+               EXTENDS interface_type:ift 
+               {: 
+               ParseNode pn=new ParseNode("extend_interface_list");
+               pn.addChild(ift);
+               RESULT=pn; 
+               :}
+     |       extends_interfaces:eifs COMMA interface_type:ift
+             {:
+             eifs.addChild(ift);
+             RESULT=eifs;
+             :}
+       ;
+interface_body ::=
+               LBRACE interface_member_declarations_opt:imdo RBRACE
+               {: RESULT=imdo; :}
+       ;
+interface_member_declarations_opt ::=
+       {: RESULT=new ParseNode("empty"); :}
+       |       interface_member_declarations:imd {: RESULT=imd; :}
+       ;
+interface_member_declarations ::=
+               interface_member_declaration:imd {: 
+                       ParseNode pn=new ParseNode("interface_member_declaration_list");
+                       pn.addChild(imd);
+                       RESULT=pn;
+               :}
+       |       interface_member_declarations:imds interface_member_declaration:imd {: 
+                       imds.addChild(imd);
+                       RESULT=imds;
+               :}
+       ;
+interface_member_declaration ::=
+               constant_declaration:constant {: 
+               RESULT=(new ParseNode("constant")).addChild(constant).getRoot();
+       :}
+       |       abstract_method_declaration:method {:
+       RESULT=(new ParseNode("method")).addChild(method).getRoot(); 
+       :}
+          |    enum_declaration:ed {:
+          RESULT=(new ParseNode("enum_declaration")).addChild(ed).getRoot();
+          :}
+//       |       class_declaration:class 
+//       |       interface_declaration:interface 
+       |       SEMICOLON {: 
+       RESULT=new ParseNode("empty"); 
+       :}
+       ;
+constant_declaration ::=
+               field_declaration:fd {: RESULT=fd; :}
+       // need to semantically check that modifiers of field declaration
+       // include only PUBLIC, STATIC, or FINAL.  Other modifiers are
+       // disallowed.
+       ;
+abstract_method_declaration ::=
+               method_header:header SEMICOLON {:
+               ParseNode pn=new ParseNode("method_declaration");
+               pn.addChild("header").addChild(header);
+               pn.addChild("body").addChild(new ParseNode("empty"));
+               RESULT=pn;
+       :}
+       ;
 
 
 // 19.10) Arrays
@@ -1131,6 +1275,9 @@ block_statement ::=
        |       statement:statement {: 
                RESULT=statement;
        :}
+//     |       enum_declaration:ed {:
+//             RESULT=ed;
+//     :}
 //     |       class_declaration
 //     |       interface_declaration
        ;
@@ -1181,7 +1328,7 @@ statement_without_trailing_substatement ::=
                block:st {: RESULT=st; :}
        |       empty_statement:st {: RESULT=st; :}
        |       expression_statement:st {: RESULT=st; :}
-//     |       switch_statement
+       |       switch_statement:st {: RESULT=st; :}
        |       do_statement:dos {:RESULT=dos; :}
        |       break_statement:st {: RESULT=st; :}
        |       continue_statement:st {: RESULT=st; :}
@@ -1190,6 +1337,7 @@ statement_without_trailing_substatement ::=
        |       atomic_statement:st {: RESULT=st; :}
        |       sese_statement:st {: RESULT=st; :}
        |       synchronized_statement:st {: RESULT=st; :}
+       |       genreach_statement:st {: RESULT=st; :}
 //     |       throw_statement
 //     |       try_statement
 //     |       assert_statement
@@ -1246,30 +1394,86 @@ if_then_else_statement_no_short_if ::=
                RESULT=pn;
        :}
        ;
-//switch_statement ::=
-//             SWITCH LPAREN expression RPAREN switch_block
-//     ;
-//switch_block ::=
-//             LBRACE switch_block_statement_groups switch_labels RBRACE
-//     |       LBRACE switch_block_statement_groups RBRACE
-//     |       LBRACE switch_labels RBRACE
-//     |       LBRACE RBRACE
-//     ;
-//switch_block_statement_groups ::=
-//             switch_block_statement_group
-//     |       switch_block_statement_groups switch_block_statement_group
-//     ;
-//switch_block_statement_group ::=
-//             switch_labels block_statements
-//     ;
-//switch_labels ::=
-//             switch_label
-//     |       switch_labels switch_label
-//     ;
-//switch_label ::=
-//             CASE constant_expression COLON
-//     |       DEFAULT COLON
-//     ;
+switch_statement ::=
+               SWITCH LPAREN expression:exp RPAREN switch_block:body
+               {:
+                   ParseNode pn=new ParseNode("switch_statement");
+                   pn.addChild("condition").addChild(exp);
+                   pn.addChild("statement").addChild(body);
+                   RESULT=pn;
+               :}
+       ;
+switch_block ::=
+               LBRACE switch_block_statement_groups:sbsg switch_labels:sl RBRACE
+               {: 
+                   ParseNode pn = new ParseNode("switch_block");
+                   pn.addChild("switch_labels").addChild(sl);
+                   pn.addChild("switch_statements").addChild(new ParseNode("empty"));
+                   sbsg.addChild(pn);
+                   RESULT=sbsg; 
+               :}
+       |       LBRACE switch_block_statement_groups:sbsg RBRACE
+           {: 
+                   RESULT=sbsg; 
+               :}
+       |       LBRACE switch_labels:sl RBRACE 
+           {: 
+               ParseNode pnb = new ParseNode("switch_block_list");
+                   ParseNode pn = new ParseNode("switch_block");
+                   pn.addChild("switch_labels").addChild(sl);
+                   pn.addChild("switch_statements").addChild(new ParseNode("empty"));
+                   pnb.addChild(pn);
+                   RESULT=pnb; 
+               :}
+       |       LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
+       ;
+switch_block_statement_groups ::=
+               switch_block_statement_group:sbsg
+               {: 
+                   ParseNode pn = new ParseNode("switch_block_list");
+                   pn.addChild(sbsg);
+                   RESULT=pn;
+               :}
+       |       switch_block_statement_groups:sbsgs switch_block_statement_group:sbsg
+           {:
+               sbsgs.addChild(sbsg);
+               RESULT=sbsgs;
+           :}
+       ;
+switch_block_statement_group ::=
+               switch_labels:sls block_statements:body
+               {: 
+                   ParseNode pn=new ParseNode("switch_block");
+                   pn.addChild("switch_labels").addChild(sls);
+                   pn.addChild("switch_statements").addChild(body);
+                   RESULT=pn; 
+               :}
+       ;
+switch_labels ::=
+               switch_label:sl
+               {: 
+                   ParseNode pn=new ParseNode("switch_label_list");
+                   pn.addChild(sl);
+                   RESULT=pn; 
+               :}
+       |       switch_labels:sls switch_label:sl
+           {: 
+                   sls.addChild(sl); 
+                   RESULT=sls;
+               :}
+       ;
+switch_label ::=
+               CASE constant_expression:ce COLON
+               {: 
+                   ParseNode pn=new ParseNode("switch_label");
+                   pn.addChild(ce);
+                   RESULT=pn;
+               :}
+       |       DEFAULT COLON
+           {: 
+                   RESULT=new ParseNode("default_switch_label"); 
+               :}
+       ;
 
 while_statement ::=
                WHILE LPAREN expression:exp RPAREN statement:st {: 
@@ -1388,6 +1592,17 @@ sese_statement ::=
               pn.addChild("identifier").addChild(id);
               RESULT=pn;
        :}
+       |      RBLOCK block:blk {: 
+              ParseNode pn = new ParseNode("sese");
+              pn.addChild("body").addChild(blk);
+              RESULT=pn;
+       :}
+       |      RBLOCK variable_declarator_id:id block:blk {: 
+              ParseNode pn = new ParseNode("sese");
+              pn.addChild("body").addChild(blk);
+              pn.addChild("identifier").addChild(id);
+              RESULT=pn;
+       :}
        ;
 //try_statement ::=
 //             TRY block catches
@@ -1971,6 +2186,21 @@ expression_opt ::=
 expression ::= assignment_expression:exp {: 
                RESULT=exp; :}
        ;
-//constant_expression ::=
-//             expression
-//     ;
+// note that this constraint must be enforced during semantic checking
+// 'constant_expression' should include enumerated constants.
+constant_expression ::=
+               expression:exp 
+               {:
+                   ParseNode pn = new ParseNode("constant_expression");
+                   pn.addChild(exp);
+                   RESULT=pn;
+               :}
+       ;
+
+
+genreach_statement ::=
+               GENREACH IDENTIFIER:graphName SEMICOLON {: 
+               ParseNode pn=new ParseNode("genreach");
+               pn.addChild("graphName").addChild(graphName);
+               RESULT=pn; :}
+       ;