Skip to content

Commit

Permalink
Editorial: Clarify note re parsing the same string multiple times (#1521
Browse files Browse the repository at this point in the history
)

... which was the subject of issue #1484.

This is basically @allenwb's suggested wording from
#1484 (comment)
  • Loading branch information
jmdyck authored and ljharb committed May 18, 2019
1 parent 9a81833 commit a5375bd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,13 @@ <h1>The Syntactic Grammar</h1>
<p>When a parse is successful, it constructs a <em>parse tree</em>, a rooted tree structure in which each node is a <dfn>Parse Node</dfn>. Each Parse Node is an <em>instance</em> of a symbol in the grammar; it represents a span of the source text that can be derived from that symbol. The root node of the parse tree, representing the whole of the source text, is an instance of the parse's goal symbol. When a Parse Node is an instance of a nonterminal, it is also an instance of some production that has that nonterminal as its left-hand side. Moreover, it has zero or more <em>children</em>, one for each symbol on the production's right-hand side: each child is a Parse Node that is an instance of the corresponding symbol.</p>
<p>New Parse Nodes are instantiated for each invocation of the parser and never reused between parses even of identical source text. Parse Nodes are considered <dfn>the same Parse Node</dfn> if and only if they represent the same span of source text, are instances of the same grammar symbol, and resulted from the same parser invocation.</p>
<emu-note>
<p>Parsing the same String multiple times will lead to different Parse Nodes, e.g., as occurs in:</p>
<pre><code class="javascript">eval(str); eval(str);</code></pre>
<p>Parsing the same String multiple times will lead to different Parse Nodes. For example, consider:</p>
<pre><code class="javascript">
let str = "1 + 1;";
eval(str);
eval(str);
</code></pre>
<p>Each call to `eval` converts the value of `str` into an ECMAScript source text and performs an independent parse that creates its own separate tree of Parse Nodes. The trees are distinct even though each parse operates upon a source text that was derived from the same String value.</p>
</emu-note>
<emu-note>Parse Nodes are specification artefacts, and implementations are not required to use an analogous data structure.</emu-note>
<p>Productions of the syntactic grammar are distinguished by having just one colon &ldquo;<b>:</b>&rdquo; as punctuation.</p>
Expand Down

0 comments on commit a5375bd

Please sign in to comment.