Mini Java编译器(二)
2008-01-05 09:16:03 来源:WEB开发网核心提示:二、Mini java的文法BNFGoal ::= MainClass ( TypeDeclaration )* <EOF> MainClass ::= "class" Identifier "{" "public" "static&qu
二、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
更多精彩
赞助商链接