February 1999 Draft
JavaScript 2.0

Tuesday, February 16, 1999


JavaScript 2.0 is an experimental proposal maintained by waldemar for future changes in the JavaScript language. At this stage the emphasis is on developing the broad concepts of the language; many of the details will be worked out later. The eventual language may differ significantly from this proposal, but the goal is to move in the directions indicated here and do so via a coordinated plan rather than adding miscellaneous features ad hoc on a release-by-release basis.


Informal Syntax

The main body of this proposal uses an informal syntax to describe language constructs. An example is the following:

   [< VersionRange [: Identifier, ... , VersionRange [: Identifier>]
|  [Version.. [Version]

VersionsAndRenames and VersionRange are the names of the grammar rules. The black square brackets represent optional items, and the black ... together with its neighbors represents optional repetition of zero or more items, so a VersionsAndRenames can have zero or more sets of VersionRange [: Identifier] separated by commas. A black | indicates that either its left or right alternative may be present, but not both; |'s have the lowest metasymbol precedence. Syntactic tokens to be typed literally are in a bold blue monospaced font. Grammar nonterminals are in green italic and correspond to the nonterminals in the grammar appendix.

The informal syntax descriptions sometimes list only the general or simplified syntax. Please refer to the grammar appendix for the actual syntax.

Grammar Syntax

The LR(1) grammar rules have the format shown below. All of the grammar rules are listed in the grammar appendix.

|  ... Identifier
|  SampleListPrefix
|  SampleListPrefix , ... Identifier

This sample rule states that the nonterminal SampleList can represent one of four kinds of sequences of program tokens:

A number of rules in the grammar occur in groups of analogous rules. Rather than list them individually, these groups have been summarized using the shorthand illustrated by the example below:

Metastatements such as


introduce grammar arguments and . If these arguments later parametrize the nonterminal on the left side of a rule, that rule is implicitly replicated into a set of rules in each of which a grammar argument is consistently substituted by one of its variants. For example,

|  LeftSideExpression = AssignmentExpressionnormal,
|  LeftSideExpression CompoundAssignment AssignmentExpressionnormal,

expands into the following four rules:

|  LeftSideExpressionnormal = AssignmentExpressionnormal,allowIn
|  LeftSideExpressionnormal CompoundAssignment AssignmentExpressionnormal,allowIn
|  LeftSideExpressionnormal = AssignmentExpressionnormal,noIn
|  LeftSideExpressionnormal CompoundAssignment AssignmentExpressionnormal,noIn
|  LeftSideExpressioninitial = AssignmentExpressionnormal,allowIn
|  LeftSideExpressioninitial CompoundAssignment AssignmentExpressionnormal,allowIn
|  LeftSideExpressioninitial = AssignmentExpressionnormal,noIn
|  LeftSideExpressioninitial CompoundAssignment AssignmentExpressionnormal,noIn

AssignmentExpressionnormal,allowIn is now an unparametrized nonterminal and processed normally by the grammar.

Some of the expanded rules (such as the fourth one in the example above) may be unreachable from the starting nonterminal Program; these are ignored.

Waldemar Horwat
Last modified Tuesday, February 16, 1999