Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 3b712e5

Browse files
define "source text matched by"
1 parent c784232 commit 3b712e5

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

proposal.html

+49
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,55 @@ <h2>Goals</h2>
5555
</style>
5656

5757

58+
<!-- es6num="5.2" -->
59+
<emu-clause id="sec-algorithm-conventions">
60+
<h1>(<a href="http://tc39.github.io/ecma262/#sec-algorithm-conventions">5.2</a>) Algorithm Conventions</h1>
61+
<p>The specification often uses a numbered list to specify steps in an algorithm. These algorithms are used to precisely specify the required semantics of ECMAScript language constructs. The algorithms are not intended to imply the use of any specific implementation technique. In practice, there may be more efficient algorithms available to implement a given feature.</p>
62+
<p>Algorithms may be explicitly parameterized, in which case the names and usage of the parameters must be provided as part of the algorithm's definition. In order to facilitate their use in multiple parts of this specification, some algorithms, called <em>abstract operations</em>, are named and written in parameterized functional form so that they may be referenced by name from within other algorithms. Abstract operations are typically referenced using a functional application style such as operationName(_arg1_, _arg2_). Some abstract operations are treated as polymorphically dispatched methods of class-like specification abstractions. Such method-like abstract operations are typically referenced using a method application style such as _someValue_.operationName(_arg1_, _arg2_).</p>
63+
<p>Calls to abstract operations return Completion Records. Abstract operations referenced using the functional application style and the method application style that are prefixed by `?` indicate that ReturnIfAbrupt should be applied to the resulting Completion Record. For example, ? operationName() is equivalent to ReturnIfAbrupt(operationName()). Similarly, ? _someValue_.operationName() is equivalent to ReturnIfAbrupt(_someValue_.operationName()).</p>
64+
<p>The prefix `!` is used to indicate that an abstract operation will never return an abrupt completion and that the resulting Completion Record's value field should be used in place of the return value of the operation. For example, &ldquo;Let _val_ be ! operationName()&rdquo; is equivalent to the following algorithm steps:</p>
65+
<emu-alg>
66+
1. Let _val_ be operationName().
67+
1. Assert: _val_ is never an abrupt completion.
68+
1. If _val_ is a Completion Record, let _val_ be _val_.[[Value]].
69+
</emu-alg>
70+
<p>Algorithms may be associated with productions of one of the ECMAScript grammars. A production that has multiple alternative definitions will typically have a distinct algorithm for each alternative. When an algorithm is associated with a grammar production, it may reference the terminal and nonterminal symbols of the production alternative as if they were parameters of the algorithm. When used in this manner, nonterminal symbols refer to the actual alternative definition that is matched when parsing the source text. <ins> The <dfn>source text matched by</dfn> a grammar production is the portion of the source text that starts at the beginning of the first terminal that participated in the match and ends at the end of the last terminal that participated in the match.</ins></p>
71+
<p>When an algorithm is associated with a production alternative, the alternative is typically shown without any &ldquo;[ ]&rdquo; grammar annotations. Such annotations should only affect the syntactic recognition of the alternative and have no effect on the associated semantics for the alternative.</p>
72+
<p>Unless explicitly specified otherwise, all chain productions have an implicit definition for every algorithm that might be applied to that production's left-hand side nonterminal. The implicit definition simply reapplies the same algorithm name with the same parameters, if any, to the chain production's sole right-hand side nonterminal and then returns the result. For example, assume there is a production:</p>
73+
<emu-grammar>
74+
Block :
75+
`{` StatementList `}`
76+
</emu-grammar>
77+
<p>but there is no corresponding Evaluation algorithm that is explicitly specified for that production. If in some algorithm there is a statement of the form: &ldquo;Return the result of evaluating |Block|&rdquo; it is implicit that an Evaluation algorithm exists of the form:</p>
78+
<p><b>Runtime Semantics: Evaluation</b></p>
79+
<emu-grammar>Block : `{` StatementList `}`</emu-grammar>
80+
<emu-alg>
81+
1. Return the result of evaluating |StatementList|.
82+
</emu-alg>
83+
<p>For clarity of expression, algorithm steps may be subdivided into sequential substeps. Substeps are indented and may themselves be further divided into indented substeps. Outline numbering conventions are used to identify substeps with the first level of substeps labelled with lower case alphabetic characters and the second level of substeps labelled with lower case roman numerals. If more than three levels are required these rules repeat with the fourth level using numeric labels. For example:</p>
84+
<emu-alg>
85+
1. Top-level step
86+
1. Substep.
87+
1. Substep.
88+
1. Subsubstep.
89+
1. Subsubsubstep
90+
1. Subsubsubsubstep
91+
1. Subsubsubsubsubstep
92+
</emu-alg>
93+
<p>A step or substep may be written as an &ldquo;if&rdquo; predicate that conditions its substeps. In this case, the substeps are only applied if the predicate is true. If a step or substep begins with the word &ldquo;else&rdquo;, it is a predicate that is the negation of the preceding &ldquo;if&rdquo; predicate step at the same level.</p>
94+
<p>A step may specify the iterative application of its substeps.</p>
95+
<p>A step that begins with &ldquo;Assert:&rdquo; asserts an invariant condition of its algorithm. Such assertions are used to make explicit algorithmic invariants that would otherwise be implicit. Such assertions add no additional semantic requirements and hence need not be checked by an implementation. They are used simply to clarify algorithms.</p>
96+
<p>Mathematical operations such as addition, subtraction, negation, multiplication, division, and the mathematical functions defined later in this clause should always be understood as computing exact mathematical results on mathematical real numbers, which unless otherwise noted do not include infinities and do not include a negative zero that is distinguished from positive zero. Algorithms in this standard that model floating-point arithmetic include explicit steps, where necessary, to handle infinities and signed zero and to perform rounding. If a mathematical operation or function is applied to a floating-point number, it should be understood as being applied to the exact mathematical value represented by that floating-point number; such a floating-point number must be finite, and if it is *+0* or *-0* then the corresponding mathematical value is simply 0.</p>
97+
<p>The mathematical function <emu-eqn aoid="abs">abs(_x_)</emu-eqn> produces the absolute value of _x_, which is <emu-eqn>-_x_</emu-eqn> if _x_ is negative (less than zero) and otherwise is _x_ itself.</p>
98+
<p>The mathematical function <emu-eqn aoid="min">min(_x1_, _x2_, ..., _xN_)</emu-eqn> produces the mathematically smallest of <emu-eqn>_x1_</emu-eqn> through <emu-eqn>_xN_</emu-eqn>. The mathematical function <emu-eqn aoid="max">max(_x1_, _x2_, ..., _xN_)</emu-eqn> produces the mathematically largest of <emu-eqn>_x1_</emu-eqn> through <emu-eqn>_xN_</emu-eqn>. The domain and range of these mathematical functions include *+&infin;* and *-&infin;*.</p>
99+
<p>The notation &ldquo;<emu-eqn aoid="modulo">_x_ modulo _y_</emu-eqn>&rdquo; (_y_ must be finite and nonzero) computes a value _k_ of the same sign as _y_ (or zero) such that <emu-eqn>abs(_k_) &lt; abs(_y_) and _x_-_k_ = _q_ &times; _y_</emu-eqn> for some integer _q_.</p>
100+
<p>The mathematical function <emu-eqn aoid="floor">floor(_x_)</emu-eqn> produces the largest integer (closest to positive infinity) that is not larger than _x_.</p>
101+
<emu-note>
102+
<p><emu-eqn>floor(_x_) = _x_-(_x_ modulo 1)</emu-eqn>.</p>
103+
</emu-note>
104+
</emu-clause>
105+
106+
58107
<!-- 9.2 -->
59108
<emu-clause id="sec-ecmascript-function-objects">
60109
<h1>(<a href="http://tc39.github.io/ecma262/#sec-ecmascript-function-objects">9.2</a>) ECMAScript Function Objects</h1>

0 commit comments

Comments
 (0)