Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can someone explain me where in the ECMAScript specification operator precedence and operator associativity is mentioned

I was reading mdn docs about operator precedence and operator associativity "operator precedence and operator associativity(MDN)" and wanted to know more about it reading the ECMAScript specification.

But i didn't find anything about operator precedence and operator associativity in there.

Can someone guide me with a link to the ECMAScript specification where they describe precedence and associativity of each operator.

Any help is really appreciated. And i need to know if the ECMAScript specification doesn't mention anything about

precedence and associativity of each operator how language implementers know which operator to resolve first before the other i mean how they know which operator should get evaluated before the other operator

like image 717
Kevin Avatar asked Dec 05 '25 08:12

Kevin


1 Answers

As an example, the operator predescendence of multiplication over addition is in section 12.8 of the specification

12.8 Additive Operators Syntax

  AdditiveExpression:
      MultiplicativeExpression
      AdditiveExpression + MultiplicativeExpression
      AdditiveExpression - MultiplicativeExpression

edited for readability

Because of these productions 1 + 2 * 3 gets produced through an AdditiveExpression, with two MultiplicativeExpressions inside:

    AdditiveExpression
    (AdditiveExpression + MultiplicativeExpression)
    ((MultiplicativeExpression) + (MultiplicativeExpression MultiplicativeOperator MultiplicativeExpression))
    //...
    ((1) + (2 * 3))

If you evaluate this, the MultiplicativeExpressions get evaluated first (see section 12.8.3.1).

like image 182
Jonas Wilms Avatar answered Dec 07 '25 20:12

Jonas Wilms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!