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;
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;
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;
{:
RESULT=cd;
:}
+ | enum_declaration:ed
+ {:
+ RESULT=ed;
+ :}
| task_declaration:td
{:
RESULT=td;
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.
;
RESULT=(new ParseNode("method")).addChild(method).getRoot();
:}
/* repeat the prod for 'class_declaration' here: */
-// | 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;
-// :}
- | interface_declaration:interfaced {:
- RESULT=(new ParseNode("interface")).addChild(interfaced).getRoot();
+ | 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 ::=
| 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 {:
| statement:statement {:
RESULT=statement;
:}
+// | enum_declaration:ed {:
+// RESULT=ed;
+// :}
// | class_declaration
// | interface_declaration
;
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; :}
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 {:
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 ::=