Expression in D language (1)

xiaoxiao2021-03-06  45

Expression C and C programmers will find that the expression in D is familiar, and there are some interesting to expand.

Expressions are used to calculate multiple values ​​and return a specific type of value. Subsequent values ​​can be used to assign, test, or ignored. Expressions may also have side effects.

expression:

Assignment expression

Assignment expressions, expressions

Assignment expression:

Conditional expression

Conditional expression = assignment expression

Conditional expression = assignment expression

Conditional expression - = assignment expression

Conditional expression * = assignment expression

Conditional expression / = assignment expression

Conditional expression% = assignment expression

Conditional Expression & = Assignment Expression

Conditional expression | = assignment expression

Conditional expression ^ = assignment expression

Conditional expression ~ = assignment expression

Conditional expression << = assignment expression

Conditional expression >> = assignment expression

Conditional expression >>> = assignment expression

Conditional expression:

OROR expression

OROR expression? Expression: conditional expression

OROR expression:

Andand expressions

OROR Expression || Andand Expressions

Andand expressions:

Expression

Andand Expressions && or Expressions

Or expression:

Tone or expressions

Or expression | alone or expression

Tone or expressions:

Expression

Tone or expressions ^ and expressions

And expressions:

Equal expression

Equally expressions with expressions

Equal expression:

Relational expression

Equal expressions == Relationship expression

Equal expressions! = Relational expression

Equal expressions IS relationship expression

Relationship expression:

Displacement expression

Relationship expression

Relational expression <= shift expression

Relationship expression> Displacement expression

Relationship expression> = shift expression

Relationship expression! <> = Shift expression

Relationship expression! <> Shift expression

Relationship expression <> shift expression

Relational expression <> = shift expression

Relationship expression!> Displacement expression

Relationship expression!> = Shift expression

Relationship expression!

Relationship expression! <= Shift expression

Relationship expression in shift expression

Displacement expression:

Expressive

Displacement expression << and expressions

Displacement expression >> and expressions

Displacement expression >>> and expressions

And expressions:

Accumulate

And expressions volume list

And expressions

And expressions ~

Complexed:

One yuan expressions

Complexed by the format * one yuan express

Complexed format / one yuan express

Complexed by volume% of one yuan express

One yuan express:

Suffix expression

& One dollar expression

one yuan expressions

- a metal expression

* One yuan expressions

- a metal expression

1 yuan express

! One yuan expressions

~ One yuan expression

DELETE 1 yuan expressions

New expression

CAST (type) one yuan expressions

(Type). Mark

(Expression)

Suffix expression:

Basic expression

Suffix expression.

Suffix expression

Suffix expression -

Suffix expression (parameter list)

Index expression

Sliced ​​expression

Index expression:

Suffix expression [parameter list]

Slice expression:

Suffix expression [assignment expression .. assignment expression]

Basic expression:

Marker

Flag

THIS

Super

NULL

True

False

Numerical text

Character text

Character string

Functional volume

Assertion expression

Basic type. Signature

TYPEID (Type)

Aspect:

askERT (expression)

parameter list:

Assignment expression

Assigning expression, parameter list

NEW expression:

NEW Basic Type Stars [Assignment Expression] Notes New Basic Type Stars (Parameter List)

New Basic Type Stars

NEW (Parameter List) Basic Type Stars [Assignment Expression] Disclaimer

NEW (parameter list) basic type stars (parameter list)

NEW (parameter list) Basic Type Stars

Stars

Nothing

*

* Stars

EXPRESSION:

AssignExpression

AssignExpression, Expression

AssignExpression:

ConditionaLexpression

ConditionaLexpression = AssignExpression

ConditionaLexpression = AssignExpression

ConditionaRexpression - = AssignExpression

Conditionales * = AssignExpression

Conditionales / = AssignExpression

ConditionaRexpression% = AssignExpression

ConditionaRexpression & = AssignExpression

ConditionaRexpression | = AssignExpression

Conditionales ^ = AssignExpression

ConditionaLexpression ~ = assignexpression

ConditionaRexpression << = AssignExpression

ConditionaLexpression >> = assignexpression

ConditionaRexpression >>> = AssignExpression

ConditionaRexpression:

OROREXPRESSION

OROREXPIRESSION? Expression: ConditionaRexpression

OROREXPRESSION:

Andandexpression

OroPression || AndandExpression

Andandexpression:

OREXPRESSION

Andandexpression && Orexpression

OREXPIRESSION:

XOREXPRESSION

Orexpression | XOREXPRESSION

XOREXPRESSION:

AndExpression

XOREXPRESSION ^ AndExpression

AndExpression:

Equalexpression

AndExpression & equalExpression

Equalexpression:

Relexpression

Equalexpression == Relevance

Equalexpression! = Relevance

Equalexpression is Relexpression

Relevance:

Shiftexpression

Relevance

Relevance <= shiftExpression

Relevance> Shiftexpression

Relevance> = shiftExpression

Relevance! <> = ShiftexpressionReleXpression! <> ShiftExpression

Relevance <> shiftExpression

Relevance <> = shiftExpression

Relevance!> Shiftexpression

Relevance!> = ShiftExpression

Relevance!

Relevance! <= Shiftexpression

Relevance in shiftexpression

ShiftExpression:

AddExpression

Shiftexpression << AddExpression

Shiftexpression >> AddExpression

Shiftexpression >>> AddExpression

AddExpression:

MulexPression

AddExpression MULEXPRESSION

AddExpression - MULEXPRESSION

AddExpression ~ MULEXPRESSION

MulexPression:

UnaryExpression

MULEXPRESSION * UnaryExpression

MULEXPIESSION / UNARYEXPRESSION

MULEXPRESSION% UnaryExpression

UnaryExpression:

PostfixExpression

& UnaryExpression

unaryExpression

- UnaryExpression

* UnaryExpression

- UnaryExpression

UnaryExpression

! Unaryexpression

~ UnaryExpression

Delete UnaryExpression

NewExpression

Cast (Type) UnaryExpression

(TYPE). Identifier

(Expression)

PostfixExpression:

PRIMARYEXPIPRESSION

PostfixExpression. Identifier

PostfixExpression

PostfixExpression -

PostfixExpression (argumentlist)

Indexexpression

SLICEEXPRESSION

IndexExpression:

PostfixExpression [argumentlist]

SLICEEXPISSION:

PostfixExpression [assignexpression .. assignexpression]

PRIMARYEXPRESSION:

Identifier

.IDENTIFIER

THIS

Super

NULL

True

False

Numericliteral

Characterliteral

Stringliteral

FunctionLiteral

AskSERTEXPRESSION

BasicType. Identifier

TypeID (Type)

AskERTEXPISSION:

askERT (Expression)

Argumentlist:

AssignExpression

AssignExpression, ArgumentList

NEWEXPRESSION:

New BasicType Stars [AssignExpression] DECLARATORNEW BasicType Stars (argumentlist)

New BasicType Stars

New (argumentlist) BasicType Stars [AssignExpression] DECLARATOR

New (argumentlist) BasicType Stars (ArgumentList)

NEW (argumentlist) BasicType Stars

Stars

Nothing

*

* Stars

The order of assessment is unless otherwise specified (such as OR or ANDAL), the implementation of D can be evaluated in any part of the expression in any order. If there is no additional specification, it cannot rely on the order of value. For example, the following code is illegal:

i = i;

C = a (a = b);

FUNC ( i, i);

If the compiler can determine the value of the expression is dependent on the order order, it will report an error (but this is not a must). The ability to detect such errors is the quality of the realization.

expression

Assignment expressions, expressions

AssignExpression, Expression

First calculate first

, 'The number of operands left, then calculate the number of operands on the right. The type of expression is the type of the operand on the right, and the result of the expression is the result of the number of operands on the right.

Assignment expression

Conditional expression = assignment expression

ConditionaLexpression = AssignExpression

The type of the right operand will be implicitly converted to the type of left operand and assigns the left to the left. The type of operand is the type of left destined, and the value of the result is the value of the left value after assignment.

The left operand must be left value.

Assignment operator expression

Conditional expression = assignment expression

Conditional expression - = assignment expression

Conditional expression * = assignment expression

Conditional expression / = assignment expression

Conditional expression% = assignment expression

Conditional Expression & = Assignment Expression

Conditional expression | = assignment expression

Conditional expression ^ = assignment expression

Conditional expression << = assignment expression

Conditional expression >> = assignment expression

Conditional expression >>> = assignment expression

ConditionaLexpression = AssignExpression

ConditionaRexpression - = AssignExpression

Conditionales * = AssignExpression

Conditionales / = AssignExpression

ConditionaRexpression% = AssignExpression

ConditionaRexpression & = AssignExpression

ConditionaRexpression | = AssignExpression

Conditionales ^ = AssignExpression

ConditionaRexpression << = AssignExpression

ConditionaLexpression >> = assignexpression

ConditionaRexpression >>> = AssignExpression

Assignment operator expressions, such as:

A op = B

Is equivalent to: a = a op b

Differences are operands

a only calculates once.

Conditional expression

OROR expression? Expression: conditional expression

OROREXPIRESSION? Expression: ConditionaRexpression

The first expression will be converted to a Boolean and is calculated. If the result is true, the second expression is calculated, the resulting result is the result of the conditional expression. If the result is false, the third expression is calculated, the result is the result of the conditional expression. If the second or third expression is a VOID type, the type returned is VOID. Otherwise, the type of the second and third expressions will be implicitly converted to a common type thereof and become the type of conditional expression results.

OROR expression

OROR Expression || Andand Expressions

OroPression || AndandExpression

The return type of the OROR expression is a Boolean, and the result is a VOID type when the number of operands is VOID.

OROR expression calculates its leftmost operand. If the left operand is transformed into the Boolean type, the result is not true, and the number of operands on the right is not calculated. If the type of OROR expression results are Boolean, the result of the expression is true. If the left operand is false, the number of operands on the right is calculated. If the OROR expression is a Boolean, the result is the result of the operating number of the right side into the Boolean result.

Andand expressions

Andand Expressions && OR Expressions

Andandexpression && Orexpression

The return type of the Andand expression is a Boolean. The exception is that when the operand on the right is Void, the result is a VOID type.

Andand expressions calculate the number of operands on the left. If the left operand is transformed into the Boolean, the result is not to calculate the number of operands on the right. If the type of Andand expression results are Boolean, the result of the expression is false. If the left operand is true, the number of operands on the right is calculated. If the Andand expression is a Boolean, the result is the result of the operating number of the right side to the Boolean results.

Bit-bit expressions are bitten by bit by bit expressions. Their operands must be positive types. First, the default positive number will be applied. Then, perform a bitwise operation.

OR expression

Or expression | alone or expression

Orexpression | XOREXPRESSION

Execute 'or' calculations between operands.

XOR expression

Tone or expressions ^ and expressions

XOREXPRESSION ^ AndExpression

Execute the 'different or' calculation between operands.

And expression

Equally expressions with expressions

AndExpression & equalExpression

Execute 'and' calculations between operands.

Equal expression

Equal expressions == Relationship expression

Equal expressions! = Relational expression

Equal expressions IS relationship expression

Equalexpression == Relevance

Equalexpression! = Relevance

Equalexpression is Relexpression

Equal expressive compare equality operators (

==) or unequal operators (

! =) Two operands. The type of result is a Boolean. Prior to comparison, the operands are transformed into one common type through common conversion transformation.

If the operand is an integer value or a pointer, it is equally defined to accurately match. The equality of the structure refers to the accurate matching of bits (checks that include empty cavities due to alignment, usually they are set to zero during initialization). The equalization of floats is more complicated. -0 and 0 are equal. If the two operands are NAN, == and! = Operation will return false. In other cases, bit bit is more equal. For multiple plits, equal is defined as equivalent:

x.re == y.re && x.im == y.im

Not phase-defined as equivalent:

X.re! = y.re || x.im! = y.im

For class objects, equal is defined as the result of calling Object.eq (). If there is an object as NULL, it will throw an exception.

As for static and dynamic arrays, equal is defined as equal to the length of the array, and the corresponding elements are equal.

Same expression

Equal expressions IS relationship expression

Equalexpression is Relexpression

IS is used to compare identity. If it is more unity, use

! (E1 IS E2). The type of result is a Boolean. Prior to comparison, the operands are transformed into one common type through common conversion transformation.

If the operand is not a class object, a static or dynamic array, the identity is defined equivalent to equalization.

For class objects, the identity is defined as reference to the same object. You can use the IS to compare null class objects.

For static and dynamic arrays, identity is defined as pointing to the same array element.

The same operator IS cannot be overloaded.

Relational expression

Relationship expression

Relational expression <= shift expression

Relationship expression> Displacement expression

Relationship expression> = shift expression

Relationship expression! <> = Shift expression

Relationship expression! <> Shift expression

Relationship expression <> shift expression

Relational expression <> = shift expression

Relationship expression!> Displacement expression

Relationship expression!> = Shift expression

Relationship expression!

Relationship expression! <= Shift expression

Relationship expression in shift expression

Relevance

Relevance <= shiftExpression

Relevance> Shiftexpression

Relevance> = shiftExpression

Relevance! <> = Shiftexpression

Relevance! <> Shiftexpression

Relevance <> shiftExpression

Relevance <> = shiftExpression

Relevance!> Shiftexpression

Relevance!> = ShiftExpression

Relevance!

Relevance! <= Shiftexpression

Relevance in shiftexpression

First, an integer is applied to an operand. The type of relationship expression returns the result is a Boolean.

For class objects, the result of Object.cmp () constitutes the left operation, 0 constitutes the right operand. The result of the relationship expression (O1 OP O2) is:

(O1.cmp (o2) op 0)

If the object is NULL, it is an error.

For static and dynamic arrays, the results of the relationship OP are the results of the operator to apply to the first unequal element in the array. If the two arrays are equal, but the length is different, the shorter array "less than" a longer array. Integer comparison If the two operands are integer types, they will perform an integer comparison.

Integer comparison operator

Operator relationship greater than <= less than or equal to> = greater than or equal to == equal! = Not equal

If <, <=,> or> = expression in the expression is a symbol number, the other operand is unsigned, and it is considered an error. You can use the type conversion to transform the two operands to the same number or no symbol number.

Floating point comparison If the operand is the number of floats, the floating point is performed.

Any floating point operation with practical value must support the NAN value. In particular, the relationship operator supports the NAN operand. The result of the relationship between floating point numbers can be less than, greater than, equal to or undefined (undefined means to have an operand NAN). This means there is 14 possible comparison conditions:

Floating point comparison operator

The operator is greater than it is less than or equal to the undefined anomalous relationship == FFTF NO is equal to! = TTFT NO Undefined, less than or greater than> TFFFFFFFFFFFFFFTF = fttf yes is less than or equal to or equal to or equal! <> = FFFT NO Undefined <> TTFF YES is less than or greater than <> = tttf yes is less than, equal to or greater than! <= TFFT NO Undefined or greater than! = Ftft no undefined or less than!> Fttt NO undefined, less than or equal to! <> FFTT NO is not defined or equal to

note:

For floating point comparison operators, (a! Op b) is not equivalent to! (A OP B). The "undefined" means that there is an operand nan. "Abnormal" means that if the operand is NAN, INVALID exception is thrown.

转载请注明原文地址:https://www.9cbs.com/read-58889.html

New Post(0)