In ES6, what is the meaning of the parameter [Yield], [In] in a grammar production

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

In ES6, what is the meaning of the parameter [Yield], [In] in a grammar production

Coolwust
I know a production may be parameterized by suffixing the nonterminal symbol, my question is what is the meaning of the parameter [Yield], [In]? For example, in section 12.1, identifier expression has the syntax  below:

```
IdentifierReference [Yield] :
Identifier
[~Yield] yield
```

Thanks.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: In ES6, what is the meaning of the parameter [Yield], [In] in a grammar production

Michael Dyck
On 15-03-09 04:10 AM, Coolwust wrote:
> I know a production may be parameterized by suffixing the nonterminal
> symbol, my question is what is the meaning of the parameter [Yield], [In]?

To figure out the 'meaning' of a particular parameter, look at all the
places where that parameter is used as a prefix/guard for a whole RHS.

E.g., consider Yield:

12.14 says:
     AssignmentExpression[In,Yield] :
       ...
       [+Yield] YieldExpresion[?In]
So the *presence* of the Yield parameter means that a YieldExpression is
allowed (i.e., 'yield' is treated as a keyword).

Whereas 12.1 says:
     IdentifierReference[Yield] :
       Identifier
       [~Yield] yield
(And similarly for BindingIdentifier and LabelIdentifier.)
So the *absence* of the Yield parameter means that 'yield' is allowed as
an IdentifierReference or BindingIdentifier or LabelIdentifier. (That is,
it's treated the same as an Identifier.)

So, in general, the Yield parameter controls whether 'yield' is treated as
a ReservedWord or not.

-Michael
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: In ES6, what is the meaning of the parameter [Yield], [In] in a grammar production

Coolwust
My bad, it is a keyword, I found. Thanks again.

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: In ES6, what is the meaning of the parameter [Yield], [In] in a grammar production

Coolwust
In reply to this post by Coolwust
I have one more question, why `yield` and `in` keywords are so special? When can I treat `yield` and `in` as the non-reserved-word?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: In ES6, what is the meaning of the parameter [Yield], [In] in a grammar production

Brendan Eich-2
Coolwust wrote:
> I have one more question, why `yield` and `in` keywords are so
> special? When can I treat `yield` and `in` as the non-reserved-word?

You can't treat `in` as an unreserved identifier, in any event. It has
been reserved since JS1 in 1995, de-jure in ECMA-262 Edition 1 (ES1).

These are different, their histories differ. ES6 (after ES4 but without
opt-in versioning) supports `yield` in generator functions but not
elsewhere, because extant code on the Web over the last almost-20-years
uses `yield` as an identifier in plain functions and/or global code.

`in` needs special treatment due to the ES3 grammatical ambiguity that
would otherwise allow two ways of parsing the left sentential form `for
(var x = y in z ...` (where the ... is meta). ECMA-262 aspires to
specify an LR(1) grammar with lookahead restrictions and error
correction procedures such as ASI. Allowing `in` expressions in variable
intiialisers at the front of `for` loops would make the grammar not
LR(k) for any k. (The potential ambiguity arose first in ES3 because
that was when the `in` operator was added.)

/be
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: In ES6, what is the meaning of the parameter [Yield], [In] in a grammar production

Coolwust
In reply to this post by Coolwust
Thanks Brendan, very informative reply!

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