ECMAScript 4 Netscape Proposal
Formal Description
Syntactic Grammar
previousupnext

Monday, June 30, 2003

This LALR(1) grammar describes the syntax of the ECMAScript 4 proposal. The starting nonterminal is Program. See also the description of the grammar notation.

This document is also available as a Word RTF file.

Terminals

General tokens: Identifier NegatedMinLong Number RegularExpression String VirtualSemicolon

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

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

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

Non-reserved words: get set

Expressions

  {allowInnoIn}

Identifiers

Identifier 
   Identifier
|  get
|  set

Qualified Identifiers

SimpleQualifiedIdentifier 
   Identifier
|  Identifier :: Identifier
|  ReservedNamespace :: Identifier
ExpressionQualifiedIdentifier  ParenExpression :: Identifier
QualifiedIdentifier 
   SimpleQualifiedIdentifier
|  ExpressionQualifiedIdentifier

Primary Expressions

PrimaryExpression 
   null
|  true
|  false
|  Number
|  String
|  this
|  RegularExpression
|  ReservedNamespace
|  ParenListExpression
|  ArrayLiteral
|  ObjectLiteral
|  FunctionExpression
ReservedNamespace 
   public
|  private
ParenExpression  ( AssignmentExpressionallowIn )
ParenListExpression 
   ParenExpression
|  ( ListExpressionallowIn , AssignmentExpressionallowIn )

Function Expressions

FunctionExpression 
   function FunctionCommon
|  function Identifier FunctionCommon

Object Literals

ObjectLiteral  { FieldList }
FieldList 
   «empty»
|  NonemptyFieldList
NonemptyFieldList 
   LiteralField
|  LiteralField , NonemptyFieldList
LiteralField  FieldName : AssignmentExpressionallowIn
FieldName 
   QualifiedIdentifier
|  String
|  Number
|  ParenExpression

Array Literals

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

Super Expressions

SuperExpression 
   super
|  super ParenExpression

Postfix Expressions

PostfixExpression 
   AttributeExpression
|  FullPostfixExpression
|  ShortNewExpression
AttributeExpression 
   SimpleQualifiedIdentifier
|  AttributeExpression PropertyOperator
|  AttributeExpression Arguments
FullPostfixExpression 
   PrimaryExpression
|  ExpressionQualifiedIdentifier
|  FullNewExpression
|  FullPostfixExpression PropertyOperator
|  SuperExpression PropertyOperator
|  FullPostfixExpression Arguments
|  PostfixExpression [no line break] ++
|  PostfixExpression [no line break] --
FullNewExpression  new FullNewSubexpression Arguments
FullNewSubexpression 
   PrimaryExpression
|  QualifiedIdentifier
|  FullNewExpression
|  FullNewSubexpression PropertyOperator
|  SuperExpression PropertyOperator
ShortNewExpression  new ShortNewSubexpression
ShortNewSubexpression 
   FullNewSubexpression
|  ShortNewExpression

Property Operators

PropertyOperator 
   . QualifiedIdentifier
|  Brackets
Brackets 
   [ ]
|  [ ListExpressionallowIn ]
|  [ ExpressionsWithRest ]
Arguments 
   ( )
|  ParenListExpression
|  ( ExpressionsWithRest )
ExpressionsWithRest 
   RestExpression
|  ListExpressionallowIn , RestExpression
RestExpression  ... AssignmentExpressionallowIn

Unary Operators

UnaryExpression 
   PostfixExpression
|  delete PostfixExpression
|  void UnaryExpression
|  typeof UnaryExpression
|  ++ PostfixExpression
|  -- PostfixExpression
|  + UnaryExpression
|  - UnaryExpression
|  - NegatedMinLong
|  ~ 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 is ShiftExpression
|  RelationalExpressionallowIn as ShiftExpression
|  RelationalExpressionallowIn in ShiftExpression
|  RelationalExpressionallowIn instanceof ShiftExpression
RelationalExpressionnoIn 
   ShiftExpression
|  RelationalExpressionnoIn < ShiftExpression
|  RelationalExpressionnoIn > ShiftExpression
|  RelationalExpressionnoIn <= ShiftExpression
|  RelationalExpressionnoIn >= ShiftExpression
|  RelationalExpressionnoIn is ShiftExpression
|  RelationalExpressionnoIn as ShiftExpression
|  RelationalExpressionnoIn instanceof ShiftExpression

Equality Operators

EqualityExpression 
   RelationalExpression
|  EqualityExpression == RelationalExpression
|  EqualityExpression != RelationalExpression
|  EqualityExpression === RelationalExpression
|  EqualityExpression !== RelationalExpression

Binary Bitwise Operators

BitwiseAndExpression 
   EqualityExpression
|  BitwiseAndExpression & EqualityExpression
BitwiseXorExpression 
   BitwiseAndExpression
|  BitwiseXorExpression ^ BitwiseAndExpression
BitwiseOrExpression 
   BitwiseXorExpression
|  BitwiseOrExpression | BitwiseXorExpression

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
|  PostfixExpression CompoundAssignment AssignmentExpression
|  PostfixExpression LogicalAssignment AssignmentExpression
CompoundAssignment 
   *=
|  /=
|  %=
|  +=
|  -=
|  <<=
|  >>=
|  >>>=
|  &=
|  ^=
|  |=
LogicalAssignment 
   &&=
|  ^^=
|  ||=

Comma Expressions

ListExpression 
   AssignmentExpression
|  ListExpression , AssignmentExpression

Type Expressions

TypeExpression  NonAssignmentExpression

Statements

  {abbrevnoShortIffull}
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 Substatementabbrev
SubstatementsPrefix 
   «empty»
|  SubstatementsPrefix Substatementfull
Semicolonabbrev 
   ;
|  VirtualSemicolon
|  «empty»
SemicolonnoShortIf 
   ;
|  VirtualSemicolon
|  «empty»
Semicolonfull 
   ;
|  VirtualSemicolon

Empty Statement

EmptyStatement  ;

Expression Statement

ExpressionStatement  [lookahead{function{}] ListExpressionallowIn

Super Statement

SuperStatement  super Arguments

Block Statement

Block  { Directives }

Labeled Statements

LabeledStatement  Identifier : Substatement

If Statement

IfStatementabbrev 
   if ParenListExpression Substatementabbrev
|  if ParenListExpression SubstatementnoShortIf else Substatementabbrev
IfStatementfull 
   if ParenListExpression Substatementfull
|  if ParenListExpression SubstatementnoShortIf else Substatementfull
IfStatementnoShortIf  if ParenListExpression SubstatementnoShortIf else SubstatementnoShortIf

Switch Statement

SwitchStatement  switch ParenListExpression { CaseElements }
CaseElements 
   «empty»
|  CaseLabel
|  CaseLabel CaseElementsPrefix CaseElementabbrev
CaseElementsPrefix 
   «empty»
|  CaseElementsPrefix CaseElementfull
CaseElement 
   Directive
|  CaseLabel
CaseLabel 
   case ListExpressionallowIn :
|  default :

Do-While Statement

DoStatement  do Substatementabbrev while ParenListExpression

While Statement

WhileStatement  while ParenListExpression Substatement

For Statements

ForStatement 
   for ( ForInitializer ; OptionalExpression ; OptionalExpression ) Substatement
|  for ( ForInBinding in ListExpressionallowIn ) Substatement
ForInitializer 
   «empty»
|  ListExpressionnoIn
|  VariableDefinitionnoIn
|  Attributes [no line break] VariableDefinitionnoIn
ForInBinding 
   PostfixExpression
|  VariableDefinitionKind VariableBindingnoIn
|  Attributes [no line break] VariableDefinitionKind VariableBindingnoIn
OptionalExpression 
   ListExpressionallowIn
|  «empty»

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] ListExpressionallowIn

Throw Statement

ThrowStatement  throw [no line break] ListExpressionallowIn

Try Statement

TryStatement 
   try Block CatchClauses
|  try Block CatchClausesOpt finally Block
CatchClausesOpt 
   «empty»
|  CatchClauses
CatchClauses 
   CatchClause
|  CatchClauses CatchClause
CatchClause  catch ( Parameter ) Block

Directives

Directive 
   EmptyStatement
|  Statement
|  AnnotatableDirective
|  Attributes [no line break] AnnotatableDirective
|  Attributes [no line break] { Directives }
|  Pragma Semicolon
AnnotatableDirective 
   VariableDefinitionallowIn Semicolon
|  FunctionDefinition
|  ClassDefinition
|  NamespaceDefinition Semicolon
|  ImportDirective Semicolon
|  UseDirective Semicolon
Directives 
   «empty»
|  DirectivesPrefix Directiveabbrev
DirectivesPrefix 
   «empty»
|  DirectivesPrefix Directivefull

Attributes

Attributes 
   Attribute
|  AttributeCombination
AttributeCombination  Attribute [no line break] Attributes
Attribute 
   AttributeExpression
|  true
|  false
|  ReservedNamespace

Use Directive

UseDirective  use namespace ParenListExpression

Import Directive

ImportDirective 
   import PackageName
|  import Identifier = PackageName

Pragma

Pragma  use PragmaItems
PragmaItems 
   PragmaItem
|  PragmaItems , PragmaItem
PragmaItem 
   PragmaExpr
|  PragmaExpr ?
PragmaExpr 
   Identifier
|  Identifier ( PragmaArgument )
PragmaArgument 
   true
|  false
|  Number
|  - Number
|  - NegatedMinLong
|  String

Definitions

Variable Definition

VariableDefinition  VariableDefinitionKind VariableBindingList
VariableDefinitionKind 
   var
|  const
VariableBindingList 
   VariableBinding
|  VariableBindingList , VariableBinding
VariableBinding  TypedIdentifier VariableInitialisation
VariableInitialisation 
   «empty»
|  = VariableInitializer
VariableInitializer 
   AssignmentExpression
|  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 VariableInitialisationallowIn

Function Definition

FunctionDefinition  function FunctionName FunctionCommon
FunctionName 
   Identifier
|  get [no line break] Identifier
|  set [no line break] Identifier
FunctionCommon  ( Parameters ) Result Block
Parameters 
   «empty»
|  NonemptyParameters
NonemptyParameters 
   ParameterInit
|  ParameterInit , NonemptyParameters
|  RestParameter
Parameter  ParameterAttributes TypedIdentifierallowIn
ParameterAttributes 
   «empty»
|  const
ParameterInit 
   Parameter
|  Parameter = AssignmentExpressionallowIn
RestParameter 
   ...
|  ... ParameterAttributes Identifier
Result 
   «empty»
|  : TypeExpressionallowIn

Class Definition

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

Namespace Definition

NamespaceDefinition  namespace Identifier

Programs

Program 
   Directives
|  PackageDefinition Program

Package Definition

PackageDefinition  package PackageNameOpt Block
PackageNameOpt 
   «empty»
|  PackageName
PackageName 
   String
|  PackageIdentifiers
PackageIdentifiers 
   Identifier
|  PackageIdentifiers . Identifier

Waldemar Horwat
Last modified Monday, June 30, 2003
previousupnext