JavaScript 2.0
Formal Description
Regular Expression Grammar
previousupnext

Sunday, May 16, 1999

This LR(1) grammar describes the regular expression syntax of the JavaScript 2.0 proposal. See also the description of the grammar notation.

This document is also available as a Word 98 rtf file.

Unicode Character Classes

UnicodeCharacter  Any Unicode character
UnicodeAlphanumeric  Any Unicode alphabetic or decimal digit character (includes ASCII 0-9, A-Z, and a-z)
LineTerminator  «LF» | «CR» | «u2028» | «u2029»
NonTerminator  UnicodeCharacter except LineTerminator

Regular Expression Definitions

Regular Expression Patterns

RegularExpressionPattern  Disjunction

Disjunctions

Disjunction 
   Alternativenormal
|  Alternativenormal | Disjunction

Quantifiers

l  {normalnonDecimalDigitnonOctalDigit}
Alternativel 
   «empty»
|  Assertion Alternativenormal
|  OrdinaryAtoml Alternativenormal
|  OneDigitEscape AlternativenonDecimalDigit
|  ShortOctalEscape AlternativenonOctalDigit
|  Atoml Quantifier Alternativenormal
Quantifier 
   QuantifierPrefix
|  QuantifierPrefix ?
QuantifierPrefix 
   *
|  +
|  ?
|  { DecimalDigits }
|  { DecimalDigits , }
|  { DecimalDigits , DecimalDigits }
DecimalDigits 
   DecimalDigit
|  DecimalDigits DecimalDigit
DecimalDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Assertions

Assertion 
   ^
|  $
|  \ b
|  \ B

Atoms

Atoml 
   OrdinaryAtoml
|  OneDigitEscape
|  ShortOctalEscape
OrdinaryAtoml 
   CompoundAtom
|  PatternCharacterl
PatternCharacternormal  NonTerminator except ^ | $ | \ | . | * | + | ? | ( | ) | [ | ] | { | } | |
PatternCharacternonDecimalDigit  PatternCharacternormal except DecimalDigit
PatternCharacternonOctalDigit  PatternCharacternormal except OctalDigit
CompoundAtom 
   ( Disjunction )
|  ( ? : Disjunction )
|  .
|  CharacterClass
|  CharacterEscape
|  TwoDigitEscape
|  CharacterClassEscape

Escapes

CharacterEscape 
   ControlEscape
|  \ c ControlLetter
|  ThreeDigitEscape
|  HexEscape
|  \ IdentityEscape
ControlLetter 
   A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
|  a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z
IdentityEscape  NonTerminator except UnicodeAlphanumeric
ControlEscape 
   \ f
|  \ n
|  \ r
|  \ t
|  \ v

Numeric Escapes

OneDigitEscape  \ DecimalDigit
ShortOctalEscape  \ ZeroToThree OctalDigit
TwoDigitEscape 
   \ ZeroToThree EightOrNine
|  \ FourToNine DecimalDigit
ThreeDigitEscape  \ ZeroToThree OctalDigit OctalDigit
ZeroToThree  0 | 1 | 2 | 3
FourToNine  4 | 5 | 6 | 7 | 8 | 9
OctalDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
EightOrNine  8 | 9
HexEscape 
   \ x HexDigit HexDigit
|  \ u HexDigit HexDigit HexDigit HexDigit
HexDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | a | b | c | d | e | f

Character Class Escapes

CharacterClassEscape 
   \ s
|  \ S
|  \ d
|  \ D
|  \ w
|  \ W

User-Specified Character Classes

s  {anynoCaretnoDash}
CharacterClass 
   [ ClassRangesnoCaret ]
|  [ ^ ClassRangesany ]
ClassRangess 
   «empty»
|  RangeLists,normal
RangeLists,l 
   FinalRangeAtoms,l
|  OrdinaryRangeAtoms,l RangeListSuffixnormal
|  ZeroEscape RangeListSuffixnonDecimalDigit
|  ShortOctalEscape RangeListSuffixnonOctalDigit
RangeListSuffixl 
   RangeListnoDash,l
|  - RangeAtomany,normal
|  - OrdinaryRangeAtomany,normal RangeListany,normal
|  - ZeroEscape RangeListany,nonDecimalDigit
|  - ShortOctalEscape RangeListany,nonOctalDigit

Character Class Range Atoms

FinalRangeAtomany,l  RangeAtomany,l
FinalRangeAtomnoCaret,l  RangeAtomnoCaret,l
FinalRangeAtomnoDash,l  RangeAtomany,l
RangeAtoms,l 
   OrdinaryRangeAtoms,l
|  ZeroEscape
|  ShortOctalEscape
OrdinaryRangeAtoms,l 
   RangeCharacters,l
|  RangeEscape
RangeCharacterany,normal  NonTerminator except \ | ]
RangeCharacterany,nonDecimalDigit  RangeCharacterany,normal except DecimalDigit
RangeCharacterany,nonOctalDigit  RangeCharacterany,normal except OctalDigit
RangeCharacternoCaret,normal  RangeCharacterany,normal except ^
RangeCharacternoDash,normal  RangeCharacterany,normal except -
RangeCharacternoDash,nonDecimalDigit  RangeCharacternoDash,normal except DecimalDigit
RangeCharacternoDash,nonOctalDigit  RangeCharacternoDash,normal except OctalDigit
RangeEscape 
   \ b
|  CharacterEscape
|  CharacterClassEscape
ZeroEscape  \ 0

Waldemar Horwat
Last modified Sunday, May 16, 1999