JLS中表达式的所有文法

时间:2022-10-19 05:01:16

3.8. Identifiers

Identifier:
    IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral

IdentifierChars:
    JavaLetter
    IdentifierChars JavaLetterOrDigit

JavaLetter:
    any Unicode character that is a Java letter (see below)

JavaLetterOrDigit:
    any Unicode character that is a Java letter-or-digit (see below)

  

15.8. Primary Expressions

Primary:
    PrimaryNoNewArray
    ArrayCreationExpression

PrimaryNoNewArray:
    Literal
    Type . class
    void . class
    this
    ClassName . this
    ( Expression )
    ClassInstanceCreationExpression
    FieldAccess
    MethodInvocation
    ArrayAccess

15.8.1. Lexical Literals

Literal:
    IntegerLiteral
    FloatingPointLiteral
    BooleanLiteral
    CharacterLiteral
    StringLiteral
    NullLiteral

  

  

15.9. Class Instance Creation Expressions

ClassInstanceCreationExpression:
    new TypeArgumentsopt TypeDeclSpecifier TypeArgumentsOrDiamondopt
                                                            ( ArgumentListopt ) ClassBodyopt
    Primary . new TypeArgumentsopt Identifier TypeArgumentsOrDiamondopt
                                                            ( ArgumentListopt ) ClassBodyopt

TypeArgumentsOrDiamond:
    TypeArguments
    <> 

ArgumentList:
    Expression
    ArgumentList , Expression

15.10. Array Creation Expressions

ArrayCreationExpression:
    new PrimitiveType DimExprs Dimsopt
    new ClassOrInterfaceType DimExprs Dimsopt
    new PrimitiveType Dims ArrayInitializer
    new ClassOrInterfaceType Dims ArrayInitializer

DimExprs:
    DimExpr
    DimExprs DimExpr

DimExpr:
    [ Expression ]

Dims:
    [ ]
    Dims [ ]

 

15.11. Field Access Expressions

FieldAccess:
    Primary . Identifier
    super . Identifier
    ClassName . super . Identifier

15.12. Method Invocation Expressions

MethodInvocation:
    MethodName ( ArgumentListopt )
    Primary . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
    super . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
    ClassName . super . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
    TypeName . NonWildTypeArguments Identifier ( ArgumentListopt )

The definition of ArgumentList from §15.9 is repeated here for convenience:  

ArgumentList:
    Expression
    ArgumentList , Expression

  

15.13. Array Access Expressions

ArrayAccess:
    ExpressionName [ Expression ]
    PrimaryNoNewArray [ Expression ]

 

15.14. Postfix Expressions

PostfixExpression:
    Primary
    ExpressionName
    PostIncrementExpression
    PostDecrementExpression

15.14.2. Postfix Increment Operator ++

PostIncrementExpression:
    PostfixExpression ++

15.14.3. Postfix Decrement Operator --

PostDecrementExpression:
    PostfixExpression --

15.15. Unary Operators

UnaryExpression:
    PreIncrementExpression
    PreDecrementExpression
    + UnaryExpression
    - UnaryExpression
    UnaryExpressionNotPlusMinus

PreIncrementExpression:
    ++ UnaryExpression

PreDecrementExpression:
    -- UnaryExpression

UnaryExpressionNotPlusMinus:
    PostfixExpression
    ~ UnaryExpression
    ! UnaryExpression
    CastExpression

15.16. Cast Expressions

CastExpression:
    ( PrimitiveType ) UnaryExpression
    ( ReferenceType ) UnaryExpressionNotPlusMinus

  

15.17. Multiplicative Operators

MultiplicativeExpression:
    UnaryExpression
    MultiplicativeExpression * UnaryExpression
    MultiplicativeExpression / UnaryExpression
    MultiplicativeExpression % UnaryExpression

  

15.18. Additive Operators

AdditiveExpression:
    MultiplicativeExpression
    AdditiveExpression + MultiplicativeExpression
    AdditiveExpression - MultiplicativeExpression

  

15.19. Shift Operators

ShiftExpression:
    AdditiveExpression
    ShiftExpression << AdditiveExpression
    ShiftExpression >> AdditiveExpression
    ShiftExpression >>> AdditiveExpression

  

15.20. Relational Operators

RelationalExpression:
    ShiftExpression
    RelationalExpression < ShiftExpression
    RelationalExpression > ShiftExpression
    RelationalExpression <= ShiftExpression
    RelationalExpression >= ShiftExpression
    RelationalExpression instanceof ReferenceType

  

15.21. Equality Operators

EqualityExpression:
    RelationalExpression
    EqualityExpression == RelationalExpression
    EqualityExpression != RelationalExpression

  

15.22. Bitwise and Logical Operators

AndExpression:
    EqualityExpression
    AndExpression & EqualityExpression

ExclusiveOrExpression:
    AndExpression
    ExclusiveOrExpression ^ AndExpression

InclusiveOrExpression:
    ExclusiveOrExpression
    InclusiveOrExpression | ExclusiveOrExpression

  

 

15.23. Conditional-And Operator &&

ConditionalAndExpression:
    InclusiveOrExpression
    ConditionalAndExpression && InclusiveOrExpression

15.24. Conditional-Or Operator ||

ConditionalOrExpression:
    ConditionalAndExpression
    ConditionalOrExpression || ConditionalAndExpression

  

15.25. Conditional Operator ? :

ConditionalExpression:
    ConditionalOrExpression
    ConditionalOrExpression ? Expression : ConditionalExpression

  

  

15.26. Assignment Operators

AssignmentExpression:
    ConditionalExpression
    Assignment

Assignment:
    LeftHandSide AssignmentOperator AssignmentExpression

LeftHandSide:
    ExpressionName
    FieldAccess
    ArrayAccess

AssignmentOperator: one of
    = *= /= %= += -= <<= >>= >>>= &= ^= |=

  

15.27. Expression

Expression:
    AssignmentExpression

  

15.28. Constant Expressions

ConstantExpression:
    Expression
StatementExpression:
    Assignment
    PreIncrementExpression
    PreDecrementExpression
    PostIncrementExpression
    PostDecrementExpression
    MethodInvocation
    ClassInstanceCreationExpression

  

  

 

  

Primary:
    PrimaryNoNewArray
    ArrayCreationExpression
        new PrimitiveType DimExprs Dimsopt
	new ClassOrInterfaceType DimExprs Dimsopt
	new PrimitiveType Dims ArrayInitializer
	new ClassOrInterfaceType Dims ArrayInitializer

PrimaryNoNewArray:
    ( Expression )
    Literal

    this
    ClassName . this

    Type . class
    void . class
    ClassInstanceCreationExpression
        new TypeArgumentsopt TypeDeclSpecifier TypeArgumentsOrDiamondopt
                                                       ( ArgumentListopt ) ClassBodyopt
        Primary . new TypeArgumentsopt Identifier TypeArgumentsOrDiamondopt
                                                       ( ArgumentListopt ) ClassBodyopt
    FieldAccess
        Primary . Identifier
        super . Identifier
        ClassName . super . Identifier
    MethodInvocation
	MethodName ( ArgumentListopt )
	Primary . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
	super . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
	ClassName . super . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
	TypeName . NonWildTypeArguments Identifier ( ArgumentListopt )
    ArrayAccess
        ExpressionName [ Expression ]
        PrimaryNoNewArray [ Expression ]