|
|
ExtendedStaticJava Project Your job is to extend StaticJava to have the following additional features:
Note: Highlighted non-terminals are new or modified (wrt. StaticJava concrete syntax) <program> ::= <simple-class-declaration>* <class-declaration> <simple-class-declaration>* <simple-class-declaration> ::= "class" ID "{" <public-field-declaration>* "}" <public-field-declaration> ::= "public" <type> ID ";" <class-declaration> ::= "public" "class" ID "{" <main-method-declaration> <field-or-method-declaration>* "}" <main-method-declaration> ::= "public" "static" "void" "main" "(" "String" "[" "]" ID ")" "{" <method-body> "}" <field-or-method-declaration> ::= <field-declaration> | <method-declaration> <field-declaration> ::= "static" <type> ID ";" <method-declaration> ::= "static" <return-type> ID "(" <params>? ")" "{" <method-body> "}" <type> ::= ( <basic-type> | ID ) ( "[" "]" )? <basic-type> ::= "boolean" | "int" <return-type> ::= <type> | "void" <params> ::= <param> ( "," <param> )* <param> ::= <type> ID <method-body> ::= <local-declaration>* <statement>* <local-declaration> ::= <type> ID ";" <statement> ::= <assign-statement> | <if-statement> | <while-statement> | <invoke-exp-statement> | <return-statement> | <for-statement> | <do-while-statement> | <inc-dec-statement> <assign-statement> ::= <assign> ";" <assign> ::= <lhs> "=" <exp> <lhs> ::= ID | <exp> "." ID | <exp> "[" <exp> "]" <if-statement> ::= "if" "(" <exp> ")" "{" <statement>* "}" ( "else" "{" <statement>* "}" )? <while-statement> ::= "while" "(" <exp> ")" "{" <statement>* "}" <invoke-exp-statement> ::= <invoke-exp> ";" <return-statement> ::= "return" <exp> ";" <for-statement> ::= "for" "(" <for-inits>? ";" <exp>? ";" <for-updates>? ")" "{" <statement>* "}" <for-inits> ::= <assign> ( "," <assign> )* <for-updates> ::= <inc-dec> ( "," <inc-dec> )* <inc-dec> ::= <lhs> "++" | <lhs> "--" <do-while-statement> ::= "do" "{" <statement>* "}" "while" "(" <exp> ")" ";" <inc-dec-statement> ::= <inc-dec> ";" <exp> ::= <literal-exp> | <unary-exp> | <binary-exp> | <paren-exp> | <invoke-exp> | <var-ref> | <new-exp> | <array-access-exp> | <field-access-exp> | <cond-exp> <literal-exp> ::= <boolean-literal> | NUM | "null" <boolean-literal> ::= "true" | "false" <unary-exp> ::= <unary-op> <exp> <unary-op> ::= "+" | "-" | "!" | "~" <binary-exp> ::= <exp> <binary-op> <exp> <binary-op> ::= "+" | "-" | "*" | "/" | "%" | ">" | ">=" | "==" | "<" | "<=" | "!=" | "&&" | "||" | "<<" | ">>" | ">>>" <paren-exp> ::= "(" <exp> ")" <invoke-exp> ::= ( ID "." )? ID "(" <args>? ")" <args> ::= <exp> ( "," <exp> )* <var-ref> ::= ID <cond-exp> ::= <exp> "?" <exp> ":" <exp> <new-exp> ::= "new" ID "(" ")" | "new" <type> "[" <exp> "]" | "new" <type> "[" "]" <array-init> <array-init> ::= "{" <exp> ( "," <exp> )* "}" <field-access-exp> ::= <exp> "." ID <array-access-exp> ::= <exp> "[" <exp> "]" ID = ( 'a'..'z' | 'A'..'Z' | '_' | '$' ) ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' | '$' )* NUM = '0' | ('1'..'9') ('0'..'9')*
TBD |