Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: java/java-5/habelitz/extracted
Source used for this grammar: Dieter Habelitz, Java.g
, 2008 [ANTLR3]
javaSource
, compilationUnit
, annotationList
, annotation
, AT
, qualifiedIdentifier
, IDENT
, JAVA_ID_START
, JAVA_ID_PART
, DOT
, annotationInit
, LPAREN
, annotationInitializers
, annotationInitializer
, ASSIGN
, annotationElementValue
, annotationElementValueExpression
, conditionalExpression
, logicalOrExpression
, logicalAndExpression
, inclusiveOrExpression
, exclusiveOrExpression
, andExpression
, equalityExpression
, instanceOfExpression
, relationalExpression
, shiftExpression
, additiveExpression
, multiplicativeExpression
, unaryExpression
, PLUS
, MINUS
, INC
, postfixedExpression
, primaryExpression
, parenthesizedExpression
, expression
, assignmentExpression
, PLUS_ASSIGN
, MINUS_ASSIGN
, STAR_ASSIGN
, DIV_ASSIGN
, AND_ASSIGN
, OR_ASSIGN
, XOR_ASSIGN
, MOD_ASSIGN
, SHIFT_LEFT_ASSIGN
, SHIFT_RIGHT_ASSIGN
, BIT_SHIFT_RIGHT_ASSIGN
, RPAREN
, literal
, HEX_LITERAL
, HEX_DIGIT
, INTEGER_TYPE_SUFFIX
, OCTAL_LITERAL
, DECIMAL_LITERAL
, FLOATING_POINT_LITERAL
, EXPONENT
, FLOAT_TYPE_SUFFIX
, CHARACTER_LITERAL
, ESCAPE_SEQUENCE
, UNICODE_ESCAPE
, OCTAL_ESCAPE
, STRING_LITERAL
, TRUE
, FALSE
, NULL
, newExpression
, NEW
, primitiveType
, BOOLEAN
, CHAR
, BYTE
, SHORT
, INT
, LONG
, FLOAT
, DOUBLE
, newArrayConstruction
, arrayDeclaratorList
, arrayDeclarator
, LBRACK
, RBRACK
, arrayInitializer
, LCURLY
, variableInitializer
, COMMA
, RCURLY
, genericTypeArgumentListSimplified
, LESS_THAN
, genericTypeArgumentSimplified
, type
, simpleType
, objectType
, qualifiedTypeIdent
, typeIdent
, genericTypeArgumentList
, genericTypeArgument
, QUESTION
, genericWildcardBoundType
, EXTENDS
, SUPER
, genericTypeListClosing
, GREATER_THAN
, SHIFT_RIGHT
, BIT_SHIFT_RIGHT
, qualifiedTypeIdentSimplified
, typeIdentSimplified
, arguments
, expressionList
, classBody
, classScopeDeclarations
, block
, blockStatement
, localVariableDeclaration
, localModifierList
, localModifier
, FINAL
, classFieldDeclaratorList
, classFieldDeclarator
, variableDeclaratorId
, SEMI
, typeDeclaration
, modifierList
, modifier
, PUBLIC
, PROTECTED
, PRIVATE
, STATIC
, ABSTRACT
, NATIVE
, SYNCHRONIZED
, TRANSIENT
, VOLATILE
, STRICTFP
, classTypeDeclaration
, CLASS
, genericTypeParameterList
, genericTypeParameter
, bound
, AND
, classExtendsClause
, implementsClause
, IMPLEMENTS
, typeList
, interfaceTypeDeclaration
, INTERFACE
, interfaceExtendsClause
, interfaceBody
, interfaceScopeDeclarations
, formalParameterList
, formalParameterStandardDecl
, formalParameterVarArgDecl
, ELLIPSIS
, throwsClause
, THROWS
, qualifiedIdentList
, VOID
, interfaceFieldDeclaratorList
, interfaceFieldDeclarator
, enumTypeDeclaration
, ENUM
, enumBody
, enumScopeDeclarations
, enumConstants
, enumConstant
, enumClassScopeDeclarations
, annotationTypeDeclaration
, annotationBody
, annotationScopeDeclarations
, annotationDefaultValue
, DEFAULT
, statement
, ASSERT
, COLON
, IF
, ELSE
, FOR
, forInit
, forCondition
, forUpdater
, WHILE
, DO
, TRY
, catches
, catchClause
, CATCH
, finallyClause
, FINALLY
, SWITCH
, switchBlockLabels
, switchCaseLabels
, switchCaseLabel
, CASE
, switchDefaultLabel
, RETURN
, THROW
, BREAK
, CONTINUE
, qualifiedIdentExpression
, THIS
, innerNewExpression
, DEC
, unaryExpressionNotPlusMinus
, NOT
, LOGICAL_NOT
, STAR
, DIV
, MOD
, SHIFT_LEFT
, LESS_OR_EQUAL
, GREATER_OR_EQUAL
, INSTANCEOF
, EQUAL
, NOT_EQUAL
, XOR
, OR
, LOGICAL_AND
, LOGICAL_OR
, annotationElementValueArrayInitializer
, packageDeclaration
, PACKAGE
, importDeclaration
, IMPORT
, DOTSTAR
, typeDecls
), 1 root (javaSource
), 0 top (—), 0 bottom (—).[ident]
2, [outerDot]
2, [Super]
3, [innerDot]
2, [expr1]
, [expr2]
, [ifStat]
, [elseStat]
.javaSource ::= compilationUnit
compilationUnit ::= annotationList packageDeclarationimportDeclaration typeDecls
annotationList ::=
annotation
annotation ::=
AT qualifiedIdentifier annotationInit
AT ::=
"@"
qualifiedIdentifier ::= IDENTDOT [ident]::IDENT
IDENT ::=
JAVA_ID_START JAVA_ID_PART
JAVA_ID_START ::= "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"
JAVA_ID_PART ::= JAVA_ID_START "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
DOT ::=
"."
annotationInit ::= LPAREN annotationInitializers RPAREN
LPAREN ::=
"("
annotationInitializers ::= annotationInitializerCOMMA annotationInitializer annotationElementValue
annotationInitializer ::= IDENT ASSIGN annotationElementValue
ASSIGN ::=
"="
annotationElementValue ::= annotationElementValueExpression annotation annotationElementValueArrayInitializer
annotationElementValueExpression ::= conditionalExpression
conditionalExpression ::= logicalOrExpressionQUESTION assignmentExpression COLON conditionalExpression
logicalOrExpression ::= logicalAndExpressionLOGICAL_OR logicalAndExpression
logicalAndExpression ::= inclusiveOrExpressionLOGICAL_AND inclusiveOrExpression
inclusiveOrExpression ::= exclusiveOrExpressionOR exclusiveOrExpression
exclusiveOrExpression ::= andExpressionXOR andExpression
andExpression ::= equalityExpressionAND equalityExpression
equalityExpression ::= instanceOfExpressionEQUAL NOT_EQUAL instanceOfExpression
instanceOfExpression ::= relationalExpressionINSTANCEOF type
relationalExpression ::= shiftExpressionLESS_OR_EQUAL GREATER_OR_EQUAL LESS_THAN GREATER_THAN shiftExpression
shiftExpression ::= additiveExpressionBIT_SHIFT_RIGHT SHIFT_RIGHT SHIFT_LEFT additiveExpression
additiveExpression ::= multiplicativeExpressionPLUS MINUS multiplicativeExpression
multiplicativeExpression ::= unaryExpressionSTAR DIV MOD unaryExpression
unaryExpression ::= PLUS unaryExpression MINUS unaryExpression INC postfixedExpression DEC postfixedExpression unaryExpressionNotPlusMinus
PLUS ::=
"+"
MINUS ::=
"-"
INC ::=
"++"
postfixedExpression ::= primaryExpression[outerDot]::DOT genericTypeArgumentListSimplified IDENT arguments THIS [Super]::SUPER arguments SUPER [innerDot]::DOT IDENT arguments innerNewExpression LBRACK expression RBRACK INC DEC
primaryExpression ::= parenthesizedExpression literal newExpression qualifiedIdentExpression genericTypeArgumentListSimplifiedSUPER arguments DOT IDENT arguments IDENT arguments THIS arguments THIS arguments SUPER arguments SUPER DOT IDENT arguments ε primitiveType arrayDeclarator DOT CLASS VOID DOT CLASS
parenthesizedExpression ::= LPAREN expression RPAREN
expression ::= assignmentExpression
assignmentExpression ::= conditionalExpressionASSIGN PLUS_ASSIGN MINUS_ASSIGN STAR_ASSIGN DIV_ASSIGN AND_ASSIGN OR_ASSIGN XOR_ASSIGN MOD_ASSIGN SHIFT_LEFT_ASSIGN SHIFT_RIGHT_ASSIGN BIT_SHIFT_RIGHT_ASSIGN assignmentExpression
PLUS_ASSIGN ::=
"+="
MINUS_ASSIGN ::=
"-="
STAR_ASSIGN ::=
"*="
DIV_ASSIGN ::=
"/="
AND_ASSIGN ::=
"&="
OR_ASSIGN ::=
"|="
XOR_ASSIGN ::=
"^="
MOD_ASSIGN ::=
"%="
SHIFT_LEFT_ASSIGN ::=
"<<="
SHIFT_RIGHT_ASSIGN ::=
">>="
BIT_SHIFT_RIGHT_ASSIGN ::=
">>>="
RPAREN ::=
")"
literal ::= HEX_LITERAL OCTAL_LITERAL DECIMAL_LITERAL FLOATING_POINT_LITERAL CHARACTER_LITERAL STRING_LITERAL TRUE FALSE NULL
HEX_LITERAL ::= "0" "x""X" HEX_DIGIT INTEGER_TYPE_SUFFIX
HEX_DIGIT ::= "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" "A" "B" "C" "D" "E" "F"
INTEGER_TYPE_SUFFIX ::= "l" "L"
OCTAL_LITERAL ::= "0" "0""1""2""3""4""5""6""7" INTEGER_TYPE_SUFFIX
DECIMAL_LITERAL ::= "0""1""2""3""4""5""6""7""8""9" "0""1""2""3""4""5""6""7""8""9" INTEGER_TYPE_SUFFIX
FLOATING_POINT_LITERAL ::= "0""1""2""3""4""5""6""7""8""9" DOT "0""1""2""3""4""5""6""7""8""9" EXPONENT FLOAT_TYPE_SUFFIX EXPONENT FLOAT_TYPE_SUFFIX FLOAT_TYPE_SUFFIX DOT "0""1""2""3""4""5""6""7""8""9" EXPONENT FLOAT_TYPE_SUFFIX
EXPONENT ::= "e""E" "+""-" "0""1""2""3""4""5""6""7""8""9"
FLOAT_TYPE_SUFFIX ::= "f" "F" "d" "D"
CHARACTER_LITERAL ::= "\'" ESCAPE_SEQUENCE string "\'"
ESCAPE_SEQUENCE ::= "\\" "b""t""n""f""r""\"""\'""\\" UNICODE_ESCAPE OCTAL_ESCAPE
UNICODE_ESCAPE ::= "\\" "u" HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
OCTAL_ESCAPE ::= "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"
STRING_LITERAL ::= """ ESCAPE_SEQUENCE string """
TRUE ::=
"true"
FALSE ::=
"false"
NULL ::=
"null"
newExpression ::= NEWprimitiveType newArrayConstruction genericTypeArgumentListSimplified qualifiedTypeIdentSimplified newArrayConstruction arguments classBody
NEW ::=
"new"
primitiveType ::= BOOLEAN CHAR BYTE SHORT INT LONG FLOAT DOUBLE
BOOLEAN ::=
"boolean"
CHAR ::=
"char"
BYTE ::=
"byte"
SHORT ::=
"short"
INT ::=
"int"
LONG ::=
"long"
FLOAT ::=
"float"
DOUBLE ::=
"double"
newArrayConstruction ::= arrayDeclaratorList arrayInitializer LBRACK expression RBRACKLBRACK expression RBRACK arrayDeclaratorList
arrayDeclaratorList ::=
arrayDeclarator
arrayDeclarator ::= LBRACK RBRACK
LBRACK ::=
"["
RBRACK ::=
"]"
arrayInitializer ::= LCURLYvariableInitializer COMMA variableInitializer COMMA RCURLY
LCURLY ::=
"{"
variableInitializer ::= arrayInitializer expression
COMMA ::=
","
RCURLY ::=
"}"
genericTypeArgumentListSimplified ::= LESS_THAN genericTypeArgumentSimplifiedCOMMA genericTypeArgumentSimplified genericTypeListClosing
LESS_THAN ::=
"<"
genericTypeArgumentSimplified ::= type QUESTION
type ::= simpleType objectType
simpleType ::=
primitiveType arrayDeclaratorList
objectType ::=
qualifiedTypeIdent arrayDeclaratorList
qualifiedTypeIdent ::= typeIdentDOT typeIdent
typeIdent ::=
IDENT genericTypeArgumentList
genericTypeArgumentList ::= LESS_THAN genericTypeArgumentCOMMA genericTypeArgument genericTypeListClosing
genericTypeArgument ::=
type
QUESTION genericWildcardBoundType
QUESTION ::=
"?"
genericWildcardBoundType ::=EXTENDS SUPER type
EXTENDS ::=
"extends"
SUPER ::=
"super"
genericTypeListClosing ::= GREATER_THAN SHIFT_RIGHT BIT_SHIFT_RIGHT ε
GREATER_THAN ::=
">"
SHIFT_RIGHT ::=
">>"
BIT_SHIFT_RIGHT ::=
">>>"
qualifiedTypeIdentSimplified ::= typeIdentSimplifiedDOT typeIdentSimplified
typeIdentSimplified ::=
IDENT genericTypeArgumentListSimplified
arguments ::=
LPAREN expressionList
RPARENexpressionList ::= expressionCOMMA expression
classBody ::=
LCURLY classScopeDeclarations
RCURLYclassScopeDeclarations ::= block STATIC block modifierListgenericTypeParameterList type IDENT formalParameterList arrayDeclaratorList throwsClause block SEMI VOID IDENT formalParameterList throwsClause block SEMI [ident]::IDENT formalParameterList throwsClause block type classFieldDeclaratorList SEMI typeDeclaration SEMI
block ::=
LCURLY blockStatement
RCURLYblockStatement ::= localVariableDeclaration SEMI typeDeclaration statement
localVariableDeclaration ::= localModifierList type classFieldDeclaratorList
localModifierList ::=
localModifier
localModifier ::= FINAL annotation
FINAL ::=
"final"
classFieldDeclaratorList ::= classFieldDeclaratorCOMMA classFieldDeclarator
classFieldDeclarator ::= variableDeclaratorIdASSIGN variableInitializer
variableDeclaratorId ::=
IDENT arrayDeclaratorList
SEMI ::=
";"
typeDeclaration ::= modifierListclassTypeDeclaration interfaceTypeDeclaration enumTypeDeclaration annotationTypeDeclaration
modifierList ::=
modifier
modifier ::= PUBLIC PROTECTED PRIVATE STATIC ABSTRACT NATIVE SYNCHRONIZED TRANSIENT VOLATILE STRICTFP localModifier
PUBLIC ::=
"public"
PROTECTED ::=
"protected"
PRIVATE ::=
"private"
STATIC ::=
"static"
ABSTRACT ::=
"abstract"
NATIVE ::=
"native"
SYNCHRONIZED ::=
"synchronized"
TRANSIENT ::=
"transient"
VOLATILE ::=
"volatile"
STRICTFP ::=
"strictfp"
classTypeDeclaration ::= CLASS IDENT genericTypeParameterListclassExtendsClause implementsClause classBody
CLASS ::=
"class"
genericTypeParameterList ::= LESS_THAN genericTypeParameterCOMMA genericTypeParameter genericTypeListClosing
genericTypeParameter ::=
IDENT bound
bound ::= EXTENDS typeAND type
AND ::=
"&"
classExtendsClause ::= EXTENDS type
implementsClause ::= IMPLEMENTS typeList
IMPLEMENTS ::=
"implements"
typeList ::= typeCOMMA type
interfaceTypeDeclaration ::= INTERFACE IDENT genericTypeParameterListinterfaceExtendsClause interfaceBody
INTERFACE ::=
"interface"
interfaceExtendsClause ::= EXTENDS typeList
interfaceBody ::=
LCURLY interfaceScopeDeclarations
RCURLYinterfaceScopeDeclarations ::= modifierListgenericTypeParameterList type IDENT formalParameterList arrayDeclaratorList throwsClause SEMI VOID IDENT formalParameterList throwsClause SEMI type interfaceFieldDeclaratorList SEMI typeDeclaration SEMI
formalParameterList ::= LPARENformalParameterStandardDecl COMMA formalParameterStandardDecl COMMA formalParameterVarArgDecl formalParameterVarArgDecl ε RPAREN
formalParameterStandardDecl ::= localModifierList type variableDeclaratorId
formalParameterVarArgDecl ::= localModifierList type ELLIPSIS variableDeclaratorId
ELLIPSIS ::=
"..."
throwsClause ::= THROWS qualifiedIdentList
THROWS ::=
"throws"
qualifiedIdentList ::= qualifiedIdentifierCOMMA qualifiedIdentifier
VOID ::=
"void"
interfaceFieldDeclaratorList ::= interfaceFieldDeclaratorCOMMA interfaceFieldDeclarator
interfaceFieldDeclarator ::= variableDeclaratorId ASSIGN variableInitializer
enumTypeDeclaration ::=
ENUM IDENT implementsClause
enumBodyENUM ::=
"enum"
enumBody ::= LCURLY enumScopeDeclarations RCURLY
enumScopeDeclarations ::= enumConstants COMMAenumClassScopeDeclarations
enumConstants ::= enumConstantCOMMA enumConstant
enumConstant ::= annotationList IDENT argumentsclassBody
enumClassScopeDeclarations ::=
SEMI classScopeDeclarations
annotationTypeDeclaration ::= AT INTERFACE IDENT annotationBody
annotationBody ::=
LCURLY annotationScopeDeclarations
RCURLYannotationScopeDeclarations ::= modifierList typeIDENT LPAREN RPAREN annotationDefaultValue SEMI classFieldDeclaratorList SEMI typeDeclaration
annotationDefaultValue ::= DEFAULT annotationElementValue
DEFAULT ::=
"default"
statement ::= block ASSERT [expr1]::expressionCOLON [expr2]::expression SEMI SEMI IF parenthesizedExpression [ifStat]::statement ELSE [elseStat]::statement ε FOR LPAREN forInit SEMI forCondition SEMI forUpdater RPAREN statement localModifierList type IDENT COLON expression RPAREN statement WHILE parenthesizedExpression statement DO statement WHILE parenthesizedExpression SEMI TRY block catches finallyClause finallyClause SWITCH parenthesizedExpression LCURLY switchBlockLabels RCURLY SYNCHRONIZED parenthesizedExpression block RETURN expression SEMI THROW expression SEMI BREAK IDENT SEMI CONTINUE IDENT SEMI IDENT COLON statement expression SEMI SEMI
ASSERT ::=
"assert"
COLON ::=
":"
IF ::=
"if"
ELSE ::=
"else"
FOR ::=
"for"
forInit ::= localVariableDeclaration expressionList ε
forCondition ::=
expression
forUpdater ::=
expressionList
WHILE ::=
"while"
DO ::=
"do"
TRY ::=
"try"
catches ::=
catchClause
catchClause ::= CATCH LPAREN formalParameterStandardDecl RPAREN block
CATCH ::=
"catch"
finallyClause ::= FINALLY block
FINALLY ::=
"finally"
SWITCH ::=
"switch"
switchBlockLabels ::=
switchCaseLabels switchDefaultLabel
switchCaseLabelsswitchCaseLabels ::=
switchCaseLabel
switchCaseLabel ::=
CASE expression COLON blockStatement
CASE ::=
"case"
switchDefaultLabel ::=
DEFAULT COLON blockStatement
RETURN ::=
"return"
THROW ::=
"throw"
BREAK ::=
"break"
CONTINUE ::=
"continue"
qualifiedIdentExpression ::= qualifiedIdentifierarrayDeclarator DOT CLASS arguments [outerDot]::DOT CLASS genericTypeArgumentListSimplified [Super]::SUPER arguments SUPER [innerDot]::DOT IDENT arguments IDENT arguments THIS [Super]::SUPER arguments innerNewExpression
THIS ::=
"this"
innerNewExpression ::= NEW genericTypeArgumentListSimplifiedIDENT arguments classBody
DEC ::=
"--"
unaryExpressionNotPlusMinus ::= NOT unaryExpression LOGICAL_NOT unaryExpression LPAREN type RPAREN unaryExpression postfixedExpression
NOT ::=
"~"
LOGICAL_NOT ::=
"!"
STAR ::=
"*"
DIV ::=
"/"
MOD ::=
"%"
SHIFT_LEFT ::=
"<<"
LESS_OR_EQUAL ::=
"<="
GREATER_OR_EQUAL ::=
">="
INSTANCEOF ::=
"instanceof"
EQUAL ::=
"=="
NOT_EQUAL ::=
"!="
XOR ::=
"^"
OR ::=
"|"
LOGICAL_AND ::=
"&&"
LOGICAL_OR ::=
"||"
annotationElementValueArrayInitializer ::= LCURLYannotationElementValue COMMA annotationElementValue COMMA RCURLY
packageDeclaration ::= PACKAGE qualifiedIdentifier SEMI
PACKAGE ::=
"package"
importDeclaration ::= IMPORT STATICqualifiedIdentifier DOTSTAR SEMI
IMPORT ::=
"import"
DOTSTAR ::=
".*"
typeDecls ::= typeDeclaration SEMI