March 1999 Draft
JavaScript 2.0
Notation
previousupnext

Tuesday, February 16, 1999

Informal Syntax

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

VersionsAndRenames 
   [< VersionRange [: Identifier, ... , VersionRange [: Identifier>]
VersionRange 
   Version
|  [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.

SampleList 
   «empty»
|  ... 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

   {normalinitial}
   {allowInnoIn}

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,

AssignmentExpression, 
   ConditionalExpression,
|  LeftSideExpression = AssignmentExpressionnormal,
|  LeftSideExpression CompoundAssignment AssignmentExpressionnormal,

expands into the following four rules:

AssignmentExpressionnormal,allowIn 
   ConditionalExpressionnormal,allowIn
|  LeftSideExpressionnormal = AssignmentExpressionnormal,allowIn
|  LeftSideExpressionnormal CompoundAssignment AssignmentExpressionnormal,allowIn
AssignmentExpressionnormal,noIn 
   ConditionalExpressionnormal,noIn
|  LeftSideExpressionnormal = AssignmentExpressionnormal,noIn
|  LeftSideExpressionnormal CompoundAssignment AssignmentExpressionnormal,noIn
AssignmentExpressioninitial,allowIn 
   ConditionalExpressioninitial,allowIn
|  LeftSideExpressioninitial = AssignmentExpressionnormal,allowIn
|  LeftSideExpressioninitial CompoundAssignment AssignmentExpressionnormal,allowIn
AssignmentExpressioninitial,noIn 
   ConditionalExpressioninitial,noIn
|  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
previousupnext