ECMAScript 4 Netscape Proposal
Formal Description
Lexical Grammar
previousupnext

Monday, June 30, 2003

This LALR(1) grammar describes the lexical syntax of the ECMAScript 4 proposal. See also the description of the grammar notation.

This document is also available as a Word RTF file.

The lexer’s start symbols are: NextInputElementnum if the previous input element was a number; NextInputElementre if the previous input element was not a number and a / should be interpreted as a regular expression; and NextInputElementdiv if the previous input element was not a number and a / should be interpreted as a division or division-assignment operator.

In addition to the above, the start symbol StringNumericLiteral is used by the syntactic semantics for string-to-number conversions and the start symbol StringDecimalLiteral is used by the syntactic semantics for implementing the parseFloat function.

Unicode Character Classes

UnicodeCharacter  Any Unicode character
UnicodeInitialAlphabetic  Any character in category Lu (uppercase letter), Ll (lowercase letter), Lt (titlecase letter), Lm (modifier letter), Lo (other letter), or Nl (letter number) in the Unicode Character Database
UnicodeAlphanumeric  Any character in category Lu (uppercase letter), Ll (lowercase letter), Lt (titlecase letter), Lm (modifier letter), Lo (other letter), Nd (decimal number), Nl (letter number), Mn (non-spacing mark), Mc (combining spacing mark), or Pc (connector punctuation) in the Unicode Character Database
WhiteSpaceCharacter 
   «TAB» | «VT» | «FF» | «SP» | «u00A0»
|  «u2000» | «u2001» | «u2002» | «u2003» | «u2004» | «u2005» | «u2006» | «u2007»
|  «u2008» | «u2009» | «u200A» | «u200B»
|  «u3000»
LineTerminator  «LF» | «CR» | «u0085» | «u2028» | «u2029»
ASCIIDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Comments

LineComment  / / LineCommentCharacters
LineCommentCharacters 
   «empty»
|  LineCommentCharacters NonTerminator
NonTerminator  UnicodeCharacter except LineTerminator
SingleLineBlockComment  / * BlockCommentCharacters * /
BlockCommentCharacters 
   «empty»
|  BlockCommentCharacters NonTerminatorOrSlash
|  PreSlashCharacters /
PreSlashCharacters 
   «empty»
|  BlockCommentCharacters NonTerminatorOrAsteriskOrSlash
|  PreSlashCharacters /
NonTerminatorOrSlash  NonTerminator except /
NonTerminatorOrAsteriskOrSlash  NonTerminator except * | /
MultiLineBlockComment  / * MultiLineBlockCommentCharacters BlockCommentCharacters * /
MultiLineBlockCommentCharacters 
   BlockCommentCharacters LineTerminator
|  MultiLineBlockCommentCharacters BlockCommentCharacters LineTerminator

White Space

WhiteSpace 
   «empty»
|  WhiteSpace WhiteSpaceCharacter
|  WhiteSpace SingleLineBlockComment

Line Breaks

LineBreak 
   LineTerminator
|  LineComment LineTerminator
|  MultiLineBlockComment
LineBreaks 
   LineBreak
|  LineBreaks WhiteSpace LineBreak

Input Elements

  {redivnum}
NextInputElementre  WhiteSpace InputElementre
NextInputElementdiv  WhiteSpace InputElementdiv
NextInputElementnum  [lookahead{ContinuingIdentifierCharacter\}] WhiteSpace InputElementdiv
InputElementre 
   LineBreaks
|  IdentifierOrKeyword
|  Punctuator
|  NumericLiteral
|  StringLiteral
|  RegExpLiteral
|  EndOfInput
InputElementdiv 
   LineBreaks
|  IdentifierOrKeyword
|  Punctuator
|  DivisionPunctuator
|  NumericLiteral
|  StringLiteral
|  EndOfInput
EndOfInput 
   End
|  LineComment End

Keywords and Identifiers

IdentifierOrKeyword  IdentifierName
IdentifierName 
   InitialIdentifierCharacterOrEscape
|  NullEscapes InitialIdentifierCharacterOrEscape
|  IdentifierName ContinuingIdentifierCharacterOrEscape
|  IdentifierName NullEscape
NullEscapes 
   NullEscape
|  NullEscapes NullEscape
NullEscape  \ _
InitialIdentifierCharacterOrEscape 
   InitialIdentifierCharacter
|  \ HexEscape
InitialIdentifierCharacter  UnicodeInitialAlphabetic | $ | _
ContinuingIdentifierCharacterOrEscape 
   ContinuingIdentifierCharacter
|  \ HexEscape
ContinuingIdentifierCharacter  UnicodeAlphanumeric | $ | _

Punctuators

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

Numeric Literals

NumericLiteral 
   DecimalLiteralnoLeadingZeros
|  HexIntegerLiteral
|  DecimalLiteralnoLeadingZeros LetterF
|  IntegerLiteral LetterL
|  IntegerLiteral LetterU LetterL
IntegerLiteral 
   DecimalIntegerLiteralnoLeadingZeros
|  HexIntegerLiteral
LetterF  F | f
LetterL  L | l
LetterU  U | u
  {noLeadingZerosallowLeadingZeros}
DecimalLiteral 
   Mantissa
|  Mantissa LetterE SignedInteger
LetterE  E | e
Mantissa 
   DecimalIntegerLiteral
|  DecimalIntegerLiteral .
|  DecimalIntegerLiteral . Fraction
|  . Fraction
DecimalIntegerLiteralnoLeadingZeros 
   0
|  NonZeroDecimalDigits
DecimalIntegerLiteralallowLeadingZeros  DecimalDigits
NonZeroDecimalDigits 
   NonZeroDigit
|  NonZeroDecimalDigits ASCIIDigit
NonZeroDigit  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Fraction  DecimalDigits
SignedInteger  OptionalSign DecimalDigits
OptionalSign 
   «empty»
|  +
|  -
DecimalDigits 
   ASCIIDigit
|  DecimalDigits ASCIIDigit
HexIntegerLiteral 
   0 LetterX HexDigit
|  HexIntegerLiteral HexDigit
LetterX  X | x
HexDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | a | b | c | d | e | f

String Literals

  {singledouble}
StringLiteral 
   ' StringCharssingle '
|  " StringCharsdouble "
StringChars 
   «empty»
|  StringChars StringChar
|  StringChars NullEscape
StringChar 
   LiteralStringChar
|  \ StringEscape
LiteralStringCharsingle  UnicodeCharacter except ' | \ | LineTerminator
LiteralStringChardouble  UnicodeCharacter except " | \ | LineTerminator
StringEscape 
   ControlEscape
|  ZeroEscape
|  HexEscape
|  IdentityEscape
IdentityEscape  NonTerminator except _ | UnicodeAlphanumeric
ControlEscape 
   b
|  f
|  n
|  r
|  t
|  v
ZeroEscape  0 [lookahead{ASCIIDigit}]
HexEscape 
   x HexDigit HexDigit
|  u HexDigit HexDigit HexDigit HexDigit
|  U HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit

Regular Expression Literals

RegExpLiteral  RegExpBody RegExpFlags
RegExpFlags 
   «empty»
|  RegExpFlags ContinuingIdentifierCharacterOrEscape
|  RegExpFlags NullEscape
RegExpBody  / [lookahead{*}] RegExpChars /
RegExpChars 
   RegExpChar
|  RegExpChars RegExpChar
RegExpChar 
   OrdinaryRegExpChar
|  \ NonTerminator
OrdinaryRegExpChar  NonTerminator except \ | /

String-to-Number Conversion

StringNumericLiteral 
   StringWhiteSpace
|  StringWhiteSpace SignedDecimalLiteral StringWhiteSpace
|  StringWhiteSpace OptionalSign HexIntegerLiteral StringWhiteSpace
SignedDecimalLiteral 
   OptionalSign DecimalLiteralallowLeadingZeros
|  OptionalSign I n f i n i t y
|  N a N
StringWhiteSpace 
   «empty»
|  StringWhiteSpace WhiteSpaceOrLineTerminatorChar
WhiteSpaceOrLineTerminatorChar  WhiteSpaceCharacter | LineTerminator

parseFloat Conversion

StringDecimalLiteral  StringWhiteSpace SignedDecimalLiteral

Waldemar Horwat
Last modified Monday, June 30, 2003
previousupnext