Mini Java编译器(二)__教程 |
|
日期:2007-5-20 1:28:18 人气:115 [大 中 小] |
|
|
|
二、Mini Java的文法 BNF Goal
::=
MainClass ( TypeDeclaration )*
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
::=
Type Identifier ";"
MethodDeclaration
::=
"public" Type Identifier "(" ( FormalParameterList )? ")" "{" ( VarDeclaration )* ( Statement )* "return" Expression ";" "}"
FormalParameterList
::=
FormalParameter ( FormalParameterRest )*
FormalParameter
::=
Type Identifier
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 |
|
出处:本站原创 作者:佚名 |
|
|