java bnf_BNF rules of JAVA

BNF rules of JAVA

compilation_unit =

[ package_statement ]

< import_statement >

< type_declaration > .

package_statement =

"package" package_name ";" .

import_statement =

"import" ( ( package_name "." "*" ";" )

/ ( class_name / interface_name ) ) ";" .

type_declaration =

[ doc_comment ] ( class_declaration / interface_declaration ) ";" .

doc_comment = "/**" "... text ..." "*/" .

class_declaration =

< modifier > "class" identifier

[ "extends" class_name ]

[ "implements" interface_name < "," interface_name > ]

"{" < field_declaration > "}" .

interface_declaration =

< modifier > "interface" identifier

[ "extends" interface_name < "," interface_name > ]

"{" < field_declaration > "}" .

field_declaration =

( [ doc_comment ] ( method_declaration

/ constructor_declaration

/ variable_declaration ) )

/ static_initializer

/ ";" .

method_declaration =

< modifier > type identifier

"(" [ parameter_list ] ")" < "[" "]" >

( statement_block / ";" ) .

constructor_declaration =

< modifier > identifier "(" [ parameter_list ] ")"

statement_block .

statement_block = "{" < statement > "}" .

variable_declaration =

< modifier > type variable_declarator

< "," variable_declarator > ";" .

variable_declarator =

identifier < "[" "]" > [ "=" variable_initializer ] .

variable_initializer =

expression

/ ( "{" [ variable_initializer

< "," variable_initializer > [ "," ] ] "}" ) .

static_initializer =

"static" statement_block .

parameter_list =

parameter < "," parameter > .

parameter =

type identifier < "[" "]" > .

statement =

variable_declaration

/ ( expression ";" )

/ ( statement_block )

/ ( if_statement )

/ ( do_statement )

/ ( while_statement )

/ ( for_statement )

/ ( try_statement )

/ ( switch_statement )

/ ( "synchronized" "(" expression ")" statement )

/ ( "return" [ expression ] ";" )

/ ( "throw" expression ";" )

/ ( identifier ":" statement )

/ ( "break" [ identifier ] ";" )

/ ( "continue" [ identifier ] ";" )

/ ( ";" ) .

if_statement =

"if" "(" expression ")" statement

[ "else" statement ] .

do_statement =

"do" statement "while" "(" expression ")" ";" .

while_statement =

"while" "(" expression ")" statement .

for_statement =

"for" "(" ( variable_declaration / ( expression ";" ) / ";" )

[ expression ] ";"

[ expression ] ";"

")" statement .

try_statement =

"try" statement

< "catch" "(" parameter ")" statement >

[ "finally" statement ] .

switch_statement =

"switch" "(" expression ")" "{"

< ( "case" expression ":" )

/ ( "default" ":" )

/ statement >

"}" .

expression =

numeric_expression

/ testing_expression

/ logical_expression

/ string_expression

/ bit_expression

/ casting_expression

/ creating_expression

/ literal_expression

/ "null"

/ "super"

/ "this"

/ identifier

/ ( "(" expression ")" )

/ ( expression

( ( "(" [ arglist ] ")" )

/ ( "[" expression "]" )

/ ( "." expression )

/ ( "," expression )

/ ( "instanceof" ( class_name / interface_name ) )

) ) .

numeric_expression =

( ( "-"

/ "++"

/ "--" )

expression )

/ ( expression

( "++"

/ "--" ) )

/ ( expression

( "+"

/ "+="

/ "-"

/ "-="

/ "*"

/ "*="

/ "/"

/ "/="

/ "%"

/ "%=" )

expression ) .

testing_expression =

( expression

( ">"

/ "

/ ">="

/ "<="

/ "=="

/ "!=" )

expression ) .

logical_expression =

( "!" expression )

/ ( expression

( "ampersand"

/ "ampersand="

/ "|"

/ "|="

/ "^"

/ "^="

/ ( "ampersand" "ampersand" )

/ "||="

/ "%"

/ "%=" )

expression )

/ ( expression "?" expression ":" expression )

/ "true"

/ "false" .

string_expression = ( expression

( "+"

/ "+=" )

expression ) .

bit_expression =

( "~" expression )

/ ( expression

( ">>="

/ "<

/ ">>"

/ ">>>" )

expression ) .

casting_expression =

"(" type ")" expression .

creating_expression =

"new" ( ( classe_name "(" [ arglist ] ")" )

/ ( type_specifier [ "[" expression "]" ] < "[" "]" > )

/ ( "(" expression ")" ) ) .

literal_expression =

integer_literal

/ float_literal

/ string

/ character .

arglist =

expression < "," expression > .

type =

type_specifier < "[" "]" > .

type_specifier =

"boolean"

/ "byte"

/ "char"

/ "short"

/ "int"

/ "float"

/ "long"

/ "double"

/ class_name

/ interface_name .

modifier =

"public"

/ "private"

/ "protected"

/ "static"

/ "final"

/ "native"

/ "synchronized"

/ "abstract"

/ "threadsafe"

/ "transient" .

package_name =

identifier

/ ( package_name "." identifier ) .

class_name =

identifier

/ ( package_name "." identifier ) .

interface_name =

identifier

/ ( package_name "." identifier ) .

integer_literal =

( ( "1..9" < "0..9" > )

/ < "0..7" >

/ ( "0" "x" "0..9a..f" < "0..9a..f" > ) )

[ "l" ] .

float_literal =

( decimal_digits "." [ decimal_digits ] [ exponent_part ] [ float_type_suffix ] )

/ ( "." decimal_digits [ exponent_part ] [ float_type_suffix ] )

/ ( decimal_digits [ exponent_part ] [ float_type_suffix ] ) .

decimal_digits =

"0..9" < "0..9" > .

exponent_part =

"e" [ "+" / "-" ] decimal_digits .

float_type_suffix =

"f" / "d" .

character =

"based on the unicode character set" .

string =

"''" < character > "''" .

identifier =

"a..z,$,_" < "a..z,$,_,0..9,unicode character over 00C0" > .

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值