二、Mini Java的文法
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
::=
Type Identifier ";"
MethodDeclaration
::=
"public" Type Identifier "(" ( FormalParameterList )? ")" "{" ( VarDeclaration )* ( Statement )* "return" EXPression ";" "}"
FormalParameterList
::=
FormalParameter ( FormalParameterRest )*
FormalParameter
::=
Type Identifier
FormalParameterRest
::=
"," FormalParameter
Type
::=
ArrayType
BooleanType