|
JavaScript 2.0
Formal Description
Grammar Notation
|
Wednesday, May 12, 1999
This page explains the formal notation used in the parser grammar and the lexer grammar and their associated semantics. Please refer to the notation page for a description of the informal notation used on the other pages.
Each LR(1) parser grammar and lexer grammar rule consists of a nonterminal, a , and one or more expansions of the nonterminal separated by vertical bars (|). The expansions are usually listed on separate lines but may be listed on the same line if they are short. An empty expansion is denoted as «empty».
Consider the sample rule:
... Identifier, ... IdentifierThis rule states that the nonterminal SampleList can represent one of four kinds of sequences of input tokens:
... followed by some expansion of the nonterminal Identifier;, and ... and an expansion of the nonterminal
Identifier.Input tokens are characters (and the special End placeholder) in the lexer
grammar and lexer tokens in the parser grammar. Spaces separate input tokens and nonterminals
from each other. An input token that consists of a space character is denoted as «SP».
Other non-ASCII or non-printable characters are denoted by also using « and »,
as described on the main notation page.
Many rules in the grammars occur in groups of analogous rules. Rather than list them individually, these groups have been summarized using the shorthand illustrated by the example below:
Metadefinitions such as
introduce grammar arguments a and b. 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, the sample rule
= AssignmentExpressionnormal,bexpands into the following four rules:
= AssignmentExpressionnormal,allowIn= AssignmentExpressionnormal,noIn= AssignmentExpressionnormal,allowIn= AssignmentExpressionnormal,noInAssignmentExpressionnormal,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 grammar's starting nonterminal; these are ignored.
A few lexer rules have too many expansions to be practically listed. These are specified by descriptive text instead of a list of expansions after the .
Some lexer rules contain the metaword except. These rules match any expansion that is listed before the except
but that does not match any expansion after the except. All of these rules ultimately expand into single characters.
For exaple, the rule below matches any single UnicodeCharacter except the * and
/ characters: