Chapter 19. Syntax

This chapter repeats the syntactic grammar given in Chapters 4, 6-10, 14, and 15, as well as key parts of the lexical grammar from Chapter 3, using the notation from §2.4.

Productions from §3 (Lexical Structure)

Identifier:
IdentifierChars:
JavaLetter:
any Unicode character that is a "Java letter"
JavaLetterOrDigit:
any Unicode character that is a "Java letter-or-digit"
TypeIdentifier:
Identifier but not var

Productions from §4 (Types, Values, and Variables)

PrimitiveType:
IntegralType:
(one of)
byte short int long char
FloatingPointType:
(one of)
float double
ClassOrInterfaceType:
InterfaceType:
TypeVariable:
Dims:
{Annotation} [ ] {{Annotation} [ ]}
TypeParameterModifier:
TypeBound:
AdditionalBound:
TypeArguments:
TypeArgumentList:
TypeArgument:
Wildcard:
WildcardBounds:

Productions from §6 (Names)

ExpressionName:
MethodName:
PackageOrTypeName:

Productions from §7 (Packages and Modules)

OrdinaryCompilationUnit:
ModularCompilationUnit:
PackageDeclaration:
PackageModifier:
SingleTypeImportDeclaration:
import TypeName ;
TypeImportOnDemandDeclaration:
import PackageOrTypeName . * ;
SingleStaticImportDeclaration:
import static TypeName . Identifier ;
StaticImportOnDemandDeclaration:
import static TypeName . * ;
ModuleDeclaration:
{Annotation} [open] module Identifier {. Identifier} { {ModuleDirective} }
ModuleDirective:
requires {RequiresModifier} ModuleName ;
exports PackageName [to ModuleName {, ModuleName}] ;
opens PackageName [to ModuleName {, ModuleName}] ;
uses TypeName ;
provides TypeName with TypeName {, TypeName} ;
RequiresModifier:
(one of)
transitive static

Productions from §8 (Classes)

ClassModifier:
(one of)
Annotation public protected private
abstract static final strictfp
TypeParameters:
TypeParameterList:
Superclass:
extends ClassType
Superinterfaces:
implements InterfaceTypeList
InterfaceTypeList:
ClassBody:
FieldModifier:
(one of)
Annotation public protected private
static final transient volatile
VariableDeclaratorList:
VariableDeclarator:
VariableDeclaratorId:
VariableInitializer:
UnannPrimitiveType:
NumericType
boolean
UnannClassOrInterfaceType:
UnannInterfaceType:
UnannTypeVariable:
MethodDeclaration:
MethodModifier:
(one of)
Annotation public protected private
abstract static final synchronized native strictfp
Result:
UnannType
void
MethodDeclarator:
ReceiverParameter:
FormalParameterList:
VariableArityParameter:
VariableModifier:
Annotation
final
Throws:
ExceptionTypeList:
ExceptionType:
MethodBody:
Block
;
InstanceInitializer:
StaticInitializer:
static Block
ConstructorModifier:
(one of)
Annotation public protected private
SimpleTypeName:
ExplicitConstructorInvocation:
EnumBody:
EnumConstantList:
EnumConstantModifier:
EnumBodyDeclarations:

Productions from §9 (Interfaces)

NormalInterfaceDeclaration:
InterfaceModifier:
(one of)
Annotation public protected private
abstract static strictfp
ExtendsInterfaces:
InterfaceBody:
ConstantModifier:
(one of)
Annotation public
static final
InterfaceMethodDeclaration:
InterfaceMethodModifier:
(one of)
Annotation public private
abstract default static strictfp
AnnotationTypeDeclaration:
AnnotationTypeBody:
AnnotationTypeElementDeclaration:
AnnotationTypeElementModifier:
(one of)
Annotation public
abstract
DefaultValue:
default ElementValue
NormalAnnotation:
ElementValuePairList:
ElementValuePair:
ElementValueArrayInitializer:
{ [ElementValueList] [,] }
ElementValueList:
MarkerAnnotation:
SingleElementAnnotation:

Productions from §10 (Arrays)

ArrayInitializer:
VariableInitializerList:

Productions from §14 (Blocks and Statements)

Block:
BlockStatements:
LocalVariableDeclarationStatement:
LocalVariableType:
UnannType
var
EmptyStatement:
;
LabeledStatement:
LabeledStatementNoShortIf:
ExpressionStatement:
IfThenStatement:
IfThenElseStatement:
IfThenElseStatementNoShortIf:
AssertStatement:
assert Expression ;
assert Expression : Expression ;
SwitchStatement:
switch ( Expression ) SwitchBlock
SwitchBlock:
SwitchBlockStatementGroup:
SwitchLabels:
SwitchLabel:
case ConstantExpression :
case EnumConstantName :
default :
EnumConstantName:
WhileStatement:
while ( Expression ) Statement
WhileStatementNoShortIf:
DoStatement:
do Statement while ( Expression ) ;
BasicForStatement:
BasicForStatementNoShortIf:
StatementExpressionList:
BreakStatement:
break [Identifier] ;
ContinueStatement:
continue [Identifier] ;
ReturnStatement:
return [Expression] ;
ThrowStatement:
throw Expression ;
SynchronizedStatement:
synchronized ( Expression ) Block
CatchClause:
CatchType:
Finally:
finally Block
TryWithResourcesStatement:
ResourceSpecification:
( ResourceList [;] )
ResourceList:

Productions from §15 (Expressions)

ClassLiteral:
TypeName {[ ]} . class
NumericType {[ ]} . class
boolean {[ ]} . class
void . class
UnqualifiedClassInstanceCreationExpression:
ClassOrInterfaceTypeToInstantiate:
TypeArgumentsOrDiamond:
FieldAccess:
ArgumentList:
DimExprs:
DimExpr:
LambdaExpression:
LambdaParameters:
LambdaParameterList:
LambdaParameterType:
UnannType
var
LambdaBody:
AssignmentExpression:
AssignmentOperator:
(one of)
=  *=  /=  %=  +=  -=  <<=  >>=  >>>=  &=  ^=  |=
ConditionalOrExpression:
PreIncrementExpression:
PreDecrementExpression:
PostIncrementExpression:
PostDecrementExpression:
ConstantExpression: