2

I've been confused lately about productions in ecma262 spec.

There are productions based on my assumption that can be other productions.

for example, Statement

Statement can be a Block it can also be an IfStatement.

my confusion begins with algorithms that looks like that

a. Let stmtCompletion be the result of evaluating the first Statement.

evaluating Statement? What does it mean?

if a Statement, for example, is an IfStatement will it go to the 14.6 The if Statement 14.6.2 Runtime Semantics: Evaluation ?

I'm mostly confused because there are productions that have their RS: Evaluation like IfStatement and some don't have the RS: Evaluation like Statement,Declaration, etc...

AngryJohn
  • 576
  • 4
  • 10

1 Answers1

2

If a Statement, for example, is an IfStatement will it go to the 14.6 The if Statement 14.6.2 Runtime Semantics: Evaluation ?

Yes.

I'm mostly confused because there are productions that have their RS: Evaluation like IfStatement and some don't have the RS: Evaluation like Statement,Declaration, etc...

What does it mean?

This is (in recent revisions of the spec) even explained in §5.2.2 Syntax-Directed Operations. In particular,

Unless explicitly specified otherwise, all chain productions have an implicit definition for every operation that might be applied to that production's left-hand side nonterminal. The implicit definition simply reapplies the same operation with the same parameters, if any, to the chain production's sole right-hand side nonterminal and then returns the result. For example, assume that some algorithm has a step of the form: “Return the result of evaluating Block” and that there is a production:

Block : { StatementList }

but the Evaluation operation does not associate an algorithm with that production. In that case, the Evaluation operation implicitly includes an association of the form:

Runtime Semantics: Evaluation

Block : { StatementList }

  1. Return the result of evaluating StatementList.

So since there are no "Runtime Semantics: Evaluation" for the Statement production, it gets implicit semantics that will simply evaluate the respective statement kind.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • "Let stmtCompletion be the result of evaluating the first Statement." it's just an example which i show a scenario where some algorithm use the evaluating Statement which i'm not sure what exactly it does. i took the example from "14.6.2 Runtime Semantics: Evaluation" – AngryJohn Oct 16 '21 at 16:22
  • so that's mean that basically the productions that doesn't have "Runtime Semantics: Evaluation" are referring to the "Runtime Semantics: Evaluation" of their children(can also be their grandchildren) ? in more details, the Statement children are IfStatement,VariableStatement etc... therefore when i encounter an algorithm like "a. Let stmtCompletion be the result of evaluating the first Statement" then it means that it may go to the IfStatement evaluation or it may evaluate a VariableStatement. but that's depends on the code i wrote. did i understood it correctly ? – AngryJohn Oct 16 '21 at 19:35
  • @AngryJohn Yes, exactly that. – Bergi Oct 16 '21 at 21:57
  • but doesn't it says that a "A chain production is a production that has exactly one nonterminal symbol on its right-hand side along with zero or more terminal symbols." based on my understanding it's says that a production that has exactly one nonterminal along with zero or more terminals on it's right hand side has those implicit "Runtime Semantics: Evaluation" that you indicated. so Statement isn't a chain production ? because it has more than one nonterminal on it's right hand side it has BlockStatement,VariableStatement,EmptyStatement etc... or they meant per alternative ? – AngryJohn Nov 11 '21 at 17:51
  • Yes, it refers to the individual [productions](https://en.wikipedia.org/wiki/Production_(computer_science)). `Statement` is a nonterminal, `Statement → BlockStatement` is the chain production. – Bergi Nov 11 '21 at 19:18
  • Hey Bergi Just a quick question, in [https://tc39.es/ecma262/#sec-algorithm-conventions-syntax-directed-operations](Syntax Directed Operation), at the end of the section it says "all chain productions have an implicit definition for every operation that might be applied to that production's left-hand side nonterminal." the important part here is the "every operation", that means that every syntax-directed operation whether it's StringValue, BoundsNames, etc.. will have an implicit definition for chain production that doesn't have an algorithm? so it's not only applied on evaluation? – AngryJohn Mar 21 '22 at 15:13
  • So, all of them, not just *Evaluation*. – Bergi Mar 21 '22 at 17:52