简体   繁体   English

ECMAScript AssignmentExpression 生产规则如何产生`foo = 42`?

[英]How can ECMAScript AssignmentExpression production rule produce `foo = 42`?

As the spec states (yes, 5.1, that's intentional):正如规范所述(是的,5.1,这是故意的):

AssignmentExpression :

    ConditionalExpression
    LeftHandSideExpression = AssignmentExpression
    LeftHandSideExpression AssignmentOperator AssignmentExpression

Based on this definition, I don't understand how a simple foo = 42 assignment is valid.基于这个定义,我不明白一个简单的foo = 42赋值是如何有效的。

My understanding is, that foo = should always be followed by either a ConditionalExpression or essentially another assignment, but in that case, how will the production terminate if I don't use a ConditionalExpression ?我的理解是, foo =后面应该总是跟一个ConditionalExpression或者本质上是另一个赋值,但是在这种情况下,如果我不使用ConditionalExpression ,生产将如何终止? All further AssignmentExpression rules require either a ConditionalExpression or another AssignmentExpression .所有进一步的AssignmentExpression规则都需要一个ConditionalExpression或另一个AssignmentExpression

What am I missing here?我在这里想念什么?

The expression after the = operator must always be an AssignmentExpression . =运算符之后的表达式必须始终是一个AssignmentExpression This AssignmentExpression will often consist not of another assignment, but a plain ConditionalExpression , which in turn will consist of a simpler expression that might contain an operator or not, all the way down through the operator precedence hierarchy to the Literal that your number 123 forms.这个AssignmentExpression通常不包含另一个赋值,而是一个普通的ConditionalExpression ,它又包含一个可能包含或不包含运算符的更简单的表达式,一直到运算符优先级层次结构,一直到您的数字123 forms 的字面量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从EcmaScript语法的`Statement'导出`AssignmentExpression` - How can `AssignmentExpression` be derived from `Statement` in EcmaScript grammar 如何简化JavaScript / ECMAScript数组文字的生成? - How to simplify JavaScript/ECMAScript array literal production? 语法产生规则与ECMAScript中的解析如何相关 - How grammar production rules relate to parsing in ECMAScript eslint 规则禁止在赋值等于后换行(即 var foo =\\n 42) - eslint rule to disallow newline after equals in assignment (i.e. var foo =\n 42) 如何在JavaCC中实现JavaScript / ECMAScript“此处没有LineTerminator”规则? - How to implement JavaScript/ECMAScript “no LineTerminator here” rule in JavaCC? 为什么不能在同一个项目中同时使用 require('foo') 和 ECMAScript 导出? - Why can't both require('foo') and ECMAScript exports be used in the same project? 如何在ecmascript 6中模拟导入的模块? - How can I mock an imported module in ecmascript 6? 了解 ECMAScript 生产参数化注解 - Understanding ECMAScript production parameterized annotations LOOKAHEADs用于JavaScript / ECMAScript数组文字制作 - LOOKAHEADs for the JavaScript/ECMAScript array literal production 如何使用 ECMAScript 5 定义默认的 getter 和 setter? - How can I define a default getter and setter using ECMAScript 5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM