March 1999 Draft
JavaScript 2.0
Grammar
previousupnext

Wednesday, March 24, 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

α ∈ {normalinitial}
β ∈ {allowInnoIn}

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
|  @ 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,β
|  BitwiseXorExpressionα,β ^ *
|  BitwiseXorExpressionα,β ^ ?
BitwiseOrExpressionα,β 
   BitwiseXorExpressionα,β
|  BitwiseOrExpressionα,β | BitwiseXorExpressionnormal,β
|  BitwiseOrExpressionα,β | *
|  BitwiseOrExpressionα,β | ?

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

δ ∈ {topclassblock}
ω ∈ {abbrevabbrevNonEmptyabbrevNoShortIffull}
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»
Semicolonfull ⇒ ;

Empty Statement

EmptyStatementabbrev 
   ;
|  «empty»
EmptyStatementabbrevNonEmpty ⇒ ;
EmptyStatementabbrevNoShortIf 
   ;
|  «empty»
EmptyStatementfull ⇒ ;

Expression Statement

ExpressionStatement ⇒ Expressioninitial,allowIn

Block

Blockδ ⇒ { Statementsδ }
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»
|  VersionsAndRenamesPrefix
VersionsAndRenamesPrefix 
   VersionRangeAndAlias
|  VersionsAndRenamesPrefix , VersionRangeAndAlias
VersionRangeAndAlias 
   VersionRange
|  VersionRange : Identifier
VersionRange 
   Version
|  OptionalVersion .. OptionalVersion

Versions

OptionalVersion 
   Version
|  «empty»
Version ⇒ String

Version Definition

VersionDefinition 
   version Version
|  version Version > VersionList
|  version Version = Version
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

Program ⇒ Statementstop

Waldemar Horwat
Last modified Wednesday, March 24, 1999
previousupnext