
Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: java/java-5/parr/extracted
Source used for this grammar: Terence Parr, Java.g, 2006 [ANTLR3]
compilationUnit, annotations, annotation, annotationName, Identifier, Letter, JavaIDDigit, elementValuePairs, elementValuePair, elementValue, conditionalExpression, conditionalOrExpression, conditionalAndExpression, inclusiveOrExpression, exclusiveOrExpression, andExpression, equalityExpression, instanceOfExpression, relationalExpression, shiftExpression, additiveExpression, multiplicativeExpression, unaryExpression, unaryExpressionNotPlusMinus, castExpression, primitiveType, type, classOrInterfaceType, typeArguments, typeArgument, expression, assignmentOperator, primary, parExpression, identifierSuffix, arguments, expressionList, explicitGenericInvocation, nonWildcardTypeArguments, typeList, innerCreator, classCreatorRest, classBody, classBodyDeclaration, block, blockStatement, localVariableDeclarationStatement, localVariableDeclaration, variableModifiers, variableModifier, variableDeclarators, variableDeclarator, variableDeclaratorId, variableInitializer, arrayInitializer, classOrInterfaceDeclaration, classOrInterfaceModifiers, classOrInterfaceModifier, classDeclaration, normalClassDeclaration, typeParameters, typeParameter, typeBound, enumDeclaration, ENUM, enumBody, enumConstants, enumConstant, enumBodyDeclarations, interfaceDeclaration, normalInterfaceDeclaration, interfaceBody, interfaceBodyDeclaration, modifiers, modifier, interfaceMemberDecl, interfaceMethodOrFieldDecl, interfaceMethodOrFieldRest, constantDeclaratorsRest, constantDeclaratorRest, constantDeclarator, interfaceMethodDeclaratorRest, formalParameters, formalParameterDecls, formalParameterDeclsRest, qualifiedNameList, qualifiedName, interfaceGenericMethodDecl, voidInterfaceMethodDeclaratorRest, annotationTypeDeclaration, annotationTypeBody, annotationTypeElementDeclaration, annotationTypeElementRest, annotationMethodOrConstantRest, annotationMethodRest, defaultValue, annotationConstantRest, statement, ASSERT, forControl, enhancedForControl, forInit, forUpdate, catches, catchClause, formalParameter, switchBlockStatementGroups, switchBlockStatementGroup, switchLabel, constantExpression, enumConstantName, statementExpression, memberDecl, genericMethodOrConstructorDecl, genericMethodOrConstructorRest, methodDeclaratorRest, methodBody, constructorDeclaratorRest, constructorBody, explicitConstructorInvocation, memberDeclaration, methodDeclaration, fieldDeclaration, voidMethodDeclaratorRest, superSuffix, literal, integerLiteral, HexLiteral, HexDigit, IntegerTypeSuffix, OctalLiteral, DecimalLiteral, FloatingPointLiteral, Exponent, FloatTypeSuffix, CharacterLiteral, EscapeSequence, UnicodeEscape, OctalEscape, StringLiteral, booleanLiteral, creator, createdName, arrayCreatorRest, selector, shiftOp, relationalOp, elementValueArrayInitializer, packageDeclaration, importDeclaration, typeDeclaration), 1 root (compilationUnit), 0 top (—), 0 bottom (—).[t1] 8, [t2] 8, [t3] 4, [t4].compilationUnit ::= annotations packageDeclaration importDeclaration typeDeclarationclassOrInterfaceDeclaration typeDeclaration packageDeclaration importDeclaration typeDeclaration
annotations ::=
annotationannotation ::= "@" annotationName "(" elementValuePairselementValue ")"
annotationName ::= Identifier "." Identifier
Identifier ::= Letter LetterJavaIDDigit
Letter ::= "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
JavaIDDigit ::= "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
elementValuePairs ::= elementValuePair "," elementValuePair
elementValuePair ::=
Identifier "=" elementValueelementValue ::= conditionalExpression annotation elementValueArrayInitializer
conditionalExpression ::= conditionalOrExpression "?" expression ":" expression
conditionalOrExpression ::= conditionalAndExpression "||" conditionalAndExpression
conditionalAndExpression ::= inclusiveOrExpression "&&" inclusiveOrExpression
inclusiveOrExpression ::= exclusiveOrExpression "|" exclusiveOrExpression
exclusiveOrExpression ::= andExpression "^" andExpression
andExpression ::= equalityExpression "&" equalityExpression
equalityExpression ::= instanceOfExpression "==""!=" instanceOfExpression
instanceOfExpression ::= relationalExpression "instanceof" type
relationalExpression ::= shiftExpression relationalOp shiftExpression
shiftExpression ::= additiveExpression shiftOp additiveExpression
additiveExpression ::= multiplicativeExpression "+""-" multiplicativeExpression
multiplicativeExpression ::= unaryExpression "*""/""%" unaryExpression
unaryExpression ::= "+" unaryExpression "-" unaryExpression "++" unaryExpression "--" unaryExpression unaryExpressionNotPlusMinus
unaryExpressionNotPlusMinus ::= "~" unaryExpression "!" unaryExpression castExpression primary selector "++""--"
castExpression ::= "(" primitiveType ")" unaryExpression "(" typeexpression ")" unaryExpressionNotPlusMinus
primitiveType ::= "boolean" "char" "byte" "short" "int" "long" "float" "double"
type ::= classOrInterfaceType "[" "]" primitiveType "[" "]"
classOrInterfaceType ::= Identifier typeArguments "." Identifier typeArguments
typeArguments ::= "<" typeArgument "," typeArgument ">"
typeArgument ::= type "?" "extends""super" type
expression ::= conditionalExpression assignmentOperator expression
assignmentOperator ::= "=" "+=" "-=" "*=" "/=" "&=" "|=" "^=" "%=" [t1]::"<" [t2]::"<" [t3]::"=" [t1]::">" [t2]::">" [t3]::">" [t4]::"=" [t1]::">" [t2]::">" [t3]::"="
primary ::= parExpression "this" "." Identifier identifierSuffix "super" superSuffix literal "new" creator Identifier "." Identifier identifierSuffix primitiveType "[" "]" "." "class" "void" "." "class"
parExpression ::= "(" expression ")"
identifierSuffix ::= "[" "]" "." "class" "[" expression "]" arguments "." "class" "." explicitGenericInvocation "." "this" "." "super" arguments "." "new" innerCreator
arguments ::= "(" expressionList ")"
expressionList ::= expression "," expression
explicitGenericInvocation ::= nonWildcardTypeArguments Identifier arguments
nonWildcardTypeArguments ::= "<" typeList ">"
typeList ::= type "," type
innerCreator ::=
nonWildcardTypeArguments Identifier classCreatorRestclassCreatorRest ::=
arguments classBodyclassBody ::= "{" classBodyDeclaration "}"
classBodyDeclaration ::= ";" "static" block modifiers memberDecl
block ::= "{" blockStatement "}"
blockStatement ::= localVariableDeclarationStatement classOrInterfaceDeclaration statement
localVariableDeclarationStatement ::=
localVariableDeclaration ";"localVariableDeclaration ::= variableModifiers type variableDeclarators
variableModifiers ::=
variableModifiervariableModifier ::=
"final"
annotationvariableDeclarators ::= variableDeclarator "," variableDeclarator
variableDeclarator ::= variableDeclaratorId "=" variableInitializer
variableDeclaratorId ::= Identifier "[" "]"
variableInitializer ::= arrayInitializer expression
arrayInitializer ::= "{" variableInitializer "," variableInitializer "," "}"
classOrInterfaceDeclaration ::= classOrInterfaceModifiers classDeclarationinterfaceDeclaration
classOrInterfaceModifiers ::=
classOrInterfaceModifierclassOrInterfaceModifier ::= annotation "public" "protected" "private" "abstract" "static" "final" "strictfp"
classDeclaration ::= normalClassDeclaration enumDeclaration
normalClassDeclaration ::= "class" Identifier typeParameters "extends" type "implements" typeList classBody
typeParameters ::= "<" typeParameter "," typeParameter ">"
typeParameter ::= Identifier "extends" typeBound
typeBound ::= type "&" type
enumDeclaration ::= ENUM Identifier "implements" typeList enumBody
ENUM ::=
"enum"enumBody ::= "{" enumConstants "," enumBodyDeclarations "}"
enumConstants ::= enumConstant "," enumConstant
enumConstant ::= annotations Identifier arguments classBody
enumBodyDeclarations ::= ";" classBodyDeclaration
interfaceDeclaration ::= normalInterfaceDeclaration annotationTypeDeclaration
normalInterfaceDeclaration ::= "interface" Identifier typeParameters "extends" typeList interfaceBody
interfaceBody ::= "{" interfaceBodyDeclaration "}"
interfaceBodyDeclaration ::=
modifiers interfaceMemberDecl
";"modifiers ::=
modifiermodifier ::= annotation "public" "protected" "private" "static" "abstract" "final" "native" "synchronized" "transient" "volatile" "strictfp"
interfaceMemberDecl ::=
interfaceMethodOrFieldDecl
interfaceGenericMethodDecl
"void" Identifier voidInterfaceMethodDeclaratorRest
interfaceDeclaration
classDeclarationinterfaceMethodOrFieldDecl ::= type Identifier interfaceMethodOrFieldRest
interfaceMethodOrFieldRest ::=
constantDeclaratorsRest ";"
interfaceMethodDeclaratorRestconstantDeclaratorsRest ::= constantDeclaratorRest "," constantDeclarator
constantDeclaratorRest ::= "[" "]" "=" variableInitializer
constantDeclarator ::= Identifier constantDeclaratorRest
interfaceMethodDeclaratorRest ::= formalParameters "[" "]" "throws" qualifiedNameList ";"
formalParameters ::= "(" formalParameterDecls ")"
formalParameterDecls ::= variableModifiers type formalParameterDeclsRest
formalParameterDeclsRest ::= variableDeclaratorId "," formalParameterDecls "..." variableDeclaratorId
qualifiedNameList ::= qualifiedName "," qualifiedName
qualifiedName ::= Identifier "." Identifier
interfaceGenericMethodDecl ::= typeParameters type"void" Identifier interfaceMethodDeclaratorRest
voidInterfaceMethodDeclaratorRest ::= formalParameters "throws" qualifiedNameList ";"
annotationTypeDeclaration ::= "@" "interface" Identifier annotationTypeBody
annotationTypeBody ::= "{" annotationTypeElementDeclaration "}"
annotationTypeElementDeclaration ::= modifiers annotationTypeElementRest
annotationTypeElementRest ::= type annotationMethodOrConstantRest ";" normalClassDeclaration ";" normalInterfaceDeclaration ";" enumDeclaration ";" annotationTypeDeclaration ";"
annotationMethodOrConstantRest ::= annotationMethodRest annotationConstantRest
annotationMethodRest ::= Identifier "(" ")" defaultValue
defaultValue ::=
"default" elementValueannotationConstantRest ::= variableDeclarators
statement ::= block ASSERT expression ":" expression ";" "if" parExpression statement "else" statement "for" "(" forControl ")" statement "while" parExpression statement "do" statement "while" parExpression ";" "try" block catches "finally" blockcatches"finally" block "switch" parExpression "{" switchBlockStatementGroups "}" "synchronized" parExpression block "return" expression ";" "throw" expression ";" "break" Identifier ";" "continue" Identifier ";" ";" statementExpression ";" Identifier ":" statement
ASSERT ::=
"assert"forControl ::= enhancedForControl forInit ";" expression ";" forUpdate
enhancedForControl ::=
variableModifiers type Identifier ":" expressionforInit ::= localVariableDeclaration expressionList
forUpdate ::= expressionList
catches ::=
catchClause catchClausecatchClause ::= "catch" "(" formalParameter ")" block
formalParameter ::= variableModifiers type variableDeclaratorId
switchBlockStatementGroups ::=
switchBlockStatementGroupswitchBlockStatementGroup ::= switchLabel blockStatement
switchLabel ::= "case" constantExpression ":" "case" enumConstantName ":" "default" ":"
constantExpression ::= expression
enumConstantName ::= Identifier
statementExpression ::= expression
memberDecl ::=
genericMethodOrConstructorDecl
memberDeclaration
"void" Identifier voidMethodDeclaratorRest
Identifier constructorDeclaratorRest
interfaceDeclaration
classDeclarationgenericMethodOrConstructorDecl ::= typeParameters genericMethodOrConstructorRest
genericMethodOrConstructorRest ::= type"void" Identifier methodDeclaratorRest Identifier constructorDeclaratorRest
methodDeclaratorRest ::= formalParameters "[" "]" "throws" qualifiedNameList methodBody";"
methodBody ::= block
constructorDeclaratorRest ::= formalParameters "throws" qualifiedNameList constructorBody
constructorBody ::= "{" explicitConstructorInvocation blockStatement "}"
explicitConstructorInvocation ::= nonWildcardTypeArguments "this""super" arguments ";" primary "." nonWildcardTypeArguments "super" arguments ";"
memberDeclaration ::= type methodDeclarationfieldDeclaration
methodDeclaration ::= Identifier methodDeclaratorRest
fieldDeclaration ::=
variableDeclarators ";"voidMethodDeclaratorRest ::= formalParameters "throws" qualifiedNameList methodBody";"
superSuffix ::= arguments "." Identifier arguments
literal ::=
integerLiteral
FloatingPointLiteral
CharacterLiteral
StringLiteral
booleanLiteral
"null"integerLiteral ::= HexLiteral OctalLiteral DecimalLiteral
HexLiteral ::= "0" "x""X" HexDigit IntegerTypeSuffix
HexDigit ::= "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" "A" "B" "C" "D" "E" "F"
IntegerTypeSuffix ::= "l" "L"
OctalLiteral ::= "0" "0""1""2""3""4""5""6""7" IntegerTypeSuffix
DecimalLiteral ::= "0""1""2""3""4""5""6""7""8""9" "0""1""2""3""4""5""6""7""8""9" IntegerTypeSuffix
FloatingPointLiteral ::= "0""1""2""3""4""5""6""7""8""9" "." "0""1""2""3""4""5""6""7""8""9" Exponent FloatTypeSuffix "." "0""1""2""3""4""5""6""7""8""9" Exponent FloatTypeSuffix "0""1""2""3""4""5""6""7""8""9" Exponent FloatTypeSuffix "0""1""2""3""4""5""6""7""8""9" FloatTypeSuffix
Exponent ::= "e""E" "+""-" "0""1""2""3""4""5""6""7""8""9"
FloatTypeSuffix ::= "f" "F" "d" "D"
CharacterLiteral ::= "\'" EscapeSequencestring "\'"
EscapeSequence ::= "\\" "b""t""n""f""r""\"""\'""\\" UnicodeEscape OctalEscape
UnicodeEscape ::= "\\" "u" HexDigit HexDigit HexDigit HexDigit
OctalEscape ::= "\\" "0""1""2""3" "0""1""2""3""4""5""6""7" "0""1""2""3""4""5""6""7" "\\" "0""1""2""3""4""5""6""7" "0""1""2""3""4""5""6""7" "\\" "0""1""2""3""4""5""6""7"
StringLiteral ::= """ EscapeSequencestring """
booleanLiteral ::= "true" "false"
creator ::= nonWildcardTypeArguments createdName classCreatorRest createdName arrayCreatorRestclassCreatorRest
createdName ::= classOrInterfaceType primitiveType
arrayCreatorRest ::= "[" "]" "[" "]" arrayInitializerexpression "]" "[" expression "]" "[" "]"
selector ::= "." Identifier arguments "." "this" "." "super" superSuffix "." "new" innerCreator "[" expression "]"
shiftOp ::= [t1]::"<" [t2]::"<" [t1]::">" [t2]::">" [t3]::">" [t1]::">" [t2]::">"
relationalOp ::= [t1]::"<" [t2]::"=" [t1]::">" [t2]::"=" "<" ">"
elementValueArrayInitializer ::= "{" elementValue "," elementValue "," "}"
packageDeclaration ::= "package" qualifiedName ";"
importDeclaration ::= "import" "static" qualifiedName "." "*" ";"
typeDeclaration ::=
classOrInterfaceDeclaration
";"