JavaScript 2.0
Formal Description
Parser Grammar
previousupnext

Thursday, November 11, 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   VirtualSemicolon

Punctuation tokens: !   !=   !==   %   %=   &   &&   &&=   &=   (   )   *   *=   +   ++   +=   ,   -   --   -=   .   ...   /   /=   :   ::   ;   <   <<   <<=   <=   =   ==   ===   >   >=   >>   >>=   >>>   >>>=   ?   @   [   ]   ^   ^=   ^^   ^^=   {   |   |=   ||   ||=   }   ~

Future punctuation tokens: #   ->

Reserved words: break   case   catch   class   const   continue   default   delete   do   else   eval   extends   false   final   finally   for   function   if   in   instanceof   new   null   package   private   public   return   super   switch   this   throw   true   try   typeof   var   while   with

Future reserved words: abstract   debugger   enum   export   goto   implements   import   interface   native   protected   static   synchronized   throws   transient   volatile

Non-reserved words: box   constructor   field   get   language   local   method   override   set   version

Expressions

b  {allowInnoIn}

Identifiers

Identifier 
   Identifier
|  box
|  constructor
|  field
|  get
|  language
|  local
|  method
|  set
|  override
|  version
QualifiedIdentifier 
   Identifier
|  QualifiedIdentifier :: Identifier
|  ParenthesizedExpression :: Identifier

Primary Expressions

PrimaryExpression 
   null
|  true
|  false
|  Number
|  Number [no line break] String
|  String
|  this
|  super
|  QualifiedIdentifier
|  ? Identifier
|  RegularExpression
|  ParenthesizedExpression
|  ParenthesizedExpression [no line break] String
|  ArrayLiteral
|  ObjectLiteral
|  FunctionExpression
ParenthesizedExpression  ( ExpressionallowIn )

Function Expressions

FunctionExpression 
   AnonymousFunction
|  NamedFunction

Object Literals

ObjectLiteral 
   { }
|  { FieldList }
FieldList 
   LiteralField
|  FieldList , LiteralField
LiteralField  FieldName : AssignmentExpressionallowIn
FieldName 
   QualifiedIdentifier
|  String
|  Number

Array Literals

ArrayLiteral  [ ElementList ]
ElementList 
   LiteralElement
|  ElementList , LiteralElement
LiteralElement 
   «empty»
|  AssignmentExpressionallowIn

Postfix Unary Operators

PostfixExpression 
   FullPostfixExpression
|  ShortNewExpression
FullPostfixExpression 
   PrimaryExpression
|  FullNewExpression
|  FullPostfixExpression MemberOperator
|  FullPostfixExpression Arguments
|  PostfixExpression [no line break] ++
|  PostfixExpression [no line break] --
FullNewExpression  new FullNewSubexpression Arguments
ShortNewExpression  new ShortNewSubexpression
FullNewSubexpression 
   PrimaryExpression
|  FullNewSubexpression MemberOperator
|  FullNewExpression
ShortNewSubexpression 
   FullNewSubexpression
|  ShortNewExpression
MemberOperator 
   [ ArgumentList ]
|  . QualifiedIdentifier
|  . ParenthesizedExpression
|  @ QualifiedIdentifier
|  @ ParenthesizedExpression
Arguments  ( ArgumentList )
ArgumentList 
   «empty»
|  ArgumentListPrefix
|  NamedArgumentListPrefix
ArgumentListPrefix 
   AssignmentExpressionallowIn
|  ArgumentListPrefix , AssignmentExpressionallowIn
NamedArgumentListPrefix 
   LiteralField
|  ArgumentListPrefix , LiteralField
|  NamedArgumentListPrefix , LiteralField

Prefix Unary Operators

UnaryExpression 
   PostfixExpression
|  delete PostfixExpression
|  typeof UnaryExpression
|  eval UnaryExpression
|  ++ PostfixExpression
|  -- PostfixExpression
|  + UnaryExpression
|  - UnaryExpression
|  ~ UnaryExpression
|  ! UnaryExpression

Multiplicative Operators

MultiplicativeExpression 
   UnaryExpression
|  MultiplicativeExpression * UnaryExpression
|  MultiplicativeExpression / UnaryExpression
|  MultiplicativeExpression % UnaryExpression

Additive Operators

AdditiveExpression 
   MultiplicativeExpression
|  AdditiveExpression + MultiplicativeExpression
|  AdditiveExpression - MultiplicativeExpression

Bitwise Shift Operators

ShiftExpression 
   AdditiveExpression
|  ShiftExpression << AdditiveExpression
|  ShiftExpression >> AdditiveExpression
|  ShiftExpression >>> AdditiveExpression

Relational Operators

RelationalExpressionallowIn 
   ShiftExpression
|  RelationalExpressionallowIn < ShiftExpression
|  RelationalExpressionallowIn > ShiftExpression
|  RelationalExpressionallowIn <= ShiftExpression
|  RelationalExpressionallowIn >= ShiftExpression
|  RelationalExpressionallowIn instanceof ShiftExpression
|  RelationalExpressionallowIn in ShiftExpression
RelationalExpressionnoIn 
   ShiftExpression
|  RelationalExpressionnoIn < ShiftExpression
|  RelationalExpressionnoIn > ShiftExpression
|  RelationalExpressionnoIn <= ShiftExpression
|  RelationalExpressionnoIn >= ShiftExpression
|  RelationalExpressionnoIn instanceof ShiftExpression

Equality Operators

EqualityExpressionb 
   RelationalExpressionb
|  EqualityExpressionb == RelationalExpressionb
|  EqualityExpressionb != RelationalExpressionb
|  EqualityExpressionb === RelationalExpressionb
|  EqualityExpressionb !== RelationalExpressionb

Binary Bitwise Operators

BitwiseAndExpressionb 
   EqualityExpressionb
|  BitwiseAndExpressionb & EqualityExpressionb
BitwiseXorExpressionb 
   BitwiseAndExpressionb
|  BitwiseXorExpressionb ^ BitwiseAndExpressionb
|  BitwiseXorExpressionb ^ *
|  BitwiseXorExpressionb ^ ?
BitwiseOrExpressionb 
   BitwiseXorExpressionb
|  BitwiseOrExpressionb | BitwiseXorExpressionb
|  BitwiseOrExpressionb | *
|  BitwiseOrExpressionb | ?

Binary Logical Operators

LogicalAndExpressionb 
   BitwiseOrExpressionb
|  LogicalAndExpressionb && BitwiseOrExpressionb
LogicalXorExpressionb 
   LogicalAndExpressionb
|  LogicalXorExpressionb ^^ LogicalAndExpressionb
LogicalOrExpressionb 
   LogicalXorExpressionb
|  LogicalOrExpressionb || LogicalXorExpressionb

Conditional Operator

ConditionalExpressionb 
   LogicalOrExpressionb
|  LogicalOrExpressionb ? AssignmentExpressionb : AssignmentExpressionb
NonAssignmentExpressionb 
   LogicalOrExpressionb
|  LogicalOrExpressionb ? NonAssignmentExpressionb : NonAssignmentExpressionb

Assignment Operators

AssignmentExpressionb 
   ConditionalExpressionb
|  PostfixExpression = AssignmentExpressionb
|  PostfixExpression CompoundAssignment AssignmentExpressionb
CompoundAssignment 
   *=
|  /=
|  %=
|  +=
|  -=
|  <<=
|  >>=
|  >>>=
|  &=
|  ^=
|  |=
|  &&=
|  ^^=
|  ||=

Expressions

Expressionb 
   AssignmentExpressionb
|  Expressionb , AssignmentExpressionb
OptionalExpression 
   ExpressionallowIn
|  «empty»

Type Expressions

TypeExpressionb  NonAssignmentExpressionb

Statements

w  {abbrevabbrevNonEmptyabbrevNoShortIffull}
TopStatementw 
   Statementw
|  LanguageDeclarationw
Statementw 
   AnnotatedDefinitionw
|  EmptyStatementw
|  ExpressionStatement Semicolonw
|  AnnotatedBlock
|  LabeledStatementw
|  IfStatementw
|  SwitchStatement
|  DoStatement Semicolonw
|  WhileStatementw
|  ForStatementw
|  WithStatementw
|  ContinueStatement Semicolonw
|  BreakStatement Semicolonw
|  ReturnStatement Semicolonw
|  ThrowStatement Semicolonw
|  TryStatement
Semicolonabbrev 
   ;
|  VirtualSemicolon
|  «empty»
SemicolonabbrevNonEmpty 
   ;
|  VirtualSemicolon
|  «empty»
SemicolonabbrevNoShortIf 
   ;
|  VirtualSemicolon
|  «empty»
Semicolonfull 
   ;
|  VirtualSemicolon

Empty Statement

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

Expression Statement

ExpressionStatement  [lookahead{function{}] ExpressionallowIn

Block

AnnotatedBlock 
   Block
|  Visibility [no line break] Block
Block  { TopStatements }
TopStatements 
   TopStatementabbrev
|  TopStatementsPrefix TopStatementabbrevNonEmpty
TopStatementsPrefix 
   TopStatementfull
|  TopStatementsPrefix TopStatementfull

Labeled Statements

LabeledStatementw  Identifier : Statementw

If Statement

IfStatementabbrev 
   if ParenthesizedExpression Statementabbrev
|  if ParenthesizedExpression StatementabbrevNoShortIf else Statementabbrev
IfStatementabbrevNonEmpty 
   if ParenthesizedExpression StatementabbrevNonEmpty
|  if ParenthesizedExpression StatementabbrevNoShortIf else StatementabbrevNonEmpty
IfStatementfull 
   if ParenthesizedExpression Statementfull
|  if ParenthesizedExpression StatementabbrevNoShortIf else Statementfull
IfStatementabbrevNoShortIf  if ParenthesizedExpression StatementabbrevNoShortIf else StatementabbrevNoShortIf

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 ExpressionallowIn :
|  default :
CaseStatements 
   Statementabbrev
|  CaseStatementsPrefix StatementabbrevNonEmpty
CaseStatementsPrefix 
   Statementfull
|  CaseStatementsPrefix Statementfull

Do-While Statement

DoStatement  do StatementabbrevNonEmpty while ParenthesizedExpression

While Statement

WhileStatementw  while ParenthesizedExpression Statementw

For Statements

ForStatementw 
   for ( ForInitializer ; OptionalExpression ; OptionalExpression ) Statementw
|  for ( ForInBinding in ExpressionallowIn ) Statementw
ForInitializer 
   «empty»
|  ExpressionnoIn
|  VariableDefinitionKind VariableBindingListnoIn
ForInBinding 
   PostfixExpression
|  VariableDefinitionKind VariableBindingnoIn

With Statement

WithStatementw  with ParenthesizedExpression Statementw

Continue and Break Statements

ContinueStatement  continue [no line break] OptionalLabel
BreakStatement  break [no line break] OptionalLabel
OptionalLabel 
   «empty»
|  Identifier

Return Statement

ReturnStatement  return [no line break] OptionalExpression

Throw Statement

ThrowStatement  throw [no line break] ExpressionallowIn

Try Statement

TryStatement 
   try AnnotatedBlock CatchClauses
|  try AnnotatedBlock FinallyClause
|  try AnnotatedBlock CatchClauses FinallyClause
CatchClauses 
   CatchClause
|  CatchClauses CatchClause
CatchClause  catch ( TypedIdentifierallowIn ) AnnotatedBlock
FinallyClause  finally AnnotatedBlock

Definitions

AnnotatedDefinitionw 
   Visibility [no line break] Definitionw
|  Definitionw
Definitionw 
   VariableDefinition Semicolonw
|  FunctionDefinition
|  MemberDefinitionw
|  ClassDefinition

Visibility Specifications

Visibility 
   ParenthesizedExpression
|  local
|  box
|  private
|  package
|  public
|  Identifier

Variable Definition

VariableDefinition  VariableDefinitionKind VariableBindingListallowIn
VariableDefinitionKind 
   var
|  const
VariableBindingListb 
   VariableBindingb
|  VariableBindingListb , VariableBindingb
VariableBindingb  TypedIdentifierb VariableInitializerb
TypedIdentifierb 
   Identifier
|  Identifier : TypeExpressionb
VariableInitializerb 
   «empty»
|  = AssignmentExpressionb

Function Definition

FunctionDefinition 
   NamedFunction
|  AccessorFunction
AnonymousFunction  function FunctionSignature Block
NamedFunction  function Identifier FunctionSignature Block
AccessorFunction 
   function get [no line break] Identifier FunctionSignature Block
|  function set [no line break] Identifier FunctionSignature Block
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 = AssignmentExpressionallowIn
RestParameter 
   ...
|  ... TypedIdentifierallowIn
|  ... TypedIdentifierallowIn = AssignmentExpressionallowIn
ResultSignature 
   «empty»
|  : TypeExpressionallowIn

Class Member Definitions

MemberDefinitionw 
   FieldDefinition Semicolonw
|  MethodDefinitionw
|  ConstructorDefinition
FieldDefinition  field [no line break] VariableBindingListallowIn
MethodDefinitionw 
   ConcreteMethodDefinition
|  AbstractMethodDefinitionw
ConcreteMethodDefinition  MethodPrefix [no line break] MethodName FunctionSignature Block
AbstractMethodDefinitionw  MethodPrefix [no line break] MethodName FunctionSignature Semicolonw
MethodPrefix 
   method
|  override [no line break] method
|  final [no line break] method
|  final [no line break] override [no line break] method
MethodName 
   Identifier
|  get [no line break] Identifier
|  set [no line break] Identifier
ConstructorDefinition  constructor [no line break] ConstructorName ParameterSignature Block
ConstructorName 
   new
|  Identifier

Class Definition

ClassDefinition 
   class Identifier Superclasses Block
|  class extends TypeExpressionallowIn Block
Superclasses 
   «empty»
|  extends TypeExpressionallowIn

Language Declaration

LanguageDeclarationw  language LanguageId LanguageIdList LanguageAlternatives LanguageSemicolonw
LanguageSemicolonabbrev 
   ;
|  «empty»
LanguageSemicolonabbrevNonEmpty 
   ;
|  «empty»
LanguageSemicolonfull  ;
LanguageAlternatives 
   «empty»
|  LanguageAlternatives | LanguageIdList
LanguageIdList 
   «empty»
|  LanguageIdList LanguageId
LanguageId 
   Identifier
|  Number

Programs

Program  TopStatements

Waldemar Horwat
Last modified Thursday, November 11, 1999
previousupnext