JavaScript 2.0
Formal Description
Lexer Semantics
previousupnext

Saturday, May 15, 1999

The lexer semantics describe the actions the lexer takes in order to transform an input stream of Unicode characters into a stream of tokens. For convenience, the lexer grammar is repeated here. See also the description of the semantic notation.

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

The start symbols are NextTokenre and NextTokendiv depending on whether a / should be interpreted as a regular expression or division.

Unicode Character Classes

Syntax

UnicodeCharacter  Any Unicode character
UnicodeInitialAlphabetic  Any Unicode initial alphabetic character (includes ASCII A-Z and a-z)
UnicodeAlphanumeric  Any Unicode alphabetic or decimal digit character (includes ASCII 0-9, A-Z, and a-z)
WhiteSpaceCharacter 
   «TAB» | «VT» | «FF» | «SP» | «u00A0»
|  «u2000» | «u2001» | «u2002» | «u2003» | «u2004» | «u2005» | «u2006» | «u2007»
|  «u2008» | «u2009» | «u200A» | «u200B»
|  «u3000»
LineTerminator  «LF» | «CR» | «u2028» | «u2029»
ASCIIDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Semantics

action DigitValue[ASCIIDigit] : Integer = digitValue(ASCIIDigit)

Comments

Syntax

LineComment  / / LineCommentCharacters
LineCommentCharacters 
   «empty»
|  LineCommentCharacters NonTerminator
NonTerminator  UnicodeCharacter except LineTerminator
BlockComment  / * BlockCommentCharacters * /
BlockCommentCharacters 
   «empty»
|  BlockCommentCharacters NonSlash
|  PreSlashCharacters /
PreSlashCharacters 
   «empty»
|  BlockCommentCharacters NonAsteriskOrSlash
|  PreSlashCharacters /
NonSlash  UnicodeCharacter except /
NonAsteriskOrSlash  UnicodeCharacter except * | /

White space

Syntax

WhiteSpace 
   «empty»
|  WhiteSpace WhiteSpaceCharacter
|  WhiteSpace LineTerminator
|  WhiteSpace LineComment LineTerminator
|  WhiteSpace BlockComment

Tokens

Syntax

t  {rediv}
NextTokent  WhiteSpace Tokent
Tokenre 
   IdentifierOrReservedWord
|  Punctuator
|  NumericLiteral
|  QuantityLiteral
|  StringLiteral
|  RegExpLiteralslash
|  RegExpLiteralguillemet
|  EndOfInput
Tokendiv 
   IdentifierOrReservedWord
|  Punctuator
|  DivisionPunctuator
|  NumericLiteral
|  QuantityLiteral
|  StringLiteral
|  RegExpLiteralguillemet
|  EndOfInput
EndOfInput 
   End
|  LineComment End

Semantics

type RegExp = tuple {reBodyStringreFlagsString}

type Quantity = tuple {amountDoubleunitString}

type Token
  = oneof {
           identifierString;
           keywordString;
           punctuatorString;
           numberDouble;
           quantityQuantity;
           stringString;
           regularExpressionRegExp;
           end}

action Token[NextTokent] : Token

Token[NextTokent  WhiteSpace Tokent] = Token[Tokent]

action RegExpMayFollow[NextTokent] : Boolean

RegExpMayFollow[NextTokent  WhiteSpace Tokent] = RegExpMayFollow[Tokent]

action Token[Tokent] : Token

Token[Tokent  IdentifierOrReservedWord] = Token[IdentifierOrReservedWord]

Token[Tokent  Punctuator] = Token[Punctuator]

Token[Tokendiv  DivisionPunctuator] = punctuator Punctuator[DivisionPunctuator]

Token[Tokent  NumericLiteral] = number DoubleValue[NumericLiteral]

Token[Tokent  QuantityLiteral] = quantity QuantityValue[QuantityLiteral]

Token[Tokent  StringLiteral] = string StringValue[StringLiteral]

Token[Tokenre  RegExpLiteralslash] = regularExpression REValue[RegExpLiteralslash]

Token[Tokent  RegExpLiteralguillemet]
  = regularExpression REValue[RegExpLiteralguillemet]

Token[Tokent  EndOfInput] = end

action RegExpMayFollow[Tokent] : Boolean

RegExpMayFollow[Tokent  IdentifierOrReservedWord]
  = RegExpMayFollow[IdentifierOrReservedWord]

RegExpMayFollow[Tokent  Punctuator] = RegExpMayFollow[Punctuator]

RegExpMayFollow[Tokendiv  DivisionPunctuator] = true

RegExpMayFollow[Tokent  NumericLiteral] = false

RegExpMayFollow[Tokent  QuantityLiteral] = false

RegExpMayFollow[Tokent  StringLiteral] = false

RegExpMayFollow[Tokenre  RegExpLiteralslash] = false

RegExpMayFollow[Tokent  RegExpLiteralguillemet] = false

RegExpMayFollow[Tokent  EndOfInput] = true

Keywords and identifiers

Syntax

IdentifierName 
   InitialIdentifierCharacter
|  IdentifierName ContinuingIdentifierCharacter
InitialIdentifierCharacter 
   OrdinaryInitialIdentifierCharacter
|  HexEscape
OrdinaryInitialIdentifierCharacter  UnicodeInitialAlphabetic | $ | _
ContinuingIdentifierCharacter 
   OrdinaryContinuingIdentifierCharacter
|  HexEscape
OrdinaryContinuingIdentifierCharacter  UnicodeAlphanumeric | $ | _

Semantics

action Name[IdentifierName] : String

Name[IdentifierName  InitialIdentifierCharacter]
  = [CharacterValue[InitialIdentifierCharacter]]

Name[IdentifierName  IdentifierName1 ContinuingIdentifierCharacter]
  = Name[IdentifierName1 [CharacterValue[ContinuingIdentifierCharacter]]

action ContainsEscapes[IdentifierName] : Boolean

ContainsEscapes[IdentifierName  InitialIdentifierCharacter]
  = ContainsEscapes[InitialIdentifierCharacter]

ContainsEscapes[IdentifierName  IdentifierName1 ContinuingIdentifierCharacter]
  = ContainsEscapes[IdentifierName1or ContainsEscapes[ContinuingIdentifierCharacter]

action CharacterValue[InitialIdentifierCharacter] : Character

CharacterValue[InitialIdentifierCharacter  OrdinaryInitialIdentifierCharacter]
  = OrdinaryInitialIdentifierCharacter

CharacterValue[InitialIdentifierCharacter  HexEscape]
  = if isOrdinaryInitialIdentifierCharacter(CharacterValue[HexEscape])
     then CharacterValue[HexEscape]
     else 

action ContainsEscapes[InitialIdentifierCharacter] : Boolean

ContainsEscapes[InitialIdentifierCharacter  OrdinaryInitialIdentifierCharacter] = false

ContainsEscapes[InitialIdentifierCharacter  HexEscape] = true

action CharacterValue[ContinuingIdentifierCharacter] : Character

CharacterValue[ContinuingIdentifierCharacter  OrdinaryContinuingIdentifierCharacter]
  = OrdinaryContinuingIdentifierCharacter

CharacterValue[ContinuingIdentifierCharacter  HexEscape]
  = if isOrdinaryContinuingIdentifierCharacter(CharacterValue[HexEscape])
     then CharacterValue[HexEscape]
     else 

action ContainsEscapes[ContinuingIdentifierCharacter] : Boolean

ContainsEscapes[ContinuingIdentifierCharacter  OrdinaryContinuingIdentifierCharacter]
  = false

ContainsEscapes[ContinuingIdentifierCharacter  HexEscape] = true

reservedWordsRE : String[]
  = [abstract”,
      “break”,
      “case”,
      “catch”,
      “class”,
      “const”,
      “continue”,
      “debugger”,
      “default”,
      “delete”,
      “do”,
      “else”,
      “enum”,
      “eval”,
      “export”,
      “extends”,
      “field”,
      “final”,
      “finally”,
      “for”,
      “function”,
      “goto”,
      “if”,
      “implements”,
      “import”,
      “in”,
      “instanceof”,
      “native”,
      “new”,
      “package”,
      “private”,
      “protected”,
      “public”,
      “return”,
      “static”,
      “switch”,
      “synchronized”,
      “throw”,
      “throws”,
      “transient”,
      “try”,
      “typeof”,
      “var”,
      “volatile”,
      “while”,
      “with]

reservedWordsDiv : String[] = [false”, “null”, “super”, “this”, “true]

nonReservedWords : String[]
  = [constructor”, “getter”, “method”, “override”, “setter”, “traditional”, “version]

keywords : String[] = reservedWordsRE  reservedWordsDiv  nonReservedWords

member(idStringlistString[]) : Boolean
  = if empty(list)
     then false
     else let sString = first(list)
           in if id = s
               then true
               else member(idrest(list))

Syntax

IdentifierOrReservedWord  IdentifierName

Semantics

action Token[IdentifierOrReservedWord] : Token

Token[IdentifierOrReservedWord  IdentifierName]
  = let idString = Name[IdentifierName]
     in if member(idkeywordsand (not ContainsEscapes[IdentifierName])
         then keyword id
         else identifier id

action RegExpMayFollow[IdentifierOrReservedWord] : Boolean

RegExpMayFollow[IdentifierOrReservedWord  IdentifierName]
  = let idString = Name[IdentifierName]
     in member(idreservedWordsREand (not ContainsEscapes[IdentifierName])

Punctuators

Syntax

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

Semantics

action Token[Punctuator] : Token

Token[Punctuator  PunctuatorRE] = punctuator Punctuator[PunctuatorRE]

Token[Punctuator  PunctuatorDiv] = punctuator Punctuator[PunctuatorDiv]

action RegExpMayFollow[Punctuator] : Boolean

RegExpMayFollow[Punctuator  PunctuatorRE] = true

RegExpMayFollow[Punctuator  PunctuatorDiv] = false

action Punctuator[PunctuatorRE] : String

Punctuator[PunctuatorRE  !] = “!

Punctuator[PunctuatorRE  ! =] = “!=

Punctuator[PunctuatorRE  ! = =] = “!==

Punctuator[PunctuatorRE  #] = “#

Punctuator[PunctuatorRE  %] = “%

Punctuator[PunctuatorRE  % =] = “%=

Punctuator[PunctuatorRE  &] = “&

Punctuator[PunctuatorRE  & &] = “&&

Punctuator[PunctuatorRE  & & =] = “&&=

Punctuator[PunctuatorRE  & =] = “&=

Punctuator[PunctuatorRE  (] = “(

Punctuator[PunctuatorRE  *] = “*

Punctuator[PunctuatorRE  * =] = “*=

Punctuator[PunctuatorRE  +] = “+

Punctuator[PunctuatorRE  + =] = “+=

Punctuator[PunctuatorRE  ,] = “,

Punctuator[PunctuatorRE  -] = “-

Punctuator[PunctuatorRE  - =] = “-=

Punctuator[PunctuatorRE  - >] = “->

Punctuator[PunctuatorRE  .] = “.

Punctuator[PunctuatorRE  . .] = “..

Punctuator[PunctuatorRE  . . .] = “...

Punctuator[PunctuatorRE  :] = “:

Punctuator[PunctuatorRE  : :] = “::

Punctuator[PunctuatorRE  ;] = “;

Punctuator[PunctuatorRE  <] = “<

Punctuator[PunctuatorRE  < <] = “<<

Punctuator[PunctuatorRE  < < =] = “<<=

Punctuator[PunctuatorRE  < =] = “<=

Punctuator[PunctuatorRE  =] = “=

Punctuator[PunctuatorRE  = =] = “==

Punctuator[PunctuatorRE  = = =] = “===

Punctuator[PunctuatorRE  >] = “>

Punctuator[PunctuatorRE  > =] = “>=

Punctuator[PunctuatorRE  > >] = “>>

Punctuator[PunctuatorRE  > > =] = “>>=

Punctuator[PunctuatorRE  > > >] = “>>>

Punctuator[PunctuatorRE  > > > =] = “>>>=

Punctuator[PunctuatorRE  ?] = “?

Punctuator[PunctuatorRE  @] = “@

Punctuator[PunctuatorRE  [] = “[

Punctuator[PunctuatorRE  ^] = “^

Punctuator[PunctuatorRE  ^ =] = “^=

Punctuator[PunctuatorRE  ^ ^] = “^^

Punctuator[PunctuatorRE  ^ ^ =] = “^^=

Punctuator[PunctuatorRE  {] = “{

Punctuator[PunctuatorRE  |] = “|

Punctuator[PunctuatorRE  | =] = “|=

Punctuator[PunctuatorRE  | |] = “||

Punctuator[PunctuatorRE  | | =] = “||=

Punctuator[PunctuatorRE  ~] = “~

action Punctuator[PunctuatorDiv] : String

Punctuator[PunctuatorDiv  )] = “)

Punctuator[PunctuatorDiv  + +] = “++

Punctuator[PunctuatorDiv  - -] = “--

Punctuator[PunctuatorDiv  ]] = “]

Punctuator[PunctuatorDiv  }] = “}

action Punctuator[DivisionPunctuator] : String

Punctuator[DivisionPunctuator  /] = “/

Punctuator[DivisionPunctuator  / =] = “/=

Numeric literals

Syntax

NumericLiteral 
   DecimalLiteral
|  HexIntegerLiteral
|  OctalIntegerLiteral

Semantics

action DoubleValue[NumericLiteral] : Double

DoubleValue[NumericLiteral  DecimalLiteral]
  = rationalToDouble(RationalValue[DecimalLiteral])

DoubleValue[NumericLiteral  HexIntegerLiteral]
  = rationalToDouble(IntegerValue[HexIntegerLiteral])

DoubleValue[NumericLiteral  OctalIntegerLiteral]
  = rationalToDouble(IntegerValue[OctalIntegerLiteral])

expt(baseRationalexponentInteger) : Rational
  = if exponent = 0
     then 1
     else if exponent < 0
     then 1/expt(base, -exponent)
     else base*expt(baseexponent - 1)

Syntax

DecimalLiteral  Mantissa Exponent
Mantissa 
   DecimalIntegerLiteral
|  DecimalIntegerLiteral .
|  DecimalIntegerLiteral . Fraction
|  . Fraction
DecimalIntegerLiteral 
   0
|  NonZeroDecimalDigits
NonZeroDecimalDigits 
   NonZeroDigit
|  NonZeroDecimalDigits ASCIIDigit
NonZeroDigit  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Fraction  DecimalDigits

Semantics

action RationalValue[DecimalLiteral] : Rational

RationalValue[DecimalLiteral  Mantissa Exponent]
  = RationalValue[Mantissa]*expt(10, IntegerValue[Exponent])

action RationalValue[Mantissa] : Rational

RationalValue[Mantissa  DecimalIntegerLiteral] = IntegerValue[DecimalIntegerLiteral]

RationalValue[Mantissa  DecimalIntegerLiteral .] = IntegerValue[DecimalIntegerLiteral]

RationalValue[Mantissa  DecimalIntegerLiteral . Fraction]
  = IntegerValue[DecimalIntegerLiteral] + RationalValue[Fraction]

RationalValue[Mantissa  . Fraction] = RationalValue[Fraction]

action IntegerValue[DecimalIntegerLiteral] : Integer

IntegerValue[DecimalIntegerLiteral  0] = 0

IntegerValue[DecimalIntegerLiteral  NonZeroDecimalDigits]
  = IntegerValue[NonZeroDecimalDigits]

action IntegerValue[NonZeroDecimalDigits] : Integer

IntegerValue[NonZeroDecimalDigits  NonZeroDigit] = DecimalValue[NonZeroDigit]

IntegerValue[NonZeroDecimalDigits  NonZeroDecimalDigits1 ASCIIDigit]
  = 10*IntegerValue[NonZeroDecimalDigits1] + DecimalValue[ASCIIDigit]

action DigitValue[NonZeroDigit] : Integer = digitValue(NonZeroDigit)

action RationalValue[Fraction] : Rational

RationalValue[Fraction  DecimalDigits]
  = IntegerValue[DecimalDigits]/expt(10, NDigits[DecimalDigits])

Syntax

Exponent 
   «empty»
|  ExponentIndicator SignedInteger
ExponentIndicator  E | e
SignedInteger 
   DecimalDigits
|  + DecimalDigits
|  - DecimalDigits

Semantics

action IntegerValue[Exponent] : Integer

IntegerValue[Exponent  «empty»] = 0

IntegerValue[Exponent  ExponentIndicator SignedInteger] = IntegerValue[SignedInteger]

action IntegerValue[SignedInteger] : Integer

IntegerValue[SignedInteger  DecimalDigits] = IntegerValue[DecimalDigits]

IntegerValue[SignedInteger  + DecimalDigits] = IntegerValue[DecimalDigits]

IntegerValue[SignedInteger  - DecimalDigits] = -IntegerValue[DecimalDigits]

Syntax

DecimalDigits 
   ASCIIDigit
|  DecimalDigits ASCIIDigit

Semantics

action IntegerValue[DecimalDigits] : Integer

IntegerValue[DecimalDigits  ASCIIDigit] = DecimalValue[ASCIIDigit]

IntegerValue[DecimalDigits  DecimalDigits1 ASCIIDigit]
  = 10*IntegerValue[DecimalDigits1] + DecimalValue[ASCIIDigit]

action NDigits[DecimalDigits] : Integer

NDigits[DecimalDigits  ASCIIDigit] = 1

NDigits[DecimalDigits  DecimalDigits1 ASCIIDigit] = NDigits[DecimalDigits1] + 1

Syntax

HexIntegerLiteral 
   0 HexIndicator HexDigit
|  HexIntegerLiteral HexDigit
HexIndicator  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
OctalIntegerLiteral 
   0 OctalDigit
|  OctalIntegerLiteral OctalDigit
OctalDigit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7

Semantics

action IntegerValue[HexIntegerLiteral] : Integer

IntegerValue[HexIntegerLiteral  0 HexIndicator HexDigit] = HexValue[HexDigit]

IntegerValue[HexIntegerLiteral  HexIntegerLiteral1 HexDigit]
  = 16*IntegerValue[HexIntegerLiteral1] + HexValue[HexDigit]

action DigitValue[HexDigit] : Integer = digitValue(HexDigit)

action IntegerValue[OctalIntegerLiteral] : Integer

IntegerValue[OctalIntegerLiteral  0 OctalDigit] = OctalValue[OctalDigit]

IntegerValue[OctalIntegerLiteral  OctalIntegerLiteral1 OctalDigit]
  = 8*IntegerValue[OctalIntegerLiteral1] + OctalValue[OctalDigit]

action DigitValue[OctalDigit] : Integer = digitValue(OctalDigit)

Quantity literals

Syntax

QuantityLiteral  NumericLiteral _ IdentifierName

Semantics

action QuantityValue[QuantityLiteral] : Quantity

QuantityValue[QuantityLiteral  NumericLiteral _ IdentifierName]
  = amount DoubleValue[NumericLiteral], unit Name[IdentifierName]

String literals

Syntax

q  {singledouble}
StringLiteral 
   ' StringCharssingle '
|  " StringCharsdouble "

Semantics

action StringValue[StringLiteral] : String

StringValue[StringLiteral  ' StringCharssingle '] = StringValue[StringCharssingle]

StringValue[StringLiteral  " StringCharsdouble "] = StringValue[StringCharsdouble]

Syntax

StringCharsq 
   OrdinaryStringCharsq
|  StringCharsq ShortOctalEscape
OrdinaryStringCharsq 
   «empty»
|  StringCharsq PlainStringCharq
|  OrdinaryStringCharsq OctalDigit
|  StringCharsq OrdinaryEscape
PlainStringCharsingle  UnicodeCharacter except ' | \ | OctalDigit | LineTerminator
PlainStringChardouble  UnicodeCharacter except " | \ | OctalDigit | LineTerminator

Semantics

action StringValue[StringCharsq] : String

StringValue[StringCharsq  OrdinaryStringCharsq] = StringValue[OrdinaryStringCharsq]

StringValue[StringCharsq  StringCharsq1 ShortOctalEscape]
  = StringValue[StringCharsq1 [CharacterValue[ShortOctalEscape]]

action StringValue[OrdinaryStringCharsq] : String

StringValue[OrdinaryStringCharsq  «empty»] = “”

StringValue[OrdinaryStringCharsq  StringCharsq PlainStringCharq]
  = StringValue[StringCharsq [PlainStringCharq]

StringValue[OrdinaryStringCharsq  OrdinaryStringCharsq1 OctalDigit]
  = StringValue[OrdinaryStringCharsq1 [OctalDigit]

StringValue[OrdinaryStringCharsq  StringCharsq OrdinaryEscape]
  = StringValue[StringCharsq [CharacterValue[OrdinaryEscape]]

Syntax

OrdinaryEscape 
   ControlEscape
|  FullOctalEscape
|  HexEscape
|  \ IdentityEscape
IdentityEscape  NonTerminator except UnicodeAlphanumeric

Semantics

action CharacterValue[OrdinaryEscape] : Character

CharacterValue[OrdinaryEscape  ControlEscape] = CharacterValue[ControlEscape]

CharacterValue[OrdinaryEscape  FullOctalEscape] = CharacterValue[FullOctalEscape]

CharacterValue[OrdinaryEscape  HexEscape] = CharacterValue[HexEscape]

CharacterValue[OrdinaryEscape  \ IdentityEscape] = IdentityEscape

Syntax

ControlEscape 
   \ b
|  \ f
|  \ n
|  \ r
|  \ t
|  \ v

Semantics

action CharacterValue[ControlEscape] : Character

CharacterValue[ControlEscape  \ b] = ‘«BS»

CharacterValue[ControlEscape  \ f] = ‘«FF»

CharacterValue[ControlEscape  \ n] = ‘«LF»

CharacterValue[ControlEscape  \ r] = ‘«CR»

CharacterValue[ControlEscape  \ t] = ‘«TAB»

CharacterValue[ControlEscape  \ v] = ‘«VT»

Syntax

ShortOctalEscape 
   \ OctalDigit
|  \ ZeroToThree OctalDigit
FullOctalEscape 
   \ FourToSeven OctalDigit
|  \ ZeroToThree OctalDigit OctalDigit
ZeroToThree  0 | 1 | 2 | 3
FourToSeven  4 | 5 | 6 | 7

Semantics

action CharacterValue[ShortOctalEscape] : Character

CharacterValue[ShortOctalEscape  \ OctalDigit] = codeToCharacter(OctalValue[OctalDigit])

CharacterValue[ShortOctalEscape  \ ZeroToThree OctalDigit]
  = codeToCharacter(8*OctalValue[ZeroToThree] + OctalValue[OctalDigit])

action CharacterValue[FullOctalEscape] : Character

CharacterValue[FullOctalEscape  \ FourToSeven OctalDigit]
  = codeToCharacter(8*OctalValue[FourToSeven] + OctalValue[OctalDigit])

CharacterValue[FullOctalEscape  \ ZeroToThree OctalDigit1 OctalDigit2]
  = codeToCharacter(
         64*OctalValue[ZeroToThree] + 8*OctalValue[OctalDigit1] + OctalValue[OctalDigit2])

action DigitValue[ZeroToThree] : Integer = digitValue(ZeroToThree)

action DigitValue[FourToSeven] : Integer = digitValue(FourToSeven)

Syntax

HexEscape 
   \ x HexDigit HexDigit
|  \ u HexDigit HexDigit HexDigit HexDigit

Semantics

action CharacterValue[HexEscape] : Character

CharacterValue[HexEscape  \ x HexDigit1 HexDigit2]
  = codeToCharacter(16*HexValue[HexDigit1] + HexValue[HexDigit2])

CharacterValue[HexEscape  \ u HexDigit1 HexDigit2 HexDigit3 HexDigit4]
  = codeToCharacter(
         4096*HexValue[HexDigit1] + 256*HexValue[HexDigit2] + 16*HexValue[HexDigit3] +
         HexValue[HexDigit4])

Regular expression literals

Syntax

r  {slashguillemet}
RegExpLiteralr  RegExpBodyr RegExpFlags
RegExpFlags 
   «empty»
|  RegExpFlags ContinuingIdentifierCharacter
RegExpBodyslash  / RegExpFirstChar RegExpCharsslash /
RegExpBodyguillemet  «u00AB» RegExpCharsguillemet «u00BB»
RegExpFirstChar 
   OrdinaryRegExpFirstChar
|  \ NonTerminator
OrdinaryRegExpFirstChar  NonTerminator except \ | / | *
RegExpCharsr 
   «empty»
|  RegExpCharsr RegExpCharr
RegExpCharr 
   OrdinaryRegExpCharr
|  \ NonTerminator
OrdinaryRegExpCharslash  NonTerminator except \ | /
OrdinaryRegExpCharguillemet  NonTerminator except \ | «u00BB»

Semantics

action REValue[RegExpLiteralr] : RegExp

REValue[RegExpLiteralr  RegExpBodyr RegExpFlags]
  = reBody REBody[RegExpBodyr], reFlags REFlags[RegExpFlags]

action REFlags[RegExpFlags] : String

REFlags[RegExpFlags  «empty»] = “”

REFlags[RegExpFlags  RegExpFlags1 ContinuingIdentifierCharacter]
  = REFlags[RegExpFlags1 [CharacterValue[ContinuingIdentifierCharacter]]

action REBody[RegExpBodyr] : String

REBody[RegExpBodyslash  / RegExpFirstChar RegExpCharsslash /]
  = REBody[RegExpFirstChar REBody[RegExpCharsslash]

REBody[RegExpBodyguillemet  «u00AB» RegExpCharsguillemet «u00BB»]
  = REBody[RegExpCharsguillemet]

action REBody[RegExpFirstChar] : String

REBody[RegExpFirstChar  OrdinaryRegExpFirstChar] = [OrdinaryRegExpFirstChar]

REBody[RegExpFirstChar  \ NonTerminator] = [\’, NonTerminator]

action REBody[RegExpCharsr] : String

REBody[RegExpCharsr  «empty»] = “”

REBody[RegExpCharsr  RegExpCharsr1 RegExpCharr]
  = REBody[RegExpCharsr1 REBody[RegExpCharr]

action REBody[RegExpCharr] : String

REBody[RegExpCharr  OrdinaryRegExpCharr] = [OrdinaryRegExpCharr]

REBody[RegExpCharr  \ NonTerminator] = [\’, NonTerminator]


Waldemar Horwat
Last modified Saturday, May 15, 1999