return when desugaring to closures

Brendan Eich brendan at mozilla.com
Thu Oct 16 19:01:37 PDT 2008


On Oct 16, 2008, at 3:33 PM, Brendan Eich wrote:

> On Oct 16, 2008, at 1:20 PM, Waldemar Horwat wrote:
>
>> I don't think you can come up with a consistent "shift" or "greedy"  
>> notion.
>
> Funny, yacc has had one for decades, used to resolve dangling-else.

Which ES1-3 also use:

12.5 The if Statement
Syntax
IfStatement :
       if ( Expression ) Statement else Statement
       if ( Expression ) Statement
Each else for which the choice of associated if is ambiguous shall be  
associated with the nearest possible if that would otherwise have no  
corresponding else.

The grammar is not enough in ES3 without let expressions. You need at  
least this shift-reduce conflict resolution rule (I'm ignoring ASI, /  
as division vs. regexp delimiter, etc.). Adding let expressions does  
not add novel requirements for extra-grammatical disambiguation rules.

The ambiguity between blocks and object initialisers is another well- 
known case, resolved by "negative lookahead":

12.4 Expression Statement
Syntax
ExpressionStatement :
       [lookahead ∉ {{, function}] Expression ;

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20081016/49000fb7/attachment.html 


More information about the Es-discuss mailing list