Removal of NoIn grammar productions and for-loop parsing
allen at wirfs-brock.com
Sun Sep 1 17:52:45 PDT 2013
On Aug 31, 2013, at 9:21 PM, Brendan Eich wrote:
> Allen, are you doing this some other way? Static semantics can't do it, we need parametric productions or else ye olde NoIn splitting.
>> André Bargull <mailto:andre.bargull at udo.edu>
>> August 31, 2013 4:21 AM
>> The NoIn grammar productions have been removed in rev17. Does this mean that `for (a in b;;);` is now a valid (C-style) for-loop instead of a SyntaxError?
Right, this point didn't come up when we talked about eliminating the NoIn productions at the last TC39 meeting: https://github.com/rwaldron/tc39-notes/blob/master/es6/2013-07/july-23.md#41-es6-status-report
Presumably the original motivation for the NoIn productions was to resolve the ambiguity that the introduction of the ES3 'in' operator created for the ES1 production:
IterationStatement : 'for' '(' 'var' Identifier [Initializer] 'in' Expression ')' Statement
when parsing something like:
for (var x = a in b in c) ;
it could be either:
for (var x = (a in b) in c) ;
for (var x = a in (b in c)) ;
Because we agreed for ES6 to eliminate the optional Initializer from for-in/for-of statements this ambiguity is no longer a possibility and the NoIn productions are not needed to resolve them. At the last meeting the discussion was about the grammar simplification benefits of completely eliminating the NoIn productions. I did this in the rev17 ES6 draft.
However, at the meeting, we did not discussion the fact that in ES3 NoIn was also used in:
IterationStatement : 'for' '(' [ExpressionNoIn] ';' [Expression] ';' [Expression] ')' Statement
This makes statements like this:
for (a in b ;;) ;
illegal in ES3. This was presumably done for nanny reasons as using the 'in' operator in this position isn't ambiguous. The availability of the NoIn productions also made it easy to express such a restriction.
But if we eliminate the NoIn productions it's no longer so easy to impose that restriction. I may be able to come up with some other static semantic mechanism to express that restriction but it will have complexity similar to the NoIn productions.
My preference is to simply allow the use of the 'in' operator in the first expression of a for(;;) statement. This is what the rev17 grammer does. As it is currently illegal in ES<=5.1, allowing 'in' use in that context is an extension rather than a breaking change. 'a in 'b may not be very useful in that position but neither is 'a + b'. The simplification of the expression grammar is a pretty big win both now and for future extensions.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss