ECMAScript 4 Netscape Proposal
Formal Description
Lexical Semantics
previousupnext

Monday, June 30, 2003

The lexical 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 lexical grammar is repeated here. See also the description of the semantic 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.

Semantics

tag lineBreak;
tag endOfInput;
tuple Keyword
nameString
end tuple;
tuple Punctuator
nameString
end tuple;
tuple Identifier
nameString
end tuple;
tuple NumberToken
end tuple;
tag negatedMinLong;
tuple StringToken
valueString
end tuple;
tuple RegularExpression
bodyString,
flagsString
end tuple;
TokenKeyword  Punctuator  Identifier  NumberToken  {negatedMinLong StringToken  RegularExpression;
InputElement = {lineBreakendOfInput Token;
tag syntaxError;
tag rangeError;
SemanticException = {syntaxErrorrangeError};

Unicode Character Classes

Syntax

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

Semantics

DecimalValue[ASCIIDigit]: Integer = digitValue(ASCIIDigit);

Comments

Syntax

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

Syntax

WhiteSpace 
   «empty»
|  WhiteSpace WhiteSpaceCharacter
|  WhiteSpace SingleLineBlockComment

Line Breaks

Syntax

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

Input Elements

Syntax

  {redivnum}
NextInputElementre  WhiteSpace InputElementre
NextInputElementdiv  WhiteSpace InputElementdiv
NextInputElementnum  [lookahead{ContinuingIdentifierCharacter\}] WhiteSpace InputElementdiv

Semantics

Lex[NextInputElement]: InputElement;
Lex[NextInputElementre  WhiteSpace InputElementre] = Lex[InputElementre];
Lex[NextInputElementdiv  WhiteSpace InputElementdiv] = Lex[InputElementdiv];
Lex[NextInputElementnum  [lookahead{ContinuingIdentifierCharacter\}] WhiteSpace InputElementdiv] = Lex[InputElementdiv];

Syntax

InputElementre 
   LineBreaks
|  IdentifierOrKeyword
|  Punctuator
|  NumericLiteral
|  StringLiteral
|  RegExpLiteral
|  EndOfInput
InputElementdiv 
   LineBreaks
|  IdentifierOrKeyword
|  Punctuator
|  DivisionPunctuator
|  NumericLiteral
|  StringLiteral
|  EndOfInput
EndOfInput 
   End
|  LineComment End

Semantics

Lex[InputElement]: InputElement;
Lex[InputElement  LineBreaks] = lineBreak;
Lex[InputElement  IdentifierOrKeyword] = Lex[IdentifierOrKeyword];
Lex[InputElement  Punctuator] = Lex[Punctuator];
Lex[InputElementdiv  DivisionPunctuator] = Lex[DivisionPunctuator];
Lex[InputElement  NumericLiteral] = Lex[NumericLiteral];
Lex[InputElement  StringLiteral] = Lex[StringLiteral];
Lex[InputElementre  RegExpLiteral] = Lex[RegExpLiteral];
Lex[InputElement  EndOfInput] = endOfInput;

Keywords and Identifiers

Syntax

IdentifierOrKeyword  IdentifierName

Semantics

Lex[IdentifierOrKeyword  IdentifierName]: InputElement
begin
idString  Lex[IdentifierName];
if id  {“abstract”, “as”, “break”, “case”, “catch”, “class”, “const”, “continue”, “debugger”, “default”, “delete”, “do”, “else”, “enum”, “export”, “extends”, “false”, “finally”, “for”, “function”, “get”, “goto”, “if”, “implements”, “import”, “in”, “instanceof”, “interface”, “is”, “namespace”, “native”, “new”, “null”, “package”, “private”, “protected”, “public”, “return”, “set”, “super”, “switch”, “synchronized”, “this”, “throw”, “throws”, “transient”, “true”, “try”, “typeof”, “use”, “var”, “volatile”, “while”, “with”} and not ContainsEscapes[IdentifierNamethen
return Keywordnameid
else return Identifiernameid
end if
end;

Syntax

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

Semantics

Lex[IdentifierName]: String;
Lex[IdentifierName0  IdentifierName1 ContinuingIdentifierCharacterOrEscape] = Lex[IdentifierName1 [Lex[ContinuingIdentifierCharacterOrEscape]];
Lex[IdentifierName0  IdentifierName1 NullEscape] = Lex[IdentifierName1];
ContainsEscapes[IdentifierName]: Boolean;
ContainsEscapes[IdentifierName  InitialIdentifierCharacterOrEscape] = ContainsEscapes[InitialIdentifierCharacterOrEscape];
ContainsEscapes[IdentifierName  NullEscapes InitialIdentifierCharacterOrEscape] = true;
ContainsEscapes[IdentifierName0  IdentifierName1 ContinuingIdentifierCharacterOrEscape] = ContainsEscapes[IdentifierName1or ContainsEscapes[ContinuingIdentifierCharacterOrEscape];
ContainsEscapes[IdentifierName  IdentifierName NullEscape] = true;
Lex[InitialIdentifierCharacterOrEscape]: Char16;
Lex[InitialIdentifierCharacterOrEscape  \ HexEscape]
begin
chChar16  Lex[HexEscape];
if the nonterminal InitialIdentifierCharacter can expand into [ch] then
return ch
else throw syntaxError
end if
end;
ContainsEscapes[InitialIdentifierCharacterOrEscape]: Boolean;
ContainsEscapes[InitialIdentifierCharacterOrEscape  InitialIdentifierCharacter] = false;
ContainsEscapes[InitialIdentifierCharacterOrEscape  \ HexEscape] = true;
Lex[ContinuingIdentifierCharacterOrEscape]: Char16;
Lex[ContinuingIdentifierCharacterOrEscape  \ HexEscape]
begin
chChar16  Lex[HexEscape];
if the nonterminal ContinuingIdentifierCharacter can expand into [ch] then
return ch
else throw syntaxError
end if
end;
ContainsEscapes[ContinuingIdentifierCharacterOrEscape]: Boolean;
ContainsEscapes[ContinuingIdentifierCharacterOrEscape  ContinuingIdentifierCharacter] = false;
ContainsEscapes[ContinuingIdentifierCharacterOrEscape  \ HexEscape] = true;

Punctuators

Syntax

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

Semantics

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

Numeric Literals

Syntax

NumericLiteral 
   DecimalLiteralnoLeadingZeros
|  HexIntegerLiteral
|  DecimalLiteralnoLeadingZeros LetterF
|  IntegerLiteral LetterL
|  IntegerLiteral LetterU LetterL
IntegerLiteral 
   DecimalIntegerLiteralnoLeadingZeros
|  HexIntegerLiteral
LetterF  F | f
LetterL  L | l
LetterU  U | u

Semantics

Lex[NumericLiteral]: Token;
Lex[NumericLiteral  DecimalLiteralnoLeadingZeros] = NumberTokenvalue: (Lex[DecimalLiteralnoLeadingZeros])f64;
Lex[NumericLiteral  HexIntegerLiteral] = NumberTokenvalue: (Lex[HexIntegerLiteral])f64;
Lex[NumericLiteral  DecimalLiteralnoLeadingZeros LetterF] = NumberTokenvalue: (Lex[DecimalLiteralnoLeadingZeros])f32;
Lex[NumericLiteral  IntegerLiteral LetterL]
begin
iInteger  Lex[IntegerLiteral];
if i  263 – 1 then return NumberTokenvalueilong
elsif i = 263 then return negatedMinLong
else throw rangeError
end if
end;
Lex[NumericLiteral  IntegerLiteral LetterU LetterL]
begin
iInteger  Lex[IntegerLiteral];
if i  264 – 1 then return NumberTokenvalueiulong
else throw rangeError
end if
end;
Lex[IntegerLiteral]: Integer;
Lex[IntegerLiteral  DecimalIntegerLiteralnoLeadingZeros] = Lex[DecimalIntegerLiteralnoLeadingZeros];
Lex[IntegerLiteral  HexIntegerLiteral] = Lex[HexIntegerLiteral];

Syntax

  {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

Semantics

Lex[DecimalLiteral]: Rational;
Lex[DecimalLiteral  Mantissa] = Lex[Mantissa];
Lex[DecimalLiteral  Mantissa LetterE SignedInteger] = Lex[Mantissa]10Lex[SignedInteger];
Lex[Mantissa]: Rational;
Lex[Mantissa  DecimalIntegerLiteral] = Lex[DecimalIntegerLiteral];
Lex[Mantissa  DecimalIntegerLiteral .] = Lex[DecimalIntegerLiteral];
Lex[Mantissa  DecimalIntegerLiteral . Fraction] = Lex[DecimalIntegerLiteral] + Lex[Fraction];
Lex[Mantissa  . Fraction] = Lex[Fraction];
Lex[DecimalIntegerLiteral]: Integer;
Lex[DecimalIntegerLiteralnoLeadingZeros  0] = 0;
Lex[DecimalIntegerLiteralnoLeadingZeros  NonZeroDecimalDigits] = Lex[NonZeroDecimalDigits];
Lex[DecimalIntegerLiteralallowLeadingZeros  DecimalDigits] = Lex[DecimalDigits];
Lex[NonZeroDecimalDigits]: Integer;
Lex[NonZeroDecimalDigits  NonZeroDigit] = DecimalValue[NonZeroDigit];
Lex[NonZeroDecimalDigits0  NonZeroDecimalDigits1 ASCIIDigit] = 10Lex[NonZeroDecimalDigits1] + DecimalValue[ASCIIDigit];
DecimalValue[NonZeroDigit]: Integer = digitValue(NonZeroDigit);
Lex[Fraction  DecimalDigits]: Rational = Lex[DecimalDigits]/10NDigits[DecimalDigits];

Syntax

SignedInteger  OptionalSign DecimalDigits
OptionalSign 
   «empty»
|  +
|  -

Semantics

Lex[SignedInteger  OptionalSign DecimalDigits]: IntegerLex[OptionalSign]Lex[DecimalDigits];
Lex[OptionalSign]: {–1, 1};
Lex[OptionalSign  «empty»] = 1;
Lex[OptionalSign  +] = 1;
Lex[OptionalSign  -] = –1;

Syntax

DecimalDigits 
   ASCIIDigit
|  DecimalDigits ASCIIDigit

Semantics

Lex[DecimalDigits]: Integer;
Lex[DecimalDigits  ASCIIDigit] = DecimalValue[ASCIIDigit];
Lex[DecimalDigits0  DecimalDigits1 ASCIIDigit] = 10Lex[DecimalDigits1] + DecimalValue[ASCIIDigit];
NDigits[DecimalDigits]: Integer;
NDigits[DecimalDigits  ASCIIDigit] = 1;
NDigits[DecimalDigits0  DecimalDigits1 ASCIIDigit] = NDigits[DecimalDigits1] + 1;

Syntax

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

Semantics

Lex[HexIntegerLiteral]: Integer;
Lex[HexIntegerLiteral  0 LetterX HexDigit] = HexValue[HexDigit];
Lex[HexIntegerLiteral0  HexIntegerLiteral1 HexDigit] = 16Lex[HexIntegerLiteral1] + HexValue[HexDigit];
HexValue[HexDigit]: Integer = digitValue(HexDigit);

String Literals

Syntax

  {singledouble}
StringLiteral 
   ' StringCharssingle '
|  " StringCharsdouble "

Semantics

Lex[StringLiteral]: Token;
Lex[StringLiteral  ' StringCharssingle '] = StringTokenvalueLex[StringCharssingle];
Lex[StringLiteral  " StringCharsdouble "] = StringTokenvalueLex[StringCharsdouble];

Syntax

StringChars 
   «empty»
|  StringChars StringChar
|  StringChars NullEscape
StringChar 
   LiteralStringChar
|  \ StringEscape
LiteralStringCharsingle  UnicodeCharacter except ' | \ | LineTerminator
LiteralStringChardouble  UnicodeCharacter except " | \ | LineTerminator

Semantics

Lex[StringChars]: String;
Lex[StringChars  «empty»] = “”;
Lex[StringChars0  StringChars1 StringChar] = Lex[StringChars1 [Lex[StringChar]];
Lex[StringChars0  StringChars1 NullEscape] = Lex[StringChars1];
Lex[StringChar]: Char16;
Lex[StringChar  LiteralStringChar] = LiteralStringChar;
Lex[StringChar  \ StringEscape] = Lex[StringEscape];

Syntax

StringEscape 
   ControlEscape
|  ZeroEscape
|  HexEscape
|  IdentityEscape
IdentityEscape  NonTerminator except _ | UnicodeAlphanumeric

Semantics

Lex[StringEscape]: Char16;
Lex[StringEscape  ControlEscape] = Lex[ControlEscape];
Lex[StringEscape  ZeroEscape] = Lex[ZeroEscape];
Lex[StringEscape  HexEscape] = Lex[HexEscape];
Lex[StringEscape  IdentityEscape] = IdentityEscape;

Syntax

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

Semantics

Lex[ControlEscape]: Char16;
Lex[ControlEscape  b] = ‘«BS»’;
Lex[ControlEscape  f] = ‘«FF»’;
Lex[ControlEscape  n] = ‘«LF»’;
Lex[ControlEscape  r] = ‘«CR»’;
Lex[ControlEscape  t] = ‘«TAB»’;
Lex[ControlEscape  v] = ‘«VT»’;

Syntax

ZeroEscape  0 [lookahead{ASCIIDigit}]

Semantics

Lex[ZeroEscape  0 [lookahead{ASCIIDigit}]]: Char16 = ‘«NUL»’;

Syntax

HexEscape 
   x HexDigit HexDigit
|  u HexDigit HexDigit HexDigit HexDigit
|  U HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit

Semantics

Lex[HexEscape]: Char16;
Lex[HexEscape  x HexDigit1 HexDigit2] = integerToChar16(16HexValue[HexDigit1] + HexValue[HexDigit2]);
Lex[HexEscape  u HexDigit1 HexDigit2 HexDigit3 HexDigit4] = integerToChar16(4096HexValue[HexDigit1] + 256HexValue[HexDigit2] + 16HexValue[HexDigit3] + HexValue[HexDigit4]);
Lex[HexEscape  U HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit] = ????;

Regular Expression Literals

Syntax

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

Semantics

Lex[RegExpLiteral  RegExpBody RegExpFlags]: TokenRegularExpressionbodyLex[RegExpBody], flagsLex[RegExpFlags];
Lex[RegExpFlags]: String;
Lex[RegExpFlags  «empty»] = “”;
Lex[RegExpFlags0  RegExpFlags1 ContinuingIdentifierCharacterOrEscape] = Lex[RegExpFlags1 [Lex[ContinuingIdentifierCharacterOrEscape]];
Lex[RegExpFlags0  RegExpFlags1 NullEscape] = Lex[RegExpFlags1];
Lex[RegExpBody  / [lookahead{*}] RegExpChars /]: String = Lex[RegExpChars];
Lex[RegExpChars]: String;
Lex[RegExpChars  RegExpChar] = Lex[RegExpChar];
Lex[RegExpChars0  RegExpChars1 RegExpChar] = Lex[RegExpChars1 Lex[RegExpChar];
Lex[RegExpChar]: String;
Lex[RegExpChar  OrdinaryRegExpChar] = [OrdinaryRegExpChar];
Lex[RegExpChar  \ NonTerminator] = [\’, NonTerminator];

String-to-Number Conversion

Syntax

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

Semantics

tag +zero;
tag –zero;
tag +;
tag ;
tag NaN;
ExtendedRational = Rational  {+zero–zero+NaN};
Lex[StringNumericLiteral]: ExtendedRational;
Lex[StringNumericLiteral  StringWhiteSpace] = +zero;
Lex[SignedDecimalLiteral]: ExtendedRational;
Lex[SignedDecimalLiteral  OptionalSign DecimalLiteralallowLeadingZeros] = combineWithSign(Lex[OptionalSign], Lex[DecimalLiteralallowLeadingZeros]);
Lex[SignedDecimalLiteral  OptionalSign I n f i n i t y] = Lex[OptionalSign] > 0 ? + : ;
Lex[SignedDecimalLiteral  N a N] = NaN;
proc combineWithSign(sign: {–1, 1}, qRational): ExtendedRational
if q  0 then return signq
elsif sign > 0 then return +zero
else return –zero
end if
end proc;

parseFloat Conversion

Syntax

StringDecimalLiteral  StringWhiteSpace SignedDecimalLiteral

Semantics

Lex[StringDecimalLiteral  StringWhiteSpace SignedDecimalLiteral]: ExtendedRationalLex[SignedDecimalLiteral];

Waldemar Horwat
Last modified Monday, June 30, 2003
previousupnext