7

Many productions in EcmaScript are given with the following "modifiers":

[Yield, Await, In, Return]

Here are a few examples:

ArrayLiteral[Yield, Await]:
  ...

ElementList[Yield, Await]:
 ... AssignmentExpression[+In, ?Yield, ?Await]

I've searched through the spec for the explanation, specifically Grammar Notation section, but can't find it. It should be there. Can someone please point me to the relevant paragraph and maybe provide a short explanation?

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488

1 Answers1

4

Section 5.1.5: Grammar Notation -

A production may be parameterized by a subscripted annotation of the form “[parameters]”, which may appear as a suffix to the nonterminal symbol defined by the production. “parameters” may be either a single name or a comma separated list of names. A parameterized production is shorthand for a set of productions defining all combinations of the parameter names, preceded by an underscore, appended to the parameterized nonterminal symbol. This means that:

StatementList[Return]:
   ReturnStatement
   ExpressionStatement

is a convenient abbreviation for:

StatementList:
   ReturnStatement
   ExpressionStatement
StatementList_Return:
   ReturnStatement
   ExpressionStatement

and that:

StatementList[Return, In]:
   ReturnStatement
   ExpressionStatement

is an abbreviation for:

StatementList:
   ReturnStatement
   ExpressionStatement
StatementList_Return:
   ReturnStatement
   ExpressionStatement
StatementList_In:
   ReturnStatement
   ExpressionStatement
StatementList_Return_In:
   ReturnStatement
   ExpressionStatement

Multiple parameters produce a combinatory number of productions, not all of which are necessarily referenced in a complete grammar.

It continues from there talking about parameterizing right-hand sides, adding "opt", etc.

(When searching, don't just look for [Return] and such specifically, as they can and usually do appear in groups like [Yield, Await, Return] and [?Yield, ?Await, ?Return] as in the syntax for Block.)

Section 12.1.1: Identifiers - Static Semantics: Early Errors -

It is a Syntax Error if this production has a [Yield] parameter and StringValue of Identifier is "yield".

It is a Syntax Error if this production has an [Await] parameter and StringValue of Identifier is "await".

Section 12.10: Relational Operators -

The [In] grammar parameter is needed to avoid confusing the in operator in a relational expression with the in operator in a for statement.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • thanks, can you also please explain what this means `AssignmentExpression[+In, ?Yield, ?Await]`? Why is there `+` and `?` when referencing the non-terminal `AssignmentExpression`? – Max Koretskyi Sep 03 '17 at 11:46
  • 1
    @AngularInDepth.com: That's all explained in Section 5.1.5. – T.J. Crowder Sep 03 '17 at 11:48
  • ok, thanks, I'll read it thoroughly and come back with a clarifying questions if any – Max Koretskyi Sep 03 '17 at 11:53
  • I'm not a native English speaker. To understand the above 5.1 introduces it's so difficult for me.... – nuclear Feb 18 '20 at 14:24
  • @toffee - It can be difficult even for native English speakers! :-) I suggest posting a question that refers to the section quoted above (maybe even quoting it) and perhaps also refers to this answer, and saying what specifically you don't understand. Hopefully someone can explain that part in a way that helps you -- and others after you. :-) – T.J. Crowder Feb 18 '20 at 14:30