Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: java/java-5/stahl/extracted
Source used for this grammar: Michael Stahl, java15.g
, 2004 [ANTLR2]
compilationUnit
, packageDefinition
, annotations
, annotation
, AT
, identifier
, IDENT
, DOT
, annotationInit
, LPAREN
, annotationMemberInit
, ASSIGN
, annotationMemberValue
, conditionalExpression
, logicalOrExpression
, logicalAndExpression
, inclusiveOrExpression
, exclusiveOrExpression
, andExpression
, equalityExpression
, relationalExpression
, shiftExpression
, additiveExpression
, multiplicativeExpression
, unaryExpression
, INC
, DEC
, MINUS
, PLUS
, unaryExpressionNotPlusMinus
, BNOT
, LNOT
, builtInTypeSpec
, builtInType
, LBRACK
, RBRACK
, RPAREN
, classTypeSpec
, classOrInterfaceType
, typeArguments
, LT
, typeArgument
, QUESTION
, referenceTypeSpec
, arrayTypeSpec
, COMMA
, typeArgumentsEnd
, GT
, SR
, BSR
, postfixExpression
, primaryExpression
, identPrimary
, argList
, expressionList
, expression
, assignmentExpression
, PLUS_ASSIGN
, MINUS_ASSIGN
, STAR_ASSIGN
, DIV_ASSIGN
, MOD_ASSIGN
, SR_ASSIGN
, BSR_ASSIGN
, SL_ASSIGN
, BAND_ASSIGN
, BXOR_ASSIGN
, BOR_ASSIGN
, constant
, NUM_INT
, EXPONENT
, FLOAT_SUFFIX
, HEX_DIGIT
, CHAR_LITERAL
, ESC
, STRING_LITERAL
, NUM_FLOAT
, NUM_LONG
, NUM_DOUBLE
, newExpression
, type
, classBlock
, LCURLY
, classField
, modifiers
, modifier
, innerTypeDef
, enumDefinition
, ENUM
, implementsClause
, enumBlock
, enumConst
, enumConstInit
, SEMI
, RCURLY
, classDefinition
, typeParameters
, typeParameter
, BAND
, superClassClause
, interfaceDefinition
, interfaceExtends
, interfaceBlock
, interfaceField
, memberDef
, typeSpec
, parameterDeclarationList
, parameterDeclaration
, parameterModifier
, ELLIPSIS
, declaratorBrackets
, throwsClause
, compoundStatement
, statement
, declaration
, variableDefinitions
, variableDeclarator
, varInitializer
, initializer
, arrayInitializer
, COLON
, forInit
, forCond
, forIter
, casesGroup
, aCase
, caseSList
, tryBlock
, handler
, finallyClause
, ASSERT
, annotationTypeDefinition
, annotationBlock
, annotationField
, defaultValue
, ctorHead
, constructorBody
, explicitConstructorInvocation
, newArrayDeclarator
, STAR
, DIV
, MOD
, SL
, LE
, GE
, NOT_EQUAL
, EQUAL
, BXOR
, BOR
, LAND
, LOR
, annotationMemberArrayInitializer
, importDefinition
, identifierStar
, typeDefinition
), 1 root (compilationUnit
), 0 top (—), 0 bottom (—).[p]
, [lp]
5, [lpb]
, [lb]
6, [lt]
2, [q]
, [ta1]
2, [lp3]
, [ta2]
2, [lps]
, [in]
, [de]
, [lbt]
, [lbc]
, [f1]
, [f2]
, [f3]
, [f4]
, [mods]
3, [it]
3, [tp]
4, [h]
, [s]
2, [md]
2, [s3]
, [s4]
, [ed]
, [cd]
, [id]
3, [ad]
, [ic]
2, [eb]
, [i]
3, [sc]
, [cb]
, [ie]
, [ib]
, [e]
, [t]
3, [param]
, [rt]
, [tc]
, [s2]
, [v]
4, [pm]
, [el]
, [pd]
, [lc]
4, [m]
3, [c]
, [d]
, [ab]
, [ts]
, [dv]
, [lp1]
, [lp2]
.compilationUnit ::=packageDefinition ε importDefinition typeDefinition
packageDefinition ::=
annotations [p]::"package" identifier SEMI
annotations ::=
annotation
annotation ::= AT identifier annotationInit
AT ::=
"@"
identifier ::= IDENTDOT IDENT
IDENT ::= "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""_""$" "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""_""0""1""2""3""4""5""6""7""8""9""$"
DOT ::=
"."
annotationInit ::= [lp]::LPARENannotationMemberInit COMMA annotationMemberInit annotationMemberValue ε RPAREN ε
LPAREN ::=
"("
annotationMemberInit ::= IDENT ASSIGN annotationMemberValue
ASSIGN ::=
"="
annotationMemberValue ::= annotation conditionalExpression annotationMemberArrayInitializer
conditionalExpression ::= logicalOrExpressionQUESTION assignmentExpression COLON conditionalExpression
logicalOrExpression ::= logicalAndExpressionLOR logicalAndExpression
logicalAndExpression ::= inclusiveOrExpressionLAND inclusiveOrExpression
inclusiveOrExpression ::= exclusiveOrExpressionBOR exclusiveOrExpression
exclusiveOrExpression ::= andExpressionBXOR andExpression
andExpression ::= equalityExpressionBAND equalityExpression
equalityExpression ::= relationalExpressionNOT_EQUAL EQUAL relationalExpression
relationalExpression ::= shiftExpression "instanceof" typeSpecLT GT LE GE shiftExpression
shiftExpression ::= additiveExpressionSL SR BSR additiveExpression
additiveExpression ::= multiplicativeExpressionPLUS MINUS multiplicativeExpression
multiplicativeExpression ::= unaryExpressionSTAR DIV MOD unaryExpression
unaryExpression ::= INC unaryExpression DEC unaryExpression MINUS unaryExpression PLUS unaryExpression unaryExpressionNotPlusMinus
INC ::=
"++"
DEC ::=
"--"
MINUS ::=
"-"
PLUS ::=
"+"
unaryExpressionNotPlusMinus ::= BNOT unaryExpression LNOT unaryExpression [lpb]::LPAREN builtInTypeSpec RPAREN unaryExpression [lp]::LPAREN classTypeSpec RPAREN unaryExpressionNotPlusMinus postfixExpression
BNOT ::=
"~"
LNOT ::=
"!"
builtInTypeSpec ::= builtInType[lb]::LBRACK RBRACK
builtInType ::= "void" "boolean" "byte" "char" "short" "int" "float" "long" "double"
LBRACK ::=
"["
RBRACK ::=
"]"
RPAREN ::=
")"
classTypeSpec ::= classOrInterfaceType[lb]::LBRACK RBRACK
classOrInterfaceType ::= IDENT typeArgumentsDOT IDENT typeArguments
typeArguments ::= [lt]::LT typeArgumentCOMMA typeArgument typeArgumentsEnd ε
LT ::=
"<"
typeArgument ::= [q]::QUESTION "extends" referenceTypeSpec"super" referenceTypeSpec referenceTypeSpec
QUESTION ::=
"?"
referenceTypeSpec ::= classTypeSpec arrayTypeSpec
arrayTypeSpec ::= builtInType[lb]::LBRACK RBRACK
COMMA ::=
","
typeArgumentsEnd ::= GT SR BSR
GT ::=
">"
SR ::=
">>"
BSR ::=
">>>"
postfixExpression ::= primaryExpression "this" DOT [ta1]::typeArguments IDENT [lp]::LPAREN argList RPAREN"super" [lp3]::LPAREN argList RPAREN DOT [ta2]::typeArguments IDENT [lps]::LPAREN argList RPAREN DOT newExpression [lb]::LBRACK expression RBRACK [in]::INC [de]::DECDOT
primaryExpression ::= identPrimary "class" constant "true" "false" "null" newExpression "this" "super" LPAREN assignmentExpression RPAREN builtInType [lbt]::LBRACK RBRACK DOT "class"DOT
identPrimary ::= [ta1]::typeArguments IDENTDOT [ta2]::typeArguments IDENT ε [lp]::LPAREN argList RPAREN [lbc]::LBRACK RBRACK
argList ::= expressionList ε
expressionList ::= expressionCOMMA expression
expression ::= assignmentExpression
assignmentExpression ::= conditionalExpressionASSIGN PLUS_ASSIGN MINUS_ASSIGN STAR_ASSIGN DIV_ASSIGN MOD_ASSIGN SR_ASSIGN BSR_ASSIGN SL_ASSIGN BAND_ASSIGN BXOR_ASSIGN BOR_ASSIGN assignmentExpression
PLUS_ASSIGN ::=
"+="
MINUS_ASSIGN ::=
"-="
STAR_ASSIGN ::=
"*="
DIV_ASSIGN ::=
"/="
MOD_ASSIGN ::=
"%="
SR_ASSIGN ::=
">>="
BSR_ASSIGN ::=
">>>="
SL_ASSIGN ::=
"<<="
BAND_ASSIGN ::=
"&="
BXOR_ASSIGN ::=
"^="
BOR_ASSIGN ::=
"|="
constant ::= NUM_INT CHAR_LITERAL STRING_LITERAL NUM_FLOAT NUM_LONG NUM_DOUBLE
NUM_INT ::= "." "." ".""0""1""2""3""4""5""6""7""8""9" EXPONENT [f1]::FLOAT_SUFFIX "0" "x""X" HEX_DIGIT"0""1""2""3""4""5""6""7""8""9""0""1""2""3""4""5""6""7""1""2""3""4""5""6""7""8""9" "0""1""2""3""4""5""6""7""8""9" "l""L""." "0""1""2""3""4""5""6""7""8""9" EXPONENT [f2]::FLOAT_SUFFIX EXPONENT [f3]::FLOAT_SUFFIX [f4]::FLOAT_SUFFIX
EXPONENT ::= "e""E" "+""-" "0""1""2""3""4""5""6""7""8""9"
FLOAT_SUFFIX ::= "f" "F" "d" "D"
HEX_DIGIT ::= "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" "a" "b" "c" "d" "e" "f"
CHAR_LITERAL ::= "\'" ESC string "\'"
ESC ::= "\\" "n""r""t""b""f"""""\'""\\""u" HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT"0""1""2""3" "0""1""2""3""4""5""6""7" "0""1""2""3""4""5""6""7""4""5""6""7" "0""1""2""3""4""5""6""7"
STRING_LITERAL ::= """ ESC string """
NUM_FLOAT ::= "." "0""1""2""3""4""5""6""7""8""9" EXPONENT "f""F" "0" "0""1""2""3""4""5""6""7""8""9" "." EXPONENT"f""F" "1""2""3""4""5""6""7""8""9" "0""1""2""3""4""5""6""7""8""9" "." "0""1""2""3""4""5""6""7""8""9" EXPONENT "f""F" EXPONENT
NUM_LONG ::= "1""2""3""4""5""6""7""8""9" "0""1""2""3""4""5""6""7""8""9" "l""L"
NUM_DOUBLE ::= "." "0""1""2""3""4""5""6""7""8""9" EXPONENT "d""D" "0" "0""1""2""3""4""5""6""7""8""9" "." EXPONENT"d""D" "1""2""3""4""5""6""7""8""9" "0""1""2""3""4""5""6""7""8""9" "." "0""1""2""3""4""5""6""7""8""9" EXPONENT "d""D" EXPONENT
newExpression ::= "new" typeArguments type LPAREN argList RPAREN classBlock newArrayDeclarator arrayInitializer
type ::= classOrInterfaceType builtInType
classBlock ::= LCURLYclassField SEMI RCURLY
LCURLY ::=
"{"
classField ::= [mods]::modifiers "static" [s3]::compoundStatement [s4]::compoundStatement[it]::innerTypeDef [tp]::typeParameters [h]::ctorHead [s]::constructorBody [md]::memberDef
modifiers ::=modifier annotation
modifier ::= "private" "public" "protected" "static" "transient" "final" "abstract" "native" "threadsafe" "synchronized" "volatile" "strictfp"
innerTypeDef ::= [ed]::enumDefinition [cd]::classDefinition [id]::interfaceDefinition [ad]::annotationTypeDefinition
enumDefinition ::= ENUM IDENT [ic]::implementsClause [eb]::enumBlock
ENUM ::=
"enum"
implementsClause ::= "implements" classOrInterfaceType COMMA classOrInterfaceType[i]::
enumBlock ::= LCURLYenumConst COMMA enumConst COMMA SEMI classField SEMI RCURLY
enumConst ::=
annotations IDENT enumConstInit classBlock
enumConstInit ::= [lp]::LPAREN argList RPAREN ε
SEMI ::=
";"
RCURLY ::=
"}"
classDefinition ::=
"class" IDENT [tp]::typeParameters [sc]::superClassClause [ic]::implementsClause [cb]::classBlock
typeParameters ::= [lt]::LT typeParameterCOMMA typeParameter typeArgumentsEnd ε
typeParameter ::= IDENT "extends" classOrInterfaceType BAND classOrInterfaceType
BAND ::=
"&"
superClassClause ::= "extends" classOrInterfaceType
interfaceDefinition ::=
"interface" IDENT [tp]::typeParameters [ie]::interfaceExtends [ib]::interfaceBlock
interfaceExtends ::= "extends" classOrInterfaceType COMMA classOrInterfaceType[e]::
interfaceBlock ::= LCURLYinterfaceField SEMI RCURLY
interfaceField ::= [mods]::modifiers[it]::innerTypeDef [tp]::typeParameters [md]::memberDef
memberDef ::= [t]::typeSpecIDENT LPAREN [param]::parameterDeclarationList RPAREN [rt]::declaratorBrackets [tc]::throwsClause SEMI [s2]::compoundStatement [v]::variableDefinitions SEMI
typeSpec ::= classTypeSpec builtInTypeSpec
parameterDeclarationList ::=parameterDeclaration COMMA parameterDeclaration
parameterDeclaration ::=
[pm]::parameterModifier [t]::typeSpec [el]::ELLIPSIS
[id]::IDENT [pd]::declaratorBracketsparameterModifier ::= "final" annotation
ELLIPSIS ::=
"..."
declaratorBrackets ::=[lb]::LBRACK RBRACK
throwsClause ::= "throws" identifier COMMA identifier
compoundStatement ::=
[lc]::LCURLY statement
RCURLYstatement ::= compoundStatement declaration SEMI expression SEMI [m]::modifiers "if" LPAREN expression RPAREN statement "else" statement "for" LPAREN parameterDeclaration COLON expression forInit SEMI forCond SEMI forIter RPAREN statement "while" LPAREN expression RPAREN statement "do" statement "while" LPAREN expression RPAREN SEMI "break" IDENT SEMI "continue" IDENT SEMI "return" expression SEMI "switch" LPAREN expression RPAREN LCURLY casesGroup RCURLY tryBlock "throw" expression SEMI "synchronized" LPAREN expression RPAREN compoundStatement ASSERT expression COLON expression SEMI [s]::SEMIenumDefinition classDefinition IDENT [c]::COLON statement
declaration ::= [m]::modifiers [t]::typeSpec [v]::variableDefinitions
variableDefinitions ::= variableDeclaratorCOMMA variableDeclarator
variableDeclarator ::= [id]::IDENT [d]::declaratorBrackets [v]::varInitializer
varInitializer ::=ASSIGN initializer
initializer ::= expression arrayInitializer
arrayInitializer ::= [lc]::LCURLYinitializer COMMA initializer COMMA RCURLY
COLON ::=
":"
forInit ::=declaration expressionList
forCond ::=
expression
forIter ::=
expressionList
casesGroup ::=
aCase
caseSListaCase ::= "case" expression"default" COLON
caseSList ::=
statement
tryBlock ::= "try" compoundStatement handler finallyClause
handler ::=
"catch" LPAREN parameterDeclaration RPAREN compoundStatement
finallyClause ::=
"finally" compoundStatement
ASSERT ::=
"assert"
annotationTypeDefinition ::=
AT "interface" IDENT [ab]::annotationBlock
annotationBlock ::= LCURLYannotationField SEMI RCURLY
annotationField ::= [mods]::modifiers[it]::innerTypeDef [ts]::typeSpec [i]::IDENT LPAREN RPAREN [dv]::defaultValue SEMI [v]::variableDefinitions SEMI
defaultValue ::= "default" annotationMemberValue
ctorHead ::=
IDENT LPAREN parameterDeclarationList RPAREN throwsClause
constructorBody ::= [lc]::LCURLY explicitConstructorInvocationstatement RCURLY
explicitConstructorInvocation ::= typeArguments "this" [lp1]::LPAREN argList RPAREN SEMI"super" [lp2]::LPAREN argList RPAREN SEMI
newArrayDeclarator ::=[lb]::LBRACK expression RBRACK
STAR ::=
"*"
DIV ::=
"/"
MOD ::=
"%"
SL ::=
"<<"
LE ::=
"<="
GE ::=
">="
NOT_EQUAL ::=
"!="
EQUAL ::=
"=="
BXOR ::=
"^"
BOR ::=
"|"
LAND ::=
"&&"
LOR ::=
"||"
annotationMemberArrayInitializer ::= [lc]::LCURLYannotationMemberValue COMMA annotationMemberValue COMMA RCURLY
importDefinition ::= [i]::"import" "static" identifierStar SEMI
identifierStar ::= IDENTDOT IDENT DOT STAR
typeDefinition ::= [m]::modifiersclassDefinition enumDefinition interfaceDefinition annotationTypeDefinition SEMI