On May 17, 2009, at 11:48 AM, Brendan Eich wrote:

On May 17, 2009, at 11:00 AM, Brendan Eich wrote:

Python differs from JS by having only assignment statements, not assignment expressions, which simplifies the problem a bit, as the grep output cited above shows.

Of course this makes trouble with automatic semicolon insertion, unless assignment statements are split from assignment expressions. D'oh!

js> function g() {z = yield a ? f : x++()}
typein:2: SyntaxError: missing ; before statement:
typein:2: function g() {z = yield a ? f : x++()}
typein:2: .................................^
js> function g() {(z = yield a ? f : x++)()}

I was wrong, there's no issue here (apart from SpiderMonkey's diagnostic being suboptimal). This is not a case of a high-precedence prefix operator whose following operand is a low-precedence expression non-terminal. That's unsound.

In this example, yield is just like a nested assignment:

js> function g() {z = w = a ? f : x++()}
typein:1: SyntaxError: missing ; before statement:
typein:1: function g() {z = w = a ? f : x++()}
typein:1: ...............................^

where the body (z = w = a ? f : x++()) === (z = (w = (a ? f : x++()))).

If PrimaryExpression: yield AssignmentExpression were a production in the grammar, then we would have the bug I was worried about, the one that Waldemar pointed out let expressions, which also afflicts expression closures (ASI makes the bug harder to spot, was Waldemar's further point -- but ASI is not an issue here).


Patching this is harder than I thought it would be. After hacking at the Bison grammar a bit, I concede your point about implementation difficulty!

I still concede greater burden on implementor, but here's an updated WebKit/JavaScriptCore/parser patch:


Attachment: p
Description: Binary data





/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to