Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: java/java-5/jls/impl/extracted
Source used for this grammar: James Gosling, Bill Joy, Guy Steele, Gilad Bracha, Java Language Specification, 3rd edition, 2004, §18: Syntax, pages 585–596 [HTML] [PDF]
NormalClassDeclaration
, ExplicitGenericInvocation
, InterfaceDeclaration
, Statement
, Annotations
, ElementValue
, TypeParameter
, CatchClause
, ClassCreatorRest
, ClassBodyDeclaration
, BlockStatement
, Annotation
, SwitchBlockStatementGroups
, EnumConstant
, QualifiedIdentifier
, ConstantDeclaratorsRest
, AnnotationTypeDeclaration
, NonWildcardTypeArguments
, MoreStatementExpressions
, Expression3
, BlockStatements
, IdentifierSuffix
, InterfaceMethodDeclaratorRest
, FormalParameterDeclsRest
, AssignmentOperator
, ParExpression
, AnnotationTypeElementDeclarations
, VariableDeclaratorsRest
, ForControl
, VariableDeclarator
, ConstantExpression
, SwitchLabel
, ElementValues
, InterfaceMemberDecl
, AnnotationConstantRest
, QualifiedIdentifierList
, GenericMethodOrConstructorRest
, ArrayCreatorRest
, Type
, FormalParameters
, TypeList
, Selector
, VoidInterfaceMethodDeclaratorRest
, InterfaceBodyDeclaration
, MethodDeclaratorRest
, ArrayInitializer
, EnumConstants
, VariableDeclaratorRest
, MethodOrFieldRest
, Modifier
, Block
, PostfixOp
, ForInit
, EnumDeclaration
, VariableDeclarators
, Primary
, Expression2Rest
, VariableInitializer
, Literal
, ExplicitGenericInvocationSuffix
, Identifier
, ImportDeclaration
, BasicType
, GenericMethodOrConstructorDecl
, ConstantDeclarator
, ClassBody
, MemberDecl
, SwitchBlockStatementGroup
, Catches
, InterfaceMethodOrFieldRest
, Expression1Rest
, TypeArguments
, Expression
, ConditionalExpression
, Creator
, InfixOp
, ClassOrInterfaceDeclaration
, ConstructorDeclaratorRest
, InterfaceMethodOrFieldDecl
, ClassDeclaration
, MethodOrFieldDecl
, InnerCreator
, PrefixOp
, CreatedName
, TypeDeclaration
, FormalParameterDecls
, ConstantDeclaratorRest
, StatementExpression
, Arguments
, ElementValueArrayInitializer
, VariableDeclaratorId
, AnnotationMethodRest
, VoidMethodDeclaratorRest
, AnnotationTypeBody
, LocalVariableDeclarationStatement
, Expression1
, TypeParameters
, Expression2
, MethodBody
, ForVarControlRest
, EnumBodyDeclarations
, DefaultValue
, AnnotationMethodOrConstantRest
, SuperSuffix
, InterfaceGenericMethodDecl
, EnumBody
, CompilationUnit
, InterfaceBody
, EnumConstantName
, Bound
, TypeArgument
, AnnotationTypeElementRest
, AnnotationTypeElementDeclaration
, NormalInterfaceDeclaration
), 0 root (—), 2 top (MoreStatementExpressions
, CompilationUnit
), 12 bottom (ForVarControl
, StringLiteral
, Expressions
, FormalParameter
, ForUpdate
2, IntegerLiteral
, IDENTIFIER
, NullLiteral
, BooleanLiteral
, CharacterLiteral
, TypeName
, FloatingPointLiteral
).NormalClassDeclaration ::= "class" Identifier TypeParameters "extends" Type "implements" TypeList ClassBody
ExplicitGenericInvocation ::= NonWildcardTypeArguments ExplicitGenericInvocationSuffix
InterfaceDeclaration ::= NormalInterfaceDeclaration
InterfaceDeclaration ::= AnnotationTypeDeclaration
Statement ::= Block
Statement ::= "assert" Expression ":" Expression ";"
Statement ::= "if" ParExpression Statement "else" Statement
Statement ::= "for" "(" ForControl ")" Statement
Statement ::=
"while" ParExpression Statement
Statement ::= "do" Statement "while" ParExpression ";"
Statement ::= "try" Block Catches Catches "finally" Block
Statement ::= "switch" ParExpression "{" SwitchBlockStatementGroups "}"
Statement ::=
"synchronized" ParExpression Block
Statement ::= "return" Expression ";"
Statement ::= "throw" Expression ";"
Statement ::= "break" Identifier
Statement ::= "continue" Identifier
Statement ::=
";"
Statement ::=
StatementExpression ";"
Statement ::=
Identifier ":" Statement
Annotations ::=
Annotation Annotations
ElementValue ::= ConditionalExpression
ElementValue ::= Annotation
ElementValue ::= ElementValueArrayInitializer
TypeParameter ::= Identifier "extends" Bound
CatchClause ::= "catch" "(" FormalParameter ")" Block
ClassCreatorRest ::=
Arguments ClassBody
ClassBodyDeclaration ::=
";"
ClassBodyDeclaration ::= "static" Block
ClassBodyDeclaration ::=
Modifier
MemberDeclBlockStatement ::= LocalVariableDeclarationStatement
BlockStatement ::= ClassOrInterfaceDeclaration
BlockStatement ::= ":" StatementIdentifier
Annotation ::= "@" TypeName "(" Identifier "=" ElementValue ")"
SwitchBlockStatementGroups ::=
SwitchBlockStatementGroup
EnumConstant ::= Annotations Identifier ArgumentsClassBody
QualifiedIdentifier ::= Identifier "." Identifier
ConstantDeclaratorsRest ::= ConstantDeclaratorRest "," ConstantDeclarator
AnnotationTypeDeclaration ::= "@" "interface" Identifier AnnotationTypeBody
NonWildcardTypeArguments ::= "<" TypeList ">"
MoreStatementExpressions ::= "," StatementExpression
Expression3 ::= PrefixOp Expression3
Expression3 ::= "(" Expression Type ")" Expression3
Expression3 ::= Primary SelectorPostfixOp
BlockStatements ::=
BlockStatement
IdentifierSuffix ::= "[" "]" "[" "]" "." "class" Expression "]"
IdentifierSuffix ::= Arguments
IdentifierSuffix ::= "." "class" ExplicitGenericInvocation"this""super" Arguments"new" NonWildcardTypeArguments InnerCreator
InterfaceMethodDeclaratorRest ::= FormalParameters "[" "]" "throws" QualifiedIdentifierList ";"
FormalParameterDeclsRest ::= VariableDeclaratorId "," FormalParameterDecls
FormalParameterDeclsRest ::=
"..." VariableDeclaratorId
AssignmentOperator ::=
"="
AssignmentOperator ::=
"+="
AssignmentOperator ::=
"-="
AssignmentOperator ::=
"*="
AssignmentOperator ::=
"/="
AssignmentOperator ::=
"&="
AssignmentOperator ::=
"|="
AssignmentOperator ::=
"^="
AssignmentOperator ::=
"%="
AssignmentOperator ::=
"<<="
AssignmentOperator ::=
">>="
AssignmentOperator ::=
">>>="
ParExpression ::= "(" Expression ")"
AnnotationTypeElementDeclarations ::= AnnotationTypeElementDeclaration
AnnotationTypeElementDeclarations ::= AnnotationTypeElementDeclarations AnnotationTypeElementDeclaration
VariableDeclaratorsRest ::= VariableDeclaratorRest "," VariableDeclarator
ForControl ::= ForVarControl
ForControl ::= ForInit ";" Expression ";" ForUpdate
ForControl ::= "final" Annotations Type Identifier ForVarControlRest
VariableDeclarator ::= Identifier VariableDeclaratorRest
ConstantExpression ::= Expression
SwitchLabel ::= "case" ConstantExpression ":"
SwitchLabel ::= "case" EnumConstantName ":"
SwitchLabel ::= "default" ":"
ElementValues ::=
ElementValue ElementValues
InterfaceMemberDecl ::= InterfaceMethodOrFieldDecl
InterfaceMemberDecl ::= InterfaceGenericMethodDecl
InterfaceMemberDecl ::=
"void" Identifier VoidInterfaceMethodDeclaratorRest
InterfaceMemberDecl ::= InterfaceDeclaration
InterfaceMemberDecl ::= ClassDeclaration
AnnotationConstantRest ::= VariableDeclarators
QualifiedIdentifierList ::= QualifiedIdentifier "," QualifiedIdentifier
GenericMethodOrConstructorRest ::= "void" Identifier MethodDeclaratorRestType
GenericMethodOrConstructorRest ::= Identifier ConstructorDeclaratorRest
ArrayCreatorRest ::= "[" "]" "[" "]" ArrayInitializer Expression "]" "[" Expression "]" "[" "]"
Type ::= Identifier TypeArguments"." Identifier TypeArguments "[" "]"
Type ::= BasicType
FormalParameters ::= "(" FormalParameterDecls ")"
TypeList ::= Type "," Type
Selector ::= "." Identifier Arguments
Selector ::=
"." ExplicitGenericInvocation
Selector ::= "." "this"
Selector ::= "." "super" SuperSuffix
Selector ::= "." "new" NonWildcardTypeArguments InnerCreator
Selector ::=
Expression
VoidInterfaceMethodDeclaratorRest ::= FormalParameters "throws" QualifiedIdentifierList ";"
InterfaceBodyDeclaration ::=
";"
InterfaceBodyDeclaration ::=
Modifier
InterfaceMemberDeclMethodDeclaratorRest ::= FormalParameters "[" "]" "throws" QualifiedIdentifierList MethodBody";"
ArrayInitializer ::= "," VariableInitializer ","VariableInitializer
EnumConstants ::= EnumConstant
EnumConstants ::=
EnumConstants "," EnumConstant
VariableDeclaratorRest ::= "[" "]" "=" VariableInitializer
MethodOrFieldRest ::= VariableDeclaratorRest
MethodOrFieldRest ::= MethodDeclaratorRest
Modifier ::= Annotation
Modifier ::=
"public"
Modifier ::=
"protected"
Modifier ::=
"private"
Modifier ::=
"static"
Modifier ::=
"abstract"
Modifier ::=
"final"
Modifier ::=
"native"
Modifier ::=
"synchronized"
Modifier ::=
"transient"
Modifier ::=
"volatile"
Modifier ::=
"strictfp"
Block ::=
BlockStatements
PostfixOp ::=
"++"
PostfixOp ::=
"--"
ForInit ::= StatementExpression Expressions
EnumDeclaration ::= "enum" Identifier "implements" TypeList EnumBody
VariableDeclarators ::= VariableDeclarator "," VariableDeclarator
Primary ::= ParExpression
Primary ::= NonWildcardTypeArguments "this" ArgumentsExplicitGenericInvocationSuffix
Primary ::= "this" Arguments
Primary ::=
"super" SuperSuffix
Primary ::= Literal
Primary ::=
"new" Creator
Primary ::= Identifier "." Identifier IdentifierSuffix
Primary ::= BasicType "[" "]" "." "class"
Primary ::= "void" "." "class"
Expression2Rest ::=InfixOp Expression3
Expression2Rest ::=
Expression3 "instanceof" Type
VariableInitializer ::= ArrayInitializer
VariableInitializer ::= Expression
Literal ::= IntegerLiteral
Literal ::= FloatingPointLiteral
Literal ::= CharacterLiteral
Literal ::= StringLiteral
Literal ::= BooleanLiteral
Literal ::= NullLiteral
ExplicitGenericInvocationSuffix ::=
"super" SuperSuffix
ExplicitGenericInvocationSuffix ::= Identifier Arguments
Identifier ::= IDENTIFIER
ImportDeclaration ::= "import" "static" Identifier "." Identifier "." "*" ";"
BasicType ::=
"byte"
BasicType ::=
"short"
BasicType ::=
"char"
BasicType ::=
"int"
BasicType ::=
"long"
BasicType ::=
"float"
BasicType ::=
"double"
BasicType ::=
"boolean"
GenericMethodOrConstructorDecl ::= TypeParameters GenericMethodOrConstructorRest
ConstantDeclarator ::= Identifier ConstantDeclaratorRest
ClassBody ::= "{" ClassBodyDeclaration "}"
MemberDecl ::= GenericMethodOrConstructorDecl
MemberDecl ::= MethodOrFieldDecl
MemberDecl ::=
"void" Identifier VoidMethodDeclaratorRest
MemberDecl ::= Identifier ConstructorDeclaratorRest
MemberDecl ::= InterfaceDeclaration
MemberDecl ::= ClassDeclaration
SwitchBlockStatementGroup ::= SwitchLabel BlockStatements
Catches ::=
CatchClause CatchClause
InterfaceMethodOrFieldRest ::=
ConstantDeclaratorsRest ";"
InterfaceMethodOrFieldRest ::= InterfaceMethodDeclaratorRest
Expression1Rest ::= "?" Expression ":" Expression1
TypeArguments ::= "<" TypeArgument "," TypeArgument ">"
Expression ::= Expression1AssignmentOperator Expression1
ConditionalExpression ::= Expression2 Expression1Rest
Creator ::= NonWildcardTypeArgumentsCreatedName ArrayCreatorRest ClassCreatorRest
InfixOp ::=
"||"
InfixOp ::=
"&&"
InfixOp ::=
"|"
InfixOp ::=
"^"
InfixOp ::=
"&"
InfixOp ::=
"=="
InfixOp ::=
"!="
InfixOp ::=
"<"
InfixOp ::=
">"
InfixOp ::=
"<="
InfixOp ::=
">="
InfixOp ::=
"<<"
InfixOp ::=
">>"
InfixOp ::=
">>>"
InfixOp ::=
"+"
InfixOp ::=
"-"
InfixOp ::=
"*"
InfixOp ::=
"/"
InfixOp ::=
"%"
ClassOrInterfaceDeclaration ::= ModifierClassDeclaration InterfaceDeclaration
ConstructorDeclaratorRest ::= FormalParameters "throws" QualifiedIdentifierList MethodBody
InterfaceMethodOrFieldDecl ::= Type Identifier InterfaceMethodOrFieldRest
ClassDeclaration ::= NormalClassDeclaration
ClassDeclaration ::= EnumDeclaration
MethodOrFieldDecl ::= Type Identifier MethodOrFieldRest
InnerCreator ::= Identifier ClassCreatorRest
PrefixOp ::=
"++"
PrefixOp ::=
"--"
PrefixOp ::=
"!"
PrefixOp ::=
"~"
PrefixOp ::=
"+"
PrefixOp ::=
"-"
CreatedName ::= Identifier NonWildcardTypeArguments"." Identifier NonWildcardTypeArguments
TypeDeclaration ::= ClassOrInterfaceDeclaration
TypeDeclaration ::=
";"
FormalParameterDecls ::= "final" Annotations Type FormalParameterDeclsRest
ConstantDeclaratorRest ::= "[" "]" "=" VariableInitializer
StatementExpression ::= Expression
Arguments ::= "(" Expression "," Expression ")"
ElementValueArrayInitializer ::= "{" ElementValues "," "}"
VariableDeclaratorId ::= Identifier "[" "]"
AnnotationMethodRest ::= "(" ")" DefaultValue
VoidMethodDeclaratorRest ::= FormalParameters "throws" QualifiedIdentifierList MethodBody";"
AnnotationTypeBody ::= AnnotationTypeElementDeclarations
LocalVariableDeclarationStatement ::= "final" Type VariableDeclarators ";"
Expression1 ::=
Expression2 Expression1Rest
TypeParameters ::= "<" TypeParameter "," TypeParameter ">"
Expression2 ::=
Expression3 Expression2Rest
MethodBody ::= Block
ForVarControlRest ::= VariableDeclaratorsRest ";" Expression ";" ForUpdate
ForVarControlRest ::=
":" Expression
EnumBodyDeclarations ::= ";" ClassBodyDeclaration
DefaultValue ::=
"default" ElementValue
AnnotationMethodOrConstantRest ::= AnnotationMethodRest
AnnotationMethodOrConstantRest ::= AnnotationConstantRest
SuperSuffix ::= Arguments
SuperSuffix ::= "." Identifier Arguments
InterfaceGenericMethodDecl ::= TypeParameters "void" Identifier InterfaceMethodDeclaratorRestType
EnumBody ::= "," EnumBodyDeclarationsEnumConstants
CompilationUnit ::= "package" QualifiedIdentifier ";" ImportDeclaration TypeDeclarationAnnotations
InterfaceBody ::= "{" InterfaceBodyDeclaration "}"
EnumConstantName ::= Identifier
Bound ::= Type "&" Type
TypeArgument ::= Type
TypeArgument ::= "?" "extends""super" Type
AnnotationTypeElementRest ::=
Type Identifier AnnotationMethodOrConstantRest ";"
AnnotationTypeElementRest ::= ClassDeclaration
AnnotationTypeElementRest ::= InterfaceDeclaration
AnnotationTypeElementRest ::= EnumDeclaration
AnnotationTypeElementRest ::= AnnotationTypeDeclaration
AnnotationTypeElementDeclaration ::=
Modifier
AnnotationTypeElementRestNormalInterfaceDeclaration ::= "interface" Identifier TypeParameters "extends" TypeList InterfaceBody