Grammar
CompilationUnit = ["package" Qualident ';'] {ImportDeclaration} {TypeDeclaration} . Qualident = ident {'.' ident} . ImportDeclaration = "import" ident QualifiedImport ';' . QualifiedImport = '.' (ident [QualifiedImport] | '*') . TypeDeclaration = ClassOrInterfaceDeclaration | ';' . ClassOrInterfaceDeclaration = {ClassModifier} (ClassDeclaration | InterfaceDeclaration) . ClassModifier = "public" | "protected" | "private" | "abstract" | "static" | "final" | "strictfp" . Modifier = "static" | Modifier1 . Modifier1 = "public" | "protected" | "private" | "abstract" | "final" | "native" | "synchronized" | "transient" | "volatile" | "strictfp" . Type = ( Qualident | BasicType ) BracketsOpt . BasicType = "byte" | "short" | "char" | "int" | "long" | "float" | "double" | "boolean" . BracketsOpt = {'[' ']'} . TypeList = Type {',' Type} . FormalParameter = ["final"] Type VariableDeclaratorId . QualidentList = Qualident {',' Qualident} . VariableDeclarator = ident VariableDeclaratorRest . VariableDeclaratorId = ident BracketsOpt . VariableDeclaratorRest = BracketsOpt ['=' VariableInitializer] . VariableInitializer = ArrayInitializer | Expression .Classes
ClassDeclaration = "class" ident ["extends" Type] ["implements" TypeList] ClassBody . ClassBody = '{' {ClassBodyDeclaration} '}' . ClassBodyDeclaration = ';' | ["static"] ( Block | [ Modifier1 {Modifier} ] MemberDecl ) . MemberDecl = IF(identAndLPar()) ident ConstructorDeclaratorRest | MethodOrFieldDecl | "void" ident VoidMethodDeclaratorRest | ClassDeclaration | InterfaceDeclaration . MethodOrFieldDecl = Type ident MethodOrFieldRest . MethodOrFieldRest = VariableDeclaratorsRest ';' | MethodDeclaratorRest . VariableDeclaratorsRest = VariableDeclaratorRest {',' VariableDeclarator} . ArrayInitializer = '{' [VariableInitializer { IF(commaAndNoRBrace()) ',' VariableInitializer }] [','] '}' . MethodDeclaratorRest = FormalParameters BracketsOpt ["throws" QualidentList] (Block | ';') . VoidMethodDeclaratorRest = FormalParameters ["throws" QualidentList] (Block | ';') . ConstructorDeclaratorRest = FormalParameters ["throws" QualidentList] Block . FormalParameters = '(' [FormalParameter {',' FormalParameter}] ')' .Interfaces
InterfaceDeclaration = "interface" ident ["extends" TypeList] InterfaceBody . InterfaceBody = '{' {InterfaceBodyDeclaration} '}' . InterfaceBodyDeclaration = ';' | {Modifier} InterfaceMemberDecl . InterfaceMemberDecl = InterfaceMethodOrFieldDecl | "void" ident VoidInterfaceMethodDeclaratorRest | ClassDeclaration | InterfaceDeclaration . InterfaceMethodOrFieldDecl = Type ident InterfaceMethodOrFieldRest . InterfaceMethodOrFieldRest = ConstantDeclaratorsRest ';' | InterfaceMethodDeclaratorRest . ConstantDeclaratorsRest = ConstantDeclaratorRest {',' ConstantDeclarator} . ConstantDeclaratorRest = BracketsOpt '=' VariableInitializer . ConstantDeclarator = ident ConstantDeclaratorRest . InterfaceMethodDeclaratorRest = FormalParameters BracketsOpt ["throws" QualidentList] ';' . VoidInterfaceMethodDeclaratorRest = FormalParameters ["throws" QualidentList] ';' .Statements
Statement = Block | "if" ParExpression Statement ["else" Statement] | "for" '(' [ForInit] ';' [Expression] ';' [ForUpdate] ')' Statement | "while" ParExpression Statement | "do" Statement "while" ParExpression ';' | "try" Block (Catches ["finally" Block] | "finally" Block) | "switch" ParExpression '{' SwitchBlockStatementGroups '}' | "synchronized" ParExpression Block | "return" [Expression] ';' | "throw" Expression ';' | "break" [ident] ';' | "continue" [ident] ';' | ';' | IF(isLabel()) ident ':' Statement | StatementExpression ';' . Block = '{' {BlockStatement} '}' . BlockStatement = IF(isLocalVarDecl(false)) LocalVariableDeclaration ';' | ClassOrInterfaceDeclaration | Statement . LocalVariableDeclaration = ["final"] Type VariableDeclarators . VariableDeclarators = VariableDeclarator {',' VariableDeclarator} . ForInit = IF(isLocalVarDecl(true)) LocalVariableDeclaration | StatementExpression MoreStatementExpressions . ForUpdate = StatementExpression MoreStatementExpressions . StatementExpression = Expression . MoreStatementExpressions = {',' StatementExpression} . Catches = CatchClause {CatchClause} . CatchClause = "catch" '(' FormalParameter ')' Block . SwitchBlockStatementGroups = {SwitchBlockStatementGroup} . SwitchBlockStatementGroup = SwitchLabel {BlockStatement} . SwitchLabel = "case" Expression ':' | "default" ':' .Expressions
Expression = Expression1 {AssignmentOperator Expression1} . Expression1 = Expression2 [ConditionalExpr] . ConditionalExpr = '?' Expression ':' Expression1 . Expression2 = Expression3 [Expression2Rest] . Expression2Rest = {Infixop Expression3} | "instanceof" Type . Expression3 = { IF(isPrefix() || isTypeCast()) ( PrefixOp | '(' Type ')' ) } Primary {Selector} {PostfixOp} . Primary = '(' Expression ')' | "this" ArgumentsOpt | "super" SuperSuffix | Literal | "new" Creator | ident { IF(dotAndIdent()) '.' ident } [ IF(isIdentSuffix()) IdentifierSuffix ] | BasicType BracketsOpt '.' "class" | "void" '.' "class" . ArgumentsOpt = [Arguments] . Arguments = '(' [Expression {',' Expression}] ')' . SuperSuffix = Arguments | '.' ident ArgumentsOpt . Literal = IntegerLiteral | FloatingPointLiteral | CharacterLiteral | StringLiteral | "true" | "false" | "null" . Creator = BasicType ArrayCreatorRest | Qualident (ArrayCreatorRest | ClassCreatorRest) . ArrayCreatorRest = '[' ( ']' BracketsOpt ArrayInitializer | Expression ']' { IF(nonEmptyBracket()) '[' Expression ']'} { IF(emptyBracket()) '['']'} ) . ClassCreatorRest = Arguments [ClassBody] . IdentifierSuffix = '[' ']' BracketsOpt '.' "class" | Arguments | '.' ("class" | "this" | "super" '.' ident ArgumentsOpt) . Selector = '.' ( ident ArgumentsOpt | "super" Arguments | "new" InnerCreator ) | '[' Expression ']' . InnerCreator = ident ClassCreatorRest . ParExpression = '(' Expression ')' . AssignmentOperator = '=' | "+=" | "-=" | "*=" | "/=" | "&=" | "|=" | "^=" | "%=" | "<<=" | ">>=" | ">>>=" . Infixop = "||" | "&&" | '|' | '^' | '&' | "==" | "!=" | '<" | '>" | "<=" | ">=" | "<<" | ">>" | ">>>" | '+' | '-' | '*' | '/' | '%' . PrefixOp = "++" | "--" | '!' | '~' | '+' | '-' . PostfixOp = "++" | "--" .
Index
Arguments (ArgumentsOpt, ClassCreatorRest, IdentifierSuffix, Selector, SuperSuffix) ArgumentsOpt (IdentifierSuffix, Primary, Selector, SuperSuffix) ArrayCreatorRest (Creator) ArrayInitializer (ArrayCreatorRest, VariableInitializer) AssignmentOperator (Expression) BasicType (Creator, Primary, Type) Block (CatchClause, ClassBodyDeclaration, ConstructorDeclaratorRest, MethodDeclaratorRest, VoidMethodDeclaratorRest, Statement) BlockStatement (Block, SwitchBlockStatementGroup) BracketsOpt (ArrayCreatorRest, ConstantDeclaratorRest, IdentifierSuffix, InterfaceMethodDeclaratorRest, MethodDeclaratorRest, Primary, Type, VariableDeclaratorId, VariableDeclaratorRest) CatchClause (Catches) Catches (Statement) ClassBody (ClassCreatorRest, ClassDeclaration) ClassBodyDeclaration (ClassBody) ClassCreatorRest (Creator, InnerCreator) ClassDeclaration (ClassOrInterfaceDeclaration, InterfaceMethodOrFieldDecl, MemberDecl) ClassModifier (ClassOrInterfaceDeclaration) ClassOrInterfaceDeclaration (BlockStatement, TypeDeclaration) CompilationUnit ConditionalExpr (Expression1) ConstantDeclarator (ConstantDeclaratorsRest) ConstantDeclaratorRest (ConstantDeclarator, ConstantDeclaratorsRest) ConstantDeclaratorsRest (InterfaceMethodOrFieldRest) ConstructorDeclaratorRest (MemberDecl) Creator (Primary) Expression (Arguments, ArrayCreatorRest, ConditionalExpr, SwitchLabel, ParExpression, Primary, Selector, Statement, StatementExpression, VariableInitializer) Expression1 (ConditionalExpr, Expression) Expression2 (Expression1) Expression2Rest (Expression2) Expression3 (Expression2, Expression2Rest) ForInit (Statement) FormalParameter (CatchClause, FormalParameters) FormalParameters (ConstructorDeclaratorRest, InterfaceMethodDeclaratorRest, MethodDeclaratorRest, VoidInterfaceMethodDeclaratorRest, VoidMethodDeclaratorRest) ForUpdate (Statement) IdentifierSuffix (Primary) ImportDeclaration (CompilationUnit) Infixop (Expression2Rest) InnerCreator (Selector) InterfaceBody (InterfaceDeclaration) InterfaceBodyDeclaration (InterfaceBody) InterfaceDeclaration (ClassOrInterfaceDeclaration, InterfaceMemberDecl, MemberDecl) InterfaceMemberDecl (InterfaceBodyDeclaration) InterfaceMethodDeclaratorRest (InterfaceMethodOrFieldRest) InterfaceMethodOrFieldDecl (InterfaceMemberDecl) InterfaceMethodOrFieldRest (InterfaceMethodOrFieldDecl) Literal (Primary) LocalVariableDeclaration (BlockStatement, ForInit) MemberDecl (ClassBodyDeclaration) MethodDeclaratorRest (MethodOrFieldRest) MethodOrFieldDecl (MemberDecl) MethodOrFieldRest (MethodOrFieldDecl) Modifier (ClassBodyDeclaration, InterfaceBodyDeclaration) Modifier1 (ClassBodyDeclaration, Modifier) MoreStatementExpressions (ForInit, ForUpdate) ParExpression (Statement) PrefixOp (Expression3) Primary (Expression3) PostfixOp (Expression3) Qualident (CompilationUnit, Creator, QualidentList, Type) QualidentList (ConstructorDeclaratorRest, InterfaceMethodDeclaratorRest, MethodDeclaratorRest, VoidInterfaceMethodDeclaratorRest, VoidMethodDeclaratorRest) QualifiedImport (ImportDeclaration, QualifiedImport) Selector (Expression3) Statement (BlockStatement, Statement) StatementExpression (ForInit, ForUpdate, MoreStatementExpressions, Statement) SwitchBlockStatementGroup (SwitchBlockStatementGroups) SwitchBlockStatementGroups (Statement) SwitchLabel (SwitchBlockStatementGroup) SuperSuffix (Primary) Type (ClassDeclaration, Expression2Rest, Expression3, FormalParameter, InterfaceMethodOrFieldDecl, LocalVariableDeclaration, MethodOrFieldDecl, TypeList) TypeDeclaration (CompilationUnit) TypeList (ClassDeclaration, InterfaceDeclaration) VariableDeclarator (VariableDeclarators, VariableDeclaratorsRest) VariableDeclaratorId (FormalParameter) VariableDeclaratorRest (VariableDeclarator, VariableDeclaratorRest) VariableDeclarators (LocalVariableDeclaration) VariableDeclaratorsRest (MethodOrFieldRest) VariableInitializer (ArrayInitializer, ConstantDeclaratorRest, VariableDeclaratorRest) VoidInterfaceMethodDeclaratorRest (InterfaceMethodOrFieldDecl) VoidMethodDeclaratorRest (MemberDecl)
Last updated 12.07.2004