Java Reference
In-Depth Information
Chapter 18. Syntax
This chapter presents a grammar for the Java programming language.
ition, but it is not well suited as a basis for a parser. The grammar presented in this chapter
is the basis for the reference implementation. Note that it is not an LL(1) grammar, though
in many cases it minimizes the necessary look ahead.
The grammar below uses the following BNF-style conventions:
•
[x]
denotes zero or one occurrences of
x
.
•
{x}
denotes zero or more occurrences of
x
.
•
(x | y)
means one of either
x
or
y
.
Identifier:
IDENTIFIER
QualifiedIdentifier:
Identifier {
.
Identifier }
QualifiedIdentifierList:
QualifiedIdentifier {
,
QualifiedIdentifier }
CompilationUnit:
[[Annotations]
package
QualifiedIdentifier
;
]
{ImportDeclaration} {TypeDeclaration}
ImportDeclaration:
import
[
static
] Identifier {
.
Identifier } [
. *
]
;
TypeDeclaration:
ClassOrInterfaceDeclaration
;
ClassOrInterfaceDeclaration:
{Modifier} (ClassDeclaration | InterfaceDeclaration)
ClassDeclaration:
NormalClassDeclaration
EnumDeclaration
InterfaceDeclaration:
NormalInterfaceDeclaration
AnnotationTypeDeclaration
NormalClassDeclaration: