|
JavaScript 1.4 Grammar
|
 |
Monday, May 3, 1999
This is an LR(1) grammar written by waldemar that describes the state of ECMAScript
as of February 1999. The grammar is complete except for semicolon insertion (the OptionalSemicolon
grammar state can sometimes reduce to «empty») and distinguishing RegularExpression
from / and /=. Also, there is some controversy about elision in array literals, so this feature has been
omitted for now.
Grammar syntax
Grammar productions may expand nonterminals into empty right sides. Such right sides are indicated as «empty».
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:
Statements such as
a {normal, initial}
b {allowIn, noIn}
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,
AssignmentExpressiona,b
ConditionalExpressiona,b
| LeftSideExpressiona = AssignmentExpressionnormal,b
| LeftSideExpressiona CompoundAssignment AssignmentExpressionnormal,b
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.
Expressions
a {normal, initial}
b {allowIn, noIn}
Primary Expressions
this
| null
| true
| false
| Number
| String
| Identifier
| RegularExpression
ParenthesizedExpression ( Expressionnormal,allowIn )
Function Expressions
Object Literals
Array Literals
Left-Side Expressions
Postfix Operators
Unary Operators
Multiplicative Operators
MultiplicativeExpressiona
Additive Operators
Bitwise Shift Operators
Relational Operators
RelationalExpressiona,allowIn
RelationalExpressiona,noIn
Equality Operators
Binary Bitwise Operators
Binary Logical Operators
Conditional Operator
Assignment Operators
*=
| /=
| %=
| +=
| -=
| <<=
| >>=
| >>>=
| &=
| ^=
| |=
Expressions
Statements
w {noShortIf, full}
Empty Statement
Expression Statement
Variable Definition
Block
Labeled Statements
If Statement
Switch Statement
Do-While Statement
While Statement
For Statements
With Statement
Continue and Break Statements
Return Statement
Throw Statement
Try Statement
CatchClause catch ( Identifier ) Block
FinallyClause finally Block
Function Definition
FormalParameter Identifier
Programs
Waldemar Horwat
Last modified Monday, May 3, 1999