enables the labeled_statements. The scope of a label declared by a labled statement...
authoryeom <yeom>
Wed, 20 Apr 2011 18:14:38 +0000 (18:14 +0000)
committeryeom <yeom>
Wed, 20 Apr 2011 18:14:38 +0000 (18:14 +0000)
Robust/src/IR/Tree/BlockNode.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/Parse/java14.cup

index f62e6fa0041d7849af57cd130d1a569f7e588d48..dfdb70eaff9a3ec52f23239281a8070d7aa21f21 100644 (file)
@@ -10,6 +10,8 @@ public class BlockNode extends TreeNode {
   public final static int NORMAL=0;
   public final static int NOBRACES=1;
   public final static int EXPRLIST=2;
+  
+  String label=null;
 
   public BlockNode() {
     blockstatements=new Vector();
@@ -85,4 +87,13 @@ public class BlockNode extends TreeNode {
   public int kind() {
     return Kind.BlockNode;
   }
+  
+  public void setLabel(String l){
+    label=l;
+  }
+  
+  public String getLabel(){
+    return label;
+  }
+
 }
index 0342f7bb92db047433a5e6baab14301ab4d97c11..7a7006dd57855f656f3b7df96c5db9438ee7f868 100644 (file)
@@ -1427,6 +1427,11 @@ public class BuildIR {
       String graphName = pn.getChild("graphName").getTerminal();
       blockstatements.add( new GenReachNode( graphName ) );
 
+    } else if(isNode(pn,"labeledstatement")){
+      String label = pn.getChild("name").getTerminal();
+      BlockNode bn=parseSingleBlock(pn.getChild("statement").getFirstChild());
+      bn.setLabel(label);
+      blockstatements.add(new SubBlockNode(bn));  
     } else {
       System.out.println("---------------");
       System.out.println(pn.PPrint(3,true));
index 9644ac5b3a6e1ce446cda07cab5395969ea8ac08..75106cff3272ac855ba96e8bc9d501d3a2a41bde 100644 (file)
@@ -180,7 +180,7 @@ non terminal ParseNode local_variable_declaration_statement, local_variable_decl
 non terminal ParseNode statement, statement_no_short_if;
 non terminal ParseNode statement_without_trailing_substatement;
 non terminal ParseNode empty_statement;
-//non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
+non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
 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;
@@ -1406,7 +1406,7 @@ abstract_method_declaration ::=
                RESULT=pn;
        :}
        ;
-
+/*
 annotation_type_declaration ::=
                AT INTERFACE IDENTIFIER annotation_type_body
        |       modifiers_at INTERFACE IDENTIFIER annotation_type_body
@@ -1429,7 +1429,7 @@ annotation_type_element_declaration ::=
         |      interface_declaration 
        |       SEMICOLON
         ;
-
+*/
 // 19.10) Arrays
 array_initializer ::=
                LBRACE variable_initializers:var_init_list COMMA RBRACE {:
@@ -1528,7 +1528,7 @@ local_variable_declaration ::=
 statement ::=  statement_without_trailing_substatement:st {: 
                RESULT=st;
        :}
-//     |       labeled_statement:st {: RESULT=st; :}
+       |       labeled_statement:st {: RESULT=st; :}
        |       if_then_statement:st {: RESULT=st; :}
        |       if_then_else_statement:st {: RESULT=st; :}
        |       while_statement:st {: RESULT=st; :}
@@ -1536,7 +1536,7 @@ statement ::=     statement_without_trailing_substatement:st {:
        ;
 statement_no_short_if ::=
                statement_without_trailing_substatement:st {: RESULT=st; :}
-//     |       labeled_statement_no_short_if:st {: RESULT=st; :}
+       |       labeled_statement_no_short_if:st {: RESULT=st; :}
        |       if_then_else_statement_no_short_if:st {: RESULT=st; :}
        |       while_statement_no_short_if:st {: RESULT=st; :}
        |       for_statement_no_short_if:st {: RESULT=st; :}
@@ -1562,12 +1562,22 @@ statement_without_trailing_substatement ::=
 empty_statement ::=
                SEMICOLON {: RESULT=new ParseNode("nop",parser.lexer.line_num); :}
        ;
-//labeled_statement ::=
-//             IDENTIFIER COLON statement
-//     ;
-//labeled_statement_no_short_if ::=
-//             IDENTIFIER COLON statement_no_short_if
-//     ;
+labeled_statement ::=
+               IDENTIFIER:id COLON statement:st {:
+               ParseNode pn=new ParseNode("labeledstatement",parser.lexer.line_num);
+               pn.addChild("name").addChild(id);
+               pn.addChild("statement").addChild(st);
+               RESULT=pn;                              
+               :}
+       ;
+labeled_statement_no_short_if ::=
+               IDENTIFIER:id COLON statement_no_short_if:st {:
+               ParseNode pn=new ParseNode("labeledstatement",parser.lexer.line_num);
+               pn.addChild("name").addChild(id);
+               pn.addChild("statement").addChild(st);
+               RESULT=pn;                              
+               :}
+       ;
 expression_statement ::=
                statement_expression:se SEMICOLON {: 
                ParseNode pn=new ParseNode("expression",parser.lexer.line_num);