Title: JavaScript 2.0 Syntactic Grammar
Author: Waldemar Horwat
Company: Netscape

JavaScript 2.0 Syntactic Grammar 4-Mar-2002

Terminals
General tokens: Identifier Number RegularExpression String VirtualSemicolon
Punctuation tokens: ! != !== % %= & && &&= &= ( ) * *= + ++ += , - -- -= . ... / /= : :: ; < << <<= <= = == === > >= >> >>= >>> >>>= ? [ ] ^ ^= ^^ ^^= { | |= || ||= } ~
Reserved words: abstract as break case catch class const continue default delete do else export extends false final finally for function if implements import in instanceof interface is namespace new null package private public return static super switch this throw true try typeof use var void while with
Future reserved words: debugger enum goto native protected synchronized throws transient volatile
Non-reserved words: exclude get include named set
Expressions
β ∈ {allowIn, noIn}
Identifiers
Identifier ⇒
	Identifier
|	get
|	set
|	exclude
|	include
|	named
Qualified Identifiers
Qualifier ⇒
	Identifier
|	public
|	private
SimpleQualifiedIdentifier ⇒
	Identifier
|	Qualifier :: Identifier
ExpressionQualifiedIdentifier ⇒ ParenExpression :: Identifier
QualifiedIdentifier ⇒
	SimpleQualifiedIdentifier
|	ExpressionQualifiedIdentifier
Unit Expressions
UnitExpression ⇒
	ParenListExpression
|	Number [no line break] String
|	UnitExpression [no line break] String
Primary Expressions
PrimaryExpression ⇒
	null
|	true
|	false
|	public
|	Number
|	String
|	this
|	RegularExpression
|	UnitExpression
|	ArrayLiteral
|	ObjectLiteral
|	FunctionExpression
ParenExpression ⇒ ( AssignmentExpression^allowIn )
ParenListExpression ⇒
	ParenExpression
|	( ListExpression^allowIn , AssignmentExpression^allowIn )
Function Expressions
FunctionExpression ⇒
	function FunctionSignature Block
|	function Identifier FunctionSignature Block
Object Literals
ObjectLiteral ⇒
	{ }
|	{ FieldList }
FieldList ⇒
	LiteralField
|	FieldList , LiteralField
LiteralField ⇒ FieldName : AssignmentExpression^allowIn
FieldName ⇒
	Identifier
|	String
|	Number
|	ParenExpression
Array Literals
ArrayLiteral ⇒ [ ElementList ]
ElementList ⇒
	LiteralElement
|	ElementList , LiteralElement
LiteralElement ⇒
	«empty»
|	AssignmentExpression^allowIn
Super Expressions
SuperExpression ⇒
	super
|	FullSuperExpression
FullSuperExpression ⇒ super ParenExpression
Postfix Expressions
PostfixExpression ⇒
	AttributeExpression
|	FullPostfixExpression
|	ShortNewExpression
PostfixExpressionOrSuper ⇒
	PostfixExpression
|	SuperExpression
AttributeExpression ⇒
	SimpleQualifiedIdentifier
|	AttributeExpression MemberOperator
|	AttributeExpression Arguments
FullPostfixExpression ⇒
	PrimaryExpression
|	ExpressionQualifiedIdentifier
|	FullNewExpression
|	FullPostfixExpression MemberOperator
|	SuperExpression DotOperator
|	FullPostfixExpression Arguments
|	FullSuperExpression Arguments
|	PostfixExpressionOrSuper [no line break] ++
|	PostfixExpressionOrSuper [no line break] --
FullNewExpression ⇒
	new FullNewSubexpression Arguments
|	new FullSuperExpression Arguments
FullNewSubexpression ⇒
	PrimaryExpression
|	QualifiedIdentifier
|	FullNewExpression
|	FullNewSubexpression MemberOperator
|	SuperExpression DotOperator
ShortNewExpression ⇒
	new ShortNewSubexpression
|	new SuperExpression
ShortNewSubexpression ⇒
	FullNewSubexpression
|	ShortNewExpression
Member Operators
MemberOperator ⇒
	DotOperator
|	. ParenExpression
DotOperator ⇒
	. QualifiedIdentifier
|	Brackets
Brackets ⇒
	[ ]
|	[ ListExpression^allowIn ]
|	[ NamedArgumentList ]
Arguments ⇒
	ParenExpressions
|	( NamedArgumentList )
ParenExpressions ⇒
	( )
|	ParenListExpression
NamedArgumentList ⇒
	LiteralField
|	ListExpression^allowIn , LiteralField
|	NamedArgumentList , LiteralField
Unary Operators
UnaryExpression ⇒
	PostfixExpression
|	delete PostfixExpression
|	void UnaryExpression
|	typeof UnaryExpression
|	++ PostfixExpressionOrSuper
|	-- PostfixExpressionOrSuper
|	+ UnaryExpressionOrSuper
|	- UnaryExpressionOrSuper
|	~ UnaryExpressionOrSuper
|	! UnaryExpression
UnaryExpressionOrSuper ⇒
	UnaryExpression
|	SuperExpression
Multiplicative Operators
MultiplicativeExpression ⇒
	UnaryExpression
|	MultiplicativeExpressionOrSuper * UnaryExpressionOrSuper
|	MultiplicativeExpressionOrSuper / UnaryExpressionOrSuper
|	MultiplicativeExpressionOrSuper % UnaryExpressionOrSuper
MultiplicativeExpressionOrSuper ⇒
	MultiplicativeExpression
|	SuperExpression
Additive Operators
AdditiveExpression ⇒
	MultiplicativeExpression
|	AdditiveExpressionOrSuper + MultiplicativeExpressionOrSuper
|	AdditiveExpressionOrSuper - MultiplicativeExpressionOrSuper
AdditiveExpressionOrSuper ⇒
	AdditiveExpression
|	SuperExpression
Bitwise Shift Operators
ShiftExpression ⇒
	AdditiveExpression
|	ShiftExpressionOrSuper << AdditiveExpressionOrSuper
|	ShiftExpressionOrSuper >> AdditiveExpressionOrSuper
|	ShiftExpressionOrSuper >>> AdditiveExpressionOrSuper
ShiftExpressionOrSuper ⇒
	ShiftExpression
|	SuperExpression
Relational Operators
RelationalExpression^allowIn ⇒
	ShiftExpression
|	RelationalExpressionOrSuper^allowIn < ShiftExpressionOrSuper
|	RelationalExpressionOrSuper^allowIn > ShiftExpressionOrSuper
|	RelationalExpressionOrSuper^allowIn <= ShiftExpressionOrSuper
|	RelationalExpressionOrSuper^allowIn >= ShiftExpressionOrSuper
|	RelationalExpression^allowIn is ShiftExpression
|	RelationalExpression^allowIn as ShiftExpression
|	RelationalExpression^allowIn in ShiftExpressionOrSuper
|	RelationalExpression^allowIn instanceof ShiftExpression
RelationalExpression^noIn ⇒
	ShiftExpression
|	RelationalExpressionOrSuper^noIn < ShiftExpressionOrSuper
|	RelationalExpressionOrSuper^noIn > ShiftExpressionOrSuper
|	RelationalExpressionOrSuper^noIn <= ShiftExpressionOrSuper
|	RelationalExpressionOrSuper^noIn >= ShiftExpressionOrSuper
|	RelationalExpression^noIn is ShiftExpression
|	RelationalExpression^noIn as ShiftExpression
|	RelationalExpression^noIn instanceof ShiftExpression
RelationalExpressionOrSuper^β ⇒
	RelationalExpression^β
|	SuperExpression
Equality Operators
EqualityExpression^β ⇒
	RelationalExpression^β
|	EqualityExpressionOrSuper^β == RelationalExpressionOrSuper^β
|	EqualityExpressionOrSuper^β != RelationalExpressionOrSuper^β
|	EqualityExpressionOrSuper^β === RelationalExpressionOrSuper^β
|	EqualityExpressionOrSuper^β !== RelationalExpressionOrSuper^β
EqualityExpressionOrSuper^β ⇒
	EqualityExpression^β
|	SuperExpression
Binary Bitwise Operators
BitwiseAndExpression^β ⇒
	EqualityExpression^β
|	BitwiseAndExpressionOrSuper^β & EqualityExpressionOrSuper^β
BitwiseXorExpression^β ⇒
	BitwiseAndExpression^β
|	BitwiseXorExpressionOrSuper^β ^ BitwiseAndExpressionOrSuper^β
BitwiseOrExpression^β ⇒
	BitwiseXorExpression^β
|	BitwiseOrExpressionOrSuper^β | BitwiseXorExpressionOrSuper^β
BitwiseAndExpressionOrSuper^β ⇒
	BitwiseAndExpression^β
|	SuperExpression
BitwiseXorExpressionOrSuper^β ⇒
	BitwiseXorExpression^β
|	SuperExpression
BitwiseOrExpressionOrSuper^β ⇒
	BitwiseOrExpression^β
|	SuperExpression
Binary Logical Operators
LogicalAndExpression^β ⇒
	BitwiseOrExpression^β
|	LogicalAndExpression^β && BitwiseOrExpression^β
LogicalXorExpression^β ⇒
	LogicalAndExpression^β
|	LogicalXorExpression^β ^^ LogicalAndExpression^β
LogicalOrExpression^β ⇒
	LogicalXorExpression^β
|	LogicalOrExpression^β || LogicalXorExpression^β
Conditional Operator
ConditionalExpression^β ⇒
	LogicalOrExpression^β
|	LogicalOrExpression^β ? AssignmentExpression^β : AssignmentExpression^β
NonAssignmentExpression^β ⇒
	LogicalOrExpression^β
|	LogicalOrExpression^β ? NonAssignmentExpression^β : NonAssignmentExpression^β
Assignment Operators
AssignmentExpression^β ⇒
	ConditionalExpression^β
|	PostfixExpression = AssignmentExpression^β
|	PostfixExpressionOrSuper CompoundAssignment AssignmentExpression^β
|	PostfixExpressionOrSuper CompoundAssignment SuperExpression
|	PostfixExpression LogicalAssignment AssignmentExpression^β
CompoundAssignment ⇒
	*=
|	/=
|	%=
|	+=
|	-=
|	<<=
|	>>=
|	>>>=
|	&=
|	^=
|	|=
LogicalAssignment ⇒
	&&=
|	^^=
|	||=
Comma Expressions
ListExpression^β ⇒
	AssignmentExpression^β
|	ListExpression^β , AssignmentExpression^β
OptionalExpression ⇒
	ListExpression^allowIn
|	«empty»
Type Expressions
TypeExpression^β ⇒ NonAssignmentExpression^β
Statements
ω ∈ {abbrev, noShortIf, full}
Statement^ω ⇒
	ExpressionStatement Semicolon^ω
|	SuperStatement Semicolon^ω
|	Block
|	LabeledStatement^ω
|	IfStatement^ω
|	SwitchStatement
|	DoStatement Semicolon^ω
|	WhileStatement^ω
|	ForStatement^ω
|	WithStatement^ω
|	ContinueStatement Semicolon^ω
|	BreakStatement Semicolon^ω
|	ReturnStatement Semicolon^ω
|	ThrowStatement Semicolon^ω
|	TryStatement
Substatement^ω ⇒
	EmptyStatement
|	Statement^ω
|	SimpleVariableDefinition Semicolon^ω
|	Attributes [no line break] { Substatements }
Substatements ⇒
	«empty»
|	SubstatementsPrefix Substatement^abbrev
SubstatementsPrefix ⇒
	«empty»
|	SubstatementsPrefix Substatement^full
Semicolon^abbrev ⇒
	;
|	VirtualSemicolon
|	«empty»
Semicolon^noShortIf ⇒
	;
|	VirtualSemicolon
|	«empty»
Semicolon^full ⇒
	;
|	VirtualSemicolon
Empty Statement
EmptyStatement ⇒ ;
Expression Statement
ExpressionStatement ⇒ [lookahead∉{function, {}] ListExpression^allowIn
Super Statement
SuperStatement ⇒ super Arguments
Block Statement
Block ⇒ { Directives }
Labeled Statements
LabeledStatement^ω ⇒ Identifier : Substatement^ω
If Statement
IfStatement^abbrev ⇒
	if ParenListExpression Substatement^abbrev
|	if ParenListExpression Substatement^noShortIf else Substatement^abbrev
IfStatement^full ⇒
	if ParenListExpression Substatement^full
|	if ParenListExpression Substatement^noShortIf else Substatement^full
IfStatement^noShortIf ⇒ if ParenListExpression Substatement^noShortIf else Substatement^noShortIf
Switch Statement
SwitchStatement ⇒ switch ParenListExpression { CaseStatements }
CaseStatements ⇒
	«empty»
|	CaseLabel
|	CaseLabel CaseStatementsPrefix CaseStatement^abbrev
CaseStatementsPrefix ⇒
	«empty»
|	CaseStatementsPrefix CaseStatement^full
CaseStatement^ω ⇒
	Substatement^ω
|	CaseLabel
CaseLabel ⇒
	case ListExpression^allowIn :
|	default :
Do-While Statement
DoStatement ⇒ do Substatement^abbrev while ParenListExpression
While Statement
WhileStatement^ω ⇒ while ParenListExpression Substatement^ω
For Statements
ForStatement^ω ⇒
	for ( ForInitialiser ; OptionalExpression ; OptionalExpression ) Substatement^ω
|	for ( ForInBinding in ListExpression^allowIn ) Substatement^ω
ForInitialiser ⇒
	«empty»
|	ListExpression^noIn
|	VariableDefinitionKind VariableBindingList^noIn
|	Attributes [no line break] VariableDefinitionKind VariableBindingList^noIn
ForInBinding ⇒
	PostfixExpression
|	VariableDefinitionKind VariableBinding^noIn
|	Attributes [no line break] VariableDefinitionKind VariableBinding^noIn
With Statement
WithStatement^ω ⇒ with ParenListExpression Substatement^ω
Continue and Break Statements
ContinueStatement ⇒
	continue
|	continue [no line break] Identifier
BreakStatement ⇒
	break
|	break [no line break] Identifier
Return Statement
ReturnStatement ⇒
	return
|	return [no line break] ListExpression^allowIn
Throw Statement
ThrowStatement ⇒ throw [no line break] ListExpression^allowIn
Try Statement
TryStatement ⇒
	try Block CatchClauses
|	try Block FinallyClause
|	try Block CatchClauses FinallyClause
CatchClauses ⇒
	CatchClause
|	CatchClauses CatchClause
CatchClause ⇒ catch ( Parameter ) Block
FinallyClause ⇒ finally Block
Directives
Directive^ω ⇒
	EmptyStatement
|	Statement^ω
|	AnnotatableDirective^ω
|	Attributes [no line break] AnnotatableDirective^ω
|	Attributes [no line break] { Directives }
|	PackageDefinition
|	IncludeDirective Semicolon^ω
|	Pragma Semicolon^ω
AnnotatableDirective^ω ⇒
	ExportDefinition Semicolon^ω
|	VariableDefinition Semicolon^ω
|	FunctionDefinition^ω
|	ClassDefinition
|	NamespaceDefinition Semicolon^ω
|	InterfaceDefinition^ω
|	ImportDirective Semicolon^ω
|	UseDirective Semicolon^ω
Directives ⇒
	«empty»
|	DirectivesPrefix Directive^abbrev
DirectivesPrefix ⇒
	«empty»
|	DirectivesPrefix Directive^full
Attributes
Attributes ⇒
	Attribute
|	AttributeCombination
AttributeCombination ⇒ Attribute [no line break] Attributes
Attribute ⇒
	AttributeExpression
|	true
|	false
|	public
|	NonexpressionAttribute
NonexpressionAttribute ⇒
	abstract
|	final
|	private
|	static
Use Directive
UseDirective ⇒ use namespace ParenListExpression
Import Directive
ImportDirective ⇒
	import ImportBinding IncludesExcludes
|	import ImportBinding , namespace ParenListExpression IncludesExcludes
ImportBinding ⇒
	ImportSource
|	Identifier = ImportSource
ImportSource ⇒
	String
|	PackageName
IncludesExcludes ⇒
	«empty»
|	, exclude ( NamePatterns )
|	, include ( NamePatterns )
NamePatterns ⇒
	«empty»
|	NamePatternList
NamePatternList ⇒
	QualifiedIdentifier
|	NamePatternList , QualifiedIdentifier
Include Directive
IncludeDirective ⇒ include [no line break] String
Pragma
Pragma ⇒ use PragmaItems
PragmaItems ⇒
	PragmaItem
|	PragmaItems , PragmaItem
PragmaItem ⇒
	PragmaExpr
|	PragmaExpr ?
PragmaExpr ⇒
	Identifier
|	Identifier ( PragmaArgument )
PragmaArgument ⇒
	true
|	false
|	Number
|	- Number
|	String
Definitions
Export Definition
ExportDefinition ⇒ export ExportBindingList
ExportBindingList ⇒
	ExportBinding
|	ExportBindingList , ExportBinding
ExportBinding ⇒
	FunctionName
|	FunctionName = FunctionName
Variable Definition
VariableDefinition ⇒ VariableDefinitionKind VariableBindingList^allowIn
VariableDefinitionKind ⇒
	var
|	const
VariableBindingList^β ⇒
	VariableBinding^β
|	VariableBindingList^β , VariableBinding^β
VariableBinding^β ⇒ TypedIdentifier^β VariableInitialisation^β
VariableInitialisation^β ⇒
	«empty»
|	= VariableInitialiser^β
VariableInitialiser^β ⇒
	AssignmentExpression^β
|	NonexpressionAttribute
|	AttributeCombination
TypedIdentifier^β ⇒
	Identifier
|	Identifier : TypeExpression^β
Simple Variable Definition
A SimpleVariableDefinition represents the subset of VariableDefinition expansions that may be used when the variable definition is used as a Substatement^ω instead of a Directive^ω in non-strict mode. In strict mode variable definitions may not be used as substatements.
SimpleVariableDefinition ⇒ var UntypedVariableBindingList
UntypedVariableBindingList ⇒
	UntypedVariableBinding
|	UntypedVariableBindingList , UntypedVariableBinding
UntypedVariableBinding ⇒ Identifier VariableInitialisation^allowIn
Function Definition
FunctionDefinition^ω ⇒
	FunctionDeclaration Block
|	FunctionDeclaration Semicolon^ω
FunctionDeclaration ⇒ function FunctionName FunctionSignature
FunctionName ⇒
	Identifier
|	get [no line break] Identifier
|	set [no line break] Identifier
|	String
FunctionSignature ⇒ ParameterSignature ResultSignature
ParameterSignature ⇒ ( Parameters )
Parameters ⇒
	«empty»
|	AllParameters
AllParameters ⇒
	Parameter
|	Parameter , AllParameters
|	OptionalParameters
OptionalParameters ⇒
	OptionalParameter
|	OptionalParameter , OptionalParameters
|	RestAndNamedParameters
RestAndNamedParameters ⇒
	NamedParameters
|	RestParameter
|	RestParameter , NamedParameters
|	NamedRestParameter
NamedParameters ⇒
	NamedParameter
|	NamedParameter , NamedParameters
Parameter ⇒
	TypedIdentifier^allowIn
|	const TypedIdentifier^allowIn
OptionalParameter ⇒ Parameter = AssignmentExpression^allowIn
TypedInitialiser ⇒ TypedIdentifier^allowIn = AssignmentExpression^allowIn
NamedParameter ⇒
	named TypedInitialiser
|	const named TypedInitialiser
|	named const TypedInitialiser
RestParameter ⇒
	...
|	... Parameter
NamedRestParameter ⇒
	... named Identifier
|	... const named Identifier
|	... named const Identifier
ResultSignature ⇒
	«empty»
|	: TypeExpression^allowIn
Class Definition
ClassDefinition ⇒ class Identifier Inheritance Block
Inheritance ⇒
	«empty»
|	extends TypeExpression^allowIn
|	implements TypeExpressionList
|	extends TypeExpression^allowIn implements TypeExpressionList
Interface Definition
InterfaceDefinition^ω ⇒
	interface Identifier ExtendsList Block
|	interface Identifier Semicolon^ω
ExtendsList ⇒
	«empty»
|	extends TypeExpressionList
TypeExpressionList ⇒
	TypeExpression^allowIn
|	TypeExpressionList , TypeExpression^allowIn
Namespace Definition
NamespaceDefinition ⇒ namespace Identifier
Package Definition
PackageDefinition ⇒
	package Block
|	package PackageName Block
PackageName ⇒
	Identifier
|	PackageName . Identifier
Programs
Program ⇒ Directives
Index
Nonterminals
Update fields to generate this index