- 6 -
terminator; but if a multi-line comment 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.
Productions of the lexical grammar are distinguished by having two colons “::” as separating punctuation.
5.1.3 The numeric string grammar
A second 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 the characters of the Unicode
character set. This grammar appears in section 9.3.1.
Productions of the numeric string grammar are distinguished by having three colons “:::” as punctuation.
5.1.4 The syntactic grammar
The syntactic grammar for ECMAScript is given in Sections 11, 12, 13, and 14. This grammar has ECMAScript
tokens defined by the lexical grammar as its terminal symbols (see section 5.1.2). It defines a set of productions,
starting from the goal symbol Program, that describe how sequences of tokens can form syntactically correct
ECMAScript programs.
When a stream of Unicode characters is to be parsed as an ECMAScript program, 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 syntax grammar. The program is syntactically in error if the tokens in the stream of
input elements cannot be parsed as a single instance of the goal nonterminal Program, with no tokens left over.
Productions of the syntactic grammar are distinguished by having just one colon “:” as punctuation.
The syntactic grammar as presented in Sections 11, 12, 13 and 14 is actually not a complete account of which
token sequences are accepted as correct ECMAScript programs. 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 end-of-line characters). Furthermore, certain token sequences that are described
by the grammar are not considered acceptable if an end-of-line character appears in certain “awkward” places.
5.1.5 Grammar Notation
Terminal symbols of the lexical and string grammars, and some of the terminal symbols of the syntactic grammar,
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 program exactly as written.
Nonterminal symbols are shown in italic type. The definition of a nonterminal 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:
WithStatement :
with ( Expression )
Statement
states that the nonterminal WithStatement represents the token with, followed by a left parenthesis token,
followed by an Expression, followed by a right parenthesis token, followed by a Statement. The occurrences of
Expression and Statement are themselves nonterminals. As another 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 to say, 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.
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: