============== From the J++ on-line reference ============== ;;;;;;;;; 19.2 Grammer from 2.3 Syntactic Grammar Goal: CompilationUnit ;;;;;;;;; 19.3 Grammar from 3 Lexical Structure Literal: IntegerLiteral | FloatingPointLiteral | BooleanLiteral | CharacterLiteral | StringLiteral | NullLiteral ;;;;;;;;; 19.4 Grammar from 4 Types, Values and Variables Type: PrimitiveType | ReferenceType PrimitiveType: NumericType | 'boolean' NumericType: IntegralType | FloatingPointType IntegralType: one of 'byte' 'short' 'int' 'long' 'char' FloatingPointType: one of 'float' 'double' ReferenceType: ClassOrInterfaceType | ArrayType ClassOrInterfaceType: Name ClassType: ClassOrInterfaceType InterfaceType: ClassOrInterfaceType ArrayType: PrimitiveType[] | Name[] | ArrayType[] ;;;;;;;;; 19.5 Grammar from 6 Names Name: SimpleName | QualifiedName SimpleName: Identifier QualifiedName: Name '.' Identifier ;;;;;;;;; 19.6 Grammar from 7 Packages CompilationUnit: PackageDeclarationopt ImportDeclrationsopt TypeDeclarationsopt ImportDeclarations: ImportDeclaration | ImportDeclarations ImportDeclaration TypeDeclarations: TypeDeclaration | TypeDeclarations TypeDeclaration PackageDeclaration: 'package' Name ; ImportDeclaration: SingleTypeImportDeclartion | TypeImportOnDemandDeclaration SingleTypeImportDeclartion: 'import' Name ; TypeImportOnDemandDeclaration: 'import' Name . * ; TypeDeclaration: ClassDeclaration | InterfaceDeclaration | ; ;;;;;;;;; 19.7 Used only in LALR(1) Grammar Modifiers: Modifier | Modifiers Modifier Modifier: one of public protected private static abstract final native synchronized transient volatile ;;;;;;;;; 19.8.1 Grammer from 8.1 Class Declaration ClassDeclaration: Modifiersopt 'class' Identifier Superopt Interfacesopt ClassBody Super: 'extends' ClassType Interfaces: 'implements' InterfaceTypeList InterfaceTypeList: InterfaceType | InterfaceTypeList ',' InterfaceType ClassBody: '{' ClassBodyDeclarationsopt '}' ClassBodyDeclarations: ClassBodyDeclaration | ClassBodyDeclarations ClassBodyDeclaration ClassBodyDeclaration: ClassMemberDeclaration | StaticInitializer | ConstructorDeclaration ClassMemberDeclaration: FieldDeclaration | MethodDeclaration FieldDeclaration: Modifiersopt Type VariableDeclarators ';' VariableDeclarators: VariableDeclarator | VariableDeclarators ',' VariableDeclarator VariableDeclarator: VariableDeclaratorId | VariableDeclaratorId '=' VariableInitializer VariableDeclaratorId: Identifier | VariableDeclaratorId [] VariableInitializer: Expression | ArrayInitializer MethodDeclaration: MethodHeader MethodBody MethodHeader: Modifiersopt Type MethodDeclarator Throwsopt | Modifiersopt 'void' MethodDeclarator Throwsopt MethodDeclarator: Identifier '(' FormalParameterListopt ')' | MethodDeclarator [] FormalParameterList: FormalParameter | FormalParameterList ',' FormalParameter FormalParameter: Type VariableDeclaratorId Throws: 'throws' ClassTypeList ClassTypeList: ClassType | ClassTypeList ',' ClassType MethodBody: Block | ';' StaticInitializer: 'static' Block ConstructorDeclaration: Modifiersopt ConstructorDeclarator Throwsopt ConstructorBody ConstructorDeclarator: SimpleName '(' FormalParametersopt ')' ConstructorBody: '{' ExplicitConstructorInvocationopt BlockStatementsopt '}' ExplicitConstructorInvocation: 'this' '(' ArgumentListopt ')' ';' | 'super' '(' ArgumentListopt ')' ';' ;;;;;;;;; 19.9.1 Grammar from 9.1 Interface Declarations InterfaceDeclaration: Modifiersopt 'interface' Identifier ExtendsInterfacesopt InterfaceBody ExtendsInterfaces: 'extends' InterfaceType | ExtendsInterfaces ',' InterfaceType InterfaceBody: '{' InterfaceMemberDeclarationsopt '}' InterfaceMemberDeclarations: InterfaceMemberDeclaration | InterfaceMemberDeclarations InterfaceMemberDeclaration InterfaceMemberDeclaration: ConstantDeclaration | AbstractMethodDeclaration ConstantDeclaration: FieldDeclaration AbstractMethodDeclaration: MethodHeader ';' ;;;;;;;;; 19.10 Grammar from 10 Arrays ArrayInitializer: '{' VariableInitializersopt ,opt '}' VariableInitializer: VariableInitializer | VariableInitializers ',' VariableInitializer ;;;;;;;;; 19.11 Grammar from 14 Blocks and Statements 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 | 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 Catches | 'try' Block Catchesopt Finally Catches: CatchClause | Catches CatchClause CatchClause: 'catch' '(' FormalParameter ')' Block Finally: 'finally' Block ;;;;;;;;; 19.12 Grammar from Expressions Primary: PrimaryNoNewArray | ArrayCreationExpression PrimaryNoNewArray: Literal | 'this' | '(' Expression ')' | ClassInstanceCreationExpression | FieldAccess | MethodInvocation | ArrayAccess ClassInstanceCreationExpression: 'new' ClassType '(' ArgumentListopt ')' ArgumentList: Expression | ArgumentList ',' Expression ArrayCreationExpression: 'new' PrimitiveType DimExprs Dimsopt 'new' ClassOrInterfaceType DimExprs Dimsopt DimExprs: DimExpr | DimExprs DimExpr DimExpr: '[' Expression ']' Dims: '[]' FieldAccess: Primary '.' Identifier | 'super' '.' Identifier MethodInvocation: Name '(' ArgumentListopt ')' | Primary '.' Identifier '(' ArgumentListopt ')' 'super' '.' Identifier '(' ArgumentListopt ')' ArrayAccess: Name [ Expression ] | PrimaryNoNewArray [ Expression ] PostfixExpression: Primary | Name | PostIncrementExpression | PostDecrementExpression PostIncrementExpression: PostfixExpression '++' PostDecrementExpression: PostfixExpression '--' UnaryExpression: PreIncrementExpression | PreDecrementExpression | '+' UnaryExpression | '-' UnaryExpression | UnaryExpressionNotPlusMinus PreIncrementExpression: '++' UnaryExpression PreDecrementExpression: '--' UnaryExpression UnaryExpressionNotPlusMinus: PostfixExpression | '-' UnaryExpression | '!' UnaryExpression | CastExpression CastExpression: '(' PrimitiveType Dimsopt ')' UnaryExpression | '(' Expression ')' UnaryExpressionNotPlusMinus | '(' Name Dims ')' 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' ShiftExpression 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 AssignmentExpression: ConditionalExpression | Assignment Assignment: LeftHandSide AssignmentOperator AssignmentExpression LeftHandSide: Name | FieldAccess | ArrayAccess AssignmentOperator: one of = *= /= %= += -= <<= >>= >>>= &= ^= |= Expression: AssignmentExpression ConstantExpression: Expression