






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Contents | Prev | Next | Index Java Language Specification Second Edition
CHAPTER 18 Syntax
This chapter presents a grammar for the Java programming language. The grammar presented piecemeal in the preceding chapters is much better for exposition, but it is not ideally suited as a basis for a parser. The grammar presented in this chapter is the basis for the reference implementation. The grammar below uses the following BNF-style conventions:
Infixop: "||" | && | "|" | ^ | & | == | != | < | > | <= | >= | << | >> | >>> | + | - | * | / | % Expression3: PrefixOp Expression3 | ( Expr | Type ) Expression3 | Primary {Selector} {PostfixOp} Primary: ( Expression ) | this [Arguments] | super SuperSuffix | Literal | new Creator | Identifier {. Identifier }[ IdentifierSuffix] | BasicType BracketsOpt .class | void.class | IdentifierSuffix: [ ( ] BracketsOpt. class | Expression ]) | Arguments |
. ( class | this | super Arguments | new InnerCreator ) | PrefixOp: ++ | -- |! | ~ | + | - PostfixOp: ++ | -- Selector:. Identifier [Arguments] | . this | . super SuperSuffix | . new InnerCreator | [ Expression ]
SuperSuffix: Arguments |
. Identifier [Arguments] BasicType: byte | short | char | int | long | float | double | boolean ArgumentsOpt: [ Arguments ] Arguments: ( [Expression { , Expression }] ) BracketsOpt: {[]} Creator: QualifiedIdentifier ( ArrayCreatorRest | ClassCreatorRest ) InnerCreator: Identifier ClassCreatorRest ArrayCreatorRest: [ ( ] BracketsOpt ArrayInitializer | Expression ] {[ Expression ]} BracketsOpt ) ClassCreatorRest: Arguments [ClassBody] ArrayInitializer: { [VariableInitializer {, VariableInitializer} [,]] } VariableInitializer: ArrayInitializer | Expression
SwitchBlockStatementGroups: { SwitchBlockStatementGroup } SwitchBlockStatementGroup: SwitchLabel BlockStatements SwitchLabel: case ConstantExpression : | default: MoreStatementExpressions: { , StatementExpression } ForInit: StatementExpression MoreStatementExpressions | [final] Type VariableDeclarators ForUpdate: StatementExpression MoreStatementExpressions ModifiersOpt: { Modifier } Modifier: public | protected | private | static | abstract | final | native | synchronized | transient | volatile | strictfp VariableDeclarators: VariableDeclarator { , VariableDeclarator } VariableDeclaratorsRest: VariableDeclaratorRest { , VariableDeclarator } ConstantDeclaratorsRest: ConstantDeclaratorRest { , ConstantDeclarator } VariableDeclarator: Identifier VariableDeclaratorRest ConstantDeclarator: Identifier ConstantDeclaratorRest
VariableDeclaratorRest: BracketsOpt [ = VariableInitializer] ConstantDeclaratorRest: BracketsOpt = VariableInitializer VariableDeclaratorId: Identifier BracketsOpt CompilationUnit: [package QualifiedIdentifier ; ] {ImportDeclaration} {TypeDeclaration} ImportDeclaration: import Identifier {. Identifier } [. * ] ; TypeDeclaration: ClassOrInterfaceDeclaration | ; ClassOrInterfaceDeclaration: ModifiersOpt (ClassDeclaration | InterfaceDeclaration) ClassDeclaration: class Identifier [extends Type] [implements TypeList] ClassBody InterfaceDeclaration: interface Identifier [extends TypeList] InterfaceBody TypeList: Type { , Type} ClassBody: { {ClassBodyDeclaration} } InterfaceBody: { {InterfaceBodyDeclaration} } ClassBodyDeclaration: ; | [static] Block | ModifiersOpt MemberDecl
VoidInterfaceMethodDeclaratorRest: FormalParameters [throws QualifiedIdentifierList] ; ConstructorDeclaratorRest: FormalParameters [throws QualifiedIdentifierList] MethodBody QualifiedIdentifierList: QualifiedIdentifier { , QualifiedIdentifier} FormalParameters: ( [FormalParameter { , FormalParameter}] ) FormalParameter: [final] Type VariableDeclaratorId MethodBody: Block