Java Syntax (vereinfacht)


Declaration: [final] Type VarDecalration {, VarDecalration};

Type: Identifier{[]}

VarDeclaration: Identifier [= Initializer]

Initializer: Expression

Assignment: Variable = Expression

Expression: Primary | Assignment | Expr {InfixOp Expr}

Primary: Literal | Identifier | ( Expression ) | FieldAccess

Expr: Primary [PostfixOp] | [PrefixOp] Primary | CastExpression

Block: { {Declaration | Statement} }

Statement: Block | Assignment | Expression | ReturnStatement |

           ConditionalStatement | SwitchStatement |

           WhileStatement | DoStatement | RepeatStatement |

           ForStatement | ...

ConditionalStatement: if ( Expression ) Statement [else Statement]

ConditionalOperator: Expression ? Expression : Expression

SwitchStatement: switch ( Expression ) { {SwitchLabel Statement} }

SwitchLabel: case ConstantExpression :    |

             default :

WhileStatement: while ( Expression ) Statement

DoStatement: do Statement while ( Expression ) ;

RepeatStatement: repeat Statement until ( Expression ) ;

ForStatement: for ( [ForInit] ; [Expression] ; [ForUpdate] ) Statement

ForInit: Declaration | Expression {, Expression}

ForUpdate: Expression {, Expression}

BreakStatement: break [Label];

ContinueStatement: continue [Label];

Label: Identifier

CastExpression: ( Type ) Primary

ArrayAccess: Primary[Expression]

ArrayCreationExpression: new Type{Length}{[]}

Length: [Expression]

MethodDeclaration: MethodHeader MethodBody

MethodHeader: [Modifiers] ResultType MethodDeclarator

ResultType: Type | void

MethodDeclarator: Identifier ( [FormalArguments] )

FormalArguments: FormalArgument {, FormalArgument}

FormalArgument: Type Identifier

MethodBody: Block | ;

ReturnStatement: return [Expression];

StatementExpression: ... | MethodInvocation | CreationExpression

MethodInvocation: Identifier( [ActualArguments] )

ActualArguments: Expression {, Expression}

ClassDeclaration: [Modifiers] class Identifier

                        [ extends Type ]

                        [ implements Type {, Type } ]

                        ClassBody

ClassBody: { { VariableDeclaration }

             { ConstructorDeclarartion }

             { MethodDeclaration }

           }

VariableDeclaration: [Modifiers] Declaration

ConstructorDeclaration: Identifier ( [FormalArguments] ) Block

CreationExpression: new Identifier ( [ActualArguments] )

FieldAccess: Primary . Identifier

Modifiers: abstract | public | final | protected | private |

           final | transient | static | native

InterfaceDeclaration: interface Identifier [ extends Type {, Type } ]

CompilationUnit: package Identifier ;

ImportDeclaration: import Identifier { . Identifier } [ .* ] ;