February 1999 Draft
JavaScript 2.0
Grammar
|
|
Thursday, February 18, 1999
This LALR(1) grammar describes the syntax of the JavaScript 2.0 proposal. The starting nonterminal is Program.
See also the description of the grammar notation.
This document is also available as a Word 98 rtf file.
Terminals
General tokens: Identifier Number
RegularExpression String
Punctuation tokens: !
!=
!==
%
%=
&
&&
&=
(
)
*
*=
+
++
+=
,
-
--
-=
.
..
...
/
/=
:
::
;
<
<<
<<=
<=
=
==
===
>
>=
>>
>>=
>>>
>>>=
?
[
]
^
^=
{
|
|=
||
}
~
Future punctuation tokens: #
&&=
->
@
^^
^^=
||=
Reserved words: break
case
catch
class
const
continue
default
delete
do
else
eval
extends
false
field
final
finally
for
function
if
import
in
instanceof
new
null
package
private
protected
public
return
super
switch
this
throw
true
try
typeof
var
while
with
Future reserved words: abstract
debugger
enum
export
goto
implements
native
static
synchronized
throws
transient
volatile
Non-reserved words: constructor
getter
method
override
setter
traditional
version
Expressions
{normal, initial}
{allowIn, noIn}
Identifiers
Identifier
Identifier
| version
| override
| method
| getter
| setter
| traditional
| constructor
QualifiedIdentifier
Identifier
| QualifiedIdentifier ::
Identifier
| ParenthesizedExpression ::
Identifier
Primary Expressions
PrimaryExpressionnormal
SimpleExpression
| FunctionExpression
| ObjectLiteral
PrimaryExpressioninitial SimpleExpression
SimpleExpression
null
| true
| false
| Number
| String
| this
| super
| QualifiedIdentifier
| RegularExpression
| ParenthesizedExpression
| ArrayLiteral
ParenthesizedExpression (
Expressionnormal,allowIn )
Function Expressions
FunctionExpression
AnonymousFunction
| NamedFunction
Object Literals
ObjectLiteral
{
}
| {
FieldList }
FieldList
LiteralField
| FieldList ,
LiteralField
LiteralField QualifiedIdentifier :
AssignmentExpressionnormal,allowIn
Array Literals
ArrayLiteral
[
]
| [
ElementList ]
ElementList
LiteralElement
| ElementList ,
LiteralElement
LiteralElement AssignmentExpressionnormal,allowIn
Postfix Unary Operators
PostfixExpression
FullPostfixExpression
| ShortNewExpression
FullPostfixExpression
PrimaryExpression
| FullNewExpression
| FullPostfixExpression MemberOperator
| FullPostfixExpression Arguments
| PostfixExpression ++
| PostfixExpression --
| PostfixExpression !
| PostfixExpression ~
FullNewExpression new
FullNewSubexpression Arguments
ShortNewExpression new
ShortNewSubexpression
FullNewSubexpression
PrimaryExpressionnormal
| FullNewSubexpression MemberOperator
| FullNewExpression
ShortNewSubexpression
FullNewSubexpression
| ShortNewExpression
MemberOperator
[
ArgumentList ]
| .
QualifiedIdentifier
| .
ParenthesizedExpression
Arguments (
ArgumentList )
ArgumentList
«empty»
| ArgumentListPrefix
ArgumentListPrefix
AssignmentExpressionnormal,allowIn
| ArgumentListPrefix ,
AssignmentExpressionnormal,allowIn
Prefix Unary Operators
UnaryExpression
PostfixExpression
| delete
PostfixExpressionnormal
| typeof
UnaryExpressionnormal
| eval
UnaryExpressionnormal
| ++
PostfixExpressionnormal
| --
PostfixExpressionnormal
| +
UnaryExpressionnormal
| -
UnaryExpressionnormal
| ~
UnaryExpressionnormal
| !
UnaryExpressionnormal
Multiplicative Operators
MultiplicativeExpression
UnaryExpression
| MultiplicativeExpression *
UnaryExpressionnormal
| MultiplicativeExpression /
UnaryExpressionnormal
| MultiplicativeExpression %
UnaryExpressionnormal
Additive Operators
AdditiveExpression
MultiplicativeExpression
| AdditiveExpression +
MultiplicativeExpressionnormal
| AdditiveExpression -
MultiplicativeExpressionnormal
Bitwise Shift Operators
ShiftExpression
AdditiveExpression
| ShiftExpression <<
AdditiveExpressionnormal
| ShiftExpression >>
AdditiveExpressionnormal
| ShiftExpression >>>
AdditiveExpressionnormal
Relational Operators
RelationalExpression,allowIn
ShiftExpression
| RelationalExpression,allowIn <
ShiftExpressionnormal
| RelationalExpression,allowIn >
ShiftExpressionnormal
| RelationalExpression,allowIn <=
ShiftExpressionnormal
| RelationalExpression,allowIn >=
ShiftExpressionnormal
| RelationalExpression,allowIn instanceof
ShiftExpressionnormal
| RelationalExpression,allowIn in
ShiftExpressionnormal
RelationalExpression,noIn
ShiftExpression
| RelationalExpression,noIn <
ShiftExpressionnormal
| RelationalExpression,noIn >
ShiftExpressionnormal
| RelationalExpression,noIn <=
ShiftExpressionnormal
| RelationalExpression,noIn >=
ShiftExpressionnormal
| RelationalExpression,noIn instanceof
ShiftExpressionnormal
Equality Operators
EqualityExpression,
RelationalExpression,
| EqualityExpression, ==
RelationalExpressionnormal,
| EqualityExpression, !=
RelationalExpressionnormal,
| EqualityExpression, ===
RelationalExpressionnormal,
| EqualityExpression, !==
RelationalExpressionnormal,
Binary Bitwise Operators
BitwiseAndExpression,
EqualityExpression,
| BitwiseAndExpression, &
EqualityExpressionnormal,
BitwiseXorExpression,
BitwiseAndExpression,
| BitwiseXorExpression, ^
BitwiseAndExpressionnormal,
BitwiseOrExpression,
BitwiseXorExpression,
| BitwiseOrExpression, |
BitwiseXorExpressionnormal,
Binary Logical Operators
LogicalAndExpression,
BitwiseOrExpression,
| LogicalAndExpression, &&
BitwiseOrExpressionnormal,
LogicalOrExpression,
LogicalAndExpression,
| LogicalOrExpression, ||
LogicalAndExpressionnormal,
Conditional Operator
ConditionalExpression,
LogicalOrExpression,
| LogicalOrExpression, ?
AssignmentExpressionnormal, :
AssignmentExpressionnormal,
NonAssignmentExpression,
LogicalOrExpression,
| LogicalOrExpression, ?
NonAssignmentExpressionnormal, :
NonAssignmentExpressionnormal,
Assignment Operators
AssignmentExpression,
ConditionalExpression,
| PostfixExpression =
AssignmentExpressionnormal,
| PostfixExpression CompoundAssignment AssignmentExpressionnormal,
CompoundAssignment
*=
| /=
| %=
| +=
| -=
| <<=
| >>=
| >>>=
| &=
| ^=
| |=
Expressions
Expression,
AssignmentExpression,
| Expression, ,
AssignmentExpressionnormal,
OptionalExpression
Expressionnormal,allowIn
| «empty»
Type Expressions
TypeExpression, NonAssignmentExpression,
Statements
{top, class, block}
{abbrev, abbrevNonEmpty, abbrevNoShortIf, full}
Statement,
CodeStatement
| Definition,
CodeStatement
EmptyStatement
| ExpressionStatement Semicolon
| Blockblock
| LabeledStatement
| IfStatement
| SwitchStatement
| DoStatement Semicolon
| WhileStatement
| ForStatement
| WithStatement
| ContinueStatement Semicolon
| BreakStatement Semicolon
| ReturnStatement Semicolon
| ThrowStatement Semicolon
| TryStatement
| ImportStatement
Semicolonabbrev
;
| «empty»
SemicolonabbrevNonEmpty
;
| «empty»
SemicolonabbrevNoShortIf
;
| «empty»
Empty Statement
EmptyStatementabbrev
;
| «empty»
EmptyStatementabbrevNonEmpty ;
EmptyStatementabbrevNoShortIf
;
| «empty»
Expression Statement
ExpressionStatement Expressioninitial,allowIn
Block
Statements
Statement,abbrev
| StatementsPrefix Statement,abbrevNonEmpty
StatementsPrefix
Statement,full
| StatementsPrefix Statement,full
Labeled Statements
LabeledStatement Identifier :
CodeStatement
If Statement
IfStatementabbrev
if
ParenthesizedExpression CodeStatementabbrev
| if
ParenthesizedExpression CodeStatementabbrevNoShortIf else
CodeStatementabbrev
IfStatementabbrevNonEmpty
if
ParenthesizedExpression CodeStatementabbrevNonEmpty
| if
ParenthesizedExpression CodeStatementabbrevNoShortIf else
CodeStatementabbrevNonEmpty
IfStatementfull
if
ParenthesizedExpression CodeStatementfull
| if
ParenthesizedExpression CodeStatementabbrevNoShortIf else
CodeStatementfull
IfStatementabbrevNoShortIf if
ParenthesizedExpression CodeStatementabbrevNoShortIf else
CodeStatementabbrevNoShortIf
Switch Statement
SwitchStatement
switch
ParenthesizedExpression {
}
| switch
ParenthesizedExpression {
CaseGroups LastCaseGroup }
CaseGroups
«empty»
| CaseGroups CaseGroup
CaseGroup CaseGuards CaseStatementsPrefix
LastCaseGroup CaseGuards CaseStatements
CaseGuards
CaseGuard
| CaseGuards CaseGuard
CaseGuard
case
Expressionnormal,allowIn :
| default
:
CaseStatements
CodeStatementabbrev
| CaseStatementsPrefix CodeStatementabbrevNonEmpty
CaseStatementsPrefix
CodeStatementfull
| CaseStatementsPrefix CodeStatementfull
Do-While Statement
DoStatement do
CodeStatementabbrevNonEmpty while
ParenthesizedExpression
While Statement
WhileStatement while
ParenthesizedExpression CodeStatement
For Statements
ForStatement
for
(
ForInitializer ;
OptionalExpression ;
OptionalExpression )
CodeStatement
| for
(
ForInBinding in
Expressionnormal,allowIn )
CodeStatement
ForInitializer
«empty»
| Expressionnormal,noIn
| VariableDefinitionKind VariableBindingListnoIn
ForInBinding
PostfixExpressionnormal
| VariableDefinitionKind VariableBindingnoIn
With Statement
WithStatement with
ParenthesizedExpression CodeStatement
Continue and Break Statements
ContinueStatement continue
OptionalLabel
BreakStatement break
OptionalLabel
OptionalLabel
«empty»
| Identifier
Return Statement
ReturnStatement return
OptionalExpression
Throw Statement
ThrowStatement throw
Expressionnormal,allowIn
Try Statement
TryStatement
try
Blockblock CatchClauses
| try
Blockblock FinallyClause
| try
Blockblock CatchClauses FinallyClause
CatchClauses
CatchClause
| CatchClauses CatchClause
CatchClause catch
(
TypedIdentifierallowIn )
Blockblock
FinallyClause finally
Blockblock
Import Statement
ImportStatementabbrev
import
ImportList Semicolonabbrev
| import
ImportList Blockblock
| import
ImportList Blockblock else
CodeStatementabbrev
ImportStatementabbrevNonEmpty
import
ImportList SemicolonabbrevNonEmpty
| import
ImportList Blockblock
| import
ImportList Blockblock else
CodeStatementabbrevNonEmpty
ImportStatementabbrevNoShortIf
import
ImportList SemicolonabbrevNoShortIf
| import
ImportList Blockblock else
CodeStatementabbrevNoShortIf
ImportStatementfull
import
ImportList Semicolonfull
| import
ImportList Blockblock
| import
ImportList Blockblock else
CodeStatementfull
ImportList
ImportItem
| ImportList ,
ImportItem
ImportItem
ImportSource
| Identifier =
ImportSource
| protected
Identifier =
ImportSource
ImportSource
NonAssignmentExpressionnormal,noIn
| NonAssignmentExpressionnormal,noIn :
Version
Definitions
Definition,
Visibility GlobalDefinition
| LocalDefinition,
GlobalDefinition
VersionDefinition Semicolon
| VariableDefinition Semicolon
| FunctionDefinition
| MemberDefinition
| ClassDefinition
LocalDefinitiontop,
VersionDefinition Semicolon
| VariableDefinition Semicolon
| FunctionDefinition
| ClassDefinition
LocalDefinitionclass,
VariableDefinition Semicolon
| FunctionDefinition
| MemberDefinition
| ClassDefinition
LocalDefinitionblock,
VariableDefinition Semicolon
| FunctionDefinition
Visibility Specifications
Visibility
private
| package
| public
VersionsAndRenames
VersionsAndRenames
«empty»
| <
VersionRangesAndAliases >
VersionRangesAndAliases
«empty»
| VersionRangesAndAliasesPrefix
VersionRangesAndAliasesPrefix
VersionRangeAndAlias
| VersionRangesAndAliasesPrefix ,
VersionRangeAndAlias
VersionRangeAndAlias
VersionRange
| VersionRange :
Identifier
VersionRange
Version
| OptionalVersion ..
OptionalVersion
Versions
OptionalVersion
Version
| «empty»
Version Definition
VersionDefinition
version
Version
| version
Version >
VersionList
VersionList
Version
| VersionList ,
Version
Variable Definition
VariableDefinition VariableDefinitionKind VariableBindingListallowIn
VariableDefinitionKind
var
| const
VariableBindingList
VariableBinding
| VariableBindingList ,
VariableBinding
VariableBinding TypedIdentifier VariableInitializer
TypedIdentifier
Identifier
| TypeExpressionnormal, Identifier
VariableInitializer
«empty»
| =
AssignmentExpressionnormal,
Function Definition
FunctionDefinition
NamedFunction
| getter
NamedFunction
| setter
NamedFunction
| TraditionalFunction
AnonymousFunction function
FunctionSignature Blockblock
NamedFunction function
Identifier FunctionSignature Blockblock
FunctionSignature ParameterSignature ResultSignature
ParameterSignature (
Parameters )
Parameters
«empty»
| RestParameter
| RequiredParameters
| OptionalParameters
| RequiredParameters ,
RestParameter
| OptionalParameters ,
RestParameter
RequiredParameters
RequiredParameter
| RequiredParameters ,
RequiredParameter
OptionalParameters
OptionalParameter
| RequiredParameters ,
OptionalParameter
| OptionalParameters ,
OptionalParameter
RequiredParameter TypedIdentifierallowIn
OptionalParameter
TypedIdentifierallowIn =
| TypedIdentifierallowIn =
AssignmentExpressionnormal,allowIn
RestParameter
...
| ...
Identifier
ResultSignature
«empty»
| TypeExpressioninitial,allowIn
TraditionalFunction traditional
function
Identifier (
TraditionalParameterList )
Blockblock
TraditionalParameterList
«empty»
| TraditionalParameterListPrefix
TraditionalParameterListPrefix
Identifier
| TraditionalParameterListPrefix ,
Identifier
Class Member Definitions
MemberDefinition
FieldDefinition Semicolon
| MethodDefinition
| ConstructorDefinition
FieldDefinition field
VariableBindingListallowIn
MethodDefinition
ConcreteMethodDefinition
| AbstractMethodDefinition
ConcreteMethodDefinition MethodPrefix Identifier FunctionSignature Blockblock
AbstractMethodDefinition MethodPrefix Identifier FunctionSignature Semicolon
MethodPrefix
MethodKind
| override
MethodKind
| final
MethodKind
| final
override
MethodKind
MethodKind
method
| getter
method
| setter
method
ConstructorDefinition constructor
ConstructorName ParameterSignature Blockblock
ConstructorName
new
| Identifier
Class Definition
ClassDefinition
class
Identifier Superclasses Blockclass
| class
extends
TypeExpressioninitial,allowIn Blockclass
Superclasses
«empty»
| extends
TypeExpressioninitial,allowIn
Programs