|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
JAVA是一种可以撰写跨平台应用软件的面向对象的程序设计语言,由升阳(SunMicrosystems)公司的詹姆斯·高斯林(JamesGosling)等人于1990年代初开发。编译2、MiniJava的文法
BNF
Goal
::=
MainClass(TypeDeclaration)*<EOF>
MainClass
::=
"class"Identifier"{""public""static""void""main""(""String""[""]"Identifier")""{"PrintStatement"}""}"
TypeDeclaration
::=
ClassDeclaration
|
ClassExtendsDeclaration
ClassDeclaration
::=
"class"Identifier"{"(VarDeclaration)*(MethodDeclaration)*"}"
ClassExtendsDeclaration
::=
"class"Identifier"extends"Identifier"{"(VarDeclaration)*(MethodDeclaration)*"}"
VarDeclaration
::=
TypeIdentifier";"
MethodDeclaration
::=
"public"TypeIdentifier"("(FormalParameterList)?")""{"(VarDeclaration)*(Statement)*"return"Expression";""}"
FormalParameterList
::=
FormalParameter(FormalParameterRest)*
FormalParameter
::=
TypeIdentifier
FormalParameterRest
::=
","FormalParameter
Type
::=
ArrayType
|
BooleanType
|
IntegerType
|
Identifier
ArrayType
::=
"int""[""]"
BooleanType
::=
"boolean"
IntegerType
::=
"int"
Statement
::=
Block
|
AssignmentStatement
|
ArrayAssignmentStatement
|
IfStatement
|
WhileStatement
|
PrintStatement
Block
::=
"{"(Statement)*"}"
AssignmentStatement
::=
Identifier"="Expression";"
ArrayAssignmentStatement
::=
Identifier"["Expression"]""="Expression";"
IfStatement
::=
"if""("Expression")"Statement"else"Statement
WhileStatement
::=
"while""("Expression")"Statement
PrintStatement
::=
"System.out.println""("Expression")"";"
Expression
::=
AndExpression
|
CompareExpression
|
PlusExpression
|
MinusExpression
|
TimesExpression
|
ArrayLookup
|
ArrayLength
|
MessageSend
|
PrimaryExpression
AndExpression
::=
PrimaryExpression"&&"PrimaryExpression
CompareExpression
::=
PrimaryExpression"<"PrimaryExpression
PlusExpression
::=
PrimaryExpression"+"PrimaryExpression
MinusExpression
::=
PrimaryExpression"-"PrimaryExpression
TimesExpression
::=
PrimaryExpression"*"PrimaryExpression
ArrayLookup
::=
PrimaryExpression"["PrimaryExpression"]"
ArrayLength
::=
PrimaryExpression".""length"
MessageSend
::=
PrimaryExpression"."Identifier"("(ExpressionList)?")"
ExpressionList
::=
Expression(ExpressionRest)*
ExpressionRest
::=
","Expression
PrimaryExpression
::=
IntegerLiteral
|
TrueLiteral
|
FalseLiteral
|
Identifier
|
ThisExpression
|
ArrayAllocationExpression
|
AllocationExpression
|
NotExpression
|
BracketExpression
IntegerLiteral
::=
<INTEGER_LITERAL>
TrueLiteral
::=
"true"
FalseLiteral
::=
"false"
Identifier
::=
<IDENTIFIER>
ThisExpression
::=
"this"
ArrayAllocationExpression
::=
"new""int""["Expression"]"
AllocationExpression
::=
"new"Identifier"("")"
NotExpression
::=
"!"Expression
BracketExpression
::=
"("Expression")"
先谈谈我对java的一些认识。我选择java,是因为他语法简单,功能强大,从web,到桌面,到嵌入式,无所不能。但当我进一步了解了java后,感叹,java原来也有许多缺点。 |
|