ECMA-262(11th Edition) 5.1 Notational Conventions

文章翻译与相关名词解释

记录阅读ECMA-262得过程,主要是翻译文档以及弄明白里边的一些名词和过程得意思。第五章是ECMA-262的一些符号约定,所以先从这里开始。

读懂第五章需要了解的知识

【概念相关:编译原理】
定义:文法G为四元组(VN, VT, P, S).
其中VN是非终结符集;VT是终结符集;P是规则(α->β)的集合,α∈(VN∪VT)*且至少包含一个非终结符,β∈(VN∪VT)*.
S称作识别符或开始符,它是一个非终结符,至少要在一条规则中作为左部出现。

定义: 规则,又称重写规则,产生式或生成式,是形如α→β或α::=β的(α,β)有序对,其中α称为规则的左部,β称为规则的右部。这里使用的符号→(::=)读作“定义为”。例如A→a读作“A定义为a”。也把它说成是一条关于A的规则(产生式)。

定义: 设α→β是文法G(VN, VT, P, S)的规则,γ和δ是V*中的任意符号,若有符号串v,w满足v=γαδ,w=γβδ,则说v(应用规则α→β)直接产生w,或说w是v的直接推导,或说w直接规约到v,记作v ⇒ \Rightarrow w。

例如:对文法G({S},{0,1},P={S→0S1,S→01},S)有
(1)v=0S1,w=0011,直接推导:0S1 ⇒ \Rightarrow 0011,使用的规则:S→01,这里γ=0,δ=1。
(2)v=S,w=0S1,直接推导:S ⇒ \Rightarrow 0S1,使用的规则:S→0S1,这里γ= ε \varepsilon ε,w= ε \varepsilon ε
(3)v=0S1,w=00S11,直接推导:S ⇒ \Rightarrow 00S11,使用的规则:S→0S1,这里γ=0,δ=1。
更多可参考此链接

5.1 Syntactic and Lexical Grammars

5.1.1 context-free grammar

A context-free grammar consists of a number of productions. Each production has an abstract symbol called a nonterminal as its left-hand side, and a sequence of zero or more nonterminal and terminal symbols as its right-hand side. For each grammar, the terminal symbols are drawn from a specified alphabet.
-——ECMA-262 5.1.1

一个上下文无关文法由许多生产规则组成。每个生产规则组成格式如下:
在左边,是一个非终结符。在右边,是零个或多个非终结符和终结符组成的序列。

context-free grammar:上下文无关文法
nonterminal:非终结符 — 相当于变量或者代名词(比如主语,谓语)
left-hand side:左部,指的是文法规则的左边。
terminal:终结符 — 相当于具体的词汇,是基础符号,不可通过文法生成。(比如你,我,大学生)。
production:产生式,用来说明(或定义)句子的组成结构,或者说产生句子的规则。

Starting from a sentence consisting of a single distinguished nonterminal, called the goal symbol, a given context-free grammar specifies a language, namely, the (perhaps infinite) set of possible sequences of terminal symbols that can result from repeatedly replacing any nonterminal in the sequence with a right-hand side of a production for which the nonterminal is the left-hand side.
-——ECMA-262 5.1.1

一个给定的上下文无关文法描述一种语言。语言是所有按照规则生成的句子的集合。而句子由终结符组成。句子是由终结符反复的替换序列中右部带有产生式的在左部的任意非终结符形成的。

goal symbol:即标识符或开始符,是一个非终结符,至少要在一条规则中作为左部出现。
language:语言,是由文法所描述的,该文法一切句子的集合。
sentence:句子,仅有终结符组成的符号串。

在这里有一个问题,ECMA-262中描述的goal symbol是否是start symbol,在Stackoverflow上的帖子’Is goal symbol the same thing as start symbol in context-free-grammar’的Answer中回答是Yes,并说在讨论分析器时goal symbol用的更多一些。并告诉我们ECMA-262里这几段可能是从Java Language Specification里粘贴过来的

5.1.2 The Lexical and RegExp Grammars

A lexical grammar for ECMAScript is given in clause 11. This grammar has as its terminal symbols Unicode code points that conform to the rules for SourceCharacter defined in 10.1. It defines a set of productions, starting from the goal symbol InputElementDiv, InputElementTemplateTail, or InputElementRegExp, or InputElementRegExpOrTemplateTail, that
describe how sequences of such code points are translated into a sequence of input elements.

词法遵循的规则在11节。这种语法中的Unicode code point遵从定义在10.1中的SourceCharacter的规则,并且作为这种语法的终结符。它定义了生产式的集合,它开始于开始符InputElementDiv, InputElementTemplateTail, InputElementRegExp,或InputElementRegExpOrTemplateTail,并且描述了这种code points的序列怎样被翻译成输入元素的序列。

lexical grammar:词法语法
Unicode code point:简单来讲就是Unicode中每个字符的编号,在这一段中指的应该是ES中定义了一些编号所代表的Unicode字符作为文法的终结符。

The notion of a code point is used for abstraction, to distinguish both the number from an encoding as a sequence of bits, and the abstract character from a particular graphical representation (glyph).
This is because one may wish to make these distinctions to:
encode a particular code space in different ways, or display a character via different glyphs.
=>Code Point

SourceCharacter:如下

Syntax
 SourceCharacter ::
  any Unicode point

相当于非终结符SourceCharacter可以替换为任何Unicode字符编码。比如(ECMA ⇒ \Rightarrow ECMA)
InputElementDiv:如下

Syntax
 InputElementDiv ::
  WhiteSpace
  LineTerminator
  Comment
  CommonToken
  DivPunctuator
  RightBracePunctuator

对于ECMA-262中的一些非终结符,完全可以用字面意思理解。这一段句法表示的是InputElementDiv可以被下边这一系列的词汇替换,比如WhiteSpace(比如U+009所表示的tab,详细看ECMA-262 11.2)。InputElementTemplateTail等非终结符详细意思请详见ECMA-262.

Input elements other than white space and comments form the terminal symbols for the syntactic grammar for ECMAScript and are called ECMAScript tokens. These tokens are the reserved words, identifiers, literals, and punctuators of the ECMAScript language. Moreover, line terminators, although not considered to be tokens, also become part of the stream of input elements and guide the process of automatic semicolon insertion (11.9). Simple white space and single-line comments are discarded and do not appear in the stream of input elements for the syntactic grammar. A MultiLineComment (that is, a comment of the form /*…*/ regardless of whether it spans more than one line) is likewise simply discarded if it contains no line terminator; but if a MultiLineComment contains one or more line terminators, then it is replaced by a single line terminator, which becomes part of the stream of input elements for the syntactic grammar.

除了空格和注释之外的输入元素形成了ECMAScript语法的终结符,并被称为称为ECMAScript词汇(token在编译原理中指的是词法单元,这里简称为词汇)。这些词汇是ECMAScript语言的保留字、标识符、字面量和标点符号。 此外,行结束符虽然不被认为是词汇,但也成为了输入元素流的一部分,并且会指导自动插入分号的过程。普通的空白和单行注释将被舍弃,并且不会出现在句法的输入元素流中。一个多行注释(比如/**/,并且不管他是否跨越了多行)如果不包含行结束符,也会同样的被丢弃。但是如果一个多行注释包括了一个或多个行结束符,那么他就会被一个单行结束符所替换,并且作为词法输入流中的一部分。
line terminator:如下

The sequence <CR><LF> is commonly used as a line terminator. It should be considered a single SourceCharacter for the purpose of reporting line numbers.
<CR>是回车(U+000D),也就是C中的\n,
<LF>是换行(U+000A),也就是C中的\r

包括换行符,回车,行分隔符和段落分隔符。除了这四个以外的line breaking Unicode不是LineTerminator。序列’<CR><LF>'通常也作为行结束符。

token:词法单元,或单词,词汇。是字符输入流中的一些字符的序列。

A RegExp grammar for ECMAScript is given in 21.2.1. This grammar also has as its terminal symbols the code points as defined by SourceCharacter. It defines a set of productions, starting from the goal symbol Pattern, that describe how sequences of code points are translated into regular expression patterns.

ES中的正则表达式语法在21.2.1(现在不讨论RegExp的具体含义)中被定义。此语法也有被SourceCharacter定义的作为终结符的代码点。此语法定义了一个产生式的集合,从开始符Pattern开始,并且这些产生式描述了代码点的序列怎样被翻译为正则表达式的模式。

Productions of the lexical and RegExp grammars are distinguished by having two colons “::” as separating punctuation. The lexical and RegExp grammars share some productions.

正则表达式语法和词法的产生式被两个冒号“::”辨别,并且作为分隔标点。词法和正则表达式语法共用一些产生式。

5.1.3 The Numeric String Grammar

Another grammar is used for translating Strings into numeric values. This grammar is similar to the part of the lexical grammar having to do with numeric literals and has as its terminal symbols SourceCharacter. This grammar appears in 7.1.4.1.
Productions of the numeric string grammar are distinguished by having three colons “:::” as punctuation.

另一个语法被用来把字符串转化成数值。这个语法和一部分与数字字面值有关的词法相似,并且也有它的终结符。这个语法在7.1.4.1中出现。
数字字符串语法的产生式被三个冒号“:::”辨别,并且作为标点符号使用。

5.1.4 The Syntactic Grammar

The syntactic grammar for ECMAScript is given in clauses 11, 12, 13, 14, and 15. This grammar has ECMAScript tokens defined by the lexical grammar as its terminal symbols (5.1.2). It defines a set of productions, starting from two alternative goal symbols Script and Module, that describe how sequences of tokens form syntactically correct independent components of ECMAScript programs.

ES的句法在11,12,13,14和15节中给出。此语法用被词法定义的ES词汇作为终结符。它定义了一个产生式的集合,集合中的产生式开始于两个可选的开始符Script和Module,并且描述了词汇序列怎样生成独立且句法正确的ES程序组件。

Script:(待写,估计就是代码,相当于<script></script>之间的部分)
Module:(待写,估计就是模块,这俩其实就是在说JS代码的生成方式,最开始是一个标识符,然后经过替换等推导出代码。比如<句子>::=<主语><谓语>,那么首先我先需要有<句子>这个概念,从句子开始,我要把右部的<主语>和<谓语>替换成具体的词,比如<主语>换成我,<谓语>换成吃饭,这样<句子>就是我吃饭,代码形成的方式应该也是这样的。)

When a stream of code points is to be parsed as an ECMAScript Script or Module, it is first converted to a stream of input elements by repeated application of the lexical grammar; this stream of input elements is then parsed by a single application of the syntactic grammar. The input stream is syntactically in error if the tokens in the stream of input elements cannot be parsed as a single instance of the goal nonterminal (Script or Module), with no tokens left over.

当代码点流被解析为ES Script或Module的时候,它会第一次被词法的反复应用转换到输入流中。此输入流之后会被句法的一次应用解析。输入流中的词汇如果无法被解析为开始符的单个实例(Script或Module),那么就会进入句法错误状态,并且此时流中没有词汇留下。

When a parse is successful, it constructs a parse tree, a rooted tree structure in which each node is a Parse Node. Each Parse Node is an instance 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 children, 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.

一次解析成功后,他就会创建一棵语法树,这是一棵结点都是Parse Node的有根树。每一个Parse Node 是语法中字符的实例;它代表了可由那个符号获得的源文本的种类。代表了整个源文本的语法树的根节点是开始符的一个实例。当一个Parse Node 是非终结符的实例时,他也是一些把那个非终结符作为左部的产生式的实例。此外,它有零个或多个孩子,每个孩子都是产生式的右部:每个孩子是一个作为对应符号实例的Parse Node。
symbol:(待写,这里的symbol初步认为是语法树中的符号)
source text:(待写,初步认定为symbol可以生成的句子)

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 the same Parse Node 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.

每次解析器被调用都会创建新的Parse Nodes,并且即使源文本完全相同,它们也永远不会在解析时被重用。当且仅当两个Parse Nodes表示同一种源文本,是同一个语法symbol的实例并且产生自同一个解析器时,他们才会被视为相同的Parse Nodes。

NOTE 1 Parsing the same String multiple times will lead to different Parse Nodes. For example, consider:
  let str = “1 + 1;”;
  eval(str);
  eval(str);
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.
NOTE 2 Parse Nodes are specification artefacts, and implementations are not required to use an analogous data structure.

NOTE1:多次解析相同的String会产生不同的Parse Nodes,例如:
  let str = “1 + 1;”;
  eval(str);
  eval(str);
每次调用eval会把str转化成一个ES的源文本并且会执行一次独立的解析并且这次解析会创建出它自己的独立的Parse Nodes.每棵树都是截然不同的即使每一次解析都对从同一个String里获得的源文本进行操作。
NOTE2:Parse Nodes是人为规定的,并且实现它不需要使用类似的数据结构。

Productions of the syntactic grammar are distinguished by having just one colon “:” as punctuation.

句法的产生式会用一个冒号“:”作为标点符号进行辨别。

The syntactic grammar as presented in clauses 12, 13, 14 and 15 is not a complete account of which token sequences are accepted as a correct ECMAScript Script or Module. Certain additional token sequences are also accepted, namely, those that would be described by the grammar if only semicolons were added to the sequence in certain places (such as before line terminator characters). Furthermore, certain token sequences that are described by the grammar are not considered acceptable if a line terminator character appears in certain “awkward” places.

第12、13、14和15章中的句法并不能完全说明哪些词汇序列被接受为正确的ES Script或Module。某些附加的词汇序列也可以被接受,也就是说仅有分号添加在序列的确定位置上的那些才会被语法描述(比如行结束符之前的字符)。此外,某些语法描述的词汇序列的行结束符出现在错误的地方时将不会被认为是可接受的。

In certain cases, in order to avoid ambiguities, the syntactic grammar uses generalized productions that permit token sequences that do not form a valid ECMAScript Script or Module. For example, this technique is used for object literals and object destructuring patterns. In such cases a more restrictive supplemental grammar is provided that further restricts the acceptable token sequences. Typically, an early error rule will then define an error condition if “P is not covering an N”, where P is a Parse Node (an instance of the generalized production) and N is a nonterminal from the supplemental grammar. Here, the sequence of tokens originally matched by P is parsed again using N as the goal symbol. (If N takes grammatical parameters, then they are set to the same values used when P was originally parsed.) An error occurs if the sequence of tokens cannot be parsed as a single instance of N, with no tokens left over. Subsequently, algorithms access the result of the parse using a phrase of the form “the N that is covered by P”. This will always be a Parse Node (an instance of N, unique for a given P), since any parsing failure would have been detected by an early error rule.

在某些情况下,为了避免二义性,句法会使用那些接纳不产生合法ES Script或Module的词汇序列的广义产生式。例如,这种技术会被用在对象字面量和对象的析构函数模式上。在这种情况下,一种更严格的补充语法会被用于限制那些词汇序列。通常来说,Parse Node§不包括一个补充语法中的非终结符(N)时,早期的错误规则会定义一个错误的条件。此时,原来被P匹配的词汇序列会再次使用N作为开始符进行解析(如果N采用语法参数,那么它们将被设置为最初解析P时使用的相同值)。当词汇序列不能被解析为N的一个实例,错误将会发生,并且会失去所有词汇。随后,算法会使用形式为“被P覆盖的N”的短语访问解析结果。这将一直作为一个Parse Node(一种N的实例,对于给定的P是唯一的),因为任何的解析错误都会被早期错误规则所检测。

early error:(待写)

5.1.5 Grammar Notation

Terminal symbols are shown in fixed width font, both in the productions of the grammars and throughout this specification whenever the text directly refers to such a terminal symbol. These are to appear in a script exactly as written. All terminal symbol code points specified in this way are to be understood as the appropriate Unicode code points from the Basic Latin range, as opposed to any similar-looking code points from other Unicode ranges. A code point in a terminal symbol cannot be expressed by a \UnicodeEscapeSequence.

只要文本直接指向这样的终结符,它就会在语法产生式以及整个标准文档中用固定宽度的字体显示。这种情况会像所说的一样在脚本中被书写。所有以这种方式规定的终结符代码点会被认为是取自基础拉丁范围中的合适的Unicode代码点,而不是其他范围内的任何长得像的代码点。一个终结符的代码点不能用\UnicodeEscapeSequence进行表达。
UnicodeEscapeSequence:

Nonterminal symbols are shown in italic type. The definition of a nonterminal (also called a “production”) is introduced by the name of the nonterminal being defined followed by one or more colons. (The number of colons indicates to which grammar the production belongs.) One or more alternative right-hand sides for the nonterminal then follow on succeeding lines. For example, the syntactic definition:
   ArgumentList :
    AssignmentExpression
    ArgumentList , AssignmentExpression
states that an ArgumentList may represent either a single AssignmentExpression or an ArgumentList, followed by a comma, followed by an AssignmentExpression. This definition of ArgumentList is recursive, that is, it is defined in terms of itself. The result is that an ArgumentList may contain any positive number of arguments, separated by commas, where each argument expression is an AssignmentExpression. Such recursive definitions of nonterminals are common.

非终结符以斜体显示。一个非终结符(也叫产生式)是由定义它的名称后跟随的一个或多个冒号引入的(冒号的个数说明这个产生式属于哪种语法)。一个或多个可选的右部在后面跟随的行中。例如下面的句法定义:

   ArgumentList :
    AssignmentExpression
    ArgumentList , AssignmentExpression

上面的句法说明了一个ArgumentList可能代表一个单独的AssignmentExpression或者一个ArgumentList,之后跟着一个逗号,之后再跟着一个AssignmentExpression.这种定义ArgumentList的方式是递归的,就是说,它是根据自身来定义的。这种定义的结果是一个ArgumentList可能包含以逗号分割的多个正数参数,并且这些整数都是AssignmentExpression.这种递归定义非终结符的方式是很常见的。

The subscripted suffix “opt”, which may appear after a terminal or nonterminal, indicates an optional symbol. The alternative containing the optional symbol actually specifies two right-hand sides, one that omits the optional element and one that includes it. This means that:
   VariableDeclaration :
     BindingIdentifier Initializeropt
is a convenient abbreviation for:
   VariableDeclaration :
     BindingIdentifier
     BindingIdentifier Initializer
(下面更长的例子不再复述)

下标后缀“opt”可能出现在一个终结符或非终结符后,说明一个可选择的记号。包含可选记号的可选项实际上定义了两种右部,一种忽略可选元素而另一个包含它,这意味着:

   VariableDeclaration :
     BindingIdentifier Initializeropt

是下面这种形式的缩写:

   VariableDeclaration :
     BindingIdentifier
     BindingIdentifier Initializer

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
(后面的例子不再复述)
Multiple parameters produce a combinatory number of productions, not all of which are necessarily referenced in a complete grammar.

一个产生式可以用“[parameters]”的形式参数化,在出现时一般作为一个被此产生式定义的非终结符的后缀。“parameters”可能是一个名称,也有可能是用逗号分割的名称列表。一个参数化的产生式是一系列产生式的简写,它们一般定义为所有参数名字的组合,在参数前加上下划线后,附加到那个参数化的非终结符后面。这意味着:
    StatementList[Return] :
      ReturnStatement
      ExpressionStatement
是下面这种形式的简写:
    StatementList :
      ReturnStatement
      ExpressionStatement
    StatementList_Return :
      ReturnStatement
      ExpressionStatement
多重的参数产生一系列组合产生式,并且并不是所有的参数都必须在一个完整的语法中被引用。

References to nonterminals on the right-hand side of a production can also be parameterized.
A nonterminal reference may have both a parameter list and an “opt” suffix.
Prefixing a parameter name with “?” on a right-hand side nonterminal reference makes that parameter value dependent upon the occurrence of the parameter name on the reference to the current production’s left-hand side symbol. For example:
    VariableDeclaration[In] :
      BindingIdentifier Initializer[?In]
is an abbreviation for:
    VariableDeclaration :
      BindingIdentifier Initializer
    VariableDeclaration_In :
      BindingIdentifier Initializer_In

一个产生式的右部也可以被参数化。
一个非终结符的引用可以同时有参数和opt
给一个右部非终结符的参数加上“?”的前缀会让它的参数值是否出现取决于现在产生式左部的记号。

If a right-hand side alternative is prefixed with “[+parameter]” that alternative is only available if the named parameter was used in referencing the production’s nonterminal symbol. If a right-hand side alternative is prefixed with “[ ~parameter]~” that alternative is only available if the named parameter was not used in referencing the production’s nonterminal symbol.

如果一个右部备选项有了“[+parameter]”的前缀,那么它将只在这个parameter被用来引用产生式的非终结符时可用。如果一个右部备选项有了“[ ~parameter]”的前缀,那么它将仅在这个parameter没有被用来引用这个产生式的非终结符时可用。

When the words “one of” follow the colon(s) in a grammar definition, they signify that each of the terminal symbols on the following line or lines is an alternative definition.
    NonZeroDigit :: one of
      1 2 3 4
    which is merely a convenient abbreviation for:
    NonZeroDigit ::
      1
      2
      3
      4

在定义语法时,如果词组“one of” 跟在了冒号后边,那么它们将说明下面一行或几行的每个终结符都是一个备选项。

  NonZeroDigit :: one of
    1 2 3 4

这只是下面这种形式的简写:

  NonZeroDigit ::
    1
    2
    3
    4

If the phrase “[empty]” appears as the right-hand side of a production, it indicates that the production’s right-hand side contains no terminals or nonterminals.

如果[empty]出现在产生式的右部,那么它表明了产生式的右部不包含任何终结符或非终结符。

If the phrase “[lookahead ∉ set]” appears in the right-hand side of a production, it indicates that the production may not be used if the immediately following input token sequence is a member of the given set. The set can be written as a comma separated list of one or two element terminal sequences enclosed in curly brackets. For convenience, the set can also be written as a nonterminal, in which case it represents the set of all terminals to which that nonterminal could expand. If the set consists of a single terminal the phrase “[lookahead ≠ terminal]” may be used.
For example, given the definitions:
  DecimalDigit :: one of
    0 1 2 3 4 5 6 7 8 9
  DecimalDigits ::
    DecimalDigit
    DecimalDigits DecimalDigit

如果短语[lookahead ∉ set]出现在一个产生式的右部,则表示如果紧随其后输入的词汇序列是给定集合的一个子集,那么该产生式可能不会被使用。此集合可以写成逗号分隔的列表的形式,其中作为元素的终结符序列须用大括号括起来。为了方便,集合也可以用一个非终结符表示,此时这个非终结符将表示所有它代表的所有终结符的集合。如果集合由一个单独的终结符组成,那么将用短语“[lookahead ≠ terminal]”进行表示。

the definition:
    LookaheadExample ::
      n [lookahead ∉ { 1 , 3 , 5 , 7 , 9 }] DecimalDigits
      DecimalDigit [lookahead ∉ DecimalDigit]
matches either the letter n followed by one or more decimal digits the first of which is even, or a decimal digit not followed by another decimal digit.

定义:
(见引用)
匹配n,以及后边跟着的一个或多个十进制数字,并且保证第一个数字是偶数;或者一个单独的十进制数字,后边不跟其他十进制数字。

Similarly, if the phrase “[lookahead ∈ set]” appears in the right-hand side of a production, it indicates that the production may only be used if the immediately following input token sequence is a member of the given set. If the set consists of a single terminal the phrase “[lookahead = terminal]” may be used.

同样的,如果短语“[lookahead ∈ set]”出现在产生式的右部,那么它表示产生式可能只在后边紧跟的词汇序列是给定集合的子集时才会被使用。如果集合只包含一个单独的终结符,那么将使用短语“[lookahead = terminal]”

If the phrase “[no LineTerminator here]” appears in the right-hand side of a production of the syntactic grammar, it indicates that the production is a restricted production: it may not be used if a LineTerminator occurs in the input stream at the indicated position. For example, the production:
  ThrowStatement :
    throw [no LineTerminator here] Expression ;
indicates that the production may not be used if a LineTerminator occurs in the script between the throw token and the Expression.

当短语“[no LineTerminator here]”出现在一个句法产生式的右部,那么它表示这是一个有限制的产生式:它可能在一个LineTerminator出现在输入流中表明的位置时不被使用。例如:
(例子在引用中)
表明一个产生式可能不会在一个LineTerminator出现在代码的throw和Expression之间时被使用。
Expression:(待写,大概就是表达式,具体的定义在文档里)

Unless the presence of a LineTerminator is forbidden by a restricted production, any number of occurrences of LineTerminator may appear between any two consecutive tokens in the stream of input elements without affecting the syntactic acceptability of the script.
When an alternative in a production of the lexical grammar or the numeric string grammar appears to be a multi-code point token, it represents the sequence of code points that would make up such a token.

除非LineTerminator被一个有限制的产生式所禁止,否则任意个数的LineTerminator可能出现在输入流中不影响代码句法接受性的任意两个连续的词汇之间。
当一个词法或数字字符串语法产生式中的备选项看起来是多重代码点词汇时,它将表示组成这样的词汇的代码点序列。

The right-hand side of a production may specify that certain expansions are not permitted by using the phrase “but not” and then indicating the expansions to be excluded. For example, the production:
  Identifier ::
    IdentifierName but not ReservedWord
means that the nonterminal Identifier may be replaced by any sequence of code points that could replace IdentifierName provided that the same sequence of code points could not replace ReservedWord.

右部的一个产生式使用短语“but not”指定某些表达式不被允许使用。也表明这些表达式会被排除在外。例如:
(如引用中所示)
意味着非终结符Identifier可以由任何可以替换IdentifierName的代码点所替换但是这些代码点不能替换ReservedWord。

Finally, a few nonterminal symbols are described by a descriptive phrase in sans-serif type in cases where it would be impractical to list all the alternatives:
  SourceCharacter ::
    any Unicode code point

最后,一些非终结符可以在它无法轻易的列出可选项时被一个无衬线体的描述性的短语所描述。
sans-serif:
即:Font ABC(无衬线体) - Font ABC(衬线体)

句法词法部分到此结束,但是还有许多东西在理解上存在问题,等弄明白后会记录下来。

这只是5.1的内容,弄明白这些其实也并不足以用来理解明白ECMA-262这篇spec,所以还要继续学习5.2的算法部分,等把5.1的所有东西弄得差不多后进行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值