Browsable Java (J2SE 1.2 “Playground”) Grammar

CC-BY

Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: java/java-2/jls/impl/extracted
Source used for this grammar: James Gosling, Bill Joy, Guy Steele, Gilad Bracha, Java Language Specification, 2nd edition, 1998, §18: Syntax, pages 449–456 [HTML] [PDF]

Summary

Syntax

ConstantExpression ::=
	Expression
PrefixOp ::=
	"++"
PrefixOp ::=
	"--"
PrefixOp ::=
	"!"
PrefixOp ::=
	"~"
PrefixOp ::=
	"+"
PrefixOp ::=
	"-"
SwitchLabel ::=
	"case" ConstantExpression ":"
SwitchLabel ::=
	"default" ":"
VariableInitializer ::=
	ArrayInitializer
VariableInitializer ::=
	Expression
InterfaceMemberDecl ::=
	InterfaceMethodOrFieldDecl
InterfaceMemberDecl ::=
	"void" Identifier VoidInterfaceMethodDeclaratorRest
InterfaceMemberDecl ::=
	ClassOrInterfaceDeclaration
FormalParameter ::=
	"final"? Type VariableDeclaratorId
TypeDeclaration ::=
	ClassOrInterfaceDeclaration
TypeDeclaration ::=
	";"
MethodOrFieldDecl ::=
	Type Identifier MethodOrFieldRest
ConstantDeclaratorRest ::=
	BracketsOpt "=" VariableInitializer
StatementExpression ::=
	Expression
InterfaceDeclaration ::=
	"interface" Identifier ("extends" TypeList)? InterfaceBody
QualifiedIdentifierList ::=
	QualifiedIdentifier ("," QualifiedIdentifier)*
Arguments ::=
	"(" (Expression ("," Expression)*)? ")"
Statement ::=
	Block
Statement ::=
	"if" ParExpression Statement ("else" Statement)?
Statement ::=
	"for" "(" ForInitOpt ";" Expression? ";" ForUpdateOpt ")" 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 ::=
	ExpressionStatement
Statement ::=
	Identifier ":" Statement
VariableDeclaratorId ::=
	Identifier BracketsOpt
ArgumentsOpt ::=
	Arguments?
Type ::=
	Identifier ("." Identifier)* BracketsOpt
Type ::=
	BasicType
ArrayCreatorRest ::=
	"[" ("]" BracketsOpt ArrayInitializer | Expression "]" ("[" Expression "]")* BracketsOpt)
Modifier ::=
	"public"
Modifier ::=
	"protected"
Modifier ::=
	"private"
Modifier ::=
	"static"
Modifier ::=
	"abstract"
Modifier ::=
	"final"
Modifier ::=
	"native"
Modifier ::=
	"synchronized"
Modifier ::=
	"transient"
Modifier ::=
	"volatile"
Modifier ::=
	"strictfp"
InterfaceMethodOrFieldDecl ::=
	Type Identifier InterfaceMethodOrFieldRest
ImportDeclaration ::=
	"import" Identifier ("." Identifier)* ("." "*")? ";"
CompilationUnit ::=
	("package" QualifiedIdentifier ";")? ImportDeclaration* TypeDeclaration*
VoidMethodDeclaratorRest ::=
	FormalParameters ("throws" QualifiedIdentifierList)? (MethodBody | ";")
BasicType ::=
	"byte"
BasicType ::=
	"short"
BasicType ::=
	"char"
BasicType ::=
	"int"
BasicType ::=
	"long"
BasicType ::=
	"float"
BasicType ::=
	"double"
BasicType ::=
	"boolean"
CatchClause ::=
	"catch" "(" FormalParameter ")" Block
Selector ::=
	"." Identifier Arguments?
Selector ::=
	"." "this"
Selector ::=
	"." "super" SuperSuffix
Selector ::=
	"." "new" InnerCreator
Selector ::=
	"[" Expression "]"
ModifiersOpt ::=
	Modifier*
ClassCreatorRest ::=
	Arguments ClassBody?
ConstantDeclarator ::=
	Identifier ConstantDeclaratorRest
ClassBodyDeclaration ::=
	";"
ClassBodyDeclaration ::=
	"static"? Block
ClassBodyDeclaration ::=
	ModifiersOpt MemberDecl
BlockStatements ::=
	BlockStatement*
VoidInterfaceMethodDeclaratorRest ::=
	FormalParameters ("throws" QualifiedIdentifierList)? ";"
LocalVariableDeclarationStatement ::=
	"final"? Type VariableDeclarators ";"
Expression1 ::=
	Expression2 Expression1Rest?
MemberDecl ::=
	MethodOrFieldDecl
MemberDecl ::=
	"void" Identifier MethodDeclaratorRest
MemberDecl ::=
	Identifier ConstructorDeclaratorRest
MemberDecl ::=
	ClassOrInterfaceDeclaration
Expression3 ::=
	PrefixOp Expression3
Expression3 ::=
	"(" (Expr | Type) ")" Expression3
Expression3 ::=
	Primary Selector* PostfixOp*
Expression2 ::=
	Expression3 Expression2Rest?
BracketsOpt ::=
	("[" "]")*
MethodOrFieldRest ::=
	VariableDeclaratorRest
MethodOrFieldRest ::=
	MethodDeclaratorRest
MoreStatementExpressions ::=
	("," StatementExpression)*
SwitchBlockStatementGroups ::=
	SwitchBlockStatementGroup*
ArrayInitializer ::=
	"{" (VariableInitializer ("," VariableInitializer)* ","?)? "}"
Catches ::=
	CatchClause CatchClause*
InterfaceMethodOrFieldRest ::=
	ConstantDeclaratorsRest ";"
InterfaceMethodOrFieldRest ::=
	InterfaceMethodDeclaratorRest
Expression1Rest ::=
	("?" Expression ":" Expression1)?
Infixop ::=
	"||"
Infixop ::=
	"&&"
Infixop ::=
	"|"
Infixop ::=
	"^"
Infixop ::=
	"&"
Infixop ::=
	"=="
Infixop ::=
	"!="
Infixop ::=
	"<"
Infixop ::=
	">"
Infixop ::=
	"<="
Infixop ::=
	">="
Infixop ::=
	"<<"
Infixop ::=
	">>"
Infixop ::=
	">>>"
Infixop ::=
	"+"
Infixop ::=
	"-"
Infixop ::=
	"*"
Infixop ::=
	"/"
Infixop ::=
	"%"
MethodDeclaratorRest ::=
	FormalParameters BracketsOpt ("throws" QualifiedIdentifierList)? (MethodBody | ";")
InterfaceBodyDeclaration ::=
	";"
InterfaceBodyDeclaration ::=
	ModifiersOpt InterfaceMemberDecl
QualifiedIdentifier ::=
	Identifier ("." Identifier)*
ConstantDeclaratorsRest ::=
	ConstantDeclaratorRest ("," ConstantDeclarator)*
ClassOrInterfaceDeclaration ::=
	ModifiersOpt (ClassDeclaration | InterfaceDeclaration)
SuperSuffix ::=
	Arguments
SuperSuffix ::=
	"." Identifier Arguments?
VariableDeclaratorRest ::=
	BracketsOpt ("=" VariableInitializer)?
BlockStatement ::=
	LocalVariableDeclarationStatement
BlockStatement ::=
	ClassOrInterfaceDeclaration
BlockStatement ::=
	(Identifier ":")? Statement
InterfaceBody ::=
	"{" InterfaceBodyDeclaration* "}"
Literal ::=
	IntegerLiteral
Literal ::=
	FloatingPointLiteral
Literal ::=
	CharacterLiteral
Literal ::=
	StringLiteral
Literal ::=
	BooleanLiteral
Literal ::=
	NullLiteral
Identifier ::=
	IDENTIFIER
Expression ::=
	Expression1 (AssignmentOperator Expression1)?
SwitchBlockStatementGroup ::=
	SwitchLabel BlockStatements
Block ::=
	"{" BlockStatements "}"
PostfixOp ::=
	"++"
PostfixOp ::=
	"--"
InterfaceMethodDeclaratorRest ::=
	FormalParameters BracketsOpt ("throws" QualifiedIdentifierList)? ";"
IdentifierSuffix ::=
	"[" ("]" BracketsOpt "." "class" | Expression "]")
IdentifierSuffix ::=
	Arguments
IdentifierSuffix ::=
	"." ("class" | "this" | "super" Arguments | "new" InnerCreator)
ForUpdate ::=
	StatementExpression MoreStatementExpressions
ForInit ::=
	StatementExpression MoreStatementExpressions
ForInit ::=
	"final"? Type VariableDeclarators
Creator ::=
	QualifiedIdentifier (ArrayCreatorRest | ClassCreatorRest)
AssignmentOperator ::=
	"="
AssignmentOperator ::=
	"+="
AssignmentOperator ::=
	"-="
AssignmentOperator ::=
	"*="
AssignmentOperator ::=
	"/="
AssignmentOperator ::=
	"&="
AssignmentOperator ::=
	"|="
AssignmentOperator ::=
	"^="
AssignmentOperator ::=
	"%="
AssignmentOperator ::=
	"<<="
AssignmentOperator ::=
	">>="
AssignmentOperator ::=
	">>>="
ParExpression ::=
	"(" Expression ")"
VariableDeclarators ::=
	VariableDeclarator ("," VariableDeclarator)*
ClassBody ::=
	"{" ClassBodyDeclaration* "}"
Primary ::=
	"(" Expression ")"
Primary ::=
	"this" Arguments?
Primary ::=
	"super" SuperSuffix
Primary ::=
	Literal
Primary ::=
	"new" Creator
Primary ::=
	Identifier ("." Identifier)* IdentifierSuffix?
Primary ::=
	BasicType BracketsOpt "." "class"
Primary ::=
	"void" "." "class"
ConstructorDeclaratorRest ::=
	FormalParameters ("throws" QualifiedIdentifierList)? MethodBody
FormalParameters ::=
	"(" (FormalParameter ("," FormalParameter)*)? ")"
TypeList ::=
	Type ("," Type)*
MethodBody ::=
	Block
ClassDeclaration ::=
	"class" Identifier ("extends" Type)? ("implements" TypeList)? ClassBody
Expression2Rest ::=
	(Infixop Expression3)*
Expression2Rest ::=
	Expression3 "instanceof" Type
VariableDeclaratorsRest ::=
	VariableDeclaratorRest ("," VariableDeclarator)*
InnerCreator ::=
	Identifier ClassCreatorRest
VariableDeclarator ::=
	Identifier VariableDeclaratorRest

GrammarLabMaintained by Dr. Vadim Zaytsev a.k.a. @grammarware. Last updated in September 2015. []