D Operator priority level (version 1.0)

Does anyone know where the listing is for operator priority levels for version D version 1.0?

+4
source share
5 answers

On the page http://www.digitalmars.com/d/1.0/expression.html the material above has a lower priority overall. To get a specific priority, follow the rules of the parser.

15. typeof() typeid() is() assert() import() mixin() function delegate Tx x!y variables (...) [...] //(Primary expressions) "x" "y" //(Concatenation between string literals) 14. . x++ x-- x() x[] //(Postfix operators) 13. & ++x --x * +x -x ! ~ (T). new delete cast //(Prefix operators) 12½. ^^ //(Power. D2 only) 12. * / % ///(Multiplicative operators) 11. + - ~ //(Additive operators) 10. >> << >>> //(Bitwise shift) 9. == != is !is > < >= <= !> !< !>= !<= <> !<> <>= !<>= in !in //(Comparison operators) 8. & //(Bitwise AND) 7. ^ //(Bitwise XOR) 6. | //(Bitwise OR) 5. && //(Logical AND) 4. || //(Logical OR) 3. ?: //(Conditional operator) 2. op= //(Assignment operator) 1⅔. => //(Lambda. D2 only. Not really an operator) 1⅓. .. //(Slicing. Not really an operator) 1. , //(Comma operator) 
+6
source

See page D 1.0 on expression pages .

Assessment Procedure

The following binary expressions: evaluated strictly left-right order:

CommaExpression, OrOrExpression, AndAndExpression

The following binary expressions: evaluated according to implementation order:

AssignExpression, OrExpression, XorExpression, AndExpression, CmpExpression, ShiftExpression, AddExpression, CatExpression, MulExpression, function parameters

The error depends on the order if it is not specified. For example, the following is illegal:

 i = i++; c = a + (a = b); func(++i, ++i); 

If the compiler can determine that the result of the expression is illegal depending on the evaluation order, it may throw an error (but not necessary). The ability to detect these errors is a quality implementation problem.

At least that was the link mentioned by Walter (creator of D) to this mailing list thread .

+2
source

As far as I know, there is currently a good table of operator priorities for D. You can look at the page on expressions ( http://www.digitalmars.com/d/1.0/expression.html ) and break any expression that you have in accordance with grammar, and define it, but obviously this is not as good or simple as a table.

However, C and C ++ code is guaranteed to either be valid D code with the same behavior, or will not compile. So, if the expression you have is valid C or C ++, you can simply use the C / C ++ operator priority table: http://www.cppreference.com/wiki/operator_precedence

So, unfortunately, there is no good table of operator priority tables for D, if you understand the priority of the C / C ++ operator, there really should be no surprises.

Edit: Regarding the D-specific operators looking at the expression page, you have

Same priority as other assignment operators

  • =

Probably the same priority as ==

  • in
  • ! IN
  • is an
  • ! Is an

Same priority as <

  • <! > =
  • <! >
  • <>
  • <> =
  • ! >
  • ! > =
  • <
  • <! =

Same priority as →

  • <P →

Probably the same priority as *

  • ~

I believe that the full list of new operators is D. I say “probably” in two cases, because it looks like it is indicated in the answer of Mark Rushakov (in this case, the priority is very close to this operator if it is not identical). However, I'm not sure if this will actually matter, as it can be quite difficult to mix some of them in a way that would be completely ambiguous (especially this was).

Generally speaking, if you adhere to C / C ++ priority rules, you should be fine. In any case, D will be somewhat more restrictive than C / C ++ due to stricter conversion rules, etc., so I don’t think you will get any additional ambiguities. However, it would be nice to assume that an explicit operator priority table has been added to the D documentation.

+1
source

Google didn’t find much, I think D is a little niche language

However, I came across a comment in thread when converting from C ++ to D, where the creator of D says: “Conversion is one of the reasons why I like the operator’s priority. Therefore, if you can find the operator’s priority C ++, you can use it for D

0
source

Whenever possible, D uses the priority of operator C.

0
source

Source: https://habr.com/ru/post/1307363/


All Articles