BNF for Java1.1.jj
NON-TERMINALS
CompilationUnit
::=
(
PackageDeclaration
)? (
ImportDeclaration
)* (
TypeDeclaration
)* <EOF>
PackageDeclaration
::=
"package"
Name
";"
ImportDeclaration
::=
"import"
Name
( "." "*" )? ";"
TypeDeclaration
::=
ClassDeclaration
|
InterfaceDeclaration
|
";"
ClassDeclaration
::=
( "abstract" | "final" | "public" )*
UnmodifiedClassDeclaration
UnmodifiedClassDeclaration
::=
"class" <IDENTIFIER> ( "extends"
Name
)? ( "implements"
NameList
)?
ClassBody
ClassBody
::=
"{" (
ClassBodyDeclaration
)* "}"
NestedClassDeclaration
::=
( "static" | "abstract" | "final" | "public" | "protected" | "private" )*
UnmodifiedClassDeclaration
ClassBodyDeclaration
::=
Initializer
|
NestedClassDeclaration
|
NestedInterfaceDeclaration
|
ConstructorDeclaration
|
MethodDeclaration
|
FieldDeclaration
MethodDeclarationLookahead
::=
( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )*
ResultType
<IDENTIFIER> "("
InterfaceDeclaration
::=
( "abstract" | "public" )*
UnmodifiedInterfaceDeclaration
NestedInterfaceDeclaration
::=
( "static" | "abstract" | "final" | "public" | "protected" | "private" )*
UnmodifiedInterfaceDeclaration
UnmodifiedInterfaceDeclaration
::=
"interface" <IDENTIFIER> ( "extends"
NameList
)? "{" (
InterfaceMemberDeclaration
)* "}"
InterfaceMemberDeclaration
::=
NestedClassDeclaration
|
NestedInterfaceDeclaration
|
MethodDeclaration
|
FieldDeclaration
FieldDeclaration
::=
( "public" | "protected" | "private" | "static" | "final" | "transient" | "volatile" )*
Type
VariableDeclarator
( ","
VariableDeclarator
)* ";"
VariableDeclarator
::=
VariableDeclaratorId
( "="
VariableInitializer
)?
VariableDeclaratorId
::=
<IDENTIFIER> ( "[" "]" )*
VariableInitializer
::=
ArrayInitializer
|
Expression
ArrayInitializer
::=
"{" (
VariableInitializer
( ","
VariableInitializer
)* )? ( "," )? "}"
MethodDeclaration
::=
( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )*
ResultType
MethodDeclarator
( "throws"
NameList
)? (
Block
| ";" )
MethodDeclarator
::=
<IDENTIFIER>
FormalParameters
( "[" "]" )*
FormalParameters
::=
"(" (
FormalParameter
( ","
FormalParameter
)* )? ")"
FormalParameter
::=
( "final" )?
Type
VariableDeclaratorId
ConstructorDeclaration
::=
( "public" | "protected" | "private" )? <IDENTIFIER>
FormalParameters
( "throws"
NameList
)? "{" (
ExplicitConstructorInvocation
)? (
BlockStatement
)* "}"
ExplicitConstructorInvocation
::=
"this"
Arguments
";"
|
(
PrimaryExpression
"." )? "super"
Arguments
";"
Initializer
::=
( "static" )?
Block
Type
::=
(
PrimitiveType
|
Name
) ( "[" "]" )*
PrimitiveType
::=
"boolean"
|
"char"
|
"byte"
|
"short"
|
"int"
|
"long"
|
"float"
|
"double"
ResultType
::=
"void"
|
Type
Name
::=
<IDENTIFIER> ( "." <IDENTIFIER> )*
NameList
::=
Name
( ","
Name
)*
Expression
::=
ConditionalExpression
(
AssignmentOperator
Expression
)?
AssignmentOperator
::=
"="
|
"*="
|
"/="
|
"%="
|
"+="
|
"-="
|
"<<="
|
">>="
|
">>>="
|
"&="
|
"^="
|
"|="
ConditionalExpression
::=
ConditionalOrExpression
( "?"
Expression
":"
ConditionalExpression
)?
ConditionalOrExpression
::=
ConditionalAndExpression
( "||"
ConditionalAndExpression
)*
ConditionalAndExpression
::=
InclusiveOrExpression
( "&&"
InclusiveOrExpression
)*
InclusiveOrExpression
::=
ExclusiveOrExpression
( "|"
ExclusiveOrExpression
)*
ExclusiveOrExpression
::=
AndExpression
( "^"
AndExpression
)*
AndExpression
::=
EqualityExpression
( "&"
EqualityExpression
)*
EqualityExpression
::=
InstanceOfExpression
( ( "==" | "!=" )
InstanceOfExpression
)*
InstanceOfExpression
::=
RelationalExpression
( "instanceof"
Type
)?
RelationalExpression
::=
ShiftExpression
( ( "<" | ">" | "<=" | ">=" )
ShiftExpression
)*
ShiftExpression
::=
AdditiveExpression
( ( "<<" | ">>" | ">>>" )
AdditiveExpression
)*
AdditiveExpression
::=
MultiplicativeExpression
( ( "+" | "-" )
MultiplicativeExpression
)*
MultiplicativeExpression
::=
UnaryExpression
( ( "*" | "/" | "%" )
UnaryExpression
)*
UnaryExpression
::=
( "+" | "-" )
UnaryExpression
|
PreIncrementExpression
|
PreDecrementExpression
|
UnaryExpressionNotPlusMinus
PreIncrementExpression
::=
"++"
PrimaryExpression
PreDecrementExpression
::=
"--"
PrimaryExpression
UnaryExpressionNotPlusMinus
::=
( "~" | "!" )
UnaryExpression
|
CastExpression
|
PostfixExpression
CastLookahead
::=
"("
PrimitiveType
|
"("
Name
"[" "]"
|
"("
Name
")" ( "~" | "!" | "(" | <IDENTIFIER> | "this" | "super" | "new" |
Literal
)
PostfixExpression
::=
PrimaryExpression
( "++" | "--" )?
CastExpression
::=
"("
Type
")"
UnaryExpression
|
"("
Type
")"
UnaryExpressionNotPlusMinus
PrimaryExpression
::=
PrimaryPrefix
(
PrimarySuffix
)*
PrimaryPrefix
::=
Literal
|
"this"
|
"super" "." <IDENTIFIER>
|
"("
Expression
")"
|
AllocationExpression
|
ResultType
"." "class"
|
Name
PrimarySuffix
::=
"." "this"
|
"."
AllocationExpression
|
"["
Expression
"]"
|
"." <IDENTIFIER>
|
Arguments
Literal
::=
<INTEGER_LITERAL>
|
<FLOATING_POINT_LITERAL>
|
<CHARACTER_LITERAL>
|
<STRING_LITERAL>
|
BooleanLiteral
|
NullLiteral
BooleanLiteral
::=
"true"
|
"false"
NullLiteral
::=
"null"
Arguments
::=
"(" (
ArgumentList
)? ")"
ArgumentList
::=
Expression
( ","
Expression
)*
AllocationExpression
::=
"new"
PrimitiveType
ArrayDimsAndInits
|
"new"
Name
(
ArrayDimsAndInits
|
Arguments
(
ClassBody
)? )
ArrayDimsAndInits
::=
( "["
Expression
"]" )+ ( "[" "]" )*
|
( "[" "]" )+
ArrayInitializer
Statement
::=
LabeledStatement
|
Block
|
EmptyStatement
|
StatementExpression
";"
|
SwitchStatement
|
IfStatement
|
WhileStatement
|
DoStatement
|
ForStatement
|
BreakStatement
|
ContinueStatement
|
ReturnStatement
|
ThrowStatement
|
SynchronizedStatement
|
TryStatement
LabeledStatement
::=
<IDENTIFIER> ":"
Statement
Block
::=
"{" (
BlockStatement
)* "}"
BlockStatement
::=
LocalVariableDeclaration
";"
|
Statement
|
UnmodifiedClassDeclaration
|
UnmodifiedInterfaceDeclaration
LocalVariableDeclaration
::=
( "final" )?
Type
VariableDeclarator
( ","
VariableDeclarator
)*
EmptyStatement
::=
";"
StatementExpression
::=
PreIncrementExpression
|
PreDecrementExpression
|
PrimaryExpression
( "++" | "--" |
AssignmentOperator
Expression
)?
SwitchStatement
::=
"switch" "("
Expression
")" "{" (
SwitchLabel
(
BlockStatement
)* )* "}"
SwitchLabel
::=
"case"
Expression
":"
|
"default" ":"
IfStatement
::=
"if" "("
Expression
")"
Statement
( "else"
Statement
)?
WhileStatement
::=
"while" "("
Expression
")"
Statement
DoStatement
::=
"do"
Statement
"while" "("
Expression
")" ";"
ForStatement
::=
"for" "(" (
ForInit
)? ";" (
Expression
)? ";" (
ForUpdate
)? ")"
Statement
ForInit
::=
LocalVariableDeclaration
|
StatementExpressionList
StatementExpressionList
::=
StatementExpression
( ","
StatementExpression
)*
ForUpdate
::=
StatementExpressionList
BreakStatement
::=
"break" ( <IDENTIFIER> )? ";"
ContinueStatement
::=
"continue" ( <IDENTIFIER> )? ";"
ReturnStatement
::=
"return" (
Expression
)? ";"
ThrowStatement
::=
"throw"
Expression
";"
SynchronizedStatement
::=
"synchronized" "("
Expression
")"
Block
TryStatement
::=
"try"
Block
( "catch" "("
FormalParameter
")"
Block
)* ( "finally"
Block
)?