From 43ecb8a0706d23164622001d93266400abbe0f88 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 9 Feb 2006 02:33:02 +0000 Subject: [PATCH] update cup file VS: Committing in Main --- Robust/src/Parse/java14.cup | 1568 +++++++++++++++++++++++------------ 1 file changed, 1020 insertions(+), 548 deletions(-) diff --git a/Robust/src/Parse/java14.cup b/Robust/src/Parse/java14.cup index c3b83df2..2904d005 100644 --- a/Robust/src/Parse/java14.cup +++ b/Robust/src/Parse/java14.cup @@ -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 @@ -104,219 +104,307 @@ terminal ELLIPSIS; terminal ENUM; // 19.2) The Syntactic Grammar -non terminal goal; +non terminal ParseNode goal; // 19.3) Lexical Structure -non terminal literal; +non terminal ParseNode literal; // 19.4) Types, Values, and Variables -non terminal type, primitive_type, numeric_type; -non terminal integral_type, floating_point_type; -non terminal reference_type; -non terminal class_or_interface_type; -non terminal class_type, interface_type; -non terminal array_type; +non terminal ParseNode type, primitive_type, numeric_type; +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 array_type; // 19.5) Names -non terminal name, simple_name, qualified_name; +non terminal ParseNode name, simple_name, qualified_name; // 19.6) Packages -non terminal compilation_unit; -non terminal package_declaration_opt, package_declaration; -non terminal import_declarations_opt, import_declarations; -non terminal type_declarations_opt, type_declarations; -non terminal import_declaration; -non terminal single_type_import_declaration; -non terminal type_import_on_demand_declaration; -non terminal type_declaration; +non terminal ParseNode compilation_unit; +//non terminal ParseNode package_declaration_opt, package_declaration; +//non terminal ParseNode import_declarations_opt, import_declarations; +non terminal ParseNode type_declarations_opt, type_declarations; +//non terminal ParseNode import_declaration; +//non terminal ParseNode single_type_import_declaration; +//non terminal ParseNode type_import_on_demand_declaration; +non terminal ParseNode type_declaration; // 19.7) Productions used only in the LALR(1) grammar -non terminal modifiers_opt, modifiers, modifier; +non terminal ParseNode modifiers_opt, modifiers, modifier; // 19.8.1) Class Declaration -non terminal class_declaration, super, super_opt; -non terminal interfaces, interfaces_opt, interface_type_list; -non terminal class_body; -non terminal class_body_declarations, class_body_declarations_opt; -non terminal class_body_declaration, class_member_declaration; +non terminal ParseNode class_declaration, super, super_opt; +//non terminal 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; // 19.8.2) Field Declarations -non terminal field_declaration, variable_declarators, variable_declarator; -non terminal variable_declarator_id, variable_initializer; +non terminal ParseNode field_declaration, variable_declarators, variable_declarator; +non terminal ParseNode variable_declarator_id; +non terminal ParseNode variable_initializer; // 19.8.3) Method Declarations -non terminal method_declaration, method_header, method_declarator; -non terminal formal_parameter_list_opt, formal_parameter_list; -non terminal formal_parameter; -non terminal throws_opt, throws; -non terminal class_type_list, method_body; +non terminal ParseNode method_declaration, method_header, method_declarator; +non terminal ParseNode formal_parameter_list_opt, formal_parameter_list; +non terminal ParseNode formal_parameter; +//non terminal ParseNode throws_opt; +//non terminal ParseNode throws; +//non terminal ParseNode class_type_list; +non terminal ParseNode method_body; // 19.8.4) Static Initializers -non terminal static_initializer; +//non terminal ParseNode static_initializer; // 19.8.5) Constructor Declarations -non terminal constructor_declaration, constructor_declarator; -non terminal constructor_body; -non terminal explicit_constructor_invocation; +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 interface_declaration; -non terminal extends_interfaces_opt, extends_interfaces; -non terminal interface_body; -non terminal interface_member_declarations_opt, interface_member_declarations; -non terminal interface_member_declaration, constant_declaration; -non terminal 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 array_initializer; -non terminal variable_initializers; +//non terminal ParseNode array_initializer; +//non terminal ParseNode variable_initializers; // 19.11) Blocks and Statements -non terminal block; -non terminal block_statements_opt, block_statements, block_statement; -non terminal local_variable_declaration_statement, local_variable_declaration; -non terminal statement, statement_no_short_if; -non terminal statement_without_trailing_substatement; -non terminal empty_statement; -non terminal labeled_statement, labeled_statement_no_short_if; -non terminal expression_statement, statement_expression; -non terminal if_then_statement; -non terminal if_then_else_statement, if_then_else_statement_no_short_if; -non terminal switch_statement, switch_block; -non terminal switch_block_statement_groups; -non terminal switch_block_statement_group; -non terminal switch_labels, switch_label; -non terminal while_statement, while_statement_no_short_if; -non terminal do_statement; -non terminal for_statement, for_statement_no_short_if; -non terminal for_init_opt, for_init; -non terminal for_update_opt, for_update; -non terminal statement_expression_list; -non terminal identifier_opt; -non terminal break_statement, continue_statement; -non terminal return_statement, throw_statement; -non terminal synchronized_statement, try_statement; -non terminal catches_opt, catches, catch_clause; -non terminal finally; -non terminal assert_statement; +non terminal ParseNode block; +non terminal ParseNode block_statements_opt, block_statements, block_statement; +non terminal ParseNode local_variable_declaration_statement, local_variable_declaration; +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 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 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 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 break_statement, continue_statement; +non terminal ParseNode return_statement; +//non terminal ParseNode throw_statement; +//non terminal ParseNode synchronized_statement, try_statement; +//non terminal ParseNode catches_opt; +//non terminal ParseNode catches, catch_clause; +//non terminal ParseNode finally; +//non terminal ParseNode assert_statement; // 19.12) Expressions -non terminal primary, primary_no_new_array; -non terminal class_instance_creation_expression; -non terminal argument_list_opt, argument_list; -non terminal array_creation_init, array_creation_uninit; -non terminal dim_exprs, dim_expr, dims_opt, dims; -non terminal field_access, method_invocation, array_access; -non terminal postfix_expression; -non terminal postincrement_expression, postdecrement_expression; -non terminal unary_expression, unary_expression_not_plus_minus; -non terminal preincrement_expression, predecrement_expression; -non terminal cast_expression; -non terminal multiplicative_expression, additive_expression; -non terminal shift_expression, relational_expression, equality_expression; -non terminal and_expression, exclusive_or_expression, inclusive_or_expression; -non terminal conditional_and_expression, conditional_or_expression; -non terminal conditional_expression, assignment_expression; -non terminal assignment; -non terminal assignment_operator; -non terminal expression_opt, expression; -non terminal constant_expression; +non terminal ParseNode primary, primary_no_new_array; +non terminal ParseNode class_instance_creation_expression; +non terminal ParseNode argument_list_opt, argument_list; +//non terminal ParseNode array_creation_init, array_creation_uninit; +//non terminal ParseNode dim_exprs, dim_expr, dims_opt, dims; +non terminal ParseNode field_access, method_invocation; +//non terminal ParseNode array_access; +non terminal ParseNode postfix_expression; +non terminal ParseNode postincrement_expression, postdecrement_expression; +non terminal ParseNode unary_expression, unary_expression_not_plus_minus; +non terminal ParseNode preincrement_expression, predecrement_expression; +non terminal ParseNode cast_expression; +non terminal ParseNode multiplicative_expression, additive_expression; +non terminal ParseNode shift_expression, relational_expression, equality_expression; +non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression; +non terminal ParseNode conditional_and_expression, conditional_or_expression; +non terminal ParseNode conditional_expression; +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; start with goal; // 19.2) The Syntactic Grammar -goal ::= compilation_unit +goal ::= compilation_unit:cu + {: + RESULT = (new ParseNode("goal")).addChild(cu).getRoot(); + :} ; // 19.3) Lexical Structure. -literal ::= INTEGER_LITERAL - | FLOATING_POINT_LITERAL - | BOOLEAN_LITERAL - | CHARACTER_LITERAL - | STRING_LITERAL - | NULL_LITERAL + + +literal ::= INTEGER_LITERAL:integer_lit + {: + ParseNode pn=new ParseNode("literal"); + pn.addChild("integer").setLiteral(integer_lit); + RESULT=pn; + :} + | FLOATING_POINT_LITERAL:float_lit + {: + ParseNode pn=new ParseNode("literal"); + pn.addChild("float").setLiteral(float_lit); + RESULT=pn; + :} + | BOOLEAN_LITERAL:boolean_lit + {: + ParseNode pn=new ParseNode("literal"); + pn.addChild("boolean").setLiteral(boolean_lit); + RESULT=pn; + :} + | CHARACTER_LITERAL:char_lit + {: + ParseNode pn=new ParseNode("literal"); + pn.addChild("char").setLiteral(char_lit); + RESULT=pn; + :} + | STRING_LITERAL:string_lit + {: + ParseNode pn=new ParseNode("literal"); + pn.addChild("string").setLiteral(string_lit); + RESULT=pn; + :} + | NULL_LITERAL + {: + RESULT=(new ParseNode("literal")).addChild("null").getRoot(); + :} ; // 19.4) Types, Values, and Variables -type ::= primitive_type - | reference_type +type ::= primitive_type:type {: RESULT=type; :} + | reference_type:type {: RESULT=type; :} ; primitive_type ::= - numeric_type - | BOOLEAN + numeric_type:type {: RESULT=type; :} + | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :} ; -numeric_type::= integral_type - | floating_point_type +numeric_type::= integral_type:type {: RESULT=type; :} + | floating_point_type:type {: RESULT=type; :} ; integral_type ::= - BYTE - | SHORT - | INT - | LONG - | CHAR + BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :} + | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :} + | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :} + | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :} + | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :} ; floating_point_type ::= - FLOAT - | DOUBLE + FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :} + | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :} ; reference_type ::= - class_or_interface_type - | array_type + class_or_interface_type:type {: RESULT=type; :} +// | array_type:type {: RESULT=type; :} ; -class_or_interface_type ::= name; +class_or_interface_type ::= name:name {: + RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot(); + :}; -class_type ::= class_or_interface_type; -interface_type ::= class_or_interface_type; +class_type ::= class_or_interface_type:type {: RESULT=type; :}; +//interface_type ::= class_or_interface_type; -array_type ::= primitive_type dims - | name dims - ; +//array_type ::= primitive_type dims +// | name dims +// ; // 19.5) Names -name ::= simple_name - | qualified_name +name ::= simple_name:name {: RESULT=name; :} + | qualified_name:name {: RESULT=name; :} ; -simple_name ::= IDENTIFIER +simple_name ::= IDENTIFIER:id {: + RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot(); + :} ; -qualified_name ::= - name DOT IDENTIFIER +qualified_name ::= name:name DOT IDENTIFIER:id {: + ParseNode pn=new ParseNode("name"); + pn.addChild("base").addChild(name); + pn.addChild("identifier").addChild(id); + RESULT=pn; + :} ; // 19.6) Packages compilation_unit ::= - package_declaration_opt - import_declarations_opt - type_declarations_opt +// package_declaration_opt +// import_declarations_opt + type_declarations_opt:tdo {: + ParseNode pn=new ParseNode("compilation_unit"); + pn.addChild("types").addChild(tdo); + RESULT=pn; + :} ; -package_declaration_opt ::= package_declaration | ; -import_declarations_opt ::= import_declarations | ; -type_declarations_opt ::= type_declarations | ; - -import_declarations ::= - import_declaration - | import_declarations import_declaration +//package_declaration_opt ::= package_declaration | ; +//import_declarations_opt ::= import_declarations | ; +type_declarations_opt ::= type_declarations:tds {: + RESULT=tds; + :} | + {: RESULT=new ParseNode("empty"); :} ; + +//import_declarations ::= +// import_declaration +// | import_declarations import_declaration +// ; + type_declarations ::= - type_declaration - | type_declarations type_declaration - ; -package_declaration ::= - PACKAGE name SEMICOLON - ; -import_declaration ::= - single_type_import_declaration - | type_import_on_demand_declaration - ; -single_type_import_declaration ::= - IMPORT name SEMICOLON - ; -type_import_on_demand_declaration ::= - IMPORT name DOT MULT SEMICOLON + type_declaration:td {: + ParseNode pn=new ParseNode("type_declaration_list"); + pn.addChild(td); + RESULT=pn; + :} + | type_declarations:tds type_declaration:td {: + tds.addChild(td); + RESULT=tds; + :} ; + +//package_declaration ::= +// PACKAGE name SEMICOLON +// ; +//import_declaration ::= +// single_type_import_declaration +// | type_import_on_demand_declaration +// ; +//single_type_import_declaration ::= +// IMPORT name SEMICOLON +// ; +//type_import_on_demand_declaration ::= +// IMPORT name DOT MULT SEMICOLON +// ; + type_declaration ::= - class_declaration - | interface_declaration - | SEMICOLON + class_declaration:cd + {: + RESULT=(new ParseNode("type_declaration")).addChild("class").addChild(cd); + :} +// | interface_declaration + | SEMICOLON {: RESULT=new ParseNode("empty"); :} ; // 19.7) Productions used only in the LALR(1) grammar modifiers_opt::= - | modifiers - ; -modifiers ::= modifier - | modifiers modifier - ; -modifier ::= PUBLIC | PROTECTED | PRIVATE - | STATIC - | ABSTRACT | FINAL | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE - | STRICTFP // note that semantic analysis must check that the + {: RESULT=new ParseNode("empty"); :} + | modifiers:mo {: + RESULT=mo; + :} + ; +modifiers ::= modifier:mo {: + ParseNode pn=new ParseNode("modifier_list"); + pn.addChild(mo); + RESULT=pn; + :} + | modifiers:mos modifier:mo {: + mos.addChild(mo); + RESULT=mos; + :} + ; +modifier ::= + PUBLIC {: RESULT=new ParseNode("public"); :}| + PROTECTED {: RESULT=new ParseNode("protected"); :}| + PRIVATE {: RESULT=new ParseNode("private"); :}| + STATIC {: RESULT=new ParseNode("static"); :} | +// ABSTRACT | + FINAL {: RESULT=new ParseNode("final"); :}| + NATIVE {: RESULT=new ParseNode("native"); :} +// SYNCHRONIZED | +// TRANSIENT | +// VOLATILE | +// STRICTFP // note that semantic analysis must check that the // context of the modifier allows strictfp. ; @@ -324,556 +412,940 @@ modifier ::= PUBLIC | PROTECTED | PRIVATE // 19.8.1) Class Declaration: class_declaration ::= - modifiers_opt CLASS IDENTIFIER super_opt interfaces_opt class_body - ; -super ::= EXTENDS class_type + modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so {: + ParseNode pn=new ParseNode("class_declaration"); + pn.addChild("modifiers").addChild(mo); + pn.addChild("name").addChild(id); + pn.addChild("super").addChild(so); + RESULT=pn; + :} +//interfaces_opt +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("body").addChild(body); + RESULT=pn; + :} + ; +super ::= EXTENDS class_type:classtype {: + ParseNode pn=new ParseNode("super"); + pn.addChild(classtype); + RESULT=pn; + :} ; super_opt ::= - | super + {: RESULT=new ParseNode("empty"); :} + | super:su {: + RESULT=su; + :} ; -interfaces ::= IMPLEMENTS interface_type_list - ; -interfaces_opt::= - | interfaces - ; -interface_type_list ::= - interface_type - | interface_type_list COMMA interface_type - ; -class_body ::= LBRACE class_body_declarations_opt RBRACE + +//interfaces ::= IMPLEMENTS interface_type_list +// ; +//interfaces_opt::= +// | interfaces +// ; +//interface_type_list ::= +// interface_type +// | interface_type_list COMMA interface_type +// ; + +class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :} ; + class_body_declarations_opt ::= - | class_body_declarations ; + {: RESULT=new ParseNode("empty"); :} + | class_body_declarations:cbd {: RESULT=cbd; :}; + class_body_declarations ::= - class_body_declaration - | class_body_declarations class_body_declaration + class_body_declaration:cbd {: + ParseNode pn=new ParseNode("class_body_declaration_list"); + pn.addChild(cbd); + RESULT=pn; + :} + | class_body_declarations:cbds class_body_declaration:cbd {: + cbds.addChild(cbd); + RESULT=cbds; + :} ; + class_body_declaration ::= - class_member_declaration - | static_initializer - | constructor_declaration - | block + class_member_declaration:member {: + RESULT=(new ParseNode("class_body_declaration")).addChild("member").addChild(member).getRoot(); + :} +// | static_initializer + | constructor_declaration:constructor {: + RESULT=(new ParseNode("class_body_declaration")).addChild("constructor").addChild(constructor).getRoot(); + :} + | block:block {: + RESULT=(new ParseNode("class_body_declaration")).addChild("block").addChild(block).getRoot(); +:} ; class_member_declaration ::= - field_declaration - | method_declaration + field_declaration:field {: + RESULT=(new ParseNode("class_member_declaration")).addChild("field").addChild(field).getRoot(); + :} + | method_declaration:method {: + RESULT=(new ParseNode("class_member_declaration")).addChild("method").addChild(method).getRoot(); + :} /* repeat the prod for 'class_declaration' here: */ - | modifiers_opt CLASS IDENTIFIER super_opt interfaces_opt class_body - | interface_declaration - | SEMICOLON +// | modifiers_opt CLASS IDENTIFIER super_opt class_body +// | interface_declaration + | SEMICOLON {: RESULT=new ParseNode("empty"); :} ; // 19.8.2) Field Declarations field_declaration ::= - modifiers_opt type variable_declarators SEMICOLON + modifiers_opt:mo type:type variable_declarators:var SEMICOLON {: + ParseNode pn=new ParseNode("field_declaration"); + pn.addChild("modifier").addChild(mo); + pn.addChild("type").addChild(type); + pn.addChild("variables").addChild(var); + RESULT=pn; + :} ; + variable_declarators ::= - variable_declarator - | variable_declarators COMMA variable_declarator + variable_declarator:vd {: + ParseNode pn=new ParseNode("variable_declarators_list"); + pn.addChild(vd); + RESULT=pn; + :} + | variable_declarators:vds COMMA variable_declarator:vd {: + vds.addChild(vd); + RESULT=vds; + :} ; variable_declarator ::= - variable_declarator_id - | variable_declarator_id EQ variable_initializer + variable_declarator_id:id {: + ParseNode pn=new ParseNode("variable_declarator"); + pn.addChild("identifier").addChild(id); + RESULT=pn; + :} + | variable_declarator_id:id EQ variable_initializer:init {: + ParseNode pn=new ParseNode("variable_declarator"); + pn.addChild("identifier").addChild(id); + pn.addChild("initializer").addChild(init); + RESULT=pn; + :} ; variable_declarator_id ::= - IDENTIFIER - | variable_declarator_id LBRACK RBRACK + IDENTIFIER:id {: + RESULT=(new ParseNode("variable_declarator_id")).addChild("name").addChild(id);:} +// | variable_declarator_id:id LBRACK RBRACK {: +// RESULT=(new ParseNode("variable_declarator_id")).addChild("array").addChild(id);:} ; variable_initializer ::= - expression - | array_initializer + expression:exp {: RESULT=exp; :} +// | array_initializer ; // 19.8.3) Method Declarations method_declaration ::= - method_header method_body + method_header:header method_body:body {: + ParseNode pn=new ParseNode("method_declaration"); + pn.addChild("header").addChild(header); + pn.addChild("body").addChild(body); + RESULT=pn; + :} ; method_header ::= - modifiers_opt type method_declarator throws_opt - | modifiers_opt VOID method_declarator throws_opt + modifiers_opt:mo type:type method_declarator:decl //throws_opt + {: + ParseNode pn=new ParseNode("method_header"); + pn.addChild("modifiers").addChild(mo); + pn.addChild("returntype").addChild(type); + pn.addChild("declarator").addChild(decl); + RESULT=pn; + :} + | modifiers_opt:mo VOID method_declarator:decl //throws_opt + {: + ParseNode pn=new ParseNode("method_header"); + pn.addChild("modifiers").addChild(mo); + pn.addChild("declarator").addChild(decl); + RESULT=pn; + :} ; method_declarator ::= - IDENTIFIER LPAREN formal_parameter_list_opt RPAREN - | method_declarator LBRACK RBRACK // deprecated - // be careful; the above production also allows 'void foo() []' + IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {: + ParseNode pn=new ParseNode("method_declarator"); + pn.addChild("name").addChild(id); + pn.addChild("parameters").addChild(params); + RESULT=pn; + :} +// | method_declarator LBRACK RBRACK // deprecated +// be careful; the above production also allows 'void foo() []' ; formal_parameter_list_opt ::= - | formal_parameter_list + {: RESULT=new ParseNode("empty"); :} + | formal_parameter_list:fpl {: + RESULT=fpl; + :} ; formal_parameter_list ::= - formal_parameter - | formal_parameter_list COMMA formal_parameter + formal_parameter:fp {: + ParseNode pn=new ParseNode("formal_parameter_list"); + pn.addChild(fp); + RESULT=pn; + :} + | formal_parameter_list:fpl COMMA formal_parameter:fp {: + fpl.addChild(fp); + RESULT=fpl; + :} ; formal_parameter ::= - type variable_declarator_id - | FINAL type variable_declarator_id - ; -throws_opt ::= - | throws - ; -throws ::= THROWS class_type_list - ; -class_type_list ::= - class_type - | class_type_list COMMA class_type - ; -method_body ::= block - | SEMICOLON + type:type variable_declarator_id:name {: + ParseNode pn=new ParseNode("formal_parameter"); + pn.addChild("type").addChild(type); + pn.addChild("name").addChild(name); + RESULT=pn; + :} +// | FINAL type variable_declarator_id + ; +//throws_opt ::= +// | throws +// ; +//throws ::= THROWS class_type_list +// ; +//class_type_list ::= +// class_type +// | class_type_list COMMA class_type +// ; +method_body ::= block:block {: + RESULT=block; + :} + | SEMICOLON {: RESULT=new ParseNode("empty"); :} ; // 19.8.4) Static Initializers -static_initializer ::= - STATIC block - ; +//static_initializer ::= +// STATIC block +// ; // 19.8.5) Constructor Declarations constructor_declaration ::= - modifiers_opt constructor_declarator throws_opt - constructor_body + modifiers_opt:mo constructor_declarator:cd +//throws_opt + constructor_body:body {: + ParseNode pn=new ParseNode("constructor_declaration"); + pn.addChild("modifier").addChild(mo); + pn.addChild("declarator").addChild(cd); + pn.addChild("body").addChild(body); + RESULT=pn; + :} ; constructor_declarator ::= - simple_name LPAREN formal_parameter_list_opt RPAREN + simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {: + ParseNode pn=new ParseNode("constructor_declarator"); + pn.addChild("name").addChild(name); + pn.addChild("parameters").addChild(fplo); + RESULT=pn; + :} ; constructor_body ::= - LBRACE explicit_constructor_invocation - block_statements RBRACE - | LBRACE explicit_constructor_invocation RBRACE - | LBRACE block_statements RBRACE - | LBRACE RBRACE - ; -explicit_constructor_invocation ::= - THIS LPAREN argument_list_opt RPAREN SEMICOLON - | SUPER LPAREN argument_list_opt RPAREN SEMICOLON - | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON - | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON - ; +// LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE | +// LBRACE explicit_constructor_invocation RBRACE | + LBRACE block_statements:block RBRACE {: + ParseNode pn=new ParseNode("constructor_body"); + pn.addChild("block").addChild(block); + RESULT=pn; + :} + | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :} + ; +//explicit_constructor_invocation ::= +// THIS LPAREN argument_list_opt RPAREN SEMICOLON +// | SUPER LPAREN argument_list_opt RPAREN SEMICOLON +// | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON +// | primary DOT SUPER LPAREN argument_list_opt 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 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 +// ; + // 19.10) Arrays -array_initializer ::= - LBRACE variable_initializers COMMA RBRACE - | LBRACE variable_initializers RBRACE - | LBRACE COMMA RBRACE - | LBRACE RBRACE - ; -variable_initializers ::= - variable_initializer - | variable_initializers COMMA variable_initializer - ; +//array_initializer ::= +// LBRACE variable_initializers COMMA RBRACE +// | LBRACE variable_initializers RBRACE +// | LBRACE COMMA RBRACE +// | LBRACE RBRACE +// ; +//variable_initializers ::= +// variable_initializer +// | variable_initializers COMMA variable_initializer +// ; // 19.11) Blocks and Statements -block ::= LBRACE block_statements_opt RBRACE +block ::= LBRACE block_statements_opt:bso RBRACE {: + ParseNode pn=new ParseNode("block"); + pn.addChild("block_statements_opt").addChild(bso); + RESULT=pn; + :} ; block_statements_opt ::= - | block_statements + {: RESULT=new ParseNode("empty"); :} + | block_statements:bs {: + ParseNode pn=new ParseNode("block_statements_opt"); + pn.addChild("block_statements").addChild(bs); + RESULT=pn; + :} ; block_statements ::= - block_statement - | block_statements block_statement + block_statement:bs {: + ParseNode pn=new ParseNode("block_statement_list"); + pn.addChild(bs); + RESULT=pn; + :} + | block_statements:bss block_statement:bs {: + bss.addChild(bs); + RESULT=bs; + :} ; block_statement ::= - local_variable_declaration_statement - | statement - | class_declaration - | interface_declaration + local_variable_declaration_statement:lvds {: + ParseNode pn=new ParseNode("block_statement"); + pn.addChild("local_variable_declaration").addChild(lvds); + RESULT=pn; + :} + | statement:statement {: + ParseNode pn=new ParseNode("statement"); + pn.addChild("statement").addChild(statement); + RESULT=pn; + :} +// | class_declaration +// | interface_declaration ; local_variable_declaration_statement ::= - local_variable_declaration SEMICOLON + local_variable_declaration:lvd SEMICOLON {: + RESULT=lvd; + :} ; local_variable_declaration ::= - type variable_declarators - | FINAL type variable_declarators - ; -statement ::= statement_without_trailing_substatement - | labeled_statement - | if_then_statement - | if_then_else_statement - | while_statement - | for_statement + type:type variable_declarators:var_decls {: + ParseNode pn=new ParseNode("local_variable_declaration"); + pn.addChild("type").addChild(type); + pn.addChild("variables").addChild(var_decls); + RESULT=pn; +:} +// | FINAL type variable_declarators + ; +statement ::= statement_without_trailing_substatement: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; :} + | for_statement:st {: RESULT=st; :} ; statement_no_short_if ::= - statement_without_trailing_substatement - | labeled_statement_no_short_if - | if_then_else_statement_no_short_if - | while_statement_no_short_if - | for_statement_no_short_if + statement_without_trailing_substatement: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; :} ; statement_without_trailing_substatement ::= - block - | empty_statement - | expression_statement - | switch_statement - | do_statement - | break_statement - | continue_statement - | return_statement - | synchronized_statement - | throw_statement - | try_statement - | assert_statement + block:st {: RESULT=st; :} + | empty_statement:st {: RESULT=st; :} + | expression_statement:st {: RESULT=st; :} +// | switch_statement +// | do_statement + | break_statement:st {: RESULT=st; :} + | continue_statement:st {: RESULT=st; :} + | return_statement:st {: RESULT=st; :} +// | synchronized_statement +// | throw_statement +// | try_statement +// | assert_statement ; empty_statement ::= - SEMICOLON - ; -labeled_statement ::= - IDENTIFIER COLON statement - ; -labeled_statement_no_short_if ::= - IDENTIFIER COLON statement_no_short_if - ; + SEMICOLON {: RESULT=(new ParseNode("statement")).addChild("nop").getRoot(); :} + ; +//labeled_statement ::= +// IDENTIFIER COLON statement +// ; +//labeled_statement_no_short_if ::= +// IDENTIFIER COLON statement_no_short_if +// ; expression_statement ::= - statement_expression SEMICOLON + statement_expression:se SEMICOLON {: RESULT=se; :} ; statement_expression ::= - assignment - | preincrement_expression - | predecrement_expression - | postincrement_expression - | postdecrement_expression - | method_invocation - | class_instance_creation_expression + assignment:st {: RESULT=st; :} + | preincrement_expression:st {: RESULT=st; :} + | predecrement_expression:st {: RESULT=st; :} + | postincrement_expression:st {: RESULT=st; :} + | postdecrement_expression:st {: RESULT=st; :} + | method_invocation:st {: RESULT=st; :} + | class_instance_creation_expression:st {: RESULT=st; :} ; if_then_statement ::= - IF LPAREN expression RPAREN statement + IF LPAREN expression:exp RPAREN statement:st {: + ParseNode pn=new ParseNode("ifstatement"); + pn.addChild("condition").addChild(exp); + pn.addChild("statement").addChild(st); + RESULT=pn; + :} ; if_then_else_statement ::= - IF LPAREN expression RPAREN statement_no_short_if - ELSE statement + IF LPAREN expression:exp RPAREN statement_no_short_if:st + ELSE statement:else_st {: + ParseNode pn=new ParseNode("ifstatement"); + pn.addChild("condition").addChild(exp); + pn.addChild("statement").addChild(st); + pn.addChild("else_statement").addChild(else_st); + RESULT=pn; + :} ; if_then_else_statement_no_short_if ::= - IF LPAREN expression RPAREN statement_no_short_if - ELSE statement_no_short_if - ; -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 - ; + IF LPAREN expression:exp RPAREN statement_no_short_if:st + ELSE statement_no_short_if:else_st {: + ParseNode pn=new ParseNode("ifstatement"); + pn.addChild("condition").addChild(exp); + pn.addChild("statement").addChild(st); + pn.addChild("else_statement").addChild(else_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 +// ; while_statement ::= - WHILE LPAREN expression RPAREN statement + WHILE LPAREN expression:exp RPAREN statement:st {: + ParseNode pn=new ParseNode("whilestatement"); + pn.addChild("condition").addChild(exp); + pn.addChild("statement").addChild(st); + RESULT=pn; + :} ; while_statement_no_short_if ::= - WHILE LPAREN expression RPAREN statement_no_short_if - ; -do_statement ::= - DO statement WHILE LPAREN expression RPAREN SEMICOLON - ; + WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {: + ParseNode pn=new ParseNode("whilestatement"); + pn.addChild("condition").addChild(exp); + pn.addChild("statement").addChild(st); + RESULT=pn; + :} + ; +//do_statement ::= +// DO statement WHILE LPAREN expression RPAREN SEMICOLON +// ; for_statement ::= - FOR LPAREN for_init_opt SEMICOLON expression_opt SEMICOLON - for_update_opt RPAREN statement + FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON + for_update_opt:update RPAREN statement:st {: + ParseNode pn=new ParseNode("forstatement"); + pn.addChild("initializer").addChild(init); + pn.addChild("condition").addChild(exp); + pn.addChild("update").addChild(update); + pn.addChild("statement").addChild(st); + RESULT=pn; + :} ; for_statement_no_short_if ::= - FOR LPAREN for_init_opt SEMICOLON expression_opt SEMICOLON - for_update_opt RPAREN statement_no_short_if + FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON + for_update_opt:update RPAREN statement_no_short_if:st {: + ParseNode pn=new ParseNode("forstatement"); + pn.addChild("initializer").addChild(init); + pn.addChild("condition").addChild(exp); + pn.addChild("update").addChild(update); + pn.addChild("statement").addChild(st); + RESULT=pn; + :} ; for_init_opt ::= - | for_init + {: RESULT=new ParseNode("empty"); :} + | for_init:init {: RESULT=init; :} ; -for_init ::= statement_expression_list - | local_variable_declaration +for_init ::= statement_expression_list:list {: RESULT=list; :} + | local_variable_declaration:decl {: RESULT=decl; :} ; for_update_opt ::= - | for_update + {: RESULT=new ParseNode("empty"); :} + | for_update:update {: RESULT=update; :} ; -for_update ::= statement_expression_list +for_update ::= statement_expression_list:list {: RESULT=list; :} ; statement_expression_list ::= - statement_expression - | statement_expression_list COMMA statement_expression + statement_expression:expr {: + RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot(); + :} + | statement_expression_list:list COMMA statement_expression:expr {: + list.addChild(expr); + RESULT=list; + :} ; -identifier_opt ::= - | IDENTIFIER - ; +//identifier_opt ::= +// | IDENTIFIER +// ; break_statement ::= - BREAK identifier_opt SEMICOLON + BREAK +//identifier_opt +SEMICOLON {: RESULT=new ParseNode("break"); :} ; continue_statement ::= - CONTINUE identifier_opt SEMICOLON + CONTINUE +//identifier_opt +SEMICOLON +{: RESULT=new ParseNode("continue"); :} ; return_statement ::= - RETURN expression_opt SEMICOLON - ; -throw_statement ::= - THROW expression SEMICOLON - ; -synchronized_statement ::= - SYNCHRONIZED LPAREN expression RPAREN block - ; -try_statement ::= - TRY block catches - | TRY block catches_opt finally - ; -catches_opt ::= - | catches - ; -catches ::= catch_clause - | catches catch_clause - ; -catch_clause ::= - CATCH LPAREN formal_parameter RPAREN block - ; -finally ::= FINALLY block - ; -assert_statement ::= - ASSERT expression SEMICOLON - | ASSERT expression COLON expression SEMICOLON - ; + RETURN expression_opt:exp SEMICOLON {: + RESULT=(new ParseNode("return")).addChild("retvalue").addChild(exp).getRoot(); :} + ; +//throw_statement ::= +// THROW expression SEMICOLON +// ; +//synchronized_statement ::= +// SYNCHRONIZED LPAREN expression RPAREN block +// ; +//try_statement ::= +// TRY block catches +// | TRY block catches_opt finally +// ; +//catches_opt ::= +// | catches +// ; +//catches ::= catch_clause +// | catches catch_clause +// ; +//catch_clause ::= +// CATCH LPAREN formal_parameter RPAREN block +// ; +//finally ::= FINALLY block +// ; +//assert_statement ::= +// ASSERT expression SEMICOLON +// | ASSERT expression COLON expression SEMICOLON +// ; // 19.12) Expressions -primary ::= primary_no_new_array - | array_creation_init - | array_creation_uninit +primary ::= primary_no_new_array:st {: + RESULT=st; :} +// | array_creation_init +// | array_creation_uninit ; primary_no_new_array ::= - literal - | THIS - | LPAREN expression RPAREN - | class_instance_creation_expression - | field_access - | method_invocation - | array_access - | primitive_type DOT CLASS - | VOID DOT CLASS - | array_type DOT CLASS - | name DOT CLASS - | name DOT THIS + literal:lit {: RESULT=lit; :} + | THIS {: RESULT=new ParseNode("this"); :} + | LPAREN expression:exp RPAREN {: RESULT=exp; :} + | class_instance_creation_expression:exp {: RESULT=exp; :} + | field_access:exp {: RESULT=exp; :} + | method_invocation:exp {: RESULT=exp; :} +// | array_access +// | primitive_type DOT CLASS +// | VOID DOT CLASS +// | array_type DOT CLASS +// | name DOT CLASS +// | name DOT THIS ; class_instance_creation_expression ::= - NEW class_or_interface_type LPAREN argument_list_opt RPAREN - | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body - | primary DOT NEW IDENTIFIER - LPAREN argument_list_opt RPAREN - | primary DOT NEW IDENTIFIER - LPAREN argument_list_opt RPAREN class_body - | name DOT NEW IDENTIFIER - LPAREN argument_list_opt RPAREN - | name DOT NEW IDENTIFIER - LPAREN argument_list_opt RPAREN class_body + NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: + ParseNode pn=new ParseNode("createobject"); + pn.addChild("type").addChild(type); + pn.addChild("args").addChild(args); + RESULT=pn; + :} +// | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body +// | primary DOT NEW IDENTIFIER +// LPAREN argument_list_opt RPAREN {: +// +// :} +// | primary DOT NEW IDENTIFIER +// LPAREN argument_list_opt RPAREN class_body +// | name DOT NEW IDENTIFIER +// LPAREN argument_list_opt RPAREN +// | name DOT NEW IDENTIFIER +// LPAREN argument_list_opt RPAREN class_body ; argument_list_opt ::= - | argument_list + {: RESULT=new ParseNode("empty"); :} + | argument_list:args {: RESULT=args; :} ; argument_list ::= - expression - | argument_list COMMA expression - ; -array_creation_uninit ::= - NEW primitive_type dim_exprs dims_opt - | NEW class_or_interface_type dim_exprs dims_opt - ; -array_creation_init ::= - NEW primitive_type dims array_initializer - | NEW class_or_interface_type dims array_initializer - ; -dim_exprs ::= dim_expr - | dim_exprs dim_expr - ; -dim_expr ::= LBRACK expression RBRACK - ; -dims_opt ::= - | dims - ; -dims ::= LBRACK RBRACK - | dims LBRACK RBRACK - ; + expression:exp {: + ParseNode pn=new ParseNode("argument_list"); + pn.addChild(exp); + RESULT=pn; + :} + | argument_list:list COMMA expression:exp {: + list.addChild(exp); + RESULT=list; + :} + ; +//array_creation_uninit ::= +// NEW primitive_type dim_exprs dims_opt +// | NEW class_or_interface_type dim_exprs dims_opt +// ; +//array_creation_init ::= +// NEW primitive_type dims array_initializer +// | NEW class_or_interface_type dims array_initializer +// ; +//dim_exprs ::= dim_expr +// | dim_exprs dim_expr +// ; +//dim_expr ::= LBRACK expression RBRACK +// ; +//dims_opt ::= +// | dims +// ; +//dims ::= LBRACK RBRACK +// | dims LBRACK RBRACK +// ; field_access ::= - primary DOT IDENTIFIER - | SUPER DOT IDENTIFIER - | name DOT SUPER DOT IDENTIFIER + primary:base DOT IDENTIFIER:id {: + ParseNode pn=new ParseNode("fieldaccess"); + pn.addChild("base").addChild(base); + pn.addChild("field").addChild(id); + RESULT=pn; +:} +// | SUPER DOT IDENTIFIER +// | name DOT SUPER DOT IDENTIFIER ; method_invocation ::= - name LPAREN argument_list_opt RPAREN - | primary DOT IDENTIFIER LPAREN argument_list_opt RPAREN - | SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN - | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN - ; -array_access ::= - name LBRACK expression RBRACK - | primary_no_new_array LBRACK expression RBRACK - | array_creation_init LBRACK expression RBRACK - ; + name:name LPAREN argument_list_opt:args RPAREN {: + ParseNode pn=new ParseNode("methodinvoke"); + pn.addChild("name").addChild(name); + pn.addChild("args").addChild(args); + RESULT=pn; + :} + | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {: + ParseNode pn=new ParseNode("methodinvoke"); + pn.addChild("base").addChild(base); + pn.addChild("name").addChild(name); + pn.addChild("args").addChild(args); + RESULT=pn; + :} +// | SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN +// | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN + ; +//array_access ::= +// name LBRACK expression RBRACK +// | primary_no_new_array LBRACK expression RBRACK +// | array_creation_init LBRACK expression RBRACK +// ; postfix_expression ::= - primary - | name - | postincrement_expression - | postdecrement_expression + primary:exp {: + RESULT=exp; :} + | name:exp {: RESULT=exp; :} + | postincrement_expression:exp {: RESULT=exp; :} + | postdecrement_expression:exp {: RESULT=exp; :} ; postincrement_expression ::= - postfix_expression PLUSPLUS + postfix_expression:exp PLUSPLUS + {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :} ; postdecrement_expression ::= - postfix_expression MINUSMINUS + postfix_expression:exp MINUSMINUS + {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :} ; unary_expression ::= - preincrement_expression - | predecrement_expression - | PLUS unary_expression - | MINUS unary_expression - | unary_expression_not_plus_minus + preincrement_expression:exp {: RESULT=exp; :} + | predecrement_expression:exp {: RESULT=exp; :} + | PLUS unary_expression:exp + {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :} + | MINUS unary_expression:exp + {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :} + | unary_expression_not_plus_minus:exp {: + RESULT=exp; :} ; preincrement_expression ::= - PLUSPLUS unary_expression + PLUSPLUS unary_expression:exp + {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :} ; predecrement_expression ::= - MINUSMINUS unary_expression + MINUSMINUS unary_expression:exp + {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :} ; unary_expression_not_plus_minus ::= - postfix_expression - | COMP unary_expression - | NOT unary_expression - | cast_expression + postfix_expression:exp {: + RESULT=exp; :} +// | COMP unary_expression + | NOT unary_expression:exp + {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :} + | cast_expression:exp {: RESULT=exp; :} ; cast_expression ::= - LPAREN primitive_type dims_opt RPAREN unary_expression - | LPAREN expression RPAREN unary_expression_not_plus_minus - | LPAREN name dims RPAREN unary_expression_not_plus_minus + LPAREN primitive_type:type + //dims_opt + RPAREN unary_expression:exp {: + ParseNode pn=new ParseNode("cast"); + pn.addChild("type").addChild(type); + pn.addChild("exp").addChild(exp); + RESULT=pn; + :} + | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {: + ParseNode pn=new ParseNode("cast"); + pn.addChild("type").addChild(type); + pn.addChild("exp").addChild(exp); + RESULT=pn; + + :} +// | LPAREN name dims RPAREN unary_expression_not_plus_minus ; multiplicative_expression ::= - unary_expression - | multiplicative_expression MULT unary_expression - | multiplicative_expression DIV unary_expression - | multiplicative_expression MOD unary_expression + unary_expression:exp {: + RESULT=exp; :} + | multiplicative_expression:exp1 MULT unary_expression:exp2 {: + ParseNode pn=new ParseNode("mult"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} + | multiplicative_expression:exp1 DIV unary_expression:exp2 {: + ParseNode pn=new ParseNode("div"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} + | multiplicative_expression:exp1 MOD unary_expression:exp2 {: + ParseNode pn=new ParseNode("mod"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} ; additive_expression ::= - multiplicative_expression - | additive_expression PLUS multiplicative_expression - | additive_expression MINUS multiplicative_expression + multiplicative_expression:exp {: + RESULT=exp; :} + | additive_expression:exp1 PLUS multiplicative_expression:exp2 {: + ParseNode pn=new ParseNode("add"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} + | additive_expression:exp1 MINUS multiplicative_expression:exp2 {: + ParseNode pn=new ParseNode("sub"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} ; shift_expression ::= - additive_expression - | shift_expression LSHIFT additive_expression - | shift_expression RSHIFT additive_expression - | shift_expression URSHIFT additive_expression + additive_expression:exp {: + RESULT=exp; :} + | shift_expression:exp1 LSHIFT additive_expression:exp2 {: + ParseNode pn=new ParseNode("leftshift"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} + | shift_expression:exp1 RSHIFT additive_expression:exp2 {: + ParseNode pn=new ParseNode("rightshift"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} +// | shift_expression URSHIFT additive_expression ; relational_expression ::= - shift_expression - | relational_expression LT shift_expression - | relational_expression GT shift_expression - | relational_expression LTEQ shift_expression - | relational_expression GTEQ shift_expression - | relational_expression INSTANCEOF reference_type + shift_expression:exp {: + RESULT=exp; :} + | relational_expression:exp1 LT shift_expression:exp2 {: + ParseNode pn=new ParseNode("comp_lt"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} + | relational_expression:exp1 GT shift_expression:exp2 {: + ParseNode pn=new ParseNode("comp_gt"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} + | relational_expression:exp1 LTEQ shift_expression:exp2 {: + ParseNode pn=new ParseNode("comp_lte"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} + | relational_expression:exp1 GTEQ shift_expression:exp2 {: + ParseNode pn=new ParseNode("comp_gte"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} +// | relational_expression INSTANCEOF reference_type ; + equality_expression ::= - relational_expression - | equality_expression EQEQ relational_expression - | equality_expression NOTEQ relational_expression + relational_expression:exp {: + RESULT=exp; :} + | equality_expression:exp1 EQEQ relational_expression:exp2 {: + ParseNode pn=new ParseNode("equal"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} + | equality_expression:exp1 NOTEQ relational_expression:exp2 {: + ParseNode pn=new ParseNode("not_equal"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} ; and_expression ::= - equality_expression - | and_expression AND equality_expression + equality_expression:exp {: + RESULT=exp; :} + | and_expression:exp1 AND equality_expression:exp2 {: + ParseNode pn=new ParseNode("bitwise_and"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} ; exclusive_or_expression ::= - and_expression - | exclusive_or_expression XOR and_expression + and_expression:expr {: + RESULT=expr; + :} + | exclusive_or_expression:exp1 XOR and_expression:exp2 {: + ParseNode pn=new ParseNode("bitwise_xor"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; +:} ; inclusive_or_expression ::= - exclusive_or_expression - | inclusive_or_expression OR exclusive_or_expression + exclusive_or_expression:exclor {: + RESULT=exclor; :} + | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {: + ParseNode pn=new ParseNode("bitwise_or"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} ; conditional_and_expression ::= - inclusive_or_expression - | conditional_and_expression ANDAND inclusive_or_expression + inclusive_or_expression:inclor {: + RESULT=inclor; :} + | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {: + ParseNode pn=new ParseNode("logical_and"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} ; conditional_or_expression ::= - conditional_and_expression - | conditional_or_expression OROR conditional_and_expression + conditional_and_expression:condand {: + RESULT=condand; :} + | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {: + ParseNode pn=new ParseNode("logical_or"); + pn.addChild(exp1); + pn.addChild(exp2); + RESULT=pn; + :} ; conditional_expression ::= - conditional_or_expression - | conditional_or_expression QUESTION expression - COLON conditional_expression + conditional_or_expression:condor {: + RESULT=condor; :} +// | conditional_or_expression QUESTION expression +// COLON conditional_expression ; assignment_expression ::= - conditional_expression - | assignment + conditional_expression:expr {: + RESULT=expr; :} | + assignment:assign {: + RESULT=assign; :} ; // semantic check necessary here to ensure a valid left-hand side. // allowing a parenthesized variable here on the lhs was introduced in // JLS 2; thanks to Eric Blake for pointing this out. -assignment ::= postfix_expression assignment_operator assignment_expression +assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {: + ParseNode pn=new ParseNode("assignment"); + pn.addChild("op").addChild(op); + ParseNode pnargs=pn.addChild("args"); + pnargs.addChild(lvalue); + pnargs.addChild(rvalue); + RESULT=pn; + :} ; assignment_operator ::= - EQ - | MULTEQ - | DIVEQ - | MODEQ - | PLUSEQ - | MINUSEQ - | LSHIFTEQ - | RSHIFTEQ - | URSHIFTEQ - | ANDEQ - | XOREQ - | OREQ + EQ {: RESULT=(new ParseNode("assignment_operator")).addChild("eq"); :} + | MULTEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("multeq"); :} + | DIVEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("diveq"); :} + | MODEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("modeq"); :} + | PLUSEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("pluseq"); :} + | MINUSEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("minuseq"); :} + | LSHIFTEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("lshifteq"); :} + | RSHIFTEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("rshifteq"); :} +// | URSHIFTEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("urshifteq"); :} + | ANDEQ {: RESULT=(new ParseNode("assignment_operator")).addChild("andeq"); :} + | XOREQ {: RESULT=(new ParseNode("assignment_operator")).addChild("xoreq"); :} + | OREQ {: RESULT=(new ParseNode("assignment_operator")).addChild("oreq"); :} ; expression_opt ::= - | expression - ; -expression ::= assignment_expression + {: RESULT=new ParseNode("empty"); :} + | expression:exp {: + RESULT=exp; :} ; -constant_expression ::= - expression +expression ::= assignment_expression:exp {: + RESULT=exp; :} ; +//constant_expression ::= +// expression +// ; -- 2.34.1