From 07a8d0c97995704dff00c76fdb5607c81c281f51 Mon Sep 17 00:00:00 2001 From: yeom Date: Sat, 23 Apr 2011 00:52:19 +0000 Subject: [PATCH] extends grammar little more to have the break statement with label --- Robust/src/IR/Tree/BuildIR.java | 4 +++- Robust/src/Parse/java14.cup | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 30779661..8aaf398f 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1481,7 +1481,9 @@ public class BuildIR { ContinueBreakNode cbn=new ContinueBreakNode(true); cbn.setNumLine(pn.getLine()); blockstatements.add(cbn); - + ParseNode idopt_pn=pn.getChild("identifier_opt"); + ParseNode name_pn=idopt_pn.getChild("name"); + // name_pn.getTerminal() gives you the label } else if (isNode(pn,"genreach")) { String graphName = pn.getChild("graphName").getTerminal(); blockstatements.add( new GenReachNode( graphName ) ); diff --git a/Robust/src/Parse/java14.cup b/Robust/src/Parse/java14.cup index 75106cff..87079c4f 100644 --- a/Robust/src/Parse/java14.cup +++ b/Robust/src/Parse/java14.cup @@ -194,7 +194,7 @@ non terminal ParseNode for_statement, for_statement_no_short_if; non terminal ParseNode for_init_opt, for_init; non terminal ParseNode for_update_opt, for_update; non terminal ParseNode statement_expression_list; -//non terminal ParseNode identifier_opt; +non terminal ParseNode identifier_opt; non terminal ParseNode break_statement, continue_statement; non terminal ParseNode return_statement; non terminal ParseNode throw_statement; @@ -1771,14 +1771,21 @@ statement_expression_list ::= :} ; -//identifier_opt ::= -// | IDENTIFIER -// ; +identifier_opt ::= {: RESULT=new ParseNode("identifier_opt",parser.lexer.line_num); + :} + | IDENTIFIER:id {: + ParseNode pn=new ParseNode("identifier_opt",parser.lexer.line_num); + pn.addChild("name").addChild(id); + RESULT=pn; + :} + ; break_statement ::= - BREAK -//identifier_opt -SEMICOLON {: RESULT=new ParseNode("break",parser.lexer.line_num); :} + BREAK identifier_opt:id SEMICOLON {: + ParseNode pn=new ParseNode("break",parser.lexer.line_num); + pn.addChild(id); + RESULT=pn; + :} ; continue_statement ::= -- 2.34.1