On Apr 18, 2011, at 12:14 PM, Brendan Eich wrote:

> On Apr 17, 2011, at 9:09 AM, David Herman wrote:
> 
>> * functions with expression bodies
>> 
>> This was proposed for ES4 and implemented in SpiderMonkey. I believe there 
>> are some unfortunate ambiguities in the grammar that came up, and I think 
>> they've been treated as moribund. But I love them, and would love it if we 
>> could find a way to bring them back in a way that didn't break the grammar.
> 
> The counterexample Waldemar gave, adjusted to use a function with expression 
> body instead of a let expression, is worth repeating:
> 
>  function f() {return "f"}
>  var x = 3;
>  alert(function (a) a ? f : x++(1));
>      /*^^^^^^^^^^^^^^^^^^^^^^^^*/
> 
> The alert should show "f". Note that the call grammar:
> 
>  CallExpression :
>    MemberExpression Arguments
>    CallExpression Arguments
> 
> does not parse an unparenthesized AssignmentExpression (the function with 
> expression body's body non-terminal, in ES4 and what we implemented) as the 
> "callee" part of the right-hand side (underlined with ^^^ above). But it does 
> parse a PrimaryExpression, which includes function expressions, which loops 
> back to the AssignmentExpression at the end.

To be super-clear, in case anyone thought the x++(1) was a call expression, the 
grammar forbids PostfixExpression (a RHS of UnaryExpression) being 
unparenthesized as a callee in a call expression.

But by making functions with expression bodies be PrimaryExpressions ending 
with AssignmentExpressions, we have created a bad loop up the grammar that 
should allow the example with ^^^ under its callee part to parse.

It doesn't work in Firefox (SpiderMonkey), as Waldemar pointed out. We don't 
use a bottom-up parser.

Ruby has a flatter grammar-graph with lots of loops through its big expression 
nonterminal. Not so C-like languages including JS. Making bad loops at the end 
of right-hand sides is bad. Hope this helps the problem "stick" in folks minds.

/be

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

Reply via email to