We first enumerate the differences between this grammar and the grammar
described in Chapter 19 of "The
Java Language Specification".
Type: [ PrimitiveType | TypeName ] BracketPair* PrimitiveType: one of byte short int long char float double boolean void TypeName: Name Name: Identifier ( , Identifier )*
CompilationUnit: [ package Name ; ] ImportDeclaration* TypeDeclaration* ImportDeclaration: SingleTypeImportDeclaration TypeImportOnDemandDeclaration SingleTypeImportDeclaration: import Name ; TypeImportOnDemandDeclaration: import Name . * ; TypeDeclaration: ClassDeclaration InterfaceDeclaration ;
ClassDeclaration: Modifiers class Identifier [extends TypeName] [implements TypeNameList] { TypeDeclElem* }
InterfaceDeclaration: Modifiers interface Identifier [extends TypeNameList] { TypeDeclElem* }
TypeNameList: TypeName ( , TypeName )*
TypeDeclElem: FieldDeclaration MethodDeclaration ConstructorDeclaration StaticInitializer ;
FieldDeclaration: Modifiers Type VariableDeclarator ( , VariableDeclarator )* ; VariableDeclarator: Identifier BracketPair* [ = VariableInitializer ] MethodDeclaration: Modifiers Type Identifier FormalParameterList BracketPair* [throws TypeNameList] ( ; | Block )
ConstructorDeclaration: Modifiers Identifier FormalParameterList Block
StaticInitializer: Modifiers BlockFormalParameterList:
Modifiers: Modifier*, with no duplicates, and only one of private, protected, public Modifier: one of public protected private static abstract final native synchronized transient volatile
Block: { BlockStatementsopt } BlockStatements: BlockStatement BlockStatements BlockStatement BlockStatement: LocalVariableDeclarationStatement Statement LocalVariableDeclarationStatement: LocalVariableDeclaration ; LocalVariableDeclaration: Type VariableDeclarators Statement: StatementWithoutTrailingSubstatement LabeledStatement IfThenStatement IfThenElseStatement WhileStatement ForStatement StatementNoShortIf: StatementWithoutTrailingSubstatement LabeledStatementNoShortIf IfThenElseStatementNoShortIf WhileStatementNoShortIf ForStatementNoShortIf StatementWithoutTrailingSubstatement: Block EmptyStatement ExpressionStatement SwitchStatement DoStatement BreakStatement ContinueStatement ReturnStatement SynchronizedStatement ThrowStatement TryStatement EmptyStatement: ; LabeledStatement: Identifier : Statement LabeledStatementNoShortIf: Identifier : StatementNoShortIf ExpressionStatement: StatementExpression ; StatementExpression: Assignment PreIncrementExpression PreDecrementExpression PostIncrementExpression PostDecrementExpression MethodInvocation ClassInstanceCreationExpression
IfThenStatement: if ( Expression ) Statement IfThenElseStatement: if ( Expression ) StatementNoShortIf else Statement IfThenElseStatementNoShortIf: if ( Expression ) StatementNoShortIf else StatementNoShortIf SwitchStatement: switch ( Expression ) SwitchBlock SwitchBlock: { SwitchBlockStatementGroupsopt SwitchLabelsopt } SwitchBlockStatementGroups: SwitchBlockStatementGroup SwitchBlockStatementGroups SwitchBlockStatementGroup SwitchBlockStatementGroup: SwitchLabels BlockStatements SwitchLabels: SwitchLabel SwitchLabels SwitchLabel SwitchLabel: case ConstantExpression : default : WhileStatement: while ( Expression ) Statement WhileStatementNoShortIf: while ( Expression ) StatementNoShortIf DoStatement: do Statement while ( Expression ) ;
ForStatement: for ( ForInitopt ; Expressionopt ; ForUpdateopt ) Statement ForStatementNoShortIf: for ( ForInitopt ; Expressionopt ; ForUpdateopt ) StatementNoShortIf ForInit: StatementExpressionList LocalVariableDeclaration ForUpdate: StatementExpressionList StatementExpressionList: StatementExpression StatementExpressionList , StatementExpression BreakStatement: break Identifieropt ; ContinueStatement: continue Identifieropt ; ReturnStatement: return Expressionopt ; ThrowStatement: throw Expression ; SynchronizedStatement: synchronized ( Expression ) Block TryStatement: try Block CatchClause+ try Block CatchClause* Finally CatchClause: catch ( FormalParameter ) Block Finally: finally Block
Primary: PrimaryCore PrimarySuffix*
PrimaryCore: Literal Name Name ArgumentList this super . Identifier super . Identifier ArgumentList NewExpression LPAREN Expression RPAREN Literal: IntegerLiteral FloatingPointLiteral BooleanLiteral CharacterLiteral StringLiteral NullLiteral
PrimarySuffix: . Identifier . Identifier ArgumentList LSQBRACKET Expression RSQBRACKET ++ -- NewExpression: new TypeName ArgumentList new PrimitiveTypeOrTypeName DimExpr+ BracketPair* DimExpr: LSQBRACKET Expression RSQBRACKET ArgumentList: LPAREN [ Expression ( , Expression )* ]RPAREN BracketPair: [ ] UnaryExpression: ++ UnaryExpression -- UnaryExpression + UnaryExpression - UnaryExpression UnaryExpressionNotPlusMinus UnaryExpressionNotPlusMinus: ~ UnaryExpression ! UnaryExpression CastExpression PostfixExpression CastExpression: ( PrimitiveType Dimsopt ) UnaryExpression ( Name Dimsopt ) UnaryExpressionNotPlusMinus MultiplicativeExpression: UnaryExpression MultiplicativeExpression * UnaryExpression MultiplicativeExpression / UnaryExpression MultiplicativeExpression % UnaryExpression AdditiveExpression: MultiplicativeExpression AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression ShiftExpression: AdditiveExpression ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression RelationalExpression: ShiftExpression RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ReferenceType EqualityExpression: RelationalExpression EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression AndExpression: EqualityExpression AndExpression & EqualityExpression ExclusiveOrExpression: AndExpression ExclusiveOrExpression ^ AndExpression InclusiveOrExpression: ExclusiveOrExpression InclusiveOrExpression | ExclusiveOrExpression ConditionalAndExpression: InclusiveOrExpression ConditionalAndExpression && InclusiveOrExpression ConditionalOrExpression: ConditionalAndExpression ConditionalOrExpression || ConditionalAndExpression ConditionalExpression: ConditionalOrExpression ConditionalOrExpression ? Expression : ConditionalExpression Assignment: ConditionalExpression AssignmentOperator Expression AssignmentOperator: one of = *= /= %= += -= <<= >>= >>>= &= ^= |= Expression: ConditionalExpression Assignment
VariableInitializer: Expression ArrayInitializerArrayInitializer: