From 2e1715aeec4ded8b84b487a88e0a088aabe309fc Mon Sep 17 00:00:00 2001 From: yeom Date: Wed, 20 Apr 2011 18:14:38 +0000 Subject: [PATCH] enables the labeled_statements. The scope of a label declared by a labled statement is the block node following the labeled statement. Note that it might be a different way when Sonny implements continue/break with labels --- Robust/src/IR/Tree/BlockNode.java | 11 +++++++++++ Robust/src/IR/Tree/BuildIR.java | 5 +++++ Robust/src/Parse/java14.cup | 32 ++++++++++++++++++++----------- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Robust/src/IR/Tree/BlockNode.java b/Robust/src/IR/Tree/BlockNode.java index f62e6fa0..dfdb70ea 100644 --- a/Robust/src/IR/Tree/BlockNode.java +++ b/Robust/src/IR/Tree/BlockNode.java @@ -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; + } + } diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 0342f7bb..7a7006dd 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -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)); diff --git a/Robust/src/Parse/java14.cup b/Robust/src/Parse/java14.cup index 9644ac5b..75106cff 100644 --- a/Robust/src/Parse/java14.cup +++ b/Robust/src/Parse/java14.cup @@ -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); -- 2.34.1